0){ if($plan = RechargePlan::detail($data['recharge_plan_id'])){ if($plan['gift_type']['value'] == 10){ //优惠券 for($n=0;$n<$plan['gift_money'];$n++){ //计算优惠券到期时间 switch ($plan['coupon']['valid_time']['value']) { case '10': $expiretime = strtotime(date('Y-m-d').'23:59:59'); break; case '20': $expiretime = strtotime("+1 week"); break; case '30': $expiretime = strtotime("+1 month"); break; case '40': $expiretime = strtotime("+1 year"); break; default: $expiretime = time(); break; } $coupon[] = [ 'coupon_id' => $plan['coupon']['coupon_id'], 'type' => $plan['coupon']['type']['value'], 'rule' => $plan['coupon']['rule']['value'], 'expiretime' => $expiretime, 'shop_id' => $data['shop_id'], 'user_id' => $data['user_id'], 'applet_id' => $data['applet_id'] ]; } }else{ $gift_money = $plan['gift_money']; //赠送现金余额 } } } //更新用户余额信息 $user = User::get($data['user_id']); $user->money = ['inc', $data['money']+$gift_money];//增加余额 $user->save(); //添加交易记录 //是否赠送优惠券 if(sizeof($coupon) > 0){ $model = new CouponUser; $model->saveAll($coupon); } //微信 - 账单分账 if($data['type'] == 30){ $wxpay = new WxPay(SettingModel::getItem('wxpay',$data['applet_id'])); $wxpay->divide([ 'out_order_no' => $data['order_no'], 'transaction_id' => $transaction_id, 'total' => $data['money'], ],$data['applet_id']);//进行分账 } //$data['transaction_id'] = $transaction_id; $arr[0] = $data; if($gift_money > 0){ $arr[1] = $data; $arr[1]['money'] = $gift_money; $arr[1]['mode'] = 40;//赠送 $arr[1]['type'] = 10;//余额 } $this->saveAll($arr); return true; } }