diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index d704c2c4a..1dc074f92 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -25,6 +25,7 @@ use app\common\model\user\UserAddress; use app\common\model\user\UserRecharge; use app\common\model\user\UserShip; use app\common\model\user_sign\UserSign; +use app\common\model\vip_flow\VipFlow; use app\common\service\Curl; use app\common\service\PushService; use support\Log; @@ -212,6 +213,147 @@ class PayNotifyLogic extends BaseLogic // Redis::send('push-platform-print', ['id' => $order['id']], 60); // PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); + } + + //采购款支付后如果有对应的冻结的话就去反对应的log + public static function addFlowLog($order) + { + //查询当前用户有无对应的充值的冻结金额 + if($order['uid'] >0 ){ + $query = VipFlow::where([ + 'user_id'=>$order['uid'], + 'type'=>2, + 'status'=>0 + ]); + $query1 = clone $query; + $ids = $query->column('id'); + $check = $query->sum('back_num'); + $count = $query1->count(); + if($check && $check >0){ + $backPurchase = bcsub($order['pay_price'],0.1,2); + if($count == 1){ + //存在拆单子否 + //少了就冻结减去这个对应的金额 + $one = VipFlow::where([ + 'user_id'=>$order['uid'], + 'type'=>2, + 'status'=>0 + ])->find(); + $data = [ + 'vip_flow_id'=>$one['id'], + 'order_id' => $order['id'], + 'order_sn' => $order['order_id'], + 'user_id' => $order['uid'], + 'pay_type' => $pay_type ?? 1, + 'status' => 1, + 'type' => 1, + 'store_id' => $order['store_id'], + 'staff_id' => $order['staff_id'], + 'create_time' => time() + ]; + if($one['back_num'] >= $backPurchase){ + $data['number'] =$backPurchase; + Db::name('la_vip_flow_log')->insert($data); + //总的减去采购款百分之十剩余的 + $wait = bcsub($one['back_num'],$backPurchase,2); + if(empty($wait)){ + VipFlow::where('id',$one['id'])->update( + [ + 'back_num'=>0, + 'status'=>1 + ] + ); + }else{ + //add + VipFlow::where('id',$one['id'])->update([ + [ + 'back_num'=>$wait + ] + ]); + } + //并且加到对应的用户的采购款中 + User::where('id',$order['uid'])->inc('purchase_funds',$wait)->update(); + }else{ + //对比采购款支付的多少 多了就拿冻结金额即可 + $data['number'] =$one['number']; + //都存到对应的log日志 + Db::name('la_vip_flow_log')->insert($data); + VipFlow::where('id',$one['id'])->update( + [ + 'back_num'=>0, + 'status'=>1 + ] + ); + //并且加到对应的用户的采购款中 + User::where('id',$order['uid'])->inc('purchase_funds',$one['number'])->update(); + } + + }else{ + //大于0的时候 + //先处理金额大的再处理剩余的 + /**** 把所有的金额改为正的再加一条后再加***/ + VipFlow::where([ + 'user_id'=>$order['uid'], + 'type'=>2, + 'status'=>0 + ])->update([ + 'status'=>1, + 'remark'=>json_encode($ids) + ]); + if ($check >= $backPurchase) { + //补一条待解冻的 +// $data = [ +// 'order_id' => $order['id'], +// 'transaction_id' => $transaction_id ?? 0, +// 'order_sn' => $order['order_id'], +// 'user_id' => $order['uid'], +// 'number' => $total_vip, +// 'back_num' => $total_vip, +// 'pay_type' => $pay_type ?? 1, +// 'status' => 0, +// 'type' => 1, +// 'store_id' => $order['store_id'], +// 'staff_id' => $order['staff_id'], +// 'create_time' => time() +// ]; +// Db::name('vip_flow')->insert($data); + + }else{ + //log + $data = [ + 'vip_flow_id'=>0, + 'remark'=>$ids, + 'order_id' => $order['id'], + 'order_sn' => $order['order_id'], + 'user_id' => $order['uid'], + 'pay_type' => $pay_type ?? 1, + 'status' => 1, + 'type' => 1, + 'store_id' => $order['store_id'], + 'staff_id' => $order['staff_id'], + 'create_time' => time() + ]; + $data['number'] =$check; + Db::name('la_vip_flow_log')->insert($data); + User::where('id',$order['uid'])->inc('purchase_funds',$check)->update();//add + } + + + + + + } + + } + return true; + + } + + + + + + } /** @@ -453,6 +595,27 @@ class PayNotifyLogic extends BaseLogic return true; } + public static function dealRechargeFrozen($order) + { + $total_vip = bcmul($order['price'],0.1,2); + $data = [ + 'order_id' => $order['id'], + 'transaction_id' => $transaction_id ?? 0, + 'order_sn' => $order['order_id'], + 'user_id' => $order['uid'], + 'number' => $total_vip, + 'back_num' => $total_vip, + 'pay_type' => $pay_type ?? 1, + 'status' => 0, + 'type' => 1, + 'store_id' => $order['store_id'], + 'staff_id' => $order['staff_id'], + 'create_time' => time() + ]; + Db::name('vip_flow')->insert($data); + return true; + } + /** * 充值 @@ -498,6 +661,7 @@ class PayNotifyLogic extends BaseLogic if($order['other_uid']>0){ $uid=$order['other_uid']; } + self::dealRechargeFrozen($order); PushService::push('wechat_mmp_' . $uid, $uid, ['type'=>'INDUSTRYMEMBERS','msg'=>'订单支付成功','data'=>['id'=>$order['id'],'paid'=>1]]); PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type'=>'INDUSTRYMEMBERS','msg'=>'订单支付成功','data'=>['id'=>$order['id'],'paid'=>1]]); if (!empty($extra['payer']['openid'])) {