UNPKG

flexbiz-server

Version:

Flexible Server

11 lines (10 loc) 4.28 kB
const controller=require("../../controllers/controllerRPT"),moment=require("moment"); module.exports=function($router$$){new controller($router$$,"asstransferlog",async function($query_req_rs$$,$callback$$){const $condition$$=$query_req_rs$$.query;$query_req_rs$$={id_app:$condition$$.id_app};if($condition$$.username){var $keys_ngay$$=(await global.getModel("asskey").find({id_app:$condition$$.id_app,username:$condition$$.username}).lean()).map($r$$=>$r$$.address);$query_req_rs$$.$or=[{"data.from_address":{$in:$keys_ngay$$}},{"data.to_address":{$in:$keys_ngay$$}}]}$condition$$.nam?($keys_ngay$$= moment().set("years",Number($condition$$.nam)),$query_req_rs$$.date_created={$gte:$keys_ngay$$.startOf("year").toDate(),$lte:$keys_ngay$$.endOf("year").toDate()},Number($condition$$.quy)&&($keys_ngay$$.set("quarters",Number($condition$$.quy)),$query_req_rs$$.date_created={$gte:$keys_ngay$$.startOf("quarter").toDate(),$lte:$keys_ngay$$.endOf("quarter").toDate()}),Number($condition$$.thang)&&($keys_ngay$$.set("months",Number($condition$$.thang)-1),$query_req_rs$$.date_created={$gte:$keys_ngay$$.startOf("month").toDate(), $lte:$keys_ngay$$.endOf("month").toDate()}),$condition$$.ngay&&($keys_ngay$$.set("days",Number($condition$$.ngay)),$query_req_rs$$.date_created={$gte:$keys_ngay$$.startOf("date").toDate(),$lte:$keys_ngay$$.endOf("date").toDate()})):($condition$$.tu_ngay&&($query_req_rs$$.date_created={$gte:$condition$$.tu_ngay}),$condition$$.den_ngay&&($query_req_rs$$.date_created=$query_req_rs$$.date_created||{},$query_req_rs$$.date_created.$lte=$condition$$.den_ngay));$query_req_rs$$=await global.getModel("asstransaction").find($query_req_rs$$).sort({date_created:-1}).lean(); $query_req_rs$$.forEach($r$$=>{if($r$$.data){for(let $k$$ in $r$$.data)$r$$[$k$$]=$r$$.data[$k$$];$r$$.receiver=$r$$.data.to_address;$r$$.sender=$r$$.data.from_address}});$query_req_rs$$=$query_req_rs$$.filter($r$$=>$r$$.receiver||$r$$.sender);await $query_req_rs$$.filter($r$$=>$r$$.id_product).asyncJoinModel2($condition$$.id_app,"assproduct",{where:{id_product:"id"},fields:"ten_san_pham"});await $query_req_rs$$.filter($r$$=>$r$$.id_period).asyncJoinModel2($condition$$.id_app,"assperiod",{where:{id_period:"id"}, fields:["ten_ky_han","lai_suat_cam_ket","lai_suat_truoc_han","lai_suat_thoi_gian_con_lai","lai_suat_tang_them_so_huu_token"]});await $query_req_rs$$.filter($r$$=>$r$$.token).asyncJoinModel2($condition$$.id_app,"assinvestment",{where:{token:"token"},setFields:($item$$,$ref$$)=>{$item$$.user_investor=$ref$$.user_created;$item$$.wallet_investor=$ref$$.creator;$item$$.value=($item$$.amount||0)*$ref$$.gia}});await $query_req_rs$$.asyncJoinModel2($condition$$.id_app,"asskey",{where:{receiver:"address"}, fields:[{username_receiver:"username"}]});await $query_req_rs$$.asyncJoinModel2(null,"user",{where:{username_receiver:"email"},fields:[{name_receiver:"name"}]});await $query_req_rs$$.asyncJoinModel2($condition$$.id_app,"asskey",{where:{sender:"address"},fields:[{username_sender:"username"}]});await $query_req_rs$$.asyncJoinModel2(null,"user",{where:{username_sender:"email"},fields:[{name_sender:"name"}]});let $report$$=[];$query_req_rs$$.forEach($_r2_r$$=>{$_r2_r$$.ngay=$_r2_r$$.date_created;if($_r2_r$$.sender&& (!$condition$$.username||$_r2_r$$.username_sender==$condition$$.username)){let $_r$$={...$_r2_r$$,bold:!1};$_r$$.amount=Number($_r$$.amount||0);$_r$$.tokenAmount=Number($_r$$.amount||0);$_r$$.tokenValue=Number($_r$$.value);$_r$$.address=$_r$$.sender;$_r$$.received_amount=0;$_r$$.sent_amount=$_r$$.amount;$report$$.push($_r$$)}!$_r2_r$$.receiver||$condition$$.username&&$_r2_r$$.username_receiver!=$condition$$.username||($_r2_r$$={...$_r2_r$$,bold:!1},$_r2_r$$.amount=Number($_r2_r$$.amount||0),$_r2_r$$.tokenAmount= Number($_r2_r$$.amount||0),$_r2_r$$.tokenValue=Number($_r2_r$$.value),$_r2_r$$.address=$_r2_r$$.receiver,$_r2_r$$.received_amount=$_r2_r$$.amount,$_r2_r$$.sent_amount=0,$report$$.push($_r2_r$$))});$report$$.push({memo:"T\u1ed5ng c\u1ed9ng",bold:!0,amount:$report$$.map($r$$=>$r$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0),received_amount:$report$$.map($r$$=>$r$$.received_amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0),sent_amount:$report$$.map($r$$=>$r$$.sent_amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0)});$callback$$(null, $report$$)})};