flexbiz-server
Version:
Flexible Server
9 lines (8 loc) • 3.57 kB
JavaScript
'use strict';const so9=global.getModel("so9"),hd8=global.getModel("hd8"),async=require("async"),trangthai=global.getModel("trangthai"),transaction=global.getModel("transaction");
module.exports=function($condition$$,$callback$jscomp$0$$){if(!$condition$$.id_app)return $callback$jscomp$0$$("H\u00e0m n\u00e0y y\u00eau c\u1ea7u tham s\u1ed1 id_app");async.parallel({so:$callback$$=>{setImmediate(()=>{if(!$condition$$.ma_ct||0<=$condition$$.ma_ct.indexOf("so9")){let $_cd$$={...$condition$$};delete $_cd$$.show_payment_method;delete $_cd$$.show_bonus_points;so9.find($_cd$$).lean().exec(($error$$,$rs$$)=>{if($error$$)return $callback$$({message:$error$$.message,voucher:"so9",condition:$_cd$$});
$rs$$.forEach($r$$=>{$r$$.ngay_ct=$r$$.ngay_giao_hang||$r$$.ngay_ct;$r$$.tien_nt=($r$$.tien_hang_ct_nt||0)-($r$$.tien_ck_nt||0)+($r$$.tien_thue_nt||0);$r$$.tien=($r$$.tien_hang_ct||0)-($r$$.tien_ck||0)+($r$$.tien_thue||0)});$callback$$(null,$rs$$)})}else $callback$$(null,[])})},hd8:$callback$$=>{setImmediate(()=>{if(!$condition$$.ma_ct||0<=$condition$$.ma_ct.indexOf("SO9")){let $_cd$$={...$condition$$};delete $_cd$$.show_payment_method;delete $_cd$$.show_bonus_points;delete $_cd$$.ma_ct;hd8.find($_cd$$).lean().exec(($error$$,
$rs$$)=>{if($error$$)return $callback$$({message:$error$$.message,voucher:"hd8",condition:$_cd$$});$callback$$(null,$rs$$)})}else $callback$$(null,[])})}},async($error$$,$rs$$)=>{if($error$$)return $callback$jscomp$0$$($error$$);$rs$$.pbl=[];async.series({so:$callback$$=>{setImmediate(()=>{($rs$$.so||[]).forEach($r$$=>{$r$$.ctcpbhs&&$r$$.ctcpbhs.forEach($c$$=>{$c$$.tien_hang_ct=0;$c$$.tien_hang_ct_nt=0;$c$$.sl_xuat=0;$c$$.tien=$c$$.tien_hang_ct+$c$$.tien_cp;$c$$.tien_nt=$c$$.tien_hang_ct_nt+$c$$.tien_cp_nt;
$r$$.details.push($c$$)});$rs$$.pbl.push($r$$)});$callback$$()})},so_tl:$callback$$=>{setImmediate(()=>{$rs$$.hd8.forEach($r$jscomp$0$$=>{$r$jscomp$0$$.details_tl=$r$jscomp$0$$.details.map($r$$=>$r$$);$r$jscomp$0$$.details=[];$rs$$.pbl.push($r$jscomp$0$$)});$callback$$()})}},async()=>{let $reportData$$=$rs$$.pbl;await $reportData$$.asyncJoinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["post_sokho","post","post_socai","ten_trang_thai"]}]);$reportData$$=$reportData$$.filter($p$$=>
$p$$.post);const $ptthanhtoans$$=!1!==$condition$$.show_payment_method?(await global.getModel("ptthanhtoan").find({status:!0,id_app:$condition$$.id_app}).lean()).map($pt$$=>{$pt$$.ma=`pttt__${$pt$$._id}`;return $pt$$}):[];$condition$$.show_bonus_points||$ptthanhtoans$$&&0<$ptthanhtoans$$.length?async.mapSeries($reportData$$,($r$$,$callback$$)=>{setImmediate(async()=>{if($condition$$.show_bonus_points){let $trans$$=await transaction.find({id_ct:{$regex:$r$$._id.toString(),$options:"i"}}).lean();$r$$.bonus_points=
$trans$$.filter($tran$$=>$tran$$.receiver.email.toLowerCase()===$r$$.ma_kh.toLowerCase()).map($tran$$=>$tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$r$$.used_points=$trans$$.filter($tran$$=>$tran$$.sender.email.toLowerCase()===$r$$.ma_kh.toLowerCase()).map($tran$$=>$tran$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0)}$ptthanhtoans$$&&0<$ptthanhtoans$$.length&&($r$$.thanh_toan=$ptthanhtoans$$,$r$$.thanh_toan.forEach($pt$$=>{$r$$[$pt$$.ma]=0;$r$$.pt_thanh_toan===$pt$$._id.toString()&&($r$$[$pt$$.ma]+=
$r$$.tien_thu||$r$$.tien_con_lai||0);$r$$.pt_thanh_toan2===$pt$$._id.toString()&&($r$$[$pt$$.ma]+=$r$$.tien_thu2||0);$pt$$.tien_thu=$r$$[$pt$$.ma]}));$callback$$(null,$r$$)})},()=>{$callback$jscomp$0$$(null,$reportData$$,$ptthanhtoans$$)}):$callback$jscomp$0$$(null,$reportData$$)})})};