禧侬农养殖农场喜农数字化农场核心收益奖励核心源码
禧侬农数字化农场包含的功能如下:
1.会员中心
2.认养模块
3.交易模块
4.易货阶段
5.收益奖励分润模块
6.推荐分销奖励模块
7.订单模块
8.财务模块
9.数据统计分析功能
10.农场上下架设置
此段代码是农场奖励分润核心代码段
public static function teamfenrun($uid,$money,$level,$rate,$aid,$tuid){
//查询上级
$spread_uid = User::where('uid',$uid)->value('spread_uid');
$dengji = array_column(sys_data('team_grade'),'bilie','level');
if($spread_uid > 0){
$user = User::getUserInfo($spread_uid);
$spread_level = User::where('uid',$spread_uid)->value('grade');
if($spread_level > $level){
$indirect_reward_rate = $dengji[$spread_level];
if($indirect_reward_rate > 0 ){
//我的奖励= 总金额*(我的等级比例-上次的比例($up_rate))/100;
$status = self::findPj($spread_uid,$spread_level);
if(!$status){
$indirect_reward =bcdiv(bcmul($money, bcsub($indirect_reward_rate, $rate, 3), 2),1000,2);
}else{
$indirect_reward = bcmul(bcdiv(bcmul($money, bcsub($indirect_reward_rate, $rate, 2), 2),1000,2),0.9,2) ;
$indirect_reward_pingji = bcmul(bcdiv(bcmul($money, bcsub($indirect_reward_rate, $rate, 2), 2),1000,2),0.1,2) ;
}
//self::beginTrans();
//TODO 添加佣金记录
$res3 = true;
$res4 = true;
if($status){
// $pingji_spread_uid = User::where('uid',$status)->value('spread_uid');
$pingji_user = User::getUserInfo($status);
$pj_oldMoeny = bcadd($pingji_user['reward'],$indirect_reward_pingji,2);
$remark = "平级KPI奖励".$indirect_reward.'元,总奖金'.$pj_oldMoeny.'元';
$res3 = RewardModel::create(['uid'=>$status,'tuid'=>$tuid,'aid'=>$aid,'price'=>$indirect_reward_pingji,
'type'=>2,'status'=>1,'remark'=>$remark,'add_time'=>time()]);
$res4 = self::bcInc($status, 'reward', $indirect_reward_pingji, 'uid');
}
$oldMoeny = bcadd($user['reward'],$indirect_reward,2);
$remark = "KPI奖励".$indirect_reward.'元,总奖金'.$oldMoeny.'元';
$res1 = RewardModel::create(['uid'=>$spread_uid,'tuid'=>$tuid,'aid'=>$aid,'price'=>$indirect_reward,
'type'=>2,'status'=>1,'remark'=>$remark,'add_time'=>time()]);
$res2 = self::bcInc($spread_uid, 'reward', $indirect_reward, 'uid');
$res = $res1 && $res2 && $res3 && $res4;
//self::checkTrans($res);
if ($spread_level == 8)
return true;
$level = $spread_level;
$rate = $indirect_reward_rate;
}
}
return self::teamfenrun($spread_uid,$money,$level,$rate,$aid,$tuid);
}
return false;
}
此段代码是寄售转售溢价支付的核心代码
public function payOrder(Request $request){
list($id,$pwd,$aid) = UtilService::postMore([['id',0],['pwd',0],['aid',0]],$request,true);
if($id==0 || strlen($pwd) != 6 )return app('json')->fail('参数错误');
header('Access-Control-Allow-Origin:*');
$cache_name = 'cache_purchase_'.$request->uid();
if( cache($cache_name) )
return app('json')->fail('请勿频繁请求');
cache($cache_name,1,2);
$userinfo = User::find($request->uid());
$orderInfo = PurchaseModel::find($id);
$info = PremiumModel::where('num_id',$orderInfo->num)->find()->toArray();
if(!$orderInfo)return app('json')->fail('订单不存在');
if($orderInfo->status == 3)return app('json')->fail('订单已支付,请勿重复支付');
if(!password_verify($pwd,$userinfo->pay_pwd))return app('json')->fail('支付密码错误');
if($userinfo->now_money < $orderInfo->pay_price)return app('json')->fail('消费账户余额不足');
$prem = PremiumModel::where('num_id',13)->find()->toArray();
$userinfos = User::find($orderInfo->uid);
$oldMoney = bcsub($userinfo->now_money,$orderInfo->pay_price,2);
$guanggao = ActiveQuYu::where('id', YueOrder::where('id',$orderInfo->yid)->where('is_del',0)->value('quid'))->value('guanggao');
SpiritModel::beginTrans();
//扣除余额
try{
if($orderInfo->num == 14){
$list = PremiumModel::where('num_id',14)->field('pay_mc')->find();
$res7 = User::bcInc($orderInfo->uid,'now_money',$prem['pay_mc'],'uid');
$res8 = UserBill::income('订单转售',$orderInfo->uid,'now_money','pay_order',$prem['pay_mc'],$id,bcadd($userinfos->now_money,$prem['pay_mc'],2),'订单转售余额增加'.$prem['pay_mc']);
$res6 = PurchaseModel::edit(['status'=>8,'last_uid'=>$orderInfo->uid,'pay_time'=>date('Y-m-d H:i:s'),'uid'=>$request->uid(),'add_time'=>date('Y-m-d H:i:s')],$id,'id');
$res12 = User::bcInc($request->uid(),'shopping_intergral',$list['pay_mc'],'uid');
$res13 = UserShoppingJf::create(['uid'=>$request->uid(),'type'=>9,'status'=>1,'num'=>$list['pay_mc'],'add_time'=>date('Y-m-d H:i:s'),'from_uid'=>$id,'remark'=>'']);
$res14 = User::edit(['is_buy_order'=>1,'is_buy_time'=>time()],$request->uid(),'uid');
$res9 = Transfer::create(['uid'=>$request->uid(),'order_id'=>$orderInfo->id,'num'=>$orderInfo->num,'add_time'=>date('Y-m-d H:i:s')]);
$res20 = WhiteListModel::edit(['pay_order'=>time()],$request->uid(),'uid');
}else{
if($orderInfo->type == 2){//积分
$res12 = User::bcInc($request->uid(),'shopping_intergral',$info['pay_mc'],'uid');
$res13 = UserShoppingJf::create(['uid'=>$request->uid(),'type'=>9,'status'=>1,'num'=>$info['pay_mc'],'add_time'=>date('Y-m-d H:i:s'),'from_uid'=>$id,'remark'=>'']);
$res6 = PurchaseModel::edit(['status'=>8,'last_uid'=>$orderInfo->uid,'pay_time'=>date('Y-m-d H:i:s'),'uid'=>$request->uid(),'add_time'=>date('Y-m-d H:i:s')],$id,'id');
$res9 = Transfer::create(['uid'=>$request->uid(),'order_id'=>$orderInfo->id,'num'=>$orderInfo->num,'add_time'=>date('Y-m-d H:i:s')]);
$res20 = WhiteListModel::edit(['pay_order'=>time()],$request->uid(),'uid');
}else{
$res12 = $res13 = true;
$res6 = PurchaseModel::edit(['status'=>3,'last_uid'=>$orderInfo->uid,'sp_price_mr'=>$info['sp_price'],'pay_mr_price'=>$info['pay_mr'],'now_qy_price'=>$info['js_price'],'pay_price'=>$info['pay_mc'],'pay_time'=>date('Y-m-d H:i:s'),'uid'=>$request->uid(),'add_time'=>date('Y-m-d H:i:s')],$id,'id');
$res9 = Transfer::create(['uid'=>$orderInfo->uid,'order_id'=>$orderInfo->id,'num'=>$orderInfo->num-1,'add_time'=>date('Y-m-d H:i:s')]);
$res20 = true;
}
$res7 = User::bcInc($orderInfo->uid,'now_money',$orderInfo->pay_price,'uid');
$res8 = UserBill::income('订单转售',$orderInfo->uid,'now_money','pay_order',$orderInfo->pay_price,$id,bcadd($userinfos->now_money,$orderInfo->pay_price,2),'订单转售余额增加'.$orderInfo->pay_price);
$res14 = true;
}
$res2 = UserBill::expend('支付订单',$request->uid(),'now_money','pay_order',$orderInfo->pay_price,$id,$oldMoney,'支付订单减去余额'.$orderInfo->pay_price);
$res1 = User::where('uid',$request->uid())
->exp('buy_count',' buy_count + 1')
->exp('guanggao',' guanggao +'.$guanggao)
->exp('now_money',' now_money -'.$orderInfo->pay_price)
->update();
$res5 = GuanggaoNotice::create(['uid'=>$request->uid(),'num'=>$guanggao,'type'=>3,'status'=>1,'add_time'=>date('Y-m-d H:i:s'),'from_uid'=>$orderInfo->id,'remark'=>'支付成功解冻']);
$res11 = YueOrder::edit(['pay_status'=>2,'pay_time'=>date('Y-m-d H:i:s')],$orderInfo['yid'],'id');
$res15 = UserPayOrder::create(['uid'=>$request->uid(),'active_id'=>$aid,'pay_price'=>$orderInfo->pay_price,'order_price'=>$orderInfo['now_qy_price'],'add_time'=>time()]);
$res = $res1 && $res2 && $res6 && $res7 && $res8 && $res9 && $res11 && $res12 && $res13 && $res14 && $res15 && $res20 && $res5;
SpiritModel::checkTrans($res);
}catch (\Exception $exception){
SpiritModel::rollbackTrans();
return app('json')->fail('支付失败2');
}
try{
User::bcDec($request->uid(),'frozen_num',$guanggao,'uid');
} catch ( \Exception $e )
{
$res = true;
}
if($res){
$data = [
'uid'=>$request->uid(),
'price'=>$orderInfo['now_qy_price'],
'id'=>$orderInfo['id'],
'aid'=>$aid,
'pay_uid'=>$request->uid()
];
if($orderInfo['type']== 2){
return json(['status'=>200,'num'=>14,'msg'=>'支付成功']);
} else{
return json(['status'=>200,'num'=>0,'msg'=>'支付成功']);
}
}else{
return app('json')->fail('支付失败1');
}
}