flexbiz-server 12.1.30 → 12.1.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "flexbiz-server",
3
3
  "main": "./server/app.js",
4
4
  "description": "Flexible Server",
5
- "version": "12.1.30",
5
+ "version": "12.1.31",
6
6
  "author": {
7
7
  "name": "Van Truong Pham",
8
8
  "email": "invncur@gmail.com"
@@ -183,9 +183,9 @@ $column_name$$.indexOf("$")?($detail_yn$$=!0,$columns$$=$column_name$$.split("$"
183
183
  null;$master_columns$$.forEach(function($column$$){if(0===$column$$.indexOf("exfields.")){let $_c$$=$column$$.replace("exfields.","");$row_master$$.exfields[$_c$$]=$row$$[$column$$]}else $row_master$$[$column$$]=$row$$[$column$$]});for(let $i$$=0;$i$$<$data_new$$.length;$i$$++){let $m$$=$data_new$$[$i$$],$is_eq$$=!0;$master_columns$$.forEach(function($column$$){underscore.isEqual($m$$[$column$$],$row_master$$[$column$$])||($is_eq$$=!1)});$is_eq$$&&($row_master_exists$$=$m$$)}$row_master_exists$$?
184
184
  $row_master$$=$row_master_exists$$:$data_new$$.push($row_master$$);let $row_detail$$;for(let $detail_name$$ in $details$$)$row_detail$$={},$details$$[$detail_name$$].columns.forEach(function($column$$){$row$$[$detail_name$$+"$"+$column$$]&&($row_detail$$[$column$$]=$row$$[$detail_name$$+"$"+$column$$])}),$row_master$$[$detail_name$$]||($row_master$$[$detail_name$$]=[]),0<underscore.keys($row_detail$$).length&&$row_master$$[$detail_name$$].push($row_detail$$);$cb$$()})},()=>{$req$$.data=$data_new$$;
185
185
  setImmediate(()=>{$next$$()})})},function($req$$,$res$$){let $data$$=$req$$.data||[],$columns$$=$req$$.columns;for(let $row$$ of $data$$){let $_first$$=$row$$._first;$_first$$&&0<$_first$$.length&&underscore.extend($row$$,$_first$$[0])}setImmediate(()=>{log.create({id_app:$req$$.user.current_id_app,id_func:$ctrl$$.name,action:"IMPORTEXCEL",data:{data:$data$$,columns:$columns$$}},$req$$.user.email,$req$$.header("user-agent"),$req$$)});let $values$$=$req$$.query.values;if($values$$){try{$values$$=JSONParser($values$$)}catch($e$$){console.error($e$$)}$values$$&&
186
- $data$$.forEach($row$$=>{for(let $key$$ in $values$$)$row$$[$key$$]=$values$$[$key$$]})}global.importDataMainPool?global.importDataMainPool.exec({user:$req$$.user,id_app:$req$$.user.current_id_app,module:$name$$.toUpperCase(),data:$data$$,configs:JSONParser(JSON.stringify(configs)),replace:!0===$req$$.query.update||"true"==$req$$.query.update},$response$$=>{setImmediate(()=>{if($response$$.error)return $res$$.status(400).send({error:$response$$.error,message:$response$$.message||$response$$.error});
187
- if(0===$response$$.result.rows_error.length)return $res$$.send($response$$.result);let $msg$$=$response$$.result.rows_error.map($r$$=>$r$$.error).join(", ");return $res$$.status(400).send({error:$response$$.result,message:$msg$$})})}):$ctrl$$.import($req$$.user,$req$$.user.current_id_app,$data$$,($e$$,$rs$$)=>{setImmediate(()=>{if($e$$)return console.error($e$$),$e$$.error?($e$$.message=$e$$.message||$e$$.error,$res$$.status(400).send($e$$)):$res$$.status(400).send({error:$e$$.message||$e$$,message:$e$$.message||
188
- $e$$});if(0===$rs$$.rows_error.length)$res$$.send($rs$$);else{let $msg$$=$rs$$.rows_error.map($r$$=>$r$$.error).join(", ");$res$$.status(400).send({message:$msg$$,error:$rs$$.error||$rs$$})}})},{replace:!0===$req$$.query.update||"true"==$req$$.query.update,req:$req$$})})};
186
+ $data$$.forEach($row$$=>{for(let $key$$ in $values$$)$row$$[$key$$]=$values$$[$key$$]})}global.importDataMainPool?global.importDataMainPool.exec({user:$req$$.user,id_app:$req$$.user.current_id_app,module:$name$$.toUpperCase(),data:$data$$,configs:JSON.stringify(configs),replace:!0===$req$$.query.update||"true"==$req$$.query.update},$response$$=>{setImmediate(()=>{if($response$$.error)return $res$$.status(400).send({error:$response$$.error,message:$response$$.message||$response$$.error});if(0===$response$$.result.rows_error.length)return $res$$.send($response$$.result);
187
+ let $msg$$=$response$$.result.rows_error.map($r$$=>$r$$.error).join(", ");return $res$$.status(400).send({error:$response$$.result,message:$msg$$})})}):$ctrl$$.import($req$$.user,$req$$.user.current_id_app,$data$$,($e$$,$rs$$)=>{setImmediate(()=>{if($e$$)return console.error($e$$),$e$$.error?($e$$.message=$e$$.message||$e$$.error,$res$$.status(400).send($e$$)):$res$$.status(400).send({error:$e$$.message||$e$$,message:$e$$.message||$e$$});if(0===$rs$$.rows_error.length)$res$$.send($rs$$);else{let $msg$$=
188
+ $rs$$.rows_error.map($r$$=>$r$$.error).join(", ");$res$$.status(400).send({message:$msg$$,error:$rs$$.error||$rs$$})}})},{replace:!0===$req$$.query.update||"true"==$req$$.query.update,req:$req$$})})};
189
189
  const PostBook=require("../libs/post-book"),utils=require("../libs/utils"),Sokho=global.getModel("sokho"),Sokhott=global.getModel("sokhott"),Sokhokhongton=global.getModel("sokhokhongton"),dmvt=global.getModel("dmvt"),Tdttno=global.getModel("tdttno"),Tdttno_tt=global.getModel("tdttno_tt"),Tdttco_tt=global.getModel("tdttco_tt"),Tdttco=global.getModel("tdttco"),Vatra=global.getModel("vatra"),Vatvao=global.getModel("vatvao"),deletePost=function($user$$,$obj$$,$callback$jscomp$1$$){$obj$$.toObject&&($obj$$=
190
190
  $obj$$.toObject());if(!$obj$$._id)return console.error("Error when delete post: obj does not have _id",$obj$$),$callback$jscomp$1$$("Error when delete post: obj does not have _id",$obj$$);async.series({delete_model_books_registed:$callback$jscomp$0$$=>{setImmediate(()=>{if(!global.model_books)return $callback$jscomp$0$$();async.mapSeries(global.model_books.filter($d$$=>0>$d$$.indexOf("sokho")&&0>$d$$.indexOf("sokhott")&&0>$d$$.indexOf("sokhokhongton")&&0>$d$$.indexOf("socai")),($bookName$$,$callback$$)=>
191
191
  {setImmediate(()=>{let $book$$=mongoose.models[$bookName$$.toLowerCase()];$book$$?$book$$.deleteMany({id_ct:$obj$$._id.toString()},$e$$=>{$callback$$($e$$)}):$callback$$()})},$e$$=>{$callback$jscomp$0$$($e$$)})})},sk:$callback$jscomp$0$$=>{setImmediate(()=>{(new PostBook($obj$$,$obj$$.details,Sokho,function($detail$$,$callback$$){$callback$$($detail$$)})).remove(function($e$$){$callback$jscomp$0$$($e$$)})})},sktt:$callback$jscomp$0$$=>{setImmediate(()=>{(new PostBook($obj$$,$obj$$.details,Sokhott,
@@ -1,4 +1,4 @@
1
- 'use strict';const worker_threads=require("worker_threads"),fs=require("fs");
1
+ 'use strict';const worker_threads=require("worker_threads"),fs=require("fs"),_=require("lodash");
2
2
  module.exports=class{constructor($filename$$){if(!fs.existsSync($filename$$))throw"Worker file is not exists";this.filename=$filename$$;this._queue=[];this.createWorker=this.createWorker.bind(this);this.runTask=this.runTask.bind(this);this.exec=this.exec.bind(this)}createWorker($filename$$){function $onExit$$(){$worker$$.removeListener("error",$onExit$$);$worker$$.removeListener("exit",$onExit$$);$worker$$.removeListener("message",$onMessage$$);delete $self$$.worker;let $task$$=$self$$._queue.shift();
3
3
  $task$$&&$self$$.runTask($task$$)}function $onMessage$$($message$$){setImmediate(()=>{$self$$.current_cb&&($self$$.current_cb($message$$),delete $self$$.current_cb);$self$$._queue.shift();0<$self$$._queue.length&&$self$$.runTask($self$$._queue[0])})}const $self$$=this,$worker$$=$self$$.worker=new worker_threads.Worker($filename$$);$worker$$.once("error",$onExit$$);$worker$$.once("exit",$onExit$$);$worker$$.on("message",$onMessage$$)}runTask($task$$){const $self$$=this;setImmediate(()=>{$self$$.worker||
4
- $self$$.createWorker($self$$.filename);$self$$.worker.postMessage($task$$.params);$self$$.current_cb=$task$$.callback})}exec($params$$,$callback$$=()=>{}){this._queue.push({params:$params$$,callback:$callback$$});1===this._queue.length&&this.runTask(this._queue[0])}destroy(){this.worker&&this.worker.terminate()}};
4
+ $self$$.createWorker($self$$.filename);$task$$.params&&$task$$.params.configs&&_.isObject($task$$.params.configs)&&($task$$.params.configs=JSON.stringify($task$$.params.configs));$self$$.worker.postMessage($task$$.params);$self$$.current_cb=$task$$.callback})}exec($params$$,$callback$$=()=>{}){this._queue.push({params:$params$$,callback:$callback$$});1===this._queue.length&&this.runTask(this._queue[0])}destroy(){this.worker&&this.worker.terminate()}};
@@ -6,16 +6,16 @@ exports.isAdmin=function($current_id_app$$,$email$$,$callback$$){if(!$current_id
6
6
  exports.hasRight=async function($current_id_app$$,$email$$,$module$$,$action$$,$callback$jscomp$0$$,$options$$={}){if(!$current_id_app$$||$options$$.notNeedRight||global.controllers[$module$$]&&global.controllers[$module$$].model&&global.controllers[$module$$].model.schema&&!underscore.has(global.controllers[$module$$].model.schema.paths,"id_app"))return $callback$jscomp$0$$(null,!0);$options$$.data&&($options$$.data.trang_thai||0==$options$$.data.trang_thai)&&($options$$.data.trang_thai=$options$$.data.trang_thai.toString());
7
7
  $options$$.obj&&($options$$.obj.trang_thai||0==$options$$.obj.trang_thai)&&($options$$.obj.trang_thai=$options$$.obj.trang_thai.toString());var $data_trang_thai$$=$options$$.data||$options$$.obj||{};const $ma_ct$$=(($options$$.obj||{}).ma_ct||($options$$.data||{}).ma_ct||"").toString().toUpperCase();let $ma_trang_thai$$=($data_trang_thai$$.trang_thai||$data_trang_thai$$.progress||"").toString().toUpperCase();!$ma_trang_thai$$&&$options$$.obj&&($ma_trang_thai$$=($options$$.obj.trang_thai||$options$$.obj.progress||
8
8
  "").toString().toUpperCase());if($ma_ct$$&&$ma_trang_thai$$)if($data_trang_thai$$=await trangthai.findOne({ma_trang_thai:$ma_trang_thai$$,ma_ct:$ma_ct$$}).lean()){if($data_trang_thai$$.not_need_right)return $callback$jscomp$0$$(null,!0)}else console.log("Khong tim thay trang thai cho chuc nang nay",{ma_ct:$ma_ct$$,ma_trang_thai:$ma_trang_thai$$,trang_thai:$data_trang_thai$$,action:$action$$});exports.isAdmin($current_id_app$$,$email$$,async($e_ms$$,$admin$$,$app$$,$participant$$)=>{if($e_ms$$)return $callback$jscomp$0$$($e_ms$$,
9
- !1);if($app$$&&$app$$.allow_modules&&0<$app$$.allow_modules.length&&($e_ms$$=await global.getModel("moduleinfo").find({"items.code":{$regex:"^"+$module$$+"$",$options:"i"}}),0<$e_ms$$.length&&0==$e_ms$$.filter($m$$=>0<=$app$$.allow_modules.indexOf($m$$.code)&&(!$m$$.not_for_companies||0>$m$$.not_for_companies.indexOf($app$$._id.toString()))&&(!$m$$.only_for_companies||0<=$m$$.only_for_companies.indexOf($app$$._id.toString()))).length))return $callback$jscomp$0$$('API "'+$module$$+'" ch\u01b0a \u0111\u01b0\u1ee3c k\u00edch ho\u1ea1t cho c\u00f4ng ty n\u00e0y',
10
- !1);if($options$$.data&&$options$$.data.id_app){if($options$$.data.id_app!=$current_id_app$$)return $callback$jscomp$0$$("B\u1ea1n kh\u00f4ng th\u1ec3 truy c\u1eadp \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",!1);if($options$$.obj&&$options$$.data.id_app!=$options$$.obj.id_app)return $callback$jscomp$0$$("B\u1ea1n kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",!1)}if($options$$.obj&&$options$$.obj.id_app&&$options$$.obj.id_app!=$current_id_app$$)return $callback$jscomp$0$$("B\u1ea1n kh\u00f4ng th\u1ec3 truy c\u1eadp \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",
11
- !1);if($options$$.notNeedRight)return $callback$jscomp$0$$(null,!0,$app$$);if($options$$.obj&&!$admin$$)if(2===$options$$.obj.visible_to){if(!underscore.contains($options$$.obj.visible_to_users,$email$$)&&$options$$.obj.of_user!==$email$$.toLowerCase()&&$options$$.obj.user_created&&$options$$.obj.user_created.toLowerCase()!==$email$$.toLowerCase())return $callback$jscomp$0$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n truy c\u1eadp \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",!1)}else if(1===$options$$.obj.visible_to&&
12
- $options$$.obj.of_user!==$email$$.toLowerCase()&&$options$$.obj.user_created&&$options$$.obj.user_created.toLowerCase()!==$email$$.toLowerCase()&&await exports.nguoiPhuTrach($options$$.obj.id_app,$options$$.obj.user_created)!=$email$$.toLowerCase()&&$options$$.obj.phu_trach!=$email$$.toLowerCase()&&0>($options$$.obj.attends||[]).indexOf($email$$))return $callback$jscomp$0$$("Ch\u1ec9 ng\u01b0\u1eddi t\u1ea1o, ph\u1ee5 tr\u00e1ch, h\u1ed7 tr\u1ee3 v\u00e0 admin m\u1edbi c\u00f3 quy\u1ec1n truy c\u1eadp \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",
13
- !1);$action$$=$action$$.toLowerCase();let $key_right$$=$email$$;$participant$$&&$participant$$.group_id&&($key_right$$=$participant$$.group_id.toLowerCase());right.findOne({id_app:$current_id_app$$,email:$key_right$$,module:$module$$.toLowerCase()},async function($error$jscomp$2_user_phu_trach$$,$_right__right_trang_thai$$){if($error$jscomp$2_user_phu_trach$$)return $callback$jscomp$0$$($error$jscomp$2_user_phu_trach$$,!1);if(!$admin$$){if(!$_right__right_trang_thai$$)return global.modulesInMenu[$module$$]||
14
- "view"!==$action$$&&("add"!==$action$$||"group"!==$module$$.toLowerCase())?$callback$jscomp$0$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n \u0111\u1ed1i v\u1edbi t\u00ednh n\u0103ng n\u00e0y",!1):$callback$jscomp$0$$(null,!0,$app$$);if(!$_right__right_trang_thai$$[$action$$])return $callback$jscomp$0$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n \u0111\u1ed1i v\u1edbi t\u00ednh n\u0103ng n\u00e0y",!1);if($options$$.obj&&$_right__right_trang_thai$$&&!$_right__right_trang_thai$$.viewOfOther&&$options$$.obj.user_created.toLowerCase()!==
15
- $email$$&&(2!==$options$$.obj.visible_to||!underscore.contains($options$$.obj.visible_to_users,$email$$))&&($error$jscomp$2_user_phu_trach$$=await exports.nguoiPhuTrach($options$$.obj.id_app,$options$$.obj.user_created),$options$$.obj.phu_trach!==$email$$&&$error$jscomp$2_user_phu_trach$$!=$email$$&&0>($options$$.obj.attends||[]).indexOf($email$$)))return $callback$jscomp$0$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n truy c\u1eadp \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",!1);if($ma_trang_thai$$)if($_right__right_trang_thai$$=
16
- $_right__right_trang_thai$$[`${$action$$}_trang_thai`]){if(!$_right__right_trang_thai$$[$ma_trang_thai$$]&&void 0!=$_right__right_trang_thai$$[$ma_trang_thai$$])return $callback$jscomp$0$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n \u0111\u1ed1i v\u1edbi tr\u1ea1ng th\u00e1i ch\u1ee9ng t\u1eeb n\u00e0y",!1)}else console.warn("Ch\u01b0a ph\u00e2n quy\u1ec1n theo trang thai cho action",{action:$action$$,ma_trang_thai:$ma_trang_thai$$,ma_ct:$ma_ct$$,group_user:$key_right$$})}$options$$.obj?async.series({trangthai:$callback$$=>
17
- {$options$$.obj&&("update"===$action$$||"delete"===$action$$)&&$options$$.obj.ma_ct?trangthai.findOne({ma_ct:$options$$.obj.ma_ct.toUpperCase(),ma_trang_thai:$options$$.obj.trang_thai},function($e$$,$trang_thai$$){if($e$$)return $callback$$($e$$);if($trang_thai$$){if("update"===$action$$){if(0==$trang_thai$$.allow_update)return $callback$$("Tr\u1ea1ng th\u00e1i ch\u1ee9ng t\u1eeb n\u00e0y kh\u00f4ng cho ph\u00e9p s\u1eeda");if(1==$trang_thai$$.lock_data)return $callback$$("Tr\u1ea1ng th\u00e1i ch\u1ee9ng t\u1eeb n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c kho\u00e1")}if("delete"===
18
- $action$$&&($trang_thai$$.lock_data||0==$trang_thai$$.allow_delete))return $callback$$("Tr\u1ea1ng th\u00e1i ch\u1ee9ng t\u1eeb n\u00e0y kh\u00f4ng cho ph\u00e9p xo\u00e1")}return $callback$$()}):$callback$$()}},$e$$=>{$e$$?$callback$jscomp$0$$($e$$,!1):$callback$jscomp$0$$(null,!0,$app$$)}):$callback$jscomp$0$$(null,!0,$app$$)})},$options$$)};
9
+ !1);if($app$$&&$app$$.allow_modules&&0<$app$$.allow_modules.length&&($e_ms$$=await global.getModel("moduleinfo").find({"items.code":{$regex:"^"+$module$$+"$",$options:"i"},active_require:!0}),0<$e_ms$$.length&&0==$e_ms$$.filter($m$$=>0<=$app$$.allow_modules.indexOf($m$$.code)&&(!$m$$.not_for_companies||0>$m$$.not_for_companies.indexOf($app$$._id.toString()))&&(!$m$$.only_for_companies||0<=$m$$.only_for_companies.indexOf($app$$._id.toString()))).length))return $callback$jscomp$0$$('API "'+$module$$+
10
+ '" ch\u01b0a \u0111\u01b0\u1ee3c k\u00edch ho\u1ea1t cho c\u00f4ng ty n\u00e0y (trong module '+$e_ms$$[0].app+"/"+$e_ms$$[0].title+")",!1);if($options$$.data&&$options$$.data.id_app){if($options$$.data.id_app!=$current_id_app$$)return $callback$jscomp$0$$("B\u1ea1n kh\u00f4ng th\u1ec3 truy c\u1eadp \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",!1);if($options$$.obj&&$options$$.data.id_app!=$options$$.obj.id_app)return $callback$jscomp$0$$("B\u1ea1n kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",
11
+ !1)}if($options$$.obj&&$options$$.obj.id_app&&$options$$.obj.id_app!=$current_id_app$$)return $callback$jscomp$0$$("B\u1ea1n kh\u00f4ng th\u1ec3 truy c\u1eadp \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",!1);if($options$$.notNeedRight)return $callback$jscomp$0$$(null,!0,$app$$);if($options$$.obj&&!$admin$$)if(2===$options$$.obj.visible_to){if(!underscore.contains($options$$.obj.visible_to_users,$email$$)&&$options$$.obj.of_user!==$email$$.toLowerCase()&&$options$$.obj.user_created&&$options$$.obj.user_created.toLowerCase()!==
12
+ $email$$.toLowerCase())return $callback$jscomp$0$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n truy c\u1eadp \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",!1)}else if(1===$options$$.obj.visible_to&&$options$$.obj.of_user!==$email$$.toLowerCase()&&$options$$.obj.user_created&&$options$$.obj.user_created.toLowerCase()!==$email$$.toLowerCase()&&await exports.nguoiPhuTrach($options$$.obj.id_app,$options$$.obj.user_created)!=$email$$.toLowerCase()&&$options$$.obj.phu_trach!=$email$$.toLowerCase()&&0>($options$$.obj.attends||
13
+ []).indexOf($email$$))return $callback$jscomp$0$$("Ch\u1ec9 ng\u01b0\u1eddi t\u1ea1o, ph\u1ee5 tr\u00e1ch, h\u1ed7 tr\u1ee3 v\u00e0 admin m\u1edbi c\u00f3 quy\u1ec1n truy c\u1eadp \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",!1);$action$$=$action$$.toLowerCase();let $key_right$$=$email$$;$participant$$&&$participant$$.group_id&&($key_right$$=$participant$$.group_id.toLowerCase());right.findOne({id_app:$current_id_app$$,email:$key_right$$,module:$module$$.toLowerCase()},async function($error$jscomp$2_user_phu_trach$$,
14
+ $_right__right_trang_thai$$){if($error$jscomp$2_user_phu_trach$$)return $callback$jscomp$0$$($error$jscomp$2_user_phu_trach$$,!1);if(!$admin$$){if(!$_right__right_trang_thai$$)return global.modulesInMenu[$module$$]||"view"!==$action$$&&("add"!==$action$$||"group"!==$module$$.toLowerCase())?$callback$jscomp$0$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n \u0111\u1ed1i v\u1edbi t\u00ednh n\u0103ng n\u00e0y",!1):$callback$jscomp$0$$(null,!0,$app$$);if(!$_right__right_trang_thai$$[$action$$])return $callback$jscomp$0$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n \u0111\u1ed1i v\u1edbi t\u00ednh n\u0103ng n\u00e0y",
15
+ !1);if($options$$.obj&&$_right__right_trang_thai$$&&!$_right__right_trang_thai$$.viewOfOther&&$options$$.obj.user_created.toLowerCase()!==$email$$&&(2!==$options$$.obj.visible_to||!underscore.contains($options$$.obj.visible_to_users,$email$$))&&($error$jscomp$2_user_phu_trach$$=await exports.nguoiPhuTrach($options$$.obj.id_app,$options$$.obj.user_created),$options$$.obj.phu_trach!==$email$$&&$error$jscomp$2_user_phu_trach$$!=$email$$&&0>($options$$.obj.attends||[]).indexOf($email$$)))return $callback$jscomp$0$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n truy c\u1eadp \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y",
16
+ !1);if($ma_trang_thai$$)if($_right__right_trang_thai$$=$_right__right_trang_thai$$[`${$action$$}_trang_thai`]){if(!$_right__right_trang_thai$$[$ma_trang_thai$$]&&void 0!=$_right__right_trang_thai$$[$ma_trang_thai$$])return $callback$jscomp$0$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n \u0111\u1ed1i v\u1edbi tr\u1ea1ng th\u00e1i ch\u1ee9ng t\u1eeb n\u00e0y",!1)}else console.warn("Ch\u01b0a ph\u00e2n quy\u1ec1n theo trang thai cho action",{action:$action$$,ma_trang_thai:$ma_trang_thai$$,ma_ct:$ma_ct$$,
17
+ group_user:$key_right$$})}$options$$.obj?async.series({trangthai:$callback$$=>{$options$$.obj&&("update"===$action$$||"delete"===$action$$)&&$options$$.obj.ma_ct?trangthai.findOne({ma_ct:$options$$.obj.ma_ct.toUpperCase(),ma_trang_thai:$options$$.obj.trang_thai},function($e$$,$trang_thai$$){if($e$$)return $callback$$($e$$);if($trang_thai$$){if("update"===$action$$){if(0==$trang_thai$$.allow_update)return $callback$$("Tr\u1ea1ng th\u00e1i ch\u1ee9ng t\u1eeb n\u00e0y kh\u00f4ng cho ph\u00e9p s\u1eeda");
18
+ if(1==$trang_thai$$.lock_data)return $callback$$("Tr\u1ea1ng th\u00e1i ch\u1ee9ng t\u1eeb n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c kho\u00e1")}if("delete"===$action$$&&($trang_thai$$.lock_data||0==$trang_thai$$.allow_delete))return $callback$$("Tr\u1ea1ng th\u00e1i ch\u1ee9ng t\u1eeb n\u00e0y kh\u00f4ng cho ph\u00e9p xo\u00e1")}return $callback$$()}):$callback$$()}},$e$$=>{$e$$?$callback$jscomp$0$$($e$$,!1):$callback$jscomp$0$$(null,!0,$app$$)}):$callback$jscomp$0$$(null,!0,$app$$)})},$options$$)};
19
19
  exports.getRightByItem=function($id_app$$,$model$$,$email$$,$next$$,$module$$,$options$$={}){exports.isAdmin($id_app$$,$email$$,async function($e$jscomp$3_key_right$$,$admin$$,$app$$,$participant$$){if($e$jscomp$3_key_right$$)return $next$$($e$jscomp$3_key_right$$);let $condition$$={};$module$$||($module$$=$model$$&&$model$$.collection&&$model$$.collection.name&&1<$model$$.collection.name.length?$model$$.collection.name.substr(0,$model$$.collection.name.length-1).toLowerCase():"");if($admin$$||$options$$.notNeedRight||
20
20
  !underscore.has($model$$.schema.paths,"id_app"))$next$$(null,$condition$$,$admin$$);else{let $allUsers$$,$selUsers$$,$selGroups$$,$visible$$=[],$allow_trang_thai$$;$e$jscomp$3_key_right$$=$email$$;$participant$$&&$participant$$.group_id&&($e$jscomp$3_key_right$$=$participant$$.group_id.toLowerCase());right.findOne({id_app:$id_app$$,email:$e$jscomp$3_key_right$$,module:$module$$},async function($ds_dang_phu_trach_error$$,$_right$jscomp$1_users$$){if($_right$jscomp$1_users$$&&$_right$jscomp$1_users$$.view){$ds_dang_phu_trach_error$$=
21
21
  {visible_to:null};underscore.has($model$$.schema.paths,"visible_to")&&($condition$$.$and||($condition$$.$and=[]),$allUsers$$={visible_to:0},$selUsers$$={visible_to:2,visible_to_users:$email$$},$selGroups$$=underscore.has($model$$.schema.paths,"visible_to_usergroups")?{visible_to:5,visible_to_usergroups:($participant$$||{}).group_id}:{visible_to:5,visible_to_users:($participant$$||{}).group_id},$visible$$.push($allUsers$$),$visible$$.push($selUsers$$),$visible$$.push($selGroups$$),$visible$$.push($ds_dang_phu_trach_error$$));
@@ -1,6 +1,6 @@
1
- 'use strict';const dmhoahonghdSchema=new Schema({id_app:{type:String,required:!0,maxlength:1024},kieu:{type:String,default:"0"},ma_hoahong:{type:String,uppercase:!0,required:!0,maxlength:32},ten_hoahong:{type:String,required:!0,maxlength:1024},mieu_ta:{type:String},chi_su_dung_cho_ct:{type:String,uppercase:!0},khong_su_dung_cho_ct:{type:String,uppercase:!0},ma_nv:{type:String,default:"",maxlength:32},ten_nv:String,ma_bp:{type:String,default:"",maxlength:1024},ten_bp:String,ma_kh:{type:String,default:"",
2
- maxlength:32},ten_kh:String,nh_kh:{type:String,default:"",maxlength:1024},ten_nh_kh:String,ma_kho:{type:String,default:"",maxlength:32},ten_kho:String,gt_tu:{type:Number,default:0},gt_den:{type:Number,default:0},vts:[],sl_toi_thieu:{type:Number,default:0},tien_hh:{type:Number,default:0},ty_le_hh:{type:Number,default:0},so_tien_max:{type:Number,default:0},hieu_luc_tu:{type:Date,required:!0},hieu_luc_den:{type:Date,required:!0},ap_dung_lan_mua_thu:{type:Number},ap_dung_lan_mua_tu_thu:{type:Number},
3
- ap_dung_lan_mua_den_thu:{type:Number},details_km:[],picture:{type:String},exfields:Schema.Types.Mixed,newsfeed:{type:Boolean,default:!0},online:{type:Boolean},offline:{type:Boolean},status:{type:Boolean,default:!0},date_created:{type:Date,default:Date.now},date_updated:{type:Date,default:Date.now},user_created:{type:String,default:""},user_updated:{type:String,default:""},ma_kh_id:{type:Schema.Types.ObjectId,ref:"customer",localField:["ma_kh"],foreignField:["ma_kh"]},ma_kho_id:{type:Schema.Types.ObjectId,
4
- ref:"dmkho",localField:["ma_kho"],foreignField:["ma_kho"]}});dmhoahonghdSchema.index({id_app:1,ma_hoahong:1,ma_kho:1,ma_kh:1,hieu_luc_tu:-1,hieu_luc_den:-1});dmhoahonghdSchema.index({ap_dung_lan_mua_thu:1});dmhoahonghdSchema.index({ap_dung_lan_mua_tu_thu:1});dmhoahonghdSchema.index({ap_dung_lan_mua_den_thu:1});dmhoahonghdSchema.index({gt_tu:1});dmhoahonghdSchema.index({gt_den:1});dmhoahonghdSchema.index({ten_kho:1});dmhoahonghdSchema.index({nh_kh:1});dmhoahonghdSchema.index({ten_nh_kh:1});dmhoahonghdSchema.index({ma_nv:1});
5
- dmhoahonghdSchema.index({ma_bp:1});dmhoahonghdSchema.index({date_updated:-1});dmhoahonghdSchema.index({date_created:-1});dmhoahonghdSchema.index({user_created:1});dmhoahonghdSchema.index({online:1});dmhoahonghdSchema.index({offline:1});dmhoahonghdSchema.index({mieu_ta:"text",ma_hoahong:"text",ten_hoahong:"text",ma_kh:"text",ten_kh:"text",nh_kh:"text",ten_nh_kh:"text",ma_kho:"text",ten_kho:"text",ma_nv:"text",ten_nv:"text",ma_bp:"text",ten_bp:"text"},{name:"dmhoahonghd_index_text"});
6
- dmhoahonghdSchema.set("toObject",{virtuals:!0});dmhoahonghdSchema.set("toJSON",{virtuals:!0});dmhoahonghdSchema.index({status:1});const model=mongoose.models.dmhoahonghd||mongoose.model("dmhoahonghd",dmhoahonghdSchema);module.exports=model;
1
+ 'use strict';const dmhoahonghdSchema=new Schema({id_app:{type:String,required:!0,maxlength:1024},kieu:{type:String,default:"0"},doi_tuong:{type:String,default:"0"},hinh_thuc_tt:{type:String,default:"0"},ma_hoahong:{type:String,uppercase:!0,required:!0,maxlength:32},ten_hoahong:{type:String,required:!0,maxlength:1024},mieu_ta:{type:String},chi_su_dung_cho_ct:{type:String,uppercase:!0},khong_su_dung_cho_ct:{type:String,uppercase:!0},ma_nv:{type:String,default:"",maxlength:32},ten_nv:String,ma_bp:{type:String,
2
+ default:"",maxlength:1024},ten_bp:String,ma_kh:{type:String,default:"",maxlength:32},ten_kh:String,nh_kh:{type:String,default:"",maxlength:1024},ten_nh_kh:String,ma_kho:{type:String,default:"",maxlength:32},ten_kho:String,gt_tu:{type:Number,default:0},gt_den:{type:Number,default:0},vts:[],sl_toi_thieu:{type:Number,default:0},tien_hh:{type:Number,default:0},ty_le_hh:{type:Number,default:0},so_tien_max:{type:Number,default:0},hieu_luc_tu:{type:Date,required:!0},hieu_luc_den:{type:Date,required:!0},
3
+ ap_dung_lan_mua_thu:{type:Number},ap_dung_lan_mua_tu_thu:{type:Number},ap_dung_lan_mua_den_thu:{type:Number},details_km:[],picture:{type:String},exfields:Schema.Types.Mixed,newsfeed:{type:Boolean,default:!0},online:{type:Boolean},offline:{type:Boolean},status:{type:Boolean,default:!0},date_created:{type:Date,default:Date.now},date_updated:{type:Date,default:Date.now},user_created:{type:String,default:""},user_updated:{type:String,default:""},ma_kh_id:{type:Schema.Types.ObjectId,ref:"customer",localField:["ma_kh"],
4
+ foreignField:["ma_kh"]},ma_kho_id:{type:Schema.Types.ObjectId,ref:"dmkho",localField:["ma_kho"],foreignField:["ma_kho"]}});dmhoahonghdSchema.index({id_app:1,ma_hoahong:1,ma_kho:1,ma_kh:1,hieu_luc_tu:-1,hieu_luc_den:-1});dmhoahonghdSchema.index({ap_dung_lan_mua_thu:1});dmhoahonghdSchema.index({ap_dung_lan_mua_tu_thu:1});dmhoahonghdSchema.index({ap_dung_lan_mua_den_thu:1});dmhoahonghdSchema.index({gt_tu:1});dmhoahonghdSchema.index({gt_den:1});dmhoahonghdSchema.index({ten_kho:1});dmhoahonghdSchema.index({nh_kh:1});
5
+ dmhoahonghdSchema.index({ten_nh_kh:1});dmhoahonghdSchema.index({ma_nv:1});dmhoahonghdSchema.index({ma_bp:1});dmhoahonghdSchema.index({date_updated:-1});dmhoahonghdSchema.index({date_created:-1});dmhoahonghdSchema.index({user_created:1});dmhoahonghdSchema.index({online:1});dmhoahonghdSchema.index({offline:1});
6
+ dmhoahonghdSchema.index({mieu_ta:"text",ma_hoahong:"text",ten_hoahong:"text",ma_kh:"text",ten_kh:"text",nh_kh:"text",ten_nh_kh:"text",ma_kho:"text",ten_kho:"text",ma_nv:"text",ten_nv:"text",ma_bp:"text",ten_bp:"text"},{name:"dmhoahonghd_index_text"});dmhoahonghdSchema.set("toObject",{virtuals:!0});dmhoahonghdSchema.set("toJSON",{virtuals:!0});dmhoahonghdSchema.index({status:1});const model=mongoose.models.dmhoahonghd||mongoose.model("dmhoahonghd",dmhoahonghdSchema);module.exports=model;
@@ -6,10 +6,10 @@ tu_gio:{type:Date},den_gio:{type:Date},so_lan:Number,diem_thuong:{type:Number,de
6
6
  const ctcpbhSchema=new global.Schema({ma_cp:{type:String,uppercase:!0,required:!0},dien_giai:{type:String,maxlength:1024},tien_cp_nt:{type:Number,default:0},tien_cp:{type:Number,default:0},line:{type:Number,default:0}}),so1Schema=new global.Schema({id_app:{type:String,required:!0,maxlength:1024},ma_dvcs:{type:String,maxlength:1024},ma_ct:{type:String,default:"SO1",required:!0,uppercase:!0,maxlength:32},ma_gd:{type:String,default:"0",maxlength:32},so_ct:{type:String,uppercase:!0,trim:!0,maxlength:32},
7
7
  ngay_ct:{type:Date,default:Date.now,required:!0},ma_nt:{type:String,required:"ma_nt is required",default:"VND",trim:!0,uppercase:!0,maxlength:32},ty_gia:{type:Number,required:!0,min:0,default:1},trang_thai:{type:String,default:"1",maxlength:32},ma_kh:{type:String,uppercase:!0,maxlength:32},ten_kh:String,of_user:{type:String,maxlength:128},ma_kho:{type:String,uppercase:!0,maxlength:32},ten_kho:String,ten_nguoi_nhan:{type:String,maxlength:1024},dien_thoai:{type:String,maxlength:1024},email:{type:String,
8
8
  maxlength:1024},dia_chi:{type:String,maxlength:1024},xa_phuong:{type:String,maxlength:1024},quan_huyen:{type:String,maxlength:1024},tinh_thanh:{type:String,maxlength:1024},quoc_gia:{type:String,default:"VN",maxlength:2},post_code:{type:String,maxlength:1024},location:global.Schema.Types.Mixed,note_ship:{type:String,maxlength:1024},pt_giao_hang:{type:String,default:"1",maxlength:1024},dich_vu_giao_hang:{type:String,maxlength:1024},trang_thai_giao_hang:{type:String,maxlength:1024},ma_kiem_soat:{type:String,
9
- maxlength:1024},ly_do_that_bai:{type:String,maxlength:1024},ly_do_huy:{type:String,maxlength:1024},ma_nv:String,ma_kh_hoa_hong:{type:String,uppercase:!0,maxlength:32},ty_le_hoa_hong:Number,tien_hoa_hong:Number,tk_no_hoa_hong:String,tk_co_hoa_hong:String,tu_tinh_hoa_hong:Boolean,ngay_giao_hang:Date,ngay_hoan_thanh:Date,ngay_tra_lai:Date,user_nv_giao_hang:{type:String,maxlength:128},vi_tri_giao_hang:global.Schema.Types.Mixed,dien_giai:{type:String,default:"",maxlength:1024},exfields:global.Schema.Types.Mixed,
10
- stt_rec:String,ma_dt:{type:String,uppercase:!0,default:"",maxlength:32},profile:global.Schema.Types.Mixed,discout_code:{type:String,maxlength:32},ty_le_ck_hd:{type:Number,default:0},tien_ck_hd:{type:Number,default:0},ma_freeship:String,tien_freeship:Number,tien_phi_vc:Number,sender_email:{type:String,maxlength:128},id_trans:{type:String,maxlength:1024},paymentByPoints:{type:Number,default:0},exchangeRate:Number,tien_paymentByPoints:{type:Number,default:0},evouchers:[global.Schema.Types.Mixed],tien_evoucher:Number,
11
- tk_no_evoucher:String,tk_co_evoucher:String,da_tra:{type:Number,default:0},tien_con_lai:{type:Number,default:0},pt_thanh_toan:{type:String,maxlength:1024},note_payment:{type:String,maxlength:1024},virtual_payment_client_url:{type:String,maxlength:2024},again_link:{type:String,maxlength:2024},payment_service:String,payment_id:String,payment_getway_lang:{type:String,maxlength:1024},details:{type:[detailSchema]},ctcpbhs:[ctcpbhSchema],shared:Boolean,gio:Number,ngay:Number,thang:Number,quy:Number,nam:Number,
12
- online:Boolean,status:{type:Boolean,default:!0},date_created:{type:Date,default:Date.now},date_updated:{type:Date,default:Date.now},user_created:{type:String,default:""},user_updated:{type:String,default:""},visible_to:{type:Number,default:0},visible_to_users:[String]});so1Schema.validate={ma_nt:validator.existsNt,ngay_ct:validator.unlockBook,ma_kh:validator.existsKh,ma_kho:validVt.existsKho};so1Schema.index({id_app:1,ma_dvcs:1,so_ct:-1,ngay_ct:-1});
13
- so1Schema.index({dien_giai:"text",so_ct:"text",ma_kh:"text",ten_kh:"text",ma_kho:"text",ten_kho:"text"},{name:"so1_index_text"});so1Schema.index({ma_ct:1});so1Schema.index({ma_kh:1});so1Schema.index({ma_kho:1});so1Schema.index({ma_nv:1});so1Schema.index({"details.ma_vt":1});so1Schema.index({trang_thai:1});so1Schema.index({user_nv_giao_hang:1});so1Schema.index({user_created:1,date_created:-1});so1Schema.index({date_updated:-1});so1Schema.index({gio:1});so1Schema.index({ngay:1});so1Schema.index({thang:1});
14
- so1Schema.index({quy:1});so1Schema.index({nam:-1});so1Schema.index({status:1});so1Schema.index({online:1});so1Schema.index({user_created:1,visible_to:1,visible_to_users:1});so1Schema.pre("save",function($next$$){let $ngay_ct$$=moment(this.ngay_ct);this.gio=$ngay_ct$$.get("hours");this.ngay=$ngay_ct$$.get("dates");this.quy=$ngay_ct$$.get("quarters");this.thang=$ngay_ct$$.get("months")+1;this.nam=$ngay_ct$$.get("year");$next$$()});
15
- const model=global.mongoose.models.so1||global.mongoose.model("so1",so1Schema);model.referenceKeys={_id:[{model:"socai",key:"id_ct_goc",error:"Phi\u1ebfu n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c ho\u1ea1ch to\u00e1n"}]};module.exports=model;
9
+ maxlength:1024},ly_do_that_bai:{type:String,maxlength:1024},ly_do_huy:{type:String,maxlength:1024},ma_nv:String,user_nv:String,ma_kh_hoa_hong:{type:String,uppercase:!0,maxlength:32},ty_le_hoa_hong:Number,tien_hoa_hong:Number,tk_no_hoa_hong:String,tk_co_hoa_hong:String,tu_tinh_hoa_hong:Boolean,chuyen_ngay:Boolean,da_chuyen_hoa_hong:Boolean,user_gt:String,introduce_code:String,ma_kh_hoa_hong_gt:{type:String,uppercase:!0,maxlength:32},ty_le_hoa_hong_gt:Number,tien_hoa_hong_gt:Number,tk_no_hoa_hong_gt:String,
10
+ tk_co_hoa_hong_gt:String,chuyen_ngay_gt:Boolean,da_chuyen_hoa_hong_gt:Boolean,ngay_giao_hang:Date,ngay_hoan_thanh:Date,ngay_tra_lai:Date,user_nv_giao_hang:{type:String,maxlength:128},vi_tri_giao_hang:global.Schema.Types.Mixed,dien_giai:{type:String,default:"",maxlength:1024},exfields:global.Schema.Types.Mixed,stt_rec:String,ma_dt:{type:String,uppercase:!0,default:"",maxlength:32},profile:global.Schema.Types.Mixed,discout_code:{type:String,maxlength:32},ty_le_ck_hd:{type:Number,default:0},tien_ck_hd:{type:Number,
11
+ default:0},ma_freeship:String,tien_freeship:Number,tien_phi_vc:Number,sender_email:{type:String,maxlength:128},id_trans:{type:String,maxlength:1024},paymentByPoints:{type:Number,default:0},exchangeRate:Number,tien_paymentByPoints:{type:Number,default:0},evouchers:[global.Schema.Types.Mixed],tien_evoucher:Number,tk_no_evoucher:String,tk_co_evoucher:String,da_tra:{type:Number,default:0},tien_con_lai:{type:Number,default:0},pt_thanh_toan:{type:String,maxlength:1024},note_payment:{type:String,maxlength:1024},
12
+ virtual_payment_client_url:{type:String,maxlength:2024},again_link:{type:String,maxlength:2024},payment_service:String,payment_id:String,payment_getway_lang:{type:String,maxlength:1024},details:{type:[detailSchema]},ctcpbhs:[ctcpbhSchema],shared:Boolean,gio:Number,ngay:Number,thang:Number,quy:Number,nam:Number,online:Boolean,status:{type:Boolean,default:!0},date_created:{type:Date,default:Date.now},date_updated:{type:Date,default:Date.now},user_created:{type:String,default:""},user_updated:{type:String,
13
+ default:""},visible_to:{type:Number,default:0},visible_to_users:[String]});so1Schema.validate={ma_nt:validator.existsNt,ngay_ct:validator.unlockBook,ma_kh:validator.existsKh,ma_kho:validVt.existsKho};so1Schema.index({id_app:1,ma_dvcs:1,so_ct:-1,ngay_ct:-1});so1Schema.index({dien_giai:"text",so_ct:"text",ma_kh:"text",ten_kh:"text",ma_kho:"text",ten_kho:"text"},{name:"so1_index_text"});so1Schema.index({ma_ct:1});so1Schema.index({ma_kh:1});so1Schema.index({ma_kho:1});so1Schema.index({ma_nv:1});so1Schema.index({"details.ma_vt":1});
14
+ so1Schema.index({trang_thai:1});so1Schema.index({user_nv_giao_hang:1});so1Schema.index({user_created:1,date_created:-1});so1Schema.index({date_updated:-1});so1Schema.index({gio:1});so1Schema.index({ngay:1});so1Schema.index({thang:1});so1Schema.index({quy:1});so1Schema.index({nam:-1});so1Schema.index({status:1});so1Schema.index({online:1});so1Schema.index({user_created:1,visible_to:1,visible_to_users:1});
15
+ so1Schema.pre("save",function($next$$){let $ngay_ct$$=moment(this.ngay_ct);this.gio=$ngay_ct$$.get("hours");this.ngay=$ngay_ct$$.get("dates");this.quy=$ngay_ct$$.get("quarters");this.thang=$ngay_ct$$.get("months")+1;this.nam=$ngay_ct$$.get("year");$next$$()});const model=global.mongoose.models.so1||global.mongoose.model("so1",so1Schema);model.referenceKeys={_id:[{model:"socai",key:"id_ct_goc",error:"Phi\u1ebfu n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c ho\u1ea1ch to\u00e1n"}]};module.exports=model;
@@ -4,10 +4,10 @@ default:""}});transactionSchema.index({id_app:1});transactionSchema.index({id_ct
4
4
  model.on("index",async function($err$$){if($err$$)return console.error("Product index error",$err$$);console.log("transaction indexing complete")});model.verifyTrans=async($data$$,$trans$$)=>await wallet.verifySignature($data$$.id_app,$data$$.sender_email,{id_app:$data$$.id_app,sender_email:$data$$.sender_email,receiver_email:$data$$.receiver_email,amount:$data$$.amount},$trans$$.sender.signature);
5
5
  model.createTransId=($id_app$$,$sender_email$$,$receiver_email$$,$amount$$)=>{let $timestamp$$=(new Date).getTime();return cryptoJs.SHA256($id_app$$+$sender_email$$+$receiver_email$$+$amount$$.toString()+$timestamp$$).toString()};
6
6
  model.createTrans=async $data$$=>{$data$$.otherData||($data$$.otherData={});if($data$$.receiver_email===$data$$.sender_email||!$data$$.amount)throw"Ng\u01b0\u1eddi nh\u1eadn v\u00e0 ng\u01b0\u1eddi g\u1eedi ph\u1ea3i kh\u00e1c nhau v\u00e0 s\u1ed1 l\u01b0\u1ee3ng ph\u1ea3i l\u1edbn h\u01a1n 0";let $id_trans$$=model.createTransId($data$$.id_app,$data$$.sender_email,$data$$.receiver_email,$data$$.amount),$signature$$=await wallet.sign($data$$.id_app,$data$$.sender_email,{id_app:$data$$.id_app,sender_email:$data$$.sender_email,
7
- receiver_email:$data$$.receiver_email,amount:$data$$.amount}),$trans$$=new model({id_app:$data$$.id_app,id_trans:$id_trans$$,sender:{email:$data$$.sender_email,signature:$signature$$},receiver:{email:$data$$.receiver_email},amount:$data$$.amount,description:$data$$.description,id_ct:$data$$.otherData.id_ct,so_ct:$data$$.otherData.so_ct,ngay_ct:$data$$.otherData.ngay_ct,ma_ct:$data$$.otherData.ma_ct,tk_no:$data$$.otherData.tk_no,tk_co:$data$$.otherData.tk_co});await new Promise(($resolve$$,$reject$$)=>
8
- {$trans$$.save(async($e_kh_no_users_will_receive$$,$rs$$)=>{if($e_kh_no_users_will_receive$$)return console.log($e_kh_no_users_will_receive$$),$reject$$(Error($e_kh_no_users_will_receive$$.message));if($rs$$.tk_no&&$rs$$.tk_co){$e_kh_no_users_will_receive$$=await global.getModel("customer").findOne({id_app:$rs$$.id_app,of_user:$rs$$.receiver.email}).lean();$kh_co_notificationData_title$$=await global.getModel("customer").findOne({id_app:$rs$$.id_app,of_user:$rs$$.sender.email}).lean();let $ma_dvcs$$=
9
- await global.getModel("dvcs").findOne({id_app:$rs$$.id_app}).lean(),$master$$=$rs$$.toObject();$master$$.dien_giai=$master$$.description;$master$$.ma_dvcs=(($ma_dvcs$$||{})._id||"").toString();(new PostSocai($master$$,[{tk_no:$rs$$.tk_no,tk_co:$rs$$.tk_co,tien_nt:$rs$$.amount,tien:$rs$$.amount,ma_nt:"VND",ty_gia:1,ma_kh_no:($e_kh_no_users_will_receive$$||{}).ma_kh,ma_kh_co:($kh_co_notificationData_title$$||{}).ma_kh}])).run($e$$=>{$e$$&&console.error($e$$)})}$e_kh_no_users_will_receive$$=[$rs$$.sender.email,
10
- $rs$$.receiver.email];var $kh_co_notificationData_title$$=`${$data$$.sender_email} \u0111\u00e3 chuy\u1ec3n cho ${$data$$.receiver_email} ${$data$$.amount} \u0111i\u1ec3m v\u1edbi n\u1ed9i dung: ${$data$$.description}`;if($data$$.sender_email===$data$$.id_app||$data$$.receiver_email===$data$$.id_app)$kh_co_notificationData_title$$=`${$data$$.description}`;$kh_co_notificationData_title$$={_id:$rs$$._id,id_app:$data$$.id_app,title:$kh_co_notificationData_title$$,body:$kh_co_notificationData_title$$,
7
+ receiver_email:$data$$.receiver_email,amount:$data$$.amount}),$trans$$=new model({id_app:$data$$.id_app,id_trans:$id_trans$$,sender:{email:$data$$.sender_email,signature:$signature$$},receiver:{email:$data$$.receiver_email},amount:$data$$.amount,description:$data$$.description,id_ct:$data$$.otherData.id_ct,so_ct:$data$$.otherData.so_ct,ngay_ct:$data$$.otherData.ngay_ct,ma_ct:$data$$.otherData.ma_ct,tk_no:$data$$.otherData.tk_no,tk_co:$data$$.otherData.tk_co});return await new Promise(($resolve$$,
8
+ $reject$$)=>{$trans$$.save(async($e_kh_no_users_will_receive$$,$rs$$)=>{if($e_kh_no_users_will_receive$$)return console.log($e_kh_no_users_will_receive$$),$reject$$(Error($e_kh_no_users_will_receive$$.message));if($rs$$.tk_no&&$rs$$.tk_co){$e_kh_no_users_will_receive$$=await global.getModel("customer").findOne({id_app:$rs$$.id_app,of_user:$rs$$.receiver.email}).lean();$kh_co_notificationData_title$$=await global.getModel("customer").findOne({id_app:$rs$$.id_app,of_user:$rs$$.sender.email}).lean();
9
+ let $ma_dvcs$$=await global.getModel("dvcs").findOne({id_app:$rs$$.id_app}).lean(),$master$$=$rs$$.toObject();$master$$.dien_giai=$master$$.description;$master$$.ma_dvcs=(($ma_dvcs$$||{})._id||"").toString();(new PostSocai($master$$,[{tk_no:$rs$$.tk_no,tk_co:$rs$$.tk_co,tien_nt:$rs$$.amount,tien:$rs$$.amount,ma_nt:"VND",ty_gia:1,ma_kh_no:($e_kh_no_users_will_receive$$||{}).ma_kh,ma_kh_co:($kh_co_notificationData_title$$||{}).ma_kh}])).run($e$$=>{$e$$&&console.error($e$$)})}$e_kh_no_users_will_receive$$=
10
+ [$rs$$.sender.email,$rs$$.receiver.email];var $kh_co_notificationData_title$$=`${$data$$.sender_email} \u0111\u00e3 chuy\u1ec3n cho ${$data$$.receiver_email} ${$data$$.amount} \u0111i\u1ec3m v\u1edbi n\u1ed9i dung: ${$data$$.description}`;if($data$$.sender_email===$data$$.id_app||$data$$.receiver_email===$data$$.id_app)$kh_co_notificationData_title$$=`${$data$$.description}`;$kh_co_notificationData_title$$={_id:$rs$$._id,id_app:$data$$.id_app,title:$kh_co_notificationData_title$$,body:$kh_co_notificationData_title$$,
11
11
  code:"transaction",event:"new",action:"NEW"};global.getModel("app").emitEvent($data$$.id_app,`${$kh_co_notificationData_title$$.code}:${$kh_co_notificationData_title$$.event}`,$kh_co_notificationData_title$$,null,$e_kh_no_users_will_receive$$,!0);$resolve$$($rs$$.toObject())})})};model.getTrans=async $id_trans$$=>new Promise($resolve$$=>{model.findOne({id_trans:$id_trans$$},($e$$,$rs$$)=>{$resolve$$($rs$$)})});
12
12
  model.deleteTrans=async $id_trans$$=>{$id_trans$$="string"===typeof $id_trans$$?{id_trans:$id_trans$$}:{...$id_trans$$};console.log("delete transaction",$id_trans$$);await model.deleteMany($id_trans$$)};
13
13
  model.balance=async($email$$,$date_to$$)=>{$date_to$$||($date_to$$=new Date);$date_to$$=moment($date_to$$).endOf("date").toDate();return(await model.find({date_created:{$lte:$date_to$$},$or:[{"sender.email":$email$$},{"receiver.email":$email$$}]})).map($tran$$=>$tran$$.sender.email===$email$$?0-$tran$$.amount:$tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0)};
@@ -18,8 +18,8 @@ User.initSocket=$redisAdapter_server$$=>{global.socketContainer.socketIO=require
18
18
  if($_token$$){$socket$$.join($_token$$.email);let $clientIO$$=await global.socketContainer.loadConnectionId();$clientIO$$[$socket$$.id]={token:$msg$jscomp$0$$.token,email:$_token$$.email};global.socketContainer.saveConnectionId($clientIO$$);global.alertNotification($_token$$.email);global.alertMessage($_token$$.email);global.socketContainer.socketIO.to($socket$$.id).emit("login",{user:$_token$$.email,success:!0});$socket$$.on("offer",function($msg$$){$msg$$.from=$_token$$.email;User.socketSendTo($msg$$.to,
19
19
  "offer",$msg$$)});$socket$$.on("answer",function($msg$$){$msg$$.from=$_token$$.email;User.socketSendTo($msg$$.to,"answer",$msg$$)});$socket$$.on("candidate",function($msg$$){$msg$$.from=$_token$$.email;User.socketSendTo($msg$$.to,"candidate",$msg$$)});$socket$$.on("leave",function($msg$$){$msg$$.from=$_token$$.email;User.socketSendTo($msg$$.to,"leave",$msg$$)})}else global.socketContainer.socketIO.to($socket$$.id).emit("login",{user:$msg$jscomp$0$$.email,success:!1,message:"Token is not exists"})}});
20
20
  $socket$$.on("disconnect",async function(){let $clientIO$$=await global.socketContainer.loadConnectionId(),$client$$=$clientIO$$[$socket$$.id];$client$$&&$socket$$.leave($client$$.email);delete $clientIO$$[$socket$$.id];global.socketContainer.saveConnectionId($clientIO$$)})})};User.teststrengthPassword=$pwString$$=>5<$pwString$$.length&&/[A-Z]+/.test($pwString$$)&&/[a-z]+/.test($pwString$$)&&/[0-9]+/.test($pwString$$);User.teststrengthPin=$pin$$=>4===$pin$$.length&&/^-?\d+$/.test($pin$$);
21
- User.emitEvent=async function($email$$,$event$$,$_data_obj_send$$,$push$$,$exclude_token$$){console.log("emit event",$email$$,$event$$,$_data_obj_send$$);if($email$$){if("object"===typeof $_data_obj_send$$){var $data$$=Object.assign({},$_data_obj_send$$);$data$$.__event=$event$$}else $data$$=$_data_obj_send$$;if($data$$.body&&0<=$data$$.body.indexOf("{")&&0<=$data$$.body.indexOf("}"))try{var $cipher_unsub_file_link_unsub$$=JSON.parse($data$$.body);$cipher_unsub_file_link_unsub$$.data&&(0<=$cipher_unsub_file_link_unsub$$.data.indexOf("data:image")?
22
- $data$$.body="Image":$data$$.body="File")}catch($e$$){console.error($e$$)}if($data$$.email_content&&!$data$$.not_send_email&&$data$$.title){var $encrypted_unsub_unsub$$;0!=$data$$.allow_unsubcribe&&$data$$.id_app&&($encrypted_unsub_unsub$$=await global.getModel("subscribe").findOne({id_app:$data$$.id_app,email:$email$$,unsubcribe:!0}).lean());$encrypted_unsub_unsub$$||($_data_obj_send$$={...$data$$},$_data_obj_send$$.id_app&&($cipher_unsub_file_link_unsub$$=crypto.createCipher("aes192",configs.cryptoPassword||
21
+ User.emitEvent=async function($email$$,$event$$,$_data_obj_send$$,$push$$,$exclude_token$$){if($email$$){if("object"===typeof $_data_obj_send$$){var $data$$=Object.assign({},$_data_obj_send$$);$data$$.__event=$event$$}else $data$$=$_data_obj_send$$;if($data$$.body&&0<=$data$$.body.indexOf("{")&&0<=$data$$.body.indexOf("}"))try{var $cipher_unsub_file_link_unsub$$=JSON.parse($data$$.body);$cipher_unsub_file_link_unsub$$.data&&(0<=$cipher_unsub_file_link_unsub$$.data.indexOf("data:image")?$data$$.body=
22
+ "Image":$data$$.body="File")}catch($e$$){console.error($e$$)}if($data$$.email_content&&!$data$$.not_send_email&&$data$$.title){var $encrypted_unsub_unsub$$;0!=$data$$.allow_unsubcribe&&$data$$.id_app&&($encrypted_unsub_unsub$$=await global.getModel("subscribe").findOne({id_app:$data$$.id_app,email:$email$$,unsubcribe:!0}).lean());$encrypted_unsub_unsub$$||($_data_obj_send$$={...$data$$},$_data_obj_send$$.id_app&&($cipher_unsub_file_link_unsub$$=crypto.createCipher("aes192",configs.cryptoPassword||
23
23
  "PVT@1"),$encrypted_unsub_unsub$$=$cipher_unsub_file_link_unsub$$.update(JSON.stringify({id_app:$data$$.id_app,email:$email$$}),"utf8","hex"),$encrypted_unsub_unsub$$+=$cipher_unsub_file_link_unsub$$.final("hex"),$cipher_unsub_file_link_unsub$$=`${configs.api_url}/public/unsubscribe/${$encrypted_unsub_unsub$$}`,0!=$data$$.allow_unsubcribe&&($_data_obj_send$$.email_content=`${$_data_obj_send$$.email_content}
24
24
  <p style="text-align:center;margin-top:15px">
25
25
  <div>\u0110\u00e2y l\u00e0 th\u01b0 t\u1ef1 \u0111\u1ed9ng \u0111\u01b0\u1ee3c t\u1ea1o t\u1eeb danh s\u00e1ch \u0111\u0103ng k\u00fd c\u1ee7a ch\u00fang t\u00f4i. Do \u0111\u00f3, xin \u0111\u1eebng tr\u1ea3 l\u1eddi th\u01b0 n\u00e0y.</div>
@@ -1,51 +1,61 @@
1
- 'use strict';const PostBook=require("../../libs/post-book"),options=global.getModel("options"),PostSocai=require("../../libs/post-socai"),User=global.getModel("user"),Sokho=global.getModel("sokho"),Socaitmp=global.getModel("socai"),Sodiemthuong=global.getModel("sodiemthuong"),transaction=global.getModel("transaction"),Evoucher=global.getModel("evoucher"),dvcs=global.getModel("dvcs"),dmvt=global.getModel("dmvt"),dmtt=global.getModel("dmtt"),dmcpmh=global.getModel("dmcpmh"),dmkho=global.getModel("dmkho"),
2
- customer=global.getModel("customer"),dmdt=global.getModel("dmdt"),dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),trangthai=global.getModel("trangthai"),currency=global.getModel("currency"),ptthanhtoan=global.getModel("ptthanhtoan"),dmdiemthuong=global.getModel("dmdiemthuong"),model=global.getModel("so1"),pt1=global.getModel("pt1"),controller=require("../../controllers/controller"),async=require("async"),ma_ct="SO1",ckdiem=require("../../libs/ckdiem"),blockchainconnect=require("../../libs/blockchainconnect"),
3
- moment=require("moment"),numeral=require("numeral"),App=global.getModel("app"),Introducer=global.getModel("introducer"),getGiaBan=require("../../libs/getGiabanAsync"),dmchietkhauhd=global.getModel("dmchietkhauhd"),dmkhuyenmaihd=global.getModel("dmkhuyenmaihd"),underscore=require("underscore"),hoahonghd=async $obj$$=>{if($obj$$.tu_tinh_hoa_hong){$obj$$.tien_hoa_hong=0;$obj$$.ty_le_hoa_hong=0;$obj$$.ma_kh_hoa_hong="";if($obj$$.ma_nv){var $nv_t_tien_nt_t_tt_nt$$=await global.getModel("dmnv").findOne({id_app:$obj$$.id_app,
4
- ma_nv:$obj$$.ma_nv}).lean();$nv_t_tien_nt_t_tt_nt$$&&($obj$$.ma_kh_hoa_hong=$nv_t_tien_nt_t_tt_nt$$.ma_kh)}if($obj$$.ma_kh_hoa_hong){$nv_t_tien_nt_t_tt_nt$$=$obj$$.details.csum("tien_hang_nt");var $ckhds_query_t_ck_nt$$=$obj$$.details.csum("tien_ck_nt");$nv_t_tien_nt_t_tt_nt$$=$nv_t_tien_nt_t_tt_nt$$-$ckhds_query_t_ck_nt$$-($obj$$.tien_ck_hd||0);$ckhds_query_t_ck_nt$$={id_app:$obj$$.id_app,gt_tu:{$lte:$nv_t_tien_nt_t_tt_nt$$},ma_kho:{$in:[void 0,null,"",$obj$$.ma_kho]},kieu:{$in:["0",null,void 0]}};
5
- $ckhds_query_t_ck_nt$$.$and=[{$or:[{gt_den:{$in:[0,void 0,null]}},{gt_den:{$gte:$nv_t_tien_nt_t_tt_nt$$}}]}];var $ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$=moment($obj$$.ngay_ct).startOf("date").toDate();var $hieu_luc_tu_i_q_ma_nv$$={$lte:moment($obj$$.ngay_ct).endOf("date").toDate()};$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$={$gte:$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$};$ckhds_query_t_ck_nt$$.hieu_luc_tu=$hieu_luc_tu_i_q_ma_nv$$;$ckhds_query_t_ck_nt$$.hieu_luc_den=$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$;$hieu_luc_tu_i_q_ma_nv$$=
6
- {$in:[void 0,null,"",$obj$$.ma_nv]};$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$={$in:[void 0,null,""]};if($obj$$.ma_kh){var $kh_lan_mua_thu$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{nh_kh:1});$kh_lan_mua_thu$$&&$kh_lan_mua_thu$$.nh_kh&&($ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$={$in:[void 0,null,"",$kh_lan_mua_thu$$.nh_kh]});($kh_lan_mua_thu$$=await model.countDocuments({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,trang_thai:{$in:["5","6"]}}))||($kh_lan_mua_thu$$=0);$kh_lan_mua_thu$$+=1}$ckhds_query_t_ck_nt$$.$or=
7
- [{$and:[{ma_nv:$hieu_luc_tu_i_q_ma_nv$$},{nh_kh:{$in:["",null,void 0]}}]},{$and:[{nh_kh:$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$},{ma_kh:{$in:["",null,void 0]}}]}];$ckhds_query_t_ck_nt$$.ap_dung_lan_mua_thu={$in:[null,void 0,0,void 0]};$ckhds_query_t_ck_nt$$=await global.getModel("dmhoahonghd").find($ckhds_query_t_ck_nt$$).sort({gt_tu:-1,tien_ck:-1,ty_le_hh:-1,ma_nv:-1,nh_kh:-1,hieu_luc_tu:-1}).lean();$ckhds_query_t_ck_nt$$=$ckhds_query_t_ck_nt$$.filter($cs$$=>$cs$$.chi_su_dung_cho_ct?0<=$cs$$.chi_su_dung_cho_ct.indexOf($obj$$.ma_ct):
8
- $cs$$.khong_su_dung_cho_ct?0>$cs$$.khong_su_dung_cho_ct.indexOf($obj$$.ma_ct):!0);if(0<$ckhds_query_t_ck_nt$$.length)for($hieu_luc_tu_i_q_ma_nv$$=0;$hieu_luc_tu_i_q_ma_nv$$<$ckhds_query_t_ck_nt$$.length;$hieu_luc_tu_i_q_ma_nv$$++){$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$=$ckhds_query_t_ck_nt$$[$hieu_luc_tu_i_q_ma_nv$$];$kh_lan_mua_thu$$=$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.sl_toi_thieu||0;let $sl_dap_ung$$=0;$kh_lan_mua_thu$$&&$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.vts&&0<$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.vts.length&&
9
- $ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.vts.forEach($vt$$=>{var $ds_tien$$=$obj$$.details.filter($d$$=>$d$$.ma_vt===$vt$$.ma_vt&&(!$vt$$.ma_tt1||$vt$$.ma_tt1===$d$$.ma_tt1)&&(!$vt$$.ma_tt2||$vt$$.ma_tt2===$d$$.ma_tt2)&&(!$vt$$.ma_tt3||$vt$$.ma_tt3===$d$$.ma_tt3));if(0!=$ds_tien$$.length){var $so_luong$$=$ds_tien$$.map($d$$=>$d$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$ds_tien$$=$ds_tien$$.map($d$$=>($d$$.tien_hang_nt||0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$vt$$.sl_tu&&$so_luong$$<
10
- $vt$$.sl_tu||$vt$$.sl_den&&$so_luong$$>$vt$$.sl_den||$vt$$.gt_tu&&$ds_tien$$<$vt$$.gt_tu||$vt$$.gt_den&&$ds_tien$$>$vt$$.gt_den||($sl_dap_ung$$+=1)}});if($kh_lan_mua_thu$$<=$sl_dap_ung$$){$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.tien_hh?($obj$$.tien_hoa_hong=$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.tien_hh,$obj$$.ty_le_hoa_hong=0):($obj$$.ty_le_hoa_hong=$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.ty_le_hh||0,$obj$$.tien_hoa_hong=Math.roundBy($nv_t_tien_nt_t_tt_nt$$*$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.ty_le_hh/
11
- 100,0));$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.so_tien_max&&($obj$$.tien_hoa_hong=Math.min($ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.so_tien_max,$obj$$.tien_hoa_hong));break}}}}},khuyenmaihd=async $obj$$=>{if($obj$$.details&&$obj$$.online){var $ckhds$jscomp$1_query$jscomp$1_t_tien_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_hang_nt");if(0!==$ckhds$jscomp$1_query$jscomp$1_t_tien_nt$$){var $hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh_t_ck_nt$jscomp$1_t_tt_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_ck_nt");
12
- $hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh_t_ck_nt$jscomp$1_t_tt_nt$$=$ckhds$jscomp$1_query$jscomp$1_t_tien_nt$$-$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh_t_ck_nt$jscomp$1_t_tt_nt$$;$obj$$.details=$obj$$.details.filter($d$$=>"khuyenmaihd"!=$d$$.km_yn_for);$ckhds$jscomp$1_query$jscomp$1_t_tien_nt$$={id_app:$obj$$.id_app,gt_tu:{$lte:$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh_t_ck_nt$jscomp$1_t_tt_nt$$},ma_kho:{$in:[void 0,null,"",$obj$$.ma_kho]}};$ckhds$jscomp$1_query$jscomp$1_t_tien_nt$$.$and=[{$or:[{gt_den:{$in:[0,
13
- void 0,null]}},{gt_den:{$gte:$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh_t_ck_nt$jscomp$1_t_tt_nt$$}}]}];var $ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$=moment($obj$$.ngay_ct).startOf("date").toDate();$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh_t_ck_nt$jscomp$1_t_tt_nt$$={$lte:moment($obj$$.ngay_ct).endOf("date").toDate()};$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$={$gte:$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$};$ckhds$jscomp$1_query$jscomp$1_t_tien_nt$$.hieu_luc_tu=
14
- $hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh_t_ck_nt$jscomp$1_t_tt_nt$$;$ckhds$jscomp$1_query$jscomp$1_t_tien_nt$$.hieu_luc_den=$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$;$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh_t_ck_nt$jscomp$1_t_tt_nt$$={$in:[void 0,null,"",$obj$$.ma_kh]};$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$={$in:[void 0,null,""]};if($obj$$.ma_kh){var $kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},
15
- {nh_kh:1});$kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$&&$kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$.nh_kh&&($ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$={$in:[void 0,null,"",$kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$.nh_kh]});($kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$=await model.countDocuments({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,trang_thai:{$in:["5","6"]}}))||($kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$=0);$kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$+=
16
- 1}$ckhds$jscomp$1_query$jscomp$1_t_tien_nt$$.$or=[{$and:[{ma_kh:$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh_t_ck_nt$jscomp$1_t_tt_nt$$},{nh_kh:{$in:["",null,void 0]}}]},{$and:[{nh_kh:$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$},{ma_kh:{$in:["",null,void 0]}}]}];$ckhds$jscomp$1_query$jscomp$1_t_tien_nt$$.ap_dung_lan_mua_thu={$in:[null,void 0,0,void 0]};$ckhds$jscomp$1_query$jscomp$1_t_tien_nt$$.online=!0;$ckhds$jscomp$1_query$jscomp$1_t_tien_nt$$=await dmkhuyenmaihd.find($ckhds$jscomp$1_query$jscomp$1_t_tien_nt$$).sort({stt_uu_tien:1,
17
- gt_tu:-1,ma_kh:-1,nh_kh:-1,hieu_luc_tu:-1}).lean();for($hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh_t_ck_nt$jscomp$1_t_tt_nt$$=0;$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh_t_ck_nt$jscomp$1_t_tt_nt$$<$ckhds$jscomp$1_query$jscomp$1_t_tien_nt$$.length;$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh_t_ck_nt$jscomp$1_t_tt_nt$$++)if(($ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$=$ckhds$jscomp$1_query$jscomp$1_t_tien_nt$$[$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_kh_t_ck_nt$jscomp$1_t_tt_nt$$])&&$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.details_km&&
18
- 0<$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.details_km.length){$kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$=$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.sl_toi_thieu||0;let $sl_dap_ung$$=0;$kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$&&$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.vts&&0<$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.vts.length&&$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.vts.forEach($vt$$=>
1
+ 'use strict';const PostBook=require("../../libs/post-book"),options=global.getModel("options"),PostSocai=require("../../libs/post-socai"),User=global.getModel("user"),Sokho=global.getModel("sokho"),Socaitmp=global.getModel("socai"),transaction=global.getModel("transaction"),Evoucher=global.getModel("evoucher"),dvcs=global.getModel("dvcs"),dmvt=global.getModel("dmvt"),dmtt=global.getModel("dmtt"),dmcpmh=global.getModel("dmcpmh"),dmkho=global.getModel("dmkho"),customer=global.getModel("customer"),dmdt=
2
+ global.getModel("dmdt"),dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),trangthai=global.getModel("trangthai"),currency=global.getModel("currency"),ptthanhtoan=global.getModel("ptthanhtoan"),dmdiemthuong=global.getModel("dmdiemthuong"),model=global.getModel("so1"),pt1=global.getModel("pt1"),controller=require("../../controllers/controller"),async=require("async"),ma_ct="SO1",ckdiem=require("../../libs/ckdiem"),blockchainconnect=require("../../libs/blockchainconnect"),moment=require("moment"),
3
+ numeral=require("numeral"),App=global.getModel("app"),Introducer=global.getModel("introducer"),getGiaBan=require("../../libs/getGiabanAsync"),dmchietkhauhd=global.getModel("dmchietkhauhd"),dmkhuyenmaihd=global.getModel("dmkhuyenmaihd"),underscore=require("underscore"),{DirectSecp256k1HdWallet}=require("@cosmjs/proto-signing"),spend=async($appInfo$$,$receiver_user$$,$receiver_address$$,$amount$$,$denom$$,$memo$$,$introduce_code$$,$sub_action$$="")=>{try{await blockchainconnect.spend($appInfo$$._id,
4
+ $appInfo$$.wallet_token,$appInfo$$.wallet_address,$receiver_address$$,{amount:$amount$$,denom:$denom$$,memo:$memo$$,action:"bonus",introduce_code:$introduce_code$$,sub_action:$sub_action$$})}catch($e$$){console.error("Error send coin",$e$$,$receiver_user$$,$receiver_address$$,$amount$$,$denom$$,$memo$$)}},hoahonghdgt=async $obj$$=>{if(!$obj$$.da_chuyen_hoa_hong_gt){$obj$$.tien_hoa_hong_gt=0;$obj$$.ty_le_hoa_hong_gt=0;$obj$$.ma_kh_hoa_hong_gt="";if(!$obj$$.user_gt){var $intro_kh_t_tien_nt_t_tt_nt$$=
5
+ await global.getModel("introducer").findOne({id_app:$obj$$.id_app,be_introduced:$obj$$.user_created});$intro_kh_t_tien_nt_t_tt_nt$$&&($obj$$.user_gt=$intro_kh_t_tien_nt_t_tt_nt$$.be_introduced_by,$obj$$.introduce_code=$intro_kh_t_tien_nt_t_tt_nt$$.introduce_code)}if($obj$$.user_gt){if($intro_kh_t_tien_nt_t_tt_nt$$=await global.getModel("customer").findOne({id_app:$obj$$.id_app,of_user:$obj$$.user_gt}))$obj$$.ma_kh_hoa_hong_gt=$intro_kh_t_tien_nt_t_tt_nt$$.ma_kh;$intro_kh_t_tien_nt_t_tt_nt$$=$obj$$.details.csum("tien_hang_nt");
6
+ var $ckhds_query_t_ck_nt$$=$obj$$.details.csum("tien_ck_nt");$intro_kh_t_tien_nt_t_tt_nt$$=$intro_kh_t_tien_nt_t_tt_nt$$-$ckhds_query_t_ck_nt$$-($obj$$.tien_ck_hd||0);$ckhds_query_t_ck_nt$$={id_app:$obj$$.id_app,gt_tu:{$lte:$intro_kh_t_tien_nt_t_tt_nt$$},ma_kho:{$in:[void 0,null,"",$obj$$.ma_kho]},kieu:{$in:["0",null,void 0]},doi_tuong:"1"};$ckhds_query_t_ck_nt$$.$and=[{$or:[{gt_den:{$in:[0,void 0,null]}},{gt_den:{$gte:$intro_kh_t_tien_nt_t_tt_nt$$}}]}];var $ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$=moment($obj$$.ngay_ct).startOf("date").toDate();
7
+ var $hieu_luc_tu_i_q_ma_nv$$={$lte:moment($obj$$.ngay_ct).endOf("date").toDate()};$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$={$gte:$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$};$ckhds_query_t_ck_nt$$.hieu_luc_tu=$hieu_luc_tu_i_q_ma_nv$$;$ckhds_query_t_ck_nt$$.hieu_luc_den=$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$;$hieu_luc_tu_i_q_ma_nv$$={$in:[void 0,null,"",$obj$$.ma_nv]};$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$={$in:[void 0,null,""]};if($obj$$.ma_kh){var $kh$jscomp$1_lan_mua_thu$$=await customer.findOne({id_app:$obj$$.id_app,
8
+ ma_kh:$obj$$.ma_kh},{nh_kh:1});$kh$jscomp$1_lan_mua_thu$$&&$kh$jscomp$1_lan_mua_thu$$.nh_kh&&($ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$={$in:[void 0,null,"",$kh$jscomp$1_lan_mua_thu$$.nh_kh]});($kh$jscomp$1_lan_mua_thu$$=await model.countDocuments({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,trang_thai:{$in:["5","6"]}}))||($kh$jscomp$1_lan_mua_thu$$=0);$kh$jscomp$1_lan_mua_thu$$+=1}$ckhds_query_t_ck_nt$$.$or=[{$and:[{ma_nv:$hieu_luc_tu_i_q_ma_nv$$},{nh_kh:{$in:["",null,void 0]}}]},{$and:[{nh_kh:$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$},
9
+ {ma_kh:{$in:["",null,void 0]}}]}];$ckhds_query_t_ck_nt$$.ap_dung_lan_mua_thu={$in:[null,void 0,0,void 0]};$ckhds_query_t_ck_nt$$=await global.getModel("dmhoahonghd").find($ckhds_query_t_ck_nt$$).sort({gt_tu:-1,tien_ck:-1,ty_le_hh:-1,ma_nv:-1,nh_kh:-1,hieu_luc_tu:-1}).limit(1).lean();$ckhds_query_t_ck_nt$$=$ckhds_query_t_ck_nt$$.filter($cs$$=>$cs$$.chi_su_dung_cho_ct?0<=$cs$$.chi_su_dung_cho_ct.indexOf($obj$$.ma_ct):$cs$$.khong_su_dung_cho_ct?0>$cs$$.khong_su_dung_cho_ct.indexOf($obj$$.ma_ct):!0);
10
+ if(0<$ckhds_query_t_ck_nt$$.length)for($hieu_luc_tu_i_q_ma_nv$$=0;$hieu_luc_tu_i_q_ma_nv$$<$ckhds_query_t_ck_nt$$.length;$hieu_luc_tu_i_q_ma_nv$$++){$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$=$ckhds_query_t_ck_nt$$[$hieu_luc_tu_i_q_ma_nv$$];$kh$jscomp$1_lan_mua_thu$$=$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.sl_toi_thieu||0;let $sl_dap_ung$$=0;$kh$jscomp$1_lan_mua_thu$$&&$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.vts&&0<$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.vts.length&&$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.vts.forEach($vt$$=>
11
+ {var $ds_tien$$=$obj$$.details.filter($d$$=>$d$$.ma_vt===$vt$$.ma_vt&&(!$vt$$.ma_tt1||$vt$$.ma_tt1===$d$$.ma_tt1)&&(!$vt$$.ma_tt2||$vt$$.ma_tt2===$d$$.ma_tt2)&&(!$vt$$.ma_tt3||$vt$$.ma_tt3===$d$$.ma_tt3));if(0!=$ds_tien$$.length){var $so_luong$$=$ds_tien$$.map($d$$=>$d$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$ds_tien$$=$ds_tien$$.map($d$$=>($d$$.tien_hang_nt||0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$vt$$.sl_tu&&$so_luong$$<$vt$$.sl_tu||$vt$$.sl_den&&$so_luong$$>$vt$$.sl_den||
12
+ $vt$$.gt_tu&&$ds_tien$$<$vt$$.gt_tu||$vt$$.gt_den&&$ds_tien$$>$vt$$.gt_den||($sl_dap_ung$$+=1)}});if($kh$jscomp$1_lan_mua_thu$$<=$sl_dap_ung$$){$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.tien_hh?($obj$$.tien_hoa_hong_gt=$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.tien_hh,$obj$$.ty_le_hoa_hong_gt=0):($obj$$.ty_le_hoa_hong_gt=$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.ty_le_hh||0,$obj$$.tien_hoa_hong_gt=Math.roundBy($intro_kh_t_tien_nt_t_tt_nt$$*$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.ty_le_hh/100,0));$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.so_tien_max&&
13
+ ($obj$$.tien_hoa_hong_gt=Math.min($ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.so_tien_max,$obj$$.tien_hoa_hong_gt));$obj$$.chuyen_ngay_gt="1"==$ckhd_hieu_luc_den_q_nh_kh_tu_ngay$$.hinh_thuc_tt;break}}}}},hoahonghdnv=async $obj$$=>{if($obj$$.tu_tinh_hoa_hong&&!$obj$$.da_chuyen_hoa_hong){$obj$$.tien_hoa_hong=0;$obj$$.ty_le_hoa_hong=0;$obj$$.ma_kh_hoa_hong="";if($obj$$.ma_nv){var $nv_t_tien_nt$jscomp$1_t_tt_nt$$=await global.getModel("dmnv").findOne({id_app:$obj$$.id_app,ma_nv:$obj$$.ma_nv}).lean();$nv_t_tien_nt$jscomp$1_t_tt_nt$$&&
14
+ ($obj$$.ma_kh_hoa_hong=$nv_t_tien_nt$jscomp$1_t_tt_nt$$.ma_kh,$obj$$.user_nv=$nv_t_tien_nt$jscomp$1_t_tt_nt$$.user)}$nv_t_tien_nt$jscomp$1_t_tt_nt$$=$obj$$.details.csum("tien_hang_nt");var $ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$=$obj$$.details.csum("tien_ck_nt");$nv_t_tien_nt$jscomp$1_t_tt_nt$$=$nv_t_tien_nt$jscomp$1_t_tt_nt$$-$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$-($obj$$.tien_ck_hd||0);$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$={id_app:$obj$$.id_app,gt_tu:{$lte:$nv_t_tien_nt$jscomp$1_t_tt_nt$$},
15
+ ma_kho:{$in:[void 0,null,"",$obj$$.ma_kho]},kieu:{$in:["0",null,void 0]},doi_tuong:"0"};$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$.$and=[{$or:[{gt_den:{$in:[0,void 0,null]}},{gt_den:{$gte:$nv_t_tien_nt$jscomp$1_t_tt_nt$$}}]}];var $ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$=moment($obj$$.ngay_ct).startOf("date").toDate();var $hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_nv$$={$lte:moment($obj$$.ngay_ct).endOf("date").toDate()};$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$=
16
+ {$gte:$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$};$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$.hieu_luc_tu=$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_nv$$;$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$.hieu_luc_den=$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$;$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_nv$$={$in:[void 0,null,"",$obj$$.ma_nv]};$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$={$in:[void 0,null,""]};if($obj$$.ma_kh){var $kh$jscomp$2_lan_mua_thu$jscomp$3_sl_toi_thieu$$=
17
+ await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{nh_kh:1});$kh$jscomp$2_lan_mua_thu$jscomp$3_sl_toi_thieu$$&&$kh$jscomp$2_lan_mua_thu$jscomp$3_sl_toi_thieu$$.nh_kh&&($ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$={$in:[void 0,null,"",$kh$jscomp$2_lan_mua_thu$jscomp$3_sl_toi_thieu$$.nh_kh]});($kh$jscomp$2_lan_mua_thu$jscomp$3_sl_toi_thieu$$=await model.countDocuments({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,trang_thai:{$in:["5","6"]}}))||($kh$jscomp$2_lan_mua_thu$jscomp$3_sl_toi_thieu$$=
18
+ 0);$kh$jscomp$2_lan_mua_thu$jscomp$3_sl_toi_thieu$$+=1}$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$.$or=[{$and:[{ma_nv:$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_nv$$},{nh_kh:{$in:["",null,void 0]}}]},{$and:[{nh_kh:$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$},{ma_kh:{$in:["",null,void 0]}}]}];$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$.ap_dung_lan_mua_thu={$in:[null,void 0,0,void 0]};$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$=await global.getModel("dmhoahonghd").find($ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$).sort({gt_tu:-1,
19
+ tien_ck:-1,ty_le_hh:-1,ma_nv:-1,nh_kh:-1,hieu_luc_tu:-1}).limit(1).lean();$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$=$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$.filter($cs$$=>$cs$$.chi_su_dung_cho_ct?0<=$cs$$.chi_su_dung_cho_ct.indexOf($obj$$.ma_ct):$cs$$.khong_su_dung_cho_ct?0>$cs$$.khong_su_dung_cho_ct.indexOf($obj$$.ma_ct):!0);if(0<$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$.length)for($hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_nv$$=0;$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_nv$$<$ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$.length;$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_nv$$++){$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$=
20
+ $ckhds$jscomp$1_query$jscomp$1_t_ck_nt$$[$hieu_luc_tu$jscomp$1_i$jscomp$1_q_ma_nv$$];$kh$jscomp$2_lan_mua_thu$jscomp$3_sl_toi_thieu$$=$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.sl_toi_thieu||0;let $sl_dap_ung$$=0;$kh$jscomp$2_lan_mua_thu$jscomp$3_sl_toi_thieu$$&&$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.vts&&0<$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.vts.length&&$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.vts.forEach($vt$$=>
19
21
  {var $ds$jscomp$1_tien$$=$obj$$.details.filter($d$$=>$d$$.ma_vt===$vt$$.ma_vt&&(!$vt$$.ma_tt1||$vt$$.ma_tt1===$d$$.ma_tt1)&&(!$vt$$.ma_tt2||$vt$$.ma_tt2===$d$$.ma_tt2)&&(!$vt$$.ma_tt3||$vt$$.ma_tt3===$d$$.ma_tt3));if(0!=$ds$jscomp$1_tien$$.length){var $so_luong$$=$ds$jscomp$1_tien$$.map($d$$=>$d$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$ds$jscomp$1_tien$$=$ds$jscomp$1_tien$$.map($d$$=>($d$$.tien_hang_nt||0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$vt$$.sl_tu&&$so_luong$$<$vt$$.sl_tu||
20
- $vt$$.sl_den&&$so_luong$$>$vt$$.sl_den||$vt$$.gt_tu&&$ds$jscomp$1_tien$$<$vt$$.gt_tu||$vt$$.gt_den&&$ds$jscomp$1_tien$$>$vt$$.gt_den||($sl_dap_ung$$+=1)}});if($kh$jscomp$1_lan_mua_thu$jscomp$3_sl_toi_thieu$$<=$sl_dap_ung$$){$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.details_km.forEach($d$$=>{$d$$={...$d$$,km_yn_for:"khuyenmaihd"};$d$$.sl_xuat=$d$$.sl_km;$d$$.tien_hang_nt=$d$$.tien_hang=0;$d$$.tien_ck_nt=$d$$.tien_ck=0;$d$$.ty_le_ck=0;$d$$.tien_nt=$d$$.tien=0;$obj$$.details.push($d$$)});
21
- break}}}}},chietkhauhd=async $obj$$=>{if(!$obj$$.signature&&$obj$$.online){$obj$$.tien_ck_hd=0;$obj$$.ty_le_ck_hd=0;var $t_tien_nt$jscomp$2_t_tt_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_hang_nt"),$ckhds$jscomp$2_query$jscomp$2_t_ck_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_ck_nt");$t_tien_nt$jscomp$2_t_tt_nt$$-=$ckhds$jscomp$2_query$jscomp$2_t_ck_nt$$;$ckhds$jscomp$2_query$jscomp$2_t_ck_nt$$={id_app:$obj$$.id_app,gt_tu:{$lte:$t_tien_nt$jscomp$2_t_tt_nt$$},ma_kho:{$in:[void 0,
22
- null,"",$obj$$.ma_kho]}};$ckhds$jscomp$2_query$jscomp$2_t_ck_nt$$.$and=[{$or:[{gt_den:{$in:[0,void 0,null]}},{gt_den:{$gte:$t_tien_nt$jscomp$2_t_tt_nt$$}}]}];var $ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$=moment($obj$$.ngay_ct).startOf("date").toDate();var $hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh$$={$lte:moment($obj$$.ngay_ct).endOf("date").toDate()};$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$={$gte:$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$};
23
- $ckhds$jscomp$2_query$jscomp$2_t_ck_nt$$.hieu_luc_tu=$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh$$;$ckhds$jscomp$2_query$jscomp$2_t_ck_nt$$.hieu_luc_den=$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$;$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh$$={$in:[void 0,null,"",$obj$$.ma_kh]};$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$={$in:[void 0,null,""]};if($obj$$.ma_kh){var $kh$jscomp$2_lan_mua_thu$jscomp$5_sl_toi_thieu$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},
24
- {nh_kh:1});$kh$jscomp$2_lan_mua_thu$jscomp$5_sl_toi_thieu$$&&$kh$jscomp$2_lan_mua_thu$jscomp$5_sl_toi_thieu$$.nh_kh&&($ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$={$in:[void 0,null,"",$kh$jscomp$2_lan_mua_thu$jscomp$5_sl_toi_thieu$$.nh_kh]});($kh$jscomp$2_lan_mua_thu$jscomp$5_sl_toi_thieu$$=await model.countDocuments({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,trang_thai:{$in:["5","6"]}}))||($kh$jscomp$2_lan_mua_thu$jscomp$5_sl_toi_thieu$$=0);$kh$jscomp$2_lan_mua_thu$jscomp$5_sl_toi_thieu$$+=
25
- 1}$ckhds$jscomp$2_query$jscomp$2_t_ck_nt$$.$or=[{$and:[{ma_kh:$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh$$},{nh_kh:{$in:["",null,void 0]}}]},{$and:[{nh_kh:$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$},{ma_kh:{$in:["",null,void 0]}}]}];$ckhds$jscomp$2_query$jscomp$2_t_ck_nt$$.ap_dung_lan_mua_thu={$in:[null,void 0,0,void 0]};$ckhds$jscomp$2_query$jscomp$2_t_ck_nt$$.online=!0;$ckhds$jscomp$2_query$jscomp$2_t_ck_nt$$=await dmchietkhauhd.find($ckhds$jscomp$2_query$jscomp$2_t_ck_nt$$).sort({gt_tu:-1,
26
- tien_ck:-1,ty_le_ck:-1,ma_kh:-1,nh_kh:-1,hieu_luc_tu:-1}).lean();if(0<$ckhds$jscomp$2_query$jscomp$2_t_ck_nt$$.length)for($hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh$$=0;$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh$$<$ckhds$jscomp$2_query$jscomp$2_t_ck_nt$$.length;$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh$$++){$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$=$ckhds$jscomp$2_query$jscomp$2_t_ck_nt$$[$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh$$];$kh$jscomp$2_lan_mua_thu$jscomp$5_sl_toi_thieu$$=
27
- $ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$.sl_toi_thieu||0;let $sl_dap_ung$$=0;$kh$jscomp$2_lan_mua_thu$jscomp$5_sl_toi_thieu$$&&$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$.vts&&0<$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$.vts.length&&$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$.vts.forEach($vt$$=>{var $ds$jscomp$2_tien$$=$obj$$.details.filter($d$$=>$d$$.ma_vt===$vt$$.ma_vt&&(!$vt$$.ma_tt1||$vt$$.ma_tt1===$d$$.ma_tt1)&&
28
- (!$vt$$.ma_tt2||$vt$$.ma_tt2===$d$$.ma_tt2)&&(!$vt$$.ma_tt3||$vt$$.ma_tt3===$d$$.ma_tt3));if(0!=$ds$jscomp$2_tien$$.length){var $so_luong$$=$ds$jscomp$2_tien$$.map($d$$=>$d$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$ds$jscomp$2_tien$$=$ds$jscomp$2_tien$$.map($d$$=>($d$$.tien_hang_nt||0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$vt$$.sl_tu&&$so_luong$$<$vt$$.sl_tu||$vt$$.sl_den&&$so_luong$$>$vt$$.sl_den||$vt$$.gt_tu&&$ds$jscomp$2_tien$$<$vt$$.gt_tu||$vt$$.gt_den&&$ds$jscomp$2_tien$$>
29
- $vt$$.gt_den||($sl_dap_ung$$+=1)}});if($kh$jscomp$2_lan_mua_thu$jscomp$5_sl_toi_thieu$$<=$sl_dap_ung$$){$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$.tien_ck?($obj$$.tien_ck_hd=$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$.tien_ck,$obj$$.ty_le_ck_hd=0):($obj$$.ty_le_ck_hd=$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$.ty_le_ck,$obj$$.tien_ck_hd=Math.roundBy($t_tien_nt$jscomp$2_t_tt_nt$$*$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$.ty_le_ck/
30
- 100,0));$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$.so_tien_max&&($obj$$.tien_ck_hd=Math.min($ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$.so_tien_max,$obj$$.tien_ck_hd));break}}}},getPointBalance=async($id_app$$,$sender_email$$)=>new Promise(($resolve$$,$reject$$)=>{ckdiem({id_app:$id_app$$,email:$sender_email$$},($e$$,$rs$$)=>{if($e$$)return $reject$$(Error($e$$));$resolve$$(0===$rs$$.length?0:$rs$$[0].ton00)})}),createTransactionBonus=async function($obj$$){if("5"!=
22
+ $vt$$.sl_den&&$so_luong$$>$vt$$.sl_den||$vt$$.gt_tu&&$ds$jscomp$1_tien$$<$vt$$.gt_tu||$vt$$.gt_den&&$ds$jscomp$1_tien$$>$vt$$.gt_den||($sl_dap_ung$$+=1)}});if($kh$jscomp$2_lan_mua_thu$jscomp$3_sl_toi_thieu$$<=$sl_dap_ung$$){$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.tien_hh?($obj$$.tien_hoa_hong=$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.tien_hh,$obj$$.ty_le_hoa_hong=0):($obj$$.ty_le_hoa_hong=$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.ty_le_hh||
23
+ 0,$obj$$.tien_hoa_hong=Math.roundBy($nv_t_tien_nt$jscomp$1_t_tt_nt$$*$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.ty_le_hh/100,0));$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.so_tien_max&&($obj$$.tien_hoa_hong=Math.min($ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.so_tien_max,$obj$$.tien_hoa_hong));$obj$$.chuyen_ngay="1"==$ckhd$jscomp$1_hieu_luc_den$jscomp$1_q_nh_kh$jscomp$1_tu_ngay$$.hinh_thuc_tt;break}}}},khuyenmaihd=async $obj$$=>{if($obj$$.details&&
24
+ $obj$$.online){var $ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_hang_nt");if(0!==$ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$){var $hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh_t_ck_nt$jscomp$2_t_tt_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_ck_nt");$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh_t_ck_nt$jscomp$2_t_tt_nt$$=$ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$-$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh_t_ck_nt$jscomp$2_t_tt_nt$$;$obj$$.details=
25
+ $obj$$.details.filter($d$$=>"khuyenmaihd"!=$d$$.km_yn_for);$ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$={id_app:$obj$$.id_app,gt_tu:{$lte:$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh_t_ck_nt$jscomp$2_t_tt_nt$$},ma_kho:{$in:[void 0,null,"",$obj$$.ma_kho]}};$ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$.$and=[{$or:[{gt_den:{$in:[0,void 0,null]}},{gt_den:{$gte:$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh_t_ck_nt$jscomp$2_t_tt_nt$$}}]}];var $ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$=moment($obj$$.ngay_ct).startOf("date").toDate();
26
+ $hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh_t_ck_nt$jscomp$2_t_tt_nt$$={$lte:moment($obj$$.ngay_ct).endOf("date").toDate()};$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$={$gte:$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$};$ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$.hieu_luc_tu=$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh_t_ck_nt$jscomp$2_t_tt_nt$$;$ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$.hieu_luc_den=$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$;$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh_t_ck_nt$jscomp$2_t_tt_nt$$=
27
+ {$in:[void 0,null,"",$obj$$.ma_kh]};$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$={$in:[void 0,null,""]};if($obj$$.ma_kh){var $kh$jscomp$3_lan_mua_thu$jscomp$5_sl_toi_thieu$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{nh_kh:1});$kh$jscomp$3_lan_mua_thu$jscomp$5_sl_toi_thieu$$&&$kh$jscomp$3_lan_mua_thu$jscomp$5_sl_toi_thieu$$.nh_kh&&($ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$={$in:[void 0,null,"",$kh$jscomp$3_lan_mua_thu$jscomp$5_sl_toi_thieu$$.nh_kh]});
28
+ ($kh$jscomp$3_lan_mua_thu$jscomp$5_sl_toi_thieu$$=await model.countDocuments({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,trang_thai:{$in:["5","6"]}}))||($kh$jscomp$3_lan_mua_thu$jscomp$5_sl_toi_thieu$$=0);$kh$jscomp$3_lan_mua_thu$jscomp$5_sl_toi_thieu$$+=1}$ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$.$or=[{$and:[{ma_kh:$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh_t_ck_nt$jscomp$2_t_tt_nt$$},{nh_kh:{$in:["",null,void 0]}}]},{$and:[{nh_kh:$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$},{ma_kh:{$in:["",
29
+ null,void 0]}}]}];$ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$.ap_dung_lan_mua_thu={$in:[null,void 0,0,void 0]};$ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$.online=!0;$ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$=await dmkhuyenmaihd.find($ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$).sort({stt_uu_tien:1,gt_tu:-1,ma_kh:-1,nh_kh:-1,hieu_luc_tu:-1}).lean();for($hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh_t_ck_nt$jscomp$2_t_tt_nt$$=0;$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh_t_ck_nt$jscomp$2_t_tt_nt$$<$ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$.length;$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh_t_ck_nt$jscomp$2_t_tt_nt$$++)if(($ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$=
30
+ $ckhds$jscomp$2_query$jscomp$2_t_tien_nt$$[$hieu_luc_tu$jscomp$2_i$jscomp$2_q_ma_kh_t_ck_nt$jscomp$2_t_tt_nt$$])&&$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$.details_km&&0<$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$.details_km.length){$kh$jscomp$3_lan_mua_thu$jscomp$5_sl_toi_thieu$$=$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$.sl_toi_thieu||0;let $sl_dap_ung$$=0;$kh$jscomp$3_lan_mua_thu$jscomp$5_sl_toi_thieu$$&&$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$.vts&&
31
+ 0<$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$.vts.length&&$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$.vts.forEach($vt$$=>{var $ds$jscomp$2_tien$$=$obj$$.details.filter($d$$=>$d$$.ma_vt===$vt$$.ma_vt&&(!$vt$$.ma_tt1||$vt$$.ma_tt1===$d$$.ma_tt1)&&(!$vt$$.ma_tt2||$vt$$.ma_tt2===$d$$.ma_tt2)&&(!$vt$$.ma_tt3||$vt$$.ma_tt3===$d$$.ma_tt3));if(0!=$ds$jscomp$2_tien$$.length){var $so_luong$$=$ds$jscomp$2_tien$$.map($d$$=>$d$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);
32
+ $ds$jscomp$2_tien$$=$ds$jscomp$2_tien$$.map($d$$=>($d$$.tien_hang_nt||0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$vt$$.sl_tu&&$so_luong$$<$vt$$.sl_tu||$vt$$.sl_den&&$so_luong$$>$vt$$.sl_den||$vt$$.gt_tu&&$ds$jscomp$2_tien$$<$vt$$.gt_tu||$vt$$.gt_den&&$ds$jscomp$2_tien$$>$vt$$.gt_den||($sl_dap_ung$$+=1)}});if($kh$jscomp$3_lan_mua_thu$jscomp$5_sl_toi_thieu$$<=$sl_dap_ung$$){$ckhd$jscomp$2_hieu_luc_den$jscomp$2_q_nh_kh$jscomp$2_tu_ngay$$.details_km.forEach($d$$=>{$d$$={...$d$$,km_yn_for:"khuyenmaihd"};
33
+ $d$$.sl_xuat=$d$$.sl_km;$d$$.tien_hang_nt=$d$$.tien_hang=0;$d$$.tien_ck_nt=$d$$.tien_ck=0;$d$$.ty_le_ck=0;$d$$.tien_nt=$d$$.tien=0;$obj$$.details.push($d$$)});break}}}}},chietkhauhd=async $obj$$=>{if(!$obj$$.signature&&$obj$$.online){$obj$$.tien_ck_hd=0;$obj$$.ty_le_ck_hd=0;var $t_tien_nt$jscomp$3_t_tt_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_hang_nt"),$ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$=$obj$$.details.filter($d$$=>!$d$$.km_yn_for).csum("tien_ck_nt");$t_tien_nt$jscomp$3_t_tt_nt$$-=
34
+ $ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$;$ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$={id_app:$obj$$.id_app,gt_tu:{$lte:$t_tien_nt$jscomp$3_t_tt_nt$$},ma_kho:{$in:[void 0,null,"",$obj$$.ma_kho]}};$ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$.$and=[{$or:[{gt_den:{$in:[0,void 0,null]}},{gt_den:{$gte:$t_tien_nt$jscomp$3_t_tt_nt$$}}]}];var $ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$=moment($obj$$.ngay_ct).startOf("date").toDate();var $hieu_luc_tu$jscomp$3_i$jscomp$3_q_ma_kh$$={$lte:moment($obj$$.ngay_ct).endOf("date").toDate()};
35
+ $ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$={$gte:$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$};$ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$.hieu_luc_tu=$hieu_luc_tu$jscomp$3_i$jscomp$3_q_ma_kh$$;$ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$.hieu_luc_den=$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$;$hieu_luc_tu$jscomp$3_i$jscomp$3_q_ma_kh$$={$in:[void 0,null,"",$obj$$.ma_kh]};$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$={$in:[void 0,
36
+ null,""]};if($obj$$.ma_kh){var $kh$jscomp$4_lan_mua_thu$jscomp$7_sl_toi_thieu$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{nh_kh:1});$kh$jscomp$4_lan_mua_thu$jscomp$7_sl_toi_thieu$$&&$kh$jscomp$4_lan_mua_thu$jscomp$7_sl_toi_thieu$$.nh_kh&&($ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$={$in:[void 0,null,"",$kh$jscomp$4_lan_mua_thu$jscomp$7_sl_toi_thieu$$.nh_kh]});($kh$jscomp$4_lan_mua_thu$jscomp$7_sl_toi_thieu$$=await model.countDocuments({id_app:$obj$$.id_app,
37
+ ma_kh:$obj$$.ma_kh,trang_thai:{$in:["5","6"]}}))||($kh$jscomp$4_lan_mua_thu$jscomp$7_sl_toi_thieu$$=0);$kh$jscomp$4_lan_mua_thu$jscomp$7_sl_toi_thieu$$+=1}$ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$.$or=[{$and:[{ma_kh:$hieu_luc_tu$jscomp$3_i$jscomp$3_q_ma_kh$$},{nh_kh:{$in:["",null,void 0]}}]},{$and:[{nh_kh:$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$},{ma_kh:{$in:["",null,void 0]}}]}];$ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$.ap_dung_lan_mua_thu={$in:[null,void 0,0,void 0]};$ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$.online=
38
+ !0;$ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$=await dmchietkhauhd.find($ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$).sort({gt_tu:-1,tien_ck:-1,ty_le_ck:-1,ma_kh:-1,nh_kh:-1,hieu_luc_tu:-1}).lean();if(0<$ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$.length)for($hieu_luc_tu$jscomp$3_i$jscomp$3_q_ma_kh$$=0;$hieu_luc_tu$jscomp$3_i$jscomp$3_q_ma_kh$$<$ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$.length;$hieu_luc_tu$jscomp$3_i$jscomp$3_q_ma_kh$$++){$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$=$ckhds$jscomp$3_query$jscomp$3_t_ck_nt$$[$hieu_luc_tu$jscomp$3_i$jscomp$3_q_ma_kh$$];
39
+ $kh$jscomp$4_lan_mua_thu$jscomp$7_sl_toi_thieu$$=$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$.sl_toi_thieu||0;let $sl_dap_ung$$=0;$kh$jscomp$4_lan_mua_thu$jscomp$7_sl_toi_thieu$$&&$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$.vts&&0<$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$.vts.length&&$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$.vts.forEach($vt$$=>{var $ds$jscomp$3_tien$$=$obj$$.details.filter($d$$=>$d$$.ma_vt===$vt$$.ma_vt&&
40
+ (!$vt$$.ma_tt1||$vt$$.ma_tt1===$d$$.ma_tt1)&&(!$vt$$.ma_tt2||$vt$$.ma_tt2===$d$$.ma_tt2)&&(!$vt$$.ma_tt3||$vt$$.ma_tt3===$d$$.ma_tt3));if(0!=$ds$jscomp$3_tien$$.length){var $so_luong$$=$ds$jscomp$3_tien$$.map($d$$=>$d$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$ds$jscomp$3_tien$$=$ds$jscomp$3_tien$$.map($d$$=>($d$$.tien_hang_nt||0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$vt$$.sl_tu&&$so_luong$$<$vt$$.sl_tu||$vt$$.sl_den&&$so_luong$$>$vt$$.sl_den||$vt$$.gt_tu&&$ds$jscomp$3_tien$$<
41
+ $vt$$.gt_tu||$vt$$.gt_den&&$ds$jscomp$3_tien$$>$vt$$.gt_den||($sl_dap_ung$$+=1)}});if($kh$jscomp$4_lan_mua_thu$jscomp$7_sl_toi_thieu$$<=$sl_dap_ung$$){$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$.tien_ck?($obj$$.tien_ck_hd=$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$.tien_ck,$obj$$.ty_le_ck_hd=0):($obj$$.ty_le_ck_hd=$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$.ty_le_ck,$obj$$.tien_ck_hd=Math.roundBy($t_tien_nt$jscomp$3_t_tt_nt$$*$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$.ty_le_ck/
42
+ 100,0));$ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$.so_tien_max&&($obj$$.tien_ck_hd=Math.min($ckhd$jscomp$3_hieu_luc_den$jscomp$3_q_nh_kh$jscomp$3_tu_ngay$$.so_tien_max,$obj$$.tien_ck_hd));break}}}},getPointBalance=async($id_app$$,$sender_email$$)=>new Promise(($resolve$$,$reject$$)=>{ckdiem({id_app:$id_app$$,email:$sender_email$$},($e$$,$rs$$)=>{if($e$$)return $reject$$(Error($e$$));$resolve$$(0===$rs$$.length?0:$rs$$[0].ton00)})}),createTransactionBonus=async function($obj$$){if("5"!=
31
43
  $obj$$.trang_thai&&"6"!=$obj$$.trang_thai)return await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i"),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":introduce"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng gi\u1edbi thi\u1ec7u th\u00e0nh vi\u00ean m\u1edbi \u0111\u1ec3 t\u00ednh l\u1ea1i"),null;let $kh$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh})||{},$lan_mua$$=
32
- (await model.find({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,ngay_ct:{$lte:$obj$$.ngay_ct}})).length+1;var $_app_diem_thuong_gioi_thieu_old_trans$$=await App.findOne({_id:$obj$$.id_app}),$_intro_amount_calcDiemThuong$$=await Introducer.findOne({id_app:$obj$$.id_app,be_introduced:$obj$$.of_user||$obj$$.user_created});$_app_diem_thuong_gioi_thieu_old_trans$$=$_app_diem_thuong_gioi_thieu_old_trans$$.exfields.diem_thuong_gioi_thieu;1===$lan_mua$$&&$_app_diem_thuong_gioi_thieu_old_trans$$&&$_intro_amount_calcDiemThuong$$&&
33
- await transaction.createTrans({id_app:$obj$$.id_app,sender_email:$obj$$.id_app,receiver_email:$_intro_amount_calcDiemThuong$$.be_introduced_by,amount:$_app_diem_thuong_gioi_thieu_old_trans$$,description:"\u0110i\u1ec3m th\u01b0\u1edfng gi\u1edbi thi\u1ec7u kh\u00e1ch h\u00e0ng",otherData:{ma_ct:$obj$$.ma_ct,so_ct:$obj$$.so_ct,ngay_ct:$obj$$.ngay_ct,id_ct:$obj$$._id.toString()+":introduce"}});if(!$obj$$.exfields.survey)return null;let $now$$=moment(new Date).startOf("date").toDate();$_intro_amount_calcDiemThuong$$=
34
- $obj$$.details.filter($d$$=>$d$$.tien_hang).map(async $d$$=>{var $amount$$=await dmvt.findOne({ma_vt:$d$$.ma_vt,id_app:$obj$$.id_app}),$ckdiemthuong_ty_le_diem_thuong$$=await dmdiemthuong.find({id_app:$obj$$.id_app,status:!0,ma_kh:{$in:[null,"",$kh$$.ma_kh]},ma_kho:{$in:[null,"",$obj$$.ma_kho]},nh_kh:{$in:[null,"",$kh$$.nh_kh]},hieu_luc_tu:{$lte:$now$$},hieu_luc_den:{$gte:$now$$},ap_dung_lan_mua_thu:{$in:[0,$lan_mua$$]},ma_vt:{$in:[null,"",void 0,$d$$.ma_vt]},ma_nvt:{$in:[null,"",void 0,$amount$$?
35
- $amount$$.ma_nvt:""]}}).sort({ma_vt:-1,ma_nvt:-1,hieu_luc_tu:-1}).limit(1);return 0<$ckdiemthuong_ty_le_diem_thuong$$.length?($amount$$=0,$ckdiemthuong_ty_le_diem_thuong$$[0].tien?($ckdiemthuong_ty_le_diem_thuong$$=$ckdiemthuong_ty_le_diem_thuong$$[0].diem/$ckdiemthuong_ty_le_diem_thuong$$[0].tien)||($amount$$=Math.roundBy(($d$$.tien_hang-($d$$.tien_ck||0))*$ckdiemthuong_ty_le_diem_thuong$$,0)):$amount$$=$ckdiemthuong_ty_le_diem_thuong$$[0].diem*($d$$.sl_xuat||1),$amount$$):0});if($_intro_amount_calcDiemThuong$$=
36
- (await Promise.all($_intro_amount_calcDiemThuong$$)).reduce(($a$$,$b$$)=>$a$$+$b$$,0)){if($_app_diem_thuong_gioi_thieu_old_trans$$=await transaction.findOne({id_ct:$obj$$._id.toString()+":bonus"}),!$_app_diem_thuong_gioi_thieu_old_trans$$||$_app_diem_thuong_gioi_thieu_old_trans$$.amount!==$_intro_amount_calcDiemThuong$$)return await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i"),await transaction.createTrans({id_app:$obj$$.id_app,
37
- sender_email:$obj$$.id_app,receiver_email:$obj$$.of_user||$obj$$.user_created,amount:$_intro_amount_calcDiemThuong$$,description:"\u0110i\u1ec3m th\u01b0\u1edfng mua h\u00e0ng",otherData:{ma_ct:$obj$$.ma_ct,so_ct:$obj$$.so_ct,ngay_ct:$obj$$.ngay_ct,id_ct:$obj$$._id.toString()+":bonus"}})}else await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i")},createTransactionPayment=async function($obj$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});
38
- $obj$$.paymentByPoints&&(console.log("thanh to\u00e1n b\u1eb1ng \u0111i\u1ec3m mua h\u00e0ng",$obj$$.of_user||$obj$$.user_created,$obj$$.so_ct,$obj$$.paymentByPoints),await transaction.createTrans({id_app:$obj$$.id_app,sender_email:$obj$$.of_user||$obj$$.user_created,receiver_email:$obj$$.id_app,amount:$obj$$.paymentByPoints,description:"Thanh to\u00e1n cho \u0111\u01a1n h\u00e0ng s\u1ed1 "+$obj$$.so_ct,otherData:{ma_ct:$obj$$.ma_ct,so_ct:$obj$$.so_ct,ngay_ct:$obj$$.ngay_ct,id_ct:$obj$$._id.toString()}}))},
39
- BuyPoint=async function($obj$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"});var $amount$$=$obj$$.details;$amount$$=$amount$$.map($d$$=>{$d$$.toObject&&($d$$=$d$$.toObject());return $d$$});await $amount$$.asyncJoinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:"is_point"});($amount$$=$amount$$.filter($d$$=>$d$$.is_point).map($d$$=>$d$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0))&&await transaction.createTrans({id_app:$obj$$.id_app,sender_email:$obj$$.id_app,receiver_email:$obj$$.of_user||
40
- $obj$$.user_created,amount:$amount$$,description:$obj$$.dien_giai||"N\u1ed9p ti\u1ec1n m\u1eb7t v\u00e0o v\u00ed",otherData:{ma_ct:$obj$$.ma_ct,so_ct:$obj$$.so_ct,ngay_ct:$obj$$.ngay_ct,id_ct:$obj$$._id.toString()+":buy"}})},checkEvoucher=($user$$,$obj$$)=>{let $gt_don_hang$$=$obj$$.details.map($d$$=>$d$$.tien_hang_nt-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);return($obj$$.evouchers||[]).map($ev$$=>new Promise(($resolve$$,$reject$$)=>{(async()=>{const $_e$$=await Evoucher.findOne({ma:$ev$$.ma,
41
- id_app:$user$$.current_id_app});if(!$_e$$)return console.error("Th\u1ebb mua h\u00e0ng kh\u00f4ng t\u1ed3n t\u1ea1i",$ev$$),$reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng t\u1ed3n t\u1ea1i`));if(!$_e$$.online)return $reject$$(Error(`Kh\u00f4ng th\u1ec3 s\u1eed d\u1ee5ng th\u1ebb mua h\u00e0ng ${$ev$$.ma} cho \u0111\u01a1n h\u00e0ng online`));if($_e$$.id_ct_used&&$_e$$.id_ct_used!==($obj$$._id||"").toString())return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng`));
42
- if(1<=$_e$$.so_lan_sd&&$_e$$.id_ct_useds&&0<$_e$$.id_ct_useds.length&&($_e$$.id_ct_useds=[...(new Set([...$_e$$.id_ct_useds]))],$_e$$.id_ct_useds.length>=$_e$$.so_lan_sd&&(!$obj$$._id||0>$_e$$.id_ct_useds.indexOf($obj$$._id))))return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng h\u1ebft`));if($_e$$.user&&$_e$$.user!==($obj$$.of_user||$obj$$.user_created||$user$$.email))return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng h\u1ee3p l\u1ec7`));
43
- var $date_created_so_tien_giam$$=new Date($obj$$.date_created);if(moment($_e$$.hieu_luc_den).endOf("date").toDate().getTime()<$date_created_so_tien_giam$$.getTime())return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 h\u1ebft h\u1ea1n s\u1eed d\u1ee5ng`));if($_e$$.gt_don_hang_toi_thieu&&$gt_don_hang$$<$_e$$.gt_don_hang_toi_thieu)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} ch\u1ec9 \u00e1p d\u1ee5ng cho c\u00e1c \u0111\u01a1n h\u00e0ng c\u00f3 gi\u00e1 tr\u1ecb l\u1edbn h\u01a1n ho\u1eb7c b\u1eb1ng ${numeral($_e$$.gt_don_hang_toi_thieu).format()}`));
44
- if($_e$$.vts&&0<$_e$$.vts.length&&$_e$$.sl_toi_thieu){let $sl_dap_ung$$=0;$_e$$.vts.forEach($vt$$=>{var $ds$jscomp$3_tien$$=$obj$$.details.filter($d$$=>$d$$.ma_vt===$vt$$.ma_vt&&(!$vt$$.ma_tt1||$vt$$.ma_tt1===$d$$.ma_tt1)&&(!$vt$$.ma_tt2||$vt$$.ma_tt2===$d$$.ma_tt2)&&(!$vt$$.ma_tt3||$vt$$.ma_tt3===$d$$.ma_tt3));if(0!=$ds$jscomp$3_tien$$.length){var $so_luong$$=$ds$jscomp$3_tien$$.map($d$$=>$d$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$ds$jscomp$3_tien$$=$ds$jscomp$3_tien$$.map($d$$=>($d$$.tien_hang_nt||
45
- 0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$vt$$.sl_tu&&$so_luong$$<$vt$$.sl_tu||$vt$$.sl_den&&$so_luong$$>$vt$$.sl_den||$vt$$.gt_tu&&$ds$jscomp$3_tien$$<$vt$$.gt_tu||$vt$$.gt_den&&$ds$jscomp$3_tien$$>$vt$$.gt_den||($sl_dap_ung$$+=1)}});if($_e$$.sl_toi_thieu>$sl_dap_ung$$)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng h\u1ee3p l\u1ec7 do kh\u00f4ng \u0111\u00e1p \u1ee9ng \u0111\u01b0\u1ee3c y\u00eau c\u1ea7u s\u1ea3n ph\u1ea9m`))}$date_created_so_tien_giam$$=
44
+ (await model.find({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,ngay_ct:{$lte:$obj$$.ngay_ct}})).length+1;var $_app_diem_thuong_gioi_thieu_old_trans$$=await App.findOne({_id:$obj$$.id_app}),$_intro_amount$$=await Introducer.findOne({id_app:$obj$$.id_app,be_introduced:$obj$$.of_user||$obj$$.user_created});$_app_diem_thuong_gioi_thieu_old_trans$$=$_app_diem_thuong_gioi_thieu_old_trans$$.exfields.diem_thuong_gioi_thieu;1===$lan_mua$$&&$_app_diem_thuong_gioi_thieu_old_trans$$&&$_intro_amount$$&&await transaction.createTrans({id_app:$obj$$.id_app,
45
+ sender_email:$obj$$.id_app,receiver_email:$_intro_amount$$.be_introduced_by,amount:$_app_diem_thuong_gioi_thieu_old_trans$$,description:"\u0110i\u1ec3m th\u01b0\u1edfng gi\u1edbi thi\u1ec7u kh\u00e1ch h\u00e0ng",otherData:{ma_ct:$obj$$.ma_ct,so_ct:$obj$$.so_ct,ngay_ct:$obj$$.ngay_ct,id_ct:$obj$$._id.toString()+":introduce"}});if(!$obj$$.exfields.survey)return null;let $now$$=moment(new Date).startOf("date").toDate();$_intro_amount$$=$obj$$.details.filter($d$$=>$d$$.tien_hang).map(async $d$$=>{var $amount$$=
46
+ await dmvt.findOne({ma_vt:$d$$.ma_vt,id_app:$obj$$.id_app}),$ckdiemthuong_ty_le_diem_thuong$$=await dmdiemthuong.find({id_app:$obj$$.id_app,status:!0,ma_kh:{$in:[null,"",$kh$$.ma_kh]},ma_kho:{$in:[null,"",$obj$$.ma_kho]},nh_kh:{$in:[null,"",$kh$$.nh_kh]},hieu_luc_tu:{$lte:$now$$},hieu_luc_den:{$gte:$now$$},ap_dung_lan_mua_thu:{$in:[0,$lan_mua$$]},ma_vt:{$in:[null,"",void 0,$d$$.ma_vt]},ma_nvt:{$in:[null,"",void 0,$amount$$?$amount$$.ma_nvt:""]}}).sort({ma_vt:-1,ma_nvt:-1,hieu_luc_tu:-1}).limit(1);
47
+ return 0<$ckdiemthuong_ty_le_diem_thuong$$.length?($amount$$=0,$ckdiemthuong_ty_le_diem_thuong$$[0].tien?($ckdiemthuong_ty_le_diem_thuong$$=$ckdiemthuong_ty_le_diem_thuong$$[0].diem/$ckdiemthuong_ty_le_diem_thuong$$[0].tien)||($amount$$=Math.roundBy(($d$$.tien_hang-($d$$.tien_ck||0))*$ckdiemthuong_ty_le_diem_thuong$$,0)):$amount$$=$ckdiemthuong_ty_le_diem_thuong$$[0].diem*($d$$.sl_xuat||1),$amount$$):0});if($_intro_amount$$=(await Promise.all($_intro_amount$$)).reduce(($a$$,$b$$)=>$a$$+$b$$,0)){if($_app_diem_thuong_gioi_thieu_old_trans$$=
48
+ await transaction.findOne({id_ct:$obj$$._id.toString()+":bonus"}),!$_app_diem_thuong_gioi_thieu_old_trans$$||$_app_diem_thuong_gioi_thieu_old_trans$$.amount!==$_intro_amount$$)return await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i"),await transaction.createTrans({id_app:$obj$$.id_app,sender_email:$obj$$.id_app,receiver_email:$obj$$.of_user||$obj$$.user_created,amount:$_intro_amount$$,description:"\u0110i\u1ec3m th\u01b0\u1edfng mua h\u00e0ng",
49
+ otherData:{ma_ct:$obj$$.ma_ct,so_ct:$obj$$.so_ct,ngay_ct:$obj$$.ngay_ct,id_ct:$obj$$._id.toString()+":bonus"}})}else await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i")},createTransactionPayment=async function($obj$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});$obj$$.paymentByPoints&&(console.log("thanh to\u00e1n b\u1eb1ng \u0111i\u1ec3m mua h\u00e0ng",$obj$$.of_user||$obj$$.user_created,
50
+ $obj$$.so_ct,$obj$$.paymentByPoints),await transaction.createTrans({id_app:$obj$$.id_app,sender_email:$obj$$.of_user||$obj$$.user_created,receiver_email:$obj$$.id_app,amount:$obj$$.paymentByPoints,description:"Thanh to\u00e1n cho \u0111\u01a1n h\u00e0ng s\u1ed1 "+$obj$$.so_ct,otherData:{ma_ct:$obj$$.ma_ct,so_ct:$obj$$.so_ct,ngay_ct:$obj$$.ngay_ct,id_ct:$obj$$._id.toString()}}))},checkEvoucher=($user$$,$obj$$)=>{let $gt_don_hang$$=$obj$$.details.map($d$$=>$d$$.tien_hang_nt-($d$$.tien_ck_nt||0)).reduce(($a$$,
51
+ $b$$)=>$a$$+$b$$,0);return($obj$$.evouchers||[]).map($ev$$=>new Promise(($resolve$$,$reject$$)=>{(async()=>{const $_e$$=await Evoucher.findOne({ma:$ev$$.ma,id_app:$user$$.current_id_app});if(!$_e$$)return console.error("Th\u1ebb mua h\u00e0ng kh\u00f4ng t\u1ed3n t\u1ea1i",$ev$$),$reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng t\u1ed3n t\u1ea1i`));if(!$_e$$.online)return $reject$$(Error(`Kh\u00f4ng th\u1ec3 s\u1eed d\u1ee5ng th\u1ebb mua h\u00e0ng ${$ev$$.ma} cho \u0111\u01a1n h\u00e0ng online`));
52
+ if($_e$$.id_ct_used&&$_e$$.id_ct_used!==($obj$$._id||"").toString())return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng`));if(1<=$_e$$.so_lan_sd&&$_e$$.id_ct_useds&&0<$_e$$.id_ct_useds.length&&($_e$$.id_ct_useds=[...(new Set([...$_e$$.id_ct_useds]))],$_e$$.id_ct_useds.length>=$_e$$.so_lan_sd&&(!$obj$$._id||0>$_e$$.id_ct_useds.indexOf($obj$$._id))))return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng h\u1ebft`));
53
+ if($_e$$.user&&$_e$$.user!==($obj$$.of_user||$obj$$.user_created||$user$$.email))return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng h\u1ee3p l\u1ec7`));var $date_created_so_tien_giam$$=new Date($obj$$.date_created);if(moment($_e$$.hieu_luc_den).endOf("date").toDate().getTime()<$date_created_so_tien_giam$$.getTime())return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 h\u1ebft h\u1ea1n s\u1eed d\u1ee5ng`));if($_e$$.gt_don_hang_toi_thieu&&$gt_don_hang$$<$_e$$.gt_don_hang_toi_thieu)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} ch\u1ec9 \u00e1p d\u1ee5ng cho c\u00e1c \u0111\u01a1n h\u00e0ng c\u00f3 gi\u00e1 tr\u1ecb l\u1edbn h\u01a1n ho\u1eb7c b\u1eb1ng ${numeral($_e$$.gt_don_hang_toi_thieu).format()}`));
54
+ if($_e$$.vts&&0<$_e$$.vts.length&&$_e$$.sl_toi_thieu){let $sl_dap_ung$$=0;$_e$$.vts.forEach($vt$$=>{var $ds$jscomp$4_tien$$=$obj$$.details.filter($d$$=>$d$$.ma_vt===$vt$$.ma_vt&&(!$vt$$.ma_tt1||$vt$$.ma_tt1===$d$$.ma_tt1)&&(!$vt$$.ma_tt2||$vt$$.ma_tt2===$d$$.ma_tt2)&&(!$vt$$.ma_tt3||$vt$$.ma_tt3===$d$$.ma_tt3));if(0!=$ds$jscomp$4_tien$$.length){var $so_luong$$=$ds$jscomp$4_tien$$.map($d$$=>$d$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$ds$jscomp$4_tien$$=$ds$jscomp$4_tien$$.map($d$$=>($d$$.tien_hang_nt||
55
+ 0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$vt$$.sl_tu&&$so_luong$$<$vt$$.sl_tu||$vt$$.sl_den&&$so_luong$$>$vt$$.sl_den||$vt$$.gt_tu&&$ds$jscomp$4_tien$$<$vt$$.gt_tu||$vt$$.gt_den&&$ds$jscomp$4_tien$$>$vt$$.gt_den||($sl_dap_ung$$+=1)}});if($_e$$.sl_toi_thieu>$sl_dap_ung$$)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng h\u1ee3p l\u1ec7 do kh\u00f4ng \u0111\u00e1p \u1ee9ng \u0111\u01b0\u1ee3c y\u00eau c\u1ea7u s\u1ea3n ph\u1ea9m`))}$date_created_so_tien_giam$$=
46
56
  $_e$$.so_tien;$_e$$.ty_le&&($date_created_so_tien_giam$$=Math.roundBy($gt_don_hang$$*$_e$$.ty_le/100));$_e$$.so_tien_max&&$date_created_so_tien_giam$$>$_e$$.so_tien_max&&($date_created_so_tien_giam$$=$_e$$.so_tien_max);if($ev$$.so_tien_giam!==$date_created_so_tien_giam$$)return $reject$$(Error(`S\u1ed1 ti\u1ec1n gi\u1ea3m cho th\u1ebb ${$ev$$.ma} kh\u00f4ng h\u1ee3p l\u1ec7`));$ev$$.so_tien_giam=$date_created_so_tien_giam$$;$resolve$$(!0)})()}))},updateEvoucher=async($id_app$$,$evoucher_code$$,$id_ct_rs$$)=>
47
57
  {if($evoucher_code$$){$id_ct_rs$$=$id_ct_rs$$.toString();var $e$$=await Evoucher.findOne({ma:$evoucher_code$$,id_app:$id_app$$});$e$$?($id_app$$=$e$$.id_ct_useds||[],$id_app$$.push($id_ct_rs$$),$id_app$$=[...(new Set($id_app$$))],$id_ct_rs$$=await Evoucher.findOneAndUpdate({_id:$e$$._id},{id_ct_useds:$id_app$$}),console.log("update id_ct_useds",$evoucher_code$$,$id_app$$,$id_ct_rs$$)):console.error("can't find evoucher",$evoucher_code$$)}},deleteEvoucher=async($id_app$jscomp$2_id_ct_useds$$,$evoucher_code$$,
48
- $id_ct$$)=>{if($evoucher_code$$){$id_ct$$=$id_ct$$.toString();var $e$jscomp$2_rs$$=await Evoucher.findOne({id_app:$id_app$jscomp$2_id_ct_useds$$,ma:$evoucher_code$$});$e$jscomp$2_rs$$&&($id_app$jscomp$2_id_ct_useds$$=($e$jscomp$2_rs$$.id_ct_useds||[]).filter($ct$$=>$ct$$!==$id_ct$$),$e$jscomp$2_rs$$=await Evoucher.findOneAndUpdate({_id:$e$jscomp$2_rs$$._id},{id_ct_useds:$id_app$jscomp$2_id_ct_useds$$}),console.log("update id_ct_useds",$evoucher_code$$,$id_app$jscomp$2_id_ct_useds$$,$e$jscomp$2_rs$$))}},
58
+ $id_ct$$)=>{if($evoucher_code$$){$id_ct$$=$id_ct$$.toString();var $e$jscomp$3_rs$$=await Evoucher.findOne({id_app:$id_app$jscomp$2_id_ct_useds$$,ma:$evoucher_code$$});$e$jscomp$3_rs$$&&($id_app$jscomp$2_id_ct_useds$$=($e$jscomp$3_rs$$.id_ct_useds||[]).filter($ct$$=>$ct$$!==$id_ct$$),$e$jscomp$3_rs$$=await Evoucher.findOneAndUpdate({_id:$e$jscomp$3_rs$$._id},{id_ct_useds:$id_app$jscomp$2_id_ct_useds$$}),console.log("update id_ct_useds",$evoucher_code$$,$id_app$jscomp$2_id_ct_useds$$,$e$jscomp$3_rs$$))}},
49
59
  validOnline=async function($user$$,$obj$$,$_opt_pre_obj_t_tien_evoucher$$){$_opt_pre_obj_t_tien_evoucher$$&&($obj$$.tinh_thanh=$obj$$.tinh_thanh||$_opt_pre_obj_t_tien_evoucher$$.tinh_thanh,$obj$$.quan_huyen=$obj$$.quan_huyen||$_opt_pre_obj_t_tien_evoucher$$.quan_huyen,$obj$$.xa_phuong=$obj$$.xa_phuong||$_opt_pre_obj_t_tien_evoucher$$.xa_phuong,$obj$$.ma_freeship=void 0!==$obj$$.ma_freeship?$obj$$.ma_freeship:$_opt_pre_obj_t_tien_evoucher$$.ma_freeship,$obj$$.tien_freeship=void 0!==$obj$$.tien_freeship?
50
60
  $obj$$.tien_freeship:$_opt_pre_obj_t_tien_evoucher$$.ma_freeship);await ($obj$$.details||[]).filter($d$$=>!$d$$.ma_dvt&&$d$$.ma_tt1).asyncJoinModel2($user$$.current_id_app,dmtt,{where:{ma_vt:"ma_vt",ma_tt1:"ma_tt"},fields:"ma_dvt"});await ($obj$$.details||[]).filter($d$$=>!$d$$.ma_dvt&&$d$$.ma_tt2).asyncJoinModel2($user$$.current_id_app,dmtt,{where:{ma_vt:"ma_vt",ma_tt2:"ma_tt"},fields:"ma_dvt"});await ($obj$$.details||[]).filter($d$$=>!$d$$.ma_dvt&&$d$$.ma_tt3).asyncJoinModel2($user$$.current_id_app,
51
61
  dmtt,{where:{ma_vt:"ma_vt",ma_tt3:"ma_tt"},fields:"ma_dvt"});await ($obj$$.details||[]).filter($d$$=>!$d$$.ma_dvt).asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",fields:"ma_dvt"});await ($obj$$.details||[]).asyncJoinModel2($user$$.current_id_app,dmvt,{where:$item$$=>({ma_vt:$item$$.ma_vt}),fields:["ma_danh_muc","khu_vuc_kd","ten_vt","ten_vt_eng"]});var $details_dvgh_t_tien_nt$$=$obj$$.details.filter($d$$=>$d$$.khu_vuc_kd&&0<$d$$.khu_vuc_kd.length);for(var $freeship_i$$=0;$freeship_i$$<
@@ -63,63 +73,72 @@ if($freeship_i$$.gia_tri_dh&&$freeship_i$$.gia_tri_dh>$details_dvgh_t_tien_nt$$)
63
73
  $obj$$,$_opt_pre_obj_t_tien_evoucher$$),await Promise.all($_checkEvoucher_tien_con_lai$$)}catch($e$$){throw console.error($e$$),Error($e$$.message||$e$$);}$obj$$.evouchers=$obj$$.evouchers||($_opt_pre_obj_t_tien_evoucher$$||{}).evouchers||[];$_opt_pre_obj_t_tien_evoucher$$=$obj$$.evouchers.map($e$$=>$e$$.so_tien_giam||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);var $_checkEvoucher_tien_con_lai$$=$details_dvgh_t_tien_nt$$-($obj$$.tt_tien_thuong||0);$_opt_pre_obj_t_tien_evoucher$$>$_checkEvoucher_tien_con_lai$$&&
64
74
  ($_opt_pre_obj_t_tien_evoucher$$=$_checkEvoucher_tien_con_lai$$);$obj$$.tien_evoucher=$_opt_pre_obj_t_tien_evoucher$$;if($obj$$.tien_evoucher&&($_opt_pre_obj_t_tien_evoucher$$=await options.findOne({id_app:$obj$$.id_app,id_func:$obj$$.ma_ct.toLowerCase()}).lean())&&$_opt_pre_obj_t_tien_evoucher$$.option&&$_opt_pre_obj_t_tien_evoucher$$.option.phan_bo_evoucher){let $tien_evoucher_da_phan_bo$$=0,$tien_evoucher$$=$obj$$.tien_evoucher,$tien_evoucher_con_lai$$=$tien_evoucher$$-$tien_evoucher_da_phan_bo$$;
65
75
  ($obj$$.details||[]).forEach($detail$$=>{if(0<$tien_evoucher_con_lai$$){var $tien_evoucher_duoc_pb_tien_hang_con_lai$$=$detail$$.tien_hang_nt-($detail$$.tien_ck_nt||0);$tien_evoucher_duoc_pb_tien_hang_con_lai$$=$tien_evoucher_con_lai$$>$tien_evoucher_duoc_pb_tien_hang_con_lai$$?$tien_evoucher_duoc_pb_tien_hang_con_lai$$:$tien_evoucher_con_lai$$;$detail$$.tien_evoucher_duoc_pb=$tien_evoucher_duoc_pb_tien_hang_con_lai$$;$tien_evoucher_da_phan_bo$$+=$tien_evoucher_duoc_pb_tien_hang_con_lai$$;$tien_evoucher_con_lai$$=
66
- $tien_evoucher$$-$tien_evoucher_da_phan_bo$$}else $tien_evoucher_con_lai$$=0})}},valid=async function($user$$,$obj$$,$next$$,$i$jscomp$5_pre_obj$$){$i$jscomp$5_pre_obj$$&&($obj$$.online=$i$jscomp$5_pre_obj$$.online,$obj$$._id=$i$jscomp$5_pre_obj$$._id,$obj$$.details=$obj$$.details||$i$jscomp$5_pre_obj$$.details||[],$obj$$.evouchers=$obj$$.evouchers||$i$jscomp$5_pre_obj$$.evouchers);if($obj$$.online)try{await validOnline($user$$,$obj$$,$i$jscomp$5_pre_obj$$)}catch($e$$){return $next$$($e$$.message)}await ($obj$$.details||
67
- []).asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",fields:"is_coin"});if($obj$$.paymentByPoints)try{var $detail$$=await currency.getRate($obj$$.id_app,$obj$$.ma_nt);$detail$$=$detail$$||1;$obj$$.tien_paymentByPoints=$obj$$.paymentByPoints*$detail$$}catch($e$$){return $next$$($e$$.message)}for($i$jscomp$5_pre_obj$$=0;$i$jscomp$5_pre_obj$$<($obj$$.details||[]).length;$i$jscomp$5_pre_obj$$++)$detail$$=($obj$$.details||[])[$i$jscomp$5_pre_obj$$],$detail$$.line=$i$jscomp$5_pre_obj$$,"VND"===
76
+ $tien_evoucher$$-$tien_evoucher_da_phan_bo$$}else $tien_evoucher_con_lai$$=0})}},valid=async function($user$$,$obj$$,$next$$,$i$jscomp$6_pre_obj$$){$i$jscomp$6_pre_obj$$&&($obj$$.online=$i$jscomp$6_pre_obj$$.online,$obj$$._id=$i$jscomp$6_pre_obj$$._id,$obj$$.details=$obj$$.details||$i$jscomp$6_pre_obj$$.details||[],$obj$$.evouchers=$obj$$.evouchers||$i$jscomp$6_pre_obj$$.evouchers);if($obj$$.online)try{await validOnline($user$$,$obj$$,$i$jscomp$6_pre_obj$$)}catch($e$$){return $next$$($e$$.message)}await ($obj$$.details||
77
+ []).asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",fields:"is_coin"});if($obj$$.paymentByPoints)try{var $detail$$=await currency.getRate($obj$$.id_app,$obj$$.ma_nt);$detail$$=$detail$$||1;$obj$$.tien_paymentByPoints=$obj$$.paymentByPoints*$detail$$}catch($e$$){return $next$$($e$$.message)}for($i$jscomp$6_pre_obj$$=0;$i$jscomp$6_pre_obj$$<($obj$$.details||[]).length;$i$jscomp$6_pre_obj$$++)$detail$$=($obj$$.details||[])[$i$jscomp$6_pre_obj$$],$detail$$.line=$i$jscomp$6_pre_obj$$,"VND"===
68
78
  $obj$$.ma_nt&&($detail$$.tien_hang=$detail$$.tien_hang_nt,$detail$$.tien_ck=$detail$$.tien_ck_nt||0,$detail$$.gia_ban=$detail$$.gia_ban_nt),$detail$$.tien_nt=Math.max(0,$detail$$.tien_hang_nt-$detail$$.tien_ck_nt),$detail$$.tien=Math.max(0,$detail$$.tien_hang-$detail$$.tien_ck),$detail$$.tien_xuat=$detail$$.tien_xuat_nt;$obj$$.ma_dvcs?$next$$(null,$obj$$):dvcs.findOne({id_app:$user$$.current_id_app},{_id:1},function($error$$,$dv$$){return $error$$?$next$$($error$$):$dv$$?($obj$$.ma_dvcs=$dv$$._id.toString(),
69
79
  $next$$(null,$obj$$)):$next$$("C\u00f4ng ty/c\u1eeda h\u00e0ng n\u00e0y ch\u01b0a c\u00f3 m\u1ed9t \u0111\u01a1n v\u1ecb c\u01a1 s\u1edf n\u00e0o")})};
70
- module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,requireRecaptchaToken:!1,unique:["so_ct"],sort:{ngay_ct:-1,so_ct:-1},onEmitEvent:async($obj$$,$users_will_receive$$,$next$$)=>{$obj$$.user_nv_giao_hang&&$users_will_receive$$.push($obj$$.user_nv_giao_hang);$next$$(null,$users_will_receive$$)}});$contr_router$$.route();$contr_router$$.saving=async($user$$,$obj$$)=>{await chietkhauhd($obj$$);await khuyenmaihd($obj$$);await hoahonghd($obj$$)};
71
- $contr_router$$.handleAfterPayment=async $obj$$=>{let $app$$=await App.findOne({_id:$obj$$.id_app});$app$$.wallet_address&&$app$$.wallet_token&&$obj$$.details&&await Promise.all($obj$$.details.filter($d$$=>$d$$.is_coin&&!$d$$.transferred&&$d$$.wallet_receiver).map($detail$$=>(async()=>{let $memo$$=$obj$$.dien_giai||"",$amount$$=$detail$$.sl_xuat,$denom$$=$detail$$.ma_vt.toLowerCase(),$rs$$=await blockchainconnect.spend($obj$$.id_app,$app$$.wallet_token,$app$$.wallet_address,$detail$$.wallet_receiver,
72
- {amount:$amount$$,denom:$denom$$,memo:$memo$$});console.log("buy point result",$rs$$,$amount$$,$denom$$,$memo$$);$detail$$.transferred=!0})()));$obj$$.trang_thai_tt="5";await model.updateOne({_id:$obj$$._id},{details:$obj$$.details,trang_thai_tt:"5"});let $ctrlSO1$$=global.controllers.SO1;$ctrlSO1$$&&controller.postData($obj$$,$ctrlSO1$$,$e$$=>{if($e$$)return console.error($e$$);controller.pushNotification($ctrlSO1$$,$obj$$)});return null};$contr_router$$.post=async function($obj$$,$fn$$){$fn$$||
73
- ($fn$$=function(){});let $he_so_qd$$=await currency.getRate($obj$$.id_app,$obj$$.ma_nt)||1;await $obj$$.details.asyncJoinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["ma_thue","gia_mua"]});await $obj$$.details.filter($d$$=>$d$$.ma_thue).asyncJoinModel2($obj$$.id_app,global.getModel("vat"),{where:"ma_thue",fields:["thue_suat","tk_thue_co","tk_thue_co_treo"]});async.series({BuyPoint:$callback$$=>{BuyPoint($obj$$).then(()=>{$callback$$()}).catch($e$$=>{$callback$$($e$$)})},post_sodiemthuong:function($callback$$){const $details$$=
74
- [];$obj$$.details.filter($d$$=>$d$$.diem_thuong).forEach($d$jscomp$35_detail$$=>{$d$jscomp$35_detail$$={...$d$jscomp$35_detail$$};$d$jscomp$35_detail$$.ngay_ct=$obj$$.ngay_ct;$d$jscomp$35_detail$$.ma_kh=$obj$$.ma_kh;$d$jscomp$35_detail$$.sl_nhan=$d$jscomp$35_detail$$.diem_thuong;$details$$.push($d$jscomp$35_detail$$)});(new PostBook($obj$$,$details$$,Sodiemthuong)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},post_sokho:function($callback$jscomp$0$$){const $details$$=[];$obj$$.details.forEach($d$$=>
75
- {$details$$.push({...$d$$})});let $data_post$$=$details$$.map($detail$$=>$detail$$.combo&&0<$detail$$.combo.length?$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat*=$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*$item$$.gia_von_nt;$item$$.tien_hang=$item$$.tien_hang_nt=$item$$.sl_xuat*$item$$.gia_ban_nt;$item$$.tien_ck=$item$$.tien_ck_nt*=$item$$.sl_xuat;$item$$.tien=$item$$.tien_nt=$item$$.tien_hang_nt-$item$$.tien_ck_nt;
76
- return $item$$}):[$detail$$]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);(new PostBook($obj$$,$data_post$$,Sokho,async function($detail$$,$callback$$){$detail$$.nxt=2;$detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$detail$$.ma_kho=$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})},post_socai:function($callback$$){options.findOne({id_app:$obj$$.id_app,id_func:ma_ct.toLowerCase()}).lean().exec(async($error$$,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$)=>
77
- {let $option$$;$option$$=$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$?$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.option||{}:{};($error$$=await dmkho.findOne({id_app:$obj$$.id_app,ma_kho:$obj$$.ma_kho}).lean())||($error$$={});let $pt$$;$obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan)&&($pt$$=await ptthanhtoan.findOne({id_app:$obj$$.id_app,_id:$obj$$.pt_thanh_toan}).lean());$pt$$=$pt$$||
78
- {};$pt$$.tk_tien=$pt$$.tk_cn;$pt$$.tk_cn=$pt$$.tk_cn||$error$$.tk_cn;$pt$$.tk_dt=$error$$.tk_dt||$pt$$.tk_dt;$pt$$.tk_gv=$error$$.tk_gv||$pt$$.tk_gv;$pt$$.tk_ck=$error$$.tk_ck||$pt$$.tk_ck;$pt$$.tk_cp_gh=$error$$.tk_cp_gh||$pt$$.tk_cp_gh;$pt$$.tk_cp_bh=$error$$.tk_cp_bh||$pt$$.tk_cp_bh;$pt$$.tk_cp_ctv=$error$$.tk_cp_ctv||$pt$$.tk_cp_ctv;$pt$$.tk_cn_ctv=$error$$.tk_cn_ctv||$pt$$.tk_cn_ctv;$option$$.tk_tien=$pt$$.tk_tien||$error$$.tk_tien||$option$$.tk_tien||"1111";$option$$.tk_cn=$pt$$.tk_cn||$option$$.tk_cn||
79
- "131111";$option$$.tk_dt=$pt$$.tk_dt||$option$$.tk_dt||"51111";$option$$.tk_tl=$pt$$.tk_tl||$option$$.tk_tl||"52131";$option$$.tk_ck=$pt$$.tk_ck||$option$$.tk_ck||"52111";$option$$.tk_gv=$pt$$.tk_gv||$option$$.tk_gv||"6321";$option$$.tk_cp_gh=$pt$$.tk_cp_gh||$option$$.tk_cp_gh||"6418";$option$$.tk_cp_bh=$pt$$.tk_cp_bh||$option$$.tk_cp_bh||$option$$.tk_ck;$option$$.tk_cp_ctv=$pt$$.tk_cp_ctv||$option$$.tk_cp_ctv;$option$$.tk_cn_ctv=$pt$$.tk_cn_ctv||$option$$.tk_cn_ctv;$pt$$.ten&&0<=$pt$$.ten.indexOf("COD")?
80
- $option$$.ma_kh=$obj$$.nhan_vien_giao_hang||$obj$$.don_vi_vc||$pt$$.ma_kh||$obj$$.ma_kh:$option$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh;$obj$$.details.forEach($detail$$=>{$detail$$.ma_thue&&$detail$$.tk_thue_co_treo?($detail$$.tien_ct=($detail$$.tien_hang-($detail$$.tien_ck||0))/(1+$detail$$.thue_suat/100),$detail$$.tien_ct_nt=($detail$$.tien_hang_nt-($detail$$.tien_ck_nt||0))/(1+$detail$$.thue_suat/100),$detail$$.gia_ban_ct=Math.roundBy($detail$$.tien_ct/($detail$$.sl_xuat||1)),$detail$$.gia_ban_ct_nt=
81
- Math.roundBy($detail$$.tien_ct_nt/($detail$$.sl_xuat||1)),$detail$$.tien_ct=$detail$$.sl_xuat*$detail$$.gia_ban_ct,$detail$$.tien_ct_nt=$detail$$.sl_xuat*$detail$$.gia_ban_ct_nt,$detail$$.tien_thue=Math.roundBy($detail$$.tien_ct*$detail$$.thue_suat/100),$detail$$.tien_thue_nt=Math.roundBy($detail$$.tien_ct_nt*$detail$$.thue_suat/100)):($detail$$.tien_ck_ct_nt=$detail$$.tien_ck_nt,$detail$$.tien_ck_ct=$detail$$.tien_ck,$detail$$.tien_thue=0,$detail$$.tien_thue_nt=0,$detail$$.tien_ct=$detail$$.tien,
82
- $detail$$.tien_ct_nt=$detail$$.tien_nt)});const $details$$=[];$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$=$obj$$.details.map($a$$=>($a$$.tien_hang_nt||0)-($a$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0)-(($obj$$.tt_tien_thuong||0)+($obj$$.tien_ck_hd||0)+($obj$$.tien_evoucher||0));let $tien_paymentByPoints$$=$obj$$.tien_paymentByPoints||0;const $hoachtoandtvathue$$=($tk_tien$$,$ty_le$$)=>{$obj$$.details.forEach(function($d$jscomp$37_detail$$){$d$jscomp$37_detail$$=
83
- {...$d$jscomp$37_detail$$};$d$jscomp$37_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$37_detail$$.tk_no=$tk_tien$$;$d$jscomp$37_detail$$.ma_kh_co=$obj$$.ma_kh;$d$jscomp$37_detail$$.ma_kh_no=$option$$.ma_kh;$d$jscomp$37_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$37_detail$$.tien=$d$jscomp$37_detail$$.tien_nt=Math.roundBy($d$jscomp$37_detail$$.tien_ct_nt*$ty_le$$);$d$jscomp$37_detail$$.flag="DT_"+($d$jscomp$37_detail$$.ma_vt||"");$details$$.push($d$jscomp$37_detail$$)});$obj$$.details.filter($d$$=>
84
- $d$$.tien_thue).forEach($detail$$=>{$detail$$={...$detail$$};$detail$$.tk_no=$tk_tien$$;$detail$$.tk_co=$detail$$.tk_thue_co_treo;$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tien=$detail$$.tien_nt=Math.roundBy($detail$$.tien_thue_nt*$ty_le$$);$detail$$.flag="THUE_"+($detail$$.ma_vt||"");$details$$.push($detail$$)});console.log("post socai",$tk_tien$$,$ty_le$$)};$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$&&($hoachtoandtvathue$$($option$$.tk_cn,
85
- $tien_paymentByPoints$$/$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$),$hoachtoandtvathue$$($option$$.tk_tien,($rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$-$tien_paymentByPoints$$)/$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$));$obj$$.details.filter($d$$=>$d$$.diem_thuong&&$d$$.tk_km_no&&$d$$.tk_km_co).forEach(function($d$$){let $detail$$={...$d$$};$detail$$.tk_co=$option$$.tk_km_co||
86
- $d$$.tk_km_co;$detail$$.tk_no=$option$$.tk_km_no||$d$$.tk_km_no;$detail$$.ma_kh=$obj$$.ma_kh;$detail$$.tien=$detail$$.tien_nt=$detail$$.diem_thuong*$he_so_qd$$;$details$$.push($detail$$)});$obj$$.ctcpbhs&&$obj$$.ctcpbhs.forEach(function($d$jscomp$41_detail$$){$d$jscomp$41_detail$$={...$d$jscomp$41_detail$$};$d$jscomp$41_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$41_detail$$.tk_no=$option$$.tk_cn;$d$jscomp$41_detail$$.ma_kh_co=$obj$$.ma_kh;$d$jscomp$41_detail$$.ma_kh_no=$option$$.ma_kh;$d$jscomp$41_detail$$.ngay_ct=
87
- $obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$41_detail$$.tien_nt=$d$jscomp$41_detail$$.tien_cp_nt;$d$jscomp$41_detail$$.tien=$d$jscomp$41_detail$$.tien_cp;$details$$.push($d$jscomp$41_detail$$)});$obj$$.tien_phi_vc&&($rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$={},$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tk_co=$option$$.tk_dt,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tk_no=
88
- $option$$.tk_cn,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tien_nt=$obj$$.tien_phi_vc||0,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tien=$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tien_nt,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.ma_kh_co=$obj$$.ma_kh,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.ma_kh_no=
89
- $obj$$.nhan_vien_giao_hang||$obj$$.don_vi_vc,$details$$.push($rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$));$obj$$.tien_freeship&&($rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$={},$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tk_no=$option$$.tk_cp_gh,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tk_co=$option$$.tk_cn,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tien_nt=
90
- $obj$$.tien_freeship||0,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tien=$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tien_nt,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.ma_kh_no=$obj$$.ma_kh,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$));
91
- $obj$$.tt_tien_thuong&&($rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$={},$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tk_no=$option$$.tk_cp_bh,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tk_co=$option$$.tk_cn,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tien_nt=$obj$$.tt_tien_thuong||0,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tien=
92
- $rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tien_nt,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.ma_kh_no=$obj$$.ma_kh,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$));$obj$$.thu_nhap_ctv&&$option$$.tk_cp_ctv&&$option$$.tk_cn_ctv&&($rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$=
93
- {},$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tk_no=$option$$.tk_cp_ctv,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tk_co=$option$$.tk_cn_ctv,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tien_nt=$obj$$.thu_nhap_ctv||0,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tien=$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tien_nt,
94
- $rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.ma_kh=$obj$$.ma_ctv,$details$$.push($rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$));$obj$$.tien_evoucher&&($rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$={},$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tk_no=$obj$$.tk_no_evoucher||$option$$.tk_no_evoucher||$option$$.tk_ck,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tk_co=
95
- $obj$$.tk_co_evoucher||$option$$.tk_co_evoucher||$option$$.tk_cn,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tien_nt=$obj$$.tien_evoucher||0,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tien=$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tien_nt,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.ma_kh_no=$obj$$.ma_kh,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.ma_kh_co=
96
- $option$$.ma_kh,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.check_balance=!1,$details$$.push($rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$));$obj$$.tien_ck_hd&&($rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$={},$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tk_no=$option$$.tk_ck,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tk_co=
97
- $option$$.tk_cn,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tien_nt=$obj$$.tien_ck_hd||0,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tien=$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tien_nt,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.ma_kh_no=$obj$$.ma_kh,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.ma_kh_co=
98
- $option$$.ma_kh,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.check_balance=!1,$details$$.push($rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$));$obj$$.tien_hoa_hong&&$obj$$.ma_kh_hoa_hong&&($rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$={},$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tk_no=$obj$$.tk_no_hoa_hong||$error$$.tk_no_hoa_hong||options.tk_no_hoa_hong,
99
- $rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tk_co=$obj$$.tk_co_hoa_hong||$error$$.tk_co_hoa_hong||options.tk_co_hoa_hong,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tien_nt=$obj$$.tien_hoa_hong,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tien=$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.tien_nt*($obj$$.ty_gia||1),$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.ma_kh=
100
- $obj$$.ma_kh_hoa_hong,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.ma_nv=$obj$$.ma_nv,$rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$.check_balance=!1,$details$$.push($rs$jscomp$6_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$$));let $details_tienvon$$=[...$obj$$.details];$details_tienvon$$.joinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["tk_vt","gia_mua","tk_gv","tg_tk"]},()=>{$details_tienvon$$.forEach(function($d$jscomp$42_detail$$){$d$jscomp$42_detail$$=
101
- {...$d$jscomp$42_detail$$};$d$jscomp$42_detail$$.tk_no=$option$$.tk_gv;$d$jscomp$42_detail$$.ma_kh=$obj$$.ma_kh;$d$jscomp$42_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$42_detail$$.tk_co=$d$jscomp$42_detail$$.tk_vt||"1561";$d$jscomp$42_detail$$.tien_nt=$d$jscomp$42_detail$$.tien_xuat_nt;$d$jscomp$42_detail$$.tien=$d$jscomp$42_detail$$.tien_xuat;$d$jscomp$42_detail$$.tg_tk||($d$jscomp$42_detail$$.tien=$d$jscomp$42_detail$$.tien_nt=0);$details$$.push($d$jscomp$42_detail$$)});(new PostSocai($obj$$,
102
- $details$$,null,Socaitmp)).run(function($e$$,$rs$$){console.log("post result",$rs$$);$callback$$($e$$,$rs$$)})})})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};$contr_router$$.creating=async function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);if(!$obj$$.ma_kh){let $kh$$=await customer.findOne({id_app:$obj$$.id_app||$user$$.current_id_app,of_user:$user$$.email},{ma_kh:-1});$kh$$&&($obj$$.ma_kh=$kh$$.ma_kh)}delete $obj$$.virtual_payment_client_url;await $obj$$.details.asyncJoinModel2($user$$.current_id_app,
80
+ module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,requireRecaptchaToken:!1,unique:["so_ct"],sort:{ngay_ct:-1,so_ct:-1},onEmitEvent:async($obj$$,$users_will_receive$$,$next$$)=>{$obj$$.user_nv_giao_hang&&$users_will_receive$$.push($obj$$.user_nv_giao_hang);$next$$(null,$users_will_receive$$)}});$contr_router$$.route();$contr_router$$.saving=async($user$$,$obj$$)=>{await chietkhauhd($obj$$);await khuyenmaihd($obj$$);await hoahonghdnv($obj$$);
81
+ await hoahonghdgt($obj$$)};$contr_router$$.handleAfterPayment=async $obj$$=>{let $app$$=await App.findOne({_id:$obj$$.id_app});$app$$.wallet_address&&$app$$.wallet_token&&$obj$$.details&&await Promise.all($obj$$.details.filter($d$$=>$d$$.is_coin&&!$d$$.transferred&&$d$$.wallet_receiver).map($detail$$=>(async()=>{let $memo$$=$obj$$.dien_giai||"",$amount$$=$detail$$.sl_xuat,$denom$$=$detail$$.ma_vt.toLowerCase(),$rs$$=await blockchainconnect.spend($obj$$.id_app,$app$$.wallet_token,$app$$.wallet_address,
82
+ $detail$$.wallet_receiver,{amount:$amount$$,denom:$denom$$,memo:$memo$$});console.log("buy point result",$rs$$,$amount$$,$denom$$,$memo$$);$detail$$.transferred=!0})()));$obj$$.trang_thai_tt="5";await model.updateOne({_id:$obj$$._id},{details:$obj$$.details,trang_thai_tt:"5"});let $ctrlSO1$$=global.controllers.SO1;$ctrlSO1$$&&controller.postData($obj$$,$ctrlSO1$$,$e$$=>{if($e$$)return console.error($e$$);controller.pushNotification($ctrlSO1$$,$obj$$)});return null};$contr_router$$.post=async function($obj$$,
83
+ $fn$$){$fn$$||($fn$$=function(){});let $he_so_qd$$=await currency.getRate($obj$$.id_app,$obj$$.ma_nt)||1;const $appInfo$$=await global.getModel("app").findOne({_id:$obj$$.id_app}).lean();await $obj$$.details.asyncJoinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["ma_thue","gia_mua"]});await $obj$$.details.filter($d$$=>$d$$.ma_thue).asyncJoinModel2($obj$$.id_app,global.getModel("vat"),{where:"ma_thue",fields:["thue_suat","tk_thue_co","tk_thue_co_treo"]});async.series({post_sokho:function($callback$jscomp$0$$){const $details$$=
84
+ [];$obj$$.details.forEach($d$$=>{$details$$.push({...$d$$})});let $data_post$$=$details$$.map($detail$$=>$detail$$.combo&&0<$detail$$.combo.length?$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat*=$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*$item$$.gia_von_nt;$item$$.tien_hang=$item$$.tien_hang_nt=$item$$.sl_xuat*$item$$.gia_ban_nt;$item$$.tien_ck=$item$$.tien_ck_nt*=$item$$.sl_xuat;$item$$.tien=$item$$.tien_nt=$item$$.tien_hang_nt-
85
+ $item$$.tien_ck_nt;return $item$$}):[$detail$$]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);(new PostBook($obj$$,$data_post$$,Sokho,async function($detail$$,$callback$$){$detail$$.nxt=2;$detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$detail$$.ma_kho=$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})},post_socai:function($callback$$){options.findOne({id_app:$obj$$.id_app,id_func:ma_ct.toLowerCase()}).lean().exec(async($error$$,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$)=>
86
+ {let $option$$;$option$$=$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$?$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.option||{}:{};($error$$=await dmkho.findOne({id_app:$obj$$.id_app,ma_kho:$obj$$.ma_kho}).lean())||($error$$={});let $pt$$;$obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan)&&($pt$$=await ptthanhtoan.findOne({id_app:$obj$$.id_app,_id:$obj$$.pt_thanh_toan}).lean());
87
+ $pt$$=$pt$$||{};$pt$$.tk_tien=$pt$$.tk_cn;$pt$$.tk_cn=$pt$$.tk_cn||$error$$.tk_cn;$pt$$.tk_dt=$error$$.tk_dt||$pt$$.tk_dt;$pt$$.tk_gv=$error$$.tk_gv||$pt$$.tk_gv;$pt$$.tk_ck=$error$$.tk_ck||$pt$$.tk_ck;$pt$$.tk_cp_gh=$error$$.tk_cp_gh||$pt$$.tk_cp_gh;$pt$$.tk_cp_bh=$error$$.tk_cp_bh||$pt$$.tk_cp_bh;$pt$$.tk_cp_ctv=$error$$.tk_cp_ctv||$pt$$.tk_cp_ctv;$pt$$.tk_cn_ctv=$error$$.tk_cn_ctv||$pt$$.tk_cn_ctv;$option$$.tk_tien=$pt$$.tk_tien||$error$$.tk_tien||$option$$.tk_tien||"1111";$option$$.tk_cn=$pt$$.tk_cn||
88
+ $option$$.tk_cn||"131111";$option$$.tk_dt=$pt$$.tk_dt||$option$$.tk_dt||"51111";$option$$.tk_tl=$pt$$.tk_tl||$option$$.tk_tl||"52131";$option$$.tk_ck=$pt$$.tk_ck||$option$$.tk_ck||"52111";$option$$.tk_gv=$pt$$.tk_gv||$option$$.tk_gv||"6321";$option$$.tk_cp_gh=$pt$$.tk_cp_gh||$option$$.tk_cp_gh||"6418";$option$$.tk_cp_bh=$pt$$.tk_cp_bh||$option$$.tk_cp_bh||$option$$.tk_ck;$option$$.tk_cp_ctv=$pt$$.tk_cp_ctv||$option$$.tk_cp_ctv;$option$$.tk_cn_ctv=$pt$$.tk_cn_ctv||$option$$.tk_cn_ctv;$pt$$.ten&&0<=
89
+ $pt$$.ten.indexOf("COD")?$option$$.ma_kh=$obj$$.nhan_vien_giao_hang||$obj$$.don_vi_vc||$pt$$.ma_kh||$obj$$.ma_kh:$option$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh;$obj$$.details.forEach($detail$$=>{$detail$$.ma_thue&&$detail$$.tk_thue_co_treo?($detail$$.tien_ct=($detail$$.tien_hang-($detail$$.tien_ck||0))/(1+$detail$$.thue_suat/100),$detail$$.tien_ct_nt=($detail$$.tien_hang_nt-($detail$$.tien_ck_nt||0))/(1+$detail$$.thue_suat/100),$detail$$.gia_ban_ct=Math.roundBy($detail$$.tien_ct/($detail$$.sl_xuat||1)),
90
+ $detail$$.gia_ban_ct_nt=Math.roundBy($detail$$.tien_ct_nt/($detail$$.sl_xuat||1)),$detail$$.tien_ct=$detail$$.sl_xuat*$detail$$.gia_ban_ct,$detail$$.tien_ct_nt=$detail$$.sl_xuat*$detail$$.gia_ban_ct_nt,$detail$$.tien_thue=Math.roundBy($detail$$.tien_ct*$detail$$.thue_suat/100),$detail$$.tien_thue_nt=Math.roundBy($detail$$.tien_ct_nt*$detail$$.thue_suat/100)):($detail$$.tien_ck_ct_nt=$detail$$.tien_ck_nt,$detail$$.tien_ck_ct=$detail$$.tien_ck,$detail$$.tien_thue=0,$detail$$.tien_thue_nt=0,$detail$$.tien_ct=
91
+ $detail$$.tien,$detail$$.tien_ct_nt=$detail$$.tien_nt)});const $details$$=[];$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$=$obj$$.details.map($a$$=>($a$$.tien_hang_nt||0)-($a$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0)-(($obj$$.tt_tien_thuong||0)+($obj$$.tien_ck_hd||0)+($obj$$.tien_evoucher||0));let $tien_paymentByPoints$$=$obj$$.tien_paymentByPoints||0;const $hoachtoandtvathue$$=($tk_tien$$,$ty_le$$)=>{$obj$$.details.forEach(function($d$jscomp$35_detail$$){$d$jscomp$35_detail$$=
92
+ {...$d$jscomp$35_detail$$};$d$jscomp$35_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$35_detail$$.tk_no=$tk_tien$$;$d$jscomp$35_detail$$.ma_kh_co=$obj$$.ma_kh;$d$jscomp$35_detail$$.ma_kh_no=$option$$.ma_kh;$d$jscomp$35_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$35_detail$$.tien=$d$jscomp$35_detail$$.tien_nt=Math.roundBy($d$jscomp$35_detail$$.tien_ct_nt*$ty_le$$);$d$jscomp$35_detail$$.flag="DT_"+($d$jscomp$35_detail$$.ma_vt||"");$details$$.push($d$jscomp$35_detail$$)});$obj$$.details.filter($d$$=>
93
+ $d$$.tien_thue).forEach($detail$$=>{$detail$$={...$detail$$};$detail$$.tk_no=$tk_tien$$;$detail$$.tk_co=$detail$$.tk_thue_co_treo;$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tien=$detail$$.tien_nt=Math.roundBy($detail$$.tien_thue_nt*$ty_le$$);$detail$$.flag="THUE_"+($detail$$.ma_vt||"");$details$$.push($detail$$)});console.log("post socai",$tk_tien$$,$ty_le$$)};$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$&&($hoachtoandtvathue$$($option$$.tk_cn,
94
+ $tien_paymentByPoints$$/$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$),$hoachtoandtvathue$$($option$$.tk_tien,($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$-$tien_paymentByPoints$$)/$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));$obj$$.details.filter($d$$=>$d$$.diem_thuong&&$d$$.tk_km_no&&$d$$.tk_km_co).forEach(function($d$$){let $detail$$={...$d$$};
95
+ $detail$$.tk_co=$option$$.tk_km_co||$d$$.tk_km_co;$detail$$.tk_no=$option$$.tk_km_no||$d$$.tk_km_no;$detail$$.ma_kh=$obj$$.ma_kh;$detail$$.tien=$detail$$.tien_nt=$detail$$.diem_thuong*$he_so_qd$$;$details$$.push($detail$$)});$obj$$.ctcpbhs&&$obj$$.ctcpbhs.forEach(function($d$jscomp$39_detail$$){$d$jscomp$39_detail$$={...$d$jscomp$39_detail$$};$d$jscomp$39_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$39_detail$$.tk_no=$option$$.tk_cn;$d$jscomp$39_detail$$.ma_kh_co=$obj$$.ma_kh;$d$jscomp$39_detail$$.ma_kh_no=
96
+ $option$$.ma_kh;$d$jscomp$39_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$39_detail$$.tien_nt=$d$jscomp$39_detail$$.tien_cp_nt;$d$jscomp$39_detail$$.tien=$d$jscomp$39_detail$$.tien_cp;$details$$.push($d$jscomp$39_detail$$)});$obj$$.tien_phi_vc&&($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$option$$.tk_dt,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=
97
+ $option$$.tk_cn,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=$obj$$.tien_phi_vc||0,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_co=$obj$$.ma_kh,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_no=
98
+ $obj$$.nhan_vien_giao_hang||$obj$$.don_vi_vc,$details$$.push($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));$obj$$.tien_freeship&&($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=$option$$.tk_cp_gh,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=
99
+ $option$$.tk_cn,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=$obj$$.tien_freeship||0,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_no=$obj$$.ma_kh,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_co=
100
+ $option$$.ma_kh,$details$$.push($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));$obj$$.tt_tien_thuong&&($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=$option$$.tk_cp_bh,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$option$$.tk_cn,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=
101
+ $obj$$.tt_tien_thuong||0,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_no=$obj$$.ma_kh,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_co=$option$$.ma_kh,$details$$.push($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));
102
+ $obj$$.thu_nhap_ctv&&$option$$.tk_cp_ctv&&$option$$.tk_cn_ctv&&($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=$option$$.tk_cp_ctv,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$option$$.tk_cn_ctv,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=
103
+ $obj$$.thu_nhap_ctv||0,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh=$obj$$.ma_ctv,$details$$.push($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));$obj$$.tien_evoucher&&($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$=
104
+ {},$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=$obj$$.tk_no_evoucher||$option$$.tk_no_evoucher||$option$$.tk_ck,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$obj$$.tk_co_evoucher||$option$$.tk_co_evoucher||$option$$.tk_cn,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=$obj$$.tien_evoucher||0,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=
105
+ $rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_no=$obj$$.ma_kh,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_co=$option$$.ma_kh,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.check_balance=!1,$details$$.push($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));
106
+ $obj$$.tien_ck_hd&&($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=$option$$.tk_ck,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$option$$.tk_cn,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=$obj$$.tien_ck_hd||0,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=
107
+ $rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_no=$obj$$.ma_kh,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh_co=$option$$.ma_kh,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.check_balance=!1,$details$$.push($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));
108
+ $obj$$.tien_hoa_hong&&$obj$$.ma_kh_hoa_hong&&($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=$obj$$.tk_no_hoa_hong||$error$$.tk_no_hoa_hong||options.tk_no_hoa_hong,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$obj$$.tk_co_hoa_hong||$error$$.tk_co_hoa_hong||options.tk_co_hoa_hong,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=
109
+ $obj$$.tien_hoa_hong,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt*($obj$$.ty_gia||1),$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh=$obj$$.ma_kh_hoa_hong,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_nv=$obj$$.ma_nv,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.check_balance=
110
+ !1,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no&&$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co&&$details$$.push($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));$obj$$.tien_hoa_hong_gt&&$obj$$.ma_kh_hoa_hong_gt&&($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$={},$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no=
111
+ $obj$$.tk_no_hoa_hong_gt||$error$$.tk_no_hoa_hong_gt||options.tk_no_hoa_hong_gt,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co=$obj$$.tk_co_hoa_hong_gt||$error$$.tk_co_hoa_hong_gt||options.tk_co_hoa_hong_gt,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt=$obj$$.tien_hoa_hong_gt,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien=$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tien_nt*
112
+ ($obj$$.ty_gia||1),$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_kh=$obj$$.ma_kh_hoa_hong_gt,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.ma_nv=$obj$$.ma_nv,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.check_balance=!1,$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_no&&$rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$.tk_co&&
113
+ $details$$.push($rs$jscomp$5_t_tt_tt_tt$jscomp$1_tt$jscomp$2_tt$jscomp$3_tt$jscomp$4_tt$jscomp$5_tt$jscomp$6_tt$$));let $details_tienvon$$=[...$obj$$.details];$details_tienvon$$.joinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["tk_vt","gia_mua","tk_gv","tg_tk"]},()=>{$details_tienvon$$.forEach(function($d$jscomp$40_detail$$){$d$jscomp$40_detail$$={...$d$jscomp$40_detail$$};$d$jscomp$40_detail$$.tk_no=$option$$.tk_gv;$d$jscomp$40_detail$$.ma_kh=$obj$$.ma_kh;$d$jscomp$40_detail$$.ngay_ct=$obj$$.ngay_giao_hang||
114
+ $obj$$.ngay_ct;$d$jscomp$40_detail$$.tk_co=$d$jscomp$40_detail$$.tk_vt||"1561";$d$jscomp$40_detail$$.tien_nt=$d$jscomp$40_detail$$.tien_xuat_nt;$d$jscomp$40_detail$$.tien=$d$jscomp$40_detail$$.tien_xuat;$d$jscomp$40_detail$$.tg_tk||($d$jscomp$40_detail$$.tien=$d$jscomp$40_detail$$.tien_nt=0);$details$$.push($d$jscomp$40_detail$$)});(new PostSocai($obj$$,$details$$,null,Socaitmp)).run(function($e$$,$rs$$){console.log("post result",$rs$$);$callback$$($e$$,$rs$$)})})})},thanhtoanhoahongnv:$callback$$=>
115
+ {if($obj$$.da_chuyen_hoa_hong||!$obj$$.tien_hoa_hong||!$obj$$.user_nv||!$obj$$.chuyen_ngay)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_nhan_vien$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_nv,wallet_type:1});if(!$wallet_nhan_vien$$){$wallet_nhan_vien$$=(new global.getModel("asskey"))({user_created:$obj$$.user_nv,username:$obj$$.user_nv,id_app:$obj$$.id_app,
116
+ wallet_type:1});const $wallet$$=await DirectSecp256k1HdWallet.generate(24,{prefix:configs.ADDRESS_PREFIX});let $accounts$$=await $wallet$$.getAccounts();$wallet_nhan_vien$$.address=$accounts$$[0].address;$wallet_nhan_vien$$.mnemonic=$wallet$$.mnemonic;$wallet_nhan_vien$$.name="T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng";await $wallet_nhan_vien$$.save()}let $amount$$=$obj$$.tien_hoa_hong,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;
117
+ await spend($appInfo$$,$obj$$.be_introduced,$wallet_nhan_vien$$.address,$amount$$,$denom$$,$memo$$,"","2");$obj$$.da_chuyen_hoa_hong=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",$e$$)}$callback$$()})},thanhtoanhoahonggt:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_gt||!$obj$$.tien_hoa_hong_gt||!$obj$$.user_gt||!$obj$$.chuyen_ngay_gt)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&
118
+ $appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_gt$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_gt,wallet_type:1});if(!$wallet_gt$$){$wallet_gt$$=(new global.getModel("asskey"))({user_created:$obj$$.user_gt,username:$obj$$.user_gt,id_app:$obj$$.id_app,wallet_type:1});const $wallet$$=await DirectSecp256k1HdWallet.generate(24,{prefix:configs.ADDRESS_PREFIX});let $accounts$$=await $wallet$$.getAccounts();$wallet_gt$$.address=
119
+ $accounts$$[0].address;$wallet_gt$$.mnemonic=$wallet$$.mnemonic;$wallet_gt$$.name="T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng";await $wallet_gt$$.save()}let $amount$$=$obj$$.tien_hoa_hong_gt,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_gt$$.address,$amount$$,$denom$$,$memo$$,$obj$$.introduce_code,"2");$obj$$.da_chuyen_hoa_hong_gt=
120
+ !0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong_gt:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",$e$$)}$callback$$()})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};$contr_router$$.creating=async function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);if(!$obj$$.ma_kh){let $kh$$=await customer.findOne({id_app:$obj$$.id_app||$user$$.current_id_app,of_user:$user$$.email},{ma_kh:-1});$kh$$&&($obj$$.ma_kh=$kh$$.ma_kh)}delete $obj$$.virtual_payment_client_url;
121
+ $obj$$.da_chuyen_hoa_hong=!1;$obj$$.da_chuyen_hoa_hong_gt=!1;await $obj$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",fields:["combo"]});$obj$$.details.forEach($detail$$=>{$detail$$.combo&&0<$detail$$.combo.length&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat*=$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien_hang=$item$$.tien_hang_nt=$item$$.sl_xuat*
122
+ ($item$$.gia_ban_nt||0);$item$$.tien_ck=$item$$.tien_ck_nt=$item$$.sl_xuat*($item$$.tien_ck_nt||0);$item$$.tien=$item$$.tien_nt=$item$$.tien_hang_nt-($item$$.tien_ck_nt||0);return $item$$}))});valid($user$$,$obj$$,async $error$$=>{if($error$$)return $next$$($error$$);if(!$obj$$.paymentByPoints)return $next$$(null,$obj$$);try{if(await getPointBalance($user$$.current_id_app,$obj$$.of_user||$user$$.email)<$obj$$.paymentByPoints)return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 \u0111\u1ee7 \u0111i\u1ec3m \u0111\u1ec3 th\u1ef1c hi\u1ec7n giao d\u1ecbch n\u00e0y.");
123
+ $next$$(null,$obj$$)}catch($e$$){$next$$($e$$.message)}})};$contr_router$$.created=async function($user$$,$obj$$,$next$$){if($obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan))try{const $pt_thanh_toan$$=await global.getModel("ptthanhtoan").findOne({_id:$obj$$.pt_thanh_toan});if($pt_thanh_toan$$.payment_service){let $paymentServiceModel$$=global.getModel($pt_thanh_toan$$.payment_service);$obj$$.amount=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0);if($obj$$.amount&&
124
+ $paymentServiceModel$$.createVirtualPaymentClientURL){let $virtual_payment_client_url$$=await $paymentServiceModel$$.createVirtualPaymentClientURL($obj$$,$user$$.clientIp,$pt_thanh_toan$$);$obj$$.virtual_payment_client_url=$virtual_payment_client_url$$;$obj$$.payment_service=$pt_thanh_toan$$.payment_service;$obj$$.payment_id=((await $paymentServiceModel$$.findOne({$or:[{id_ct:$obj$$._id.toString(),order_id:$obj$$._id.toString()}]})||{})._id||"").toString()}else $obj$$.virtual_payment_client_url="",
125
+ $obj$$.payment_service="",$obj$$.payment_id=""}else $obj$$.virtual_payment_client_url=""}catch($e$$){return console.error($e$$),$next$$("Kh\u00f4ng tao li\u00ean k\u1ebft thanh to\u00e1n:"+($e$$.message||$e$$.error||$e$$))}else console.log("Chua nhap phuong thuc thanh toan"),$obj$$.virtual_payment_client_url="";model.findOneAndUpdate({_id:$obj$$._id},{virtual_payment_client_url:$obj$$.virtual_payment_client_url},$e$$=>{$e$$&&(console.error($e$$),console.log("error create Virtual Payment ClientURL",
126
+ $e$$.message))});await createTransactionPayment($obj$$);await createTransactionBonus($obj$$);$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.updating=async($user$$,$data$$,$obj$$,$next$$)=>{$data$$.details||($data$$.details=$obj$$.details);$data$$.da_chuyen_hoa_hong=$obj$$.da_chuyen_hoa_hong;$data$$.da_chuyen_hoa_hong_gt=$obj$$.da_chuyen_hoa_hong_gt;await $data$$.details.asyncJoinModel2($user$$.current_id_app,
103
127
  dmvt,{where:"ma_vt",fields:["combo"]});$obj$$.details.forEach($detail$$=>{$detail$$.combo&&0<$detail$$.combo.length&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat*=$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien_hang=$item$$.tien_hang_nt=$item$$.sl_xuat*($item$$.gia_ban_nt||0);$item$$.tien_ck=$item$$.tien_ck_nt=$item$$.sl_xuat*($item$$.tien_ck_nt||0);$item$$.tien=
104
- $item$$.tien_nt=$item$$.tien_hang_nt-($item$$.tien_ck_nt||0);return $item$$}))});valid($user$$,$obj$$,async $error$$=>{if($error$$)return $next$$($error$$);if(!$obj$$.paymentByPoints)return $next$$(null,$obj$$);try{if(await getPointBalance($user$$.current_id_app,$obj$$.of_user||$user$$.email)<$obj$$.paymentByPoints)return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 \u0111\u1ee7 \u0111i\u1ec3m \u0111\u1ec3 th\u1ef1c hi\u1ec7n giao d\u1ecbch n\u00e0y.");$next$$(null,$obj$$)}catch($e$$){$next$$($e$$.message)}})};
105
- $contr_router$$.created=async function($user$$,$obj$$,$next$$){if($obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan))try{const $pt_thanh_toan$$=await global.getModel("ptthanhtoan").findOne({_id:$obj$$.pt_thanh_toan});if($pt_thanh_toan$$.payment_service){let $paymentServiceModel$$=global.getModel($pt_thanh_toan$$.payment_service);$obj$$.amount=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0);if($obj$$.amount&&$paymentServiceModel$$.createVirtualPaymentClientURL){let $virtual_payment_client_url$$=
106
- await $paymentServiceModel$$.createVirtualPaymentClientURL($obj$$,$user$$.clientIp,$pt_thanh_toan$$);$obj$$.virtual_payment_client_url=$virtual_payment_client_url$$;$obj$$.payment_service=$pt_thanh_toan$$.payment_service;$obj$$.payment_id=((await $paymentServiceModel$$.findOne({$or:[{id_ct:$obj$$._id.toString(),order_id:$obj$$._id.toString()}]})||{})._id||"").toString()}else $obj$$.virtual_payment_client_url="",$obj$$.payment_service="",$obj$$.payment_id=""}else $obj$$.virtual_payment_client_url=
107
- ""}catch($e$$){return console.error($e$$),$next$$("Kh\u00f4ng tao li\u00ean k\u1ebft thanh to\u00e1n:"+($e$$.message||$e$$.error||$e$$))}else console.log("Chua nhap phuong thuc thanh toan"),$obj$$.virtual_payment_client_url="";model.findOneAndUpdate({_id:$obj$$._id},{virtual_payment_client_url:$obj$$.virtual_payment_client_url},$e$$=>{$e$$&&(console.error($e$$),console.log("error create Virtual Payment ClientURL",$e$$.message))});await createTransactionPayment($obj$$);await createTransactionBonus($obj$$);
108
- $obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.updating=async($user$$,$data$$,$obj$$,$next$$)=>{$data$$.details||($data$$.details=$obj$$.details);await $data$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",fields:["combo"]});$obj$$.details.forEach($detail$$=>{$detail$$.combo&&0<$detail$$.combo.length&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():
109
- {...$item$$};$item$$.sl_xuat*=$detail$$.sl_xuat;$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien_hang=$item$$.tien_hang_nt=$item$$.sl_xuat*($item$$.gia_ban_nt||0);$item$$.tien_ck=$item$$.tien_ck_nt=$item$$.sl_xuat*($item$$.tien_ck_nt||0);$item$$.tien=$item$$.tien_nt=$item$$.tien_hang_nt-($item$$.tien_ck_nt||0);return $item$$}))});$data$$.pt_thanh_toan&&$data$$.pt_thanh_toan!=$obj$$.pt_thanh_toan&&($data$$.virtual_payment_client_url="",$data$$.payment_service=
110
- "",$data$$.payment_id="");$data$$.evouchers=$data$$.evouchers||$obj$$.evouchers||[];valid($user$$,$data$$,async $error$$=>{if($error$$)return $next$$($error$$);if(($obj$$.paymentByPoints||0)!==($data$$.paymentByPoints||0))return $next$$("B\u1ea1n kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt s\u1ed1 \u0111i\u1ec3m thanh to\u00e1n.");await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"});$next$$(null,$data$$,$obj$$)},$obj$$)};$contr_router$$.updated=async function($evouchers_user$$,$obj$$,$next$$){if(!$obj$$.virtual_payment_client_url&&
111
- ("1"===$obj$$.trang_thai||"0"===$obj$$.trang_thai)){if($obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan))try{const $pt_thanh_toan$$=await global.getModel("ptthanhtoan").findOne({_id:$obj$$.pt_thanh_toan});if($pt_thanh_toan$$.payment_service){let $paymentServiceModel$$=global.getModel($pt_thanh_toan$$.payment_service);$obj$$.amount=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0);if($obj$$.amount&&$paymentServiceModel$$.createVirtualPaymentClientURL){let $virtual_payment_client_url$$=
112
- await $paymentServiceModel$$.createVirtualPaymentClientURL($obj$$,$evouchers_user$$.clientIp,$pt_thanh_toan$$);$obj$$.virtual_payment_client_url=$virtual_payment_client_url$$;$obj$$.payment_service=$pt_thanh_toan$$.payment_service;$obj$$.payment_id=((await $paymentServiceModel$$.findOne({$or:[{id_ct:$obj$$._id.toString()},{order_id:$obj$$._id.toString()}]})||{})._id||"").toString()}else $obj$$.virtual_payment_client_url="",$obj$$.payment_service="",$obj$$.payment_id=""}else $obj$$.virtual_payment_client_url=
113
- ""}catch($e$$){return console.error($e$$),$next$$("Error create Virtual Payment ClientURL:"+($e$$.message||$e$$.error||$e$$))}else $obj$$.virtual_payment_client_url="";model.findOneAndUpdate({_id:$obj$$._id},{virtual_payment_client_url:$obj$$.virtual_payment_client_url},$e$$=>{$e$$&&console.log("error create Virtual Payment ClientURL",$e$$.message)})}"9"===$obj$$.trang_thai?(await transaction.deleteTrans({id_ct:$obj$$._id.toString()}),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},
114
- "Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng"),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"})):(await createTransactionPayment($obj$$),createTransactionBonus($obj$$));await Evoucher.updateMany({id_ct_used:$obj$$._id.toString()},{id_ct_used:null});$evouchers_user$$=await Evoucher.find({id_ct_useds:$obj$$._id.toString()});await Promise.all($evouchers_user$$.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>
115
- updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.deleting=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.deleted=async function($user$$,$obj$$,$next$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng");await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"});$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>
116
- deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.view=function($user$$,$items$$,$fn$$){async.series({app:function($callback$$){$items$$.filter($item$$=>$item$$.id_app).joinModel2(null,App,[{where:{id_app:"_id"},fields:{name_app:"name"}}],function(){$callback$$()})},kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2(null,customer,[{where:$item$$=>({id_app:$item$$.id_app,ma_kh:$item$$.ma_kh}),fields:"ten_kh"}],function(){$callback$$()})},
117
- nhan_vien_giao_hang:function($callback$$){$items$$.filter($item$$=>$item$$.nhan_vien_giao_hang).joinModel2(null,customer,[{where:{nhan_vien_giao_hang:"ma_kh"},fields:[{ten_nhan_vien_giao_hang:"ten_kh"}]}],function(){$callback$$()})},nv_giao_hang:function($callback$$){$items$$.filter($item$$=>$item$$.user_nv_giao_hang).joinModel2(null,User,{where:{user_nv_giao_hang:"email"},fields:{ten_nv_giao_hang:"name"}},function(){$callback$$()})},kho:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kho).joinModel2(null,
118
- dmkho,[{where:$item$$=>({id_app:$item$$.id_app,ma_kho:$item$$.ma_kho}),fields:["ten_kho",{tk_cn_kho:"tk_cn"}]}],function(){$callback$$()})},trangthai:function($callback$$){$items$$.filter($item$$=>$item$$.trang_thai).joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["ten_trang_thai","color"]}],function(){$callback$$()})},ptthanhtoan:function($callback$$){$items$$.filter($item$$=>$item$$.pt_thanh_toan).joinModel2(null,ptthanhtoan,[{where:$item$$=>({_id:$item$$.pt_thanh_toan,
119
- id_app:$item$$.id_app}),fields:[{ten_pt_thanh_toan:"ten"},{tk_cn_thanhtoan:"tk_cn"}]}],function(){$callback$$()})},pt1:function($callback$$){$items$$.joinModel2(null,pt1,[{where:$item$$=>({id_app:$item$$.id_app,id_so1:"_id"}),fields:[{id_pt1:"_id"},{so_ct_pt1:"so_ct"},{ma_ct_pt1:"ma_ct"},{ngay_ct_pt1:"ngay_ct"}]}],function(){$callback$$()})},t_tien:function($callback$$){$items$$.filter($item$$=>$item$$.details).forEach(function($r$$){$r$$.tien_phi_vc=$r$$.tien_phi_vc||0;$r$$.tien_freeship=$r$$.tien_freeship||
120
- 0;$r$$.details?($r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_tien_hang=$r$$.details.csum("tien_hang"),$r$$.t_tien_hang_nt=$r$$.details.csum("tien_hang_nt"),$r$$.t_tien=$r$$.t_tien_hang-$r$$.details.csum("tien_ck"),$r$$.t_tien_nt=$r$$.t_tien_hang_nt-$r$$.details.csum("tien_ck_nt"),$r$$.t_ck_nt=$r$$.t_ck=$r$$.tien_ck_hd+($r$$.tien_evoucher||0)):($r$$.t_sl=0,$r$$.t_tien_hang=0,$r$$.t_tien_hang_nt=0,$r$$.t_ck=0,$r$$.t_ck_nt=0,$r$$.t_tien=$r$$.t_tien_hang,$r$$.t_tien_nt=$r$$.t_tien_hang_nt);$r$$.ctcpbhs?
121
- ($r$$.t_cp_cpb_nt=$r$$.ctcpbhs.csum("tien_cp_nt"),$r$$.t_cp_cpb=$r$$.ctcpbhs.csum("tien_cp")):($r$$.t_cp_cpb_nt=0,$r$$.t_cp_cpb=0);$r$$.t_tt=$r$$.t_tt_nt=Math.max(0,$r$$.t_tien_nt+$r$$.t_cp_cpb_nt-$r$$.t_ck_nt-($r$$.tt_tien_thuong||0)+($r$$.tien_phi_vc||0)-($r$$.tien_freeship||0))});$callback$$()},details_vt:function($callback$$){async.each($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.joinModel2(null,dmvt,[{where:$item$$=>({id_app:$r$$.id_app,
122
- ma_vt:$item$$.ma_vt}),fields:"ten_vt ten_vt_eng picture chieu_cao chieu_rong chieu_sau trong_luong".split(" ")}],function(){$callback1$$()})},function(){$callback$$()})},details_tt1:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.filter($item$$=>$item$$.ma_tt1).joinModel2(null,dmtt,[{where:$item$$=>({id_app:$r$$.id_app,ma_vt:$item$$.ma_vt,ma_tt1:$item$$.ma_tt1}),setFields:($item$$,$ref$$)=>{$item$$.ten_vt=$item$$.ten_vt+" - "+$ref$$.ten_tt}}],function(){$callback1$$()})},
123
- function(){$callback$$()})},details_dt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.filter($item$$=>$item$$.ma_dt).joinModel2(null,dmdt,[{where:$item$$=>({id_app:$r$$.id_app,ma_dt:$item$$.ma_dt}),fields:["ten_dt"]}],function(){$callback1$$()})},function(){$callback$$()})},details_contract:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;
124
- if(!$details$$)return $callback1$$();$details$$.filter($item$$=>$item$$.ma_hd).joinModel2(null,contract,[{where:$item$$=>({id_app:$r$$.id_app,so_hd:$item$$.ma_hd}),fields:["ten_hd"]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.filter($item$$=>$item$$.ma_phi).joinModel2(null,dmphi,[{where:$item$$=>({id_app:$r$$.id_app,ma_phi:$item$$.ma_phi}),
125
- fields:["ten_phi"]}],function(){$callback1$$()})},function(){$callback$$()})},details_cpbh:function($callback$$){async.each($items$$,function($r$$,$callback1$$){let $ctcpbhs$$=$r$$.ctcpbhs;if(!$ctcpbhs$$)return $callback1$$();$ctcpbhs$$?$ctcpbhs$$.filter($item$$=>$item$$.ma_cp).joinModel2(null,dmcpmh,[{where:$item$$=>({id_app:$r$$.id_app,ma_cp:$item$$.ma_cp}),fields:["ten_cp"]}],function(){$callback1$$()}):$callback1$$()},function(){$callback$$()})}},function(){$fn$$(null,$items$$)})}};
128
+ $item$$.tien_nt=$item$$.tien_hang_nt-($item$$.tien_ck_nt||0);return $item$$}))});$data$$.pt_thanh_toan&&$data$$.pt_thanh_toan!=$obj$$.pt_thanh_toan&&($data$$.virtual_payment_client_url="",$data$$.payment_service="",$data$$.payment_id="");$data$$.evouchers=$data$$.evouchers||$obj$$.evouchers||[];valid($user$$,$data$$,async $error$$=>{if($error$$)return $next$$($error$$);if(($obj$$.paymentByPoints||0)!==($data$$.paymentByPoints||0))return $next$$("B\u1ea1n kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt s\u1ed1 \u0111i\u1ec3m thanh to\u00e1n.");
129
+ await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"});$next$$(null,$data$$,$obj$$)},$obj$$)};$contr_router$$.updated=async function($evouchers_user$$,$obj$$,$next$$){if(!$obj$$.virtual_payment_client_url&&("1"===$obj$$.trang_thai||"0"===$obj$$.trang_thai)){if($obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan))try{const $pt_thanh_toan$$=await global.getModel("ptthanhtoan").findOne({_id:$obj$$.pt_thanh_toan});if($pt_thanh_toan$$.payment_service){let $paymentServiceModel$$=
130
+ global.getModel($pt_thanh_toan$$.payment_service);$obj$$.amount=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0);if($obj$$.amount&&$paymentServiceModel$$.createVirtualPaymentClientURL){let $virtual_payment_client_url$$=await $paymentServiceModel$$.createVirtualPaymentClientURL($obj$$,$evouchers_user$$.clientIp,$pt_thanh_toan$$);$obj$$.virtual_payment_client_url=$virtual_payment_client_url$$;$obj$$.payment_service=$pt_thanh_toan$$.payment_service;$obj$$.payment_id=((await $paymentServiceModel$$.findOne({$or:[{id_ct:$obj$$._id.toString()},
131
+ {order_id:$obj$$._id.toString()}]})||{})._id||"").toString()}else $obj$$.virtual_payment_client_url="",$obj$$.payment_service="",$obj$$.payment_id=""}else $obj$$.virtual_payment_client_url=""}catch($e$$){return console.error($e$$),$next$$("Error create Virtual Payment ClientURL:"+($e$$.message||$e$$.error||$e$$))}else $obj$$.virtual_payment_client_url="";model.findOneAndUpdate({_id:$obj$$._id},{virtual_payment_client_url:$obj$$.virtual_payment_client_url},$e$$=>{$e$$&&console.log("error create Virtual Payment ClientURL",
132
+ $e$$.message)})}"9"===$obj$$.trang_thai?(await transaction.deleteTrans({id_ct:$obj$$._id.toString()}),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng"),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"})):(await createTransactionPayment($obj$$),createTransactionBonus($obj$$));await Evoucher.updateMany({id_ct_used:$obj$$._id.toString()},{id_ct_used:null});$evouchers_user$$=await Evoucher.find({id_ct_useds:$obj$$._id.toString()});
133
+ await Promise.all($evouchers_user$$.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.deleting=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.deleted=async function($user$$,$obj$$,$next$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},
134
+ "Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng");await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":buy"});$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$next$$(null,$obj$$)};$contr_router$$.view=function($user$$,$items$$,$fn$$){async.series({app:function($callback$$){$items$$.filter($item$$=>$item$$.id_app).joinModel2(null,App,[{where:{id_app:"_id"},fields:{name_app:"name"}}],function(){$callback$$()})},kh:function($callback$$){$items$$.filter($item$$=>
135
+ $item$$.ma_kh).joinModel2(null,customer,[{where:$item$$=>({id_app:$item$$.id_app,ma_kh:$item$$.ma_kh}),fields:"ten_kh"}],function(){$callback$$()})},nhan_vien_giao_hang:function($callback$$){$items$$.filter($item$$=>$item$$.nhan_vien_giao_hang).joinModel2(null,customer,[{where:{nhan_vien_giao_hang:"ma_kh"},fields:[{ten_nhan_vien_giao_hang:"ten_kh"}]}],function(){$callback$$()})},nv_giao_hang:function($callback$$){$items$$.filter($item$$=>$item$$.user_nv_giao_hang).joinModel2(null,User,{where:{user_nv_giao_hang:"email"},
136
+ fields:{ten_nv_giao_hang:"name"}},function(){$callback$$()})},kho:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kho).joinModel2(null,dmkho,[{where:$item$$=>({id_app:$item$$.id_app,ma_kho:$item$$.ma_kho}),fields:["ten_kho",{tk_cn_kho:"tk_cn"}]}],function(){$callback$$()})},trangthai:function($callback$$){$items$$.filter($item$$=>$item$$.trang_thai).joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["ten_trang_thai","color"]}],function(){$callback$$()})},
137
+ ptthanhtoan:function($callback$$){$items$$.filter($item$$=>$item$$.pt_thanh_toan).joinModel2(null,ptthanhtoan,[{where:$item$$=>({_id:$item$$.pt_thanh_toan,id_app:$item$$.id_app}),fields:[{ten_pt_thanh_toan:"ten"},{tk_cn_thanhtoan:"tk_cn"}]}],function(){$callback$$()})},pt1:function($callback$$){$items$$.joinModel2(null,pt1,[{where:$item$$=>({id_app:$item$$.id_app,id_so1:"_id"}),fields:[{id_pt1:"_id"},{so_ct_pt1:"so_ct"},{ma_ct_pt1:"ma_ct"},{ngay_ct_pt1:"ngay_ct"}]}],function(){$callback$$()})},t_tien:function($callback$$){$items$$.filter($item$$=>
138
+ $item$$.details).forEach(function($r$$){$r$$.tien_phi_vc=$r$$.tien_phi_vc||0;$r$$.tien_freeship=$r$$.tien_freeship||0;$r$$.details?($r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_tien_hang=$r$$.details.csum("tien_hang"),$r$$.t_tien_hang_nt=$r$$.details.csum("tien_hang_nt"),$r$$.t_tien=$r$$.t_tien_hang-$r$$.details.csum("tien_ck"),$r$$.t_tien_nt=$r$$.t_tien_hang_nt-$r$$.details.csum("tien_ck_nt"),$r$$.t_ck_nt=$r$$.t_ck=$r$$.tien_ck_hd+($r$$.tien_evoucher||0)):($r$$.t_sl=0,$r$$.t_tien_hang=0,$r$$.t_tien_hang_nt=
139
+ 0,$r$$.t_ck=0,$r$$.t_ck_nt=0,$r$$.t_tien=$r$$.t_tien_hang,$r$$.t_tien_nt=$r$$.t_tien_hang_nt);$r$$.ctcpbhs?($r$$.t_cp_cpb_nt=$r$$.ctcpbhs.csum("tien_cp_nt"),$r$$.t_cp_cpb=$r$$.ctcpbhs.csum("tien_cp")):($r$$.t_cp_cpb_nt=0,$r$$.t_cp_cpb=0);$r$$.t_tt=$r$$.t_tt_nt=Math.max(0,$r$$.t_tien_nt+$r$$.t_cp_cpb_nt-$r$$.t_ck_nt-($r$$.tt_tien_thuong||0)+($r$$.tien_phi_vc||0)-($r$$.tien_freeship||0))});$callback$$()},details_vt:function($callback$$){async.each($items$$,function($r$$,$callback1$$){const $details$$=
140
+ $r$$.details;if(!$details$$)return $callback1$$();$details$$.joinModel2(null,dmvt,[{where:$item$$=>({id_app:$r$$.id_app,ma_vt:$item$$.ma_vt}),fields:"ten_vt ten_vt_eng picture chieu_cao chieu_rong chieu_sau trong_luong".split(" ")}],function(){$callback1$$()})},function(){$callback$$()})},details_tt1:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){$r$$.details.filter($item$$=>$item$$.ma_tt1).joinModel2(null,dmtt,[{where:$item$$=>({id_app:$r$$.id_app,ma_vt:$item$$.ma_vt,
141
+ ma_tt1:$item$$.ma_tt1}),setFields:($item$$,$ref$$)=>{$item$$.ten_vt=$item$$.ten_vt+" - "+$ref$$.ten_tt}}],function(){$callback1$$()})},function(){$callback$$()})},details_dt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.filter($item$$=>$item$$.ma_dt).joinModel2(null,dmdt,[{where:$item$$=>({id_app:$r$$.id_app,ma_dt:$item$$.ma_dt}),fields:["ten_dt"]}],function(){$callback1$$()})},function(){$callback$$()})},
142
+ details_contract:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();$details$$.filter($item$$=>$item$$.ma_hd).joinModel2(null,contract,[{where:$item$$=>({id_app:$r$$.id_app,so_hd:$item$$.ma_hd}),fields:["ten_hd"]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details;if(!$details$$)return $callback1$$();
143
+ $details$$.filter($item$$=>$item$$.ma_phi).joinModel2(null,dmphi,[{where:$item$$=>({id_app:$r$$.id_app,ma_phi:$item$$.ma_phi}),fields:["ten_phi"]}],function(){$callback1$$()})},function(){$callback$$()})},details_cpbh:function($callback$$){async.each($items$$,function($r$$,$callback1$$){let $ctcpbhs$$=$r$$.ctcpbhs;if(!$ctcpbhs$$)return $callback1$$();$ctcpbhs$$?$ctcpbhs$$.filter($item$$=>$item$$.ma_cp).joinModel2(null,dmcpmh,[{where:$item$$=>({id_app:$r$$.id_app,ma_cp:$item$$.ma_cp}),fields:["ten_cp"]}],
144
+ function(){$callback1$$()}):$callback1$$()},function(){$callback$$()})}},function(){$fn$$(null,$items$$)})}};
@@ -1,8 +1,8 @@
1
1
  'use strict';const _global=require("../global"),async=require("async"),model=global.getModel("app"),fs=require("fs"),path=require("path"),moment=require("moment"),zip=(new require("node-zip"))();require("../libs/prototypes.js");const Participant=global.getModel("participant"),{parentPort,workerData}=require("worker_threads");let connect2Db=!1;
2
- const backup=$data$$=>{const $configs$$=$data$$.configs||require("../configs");connect2Db||(mongoose.connect($configs$$.database.url,{useNewUrlParser:!0}),connect2Db=!0);let $id_app$$=$data$$.id,$dateFrom$$=$data$$.dateFrom,$dateTo$$=$data$$.dateTo,$back_app_info$$=$data$$.back_app_info;$dateFrom$$?$dateFrom$$=moment(new Date($dateFrom$$)).startOf("date"):($dateFrom$$=moment(),$dateFrom$$.year(1900));$dateTo$$?$dateTo$$=moment(new Date($dateTo$$)).endOf("date"):($dateTo$$=moment(),$dateTo$$.year(2999));
3
- let $user$$=$data$$.user;model.findOne({_id:$id_app$$}).lean().exec(async($e_par$$,$app$$)=>{if($e_par$$||!$app$$)return parentPort.postMessage({error:$e_par$$||"C\u00f4ng ty n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i"});$e_par$$=await Participant.findOne({email:$user$$,id_app:$id_app$$,admin:!0});if($app$$.user_created!==$user$$&&!$e_par$$)return parentPort.postMessage({error:"B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n th\u1ef1c hi\u1ec7n t\u00e1c v\u1ee5 n\u00e0y"});let $data$$={};$back_app_info$$&&($data$$["app.js"]=
4
- $app$$);async.parallel({data:$callback$jscomp$0$$=>{mongoose.connection.db.listCollections().toArray(($err$$,$collections$$)=>{if($err$$)return $callback$jscomp$0$$($err$$);const $collection_need_backup$$=$collections$$.filter($c$$=>"users"!==$c$$.name&&"apps"!==$c$$.name&&"logs"!==$c$$.name&&"rights"!==$c$$.name&&"participants"!==$c$$.name);console.info("Prepare backup",$collection_need_backup$$.length,"collections");const $backed$$=[];async.mapSeries($collection_need_backup$$,($collection$$,$callback$$)=>
5
- {let $query$$={id_app:$id_app$$};$query$$.$or=[{ngay_ct:null},{ngay_ct:{$gte:$dateFrom$$.toDate(),$lte:$dateTo$$.toDate()}}];console.log("backup",$collection$$.name);mongoose.connection.db.collection($collection$$.name,($err$$,$coll$$)=>{if($err$$)return $callback$$($err$$);$coll$$.find($query$$).toArray(($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);$rs$$.forEach(($r$$,$index$$)=>{$r$$.id_backup=$r$$._id.toString();$collection$$.name.includes("sokho")&&($r$$.line=$index$$);$collection$$.name.includes("socai")&&
6
- ($r$$.nh_dk=$index$$)});console.info("Backup success",$collection$$.name,$rs$$.length,"row(s)");$backed$$.push($collection$$.name);console.info("Backed",$backed$$.length,"/",$collection_need_backup$$.length,"collection(s)");$data$$[$collection$$.name]=$rs$$;$callback$$()})})},$e$$=>{$e$$&&console.error($e$$);$callback$jscomp$0$$($e$$)})})}},$e$jscomp$0$$=>{if($e$jscomp$0$$)return console.error("Error backup database",$e$jscomp$0$$),parentPort.postMessage({error:$e$jscomp$0$$});$e$jscomp$0$$=new Date;
7
- fs.existsSync(path.dirname(__dirname)+"/backup")||fs.mkdirSync(path.dirname(__dirname)+"/backup");console.log("zip data...");try{zip.file("backup.json",JSON.stringify($data$$));const $dataZipped$$=zip.generate({base64:!1,compression:"DEFLATE"});let $fileZip$$=$app$$._id+"-"+$e$jscomp$0$$.getFullYear()+"-"+($e$jscomp$0$$.getMonth()+1)+"-"+$e$jscomp$0$$.getMinutes()+".zip";console.log("write datazipped to file ",$fileZip$$);fs.writeFileSync(path.dirname(__dirname)+"/backup/"+$fileZip$$,$dataZipped$$,
8
- "binary");parentPort.postMessage({file:$fileZip$$})}catch($e$$){parentPort.postMessage({error:$e$$})}})})};parentPort.on("message",$data$$=>{backup($data$$)});workerData&&workerData.id&&backup(workerData);
2
+ const _=require("lodash"),backup=$data$$=>{if($data$$.configs&&_.isString($data$$.configs))try{$data$$.configs=JSON.parse($data$$.configs)}catch($e$$){delete $data$$.configs,console.info($e$$)}const $configs$$=$data$$.configs||require("../configs");connect2Db||(mongoose.connect($configs$$.database.url,{useNewUrlParser:!0}),connect2Db=!0);let $id_app$$=$data$$.id,$dateFrom$$=$data$$.dateFrom,$dateTo$$=$data$$.dateTo,$back_app_info$$=$data$$.back_app_info;$dateFrom$$?$dateFrom$$=moment(new Date($dateFrom$$)).startOf("date"):
3
+ ($dateFrom$$=moment(),$dateFrom$$.year(1900));$dateTo$$?$dateTo$$=moment(new Date($dateTo$$)).endOf("date"):($dateTo$$=moment(),$dateTo$$.year(2999));let $user$$=$data$$.user;model.findOne({_id:$id_app$$}).lean().exec(async($e$jscomp$1$$,$app$$)=>{if($e$jscomp$1$$||!$app$$)return parentPort.postMessage({error:$e$jscomp$1$$||"C\u00f4ng ty n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i"});$e$jscomp$1$$=await Participant.findOne({email:$user$$,id_app:$id_app$$,admin:!0});if($app$$.user_created!==$user$$&&!$e$jscomp$1$$)return parentPort.postMessage({error:"B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n th\u1ef1c hi\u1ec7n t\u00e1c v\u1ee5 n\u00e0y"});
4
+ let $data$$={};$back_app_info$$&&($data$$["app.js"]=$app$$);async.parallel({data:$callback$jscomp$0$$=>{mongoose.connection.db.listCollections().toArray(($err$$,$collections$$)=>{if($err$$)return $callback$jscomp$0$$($err$$);const $collection_need_backup$$=$collections$$.filter($c$$=>"users"!==$c$$.name&&"apps"!==$c$$.name&&"logs"!==$c$$.name&&"rights"!==$c$$.name&&"participants"!==$c$$.name);console.info("Prepare backup",$collection_need_backup$$.length,"collections");const $backed$$=[];async.mapSeries($collection_need_backup$$,
5
+ ($collection$$,$callback$$)=>{let $query$$={id_app:$id_app$$};$query$$.$or=[{ngay_ct:null},{ngay_ct:{$gte:$dateFrom$$.toDate(),$lte:$dateTo$$.toDate()}}];console.log("backup",$collection$$.name);mongoose.connection.db.collection($collection$$.name,($err$$,$coll$$)=>{if($err$$)return $callback$$($err$$);$coll$$.find($query$$).toArray(($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);$rs$$.forEach(($r$$,$index$$)=>{$r$$.id_backup=$r$$._id.toString();$collection$$.name.includes("sokho")&&($r$$.line=$index$$);
6
+ $collection$$.name.includes("socai")&&($r$$.nh_dk=$index$$)});console.info("Backup success",$collection$$.name,$rs$$.length,"row(s)");$backed$$.push($collection$$.name);console.info("Backed",$backed$$.length,"/",$collection_need_backup$$.length,"collection(s)");$data$$[$collection$$.name]=$rs$$;$callback$$()})})},$e$$=>{$e$$&&console.error($e$$);$callback$jscomp$0$$($e$$)})})}},$e$jscomp$0$$=>{if($e$jscomp$0$$)return console.error("Error backup database",$e$jscomp$0$$),parentPort.postMessage({error:$e$jscomp$0$$});
7
+ $e$jscomp$0$$=new Date;fs.existsSync(path.dirname(__dirname)+"/backup")||fs.mkdirSync(path.dirname(__dirname)+"/backup");console.log("zip data...");try{zip.file("backup.json",JSON.stringify($data$$));const $dataZipped$$=zip.generate({base64:!1,compression:"DEFLATE"});let $fileZip$$=$app$$._id+"-"+$e$jscomp$0$$.getFullYear()+"-"+($e$jscomp$0$$.getMonth()+1)+"-"+$e$jscomp$0$$.getMinutes()+".zip";console.log("write datazipped to file ",$fileZip$$);fs.writeFileSync(path.dirname(__dirname)+"/backup/"+
8
+ $fileZip$$,$dataZipped$$,"binary");parentPort.postMessage({file:$fileZip$$})}catch($e$$){parentPort.postMessage({error:$e$$})}})})};parentPort.on("message",$data$$=>{backup($data$$)});workerData&&workerData.id&&backup(workerData);
File without changes
@@ -1,5 +1,8 @@
1
- 'use strict';const _global=require("../global"),async=require("async"),group=global.getModel("group"),{parentPort,workerData}=require("worker_threads"),prototypes=require("../libs/prototypes.js");
1
+ 'use strict';const _global=require("../global"),async=require("async"),group=global.getModel("group"),{parentPort,workerData}=require("worker_threads"),prototypes=require("../libs/prototypes.js"),_=require("lodash");
2
2
  let onImport=function($user$$,$data$$,$columns$$,$next$$){$data$$.groupBy("group_name",[],function($e$$,$gs$$){if($e$$)return $next$$($e$$);async.mapSeries($gs$$,($r$$,$callback$$)=>{if(!$r$$.group_name)return $callback$$();$r$$.group_name=$r$$.group_name.toString().trim();group.findOneAndUpdate({id_app:$user$$.current_id_app,group_type:"CUSTOMER",group_name:$r$$.group_name},{group_name:$r$$.group_name,group_type:"CUSTOMER",status:!0},{new:!0,upsert:!0},function($e$$,$n$$){if($e$$)return $callback$$($e$$);
3
3
  $r$$.nh_kh=$n$$._id.toString();$callback$$(null)})},$e$jscomp$0$$=>{if($e$jscomp$0$$)return $next$$($e$jscomp$0$$);async.mapSeries($data$$,function($r$$,$callback$jscomp$0$$){async.parallel({nhom:function($callback$$){$r$$.group_name&&!$r$$.nh_kh?($r$$.group_name=$r$$.group_name.toString().trim(),group.findOne({id_app:$user$$.current_id_app,group_type:"CUSTOMER",group_name:$r$$.group_name},function($e$$,$n$$){if($e$$)return $callback$$($e$$);$r$$.nh_kh=$n$$._id.toString();$callback$$(null)})):$callback$$()}},
4
- function($e$$){$callback$jscomp$0$$($e$$)})},function($e$$){$next$$($e$$,$data$$)})})})},connect2Db=!1;parentPort.on("message",$msg$$=>{if($msg$$&&$msg$$.user){console.log("worker handle data customer...");var $configs$$=$msg$$.configs||require("../configs");connect2Db||(mongoose.connect($configs$$.database.url,{useNewUrlParser:!0}),connect2Db=!0);onImport($msg$$.user,$msg$$.data,$msg$$.columns,function($e$$,$data$$){parentPort.postMessage({error:$e$$,data:$data$$,columns:$msg$$.columns})})}else parentPort.postMessage({error:"msg is not valid"})});
5
- if(workerData&&workerData.configs&&workerData.data){console.log("worker handle data dmkh...");const $configs$$=workerData.configs||require("../configs");mongoose.connect($configs$$.database.url,{useNewUrlParser:!0});onImport(workerData.user,workerData.data,workerData.columns,function($e$$,$data$$){parentPort.postMessage({error:$e$$,data:$data$$,columns:workerData.columns})})};
4
+ function($e$$){$callback$jscomp$0$$($e$$)})},function($e$$){$next$$($e$$,$data$$)})})})},connect2Db=!1;
5
+ parentPort.on("message",$msg$$=>{if($msg$$&&$msg$$.user){console.log("worker handle data customer...");if($msg$$.configs&&_.isString($msg$$.configs))try{$msg$$.configs=JSON.parse($msg$$.configs)}catch($e$$){delete $msg$$.configs,console.info($e$$)}var $configs$$=$msg$$.configs||require("../configs");connect2Db||(mongoose.connect($configs$$.database.url,{useNewUrlParser:!0}),connect2Db=!0);onImport($msg$$.user,$msg$$.data,$msg$$.columns,function($e$$,$data$$){parentPort.postMessage({error:$e$$,data:$data$$,
6
+ columns:$msg$$.columns})})}else parentPort.postMessage({error:"msg is not valid"})});
7
+ if(workerData&&workerData.configs&&workerData.data){console.log("worker handle data dmkh...");if(workerData.configs&&_.isString(workerData.configs))try{workerData.configs=JSON.parse(workerData.configs)}catch($e$$){delete workerData.configs,console.info($e$$)}const $configs$$=workerData.configs||require("../configs");mongoose.connect($configs$$.database.url,{useNewUrlParser:!0});onImport(workerData.user,workerData.data,workerData.columns,function($e$$,$data$$){parentPort.postMessage({error:$e$$,data:$data$$,
8
+ columns:workerData.columns})})};
@@ -1,7 +1,9 @@
1
- 'use strict';const _global=require("../global"),async=require("async"),Dmdvt=global.getModel("dmdvt"),Dmnvt=global.getModel("dmnvt"),{parentPort,workerData}=require("worker_threads"),prototypes=require("../libs/prototypes.js"),onImport=function($user$$,$data$$,$columns$$,$next$$){async.parallel({nvt:$callback$jscomp$0$$=>{$data$$.groupBy("ten_nvt",[],function($e$$,$nvts$$){if($e$$)return $callback$jscomp$0$$($e$$);async.mapSeries($nvts$$,($r$$,$callback$$)=>{if(!$r$$.ten_nvt)return $callback$$(null);
1
+ 'use strict';const _global=require("../global"),async=require("async"),Dmdvt=global.getModel("dmdvt"),Dmnvt=global.getModel("dmnvt"),{parentPort,workerData}=require("worker_threads"),_=require("lodash"),prototypes=require("../libs/prototypes.js"),onImport=function($user$$,$data$$,$columns$$,$next$$){async.parallel({nvt:$callback$jscomp$0$$=>{$data$$.groupBy("ten_nvt",[],function($e$$,$nvts$$){if($e$$)return $callback$jscomp$0$$($e$$);async.mapSeries($nvts$$,($r$$,$callback$$)=>{if(!$r$$.ten_nvt)return $callback$$(null);
2
2
  $r$$.ten_nvt=$r$$.ten_nvt.toString().trim();Dmnvt.findOneAndUpdate({id_app:$user$$.current_id_app,ten_nvt:$r$$.ten_nvt},{ten_nvt:$r$$.ten_nvt,status:!0},{new:!0,upsert:!0},function($e$$){if($e$$)return $callback$$($e$$);$callback$$(null)})},($e$$,$rs$$)=>{$callback$jscomp$0$$($e$$,$rs$$)})})},dvt:$callback$jscomp$0$$=>{$data$$.groupBy(["ma_dvt"],[],function($e$jscomp$0$$,$nvts$$){if($e$jscomp$0$$)return $callback$jscomp$0$$($e$jscomp$0$$);async.mapSeries($nvts$$,($r$$,$callback$$)=>{if(!$r$$.ma_dvt)return $callback$$(null);
3
3
  $r$$.ma_dvt=$r$$.ma_dvt.toString().trim();Dmdvt.findOneAndUpdate({id_app:$user$$.current_id_app,ma_dvt:$r$$.ma_dvt},{ma_dvt:$r$$.ma_dvt,ten_dvt:$r$$.ma_dvt,status:!0},{new:!0,upsert:!0},function($e$$){if($e$$)return $callback$$($e$$);$callback$$(null)})},($e$$,$rs$$)=>{$callback$jscomp$0$$($e$$,$rs$$)})})}},$e$jscomp$0$$=>{if($e$jscomp$0$$)return $next$$($e$jscomp$0$$);async.mapSeries($data$$,function($r$$,$callback0$$){async.parallel({nhom:function($callback$$){$r$$.ten_nvt&&!$r$$.ma_nvt?($r$$.ten_nvt=
4
4
  $r$$.ten_nvt.toString().trim(),Dmnvt.findOne({id_app:$user$$.current_id_app,ten_nvt:$r$$.ten_nvt},function($e$$,$n$$){if($e$$)return $callback$$($e$$);if(!$n$$)return console.log("nhom",$r$$.ten_nvt,"khong ton tai"),$callback$$(null);$r$$.ma_nvt=$n$$._id.toString();$callback$$(null)})):$callback$$()},dvt:function($callback$$){$r$$.ma_dvt?($r$$.ma_dvt=$r$$.ma_dvt.toString().trim(),Dmdvt.findOne({id_app:$user$$.current_id_app,ma_dvt:$r$$.ma_dvt},function($e$$,$n$$){if($e$$)return $callback$$($e$$);
5
5
  if(!$n$$)return console.log("dvt",$r$$.ma_dvt,"khong ton tai"),$callback$$(null);$r$$.ma_dvt=$n$$.ma_dvt;$callback$$(null)})):$callback$$()}},function(){$callback0$$(null,$r$$)})},function($e$$,$rs$$){$next$$($e$$,$rs$$)})})};let connect2Db=!1;
6
- parentPort.on("message",$msg$$=>{if($msg$$&&$msg$$.user){console.log("worker handle data dmvt...");var $configs$$=$msg$$.configs||require("../configs");connect2Db||(mongoose.connect($configs$$.database.url,{useNewUrlParser:!0}),connect2Db=!0);onImport($msg$$.user,$msg$$.data,$msg$$.columns,function($e$$,$data$$){parentPort.postMessage({error:$e$$,data:$data$$,columns:$msg$$.columns})})}else parentPort.postMessage({error:"msg is not valid"})});
7
- if(workerData&&workerData.configs&&workerData.data){console.log("worker handle data dmvt...");const $configs$$=workerData.configs||require("../configs");mongoose.connect($configs$$.database.url,{useNewUrlParser:!0});onImport(workerData.user,workerData.data,workerData.columns,function($e$$,$data$$){parentPort.postMessage({error:$e$$,data:$data$$,columns:workerData.columns})})};
6
+ parentPort.on("message",$msg$$=>{if($msg$$&&$msg$$.user){console.log("worker handle data dmvt...");if($msg$$.configs&&_.isString($msg$$.configs))try{$msg$$.configs=JSON.parse($msg$$.configs)}catch($e$$){delete $msg$$.configs,console.info($e$$)}var $configs$$=$msg$$.configs||require("../configs");connect2Db||(mongoose.connect($configs$$.database.url,{useNewUrlParser:!0}),connect2Db=!0);onImport($msg$$.user,$msg$$.data,$msg$$.columns,function($e$$,$data$$){parentPort.postMessage({error:$e$$,data:$data$$,
7
+ columns:$msg$$.columns})})}else parentPort.postMessage({error:"msg is not valid"})});
8
+ if(workerData&&workerData.configs&&workerData.data){console.log("worker handle data dmvt...");if(workerData.configs&&_.isString(workerData.configs))try{workerData.configs=JSON.parse(workerData.configs)}catch($e$$){delete workerData.configs,console.info($e$$)}const $configs$$=workerData.configs||require("../configs");mongoose.connect($configs$$.database.url,{useNewUrlParser:!0});onImport(workerData.user,workerData.data,workerData.columns,function($e$$,$data$$){parentPort.postMessage({error:$e$$,data:$data$$,
9
+ columns:workerData.columns})})};
File without changes
@@ -1,3 +1,4 @@
1
- 'use strict';const express=require("express"),app=express(),{parentPort,workerData}=require("worker_threads"),handleImport=$msg$$=>{try{let $module$$=global.controllers[$msg$$.module.trim()];$module$$?$module$$.import($msg$$.user,$msg$$.id_app,$msg$$.data,($error$$,$rs$$)=>{parentPort.postMessage({error:$error$$,result:$rs$$})},{replace:$msg$$.replace}):parentPort.postMessage({error:"Kh\u00f4ng t\u00ecm th\u1ea5y module "+$msg$$.module})}catch($e$$){parentPort.postMessage({error:$e$$})}};let sv=!1;
2
- parentPort.on("message",$msg$$=>{if($msg$$&&$msg$$.user&&$msg$$.module)if(sv)console.info("reuse worker import data...1"),handleImport($msg$$);else{const $configs$$=$msg$$.configs||require("../configs");$configs$$.use_ssl=!1;require("../app")(app,{configs:$configs$$,createServer:!1,start_import_data_pool:!1,lite:!0},()=>{sv=!0;if($msg$$.load)return parentPort.postMessage({rs:"ready"});handleImport($msg$$)})}else parentPort.postMessage({error:"msg is not valid"})});
3
- if(workerData&&workerData.configs){let $msg$$=workerData;if(sv)console.info("reuse worker import data...2"),handleImport($msg$$);else{const $configs$$=$msg$$.configs;$configs$$.use_ssl=!1;require("../app")(app,{configs:$configs$$,createServer:!1,start_import_data_pool:!1,lite:!0},()=>{sv=!0;if($msg$$.load)return parentPort.postMessage({rs:"ready"});handleImport($msg$$)})}};
1
+ 'use strict';const express=require("express"),app=express(),{parentPort,workerData}=require("worker_threads"),_=require("lodash"),handleImport=$msg$$=>{try{let $module$$=global.controllers[$msg$$.module.trim()];$module$$?$module$$.import($msg$$.user,$msg$$.id_app,$msg$$.data,($error$$,$rs$$)=>{parentPort.postMessage({error:$error$$,result:$rs$$})},{replace:$msg$$.replace}):parentPort.postMessage({error:"Kh\u00f4ng t\u00ecm th\u1ea5y module "+$msg$$.module})}catch($e$$){parentPort.postMessage({error:$e$$})}};
2
+ let sv=!1;
3
+ parentPort.on("message",$msg$$=>{if($msg$$&&$msg$$.user&&$msg$$.module)if(sv)console.info("reuse worker import data...1"),handleImport($msg$$);else{if($msg$$.configs&&_.isString($msg$$.configs))try{$msg$$.configs=JSON.parse($msg$$.configs)}catch($e$$){delete $msg$$.configs,console.info($e$$)}const $configs$$=$msg$$.configs||require("../configs");$configs$$.use_ssl=!1;require("../app")(app,{configs:$configs$$,createServer:!1,start_import_data_pool:!1,lite:!0},()=>{sv=!0;if($msg$$.load)return parentPort.postMessage({rs:"ready"});handleImport($msg$$)})}else parentPort.postMessage({error:"msg is not valid"})});
4
+ if(workerData&&workerData.configs){let $msg$$=workerData;if($msg$$.configs&&_.isString($msg$$.configs))try{$msg$$.configs=JSON.parse($msg$$.configs)}catch($e$$){console.info($e$$)}if(sv)console.info("reuse worker import data...2"),handleImport($msg$$);else{const $configs$$=$msg$$.configs;$configs$$.use_ssl=!1;require("../app")(app,{configs:$configs$$,createServer:!1,start_import_data_pool:!1,lite:!0},()=>{sv=!0;if($msg$$.load)return parentPort.postMessage({rs:"ready"});handleImport($msg$$)})}};
@@ -1,9 +1,10 @@
1
- 'use strict';const _global=require("../global"),Endpoint=global.getModel("endpoint"),Payload=global.getModel("payload"),{Expo}=require("expo-server-sdk"),{parentPort,workerData}=require("worker_threads"),redis=require("redis");global.clientRedis=redis.createClient();const prototypes=require("../libs/prototypes.js");let connect2Db=!1;
2
- const pustNotify=async($configs_msg_number_notifi_query_endpoint_vapidKeys$$,$callback$$)=>{const {email:$email$$,data:$data$$,event:$event$$}=$configs_msg_number_notifi_query_endpoint_vapidKeys$$;$configs_msg_number_notifi_query_endpoint_vapidKeys$$=$configs_msg_number_notifi_query_endpoint_vapidKeys$$.configs||global.configs||require("../configs");connect2Db||(mongoose.connect($configs_msg_number_notifi_query_endpoint_vapidKeys$$.database.url,{useNewUrlParser:!0}),{vapidKeys:$configs_msg_number_notifi_query_endpoint_vapidKeys$$}=
3
- $configs_msg_number_notifi_query_endpoint_vapidKeys$$,$configs_msg_number_notifi_query_endpoint_vapidKeys$$?webPush.setVapidDetails("mailto:invncur@gmail.com",$configs_msg_number_notifi_query_endpoint_vapidKeys$$.publicKey,$configs_msg_number_notifi_query_endpoint_vapidKeys$$.privateKey):console.log("use webPush tool to create a vapidKeys and add to configs file. ex: web-push generate-vapid-key --json"),connect2Db=!0);$data$$.title&&($data$$.title=$data$$.title.replace(/<[^>]*>?/gm,""));$data$$.body&&
4
- ($data$$.body=$data$$.body.replace(/<[^>]*>?/gm,""));$configs_msg_number_notifi_query_endpoint_vapidKeys$$=await global.asyncCountNotifications($email$$);let $number_message$$=await global.asyncCountUnRead($email$$),$badge$$=$configs_msg_number_notifi_query_endpoint_vapidKeys$$+$number_message$$;$configs_msg_number_notifi_query_endpoint_vapidKeys$$={user:$email$$,id_app:{$in:[$data$$.id_app,void 0,null,""]}};console.log("query endpoint",$configs_msg_number_notifi_query_endpoint_vapidKeys$$);Endpoint.find($configs_msg_number_notifi_query_endpoint_vapidKeys$$).limit(5).sort({date_create:-1}).lean().exec(async function($e$$,
5
- $eps$$){if($eps$$&&0<$eps$$.length){let $expo$$=new Expo,$messages$$=[];$eps$$.forEach(function($ep$$){if(Expo.isExpoPushToken($ep$$.endpoint))$messages$$.push({to:$ep$$.endpoint,sound:"default",badge:$badge$$,title:$data$$.title,body:$data$$.body!==$data$$.title?$data$$.body:"",data:$data$$,channelId:$data$$.channel||"default"});else try{const $pushSubscription$$=JSON.parse($ep$$.endpoint);if($pushSubscription$$.endpoint){let $options$$={},$ep_id$$=Buffer.from($ep$$.endpoint).toString("base64");
6
- (new Payload({ep_id:$ep_id$$,endpoint:$ep$$.endpoint,user:$email$$,payload:JSON.stringify($data$$)})).save(function($e$jscomp$2$$){if($e$jscomp$2$$)return console.error($e$jscomp$2$$);webPush.sendNotification($pushSubscription$$,JSON.stringify($data$$),$options$$).then(function(){console.log("web push success",$email$$,$event$$)},function($e$jscomp$0$$){console.error("error web push:",$email$$,$event$$,$e$jscomp$0$$);Endpoint.deleteOne({endpoint:$ep$$.endpoint},$e$$=>{console.log("deleted error endpoint",
7
- {endpoint:$ep$$.endpoint},$e$$)})})})}else Endpoint.deleteOne({endpoint:$ep$$.endpoint},$e$$=>{console.log("deleted error endpoint",{endpoint:$ep$$.endpoint},$e$$)})}catch($e$jscomp$0$$){console.error($e$jscomp$0$$),Endpoint.deleteOne({endpoint:$ep$$.endpoint},$e$$=>{console.log("deleted error endpoint",{endpoint:$ep$$.endpoint},$e$$)})}});$messages$$.forEach($message$$=>{let $chunks$$=$expo$$.chunkPushNotifications([$message$$]),$tickets$$=[];(async()=>{for(let $chunk$$ of $chunks$$)try{console.log("mobile push",
8
- $email$$,$event$$);let $ticketChunk$$=await $expo$$.sendPushNotificationsAsync($chunk$$);0<$ticketChunk$$.length&&"error"===$ticketChunk$$[0].status&&console.error($ticketChunk$$,$message$$);$tickets$$.push(...$ticketChunk$$)}catch($error$$){console.error($error$$)}})()})}$callback$$()})};parentPort.on("message",async $msg$$=>{$msg$$?pustNotify($msg$$,function($e$$){parentPort.postMessage({error:$e$$})}):parentPort.postMessage({error:"msg is not valid"})});
1
+ 'use strict';const _global=require("../global"),Endpoint=global.getModel("endpoint"),Payload=global.getModel("payload"),{Expo}=require("expo-server-sdk"),{parentPort,workerData}=require("worker_threads"),redis=require("redis");global.clientRedis=redis.createClient();const _=require("lodash"),prototypes=require("../libs/prototypes.js");let connect2Db=!1;
2
+ const pustNotify=async($configs_msg_number_notifi_query_endpoint_vapidKeys$$,$callback$$)=>{const {email:$email$$,data:$data$$,event:$event$$}=$configs_msg_number_notifi_query_endpoint_vapidKeys$$;if($configs_msg_number_notifi_query_endpoint_vapidKeys$$.configs&&_.isString($configs_msg_number_notifi_query_endpoint_vapidKeys$$.configs))try{$configs_msg_number_notifi_query_endpoint_vapidKeys$$.configs=JSON.parse($configs_msg_number_notifi_query_endpoint_vapidKeys$$.configs)}catch($e$$){delete $configs_msg_number_notifi_query_endpoint_vapidKeys$$.configs,
3
+ console.info($e$$)}$configs_msg_number_notifi_query_endpoint_vapidKeys$$=$configs_msg_number_notifi_query_endpoint_vapidKeys$$.configs||global.configs||require("../configs");connect2Db||(mongoose.connect($configs_msg_number_notifi_query_endpoint_vapidKeys$$.database.url,{useNewUrlParser:!0}),{vapidKeys:$configs_msg_number_notifi_query_endpoint_vapidKeys$$}=$configs_msg_number_notifi_query_endpoint_vapidKeys$$,$configs_msg_number_notifi_query_endpoint_vapidKeys$$?webPush.setVapidDetails("mailto:invncur@gmail.com",
4
+ $configs_msg_number_notifi_query_endpoint_vapidKeys$$.publicKey,$configs_msg_number_notifi_query_endpoint_vapidKeys$$.privateKey):console.log("use webPush tool to create a vapidKeys and add to configs file. ex: web-push generate-vapid-key --json"),connect2Db=!0);$data$$.title&&($data$$.title=$data$$.title.replace(/<[^>]*>?/gm,""));$data$$.body&&($data$$.body=$data$$.body.replace(/<[^>]*>?/gm,""));$configs_msg_number_notifi_query_endpoint_vapidKeys$$=await global.asyncCountNotifications($email$$);
5
+ let $number_message$$=await global.asyncCountUnRead($email$$),$badge$$=$configs_msg_number_notifi_query_endpoint_vapidKeys$$+$number_message$$;$configs_msg_number_notifi_query_endpoint_vapidKeys$$={user:$email$$,id_app:{$in:[$data$$.id_app,void 0,null,""]}};console.log("query endpoint",$configs_msg_number_notifi_query_endpoint_vapidKeys$$);Endpoint.find($configs_msg_number_notifi_query_endpoint_vapidKeys$$).limit(5).sort({date_create:-1}).lean().exec(async function($e$jscomp$2$$,$eps$$){if($eps$$&&
6
+ 0<$eps$$.length){let $expo$$=new Expo,$messages$$=[];$eps$$.forEach(function($ep$$){if(Expo.isExpoPushToken($ep$$.endpoint))$messages$$.push({to:$ep$$.endpoint,sound:"default",badge:$badge$$,title:$data$$.title,body:$data$$.body!==$data$$.title?$data$$.body:"",data:$data$$,channelId:$data$$.channel||"default"});else try{const $pushSubscription$$=JSON.parse($ep$$.endpoint);if($pushSubscription$$.endpoint){let $options$$={},$ep_id$$=Buffer.from($ep$$.endpoint).toString("base64");(new Payload({ep_id:$ep_id$$,
7
+ endpoint:$ep$$.endpoint,user:$email$$,payload:JSON.stringify($data$$)})).save(function($e$jscomp$1$$){if($e$jscomp$1$$)return console.error($e$jscomp$1$$);webPush.sendNotification($pushSubscription$$,JSON.stringify($data$$),$options$$).then(function(){console.log("web push success",$email$$,$event$$)},function($e$jscomp$0$$){console.error("error web push:",$email$$,$event$$,$e$jscomp$0$$);Endpoint.deleteOne({endpoint:$ep$$.endpoint},$e$$=>{console.log("deleted error endpoint",{endpoint:$ep$$.endpoint},
8
+ $e$$)})})})}else Endpoint.deleteOne({endpoint:$ep$$.endpoint},$e$$=>{console.log("deleted error endpoint",{endpoint:$ep$$.endpoint},$e$$)})}catch($e$jscomp$0$$){console.error($e$jscomp$0$$),Endpoint.deleteOne({endpoint:$ep$$.endpoint},$e$$=>{console.log("deleted error endpoint",{endpoint:$ep$$.endpoint},$e$$)})}});$messages$$.forEach($message$$=>{let $chunks$$=$expo$$.chunkPushNotifications([$message$$]),$tickets$$=[];(async()=>{for(let $chunk$$ of $chunks$$)try{console.log("mobile push",$email$$,
9
+ $event$$);let $ticketChunk$$=await $expo$$.sendPushNotificationsAsync($chunk$$);0<$ticketChunk$$.length&&"error"===$ticketChunk$$[0].status&&console.error($ticketChunk$$,$message$$);$tickets$$.push(...$ticketChunk$$)}catch($error$$){console.error($error$$)}})()})}$callback$$()})};parentPort.on("message",async $msg$$=>{$msg$$?pustNotify($msg$$,function($e$$){parentPort.postMessage({error:$e$$})}):parentPort.postMessage({error:"msg is not valid"})});
9
10
  workerData&&workerData.email&&workerData.data&&workerData.event&&pustNotify(workerData,function($e$$){parentPort.postMessage({error:$e$$})});
@@ -1,3 +1,4 @@
1
- 'use strict';const express=require("express"),app=express(),{parentPort,workerData}=require("worker_threads"),handleReport=$msg$$=>{if(!$msg$$.req)return parentPort.postMessage({error:"Thi\u1ebfu bi\u1ebfn req"});try{let $module$$=global.report_controllers[$msg$$.module];if($module$$)try{$module$$.getData($msg$$.req,($error$$,$rs$$)=>{parentPort.postMessage({error:$error$$,result:$rs$$})})}catch($e$$){parentPort.postMessage({error:$e$$.message})}else parentPort.postMessage({error:"Kh\u00f4ng t\u00ecm th\u1ea5y module "+
2
- $msg$$.module})}catch($e$$){parentPort.postMessage({error:$e$$})}};let sv=!1;parentPort.on("message",$msg$$=>{if($msg$$)if(sv)handleReport($msg$$);else{const $configs$$=$msg$$.configs||require("../configs");$configs$$.use_ssl=!1;require("../app")(app,{configs:$configs$$,createServer:!1,start_import_data_pool:!1,lite:!0},()=>{sv=!0;if($msg$$.load)return parentPort.postMessage({rs:"ready"});handleReport($msg$$)})}else parentPort.postMessage({error:"msg is not valid"})});
3
- if(workerData&&workerData.configs){let $msg$$=workerData;if(sv)handleReport($msg$$);else{const $configs$$=$msg$$.configs;$configs$$.use_ssl=!1;require("../app")(app,{configs:$configs$$,createServer:!1,start_import_data_pool:!1,lite:!0},()=>{sv=!0;if($msg$$.load)return parentPort.postMessage({rs:"ready"});handleReport($msg$$)})}};
1
+ 'use strict';const express=require("express"),app=express(),{parentPort,workerData}=require("worker_threads"),_=require("lodash"),handleReport=$msg$$=>{if(!$msg$$.req)return parentPort.postMessage({error:"Thi\u1ebfu bi\u1ebfn req"});try{let $module$$=global.report_controllers[$msg$$.module];if($module$$)try{$module$$.getData($msg$$.req,($error$$,$rs$$)=>{parentPort.postMessage({error:$error$$,result:$rs$$})})}catch($e$$){parentPort.postMessage({error:$e$$.message})}else parentPort.postMessage({error:"Kh\u00f4ng t\u00ecm th\u1ea5y module "+
2
+ $msg$$.module})}catch($e$$){parentPort.postMessage({error:$e$$})}};let sv=!1;
3
+ parentPort.on("message",$msg$$=>{if($msg$$)if(sv)handleReport($msg$$);else{if($msg$$.configs&&_.isString($msg$$.configs))try{$msg$$.configs=JSON.parse($msg$$.configs)}catch($e$$){delete $msg$$.configs,console.info($e$$)}const $configs$$=$msg$$.configs||require("../configs");$configs$$.use_ssl=!1;require("../app")(app,{configs:$configs$$,createServer:!1,start_import_data_pool:!1,lite:!0},()=>{sv=!0;if($msg$$.load)return parentPort.postMessage({rs:"ready"});handleReport($msg$$)})}else parentPort.postMessage({error:"msg is not valid"})});
4
+ if(workerData&&workerData.configs){let $msg$$=workerData;if(sv)handleReport($msg$$);else{if($msg$$.configs&&_.isString($msg$$.configs))try{$msg$$.configs=JSON.parse($msg$$.configs)}catch($e$$){delete $msg$$.configs,console.info($e$$)}const $configs$$=$msg$$.configs||require("../configs");$configs$$.use_ssl=!1;require("../app")(app,{configs:$configs$$,createServer:!1,start_import_data_pool:!1,lite:!0},()=>{sv=!0;if($msg$$.load)return parentPort.postMessage({rs:"ready"});handleReport($msg$$)})}};
@@ -1,12 +1,12 @@
1
- 'use strict';const _global=require("../global"),async=require("async"),model=global.getModel("app"),Participant=global.getModel("participant"),fs=require("fs"),underscore=require("underscore"),JSZip=require("jszip");require("../libs/prototypes.js");const {parentPort,workerData}=require("worker_threads"),{ObjectId}=require("mongodb");let connect2Db=!1;
1
+ 'use strict';const _global=require("../global"),async=require("async"),model=global.getModel("app"),Participant=global.getModel("participant"),fs=require("fs"),underscore=require("underscore"),JSZip=require("jszip");require("../libs/prototypes.js");const _=require("lodash"),{parentPort,workerData}=require("worker_threads"),{ObjectId}=require("mongodb");let connect2Db=!1;
2
2
  const replaceAll=($data$$,$old_id$$,$new_id$$,$cb$$)=>{async.mapSeries(Object.keys($data$$).filter($k$$=>"user.js"!==$k$$&&"app.js"!==$k$$),($coll$$,$cb$$)=>{$data$$[$coll$$]=$data$$[$coll$$].map($r$$=>$r$$.split($old_id$$).join($new_id$$));$cb$$()},()=>{$cb$$()})},insertOne=($coll$$,$rows$$)=>new Promise(($resolve$$,$reject$$)=>{async.mapSeries($rows$$,($row$$,$callback$$)=>{let $old_id$$=$row$$._id;delete $row$$._id;$coll$$.insertOne($row$$,($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);$callback$$(null,
3
- {old_id:$old_id$$,new_id:$rs$$.insertedId.toString()})})},($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resolve$$($rs$$)})}),insert=($col_name$$,$coll$$,$rows$$,$id_app$$)=>{$rows$$=$rows$$.map($row$$=>{delete $row$$.__v;delete $row$$.pkey;$row$$.id_app=$id_app$$;return $row$$});return insertOne($coll$$,$rows$$)},restore=$message$$=>{const $configs$$=$message$$.configs||require("../configs");connect2Db||(mongoose.connect($configs$$.database.url,{useNewUrlParser:!0}),connect2Db=!0);let $id_app$$=
4
- $message$$.id,$user$$=$message$$.user,$fileZip$$=$message$$.file;model.findOne({_id:$id_app$$}).lean().exec(async($e$jscomp$1$$,$app$$)=>{if($e$jscomp$1$$||!$app$$)return parentPort.postMessage({error:$e$jscomp$1$$||"C\u00f4ng ty n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i"});$e$jscomp$1$$=await Participant.findOne({email:$user$$,id_app:$id_app$$,admin:!0});if($app$$.user_created!==$user$$&&!$e$jscomp$1$$)return parentPort.postMessage({error:"B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n th\u1ef1c hi\u1ec7n t\u00e1c v\u1ee5 n\u00e0y"});
5
- fs.readFile($fileZip$$,($err$$,$dataZip$$)=>{if($err$$)return parentPort.postMessage({error:$err$$});try{JSZip.loadAsync($dataZip$$).then(function($zip$$){return $zip$$.file("backup.json").async("string")}).then($string_data$$=>{if($string_data$$){let $data$$=JSON.parse($string_data$$);async.parallel({app:$callback$$=>{let $appInfo$$=$data$$["app.js"];$appInfo$$?(delete $appInfo$$._id,delete $appInfo$$.__v,console.log("restore app info"),model.findOneAndUpdate({_id:$id_app$$},$appInfo$$,$e$$=>{if($e$$)return $callback$$($e$$);
6
- console.log("app info was restore successfull");$callback$$()})):$callback$$()},data:$callback$jscomp$0$$=>{try{let $colls$$=underscore.keys($data$$).filter($k$$=>"user.js"!==$k$$&&"app.js"!==$k$$);console.log("total collection",$colls$$.length);Promise.all($colls$$.map($col_name$$=>new Promise(($resolve$$,$reject$$)=>{let $rows$$=$data$$[$col_name$$]||[];$rows$$.forEach(($r$$,$index$$)=>{$r$$.index=$index$$});mongoose.connection.db.collection($col_name$$,($err$$,$coll$$)=>{if($err$$)return $reject$$($err$$);
7
- if(!$coll$$)return console.log("can't insert data, collection",$col_name$$,"is not exists"),$resolve$$([]);$coll$$.deleteMany({id_app:$id_app$$},$e$jscomp$0$$=>{if($e$jscomp$0$$)return $reject$$($e$jscomp$0$$);if(0===$rows$$.length)return $resolve$$([]);insert($col_name$$,$coll$$,$rows$$,$id_app$$).then($pairs$$=>{console.log("restored collection",$col_name$$,$rows$$.length);$resolve$$($pairs$$)}).catch($e$$=>{$reject$$($e$$)})})})}))).then($_pairs_pairs$$=>{$_pairs_pairs$$=$_pairs_pairs$$.reduce(($a$$,
8
- $b$$)=>$a$$.concat($b$$),[]);console.log("inserted data");let $data_replace$$=JSON.parse($string_data$$);Object.keys($data_replace$$).filter($k$$=>"user.js"!==$k$$&&"app.js"!==$k$$).forEach($k$$=>{$data_replace$$[$k$$]=$data_replace$$[$k$$].map($r$$=>JSON.stringify($r$$))});async.mapSeries($_pairs_pairs$$,($pair$$,$cb$$)=>{setImmediate(()=>{replaceAll($data_replace$$,$pair$$.old_id,$pair$$.new_id,()=>{console.log("replace pair",$pair$$);$cb$$()})})},()=>{let $colls$$=underscore.keys($data_replace$$).filter($k$$=>
9
- "user.js"!==$k$$&&"app.js"!==$k$$);async.mapSeries($colls$$,($col_name$$,$callback3$$)=>{let $rows$$=$data_replace$$[$col_name$$];$rows$$&&0<$rows$$.length?mongoose.connection.db.collection($col_name$$,($err$$,$coll$$)=>{if($err$$)return $callback3$$($err$$);if(!$coll$$)return console.log("can't update data. collection",$col_name$$,"is not exists"),$callback3$$();async.mapSeries($rows$$,($_row_row$$,$callback$$)=>{$_row_row$$=JSON.parse($_row_row$$);delete $_row_row$$.__v;delete $_row_row$$.pkey;
10
- $_row_row$$.id_app=$id_app$$;let $_id$$=ObjectId($_row_row$$._id);delete $_row_row$$._id;$coll$$.updateOne({_id:$_id$$},{$set:$_row_row$$},($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);console.log("updated",$col_name$$,$rs$$.matchedCount,$rs$$.modifiedCount,$rs$$.upsertedId);$callback$$()})},$e$$=>{console.log("updated collection",$col_name$$,"successfull");$callback3$$($e$$)})}):$callback3$$()},$e$$=>{$e$$||console.log("all collections was restore successful");$callback$jscomp$0$$($e$$)})})}).catch($e$$=>
11
- {$callback$jscomp$0$$($e$$)})}catch($e$$){console.error($e$$),$callback$jscomp$0$$($e$$)}}},$e$$=>{if($e$$)return console.error($e$$),parentPort.postMessage({error:$e$$});console.log("database was restore successful");parentPort.postMessage({result:"Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 kh\u00f4i ph\u1ee5c d\u1eef li\u1ec7u th\u00e0nh c\u00f4ng"})})}else return parentPort.postMessage({error:"File l\u01b0u tr\u1eef kh\u00f4ng c\u00f3 d\u1eef li\u1ec7u"})})}catch($e$$){return console.error($e$$),
3
+ {old_id:$old_id$$,new_id:$rs$$.insertedId.toString()})})},($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resolve$$($rs$$)})}),insert=($col_name$$,$coll$$,$rows$$,$id_app$$)=>{$rows$$=$rows$$.map($row$$=>{delete $row$$.__v;delete $row$$.pkey;$row$$.id_app=$id_app$$;return $row$$});return insertOne($coll$$,$rows$$)},restore=$message$$=>{if($message$$.configs&&_.isString($message$$.configs))try{$message$$.configs=JSON.parse($message$$.configs)}catch($e$$){delete $message$$.configs,console.info($e$$)}const $configs$$=
4
+ $message$$.configs||require("../configs");connect2Db||(mongoose.connect($configs$$.database.url,{useNewUrlParser:!0}),connect2Db=!0);let $id_app$$=$message$$.id,$user$$=$message$$.user,$fileZip$$=$message$$.file;model.findOne({_id:$id_app$$}).lean().exec(async($e$jscomp$1$$,$app$$)=>{if($e$jscomp$1$$||!$app$$)return parentPort.postMessage({error:$e$jscomp$1$$||"C\u00f4ng ty n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i"});$e$jscomp$1$$=await Participant.findOne({email:$user$$,id_app:$id_app$$,admin:!0});
5
+ if($app$$.user_created!==$user$$&&!$e$jscomp$1$$)return parentPort.postMessage({error:"B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n th\u1ef1c hi\u1ec7n t\u00e1c v\u1ee5 n\u00e0y"});fs.readFile($fileZip$$,($err$$,$dataZip$$)=>{if($err$$)return parentPort.postMessage({error:$err$$});try{JSZip.loadAsync($dataZip$$).then(function($zip$$){return $zip$$.file("backup.json").async("string")}).then($string_data$$=>{if($string_data$$){let $data$$=JSON.parse($string_data$$);async.parallel({app:$callback$$=>{let $appInfo$$=
6
+ $data$$["app.js"];$appInfo$$?(delete $appInfo$$._id,delete $appInfo$$.__v,console.log("restore app info"),model.findOneAndUpdate({_id:$id_app$$},$appInfo$$,$e$$=>{if($e$$)return $callback$$($e$$);console.log("app info was restore successfull");$callback$$()})):$callback$$()},data:$callback$jscomp$0$$=>{try{let $colls$$=underscore.keys($data$$).filter($k$$=>"user.js"!==$k$$&&"app.js"!==$k$$);console.log("total collection",$colls$$.length);Promise.all($colls$$.map($col_name$$=>new Promise(($resolve$$,
7
+ $reject$$)=>{let $rows$$=$data$$[$col_name$$]||[];$rows$$.forEach(($r$$,$index$$)=>{$r$$.index=$index$$});mongoose.connection.db.collection($col_name$$,($err$$,$coll$$)=>{if($err$$)return $reject$$($err$$);if(!$coll$$)return console.log("can't insert data, collection",$col_name$$,"is not exists"),$resolve$$([]);$coll$$.deleteMany({id_app:$id_app$$},$e$jscomp$0$$=>{if($e$jscomp$0$$)return $reject$$($e$jscomp$0$$);if(0===$rows$$.length)return $resolve$$([]);insert($col_name$$,$coll$$,$rows$$,$id_app$$).then($pairs$$=>
8
+ {console.log("restored collection",$col_name$$,$rows$$.length);$resolve$$($pairs$$)}).catch($e$$=>{$reject$$($e$$)})})})}))).then($_pairs_pairs$$=>{$_pairs_pairs$$=$_pairs_pairs$$.reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);console.log("inserted data");let $data_replace$$=JSON.parse($string_data$$);Object.keys($data_replace$$).filter($k$$=>"user.js"!==$k$$&&"app.js"!==$k$$).forEach($k$$=>{$data_replace$$[$k$$]=$data_replace$$[$k$$].map($r$$=>JSON.stringify($r$$))});async.mapSeries($_pairs_pairs$$,($pair$$,
9
+ $cb$$)=>{setImmediate(()=>{replaceAll($data_replace$$,$pair$$.old_id,$pair$$.new_id,()=>{console.log("replace pair",$pair$$);$cb$$()})})},()=>{let $colls$$=underscore.keys($data_replace$$).filter($k$$=>"user.js"!==$k$$&&"app.js"!==$k$$);async.mapSeries($colls$$,($col_name$$,$callback3$$)=>{let $rows$$=$data_replace$$[$col_name$$];$rows$$&&0<$rows$$.length?mongoose.connection.db.collection($col_name$$,($err$$,$coll$$)=>{if($err$$)return $callback3$$($err$$);if(!$coll$$)return console.log("can't update data. collection",
10
+ $col_name$$,"is not exists"),$callback3$$();async.mapSeries($rows$$,($_row_row$$,$callback$$)=>{$_row_row$$=JSON.parse($_row_row$$);delete $_row_row$$.__v;delete $_row_row$$.pkey;$_row_row$$.id_app=$id_app$$;let $_id$$=ObjectId($_row_row$$._id);delete $_row_row$$._id;$coll$$.updateOne({_id:$_id$$},{$set:$_row_row$$},($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);console.log("updated",$col_name$$,$rs$$.matchedCount,$rs$$.modifiedCount,$rs$$.upsertedId);$callback$$()})},$e$$=>{console.log("updated collection",
11
+ $col_name$$,"successfull");$callback3$$($e$$)})}):$callback3$$()},$e$$=>{$e$$||console.log("all collections was restore successful");$callback$jscomp$0$$($e$$)})})}).catch($e$$=>{$callback$jscomp$0$$($e$$)})}catch($e$$){console.error($e$$),$callback$jscomp$0$$($e$$)}}},$e$$=>{if($e$$)return console.error($e$$),parentPort.postMessage({error:$e$$});console.log("database was restore successful");parentPort.postMessage({result:"Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 kh\u00f4i ph\u1ee5c d\u1eef li\u1ec7u th\u00e0nh c\u00f4ng"})})}else return parentPort.postMessage({error:"File l\u01b0u tr\u1eef kh\u00f4ng c\u00f3 d\u1eef li\u1ec7u"})})}catch($e$$){return console.error($e$$),
12
12
  parentPort.postMessage({error:$e$$.message})}})})};parentPort.on("message",$message$$=>{$message$$?restore($message$$):parentPort.postMessage({error:"msg is not valid"})});workerData&&workerData.id&&workerData.findOne&&restore(workerData);
@@ -1,4 +1,4 @@
1
- 'use strict';const axios=require("axios"),moment=require("moment"),numeral=require("numeral"),{evalute}=require("../libs/utils"),{parentPort,workerData}=require("worker_threads"),async=require("async"),runScript=async $data_function_body_msg$$=>{if($data_function_body_msg$$=$data_function_body_msg$$.script){if(0<=$data_function_body_msg$$.indexOf("async "))return parentPort.postMessage({error:"async function is not allow"});0>$data_function_body_msg$$.indexOf("return ")&&($data_function_body_msg$$=
1
+ 'use strict';const axios=require("axios"),moment=require("moment"),numeral=require("numeral"),{evalute}=require("../libs/utils"),{parentPort,workerData}=require("worker_threads"),async=require("async"),_=require("lodash"),runScript=async $data_function_body_msg$$=>{if($data_function_body_msg$$=$data_function_body_msg$$.script){if(0<=$data_function_body_msg$$.indexOf("async "))return parentPort.postMessage({error:"async function is not allow"});0>$data_function_body_msg$$.indexOf("return ")&&($data_function_body_msg$$=
2
2
  `return ${$data_function_body_msg$$}`);var $sandbox$$={moment,numeral,axios,async};try{await evalute(`return (async ()=>{
3
3
  ${$data_function_body_msg$$}
4
- })`,$sandbox$$)(),parentPort.postMessage({result:"OK"})}catch($e$$){parentPort.postMessage({error:$e$$})}}};parentPort.on("message",$msg$$=>{$msg$$?runScript($msg$$):parentPort.postMessage({error:"msg is not valid"})});workerData&&workerData.configs&&runScript(workerData);
4
+ })`,$sandbox$$)(),parentPort.postMessage({result:"OK"})}catch($e$$){parentPort.postMessage({error:$e$$})}}};parentPort.on("message",$msg$$=>{$msg$$?runScript($msg$$):parentPort.postMessage({error:"msg is not valid"})});if(workerData&&workerData.configs){let $msg$$=workerData;if($msg$$.configs&&_.isString($msg$$.configs))try{$msg$$.configs=JSON.parse($msg$$.configs)}catch($e$$){delete $msg$$.configs,console.info($e$$)}$msg$$.configs&&runScript($msg$$)};
@@ -1,8 +1,9 @@
1
1
  'use strict';const {parentPort,workerData}=require("worker_threads");require("../global");
2
- const nodemailer=require("nodemailer"),smtpTransport=require("nodemailer-smtp-transport"),async=require("async"),underscore=require("underscore"),path=require("path"),fs=require("fs"),wellknown=require("nodemailer-wellknown"),Axios=require("axios"),sendHtml=function($message_smtp_tp$$,$fn$$){const $configs$$=$message_smtp_tp$$.configs||require("../configs"),$options$$=$message_smtp_tp$$.options;let $transporter$$,$from$$,$sender$$;$options$$.account?($message_smtp_tp$$=$options$$.account.smtp.host.split("."),
3
- 1<$message_smtp_tp$$.length&&($sender$$=wellknown($message_smtp_tp$$[1])),$sender$$||($sender$$={host:$options$$.account.smtp.host,port:$options$$.account.smtp.port}),$sender$$.auth={user:$options$$.account.username,pass:$options$$.account.password},$message_smtp_tp$$=smtpTransport($sender$$),$transporter$$=nodemailer.createTransport($message_smtp_tp$$),$from$$={name:$options$$.account.fullname,address:$options$$.account.username}):($sender$$=$options$$.app_info&&$options$$.app_info.email_host&&$options$$.app_info.email_user&&
4
- $options$$.app_info.email_pass?{host:$options$$.app_info.email_host,port:$options$$.app_info.email_port||465,secure:void 0===$options$$.app_info.email_secure?!0:$options$$.app_info.email_secure,authMethod:$options$$.app_info.email_authMethod||"LOGIN",auth:{user:$options$$.app_info.email_user,pass:$options$$.app_info.email_pass},name:$options$$.app_info.email_name||$options$$.app_info.name||$options$$.app_info.email_user}:$configs$$.sender,$sender$$.url?$transporter$$={sendMail:($msg$$,$callback$$)=>
5
- {$msg$$.secretKey=$sender$$.secretKey;$msg$$.message=$msg$$.message||$msg$$.html;$msg$$.name=$sender$$.name;Axios.post($sender$$.url,$msg$$).then($res$$=>{$callback$$(null,$res$$.data)}).catch($error$$=>{$callback$$($error$$.data)})}}:($transporter$$=nodemailer.createTransport(smtpTransport($sender$$)),$from$$={name:$sender$$.name,address:$sender$$.auth.user},$options$$.sender&&($from$$.name=$options$$.sender)));let $attachments$$=[];$options$$.attachments||($options$$.attachments=[]);async.mapSeries($options$$.attachments,
6
- ($att$$,$callback$$)=>{let $file_name$$=$att$$.file.name,$root$$=$configs$$.paths.uploads;$root$$||($root$$=__dirname,$root$$=path.dirname($root$$),$root$$=path.join($root$$,"uploads"));$file_name$$=path.join($root$$,$file_name$$);fs.existsSync($file_name$$)&&$attachments$$.push({path:$file_name$$,filename:$att$$.file.originalname});$callback$$()},()=>{underscore.isObject($options$$.to)?($transporter$$.sendMail({from:$from$$,to:$options$$.to,cc:$options$$.cc,bcc:$options$$.bcc,subject:$options$$.subject,
7
- html:$options$$.html,attachments:$attachments$$},function($error$$,$info$$){$error$$&&console.error($error$$,$info$$,$sender$$)}),$fn$$()):underscore.isArray($options$$.to)&&async.mapSeries($options$$.to,function($to$$,$callback$$){$to$$.address?($transporter$$.sendMail({from:$from$$,to:$to$$,cc:$options$$.cc,bcc:$options$$.bcc,subject:$options$$.subject,html:$options$$.html,attachments:$attachments$$},function($error$$,$info$$){$error$$&&console.error($error$$,$info$$,$sender$$)}),$callback$$()):
8
- $callback$$(null)},function($error$$,$t$$){$fn$$($error$$,$t$$)})})};parentPort.on("message",$data$$=>{$data$$?sendHtml($data$$,function($e$$,$rs$$){parentPort.postMessage({error:$e$$,data:$rs$$})}):parentPort.postMessage({error:"msg is not valid"})});workerData&&workerData.filePath&&sendHtml(workerData,function($e$$,$rs$$){parentPort.postMessage({error:$e$$,data:$rs$$})});
2
+ const nodemailer=require("nodemailer"),smtpTransport=require("nodemailer-smtp-transport"),async=require("async"),underscore=require("underscore"),path=require("path"),fs=require("fs"),wellknown=require("nodemailer-wellknown"),Axios=require("axios"),_=require("lodash"),sendHtml=function($message_smtp_tp$$,$fn$$){if($message_smtp_tp$$.configs&&_.isString($message_smtp_tp$$.configs))try{$message_smtp_tp$$.configs=JSON.parse($message_smtp_tp$$.configs)}catch($e$$){delete $message_smtp_tp$$.configs,console.info($e$$)}const $configs$$=
3
+ $message_smtp_tp$$.configs||require("../configs"),$options$$=$message_smtp_tp$$.options;let $transporter$$,$from$$,$sender$$;$options$$.account?($message_smtp_tp$$=$options$$.account.smtp.host.split("."),1<$message_smtp_tp$$.length&&($sender$$=wellknown($message_smtp_tp$$[1])),$sender$$||($sender$$={host:$options$$.account.smtp.host,port:$options$$.account.smtp.port}),$sender$$.auth={user:$options$$.account.username,pass:$options$$.account.password},$message_smtp_tp$$=smtpTransport($sender$$),$transporter$$=
4
+ nodemailer.createTransport($message_smtp_tp$$),$from$$={name:$options$$.account.fullname,address:$options$$.account.username}):($sender$$=$options$$.app_info&&$options$$.app_info.email_host&&$options$$.app_info.email_user&&$options$$.app_info.email_pass?{host:$options$$.app_info.email_host,port:$options$$.app_info.email_port||465,secure:void 0===$options$$.app_info.email_secure?!0:$options$$.app_info.email_secure,authMethod:$options$$.app_info.email_authMethod||"LOGIN",auth:{user:$options$$.app_info.email_user,
5
+ pass:$options$$.app_info.email_pass},name:$options$$.app_info.email_name||$options$$.app_info.name||$options$$.app_info.email_user}:$configs$$.sender,$sender$$.url?$transporter$$={sendMail:($msg$$,$callback$$)=>{$msg$$.secretKey=$sender$$.secretKey;$msg$$.message=$msg$$.message||$msg$$.html;$msg$$.name=$sender$$.name;Axios.post($sender$$.url,$msg$$).then($res$$=>{$callback$$(null,$res$$.data)}).catch($error$$=>{$callback$$($error$$.data)})}}:($transporter$$=nodemailer.createTransport(smtpTransport($sender$$)),
6
+ $from$$={name:$sender$$.name,address:$sender$$.auth.user},$options$$.sender&&($from$$.name=$options$$.sender)));let $attachments$$=[];$options$$.attachments||($options$$.attachments=[]);async.mapSeries($options$$.attachments,($att$$,$callback$$)=>{let $file_name$$=$att$$.file.name,$root$$=$configs$$.paths.uploads;$root$$||($root$$=__dirname,$root$$=path.dirname($root$$),$root$$=path.join($root$$,"uploads"));$file_name$$=path.join($root$$,$file_name$$);fs.existsSync($file_name$$)&&$attachments$$.push({path:$file_name$$,
7
+ filename:$att$$.file.originalname});$callback$$()},()=>{underscore.isObject($options$$.to)?($transporter$$.sendMail({from:$from$$,to:$options$$.to,cc:$options$$.cc,bcc:$options$$.bcc,subject:$options$$.subject,html:$options$$.html,attachments:$attachments$$},function($error$$,$info$$){$error$$&&console.error($error$$,$info$$,$sender$$)}),$fn$$()):underscore.isArray($options$$.to)&&async.mapSeries($options$$.to,function($to$$,$callback$$){$to$$.address?($transporter$$.sendMail({from:$from$$,to:$to$$,
8
+ cc:$options$$.cc,bcc:$options$$.bcc,subject:$options$$.subject,html:$options$$.html,attachments:$attachments$$},function($error$$,$info$$){$error$$&&console.error($error$$,$info$$,$sender$$)}),$callback$$()):$callback$$(null)},function($error$$,$t$$){$fn$$($error$$,$t$$)})})};parentPort.on("message",$data$$=>{$data$$?sendHtml($data$$,function($e$$,$rs$$){parentPort.postMessage({error:$e$$,data:$rs$$})}):parentPort.postMessage({error:"msg is not valid"})});
9
+ workerData&&workerData.filePath&&sendHtml(workerData,function($e$$,$rs$$){parentPort.postMessage({error:$e$$,data:$rs$$})});
@@ -1,3 +1,3 @@
1
1
  'use strict';const axios=require("axios"),moment=require("moment"),numeral=require("numeral"),{evalute}=require("../libs/utils"),{parentPort,workerData}=require("worker_threads"),runWebhook=async $msg$$=>{if(!$msg$$.webhook_configs||!$msg$$.webhook_configs.url)return parentPort.postMessage({error:"configs webhook is not valid"});console.info("running webhook",$msg$$.webhook_configs.url,$msg$$.webhook_configs.action);let $data$$=$msg$$.data,$custom_data_send$$=$msg$$.webhook_configs.custom_data_send;
2
2
  if($custom_data_send$$)try{let $str_func$$=$custom_data_send$$;if(0<=$str_func$$.indexOf("async "))return parentPort.postMessage({error:"Async is not allow to use when customing data"});0!==$str_func$$.indexOf("return ")&&($str_func$$=`return ${$str_func$$}`);$data$$=evalute($str_func$$,{data:$data$$,moment,numeral})}catch($e$$){return console.error($e$$,$custom_data_send$$),parentPort.postMessage({error:$e$$.message||$e$$})}try{axios.post($msg$$.webhook_configs.url,$data$$).then(function($response$$){parentPort.postMessage({result:$response$$.data})}).catch(function($error$$){parentPort.postMessage({error:$error$$.data||
3
- $error$$.message||$error$$})})}catch($e$$){parentPort.postMessage({error:$e$$})}};parentPort.on("message",$msg$$=>{$msg$$?runWebhook($msg$$):parentPort.postMessage({error:"msg is not valid"})});workerData&&workerData.configs&&runWebhook(workerData);
3
+ $error$$.message||$error$$})})}catch($e$$){parentPort.postMessage({error:$e$$})}};parentPort.on("message",$msg$$=>{$msg$$?runWebhook($msg$$):parentPort.postMessage({error:"msg is not valid"})});workerData&&workerData.webhook_configs&&runWebhook(workerData);
@@ -1,54 +0,0 @@
1
-
2
- const express = require("express");
3
- const app = express();
4
- const { parentPort,workerData} = require('worker_threads');
5
- const handleImport =(msg)=>{
6
- try{
7
- let module = global.controllers[msg.module];
8
- const controller = require("../controllers/controller");
9
- if(module){
10
- controller.import(module,msg.user,msg.id_app,msg.data,(error,rs)=>{
11
- parentPort.postMessage({error:error,result:rs});
12
- },{replace:msg.replace})
13
- }else{
14
- parentPort.postMessage({error:"Không tìm thấy module " + msg.module});
15
- }
16
- }catch(e){
17
- parentPort.postMessage({error:e});
18
- }
19
- }
20
- let sv = false;
21
- parentPort.on("message", (msg)=>{
22
- if(!sv){
23
- console.info("Khoi tao service..");
24
- const configs = msg.configs || require("../configs");
25
- configs.use_ssl = false;
26
- const Server = require('../app');
27
- Server(app,{configs,createServer:false,start_import_data_pool:false,lite:true},()=>{
28
- sv = true;
29
- if(msg.load){
30
- return parentPort.postMessage({rs:"ready"});
31
- }
32
- handleImport(msg);
33
- });
34
- }else{
35
- console.info("reuse worker import data...");
36
- handleImport(msg)
37
- }
38
- })
39
- if(workerData && workerData.configs){
40
- let msg = workerData;
41
- if(!sv){
42
- const configs = msg.configs;
43
- configs.use_ssl = false;
44
- const Server = require('../app');
45
- Server(app,{configs,createServer:false,start_import_data_pool:false,lite:true},()=>{
46
- sv = true;
47
- if(msg.load) return parentPort.postMessage({rs:"ready"});
48
- handleImport(msg);
49
- });
50
- }else{
51
- console.info("reuse worker import data...");
52
- handleImport(msg)
53
- }
54
- }
File without changes