UNPKG

flexbiz-server

Version:

Flexible Server

8 lines (7 loc) 3 kB
const moment=require("moment"); module.exports=async function($condition$$,$callback$$){var $query_rs$$={id_app:$condition$$.id_app,event:{$regex:"BONUS",$options:"i"}};$condition$$.token&&($query_rs$$["data.token"]=$condition$$.token);$condition$$.introduce_code&&($query_rs$$["data.introduce_code"]=$condition$$.introduce_code);$condition$$.id_product&&($query_rs$$["data.id_product"]=$condition$$.id_product);$condition$$.id_period&&($query_rs$$["data.id_period"]=$condition$$.id_period);$condition$$.wallet_address&&($query_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_rs$$.date_created={$gte:$ngay$$.startOf("year").toDate(),$lte:$ngay$$.endOf("year").toDate()};Number($condition$$.quy)&&($ngay$$.set("quarters",Number($condition$$.quy)),$query_rs$$.date_created={$gte:$ngay$$.startOf("quarter").toDate(),$lte:$ngay$$.endOf("quarter").toDate()});Number($condition$$.thang)&&($ngay$$.set("months", Number($condition$$.thang)-1),$query_rs$$.date_created={$gte:$ngay$$.startOf("month").toDate(),$lte:$ngay$$.endOf("month").toDate()});$condition$$.ngay&&($ngay$$.set("days",Number($condition$$.ngay)),$query_rs$$.date_created={$gte:$ngay$$.startOf("date").toDate(),$lte:$ngay$$.endOf("date").toDate()})}else $condition$$.tu_ngay&&($query_rs$$.date_created={$gte:$condition$$.tu_ngay}),$condition$$.den_ngay&&($query_rs$$.date_created=$query_rs$$.date_created||{},$query_rs$$.date_created.$lte=$condition$$.den_ngay); $query_rs$$=await global.getModel("asstransaction").find($query_rs$$).sort({date_created:1}).lean();$query_rs$$.forEach($r$$=>{$r$$.receiver=($r$$.data||{}).to_address;$r$$.amount=($r$$.data||{}).amount||0;$r$$.tokenAmount=$r$$.amount});$condition$$.wallet_address&&($query_rs$$=$query_rs$$.filter($r$$=>$r$$.receiver==$condition$$.wallet_address));await $query_rs$$.asyncJoinModel2($condition$$.id_app,"asskey",{where:{receiver:"address"},fields:["username"]});$condition$$.username&&($query_rs$$=$query_rs$$.filter($r$$=> $r$$.username===$condition$$.username));await $query_rs$$.asyncJoinModel2($condition$$.id_app,"assproduct",{where:{idProduct:"id"},fields:"ten_san_pham"});await $query_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_rs$$.asyncJoinModel2($condition$$.id_app,"assinvestment",{where:{tokenName:"token"},fields:[{user_investor:"user_created", wallet_investor:"creator",gia:"gia"}]});await $query_rs$$.asyncJoinModel2(null,"user",{where:{username:"email"},fields:["name"]});await $query_rs$$.asyncJoinModel2($condition$$.id_app,"customer",{where:{username:"of_user"},fields:["ma_kh","ten_kh"]});$query_rs$$.forEach($r$$=>{$r$$.date=$r$$.date_created;$r$$.bold=!1;$r$$.tokenValue=($r$$.gia||1)*$r$$.tokenAmount});$callback$$(null,$query_rs$$)};