UNPKG

flexbiz-server

Version:

Flexible Server

9 lines (8 loc) 3.42 kB
const controller=require("../../controllers/controllerRPT"),moment=require("moment"); module.exports=function($router$$){new controller($router$$,"assinterest",async function($query_req_rs$$,$callback$$){const $condition$$=$query_req_rs$$.query;$query_req_rs$$={id_app:$condition$$.id_app,event:{$regex:"BONUS",$options:"i"}};$condition$$.token&&($query_req_rs$$["data.token"]=$condition$$.token);$condition$$.introduce_code&&($query_req_rs$$["data.introduce_code"]=$condition$$.introduce_code);$condition$$.id_product&&($query_req_rs$$["data.id_product"]=$condition$$.id_product);$condition$$.id_period&& ($query_req_rs$$["data.id_period"]=$condition$$.id_period);$condition$$.wallet_address&&($query_req_rs$$.$or=[{"data.from_address":$condition$$.wallet_address},{"data.to_address":$condition$$.wallet_address}]);if($condition$$.nam){let $ngay$$=moment().set("years",Number($condition$$.nam));$query_req_rs$$.date_created={$gte:$ngay$$.startOf("year").toDate(),$lte:$ngay$$.endOf("year").toDate()};Number($condition$$.quy)&&($ngay$$.set("quarters",Number($condition$$.quy)),$query_req_rs$$.date_created={$gte:$ngay$$.startOf("quarter").toDate(), $lte:$ngay$$.endOf("quarter").toDate()});Number($condition$$.thang)&&($ngay$$.set("months",Number($condition$$.thang)-1),$query_req_rs$$.date_created={$gte:$ngay$$.startOf("month").toDate(),$lte:$ngay$$.endOf("month").toDate()});$condition$$.ngay&&($ngay$$.set("days",Number($condition$$.ngay)),$query_req_rs$$.date_created={$gte:$ngay$$.startOf("date").toDate(),$lte:$ngay$$.endOf("date").toDate()})}else $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$$=>{$r$$.receiver=($r$$.data||{}).to_address;$r$$.amount=($r$$.data||{}).amount||0;$r$$.tokenAmount=$r$$.amount});$condition$$.wallet_address&&($query_req_rs$$=$query_req_rs$$.filter($r$$=>$r$$.receiver==$condition$$.wallet_address));await $query_req_rs$$.asyncJoinModel2($condition$$.id_app, "asskey",{where:{receiver:"address"},fields:["username"]});$condition$$.username&&($query_req_rs$$=$query_req_rs$$.filter($r$$=>$r$$.username===$condition$$.username));await $query_req_rs$$.asyncJoinModel2($condition$$.id_app,"assproduct",{where:{idProduct:"id"},fields:"ten_san_pham"});await $query_req_rs$$.asyncJoinModel2($condition$$.id_app,"assperiod",{where:{idPeriod:"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$$.asyncJoinModel2($condition$$.id_app,"assinvestment",{where:{tokenName:"token"},fields:[{user_investor:"user_created",wallet_investor:"creator",gia:"gia"}]});await $query_req_rs$$.asyncJoinModel2(null,"user",{where:{username:"email"},fields:["name"]});await $query_req_rs$$.asyncJoinModel2($condition$$.id_app,"customer",{where:{username:"of_user"},fields:["ma_kh","ten_kh"]});$query_req_rs$$.forEach($r$$=>{$r$$.date=$r$$.date_created;$r$$.bold=!1;$r$$.tokenValue=($r$$.gia||1)*$r$$.tokenAmount}); $query_req_rs$$.push({memo:"T\u1ed5ng c\u1ed9ng",bold:!0,amount:$query_req_rs$$.map($r$$=>$r$$.amount).reduce(($a$$,$b$$)=>$a$$+$b$$,0)});$callback$$(null,$query_req_rs$$)},{stream:!1})};