flexbiz-server
Version:
Flexible Server
5 lines (4 loc) • 1.95 kB
JavaScript
'use strict';const introducer=global.getModel("introducer"),user=global.getModel("user"),moment=require("moment"),controller=require("../../controllers/controllerRPT"),databanle=require("../../libs/databanle"),asyncDatabanle=async $query$$=>new Promise(($resove$$,$reject$$)=>{databanle($query$$,($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resove$$($rs$$)})});
module.exports=function($router$$){new controller($router$$,"tkgioithieukh",function($req$$,$callback$$){let $tu_ngay$$=moment($req$$.query.tu_ngay).startOf("date").toDate(),$den_ngay$$=moment($req$$.query.den_ngay).endOf("date").toDate(),$id_app$$=$req$$.query.id_app,$query$$={id_app:$id_app$$,date_created:{$gte:$tu_ngay$$,$lte:$den_ngay$$}};$req$$.query.introducer&&($query$$.be_introduced_by=$req$$.query.introducer);introducer.find($query$$).lean().exec(async($e$jscomp$1_rs$$,$introdueds$$)=>{if($e$jscomp$1_rs$$)return $callback$$($e$jscomp$1_rs$$.message);
$e$jscomp$1_rs$$=await (await Promise.all($introdueds$$.filter($r$$=>$r$$.be_introduced!==$r$$.be_introduced_by).map(async $intro$$=>{var $query_banle_so_lan_mua_hang$$={id_app:$id_app$$,ma_kh:$intro$$.be_introduced};$query_banle_so_lan_mua_hang$$.ngay_ct={$gte:$tu_ngay$$,$lte:$den_ngay$$};$query_banle_so_lan_mua_hang$$=(await asyncDatabanle($query_banle_so_lan_mua_hang$$)).map($r$$=>"HD7"!==$r$$.so_ct?1:0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$intro$$.downloaded=1;$intro$$.so_lan_mua_hang=$query_banle_so_lan_mua_hang$$;
$intro$$.mua_1_lan=1===$intro$$.so_lan_mua_hang?1:0;$intro$$.mua_hon_1_lan=1<$intro$$.so_lan_mua_hang?1:0;$intro$$.chua_mua=0===$intro$$.so_lan_mua_hang?1:0;$intro$$.introducer=$intro$$.be_introduced_by;return $intro$$}))).asyncGroupBy(["introducer"],["downloaded","chua_mua","mua_1_lan","mua_hon_1_lan"]);await $e$jscomp$1_rs$$.asyncJoinModel2(null,user,{where:{introducer:"email"},fields:{introducer_name:"name"}});$callback$$(null,$e$jscomp$1_rs$$.filter($r$$=>$r$$.introducer_name))})})};