UNPKG

flexbiz-server

Version:

Flexible Server

9 lines (8 loc) 3.23 kB
'use strict';const asssellSchema=new Schema({id_app:String,creator:{type:String,required:!0,trim:!0},id:{type:String,trim:!0},id_product:{type:String,trim:!0},ten_san_pham:{type:String},product_token:{type:String,lowercase:!0,trim:!0},id_period:{type:String,trim:!0},ten_ky_han:{type:String,trim:!0},ten_lh_dt:String,ky_han:Number,token:{type:String,required:!0,lowercase:!0,trim:!0},gia_goc:{type:Number},lai_suat_cam_ket:Number,denom:{type:String,required:!0,lowercase:!0,trim:!0},so_luong:{type:Number}, da_ban:{type:Number},con_lai:{type:Number},gia_ban:{type:Number},tong_gia_tri:{type:Number},ngay_het_han:{type:Date,required:!0},buyer:String,id_need_to_buy:String,fee:Number,exchange_address:String,trang_thai:String,signature:String,exfields:Schema.Types.Mixed,status:{type:Boolean,default:!0},date_created:{type:Date,default:Date.now},date_updated:{type:Date,default:Date.now},user_created:{type:String,default:""},user_updated:{type:String,default:""}}),model=mongoose.models.asssell||mongoose.model("asssell", asssellSchema); (global.configs||{}).createIndexes&&(asssellSchema.index({id_app:1}),asssellSchema.index({creator:1}),asssellSchema.index({id:1}),asssellSchema.index({denom:1}),asssellSchema.index({token:1}),asssellSchema.index({trang_thai:1}),asssellSchema.index({id_product:1}),asssellSchema.index({ten_san_pham:1}),asssellSchema.index({product_token:1}),asssellSchema.index({id_period:1}),asssellSchema.index({ky_han:1}),asssellSchema.index({gia_goc:1}),asssellSchema.index({lai_suat_cam_ket:1}),asssellSchema.index({ten_lh_dt:1}),asssellSchema.index({ngay_het_han:-1}), asssellSchema.index({status:1}),asssellSchema.index({user_created:1}),asssellSchema.index({creator:"text",token:"text",denom:"text",ten_san_pham:"text",ten_ky_han:"text"},{name:"asssell_index2"}),model.on("index",async function($err$$){$err$$?console.error("asssell index error",$err$$):console.info("asssell indexing complete")})); model.updateSell=async $item$$=>{$item$$.token&&await [$item$$].asyncJoinModel2($item$$.id_app,global.getModel("assinvestment"),{where:"token",fields:["ten_san_pham",{gia_goc:"gia"},"ngay_phat_hanh","id_product","product_token","ky_han","id_period","ten_ky_han","ngay_dao_han","lai_suat_cam_ket","lai_suat_truoc_han","cho_phep_rut_von","co_phan"]});void 0!=$item$$.id_period&&null!=$item$$.id_period&&await [$item$$].asyncJoinModel2($item$$.id_app,global.getModel("assperiod"),{where:$item$$=>({id:$item$$.id_period, id_product:$item$$.id_product}),fields:["ten_lh_dt","ten_ky_han","ky_tinh_lai","goi_dau_tu"]});$item$$.con_lai=$item$$.so_luong-$item$$.da_ban;$item$$.tong_gia_tri_con_lai=$item$$.con_lai*$item$$.gia_goc;$item$$.lai_du_tinh_con_lai=Math.roundBy($item$$.lai_suat_cam_ket/365*$item$$.tong_gia_tri_con_lai*$item$$.ky_han/100,0);$item$$.tong_gia_tri_dao_han_con_lai=$item$$.tong_gia_tri_con_lai+$item$$.lai_du_tinh_con_lai;$item$$.ky_han&&!$item$$.co_phan?($item$$.so_ngay_hien_tai=Math.roundBy(((new Date).getTime()- (new Date($item$$.ngay_phat_hanh)).getTime())/864E5),$item$$.tien_lai_hien_tai=Math.roundBy($item$$.so_ngay_hien_tai*($item$$.lai_suat_cam_ket||0)/365*$item$$.tong_gia_tri_con_lai/100)):($item$$.tien_lai_hien_tai=0,$item$$.so_ngay_hien_tai=0)};module.exports=model;