flexbiz-server
Version:
Flexible Server
9 lines (8 loc) • 3.82 kB
JavaScript
'use strict';const model=global.getModel("asscashwithdraw"),App=global.getModel("app"),Trangthai=global.getModel("trangthai"),PC1=global.getModel("pc1"),Customer=global.getModel("customer"),controller=require("../../controllers/controller"),{isSupperAdmin}=require("../../libs/utils");
module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,"asscashwithdraw",{sort:{date_created:-1},notNeedRight:!0,requireOtp:($data$$,$options$$)=>isSupperAdmin($options$$.user.email.toLowerCase())?!1:!0,onFinding:async($user$$,$condition$$,$next$$)=>{$next$$(null,$condition$$)},onView:async($user$$,$items$$,$next$$)=>{await $items$$.asyncJoinModel2(null,Trangthai,[{where:$a$$=>({ma_trang_thai:$a$$.trang_thai,ma_ct:"ASSCASHWITHDRAW"}),fields:["ten_trang_thai",
"color"]}]);await $items$$.asyncJoinModel2(null,"user",[{where:$a$$=>({email:$a$$.user_created}),fields:["name"]}]);await $items$$.asyncJoinModel2($user$$.current_id_app,Customer,[{where:$a$$=>({of_user:$a$$.user_created}),fields:["ma_kh","ten_kh"]}]);await $items$$.asyncJoinModel2($user$$.current_id_app,PC1,[{where:$a$$=>({id_asscashwithdraw:$a$$._id}),fields:[{so_ct_pc1:"so_ct",id_pc1:"_id",ngay_ct_pc1:"ngay_ct",ma_ct_pc1:"ma_ct"}]}]);$next$$(null,$items$$)},onCreating:async($user$$,$CashWithdraw$$,
$next$$)=>{let $creator$$=$CashWithdraw$$.creator;if(!await global.getModel("asskey").findOne({id_app:$user$$.current_id_app,username:$user$$.email,address:$creator$$}).lean())return $next$$("\u0110\u1ecba ch\u1ec9 v\u00ed n\u00e0y kh\u00f4ng thu\u1ed9c v\u1ec1 b\u1ea1n");let $app$$=await App.findOne({_id:$user$$.current_id_app}),$identity$$=await global.getModel("assuser_identity").findOne({id_app:$user$$.current_id_app,user_created:$user$$.email});if(!$identity$$)return $next$$({error:"B\u1ea1n c\u1ea7n x\u00e1c th\u1ef1c th\u00f4ng tin ng\u01b0\u1eddi d\u00f9ng tr\u01b0\u1edbc khi th\u1ef1c hi\u1ec7n giao d\u1ecbch"});
if("1"!=$identity$$.trang_thai)return $next$$({error:"H\u1ed3 s\u01a1 th\u00f4ng tin c\u1ee7a b\u1ea1n ch\u01b0a \u0111\u01b0\u1ee3c duy\u1ec7t"});if(!$app$$.wallet_address)return $next$$("Kh\u00f4ng th\u1ec3 y\u00eau c\u1ea7u thanh to\u00e1n. H\u00e3y th\u1eed l\u1ea1i sau");$CashWithdraw$$.payer=$app$$.wallet_address;$CashWithdraw$$.require_date=new Date;$CashWithdraw$$.trang_thai="0";try{await global.getModel("assbank").sendCoinsFromAccountToSystem($user$$.current_id_app,$creator$$,$CashWithdraw$$.amount,
$CashWithdraw$$.token)}catch($e$$){return $next$$($e$$)}$next$$(null,$CashWithdraw$$)},onCreated:async($user$$,$obj$$,$next$$)=>{$obj$$.id=$obj$$._id.toString();await model.updateOne({_id:$obj$$._id},{id:$obj$$.id});$next$$(null,$obj$$)}});$contr_router$$.deleting=function($user$$,$obj$$,$fn$$){if(isSupperAdmin($user$$.email.toLowerCase()))return $fn$$(null,$obj$$);if($user$$.email!==$obj$$.user_created)return $fn$$("B\u1ea1n kh\u00f4ng c\u00f3 x\u00f3a y\u00eau c\u1ea7u n\u00e0y");if("5"==$obj$$.trang_thai)return $fn$$("Y\u00eau c\u1ea7u n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n");
if("9"==$obj$$.trang_thai)return $fn$$("Y\u00eau c\u1ea7u n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c h\u1ee7y")};$contr_router$$.updating=async function($user$$,$data$$,$obj$$,$fn$$){if($user$$.email!==$obj$$.user_created&&!isSupperAdmin($user$$.email.toLowerCase()))return $fn$$("B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n c\u1eadp nh\u1eadt");if("9"==$obj$$.trang_thai)return $fn$$("Y\u00eau c\u1ea7u n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c h\u1ee7y");if("5"==$obj$$.trang_thai)return $fn$$("Y\u00eau c\u1ea7u n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n");
if($data$$.creator&&$data$$.creator!==$obj$$.creator)return $fn$$("Kh\u00f4ng \u0111\u01b0\u1ee3c ph\u00e9p s\u1eeda \u0111\u1ecba ch\u1ec9 v\u00ed ng\u01b0\u1eddi t\u1ea1o")};$contr_router$$.route()};