From f550a4a539d708375578473a074294ecf09ee8fc Mon Sep 17 00:00:00 2001 From: Hankin Date: Thu, 9 Apr 2026 13:52:20 +0800 Subject: [PATCH] store ufutx customer --- app/Http/Controllers/App/OrderController.php | 959 ++++++++++-------- app/Http/Controllers/Controller.php | 16 +- .../Controllers/Server/H5/OrderController.php | 656 +++++++----- app/Http/Controllers/TestController.php | 4 +- app/Models/Dma/DmaServiceUserRole.php | 11 + app/Models/Dma/S2Customer.php | 14 + app/Services/OrderService.php | 366 ++++--- config/database.php | 18 +- 8 files changed, 1207 insertions(+), 837 deletions(-) create mode 100644 app/Models/Dma/DmaServiceUserRole.php create mode 100644 app/Models/Dma/S2Customer.php diff --git a/app/Http/Controllers/App/OrderController.php b/app/Http/Controllers/App/OrderController.php index a2dc621..b762a9c 100644 --- a/app/Http/Controllers/App/OrderController.php +++ b/app/Http/Controllers/App/OrderController.php @@ -10,6 +10,8 @@ use App\Jobs\SendTemplateMsg; use App\Jobs\SyncClientComment; use App\Models\ConsultAccount; use App\Models\Course\CourseVideo; +use App\Models\Dma\DmaServiceUserRole; +use App\Models\Dma\S2Customer; use App\Models\SaasReservationConsultScheduling; use App\Models\Server\MerchantApplyment; use App\Models\Server\MerchantEvaluate; @@ -17,7 +19,9 @@ use App\Models\Server\SaasMemberBuyInfo; use App\Models\Server\SaasMemberLevel; use App\Models\Server\SaasMemberUser; use App\Models\Server\ShopAgentOrder; +use App\Models\Wechat; use App\Services\EvaluateService; +use App\Services\OrderService; use App\Services\SaasVipGainService; use App\Services\SaasVipNoticeService; use App\Services\SaasVipSpreadEarningService; @@ -74,7 +78,7 @@ use App\Utils\Messenger; use EasyWeChat\Kernel\Support\XML; class OrderController extends Controller { - use ResponseJson; + use ResponseJson; protected $sms; protected $orderCon; @@ -99,7 +103,7 @@ class OrderController extends Controller $order = Order::where('trade_no', $trade_no)->first(); $pay_order = PayOrder::where('trade_no', $trade_no)->first(); if (empty($pay_order)) { - $message = '订单不存在,订单号:'.$trade_no; + $message = '订单不存在,订单号:' . $trade_no; throw new \Exception($message, 1); } if ($pay_order->is_hooked) { @@ -115,26 +119,28 @@ class OrderController extends Controller $result = \WechatService::orderPaid($trade_no); $PayLog = new PayLog; $PayLog->type = 'activity'; - $PayLog->user_id = $order->user_id??0; + $PayLog->user_id = $order->user_id ?? 0; $PayLog->trade_no = $trade_no; - $PayLog->remark = '回调监听'.$result; + $PayLog->remark = '回调监听' . $result; $PayLog->save(); // $result = true; - }elseif ($order->pay_type === 'alipay') { + } elseif ($order->pay_type === 'alipay') { //todo 支付宝查询订单 $result = true; - }else{ + } else { throw new \Exception("订单检查失败", 1); } - if (empty($result)) return $this->failure('订单检查失败'); + if (empty($result)) + return $this->failure('订单检查失败'); $result = $this->markOrder($order, $pay_order); - if (empty($result)) return $this->failure('分类回调订单失败'); - }else{ + if (empty($result)) + return $this->failure('分类回调订单失败'); + } else { throw new \Exception("订单时间超过30天", 1); } } - $user = User::where('id',$order->user_id)->first(); - \CommonUtilsService::sendMiniBuySuccessNoticeToUser($order->goods,'oPC_2vudkf3stdiNgjA-e2n6t9_M','merchant',$order->price,$user->mobile,$user->nickname); + $user = User::where('id', $order->user_id)->first(); + \CommonUtilsService::sendMiniBuySuccessNoticeToUser($order->goods, 'oPC_2vudkf3stdiNgjA-e2n6t9_M', 'merchant', $order->price, $user->mobile, $user->nickname); return $this->success('ok'); } catch (\Exception $e) { $this->getError($e); @@ -151,7 +157,7 @@ class OrderController extends Controller $order = TouristOrder::where('trade_no', $trade_no)->first(); //$pay_order = PayOrder::where('trade_no', $trade_no)->first(); if (empty($order)) { - $message = '订单不存在,订单号:'.$trade_no; + $message = '订单不存在,订单号:' . $trade_no; throw new \Exception($message, 1); } if ($order->pay_status) { @@ -167,27 +173,30 @@ class OrderController extends Controller $result = \WechatService::orderPaid($trade_no); $PayLog = new PayLog; $PayLog->type = 'activity'; - $PayLog->user_id = $order->user_id??0; + $PayLog->user_id = $order->user_id ?? 0; $PayLog->trade_no = $trade_no; - $PayLog->remark = '回调监听'.$result; + $PayLog->remark = '回调监听' . $result; $PayLog->save(); // $result = true; - TouristOrder::where('trade_no', $order->trade_no)->update(['pay_status'=>1]); + TouristOrder::where('trade_no', $order->trade_no)->update(['pay_status' => 1]); // 给嘉宾编号 - if($order->account_id){ + if ($order->account_id) { $remark = $this->numMember($order); - if($remark) TouristOrder::where('trade_no', $order->trade_no)->update(['remark'=>$remark]); + if ($remark) + TouristOrder::where('trade_no', $order->trade_no)->update(['remark' => $remark]); } - }elseif ($order->pay_type === 'alipay') { + } elseif ($order->pay_type === 'alipay') { //todo 支付宝查询订单 $result = true; - }else{ + } else { throw new \Exception("订单检查失败", 1); } - if (empty($result)) throw new \Exception("微信端没有订单 订单未支付成功", 1); + if (empty($result)) + throw new \Exception("微信端没有订单 订单未支付成功", 1); - if (empty($result)) throw new \Exception("订单回调失败 订单未支付成功", 1); - }else{ + if (empty($result)) + throw new \Exception("订单回调失败 订单未支付成功", 1); + } else { throw new \Exception("订单时间超过30天", 1); } } @@ -204,7 +213,7 @@ class OrderController extends Controller $str_time2 = strtotime($time2) + 30 * 24 * 3600; if ($str_time1 >= $str_time2) {//已過期 return false; - }else{ + } else { return true; } } @@ -221,32 +230,38 @@ class OrderController extends Controller //会员订单 if ($order->type === 'rank') { $result = $this->markRankOrder($order, $pay_order); - if (empty($result)) throw new \Exception("回调会员订单失败", 1); - }elseif ($order->type === 'activity') { + if (empty($result)) + throw new \Exception("回调会员订单失败", 1); + } elseif ($order->type === 'activity') { $PayLog = new PayLog; $PayLog->type = 'activity'; - $PayLog->user_id = $order->user_id??0; - $PayLog->trade_no = $order->trade_no??0; + $PayLog->user_id = $order->user_id ?? 0; + $PayLog->trade_no = $order->trade_no ?? 0; $PayLog->remark = '回调活动监听'; $PayLog->save(); $result = $this->markActivityOrder($order, $pay_order); - if (empty($result)) throw new \Exception("回调活动订单失败", 1); - }elseif ($order->type === 'community') { - $result = $this->markCommunityOrder($order,$pay_order); - if (empty($result)) throw new \Exception("回调社群订单失败", 1); - }elseif ($order->type === 'single_service') { - $result = $this->markSingleServiceOrder($order,$pay_order); - if (empty($result)) throw new \Exception("回调单身服务订单失败", 1); - }elseif ($order->type === 'coin') {//福币充值订单 + if (empty($result)) + throw new \Exception("回调活动订单失败", 1); + } elseif ($order->type === 'community') { + $result = $this->markCommunityOrder($order, $pay_order); + if (empty($result)) + throw new \Exception("回调社群订单失败", 1); + } elseif ($order->type === 'single_service') { + $result = $this->markSingleServiceOrder($order, $pay_order); + if (empty($result)) + throw new \Exception("回调单身服务订单失败", 1); + } elseif ($order->type === 'coin') {//福币充值订单 $result = $this->markCoinOrder($order, $pay_order); - if (empty($result)) throw new \Exception("回调福币充值订单失败,订单号:".$order->trade_no, 1); - }elseif($order->type === 'course'){//购买课程 - $result = $this->markCourses($order,$pay_order); - if (empty($result)) throw new \Exception("回调购买课程订单失败", 1); + if (empty($result)) + throw new \Exception("回调福币充值订单失败,订单号:" . $order->trade_no, 1); + } elseif ($order->type === 'course') {//购买课程 + $result = $this->markCourses($order, $pay_order); + if (empty($result)) + throw new \Exception("回调购买课程订单失败", 1); } \DB::beginTransaction(); - PayOrder::where('trade_no', $order->trade_no)->update(['is_hooked'=>1,'pay_status'=>'PAID']); - Order::where('trade_no', $order->trade_no)->update(['pay_status'=>'PAID']); + PayOrder::where('trade_no', $order->trade_no)->update(['is_hooked' => 1, 'pay_status' => 'PAID']); + Order::where('trade_no', $order->trade_no)->update(['pay_status' => 'PAID']); \DB::commit(); StoreOrderWorthShare::dispatch($order, $pay_order)->onQueue('love'); return true; @@ -267,15 +282,18 @@ class OrderController extends Controller { try { $ratio_coin = RatioCoin::where('id', $order->type_id)->first(); - if (empty($ratio_coin)) throw new \Exception("福币比例不存在", 1); + if (empty($ratio_coin)) + throw new \Exception("福币比例不存在", 1); $user = User::find($order->user_id); - if (empty($user)) throw new \Exception("订单用户不存在", 1); + if (empty($user)) + throw new \Exception("订单用户不存在", 1); \DB::beginTransaction(); //增加福币充值记录 - $coin = $order->pay_type == 'ios'?$ratio_coin->ios_coin:$ratio_coin->coin; + $coin = $order->pay_type == 'ios' ? $ratio_coin->ios_coin : $ratio_coin->coin; $result = $user->addCoinLog('RECHARGE', $order->type_id, $coin); - if (empty($result)) throw new \Exception("增加福币记录失败", 1); + if (empty($result)) + throw new \Exception("增加福币记录失败", 1); //增加福币余额 $result = $user->updateCoinInfo('add', $coin); \DB::commit(); @@ -290,209 +308,218 @@ class OrderController extends Controller // 回调家与味道 public function familyOrder(Request $request, $trade_no) { - if(empty($trade_no)) - return $this->failure('没有回调订单号'); + if (empty($trade_no)) + return $this->failure('没有回调订单号'); $PayLog = new PayLog; $PayLog->type = 'family'; $PayLog->trade_no = $trade_no; - $result = FamilyOrder::where('trade_no',$trade_no)->first(); - if(!$result){ - $PayLog->remark = '订单号不存在:'.$trade_no; + $result = FamilyOrder::where('trade_no', $trade_no)->first(); + if (!$result) { + $PayLog->remark = '订单号不存在:' . $trade_no; $PayLog->save(); return $this->failure('没有回调订单号'); } - if($result->pay_status==1){ + if ($result->pay_status == 1) { $PayLog->remark = '订单已经回调'; $PayLog->save(); return $this->failure('订单已经回调'); } - if($result->price>0){ + if ($result->price > 0) { $PayLog->remark = '订单回调成功'; $PayLog->save(); - $result->pay_status=1; + $result->pay_status = 1; $result->save(); } $message = '就在刚刚,有位会员购买了《家的味道》礼盒,赶紧用电脑访问love.ufutx.com/admin 跟进吧!'; $mobile = 13825210868; Message::create([ - 'phone' => $mobile, - 'message' => $message, - 'confirmed' => 1, - 'code' => '家的味道购买通知', - 'ip' => request() ? request()->ip() : '127.0.0.1', - ]); + 'phone' => $mobile, + 'message' => $message, + 'confirmed' => 1, + 'code' => '家的味道购买通知', + 'ip' => request() ? request()->ip() : '127.0.0.1', + ]); Messenger::sendSMS($mobile, $message); return $this->success('订单回调成功'); } - // 回调 社群-参与活动 - public function CommunityOrder(Request $request, $trade_no) - { + // 回调 社群-参与活动 + public function CommunityOrder(Request $request, $trade_no) + { try { - if(empty($trade_no)) { + if (empty($trade_no)) { return $this->failure('没有回调订单号'); } $PayLog = new PayLog; - $result = TouristOrder::where('trade_no',$trade_no)->first(); - if(!$result){ - $PayLog->remark = '订单号不存在:'.$trade_no; + $result = TouristOrder::where('trade_no', $trade_no)->first(); + if (!$result) { + $PayLog->remark = '订单号不存在:' . $trade_no; $PayLog->save(); return $this->failure('没有回调订单号'); } - if($result->pay_status != 0){ + if ($result->pay_status != 0) { $PayLog->trade_no = $trade_no; $PayLog->remark = '订单已经回调'; $PayLog->save(); return $this->success('订单已经回调'); } - \Log::info('para:'.$request->getcontent()); - if(!$result->wechat_transaction_id){ - if($request->getcontent()){ + \Log::info('para:' . $request->getcontent()); + if (!$result->wechat_transaction_id) { + if ($request->getcontent()) { try { $xml = $request->getcontent(); $message = XML::parse($xml); - if($message && $message['transaction_id']) { + if ($message && $message['transaction_id']) { $result->wechat_transaction_id = $message['transaction_id']; $result->save(); } - }catch (\Exception $e){ - \Log::info('回调出错,信息:'.$request->getcontent()); + } catch (\Exception $e) { + \Log::info('回调出错,信息:' . $request->getcontent()); } } } if ($result->pay_type == "partner") { - $applyment = MerchantApplyment::where('m_id',$result->merchant_id)->first(); + $applyment = MerchantApplyment::where('m_id', $result->merchant_id)->first(); $pay_result = \WechatService::partnerOrderPaid($trade_no, $applyment->sub_mch_id); - if (empty($pay_result) || $pay_result->trade_state != "SUCCESS") return $this->failure("支付回调失败"); - }else { + if (empty($pay_result) || $pay_result->trade_state != "SUCCESS") + return $this->failure("支付回调失败"); + } else { $pay_result = \WechatService::orderPaid($trade_no); - if (empty($pay_result)) return $this->failure("支付回调失败"); + if (empty($pay_result)) + return $this->failure("支付回调失败"); } - $merchant = MerchantAccount::where('id',$result->merchant_id)->first(); - $merchant_openid = $merchant->openid??''; + $merchant = MerchantAccount::where('id', $result->merchant_id)->first(); + $merchant_openid = $merchant->openid ?? ''; $usermember = new UserMember(); - $usermember->type = $result->type??''; - $usermember->type_id = $result->type_id??''; - $usermember->m_id = $result->merchant_id??''; - $usermember->m_user_id = $result->account_id??''; - $usermember->pay_type = 'wechat'; - $usermember->trade_no = $trade_no??''; + $usermember->type = $result->type ?? ''; + $usermember->type_id = $result->type_id ?? ''; + $usermember->m_id = $result->merchant_id ?? ''; + $usermember->m_user_id = $result->account_id ?? ''; + $usermember->pay_type = 'wechat'; + $usermember->trade_no = $trade_no ?? ''; $usermember->save(); - if($result->price>0 && $result->type == 'community'){ + if ($result->price > 0 && $result->type == 'community') { $remark = $this->numMember($result); $result->remark = $remark; $PayLog->type = 'Community'; $PayLog->trade_no = $trade_no; $PayLog->remark = '订单回调成功'; $PayLog->save(); - $result->pay_status=1; + $result->pay_status = 1; $result->save();//社群活动回调 //发送通知 //判断是服务还是活动 - $res = CommunityActivity::where('id',$result->type_id)->first(); - if($res->class == 'one') $class = 'activity'; - if($res->class == 'many') $class = 'service'; - $merchant_openid =$merchant->openid??''; + $res = CommunityActivity::where('id', $result->type_id)->first(); + if ($res->class == 'one') + $class = 'activity'; + if ($res->class == 'many') + $class = 'service'; + $merchant_openid = $merchant->openid ?? ''; //多人报名增加手动签到 if ($result->linkmen && count(json_decode($result->linkmen, true)) >= 1) { AddVirtualMember::dispatch(json_decode($result->linkmen, true), $res, $result)->onQueue('love'); } // 商家 - if(!$merchant_openid){ - $merchant_openid = Anchor::where('id',$res->anchor_id)->value('openid'); + if (!$merchant_openid) { + $merchant_openid = Anchor::where('id', $res->anchor_id)->value('openid'); } // 发送给渠道 - $channel_openid = null ; - if($result->share_channel_id&&$result->share_channel_id != 'null'){ - $bind_m_user_id = MerchantShareChannel::where('id',$result->share_channel_id) + $channel_openid = null; + if ($result->share_channel_id && $result->share_channel_id != 'null') { + $bind_m_user_id = MerchantShareChannel::where('id', $result->share_channel_id) ->value('bind_m_user_id'); - if($bind_m_user_id){ - $channel_openid = MerchantUser::where('id',$bind_m_user_id)->value('openid'); + if ($bind_m_user_id) { + $channel_openid = MerchantUser::where('id', $bind_m_user_id)->value('openid'); } } + + // 友福活动将被邀请人添加到客户 + $orderService = new OrderService(); + $orderService->storeUftxCustomer($result); } - if($result->price>0 && $result->type=='course'){//课程回调 + if ($result->price > 0 && $result->type == 'course') {//课程回调 $PayLog->type = 'course'; $PayLog->trade_no = $trade_no; $PayLog->remark = '订单回调成功'; $PayLog->save(); \DB::table('courses')->increment('user_count'); - UserCourses::where('trade_no',$trade_no)->update(['status'=>1]); + UserCourses::where('trade_no', $trade_no)->update(['status' => 1]); $result->pay_status = 1; $result->save(); //发送通知 - $res = Course::where('id',$result->type_id)->first(); + $res = Course::where('id', $result->type_id)->first(); $class = $result->type; //商户 - $merchant_openid = Course::where('id',$result->type_id)->value('open_id'); - // 发送给渠道 - $channel_openid = null ; - if($result->share_channel_id&& $result->share_channel_id != 'null'){ - $bind_m_user_id = MerchantShareChannel::where('id',$result->share_channel_id) + $merchant_openid = Course::where('id', $result->type_id)->value('open_id'); + // 发送给渠道 + $channel_openid = null; + if ($result->share_channel_id && $result->share_channel_id != 'null') { + $bind_m_user_id = MerchantShareChannel::where('id', $result->share_channel_id) ->value('bind_m_user_id'); - if($bind_m_user_id){ - $channel_openid = MerchantUser::where('id',$bind_m_user_id)->value('openid'); + if ($bind_m_user_id) { + $channel_openid = MerchantUser::where('id', $bind_m_user_id)->value('openid'); } } } - if($result->price>0 && $result->type =='member') {//saas会员回调 + if ($result->price > 0 && $result->type == 'member') {//saas会员回调 $pay_result = \WechatService::orderPaid($trade_no); - if($pay_result) { - $member_user = SaasMemberUser::where('merchant_id',$result->merchant_id) - ->where('member_level_id',$result->type_id) - ->where('merchant_user_id',$result->account_id) - ->first(); - $level = SaasMemberLevel::where('merchant_id',$result->merchant_id) - ->where('id',$result->type_id) - ->first(); - if($member_user){ + if ($pay_result) { + $member_user = SaasMemberUser::where('merchant_id', $result->merchant_id) + ->where('member_level_id', $result->type_id) + ->where('merchant_user_id', $result->account_id) + ->first(); + $level = SaasMemberLevel::where('merchant_id', $result->merchant_id) + ->where('id', $result->type_id) + ->first(); + if ($member_user) { $expire = Carbon::parse($member_user->expire_time)->timestamp; - if($expire > Carbon::now()->timestamp) { + if ($expire > Carbon::now()->timestamp) { $member_user_expire = Carbon::parse($member_user->expire_time) - ->addYear($level->level_years) - ->addMonths($level->level_month)->toDateTimeString(); + ->addYear($level->level_years) + ->addMonths($level->level_month)->toDateTimeString(); $member_user->expire_time = $member_user_expire; - }else{ + } else { $member_user->expire_time = Carbon::now()->addYear($level->level_years) - ->addMonths($level->level_month)->toDateTimeString();; + ->addMonths($level->level_month)->toDateTimeString(); + ; } $member_user->save(); - }else{ + } else { $member_user = new SaasMemberUser(); $member_user->merchant_id = $result->merchant_id; $member_user->merchant_user_id = $result->account_id; $member_user->member_level_id = $result->type_id; - $member_user_expire = Carbon::parse($result->created_at)->addYear($level->level_years) - ->addMonths($level->level_month)->toDateTimeString(); + $member_user_expire = Carbon::parse($result->created_at)->addYear($level->level_years) + ->addMonths($level->level_month)->toDateTimeString(); $member_user->expire_time = $member_user_expire; $member_user->save(); } $result->pay_status = 1; $result->save(); //天路合一 - if($result->merchant_id == 1094 || $result->merchant_id == 596){ + if ($result->merchant_id == 1094 || $result->merchant_id == 596) { //发放未领取权益 $s1 = new SaasVipGainService(); $s1->grantNotUseGain($result); //收益逻辑 // if($result->merchant_id == 1094){ - $s2 = new SaasVipSpreadEarningService(); -// }else{ + $s2 = new SaasVipSpreadEarningService(); + // }else{ // //测试 // $s2 = new SaasVipSpreadEarningTestService(); // } $s2->earningLogic($result->id); } return 'success'; - }else{ - \Log::info('回调出错,确认支付异常,信息:'.$request->getcontent()); + } else { + \Log::info('回调出错,确认支付异常,信息:' . $request->getcontent()); return $this->failure('回调出错'); } } - if($result->price>0 && $result->type=='shop'){//商城商品回调 + if ($result->price > 0 && $result->type == 'shop') {//商城商品回调 $PayLog->type = 'shop'; $PayLog->trade_no = $trade_no; $PayLog->remark = '订单回调成功'; @@ -500,27 +527,27 @@ class OrderController extends Controller $result->pay_status = 1; $result->save(); //发送通知 - $res = MerchantShop::where('id',$result->type_id)->first(); + $res = MerchantShop::where('id', $result->type_id)->first(); //给用户 $class = $result->type; //给商户 - $merchant_openid = $merchant->openid??''; - if(!$merchant_openid){ - $merchant_openid = Anchor::where('m_id',$res->merchant_id)->value('openid'); + $merchant_openid = $merchant->openid ?? ''; + if (!$merchant_openid) { + $merchant_openid = Anchor::where('m_id', $res->merchant_id)->value('openid'); } // 发送给渠道 - $channel_openid = null ; + $channel_openid = null; // 发送给渠道 - if($result->share_channel_id&& $result->share_channel_id != 'null'){ - $bind_m_user_id = MerchantShareChannel::where('id',$result->share_channel_id) + if ($result->share_channel_id && $result->share_channel_id != 'null') { + $bind_m_user_id = MerchantShareChannel::where('id', $result->share_channel_id) ->value('bind_m_user_id'); - if($bind_m_user_id){ - $channel_openid = MerchantUser::where('id',$bind_m_user_id)->value('openid'); + if ($bind_m_user_id) { + $channel_openid = MerchantUser::where('id', $bind_m_user_id)->value('openid'); } } } - if($result->price>0 && $result->type=='evaluate') {//评测回调 - $res = MerchantEvaluate::where('id',$result->type_id)->first(); + if ($result->price > 0 && $result->type == 'evaluate') {//评测回调 + $res = MerchantEvaluate::where('id', $result->type_id)->first(); $PayLog->remark = '订单回调成功'; $PayLog->type = 'evaluate'; $PayLog->trade_no = $trade_no; @@ -530,18 +557,18 @@ class OrderController extends Controller EvaluateService::testUpdate($trade_no); $class = 'evaluate'; // 发送给渠道 - $channel_openid = null ; + $channel_openid = null; // 发送给渠道 - if($result->share_channel_id&& $result->share_channel_id != 'null'){ - $bind_m_user_id = MerchantShareChannel::where('id',$result->share_channel_id) + if ($result->share_channel_id && $result->share_channel_id != 'null') { + $bind_m_user_id = MerchantShareChannel::where('id', $result->share_channel_id) ->value('bind_m_user_id'); - if($bind_m_user_id){ - $channel_openid = MerchantUser::where('id',$bind_m_user_id)->value('openid'); + if ($bind_m_user_id) { + $channel_openid = MerchantUser::where('id', $bind_m_user_id)->value('openid'); } } } - if($result->price>0 && $result->type=='consult') {//评测拼团回调 - $res = Consultation::where('id',$result->type_id)->first(); + if ($result->price > 0 && $result->type == 'consult') {//评测拼团回调 + $res = Consultation::where('id', $result->type_id)->first(); $PayLog->remark = '订单回调成功'; $PayLog->type = 'consult'; $PayLog->trade_no = $trade_no; @@ -550,13 +577,13 @@ class OrderController extends Controller $result->save(); $class = 'consult'; // 发送给渠道 - $channel_openid = null ; + $channel_openid = null; // 发送给渠道 - if($result->share_channel_id&& $result->share_channel_id != 'null'){ - $bind_m_user_id = MerchantShareChannel::where('id',$result->share_channel_id) + if ($result->share_channel_id && $result->share_channel_id != 'null') { + $bind_m_user_id = MerchantShareChannel::where('id', $result->share_channel_id) ->value('bind_m_user_id'); - if($bind_m_user_id){ - $channel_openid = MerchantUser::where('id',$bind_m_user_id)->value('openid'); + if ($bind_m_user_id) { + $channel_openid = MerchantUser::where('id', $bind_m_user_id)->value('openid'); } } } @@ -566,87 +593,91 @@ class OrderController extends Controller } //同步备注 SyncClientComment::dispatch($result)->onQueue('love'); - if($result->group_id){//是否成团 - $history = CollageGroupHistories::where('m_order_id',$result->id)->first(); - $group = CollageGroup::where('id',$result->group_id)->first(); - if(!$history || !$group){ + if ($result->group_id) {//是否成团 + $history = CollageGroupHistories::where('m_order_id', $result->id)->first(); + $group = CollageGroup::where('id', $result->group_id)->first(); + if (!$history || !$group) { //出错了 } - $param = $this->getGroupParams($result,$group,$history->deadline,0); - if($history->is_initiator == 1){//是团长 发送开团通知 - CollageGroupBatch::create(['history_id'=>$history->id,'batch'=>$history->id]); + $param = $this->getGroupParams($result, $group, $history->deadline, 0); + if ($history->is_initiator == 1) {//是团长 发送开团通知 + CollageGroupBatch::create(['history_id' => $history->id, 'batch' => $history->id]); \WechatService::stratGroupNotice($param); - }else{//是团员 发送参团通知 - $history_i_id = CollageGroupHistories::where('group_id',$result->group_id)->where('is_initiator',1) - ->where('deadline',$history->deadline)->value('id'); - CollageGroupBatch::create(['history_id'=>$history->id,'batch'=>$history_i_id]); + } else {//是团员 发送参团通知 + $history_i_id = CollageGroupHistories::where('group_id', $result->group_id)->where('is_initiator', 1) + ->where('deadline', $history->deadline)->value('id'); + CollageGroupBatch::create(['history_id' => $history->id, 'batch' => $history_i_id]); \WechatService::sendJoinGroupNotice($param); } - $m_order_ids = CollageGroupHistories::where('group_id',$history->group_id) - ->where('deadline',$history->deadline)->pluck('m_order_id')->toArray(); + $m_order_ids = CollageGroupHistories::where('group_id', $history->group_id) + ->where('deadline', $history->deadline)->pluck('m_order_id')->toArray(); // 目前参与人员数量 - $num = TouristOrder::whereIn('id',$m_order_ids)->whereIn('pay_status',[1,4])->get()->count(); - if($group->require_num == $num){ - CollageGroupHistories::whereIn('m_order_id',$m_order_ids)->update(['status'=>1]); + $num = TouristOrder::whereIn('id', $m_order_ids)->whereIn('pay_status', [1, 4])->get()->count(); + if ($group->require_num == $num) { + CollageGroupHistories::whereIn('m_order_id', $m_order_ids)->update(['status' => 1]); //本次拼团成功(给所有拼团人员发) - $notice_users = TouristOrder::whereIn('id',$m_order_ids)->whereIn('pay_status',[1,4])->get(); - foreach ($notice_users as $notice_user) { - $param = $this->getGroupParams($notice_user,$group,$history->deadline,1); + $notice_users = TouristOrder::whereIn('id', $m_order_ids)->whereIn('pay_status', [1, 4])->get(); + foreach ($notice_users as $notice_user) { + $param = $this->getGroupParams($notice_user, $group, $history->deadline, 1); \WechatService::sendJoinGroupNotice($param); } } } // 给用户 - \CommonUtilsService::sendBuySuccessNoticeToUser($res,$result->open_id,$class,$trade_no,$result->price); + \CommonUtilsService::sendBuySuccessNoticeToUser($res, $result->open_id, $class, $trade_no, $result->price); if ($result->channel == 0) { - //发送商户 - \CommonUtilsService::sendBuySuccessNoticeToBusiness($res,$merchant_openid,'merchant',$result->price,$result->mobile,$result->name); + //发送商户 + \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $merchant_openid, 'merchant', $result->price, $result->mobile, $result->name); } - if( $result->merchant_id == 491 ){ + if ($result->merchant_id == 491) { //给客服脱单姐 管理员 $openids = [ - "oPC_2vn6Q3M5jQpw9xAS7NNCMfjs", "oPC_2vudkf3stdiNgjA-e2n6t9_M","oPC_2vtrwOLgWHLwVEFTFsJ7N7fw","oPC_2vt7nGwKk_OFzJL70SlVuTiU","oPC_2vg_Eur-Wa_Vwnx9JiyRVn9Q + "oPC_2vn6Q3M5jQpw9xAS7NNCMfjs", + "oPC_2vudkf3stdiNgjA-e2n6t9_M", + "oPC_2vtrwOLgWHLwVEFTFsJ7N7fw", + "oPC_2vt7nGwKk_OFzJL70SlVuTiU", + "oPC_2vg_Eur-Wa_Vwnx9JiyRVn9Q " ]; foreach ($openids as $openid) { - \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $openid,'merchant',$result->price,$result->mobile,$result->name); + \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $openid, 'merchant', $result->price, $result->mobile, $result->name); } - + } //发送推荐人 - if($result->from_openid && $result->from_openid != 'null'){ - \CommonUtilsService::sendBuySuccessNoticeToBusiness($res,$result->from_openid,'recommend',$result->price,$result->mobile,$result->name); + if ($result->from_openid && $result->from_openid != 'null') { + \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $result->from_openid, 'recommend', $result->price, $result->mobile, $result->name); } // 首邀 - $first_invitation = AccessRecord::where('open_id',$result->open_id)->where('account_id',$result->merchant_id)->value('from_openid'); - if($first_invitation&&$first_invitation!=$result->from_openid){ - \CommonUtilsService::sendBuySuccessNoticeToBusiness($res,$first_invitation,'first_invitation',$result->price,$result->mobile,$result->name); + $first_invitation = AccessRecord::where('open_id', $result->open_id)->where('account_id', $result->merchant_id)->value('from_openid'); + if ($first_invitation && $first_invitation != $result->from_openid) { + \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $first_invitation, 'first_invitation', $result->price, $result->mobile, $result->name); } // 渠道 - if($result->channel ==0 && $channel_openid){ - \CommonUtilsService::sendBuySuccessNoticeToBusiness($res,$channel_openid,'channel',$result->price,$result->mobile,$result->name); + if ($result->channel == 0 && $channel_openid) { + \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $channel_openid, 'channel', $result->price, $result->mobile, $result->name); } // app消息推送 - if(isset($merchant->info->android_id)){ + if (isset($merchant->info->android_id)) { // 推送平台 ios android $params['platform'] = 'android'; // 推送标题 $params['title'] = '收到新订单提醒通知'; // 推送内容 - $params['content'] = $res->title.'收到付款'.$result->price.'元'; + $params['content'] = $res->title . '收到付款' . $result->price . '元'; // 通知栏样式 ID $params['builderId'] = 1; // 唤醒APP - $params['intent'] = ['url'=>'intent:#Intent;action=com.love.ufutx.saas.ui.main.MainActivity;component=com.love.ufutx.saas/com.love.ufutx.saas.ui.main.MainActivity;end']; + $params['intent'] = ['url' => 'intent:#Intent;action=com.love.ufutx.saas.ui.main.MainActivity;component=com.love.ufutx.saas/com.love.ufutx.saas.ui.main.MainActivity;end']; $params['uri_activity'] = 'com.love.ufutx.saas.ui.main.MainActivity'; $params['uri_action'] = 'com.love.ufutx.saas.ui.main.MainActivity'; // 附加字段(这里自定义 Key / value 信息,以供业务使用) $params['extras'] = [ - 'url' => 'https://love.ufutx.com/pu_m/#/orderDetail/'.$result->id.'?type='.$result->type.'&equipmentType=android', + 'url' => 'https://love.ufutx.com/pu_m/#/orderDetail/' . $result->id . '?type=' . $result->type . '&equipmentType=android', ]; // 推送类型 1-别名 2-注册id 3-全部 $params['type'] = 2; @@ -658,16 +689,16 @@ class OrderController extends Controller } $redis = Redis::connection('big_data'); - Log::info('checkEarningOrder earning:order:ids '.$result->id); + Log::info('checkEarningOrder earning:order:ids ' . $result->id); $redis->lpush('earning:order:ids', $result->id); //短信通知商家 - $jump_url = env('APP_URL').'/pu_m/#/earningsRecord?merchant_id='.$merchant->id; - $short_url = \CommonUtilsService::shortUrl(env('APP_URL').'/h5/#/jump_url?url='.$jump_url); + $jump_url = env('APP_URL') . '/pu_m/#/earningsRecord?merchant_id=' . $merchant->id; + $short_url = \CommonUtilsService::shortUrl(env('APP_URL') . '/h5/#/jump_url?url=' . $jump_url); $title = $res->title; - if(mb_strlen($title)>5){ - $title = mb_substr($title,0,5,'utf-8').'...'; + if (mb_strlen($title) > 5) { + $title = mb_substr($title, 0, 5, 'utf-8') . '...'; } - $message = '有用户下单了~ '.$result->name.'购买了平台的《'.$title.'》'.$result->price.'元,点击'.$short_url['url'].' 查看详情'; + $message = '有用户下单了~ ' . $result->name . '购买了平台的《' . $title . '》' . $result->price . '元,点击' . $short_url['url'] . ' 查看详情'; if ($merchant->mobile) { Messenger::sendSMS($merchant->mobile, $message); //增加记录 @@ -681,22 +712,22 @@ class OrderController extends Controller } // 发送短信给渠道分享人 - if($result->share_channel_id&& $result->share_channel_id != 'null'){ - $share_channel = MerchantShareChannel::where('id',$result->share_channel_id)->first(); - if(!empty($share_channel)){ - $merchant_user = MerchantUser::where('id',$share_channel->bind_m_user_id)->first(); - if($merchant_user && $merchant_user->mobile){ - $share_message = 'Hi,'.$merchant_user->nickname.',刚刚有人通过你的渠道「'.$share_channel->title.'」购买了'.$res->title; + if ($result->share_channel_id && $result->share_channel_id != 'null') { + $share_channel = MerchantShareChannel::where('id', $result->share_channel_id)->first(); + if (!empty($share_channel)) { + $merchant_user = MerchantUser::where('id', $share_channel->bind_m_user_id)->first(); + if ($merchant_user && $merchant_user->mobile) { + $share_message = 'Hi,' . $merchant_user->nickname . ',刚刚有人通过你的渠道「' . $share_channel->title . '」购买了' . $res->title; Messenger::sendSMS($merchant_user->mobile, $share_message); } } } //插入购买通知 // $pay_name = $result->user ? $result->user->nickname : '匿名用户'; - $content = $result->name.'购买了【'.$res->title.'】查看订单详情>>'; - SaasNotice::addRecord($result->merchant_id,$result->account_id,'order',$result->id,$content,0); - if($result->user_coupon_id){ - $user_coupon = UserCoupon::where('id',$result->user_coupon_id)->update(['status' => 1]); + $content = $result->name . '购买了【' . $res->title . '】查看订单详情>>'; + SaasNotice::addRecord($result->merchant_id, $result->account_id, 'order', $result->id, $content, 0); + if ($result->user_coupon_id) { + $user_coupon = UserCoupon::where('id', $result->user_coupon_id)->update(['status' => 1]); } Log::info("订单类型:{$result->type}, 类型id:{$result->type_id}"); if ($result->type == "community" && $result->type_id == 2451) {//通知企业微信 @@ -710,23 +741,25 @@ class OrderController extends Controller } } + + public function wechatWorkNotice($order) { $header = "2024开年餐宴·早鸟票\r\n"; $line = "-----------------------\r\n"; $omit = "...\r\n"; - $orders = TouristOrder::whereIn("pay_status", [1,4])->where("type", $order->type)->where('type_id', $order->type_id) + $orders = TouristOrder::whereIn("pay_status", [1, 4])->where("type", $order->type)->where('type_id', $order->type_id) ->where('id', '<=', $order->id)->orderByDesc('id')->limit(3)->get(); - $count = TouristOrder::whereIn("pay_status", [1,4])->where("type", $order->type)->where('type_id', $order->type_id)->where('id', '<=', $order->id)->count(); - if (empty($orders)) return ; + $count = TouristOrder::whereIn("pay_status", [1, 4])->where("type", $order->type)->where('type_id', $order->type_id)->where('id', '<=', $order->id)->count(); + if (empty($orders)) + return; $index = 0; - foreach ($orders as $order) - { + foreach ($orders as $order) { $linkmen = json_decode($order->linkmen, true); - $linkmen_num = $linkmen?count($linkmen):0; + $linkmen_num = $linkmen ? count($linkmen) : 0; $num = $count - $index; - $name = $linkmen[0]['name']??$order->name; - $introduce_name = MerchantUser::where('openid',$order->from_openid)->value('nickname'); + $name = $linkmen[0]['name'] ?? $order->name; + $introduce_name = MerchantUser::where('openid', $order->from_openid)->value('nickname'); $name_arr[] = "{$num}:{$name} {$linkmen_num} 介绍人 {$introduce_name}\r\n"; $index++; } @@ -737,7 +770,7 @@ class OrderController extends Controller $send_data = [ 'msgtype' => 'markdown', 'markdown' => [ - 'content' => $header.$line.$omit.$omit.$omit.$name_str.$line.$img.$url, + 'content' => $header . $line . $omit . $omit . $omit . $name_str . $line . $img . $url, ] ]; //正式 @@ -747,18 +780,19 @@ class OrderController extends Controller $response = \App\Utils\Http::post($url, json_encode($send_data)); } - public function getGroupParams($order,$group,$deadline,$status = 0){ - $history_id = CollageGroupHistories::where('m_order_id',$order->id)->value('id'); + public function getGroupParams($order, $group, $deadline, $status = 0) + { + $history_id = CollageGroupHistories::where('m_order_id', $order->id)->value('id'); $param['openid'] = $order->open_id; $param['order_id'] = $order->id; $param['title'] = $order->desc; - $param['price'] = $order->price.'元'; - $param['num'] = $group->require_num.'人'; + $param['price'] = $order->price . '元'; + $param['num'] = $group->require_num . '人'; $param['deadline'] = $deadline; //发送给团员的温馨提示 $param['team_desc'] = '您已成功参与拼团,具体拼团成败请留意通知'; //发送给团张的温馨提示 - $param['lead_desc'] = '本团有效期为'.$group->expire_in.'小时 赶紧邀请好友来拼团吧'; + $param['lead_desc'] = '本团有效期为' . $group->expire_in . '小时 赶紧邀请好友来拼团吧'; $param['desc'] = '恭喜你,本次拼团已成功'; $param['status'] = $status; $param['history_id'] = $history_id; @@ -766,66 +800,69 @@ class OrderController extends Controller } //拼团订单回调 - public function groupOrder(Request $request,$trade_no){ - if(empty($trade_no)){ + public function groupOrder(Request $request, $trade_no) + { + if (empty($trade_no)) { return $this->failure('没有回调订单号'); } - $result = TouristOrder::where('trade_no',$trade_no)->first(); + $result = TouristOrder::where('trade_no', $trade_no)->first(); $log = new PayLog; $log->type = 'group'; $log->trade_no = $trade_no; - if(!$result){ - $log->remark = '订单号不存在:'.$trade_no; + if (!$result) { + $log->remark = '订单号不存在:' . $trade_no; $log->save(); return $this->failure('没有回调订单号'); } - if($result->pay_status==1 || $result->pay_status==4){ + if ($result->pay_status == 1 || $result->pay_status == 4) { $log->remark = '订单已经回调'; $log->save(); return $this->failure('订单已经回调'); } - if($result->price<=0){ + if ($result->price <= 0) { $log->remark = '订单回调成功'; $log->save(); - $result->pay_status=1; + $result->pay_status = 1; $result->save(); } if ($result->pay_type == "partner") { - $applyment = MerchantApplyment::where('m_id',$result->merchant_id)->first(); + $applyment = MerchantApplyment::where('m_id', $result->merchant_id)->first(); $pay_result = \WechatService::partnerOrderPaid($trade_no, $applyment->sub_mch_id); - if (empty($pay_result) || $pay_result->trade_state != "SUCCESS") return $this->failure("支付回调失败"); - }else { + if (empty($pay_result) || $pay_result->trade_state != "SUCCESS") + return $this->failure("支付回调失败"); + } else { $pay_result = \WechatService::orderPaid($trade_no); - if (empty($pay_result)) return $this->failure("支付回调失败"); + if (empty($pay_result)) + return $this->failure("支付回调失败"); } $log->remark = '订单回调成功'; $log->save(); - $result->pay_status=1; + $result->pay_status = 1; $result->save(); - $history = CollageGroupHistories::where('m_order_id',$result->id)->first(); - if($history->is_initiator){ + $history = CollageGroupHistories::where('m_order_id', $result->id)->first(); + if ($history->is_initiator) { $collageGroupBatch = new CollageGroupBatch(); - $collageGroupBatch->history_id = $history->id; - $collageGroupBatch->batch = $history->id; + $collageGroupBatch->history_id = $history->id; + $collageGroupBatch->batch = $history->id; $collageGroupBatch->save(); - }else{ + } else { $collageGroupBatch = new CollageGroupBatch(); - $collageGroupBatch->history_id = $history->id; - $collageGroupBatch->batch = $history->group_master_id; + $collageGroupBatch->history_id = $history->id; + $collageGroupBatch->batch = $history->group_master_id; $collageGroupBatch->save(); } - $history_ids = CollageGroupBatch::where('batch',$history->group_master_id)->pluck('history_id')->toArray(); + $history_ids = CollageGroupBatch::where('batch', $history->group_master_id)->pluck('history_id')->toArray(); $num = sizeof($history_ids); - $group = CollageGroup::where('id',$result->group_id)->first(); - if( $num >= $group->require_num) { - CollageGroupHistories::whereIn('id',$history_ids)->update(['status'=>1]); - $order_ids = CollageGroupHistories::whereIn('id',$history_ids)->pluck('m_order_id'); - $orders = TouristOrder::whereIn('id',$order_ids)->whereIn('pay_status',[1,4]) - ->where('group_id',$history->group_id) + $group = CollageGroup::where('id', $result->group_id)->first(); + if ($num >= $group->require_num) { + CollageGroupHistories::whereIn('id', $history_ids)->update(['status' => 1]); + $order_ids = CollageGroupHistories::whereIn('id', $history_ids)->pluck('m_order_id'); + $orders = TouristOrder::whereIn('id', $order_ids)->whereIn('pay_status', [1, 4]) + ->where('group_id', $history->group_id) ->get(); - foreach ($orders as $order){ - if($result->type == 'course') { - if(!$history->group_master_id){ + foreach ($orders as $order) { + if ($result->type == 'course') { + if (!$history->group_master_id) { continue; } switch ($order->channel) { @@ -847,37 +884,41 @@ class OrderController extends Controller 'remark' => '点击详情可查看课程', ] ]; - Log::info('订单ID='.$trade_no.'发起拼团通知'); + Log::info('订单ID=' . $trade_no . '发起拼团通知'); //通知用户 SendTemplateMsg::dispatch($param)->onQueue("love"); break; } } } - switch ($group->type){ + switch ($group->type) { case 'course': - foreach ($orders as $order){ - UserCourses::where('trade_no',$order->trade_no)->update(['status'=>1]); + foreach ($orders as $order) { + UserCourses::where('trade_no', $order->trade_no)->update(['status' => 1]); } break; } } - if($result->price>0 && $result->type == 'community'){ - $res = CommunityActivity::where('id',$result->type_id)->first(); + if ($result->price > 0 && $result->type == 'community') { + $res = CommunityActivity::where('id', $result->type_id)->first(); } - if($result->price>0 && $result->type=='course'){//课程回调 - $res = Course::where('id',$result->type_id)->first(); + if ($result->price > 0 && $result->type == 'course') {//课程回调 + $res = Course::where('id', $result->type_id)->first(); } - if( $result->merchant_id == 491 ){ + if ($result->merchant_id == 491) { //给客服脱单姐 // \CommonUtilsService::sendBuySuccessNoticeToBusiness($res,'oPC_2vudkf3stdiNgjA-e2n6t9_M','merchant',$result->price,$result->mobile,$result->name); $openids = [ - "oPC_2vn6Q3M5jQpw9xAS7NNCMfjs", "oPC_2vudkf3stdiNgjA-e2n6t9_M","oPC_2vtrwOLgWHLwVEFTFsJ7N7fw","oPC_2vt7nGwKk_OFzJL70SlVuTiU","oPC_2vg_Eur-Wa_Vwnx9JiyRVn9Q + "oPC_2vn6Q3M5jQpw9xAS7NNCMfjs", + "oPC_2vudkf3stdiNgjA-e2n6t9_M", + "oPC_2vtrwOLgWHLwVEFTFsJ7N7fw", + "oPC_2vt7nGwKk_OFzJL70SlVuTiU", + "oPC_2vg_Eur-Wa_Vwnx9JiyRVn9Q " ]; foreach ($openids as $openid) { - \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $openid,'merchant',$result->price,$result->mobile,$result->name); + \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $openid, 'merchant', $result->price, $result->mobile, $result->name); } } return $this->success('ok'); @@ -886,149 +927,152 @@ class OrderController extends Controller // 回调咨询订单 public function consultation(Request $request, $trade_no) { - if(empty($trade_no)) - return $this->failure('没有回调订单号'); + if (empty($trade_no)) + return $this->failure('没有回调订单号'); $PayLog = new PayLog; $PayLog->type = 'Consultation'; $PayLog->trade_no = $trade_no; - $result = ConsultationRecords::where('trade_no',$trade_no)->first(); - $config = TouristOrder::where('trade_no',$trade_no)->first(); + $result = ConsultationRecords::where('trade_no', $trade_no)->first(); + $config = TouristOrder::where('trade_no', $trade_no)->first(); if ($config->pay_type == "partner") { - $applyment = MerchantApplyment::where('m_id',$config->merchant_id)->first(); + $applyment = MerchantApplyment::where('m_id', $config->merchant_id)->first(); $pay_result = \WechatService::partnerOrderPaid($trade_no, $applyment->sub_mch_id); - if (empty($pay_result) || $pay_result->trade_state != "SUCCESS") return $this->failure("支付回调失败"); - }else { + if (empty($pay_result) || $pay_result->trade_state != "SUCCESS") + return $this->failure("支付回调失败"); + } else { $pay_result = \WechatService::orderPaid($trade_no); - if (empty($pay_result)) return $this->failure("支付回调失败"); + if (empty($pay_result)) + return $this->failure("支付回调失败"); } - $scheduling = SaasReservationConsultScheduling::where('id',$result->scheduling_id) - ->where('merchant_id',$result->merchant_id) + $scheduling = SaasReservationConsultScheduling::where('id', $result->scheduling_id) + ->where('merchant_id', $result->merchant_id) ->first(); - if(!$result){ - $PayLog->remark = '订单号不存在:'.$trade_no; + if (!$result) { + $PayLog->remark = '订单号不存在:' . $trade_no; $PayLog->save(); return $this->failure('没有回调订单号'); } - if($result->pay_status==1){ + if ($result->pay_status == 1) { $PayLog->remark = '订单已经回调'; $PayLog->save(); return $this->failure('订单已经回调'); } - if($result->price>0){ + if ($result->price > 0) { $PayLog->remark = '订单回调成功'; $PayLog->save(); - $result->pay_status=1; -// $result->save(); - $config->pay_status=1; + $result->pay_status = 1; + // $result->save(); + $config->pay_status = 1; $config->save(); } //是否有选择指定预约时间段 - if($scheduling){ - $scheduling->decrement('residue_num',1); + if ($scheduling) { + $scheduling->decrement('residue_num', 1); $result->reservation_time = "{$scheduling->date} {$scheduling->date_range}"; } $result->save(); - if ($config->user_coupon_id){ + if ($config->user_coupon_id) { $user_coupon = UserCoupon::query()->find($config->user_coupon_id); - if ($user_coupon){ + if ($user_coupon) { $user_coupon->status = 1; $user_coupon->save(); } } - if($config->group_id){//是否成团 - $history = CollageGroupHistories::where('m_order_id',$config->id)->first(); - $group = CollageGroup::where('id',$config->group_id)->first(); - if(!$history || !$group){ + if ($config->group_id) {//是否成团 + $history = CollageGroupHistories::where('m_order_id', $config->id)->first(); + $group = CollageGroup::where('id', $config->group_id)->first(); + if (!$history || !$group) { //出错了 } - $param = $this->getGroupParams($config,$group,$history->deadline,0); - if($history->is_initiator == 1){//是团长 发送开团通知 - CollageGroupBatch::create(['history_id'=>$history->id,'batch'=>$history->id]); + $param = $this->getGroupParams($config, $group, $history->deadline, 0); + if ($history->is_initiator == 1) {//是团长 发送开团通知 + CollageGroupBatch::create(['history_id' => $history->id, 'batch' => $history->id]); \WechatService::stratGroupNotice($param); - }else{//是团员 发送参团通知 - $history_i_id = CollageGroupHistories::where('group_id',$config->group_id)->where('is_initiator',1) - ->where('deadline',$history->deadline)->value('id'); - CollageGroupBatch::create(['history_id'=>$history->id,'batch'=>$history_i_id]); + } else {//是团员 发送参团通知 + $history_i_id = CollageGroupHistories::where('group_id', $config->group_id)->where('is_initiator', 1) + ->where('deadline', $history->deadline)->value('id'); + CollageGroupBatch::create(['history_id' => $history->id, 'batch' => $history_i_id]); \WechatService::sendJoinGroupNotice($param); } - $m_order_ids = CollageGroupHistories::where('group_id',$history->group_id) - ->where('deadline',$history->deadline)->pluck('m_order_id')->toArray(); + $m_order_ids = CollageGroupHistories::where('group_id', $history->group_id) + ->where('deadline', $history->deadline)->pluck('m_order_id')->toArray(); // 目前参与人员数量 - $num = TouristOrder::whereIn('id',$m_order_ids)->whereIn('pay_status',[1,4])->get()->count(); - if($group->require_num == $num){ - CollageGroupHistories::whereIn('m_order_id',$m_order_ids)->update(['status'=>1]); + $num = TouristOrder::whereIn('id', $m_order_ids)->whereIn('pay_status', [1, 4])->get()->count(); + if ($group->require_num == $num) { + CollageGroupHistories::whereIn('m_order_id', $m_order_ids)->update(['status' => 1]); //本次拼团成功(给所有拼团人员发) - $notice_users = TouristOrder::whereIn('id',$m_order_ids)->whereIn('pay_status',[1,4])->get(); - foreach ($notice_users as $notice_user) { - $param = $this->getGroupParams($notice_user,$group,$history->deadline,1); + $notice_users = TouristOrder::whereIn('id', $m_order_ids)->whereIn('pay_status', [1, 4])->get(); + foreach ($notice_users as $notice_user) { + $param = $this->getGroupParams($notice_user, $group, $history->deadline, 1); \WechatService::sendJoinGroupNotice($param); } } } $redis = Redis::connection('big_data'); - Log::info('checkEarningOrder earning:order:ids '.$config->id); + Log::info('checkEarningOrder earning:order:ids ' . $config->id); $redis->lpush('earning:order:ids', $config->id); - $way= 'consulation'; + $way = 'consulation'; $type = 'merchant'; //通知用户 - $res = Consultation::where('id',$result->consulation_id)->first(); + $res = Consultation::where('id', $result->consulation_id)->first(); $user_openid = $config->open_id; - $merchant = MerchantAccount::where('id',$result->merchant_id)->first(); + $merchant = MerchantAccount::where('id', $result->merchant_id)->first(); $merchant_openid = $merchant->openid; - if(empty($merchant_openid)) $merchant_openid = Anchor::where('m_id',$merchant->id)->value('openid'); + if (empty($merchant_openid)) + $merchant_openid = Anchor::where('m_id', $merchant->id)->value('openid'); - \CommonUtilsService::sendBuySuccessNoticeToUser($res,$user_openid,$way,$trade_no,$result->price); + \CommonUtilsService::sendBuySuccessNoticeToUser($res, $user_openid, $way, $trade_no, $result->price); //通知商户 - \CommonUtilsService::sendBuySuccessNoticeToBusiness($res,$merchant_openid,$type,$result->price,$result->phone,$result->name); + \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $merchant_openid, $type, $result->price, $result->phone, $result->name); //发送推荐人 - if($result->from_open_id && $result->from_open_id != 'null'){ + if ($result->from_open_id && $result->from_open_id != 'null') { $type = 'recommend'; - \CommonUtilsService::sendBuySuccessNoticeToBusiness($res,$result->from_open_id,$type,$result->price,$result->mobile,$result->name); + \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $result->from_open_id, $type, $result->price, $result->mobile, $result->name); } // 首邀 - $first_invitation = AccessRecord::where('open_id',$result->open_id)->where('account_id',$result->merchant_id)->value('from_openid'); - if($first_invitation&&$first_invitation!=$result->from_openid){ + $first_invitation = AccessRecord::where('open_id', $result->open_id)->where('account_id', $result->merchant_id)->value('from_openid'); + if ($first_invitation && $first_invitation != $result->from_openid) { $way = 'first_invitation'; - \CommonUtilsService::sendBuySuccessNoticeToBusiness($res,$first_invitation,$way,$result->price,$result->mobile,$result->name); + \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $first_invitation, $way, $result->price, $result->mobile, $result->name); } // 发送给渠道 - if($result->share_channel_id&& $result->share_channel_id != 'null'){ + if ($result->share_channel_id && $result->share_channel_id != 'null') { $way = 'channel'; - $share_channel = MerchantShareChannel::where('id',$result->share_channel_id)->first(); + $share_channel = MerchantShareChannel::where('id', $result->share_channel_id)->first(); $bind_m_user_id = $share_channel->bind_m_user_id; - if($bind_m_user_id){ - $merchant_user = MerchantUser::where('id',$bind_m_user_id)->first(); - if($merchant_user->openid){ - \CommonUtilsService::sendBuySuccessNoticeToBusiness($res,$merchant_user->openid,$way,$result->price,$result->mobile,$result->name); + if ($bind_m_user_id) { + $merchant_user = MerchantUser::where('id', $bind_m_user_id)->first(); + if ($merchant_user->openid) { + \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $merchant_user->openid, $way, $result->price, $result->mobile, $result->name); } - if($merchant_user->mobile){ - $share_message = 'Hi,'.$merchant_user->nickname.',刚刚有人通过你的渠道「'.$share_channel->title.'」购买了'.$res->title; - $this->sentMessage($merchant_user->mobile,$share_message); + if ($merchant_user->mobile) { + $share_message = 'Hi,' . $merchant_user->nickname . ',刚刚有人通过你的渠道「' . $share_channel->title . '」购买了' . $res->title; + $this->sentMessage($merchant_user->mobile, $share_message); } } } // app消息推送 - if(isset($merchant->info->android_id)){ + if (isset($merchant->info->android_id)) { // 推送平台 ios android $params['platform'] = 'android'; // 推送标题 $params['title'] = '收到新订单提醒通知'; // 推送内容 - $params['content'] = $res->title.'收到付款'.$result->price.'元'; + $params['content'] = $res->title . '收到付款' . $result->price . '元'; // 通知栏样式 ID $params['builderId'] = 1; // 唤醒APP - $params['intent'] = ['url'=>'intent:#Intent;action=com.love.ufutx.saas.ui.main.MainActivity;component=com.love.ufutx.saas/com.love.ufutx.saas.ui.main.MainActivity;end']; + $params['intent'] = ['url' => 'intent:#Intent;action=com.love.ufutx.saas.ui.main.MainActivity;component=com.love.ufutx.saas/com.love.ufutx.saas.ui.main.MainActivity;end']; $params['uri_activity'] = 'com.love.ufutx.saas.ui.main.MainActivity'; $params['uri_action'] = 'com.love.ufutx.saas.ui.main.MainActivity'; // 附加字段(这里自定义 Key / value 信息,以供业务使用) $params['extras'] = [ - 'url' => 'https://love.ufutx.com/pu_m/#/orderDetail/'.$config->id.'?type='.$config->type.'&equipmentType=android', + 'url' => 'https://love.ufutx.com/pu_m/#/orderDetail/' . $config->id . '?type=' . $config->type . '&equipmentType=android', ]; // 推送类型 1-别名 2-注册id 3-全部 $params['type'] = 2; @@ -1040,13 +1084,13 @@ class OrderController extends Controller } //短信通知商家 - $jump_url = env('APP_URL').'/pu_m/#/earningsRecord?merchant_id='.$merchant->id; - $short_url = \CommonUtilsService::shortUrl(env('APP_URL').'/h5/#/jump_url?url='.$jump_url); + $jump_url = env('APP_URL') . '/pu_m/#/earningsRecord?merchant_id=' . $merchant->id; + $short_url = \CommonUtilsService::shortUrl(env('APP_URL') . '/h5/#/jump_url?url=' . $jump_url); $title = $res->title; - if(mb_strlen($title)>5){ - $title = mb_substr($title,0,5,'utf-8').'...'; + if (mb_strlen($title) > 5) { + $title = mb_substr($title, 0, 5, 'utf-8') . '...'; } - $message = '有用户下单了~ '.$config->name.'购买了平台的《'.$title.'》'.$config->price.'元,点击'.$short_url['url'].' 查看详情'; + $message = '有用户下单了~ ' . $config->name . '购买了平台的《' . $title . '》' . $config->price . '元,点击' . $short_url['url'] . ' 查看详情'; if ($merchant->mobile) { Messenger::sendSMS($merchant->mobile, $message); //增加记录 @@ -1060,25 +1104,29 @@ class OrderController extends Controller } //插入购买通知 // $pay_name = $result->user ? $result->user->nickname : '匿名用户'; - $content = $result->name.'购买了【'.$res->title.'】查看订单详情>>'; - SaasNotice::addRecord($result->merchant_id,$result->account_id,'order',$result->id,$content,0); + $content = $result->name . '购买了【' . $res->title . '】查看订单详情>>'; + SaasNotice::addRecord($result->merchant_id, $result->account_id, 'order', $result->id, $content, 0); //通知老师 // if ($result->merchant_id != 596){ // return; // } $consult_account = ConsultAccount::find($res->consult_account_id); - if ($consult_account && $consult_account->mobile){ + if ($consult_account && $consult_account->mobile) { //公众号 $content = "有用户下单了【{$res->title}】咨询。"; - $teacher = MerchantUser::where('mobile',$consult_account->mobile)->first(); + $teacher = MerchantUser::where('mobile', $consult_account->mobile)->first(); if ($teacher && $teacher->openid) { - \CommonUtilsService::consultCustomNotice($teacher->openid, '', $config->name, - "{$scheduling->date} {$scheduling->date_range}", $content + \CommonUtilsService::consultCustomNotice( + $teacher->openid, + '', + $config->name, + "{$scheduling->date} {$scheduling->date_range}", + $content ); } //短信 $content = "咨询预约通知:有用户下单了【{$res->title}】咨询。"; - if ($scheduling){ + if ($scheduling) { $content .= "预约时间{$scheduling->date} {$scheduling->date_range}"; } Message::create([ @@ -1108,15 +1156,15 @@ class OrderController extends Controller $result = $this->orderCon->changeAsset($user, $score); if (empty($result)) { \DB::rollback(); - throw new \Exception("订单回调失败,福气溢出,订单号:".$order->trade_no, 1); + throw new \Exception("订单回调失败,福气溢出,订单号:" . $order->trade_no, 1); } } //更改会员 $month = SubRank::where('id', $order->type_id)->value('month'); - $result = $user->addSuperRank($day=0, $month, $type='RECSYSTEM'); + $result = $user->addSuperRank($day = 0, $month, $type = 'RECSYSTEM'); if (empty($result)) { \DB::rollback(); - throw new \Exception("订单回调失败,更改会员等级失败,订单号:".$order->trade_no, 1); + throw new \Exception("订单回调失败,更改会员等级失败,订单号:" . $order->trade_no, 1); } \DB::commit(); return true; @@ -1145,7 +1193,7 @@ class OrderController extends Controller $result = $this->orderCon->changeAsset($user, $score); if (empty($result)) { \DB::rollback(); - throw new \Exception("订单回调失败,福气溢出,订单号:".$order->trade_no, 1); + throw new \Exception("订单回调失败,福气溢出,订单号:" . $order->trade_no, 1); } } //生成活动成员 @@ -1181,11 +1229,11 @@ class OrderController extends Controller $param['user_name'] = $user->nickname; $param['user_mobile'] = $user->mobile; $param['start_time'] = $activity->start_time; - $param['address'] = $activity->province.$activity->city.$activity->dist.$activity->address; + $param['address'] = $activity->province . $activity->city . $activity->dist . $activity->address; $param['openid'] = 'oPC_2vudkf3stdiNgjA-e2n6t9_M'; $param['activity_id'] = $activity->id; \WechatService::activitySuccessNotice($param); - return ; + return; } /** @@ -1207,18 +1255,18 @@ class OrderController extends Controller $result = $this->orderCon->changeAsset($user, $score); if (empty($result)) { \DB::rollback(); - throw new \Exception("订单回调失败,福气溢出,订单号:".$order->trade_no, 1); + throw new \Exception("订单回调失败,福气溢出,订单号:" . $order->trade_no, 1); } } $community = Community::find($order->type_id); if (empty($community)) { \DB::rollback(); - throw new \Exception("社区不存在,订单号:".$order->trade_no, 1); + throw new \Exception("社区不存在,订单号:" . $order->trade_no, 1); } //生成社群成员并且邀请进入IM群 $member = $community->members()->firstOrCreate([ - 'user_id'=>$user->id, - 'status'=>1 + 'user_id' => $user->id, + 'status' => 1 ]); //添加会员数 $community->increment('member_num', 1); @@ -1226,7 +1274,7 @@ class OrderController extends Controller $result = $community->addIntoIMGroup([$user->id]); if (empty($result)) { \DB::rollback(); - throw new \Exception("加入IM群失败,订单号:".$order->trade_no, 1); + throw new \Exception("加入IM群失败,订单号:" . $order->trade_no, 1); } \DB::commit(); return true; @@ -1248,14 +1296,14 @@ class OrderController extends Controller //更新订单表信息 $order->pay_status = 'PAID'; //扣除优惠券 - if($order->remark&&$order->price==0){ - UserCoupon::where('id',$order->type_id)->Where('user_id', $user->id)->update(['status'=>1]); + if ($order->remark && $order->price == 0) { + UserCoupon::where('id', $order->type_id)->Where('user_id', $user->id)->update(['status' => 1]); } $order->save(); - $pay_order->pay_status = 'PAID'; + $pay_order->pay_status = 'PAID'; $pay_order->save(); \DB::table('courses')->increment('user_count'); - UserCourses::where('trade_no',$pay_order->trade_no)->update(['status'=>1]); + UserCourses::where('trade_no', $pay_order->trade_no)->update(['status' => 1]); \DB::commit(); return true; } catch (\Exception $e) { @@ -1283,31 +1331,31 @@ class OrderController extends Controller $result = $this->orderCon->changeAsset($user, $score); if (empty($result)) { \DB::rollback(); - throw new \Exception("订单回调失败,福气溢出,订单号:".$order->trade_no, 1); + throw new \Exception("订单回调失败,福气溢出,订单号:" . $order->trade_no, 1); } } //查询服务 $service = SingleService::where('id', $order->type_id)->first(); if (empty($service)) { - throw new \Exception("单身服务不存在,订单号:".$order->trade_no, 1); + throw new \Exception("单身服务不存在,订单号:" . $order->trade_no, 1); } // //生成服务记录 // $this->addServiceHistory($user->id, $service->type, $service->type_id); //添加会员期限 $month = $service->rank_month; - $result = $user->addSuperRank($day=0, $month); + $result = $user->addSuperRank($day = 0, $month); if (empty($result)) { - throw new \Exception("修改用户会员失败,订单号:".$order->trade_no, 1); + throw new \Exception("修改用户会员失败,订单号:" . $order->trade_no, 1); } //短信通知艳斌 if (config('app.env') == 'production') { if ($service->type == 'active' || $service->type == 'passive') { $user_name = $user->nickname; - $message = '用户'.$user_name.'购买了'.$service->title.'服务'; + $message = '用户' . $user_name . '购买了' . $service->title . '服务'; $this->sms->sentMessage('13377553550', $message); //短信通知购买服务用户 - $notice = '您已成功购买【'.$service->title.'】服务套餐,福恋工作人员将尽快联系您为您服务,请耐心等待。如有问题,请联系:18922809346'; - $this->sms->sentMessage($user->mobile,$notice); + $notice = '您已成功购买【' . $service->title . '】服务套餐,福恋工作人员将尽快联系您为您服务,请耐心等待。如有问题,请联系:18922809346'; + $this->sms->sentMessage($user->mobile, $notice); } } \DB::commit(); @@ -1329,11 +1377,11 @@ class OrderController extends Controller return; } AppointmentHistory::create([ - 'user_id'=>$user_id, - 'point_id'=>$appointment->id, - 'price'=>$appointment->price, - 'type'=>$type, - 'num'=>$appointment->num, + 'user_id' => $user_id, + 'point_id' => $appointment->id, + 'price' => $appointment->price, + 'type' => $type, + 'num' => $appointment->num, ]); return; } @@ -1348,15 +1396,17 @@ class OrderController extends Controller { try { $ratio_coin = RatioCoin::find($coin_id); - if (empty($ratio_coin)) throw new \Exception("福币比例不存在", 1); + if (empty($ratio_coin)) + throw new \Exception("福币比例不存在", 1); $os = request()->header('client_os'); if ($os == 'IOS') { - $goods = '充值'.$ratio_coin->ios_coin.'个福币'; - }else{ - $goods = '充值'.$ratio_coin->coin.'个福币'; + $goods = '充值' . $ratio_coin->ios_coin . '个福币'; + } else { + $goods = '充值' . $ratio_coin->coin . '个福币'; } - $result = $this->orderCon->makeAppOrder($request, $ratio_coin->price, $type='coin', $coin_id, $goods, $linkmen=[], $detail=''); - if (empty($result)) throw new \Exception("支付订单生成失败", 1); + $result = $this->orderCon->makeAppOrder($request, $ratio_coin->price, $type = 'coin', $coin_id, $goods, $linkmen = [], $detail = ''); + if (empty($result)) + throw new \Exception("支付订单生成失败", 1); return $this->success('ok', $result); } catch (\Exception $e) { @@ -1381,19 +1431,19 @@ class OrderController extends Controller if (empty($order) || empty($pay_order)) { return $this->failure('订单不存在'); } - if(empty($receipt_data)){ + if (empty($receipt_data)) { return $this->failure('参数错误'); } if (!$order || $order->pay_status != 'UNPAID') { return $this->failure('订单状态异常'); } if ($receipt_data) { - $result = PayOrder::where('id', $pay_order->id)->update(['receipt'=>$receipt_data]); + $result = PayOrder::where('id', $pay_order->id)->update(['receipt' => $receipt_data]); } \DB::beginTransaction(); $ios_sandBox = $request->input('ios_sandBox');//判断生产环境,开发环境 // 获取校验结果 - $result= $this->validate_apple_pay($receipt_data,$ios_sandBox); + $result = $this->validate_apple_pay($receipt_data, $ios_sandBox); if (!$result || !is_array($result) || !isset($result['status'])) { return $this->failure('获取数据失败,请重试'); } @@ -1405,10 +1455,11 @@ class OrderController extends Controller if ($result['status'] == 0) { $transaction_ids = [];//用来收集需要关闭的transaction_id //遍历未结束交易的列表(in_app) - foreach ($result['receipt']['in_app'] as $v){ + foreach ($result['receipt']['in_app'] as $v) { $order_product_id = $this->getOrderProductId($order); $product_id = $v['product_id']; - if ($order_product_id != $product_id) throw new \Exception("产品id不一致", 1); + if ($order_product_id != $product_id) + throw new \Exception("产品id不一致", 1); $transaction_ids[] = $v['transaction_id'];//不管当前交易是否已经处理过,都要返回给客户端结束交易 $is_exist = \DB::table('ios_transaction_ids')->where('transaction_id', $v['transaction_id'])->first(); @@ -1419,18 +1470,19 @@ class OrderController extends Controller //否则在此处理业务逻辑 //回调订单 $result = $this->markOrder($order, $pay_order); - if (empty($result)) throw new \Exception("回调内购订单失败", 1); + if (empty($result)) + throw new \Exception("回调内购订单失败", 1); //然后记录下此transaction_id标记为已处理过 \DB::table('ios_transaction_ids')->insert([ - 'trade_no'=>$trade_no, + 'trade_no' => $trade_no, 'transaction_id' => $v['transaction_id'], - 'created_at'=>date('Y-m-d H:i:s'), - 'updated_at'=>date('Y-m-d H:i:s') + 'created_at' => date('Y-m-d H:i:s'), + 'updated_at' => date('Y-m-d H:i:s') ]); } \DB::commit(); //返回给客户端需要结束交易的transaction_id列表 - return $this->success('ok',$transaction_ids); + return $this->success('ok', $transaction_ids); } \DB::commit(); } catch (\Exception $e) { @@ -1445,10 +1497,10 @@ class OrderController extends Controller $order_product_id = ''; switch ($order->type) { case 'rank': - $order_product_id = 'com.ufutx.love.buyVip'.(int)$order->price.'yuan'; + $order_product_id = 'com.ufutx.love.buyVip' . (int) $order->price . 'yuan'; break; case 'coin': - $order_product_id = 'com.ufutx.love.recharge'.(int)$order->price.'yuan'; + $order_product_id = 'com.ufutx.love.recharge' . (int) $order->price . 'yuan'; break; default: # code... @@ -1462,7 +1514,7 @@ class OrderController extends Controller * @param string $receipt_data 付款后凭证 * @return array 验证是否成功 */ - protected function validate_apple_pay($receipt_data,$ios_sandBox) + protected function validate_apple_pay($receipt_data, $ios_sandBox) { /** * 21000 App Store不能读取你提供的JSON对象 @@ -1475,66 +1527,67 @@ class OrderController extends Controller * 21008 receipt是生产receipt,但却发送至Sandbox环境的验证服务 */ - $POSTFIELDS = ["receipt-data"=>$receipt_data]; + $POSTFIELDS = ["receipt-data" => $receipt_data]; // if(!$ios_sandBox){ // // 请求验证 // $data = \App\Utils\Http::http('https://sandbox.itunes.apple.com/verifyReceipt', $POSTFIELDS, 'POST'); // }else{ - // 请求验证 - $data = \App\Utils\Http::http('https://buy.itunes.apple.com/verifyReceipt', $POSTFIELDS, 'POST'); + // 请求验证 + $data = \App\Utils\Http::http('https://buy.itunes.apple.com/verifyReceipt', $POSTFIELDS, 'POST'); // } - return json_decode($data,true); + return json_decode($data, true); } // 回调 社群-参与活动 - public function VideoOrder(Request $request, $trade_no) + public function VideoOrder(Request $request, $trade_no) { try { - if(empty($trade_no)) { + if (empty($trade_no)) { return $this->failure('没有回调订单号'); } $PayLog = new PayLog; - $result = TouristOrder::where('trade_no',$trade_no)->first(); - if(!$result){ - $PayLog->remark = '订单号不存在:'.$trade_no; + $result = TouristOrder::where('trade_no', $trade_no)->first(); + if (!$result) { + $PayLog->remark = '订单号不存在:' . $trade_no; $PayLog->save(); return $this->failure('没有回调订单号'); } - if($result->pay_status != 0){ + if ($result->pay_status != 0) { $PayLog->trade_no = $trade_no; $PayLog->remark = '订单已经回调'; $PayLog->save(); return $this->success('订单已经回调'); } - \Log::info('para:'.$request->getcontent()); - if(!$result->wechat_transaction_id){ - if($request->getcontent()){ + \Log::info('para:' . $request->getcontent()); + if (!$result->wechat_transaction_id) { + if ($request->getcontent()) { try { $xml = $request->getcontent(); $message = XML::parse($xml); - if($message && $message['transaction_id']) { + if ($message && $message['transaction_id']) { $result->wechat_transaction_id = $message['transaction_id']; $result->save(); } - }catch (\Exception $e){ - \Log::info('回调出错,信息:'.$request->getcontent()); + } catch (\Exception $e) { + \Log::info('回调出错,信息:' . $request->getcontent()); } } } $pay_result = \WechatService::orderPaid($trade_no); - if (empty($pay_result)) return $this->failure("支付回调失败"); + if (empty($pay_result)) + return $this->failure("支付回调失败"); - $merchant = MerchantAccount::where('id',$result->merchant_id)->first(); - $merchant_openid = $merchant->openid??''; + $merchant = MerchantAccount::where('id', $result->merchant_id)->first(); + $merchant_openid = $merchant->openid ?? ''; $usermember = new UserMember(); - $usermember->type = $result->type??''; - $usermember->type_id = $result->type_id??''; - $usermember->m_id = $result->merchant_id??''; - $usermember->m_user_id = $result->account_id??''; - $usermember->pay_type = 'wechat'; - $usermember->trade_no = $trade_no??''; + $usermember->type = $result->type ?? ''; + $usermember->type_id = $result->type_id ?? ''; + $usermember->m_id = $result->merchant_id ?? ''; + $usermember->m_user_id = $result->account_id ?? ''; + $usermember->pay_type = 'wechat'; + $usermember->trade_no = $trade_no ?? ''; $usermember->save(); - if($result->price>0 && $result->type=='video'){//课程回调 + if ($result->price > 0 && $result->type == 'video') {//课程回调 $PayLog->type = 'video'; $PayLog->trade_no = $trade_no; $PayLog->remark = '订单回调成功'; @@ -1542,17 +1595,17 @@ class OrderController extends Controller $result->pay_status = 1; $result->save(); //发送通知 - $res = CourseVideo::where('id',$result->type_id)->first(); + $res = CourseVideo::where('id', $result->type_id)->first(); $class = $result->type; //商户 - $merchant_openid = Course::where('id',$result->type_id)->value('open_id'); + $merchant_openid = Course::where('id', $result->type_id)->value('open_id'); // 发送给渠道 - $channel_openid = null ; - if($result->share_channel_id&& $result->share_channel_id != 'null'){ - $bind_m_user_id = MerchantShareChannel::where('id',$result->share_channel_id) + $channel_openid = null; + if ($result->share_channel_id && $result->share_channel_id != 'null') { + $bind_m_user_id = MerchantShareChannel::where('id', $result->share_channel_id) ->value('bind_m_user_id'); - if($bind_m_user_id){ - $channel_openid = MerchantUser::where('id',$bind_m_user_id)->value('openid'); + if ($bind_m_user_id) { + $channel_openid = MerchantUser::where('id', $bind_m_user_id)->value('openid'); } } @@ -1566,56 +1619,60 @@ class OrderController extends Controller SyncClientComment::dispatch($result)->onQueue('love'); // 给用户 - \CommonUtilsService::sendBuySuccessNoticeToUser($res,$result->open_id,$class,$trade_no,$result->price); + \CommonUtilsService::sendBuySuccessNoticeToUser($res, $result->open_id, $class, $trade_no, $result->price); if ($result->channel == 0) { //发送商户 - \CommonUtilsService::sendBuySuccessNoticeToBusiness($res,$merchant_openid,'merchant',$result->price,$result->mobile,$result->name); + \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $merchant_openid, 'merchant', $result->price, $result->mobile, $result->name); } - if( $result->merchant_id == 491 ){ + if ($result->merchant_id == 491) { //给客服脱单姐 // \CommonUtilsService::sendBuySuccessNoticeToBusiness($res,'oPC_2vudkf3stdiNgjA-e2n6t9_M','merchant',$result->price,$result->mobile,$result->name); $openids = [ - "oPC_2vn6Q3M5jQpw9xAS7NNCMfjs", "oPC_2vudkf3stdiNgjA-e2n6t9_M","oPC_2vtrwOLgWHLwVEFTFsJ7N7fw","oPC_2vt7nGwKk_OFzJL70SlVuTiU","oPC_2vg_Eur-Wa_Vwnx9JiyRVn9Q + "oPC_2vn6Q3M5jQpw9xAS7NNCMfjs", + "oPC_2vudkf3stdiNgjA-e2n6t9_M", + "oPC_2vtrwOLgWHLwVEFTFsJ7N7fw", + "oPC_2vt7nGwKk_OFzJL70SlVuTiU", + "oPC_2vg_Eur-Wa_Vwnx9JiyRVn9Q " ]; foreach ($openids as $openid) { - \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $openid,'merchant',$result->price,$result->mobile,$result->name); + \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $openid, 'merchant', $result->price, $result->mobile, $result->name); } } //发送推荐人 - if($result->from_openid && $result->from_openid != 'null'){ - \CommonUtilsService::sendBuySuccessNoticeToBusiness($res,$result->from_openid,'recommend',$result->price,$result->mobile,$result->name); + if ($result->from_openid && $result->from_openid != 'null') { + \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $result->from_openid, 'recommend', $result->price, $result->mobile, $result->name); } // 首邀 - $first_invitation = AccessRecord::where('open_id',$result->open_id)->where('account_id',$result->merchant_id)->value('from_openid'); - if($first_invitation&&$first_invitation!=$result->from_openid){ - \CommonUtilsService::sendBuySuccessNoticeToBusiness($res,$first_invitation,'first_invitation',$result->price,$result->mobile,$result->name); + $first_invitation = AccessRecord::where('open_id', $result->open_id)->where('account_id', $result->merchant_id)->value('from_openid'); + if ($first_invitation && $first_invitation != $result->from_openid) { + \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $first_invitation, 'first_invitation', $result->price, $result->mobile, $result->name); } // 渠道 - if($result->channel ==0 && $channel_openid){ - \CommonUtilsService::sendBuySuccessNoticeToBusiness($res,$channel_openid,'channel',$result->price,$result->mobile,$result->name); + if ($result->channel == 0 && $channel_openid) { + \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $channel_openid, 'channel', $result->price, $result->mobile, $result->name); } // app消息推送 - if(isset($merchant->info->android_id)){ + if (isset($merchant->info->android_id)) { // 推送平台 ios android $params['platform'] = 'android'; // 推送标题 $params['title'] = '收到新订单提醒通知'; // 推送内容 - $params['content'] = $res->title.'收到付款'.$result->price.'元'; + $params['content'] = $res->title . '收到付款' . $result->price . '元'; // 通知栏样式 ID $params['builderId'] = 1; // 唤醒APP - $params['intent'] = ['url'=>'intent:#Intent;action=com.love.ufutx.saas.ui.main.MainActivity;component=com.love.ufutx.saas/com.love.ufutx.saas.ui.main.MainActivity;end']; + $params['intent'] = ['url' => 'intent:#Intent;action=com.love.ufutx.saas.ui.main.MainActivity;component=com.love.ufutx.saas/com.love.ufutx.saas.ui.main.MainActivity;end']; $params['uri_activity'] = 'com.love.ufutx.saas.ui.main.MainActivity'; $params['uri_action'] = 'com.love.ufutx.saas.ui.main.MainActivity'; // 附加字段(这里自定义 Key / value 信息,以供业务使用) $params['extras'] = [ - 'url' => 'https://love.ufutx.com/pu_m/#/orderDetail/'.$result->id.'?type='.$result->type.'&equipmentType=android', + 'url' => 'https://love.ufutx.com/pu_m/#/orderDetail/' . $result->id . '?type=' . $result->type . '&equipmentType=android', ]; // 推送类型 1-别名 2-注册id 3-全部 $params['type'] = 2; @@ -1627,16 +1684,16 @@ class OrderController extends Controller } $redis = Redis::connection('big_data'); - Log::info('checkEarningOrder earning:order:ids '.$result->id); + Log::info('checkEarningOrder earning:order:ids ' . $result->id); $redis->lpush('earning:order:ids', $result->id); //短信通知商家 - $jump_url = env('APP_URL').'/pu_m/#/earningsRecord?merchant_id='.$merchant->id; - $short_url = \CommonUtilsService::shortUrl(env('APP_URL').'/h5/#/jump_url?url='.$jump_url); + $jump_url = env('APP_URL') . '/pu_m/#/earningsRecord?merchant_id=' . $merchant->id; + $short_url = \CommonUtilsService::shortUrl(env('APP_URL') . '/h5/#/jump_url?url=' . $jump_url); $title = $res->title; - if(mb_strlen($title)>5){ - $title = mb_substr($title,0,5,'utf-8').'...'; + if (mb_strlen($title) > 5) { + $title = mb_substr($title, 0, 5, 'utf-8') . '...'; } - $message = '有用户下单了~ '.$result->name.'购买了平台的《'.$title.'》'.$result->price.'元,点击'.$short_url['url'].' 查看详情'; + $message = '有用户下单了~ ' . $result->name . '购买了平台的《' . $title . '》' . $result->price . '元,点击' . $short_url['url'] . ' 查看详情'; Messenger::sendSMS($merchant->mobile, $message); //增加记录 Message::create([ @@ -1647,22 +1704,22 @@ class OrderController extends Controller 'ip' => request() ? request()->ip() : '127.0.0.1', ]); // 发送短信给渠道分享人 - if($result->share_channel_id&& $result->share_channel_id != 'null'){ - $share_channel = MerchantShareChannel::where('id',$result->share_channel_id)->first(); - if(!empty($share_channel)){ - $merchant_user = MerchantUser::where('id',$share_channel->bind_m_user_id)->first(); - if($merchant_user && $merchant_user->mobile){ - $share_message = 'Hi,'.$merchant_user->nickname.',刚刚有人通过你的渠道「'.$share_channel->title.'」购买了'.$res->title; + if ($result->share_channel_id && $result->share_channel_id != 'null') { + $share_channel = MerchantShareChannel::where('id', $result->share_channel_id)->first(); + if (!empty($share_channel)) { + $merchant_user = MerchantUser::where('id', $share_channel->bind_m_user_id)->first(); + if ($merchant_user && $merchant_user->mobile) { + $share_message = 'Hi,' . $merchant_user->nickname . ',刚刚有人通过你的渠道「' . $share_channel->title . '」购买了' . $res->title; Messenger::sendSMS($merchant_user->mobile, $share_message); } } } //插入购买通知 // $pay_name = $result->user ? $result->user->nickname : '匿名用户'; - $content = $result->name.'购买了【'.$res->title.'】查看订单详情>>'; - SaasNotice::addRecord($result->merchant_id,$result->account_id,'order',$result->id,$content,0); - if($result->user_coupon_id){ - $user_coupon = UserCoupon::where('id',$result->user_coupon_id)->update(['status' => 1]); + $content = $result->name . '购买了【' . $res->title . '】查看订单详情>>'; + SaasNotice::addRecord($result->merchant_id, $result->account_id, 'order', $result->id, $content, 0); + if ($result->user_coupon_id) { + $user_coupon = UserCoupon::where('id', $result->user_coupon_id)->update(['status' => 1]); } return $this->success('ok'); diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 712be57..f86f03a 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -40,6 +40,7 @@ use App\Models\Server\Survey; use App\Models\UnionUser; use App\Server\ReportFile; use App\Services\LiveAlipayService; +use App\Services\OrderService; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Routing\Controller as BaseController; use Illuminate\Foundation\Validation\ValidatesRequests; @@ -2166,17 +2167,10 @@ class Controller extends BaseController public function test(Request $request) { - // $access_token = ""; - // $app = \WechatService::officialApp()->access_token; - // $token = $app->getToken(true); - // $access_token = $token['access_token']; - // if (empty($access_token)) { - // return $this->failure("缺少access_token"); - // } - // $url = "https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token=" . $access_token; - - // $result = Http::get($url); - // dd($result); + $order = TouristOrder::find($request->order_id); + $orderService = new OrderService(); + $res = $orderService->storeUftxCustomer($order); + dd($res); } public function postIndex() diff --git a/app/Http/Controllers/Server/H5/OrderController.php b/app/Http/Controllers/Server/H5/OrderController.php index 3b34c6f..d721da2 100644 --- a/app/Http/Controllers/Server/H5/OrderController.php +++ b/app/Http/Controllers/Server/H5/OrderController.php @@ -19,6 +19,7 @@ use App\Models\Server\WechatSubMerchant; use App\Models\UserCoupon; use App\Models\UserMember; use App\Services\EvaluateService; +use App\Services\OrderService; use Illuminate\Contracts\View\Factory; use Illuminate\Foundation\Application; use Illuminate\Http\JsonResponse; @@ -71,8 +72,10 @@ class OrderController extends Controller $order->address = $recive->address; $order->title = $shop->title; $order->icon = $shop->icon; - if ($order->banners && $order->banners != 'null') $order->banners = json_decode($shop->banners) ?? []; - if ($order->remark && $order->remark != 'null') $order->remark = json_decode($shop->remark) ?? []; + if ($order->banners && $order->banners != 'null') + $order->banners = json_decode($shop->banners) ?? []; + if ($order->remark && $order->remark != 'null') + $order->remark = json_decode($shop->remark) ?? []; $order->describe = $shop->describe; $order->introduction = $shop->sub_title; $order->sku = json_decode($shop->sku, true); @@ -136,9 +139,12 @@ class OrderController extends Controller $pic = $request->pic; $value = Order::where('id', $id)->whereIn('pay_status', [1, 4])->first(); - if ($request->comment) $value->comment = $comment; - if ($request->Praise) $value->Praise = $Praise; - if ($request->pic) $value->comment = json_encode($pic); + if ($request->comment) + $value->comment = $comment; + if ($request->Praise) + $value->Praise = $Praise; + if ($request->pic) + $value->comment = json_encode($pic); $record = ConsultationRecords::where('trade_no', $value->trade_no)->first(); if ($record) { @@ -165,7 +171,8 @@ class OrderController extends Controller try { $id = $request->id; $result = ConsultationRecords::where('id', $id)->where('pay_status', 1)->first(); - if (!$result) return $this->failure('未查到该订单信息~'); + if (!$result) + return $this->failure('未查到该订单信息~'); if ($request->status) $result->status = $request->status; if ($request->record) @@ -212,9 +219,11 @@ class OrderController extends Controller try { $id = $request->id; $order = Order::where('id', $id)->whereIn('pay_status', [1, 4])->first(); - if ($request->trade_no) $order = Order::where('trade_no', $request->trade_no)->whereIn('pay_status', [1, 4]) - ->first(); - if (!$order) return $this->failure('未查询到该订单。'); + if ($request->trade_no) + $order = Order::where('trade_no', $request->trade_no)->whereIn('pay_status', [1, 4]) + ->first(); + if (!$order) + return $this->failure('未查询到该订单。'); $order->pic = json_decode($order->pic, true) ?? []; $order->Praise = floatval($order->Praise); $order->price = floatval($order->price); @@ -245,7 +254,7 @@ class OrderController extends Controller try { //用户id $user_id = $request->merchant_user_id; - $merchant_user = MerchantUser::select('nickname', 'mobile','openid')->where('id', $user_id)->first(); + $merchant_user = MerchantUser::select('nickname', 'mobile', 'openid')->where('id', $user_id)->first(); $wechatUser = session('wechat.oauth_user.new'); if ($wechatUser) { $openid = $wechatUser->getId(); @@ -256,12 +265,16 @@ class OrderController extends Controller $openid = 'odh7zsgI75iT8FRh0fGlSojc9PWM'; } $type = $request->type ?? 'reward_info'; - if (empty($openid)) throw new \Exception('打赏失败,未获取用户微信信息'); + if (empty($openid)) + throw new \Exception('打赏失败,未获取用户微信信息'); $merchant_id = $request->input('merchant_id'); - if (empty($merchant_id)) throw new \Exception("打赏失败,获取到商家id"); + if (empty($merchant_id)) + throw new \Exception("打赏失败,获取到商家id"); $amount = $request->input('amount'); - if (empty($amount)) return $this->failure("请输入打赏金额"); - if (!is_numeric($amount) || (is_numeric($amount) && $amount < 0)) throw new \Exception('输入打赏金额格式错误'); + if (empty($amount)) + return $this->failure("请输入打赏金额"); + if (!is_numeric($amount) || (is_numeric($amount) && $amount < 0)) + throw new \Exception('输入打赏金额格式错误'); $trade_no = \CommonUtilsService::getTradeNO(); $order = array( 'open_id' => $openid, @@ -320,9 +333,11 @@ class OrderController extends Controller } $goods = '默认规格'; $result = MerchantShop::where('id', $request->id)->where('is_show', 1)->first(); - if (!$result) return $this->failure('你购买的商品不存在或已下架。'); + if (!$result) + return $this->failure('你购买的商品不存在或已下架。'); $sku_id = $request->sku_id; - if (!$sku_id && $result->pay_type == 'wechat') return $this->failure('规格参数不存在,请稍后再试。'); + if (!$sku_id && $result->pay_type == 'wechat') + return $this->failure('规格参数不存在,请稍后再试。'); if ($sku_id) { $skus = json_decode($result->sku, true); $skus = array_column($skus, null, 'sku_id'); @@ -333,38 +348,44 @@ class OrderController extends Controller } else { $price = $result->price; $desc = $result->title; - $goods = $result->describe;; + $goods = $result->describe; + ; } $group_id = null; - if($buy_type && $buy_type == 'group'){ + if ($buy_type && $buy_type == 'group') { $time = date('Y-m-d H:i:s'); - $group = CollageGroup::where('type','shop')->where('type_id',$request->id)->first(); - if(!$group) return $this->failure('拼团信息不存在'); + $group = CollageGroup::where('type', 'shop')->where('type_id', $request->id)->first(); + if (!$group) + return $this->failure('拼团信息不存在'); $group_sku = json_decode($group->sku, true) ?? null; - if($group_sku && sizeof($group_sku)>0){ + if ($group_sku && sizeof($group_sku) > 0) { $group_skus = array_column($group_sku, null, 'sku_id'); $sku = $group_skus[$sku_id]; $price = $sku['discount_price']; - }else{ + } else { $price = $group->price; } $group_id = $group->id; - $history = CollageGroupHistories::where('id',$history_id)->first(); - if($history){ - if($history->deadline < $time) return $this->failure('你慢了一步,拼团已过有效期'); - if($history->status == 1) return $this->failure('你慢了一步,该团已被他人完成'); - $m_order_ids = CollageGroupHistories::where('group_id',$history->group_id) - ->where('m_user_id',$merchant_user_id)->where('status',0)->where('deadline','>',$time) + $history = CollageGroupHistories::where('id', $history_id)->first(); + if ($history) { + if ($history->deadline < $time) + return $this->failure('你慢了一步,拼团已过有效期'); + if ($history->status == 1) + return $this->failure('你慢了一步,该团已被他人完成'); + $m_order_ids = CollageGroupHistories::where('group_id', $history->group_id) + ->where('m_user_id', $merchant_user_id)->where('status', 0)->where('deadline', '>', $time) ->pluck('m_order_id')->toArray(); - $exists = TouristOrder::whereIn('id',$m_order_ids)->whereIn('pay_status',[1,4])->first(); - if($exists) return $this->failure('该活动你有尚未完成的拼团,请耐心等待'); - $exists = CollageGroupHistories::with('tOrder')->whereHas('tOrder',function($sql){ - $sql->whereIn('pay_status',[1,4]); + $exists = TouristOrder::whereIn('id', $m_order_ids)->whereIn('pay_status', [1, 4])->first(); + if ($exists) + return $this->failure('该活动你有尚未完成的拼团,请耐心等待'); + $exists = CollageGroupHistories::with('tOrder')->whereHas('tOrder', function ($sql) { + $sql->whereIn('pay_status', [1, 4]); }) - ->where('group_id',$group->id)->where('m_user_id',$merchant_user_id) - ->where('status',1) + ->where('group_id', $group->id)->where('m_user_id', $merchant_user_id) + ->where('status', 1) ->first(); - if($exists) return $this->failure('你已成功拼团参与过该活动,无需重复参与'); + if ($exists) + return $this->failure('你已成功拼团参与过该活动,无需重复参与'); } } @@ -372,11 +393,11 @@ class OrderController extends Controller // if($pay_price!=$request->price) return $this->failure('支付价格与商品价格不一致。'); $anchor = Anchor::where('id', $result->anchor_id)->first(); $trade_no = $this->getTradeNo(); - list($pay_type, $sub_mch_id)= MerchantAccount::payType($request->merchant_id); + list($pay_type, $sub_mch_id) = MerchantAccount::payType($request->merchant_id); $TouristOrder = new Order(); $TouristOrder->open_id = $openid; $TouristOrder->price = floatval($pay_price); - $TouristOrder->pay_type = $pay_type=='partner'?:$result->pay_type; + $TouristOrder->pay_type = $pay_type == 'partner' ?: $result->pay_type; $TouristOrder->type = 'shop'; $TouristOrder->num = $request->num; $TouristOrder->type_id = $request->id; @@ -411,33 +432,60 @@ class OrderController extends Controller $way = 'merchant'; $res = MerchantShop::where('id', $TouristOrder->type_id)->first(); //给用户 - \CommonUtilsService::sendBuySuccessNoticeToUser($res, $TouristOrder->open_id, $TouristOrder->type, - $TouristOrder->trade_no, $TouristOrder->price); + \CommonUtilsService::sendBuySuccessNoticeToUser( + $res, + $TouristOrder->open_id, + $TouristOrder->type, + $TouristOrder->trade_no, + $TouristOrder->price + ); //给商户 $merchant = MerchantAccount::where('id', $TouristOrder->merchant_id)->first(); $merchant_openid = $merchant->openid ?? ''; if (!$merchant_openid) { $merchant_openid = Anchor::where('m_id', $res->merchant_id)->value('openid'); } - \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $merchant_openid, $way, $TouristOrder->price, - $TouristOrder->mobile, $TouristOrder->name); - if( $TouristOrder->merchant_id == 491 ){ + \CommonUtilsService::sendBuySuccessNoticeToBusiness( + $res, + $merchant_openid, + $way, + $TouristOrder->price, + $TouristOrder->mobile, + $TouristOrder->name + ); + if ($TouristOrder->merchant_id == 491) { //给客服脱单姐 管理员 $openids = [ - "oPC_2vn6Q3M5jQpw9xAS7NNCMfjs", "oPC_2vudkf3stdiNgjA-e2n6t9_M","oPC_2vtrwOLgWHLwVEFTFsJ7N7fw","oPC_2vt7nGwKk_OFzJL70SlVuTiU","oPC_2vg_Eur-Wa_Vwnx9JiyRVn9Q + "oPC_2vn6Q3M5jQpw9xAS7NNCMfjs", + "oPC_2vudkf3stdiNgjA-e2n6t9_M", + "oPC_2vtrwOLgWHLwVEFTFsJ7N7fw", + "oPC_2vt7nGwKk_OFzJL70SlVuTiU", + "oPC_2vg_Eur-Wa_Vwnx9JiyRVn9Q " ]; foreach ($openids as $openid) { - \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $openid,'merchant',$TouristOrder->price, - $TouristOrder->mobile, $TouristOrder->namee); + \CommonUtilsService::sendBuySuccessNoticeToBusiness( + $res, + $openid, + 'merchant', + $TouristOrder->price, + $TouristOrder->mobile, + $TouristOrder->namee + ); } - + } //发送推荐人 if ($TouristOrder->from_openid && $TouristOrder->from_openid != 'null') { $way = 'recommend'; - \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $TouristOrder->from_openid, $way, - $TouristOrder->price, $TouristOrder->mobile, $TouristOrder->name); + \CommonUtilsService::sendBuySuccessNoticeToBusiness( + $res, + $TouristOrder->from_openid, + $way, + $TouristOrder->price, + $TouristOrder->mobile, + $TouristOrder->name + ); } //短信通知商家 $jump_url = env('APP_URL') . '/pu_m/#/earningsRecord?merchant_id=' . $merchant->id; @@ -459,15 +507,21 @@ class OrderController extends Controller ]); //插入购买通知 $content = $TouristOrder->name . '购买了【' . $res->title . '】查看订单详情>>'; - SaasNotice::addRecord($TouristOrder->merchant_id, $TouristOrder->account_id, 'order', - $TouristOrder->id, $content, 0); + SaasNotice::addRecord( + $TouristOrder->merchant_id, + $TouristOrder->account_id, + 'order', + $TouristOrder->id, + $content, + 0 + ); return $this->success('ok', $TouristOrder); } $TouristOrder->save(); $ShopRecive->order_id = $TouristOrder->id; $ShopRecive->save(); - if($buy_type == 'group'){ - if($request->history_id){ + if ($buy_type == 'group') { + if ($request->history_id) { $history = CollageGroupHistories::find($request->history_id); $deadline = $history->deadline; $is_initiator = 0; @@ -478,11 +532,11 @@ class OrderController extends Controller $CollageGroupHistories->group_master_id = $request->history_id; $CollageGroupHistories->is_initiator = $is_initiator; $CollageGroupHistories->status = 0; - $CollageGroupHistories->deadline =$deadline; + $CollageGroupHistories->deadline = $deadline; $CollageGroupHistories->save(); - }else{ + } else { //分享不带history_id 就是团长 - $deadline = date('Y-m-d H:i:s',strtotime('+'.$group->expire_in.'hours')); + $deadline = date('Y-m-d H:i:s', strtotime('+' . $group->expire_in . 'hours')); $is_initiator = 1; $CollageGroupHistories = new CollageGroupHistories(); $CollageGroupHistories->m_user_id = $TouristOrder->account_id; @@ -490,7 +544,7 @@ class OrderController extends Controller $CollageGroupHistories->m_order_id = $TouristOrder->id; $CollageGroupHistories->is_initiator = $is_initiator; $CollageGroupHistories->status = 0; - $CollageGroupHistories->deadline =$deadline; + $CollageGroupHistories->deadline = $deadline; $CollageGroupHistories->save(); $CollageGroupHistories->group_master_id = $CollageGroupHistories->id; $CollageGroupHistories->save(); @@ -507,9 +561,9 @@ class OrderController extends Controller 'openid' => $openid, 'order_id' => $TouristOrder->id, ); - if($pay_type == 'partner'){ - $result = WechatService::partnerPay($TouristOrder->id, $sub_mch_id, $price * $request->num , $openid, $trade_no, $callback, $desc); - }else{ + if ($pay_type == 'partner') { + $result = WechatService::partnerPay($TouristOrder->id, $sub_mch_id, $price * $request->num, $openid, $trade_no, $callback, $desc); + } else { $result = WechatService::officialPay($attributes); } //$result = \WechatService::officialPay($attributes); @@ -542,29 +596,32 @@ class OrderController extends Controller } else { $openid = $MerchantUser->openid; } - if($user_coupon_id && $buy_type == 'group'){ + if ($user_coupon_id && $buy_type == 'group') { return $this->failure('优惠券与团购不能同时使用'); } $result = CommunityActivity::where('id', $request->id)->first(); - if (!$result) return $this->failure('你参与的活动不存在或已下架。'); -// if (empty($result->status)) return $this->failure("该活动已下架"); + if (!$result) + return $this->failure('你参与的活动不存在或已下架。'); + // if (empty($result->status)) return $this->failure("该活动已下架"); //活动不能重复参与 - if($result->class == 'one' && $result->merchant_id != 44){ - $is_join = TouristOrder::where('type','community')->where('type_id',$request->id) - ->whereIn('pay_status',[1,4])->where('account_id',$merchant_user_id) + if ($result->class == 'one' && $result->merchant_id != 44) { + $is_join = TouristOrder::where('type', 'community')->where('type_id', $request->id) + ->whereIn('pay_status', [1, 4])->where('account_id', $merchant_user_id) ->first(); - if($is_join) return $this->failure('已参与,请勿重复报名'); + if ($is_join) + return $this->failure('已参与,请勿重复报名'); } if ($result->class == 'one' && $result->apply_deadline) { if ($result->apply_deadline <= $time) { - if(!$sign_buy){ + if (!$sign_buy) { return $this->failure('该活动已截止报名,看看其他活动吧'); } } } $sku_id = $request->sku_id; - if (!$sku_id && $result->pay_type == 'wechat') return $this->failure('规格参数不存在,请稍后再试。'); - if($user_coupon_id) { + if (!$sku_id && $result->pay_type == 'wechat') + return $this->failure('规格参数不存在,请稍后再试。'); + if ($user_coupon_id) { //$result_array = $result->toArray(); $user_coupon = UserCoupon::where('id', $user_coupon_id)->where('status', 0) ->where('m_id', $request->merchant_id)->where('m_user_id', $merchant_user_id) @@ -586,48 +643,48 @@ class OrderController extends Controller $sku = $skus[$sku_id]; $total_limit_num = $sku['total_limit_num'] ?? 0; - $sku_buy_num = (new Order)->getSkuBuyNum($request->id,$request->merchant_id,$sku_id); - if($total_limit_num && $total_limit_num < ($sku_buy_num + count($request->linkmen))){ + $sku_buy_num = (new Order)->getSkuBuyNum($request->id, $request->merchant_id, $sku_id); + if ($total_limit_num && $total_limit_num < ($sku_buy_num + count($request->linkmen))) { return $this->failure('报名人数已超限制'); } $member_num = count($request->linkmen); - $member_num = $request->num?:$member_num; - if($user_coupon_id) { + $member_num = $request->num ?: $member_num; + if ($user_coupon_id) { switch ($coupon->coupon_type) { case 1: $price = 0.00; break; case 2: if (isset($sku['num']) && $sku['num'] == 0) {//不限人数, 通过报名信息判断数量 - $price = number_format($sku['price'] * $member_num * $coupon->discount_rate, 2, '.',''); + $price = number_format($sku['price'] * $member_num * $coupon->discount_rate, 2, '.', ''); } else { - $price = number_format($sku['price'] * $coupon->discount_rate, 2, '.',''); + $price = number_format($sku['price'] * $coupon->discount_rate, 2, '.', ''); } break; case 3: if (isset($sku['num']) && $sku['num'] == 0) { - $price = number_format($sku['price'] * $member_num - $coupon->discount_rate, 2,'.',''); - }else { - $price = number_format($sku['price'] - $coupon->discount_rate, 2,'.',''); + $price = number_format($sku['price'] * $member_num - $coupon->discount_rate, 2, '.', ''); + } else { + $price = number_format($sku['price'] - $coupon->discount_rate, 2, '.', ''); } -// if ($price <= 0 && $sku['price'] != 0) return $this->failure("优惠券不适合此规格"); + // if ($price <= 0 && $sku['price'] != 0) return $this->failure("优惠券不适合此规格"); break; default: $price = $sku['price']; break; } - }else{ + } else { if (isset($sku['num']) && $sku['num'] == 0) {//不限人数, 通过报名信息判断数量 - $price = number_format($sku['price'] * $member_num, 2, '.',''); - }else { + $price = number_format($sku['price'] * $member_num, 2, '.', ''); + } else { $price = $sku['price']; } } $desc = $result['title'] . '-' . $sku['name'] . ''; $goods = $sku['name'] . ''; - }else{ - if($user_coupon_id) { + } else { + if ($user_coupon_id) { $user_coupon = UserCoupon::where('id', $user_coupon_id)->with('coupon') ->first(); if ($user_coupon && $user_coupon->coupon) { @@ -651,70 +708,75 @@ class OrderController extends Controller break; } } - }else{ + } else { $price = $result['price']; } $goods = null; $desc = $result['title']; } $group_id = null; - if($buy_type && $buy_type == 'group'){ + if ($buy_type && $buy_type == 'group') { $time = date('Y-m-d H:i:s'); - $group = CollageGroup::where('type','community')->where('type_id',$request->id)->first(); - if(!$group) return $this->failure('拼团信息不存在'); + $group = CollageGroup::where('type', 'community')->where('type_id', $request->id)->first(); + if (!$group) + return $this->failure('拼团信息不存在'); $sku = json_decode($group->sku, true) ?? null; - if(sizeof($sku)>0){ - foreach($sku as $key =>$value ){ - foreach ($value as $vk => $vv){ - if($vk == 'sku_id' && $vv == $sku_id){ + if (sizeof($sku) > 0) { + foreach ($sku as $key => $value) { + foreach ($value as $vk => $vv) { + if ($vk == 'sku_id' && $vv == $sku_id) { $price = $value['discount_price']; break; } } } - }else{ + } else { $price = $group->price; } $group_id = $group->id; $history_id = $request->history_id; - $history = CollageGroupHistories::where('id',$history_id)->first(); - if($history){ - if($history->deadline < $time) return $this->failure('你慢了一步,拼团已过有效期'); - if($history->status == 1) return $this->failure('你慢了一步,该团已被他人完成'); - $m_order_ids = CollageGroupHistories::where('group_id',$history->group_id) - ->where('m_user_id',$merchant_user_id)->where('status',0)->where('deadline','>',$time) + $history = CollageGroupHistories::where('id', $history_id)->first(); + if ($history) { + if ($history->deadline < $time) + return $this->failure('你慢了一步,拼团已过有效期'); + if ($history->status == 1) + return $this->failure('你慢了一步,该团已被他人完成'); + $m_order_ids = CollageGroupHistories::where('group_id', $history->group_id) + ->where('m_user_id', $merchant_user_id)->where('status', 0)->where('deadline', '>', $time) ->pluck('m_order_id')->toArray(); - $exists = TouristOrder::whereIn('id',$m_order_ids)->whereIn('pay_status',[1,4])->first(); - if($exists) return $this->failure('该活动你有尚未完成的拼团,请耐心等待'); - $exists = CollageGroupHistories::with('tOrder')->whereHas('tOrder',function($sql){ - $sql->whereIn('pay_status',[1,4]); + $exists = TouristOrder::whereIn('id', $m_order_ids)->whereIn('pay_status', [1, 4])->first(); + if ($exists) + return $this->failure('该活动你有尚未完成的拼团,请耐心等待'); + $exists = CollageGroupHistories::with('tOrder')->whereHas('tOrder', function ($sql) { + $sql->whereIn('pay_status', [1, 4]); }) - ->where('group_id',$group->id)->where('m_user_id',$merchant_user_id) - ->where('status',1) + ->where('group_id', $group->id)->where('m_user_id', $merchant_user_id) + ->where('status', 1) ->first(); - if($exists) return $this->failure('你已成功拼团参与过该活动,无需重复参与'); + if ($exists) + return $this->failure('你已成功拼团参与过该活动,无需重复参与'); } } $anchor = Anchor::where('id', $result->anchor_id)->first(); - if ($request->merchant_id == 44 || $request->merchant_id == 69) { - $trade_no = "saas_".$this->getTradeNO(); - }else { + if ($request->merchant_id == 44 || $request->merchant_id == 69) { + $trade_no = "saas_" . $this->getTradeNO(); + } else { $trade_no = $this->getTradeNo(); } - list($pay_type, $sub_mch_id)= MerchantAccount::payType($request->merchant_id); + list($pay_type, $sub_mch_id) = MerchantAccount::payType($request->merchant_id); $TouristOrder = new Order(); $TouristOrder->open_id = $openid; $TouristOrder->price = floatval($price); - $TouristOrder->pay_type = $pay_type=="partner"?$pay_type:$result->pay_type; + $TouristOrder->pay_type = $pay_type == "partner" ? $pay_type : $result->pay_type; $TouristOrder->type = 'community'; $TouristOrder->type_id = $request->id; $TouristOrder->trade_no = $trade_no; $TouristOrder->desc = $desc; $TouristOrder->goods = $goods; - if($user_coupon_id){ + if ($user_coupon_id) { $TouristOrder->user_coupon_id = $user_coupon_id; } - if($buy_type && $buy_type == 'group'){ + if ($buy_type && $buy_type == 'group') { $TouristOrder->group_id = $group_id; } $TouristOrder->from_openid = $request->from_openid; @@ -731,14 +793,16 @@ class OrderController extends Controller $TouristOrder->insurance_info = json_encode($request->insurance_info); if (is_array($request->linkmen) && count($request->linkmen)) { $linkmen = $request->linkmen; - foreach ($linkmen as &$linkman) - { - if (!$linkman['mobile']) $linkman['mobile'] = "18888888888"; - if (!$linkman['name']) $linkman['name'] = "嘉宾"; - if (isset($linkman['sex']) && empty($linkman['sex'])) $linkman['sex'] = "男"; + foreach ($linkmen as &$linkman) { + if (!$linkman['mobile']) + $linkman['mobile'] = "18888888888"; + if (!$linkman['name']) + $linkman['name'] = "嘉宾"; + if (isset($linkman['sex']) && empty($linkman['sex'])) + $linkman['sex'] = "男"; } $TouristOrder->linkmen = json_encode($linkmen); - }else { + } else { return $this->failure("请填写报名人信息"); } @@ -759,47 +823,70 @@ class OrderController extends Controller //发送通知 //判断是服务还是活动 $res = CommunityActivity::where('id', $TouristOrder->type_id)->first(); - if ($res->class == 'one') $class = 'activity'; - if ($res->class == 'many') $class = 'service'; - \CommonUtilsService::sendBuySuccessNoticeToUser($res, $TouristOrder->open_id, $class, $trade_no, - $TouristOrder->price); + if ($res->class == 'one') + $class = 'activity'; + if ($res->class == 'many') + $class = 'service'; + \CommonUtilsService::sendBuySuccessNoticeToUser( + $res, + $TouristOrder->open_id, + $class, + $trade_no, + $TouristOrder->price + ); //发送商户 $merchant_openid = $merchant->openid ?? ''; if (!$merchant_openid) { $merchant_openid = Anchor::where('id', $res->anchor_id)->value('openid'); } - \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $merchant_openid, $way, $TouristOrder->price, - $TouristOrder->mobile, $TouristOrder->name); + \CommonUtilsService::sendBuySuccessNoticeToBusiness( + $res, + $merchant_openid, + $way, + $TouristOrder->price, + $TouristOrder->mobile, + $TouristOrder->name + ); //发送推荐人 if ($TouristOrder->from_openid && $TouristOrder->from_openid != 'null') { $way = 'recommend'; - \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $TouristOrder->from_openid, $way, - $TouristOrder->price, $TouristOrder->mobile, $TouristOrder->name); + \CommonUtilsService::sendBuySuccessNoticeToBusiness( + $res, + $TouristOrder->from_openid, + $way, + $TouristOrder->price, + $TouristOrder->mobile, + $TouristOrder->name + ); } - if( $TouristOrder->merchant_id == 491 ){ + if ($TouristOrder->merchant_id == 491) { //给客服脱单姐 管理员 $openids = [ - "oPC_2vn6Q3M5jQpw9xAS7NNCMfjs", "oPC_2vudkf3stdiNgjA-e2n6t9_M","oPC_2vtrwOLgWHLwVEFTFsJ7N7fw","oPC_2vt7nGwKk_OFzJL70SlVuTiU","oPC_2vg_Eur-Wa_Vwnx9JiyRVn9Q + "oPC_2vn6Q3M5jQpw9xAS7NNCMfjs", + "oPC_2vudkf3stdiNgjA-e2n6t9_M", + "oPC_2vtrwOLgWHLwVEFTFsJ7N7fw", + "oPC_2vt7nGwKk_OFzJL70SlVuTiU", + "oPC_2vg_Eur-Wa_Vwnx9JiyRVn9Q " ]; foreach ($openids as $openid) { - \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $openid,'merchant',$TouristOrder->price, $TouristOrder->mobile, $TouristOrder->name); + \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $openid, 'merchant', $TouristOrder->price, $TouristOrder->mobile, $TouristOrder->name); } - + } $users = new UserMember(); $users->type = 'community'; $users->type_id = $result->id; $users->m_id = $request->merchant_id ?? 0; $users->m_user_id = $merchant_user_id; - if($user_coupon_id) { + if ($user_coupon_id) { $users->coupons_id = $user_coupon_id; $users->pay_type = 'coupon'; - }else{ + } else { $users->pay_type = 'wechat'; } $users->save(); - if($user_coupon_id) { + if ($user_coupon_id) { $user_coupon->status = 1; $user_coupon->save(); } @@ -810,13 +897,23 @@ class OrderController extends Controller //添加购买通知记录 $content = $result->name . '购买了【' . $res->title . '】查看订单详情>>'; - SaasNotice::addRecord($TouristOrder->merchant_id, $TouristOrder->account_id, 'order', - $TouristOrder->id, $content, 0); + SaasNotice::addRecord( + $TouristOrder->merchant_id, + $TouristOrder->account_id, + 'order', + $TouristOrder->id, + $content, + 0 + ); + + // 友福活动将被邀请人添加到客户 + $orderService = new OrderService(); + $orderService->storeUftxCustomer($TouristOrder); return $this->success('ok', $TouristOrder); - }else { + } else { $TouristOrder->save(); - if($buy_type == 'group'){ - if($request->history_id){ + if ($buy_type == 'group') { + if ($request->history_id) { $history = CollageGroupHistories::find($request->history_id); $deadline = $history->deadline; $is_initiator = 0; @@ -827,11 +924,11 @@ class OrderController extends Controller $CollageGroupHistories->group_master_id = $request->history_id; $CollageGroupHistories->is_initiator = $is_initiator; $CollageGroupHistories->status = 0; - $CollageGroupHistories->deadline =$deadline; + $CollageGroupHistories->deadline = $deadline; $CollageGroupHistories->save(); - }else{ + } else { //分享不带history_id 就是团长 - $deadline = date('Y-m-d H:i:s',strtotime('+'.$group->expire_in.'hours')); + $deadline = date('Y-m-d H:i:s', strtotime('+' . $group->expire_in . 'hours')); $is_initiator = 1; $CollageGroupHistories = new CollageGroupHistories(); $CollageGroupHistories->m_user_id = $TouristOrder->account_id; @@ -839,7 +936,7 @@ class OrderController extends Controller $CollageGroupHistories->m_order_id = $TouristOrder->id; $CollageGroupHistories->is_initiator = $is_initiator; $CollageGroupHistories->status = 0; - $CollageGroupHistories->deadline =$deadline; + $CollageGroupHistories->deadline = $deadline; $CollageGroupHistories->save(); $CollageGroupHistories->group_master_id = $CollageGroupHistories->id; $CollageGroupHistories->save(); @@ -856,9 +953,9 @@ class OrderController extends Controller 'openid' => $openid, 'order_id' => $TouristOrder->id, ); - if($pay_type == 'partner'){ - $res = WechatService::partnerPay($TouristOrder->id, $sub_mch_id, $price, $attributes['openid'], $attributes['out_trade_no'], $attributes['notify_url'], $attributes['body']); - }else { + if ($pay_type == 'partner') { + $res = WechatService::partnerPay($TouristOrder->id, $sub_mch_id, $price, $attributes['openid'], $attributes['out_trade_no'], $attributes['notify_url'], $attributes['body']); + } else { $res = WechatService::officialPay($attributes); } return $this->success('ok', $res); @@ -874,23 +971,26 @@ class OrderController extends Controller $sign_buy = $request->sign_buy; $result = CommunityActivity::where('id', $id)->where('status', 1)->first(); - if (!$result) return ['code'=>1, 'msg'=>'你参与的活动不存在或已下架。']; + if (!$result) + return ['code' => 1, 'msg' => '你参与的活动不存在或已下架。']; //活动不能重复参与 - if($result->class == 'one' && $result->merchant_id != 44){ - $is_join = TouristOrder::where('type','community')->where('type_id',$id) - ->whereIn('pay_status',[1,4])->where('account_id',$user_id) + if ($result->class == 'one' && $result->merchant_id != 44) { + $is_join = TouristOrder::where('type', 'community')->where('type_id', $id) + ->whereIn('pay_status', [1, 4])->where('account_id', $user_id) ->first(); - if($is_join) return ['code'=>1, 'msg'=>'已参与,请勿重复报名']; + if ($is_join) + return ['code' => 1, 'msg' => '已参与,请勿重复报名']; } if ($result->class == 'one' && $result->apply_deadline) { if ($result->apply_deadline <= date('Y-m-d H:i:s')) { - if(!$sign_buy){ - return ['code'=>1,'该活动已截止报名,看看其他活动吧']; + if (!$sign_buy) { + return ['code' => 1, '该活动已截止报名,看看其他活动吧']; } } } $sku_id = $request->sku_id; - if (!$sku_id && $result->pay_type == 'wechat') return ['code'=>1,'规格参数不存在,请稍后再试。']; + if (!$sku_id && $result->pay_type == 'wechat') + return ['code' => 1, '规格参数不存在,请稍后再试。']; if ($sku_id) { $skus = json_decode($result->sku, true); $skus = array_column($skus, null, 'sku_id'); @@ -898,7 +998,7 @@ class OrderController extends Controller $price = $sku['price']; $desc = $result->title . '-' . $sku['name'] . ''; $goods = $sku['name'] . ''; - }else{ + } else { $price = $result->price; $goods = null; $desc = $result->title; @@ -944,38 +1044,64 @@ class OrderController extends Controller //发送通知 //判断是服务还是活动 $res = CommunityActivity::where('id', $order->type_id)->first(); - if ($res->class == 'one') $class = 'activity'; - if ($res->class == 'many') $class = 'service'; - \CommonUtilsService::sendBuySuccessNoticeToUser($res, $order->open_id, $class, $trade_no, - $order->price); + if ($res->class == 'one') + $class = 'activity'; + if ($res->class == 'many') + $class = 'service'; + \CommonUtilsService::sendBuySuccessNoticeToUser( + $res, + $order->open_id, + $class, + $trade_no, + $order->price + ); //发送商户 $merchant_openid = $merchant->openid ?? ''; if (!$merchant_openid) { $merchant_openid = Anchor::where('id', $res->anchor_id)->value('openid'); } - \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $merchant_openid, $way, $order->price, - $order->mobile, $order->name); + \CommonUtilsService::sendBuySuccessNoticeToBusiness( + $res, + $merchant_openid, + $way, + $order->price, + $order->mobile, + $order->name + ); //发送推荐人 if ($order->from_openid && $order->from_openid != 'null') { $way = 'recommend'; - \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $order->from_openid, $way, - $order->price, $order->mobile, $order->name); + \CommonUtilsService::sendBuySuccessNoticeToBusiness( + $res, + $order->from_openid, + $way, + $order->price, + $order->mobile, + $order->name + ); } //添加购买通知记录 $content = $result->name . '购买了【' . $res->title . '】查看订单详情>>'; - SaasNotice::addRecord($order->merchant_id, $order->account_id, 'order', - $order->id, $content, 0); - return ['code'=>0, 'data'=>$order]; + SaasNotice::addRecord( + $order->merchant_id, + $order->account_id, + 'order', + $order->id, + $content, + 0 + ); + return ['code' => 0, 'data' => $order]; } $order->save(); - $order->need_pay = $price?1:0; - return ['code'=>0, 'data'=>$order]; + $order->need_pay = $price ? 1 : 0; + return ['code' => 0, 'data' => $order]; } public function payCourseOrder($request, $course_id, $user_id, $openid) { $course = Course::where('id', $course_id)->first(); - if (empty($course)) return ['code'=>1, 'msg'=>"该课程已下线"]; + if (empty($course)) + return ['code' => 1, 'msg' => "该课程已下线"]; $trade_no = $this->getTradeNo(); $merchant_user = MerchantUser::where('id', $user_id)->first(); $order = new TouristOrder(); @@ -1001,7 +1127,7 @@ class OrderController extends Controller } else { $mobile = $merchant_user->mobile; } -// if($user_coupon_id){ + // if($user_coupon_id){ // $order->user_coupon_id = $user_coupon_id; // } $order->mobile = $mobile ?: '匿名用户'; @@ -1020,25 +1146,43 @@ class OrderController extends Controller $order->save(); $user_course->status = 1; $user_course->save(); - if(!empty($user_coupon)){ + if (!empty($user_coupon)) { $user_coupon->status = 1; $user_coupon->save(); } //发送通知 //给用户 - \CommonUtilsService::sendBuySuccessNoticeToUser($course, $order->open_id, $order->type, - $trade_no, $order->price); + \CommonUtilsService::sendBuySuccessNoticeToUser( + $course, + $order->open_id, + $order->type, + $trade_no, + $order->price + ); //给商户 $merchant_openid = $course->open_id; - if (empty($merchant_id)) $merchant_openid = Anchor::where('m_id', $order->merchant_id) - ->value('openid'); - \CommonUtilsService::sendBuySuccessNoticeToBusiness($course, $merchant_openid, $way, - $order->price, $order->mobile, $order->name); + if (empty($merchant_id)) + $merchant_openid = Anchor::where('m_id', $order->merchant_id) + ->value('openid'); + \CommonUtilsService::sendBuySuccessNoticeToBusiness( + $course, + $merchant_openid, + $way, + $order->price, + $order->mobile, + $order->name + ); //发送推荐人 if ($order->from_openid && $order->from_openid != 'null') { $way = 'recommend'; - \CommonUtilsService::sendBuySuccessNoticeToBusiness($course, $order->from_openid, $way, - $order->price, $order->mobile, $order->name); + \CommonUtilsService::sendBuySuccessNoticeToBusiness( + $course, + $order->from_openid, + $way, + $order->price, + $order->mobile, + $order->name + ); } //短信通知商家 $jump_url = env('APP_URL') . '/pu_m/#/earningsRecord?merchant_id=' . $order->merchant_id; @@ -1050,15 +1194,21 @@ class OrderController extends Controller $message = '有用户下单了~ ' . $order->name . '购买了平台的《' . $title . '》' . $order->price . '元,点击' . $short_url['url'] . ' 查看详情'; $anchor_mobile = Anchor::where('id', $request->merchant_id)->value('mobile'); - $this->sentMessage($anchor_mobile,$message); + $this->sentMessage($anchor_mobile, $message); $content = $order->name . '购买了【' . $course->title . '】查看订单详情>>'; - SaasNotice::addRecord($order->merchant_id, $order->account_id, 'order', - $order->id, $content, 0); + SaasNotice::addRecord( + $order->merchant_id, + $order->account_id, + 'order', + $order->id, + $content, + 0 + ); $user_course->save(); } $order->save(); - $order->need_pay = $course->charge?1:0; - return ['code' => 0, 'data'=>$order]; + $order->need_pay = $course->charge ? 1 : 0; + return ['code' => 0, 'data' => $order]; } @@ -1070,36 +1220,43 @@ class OrderController extends Controller $history_id = $request->history_id; $buy_type = $request->buy_type ?? 'normal';//normal:单独购买 group:拼团购买 $user = MerchantUser::where('id', $user_id)->first(); - if (!$user) throw new \Exception("用户信息不存在"); + if (!$user) + throw new \Exception("用户信息不存在"); $config = Consultation::where('id', $consult_id)->first(); - if (empty($config)) return ['code'=>1, 'msg'=>"该咨询已下线"]; + if (empty($config)) + return ['code' => 1, 'msg' => "该咨询已下线"]; $link_name = $request->linkmen['name'] ?? ($request->linkmen[0]['name'] ?? null); $link_mobile = $request->linkmen['mobile'] ?? ($request->linkmen[0]['mobile'] ?? ''); $group_id = null; - if($buy_type && $buy_type == 'group'){ + if ($buy_type && $buy_type == 'group') { $time = date('Y-m-d H:i:s'); - $group = CollageGroup::where('type','community')->where('type_id',$request->id)->first(); - if(!$group) return $this->failure('拼团信息不存在'); + $group = CollageGroup::where('type', 'community')->where('type_id', $request->id)->first(); + if (!$group) + return $this->failure('拼团信息不存在'); $price = $group->price; $group_id = $group->id; $history_id = $request->history_id; - if($history_id) { + if ($history_id) { $history = CollageGroupHistories::where('id', $history_id)->first(); if ($history) { - if ($history->deadline < $time) return $this->failure('你慢了一步,拼团已过有效期'); - if ($history->status == 1) return $this->failure('你慢了一步,该团已被他人完成'); + if ($history->deadline < $time) + return $this->failure('你慢了一步,拼团已过有效期'); + if ($history->status == 1) + return $this->failure('你慢了一步,该团已被他人完成'); $m_order_ids = CollageGroupHistories::where('group_id', $history->group_id) ->where('m_user_id', $user_id)->where('status', 0)->where('deadline', '>', $time) ->pluck('m_order_id')->toArray(); $exists = TouristOrder::whereIn('id', $m_order_ids)->whereIn('pay_status', [1, 4])->first(); - if ($exists) return $this->failure('该活动你有尚未完成的拼团,请耐心等待'); + if ($exists) + return $this->failure('该活动你有尚未完成的拼团,请耐心等待'); $exists = CollageGroupHistories::with('tOrder')->whereHas('tOrder', function ($sql) { $sql->whereIn('pay_status', [1, 4]); }) ->where('group_id', $group->id)->where('m_user_id', $user_id) ->where('status', 1) ->first(); - if ($exists) return $this->failure('你已成功拼团参与过该活动,无需重复参与'); + if ($exists) + return $this->failure('你已成功拼团参与过该活动,无需重复参与'); } } } @@ -1131,7 +1288,7 @@ class OrderController extends Controller $order->type_id = $request->consultation_id; $order->pay_type = 'wechat'; $order->type = 'consult'; - if($buy_type && $buy_type == 'group'){ + if ($buy_type && $buy_type == 'group') { $order->group_id = $group_id; } $order->withdrawal_radio = 100; @@ -1159,7 +1316,8 @@ class OrderController extends Controller \CommonUtilsService::sendBuySuccessNoticeToUser($res, $openid, $way, $trade_no, $consult_record->price); $merchant = MerchantAccount::where('id', $consult_record->merchant_id)->first(); $merchant_openid = $merchant->openid; - if (empty($merchant_openid)) $merchant_openid = Anchor::where('m_id', $merchant->id)->value('openid'); + if (empty($merchant_openid)) + $merchant_openid = Anchor::where('m_id', $merchant->id)->value('openid'); //通知商户 \CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $merchant_openid, $type, $order->price, $order->mobile, $order->name); //发送推荐人 @@ -1191,8 +1349,8 @@ class OrderController extends Controller } $order->save(); $consult_record->save(); - $order->need_pay = $config->price?1:0; - return ['code'=>0, 'data'=>$order]; + $order->need_pay = $config->price ? 1 : 0; + return ['code' => 0, 'data' => $order]; } @@ -1202,20 +1360,23 @@ class OrderController extends Controller ->first(); $test_item_id = $evaluate_id; $merchant_id = $request->merchant_id; - if (!$merchant_id || !$test_item_id) throw new \Exception("缺少商户信息或测评信息"); + if (!$merchant_id || !$test_item_id) + throw new \Exception("缺少商户信息或测评信息"); $trade_no = $this->getTradeNO(); $merchant_evaluates = MerchantEvaluate::where('merchant_id', $merchant_id) ->where('test_item_id', $test_item_id) ->first(); - if (!$merchant_evaluates) return ['code'=>1, 'msg'=>"该测评已下线"]; - if($merchant_evaluates->type ==1){ + if (!$merchant_evaluates) + return ['code' => 1, 'msg' => "该测评已下线"]; + if ($merchant_evaluates->type == 1) { //查询一点灵价格 $result = EvaluateService::testDetails($test_item_id); - if (!$result) return ['code'=>1, 'msg'=>"该测评已下线"]; - }else{ + if (!$result) + return ['code' => 1, 'msg' => "该测评已下线"]; + } else { $result = EvaluateDetail::where('test_item_id', $test_item_id) ->first(); - $result->price = $result->price * 100; + $result->price = $result->price * 100; } //写入订单表 $order = new TouristOrder(); @@ -1232,8 +1393,8 @@ class OrderController extends Controller $order->from_openid = $request->from_openid; $order->share_channel_id = $request->share_channel_id; $order->alliance_id = $request->alliance_id; - $link_name = $request->linkmen['name']??($request->linkmen[0]['name']??null); - $link_mobile = $request->linkmen['mobile']??($request->linkmen[0]['mobile']??''); + $link_name = $request->linkmen['name'] ?? ($request->linkmen[0]['name'] ?? null); + $link_mobile = $request->linkmen['mobile'] ?? ($request->linkmen[0]['mobile'] ?? ''); $order->name = $request->name ?? ($MerchantUser->nickname ?? $link_name); $order->mobile = $request->mobile ?? ($MerchantUser->mobile ?? $link_mobile); $order->account_id = $user_id; @@ -1243,33 +1404,36 @@ class OrderController extends Controller $order->area_code = null; $order->linkmen = json_encode($request->linkmen); $order->save(); - $list = EvaluateList::where('test_item_id',$test_item_id) + $list = EvaluateList::where('test_item_id', $test_item_id) ->first(); - if($list->type ==1) { + if ($list->type == 1) { //调用一点灵评测下单接口下单 $evaluate = EvaluateService::testCreate($test_item_id, $result['price'], $trade_no); - if (!$evaluate) throw new \Exception("第三方未返回数据"); + if (!$evaluate) + throw new \Exception("第三方未返回数据"); } if ($result['price'] == 0) { $order->pay_status = 1; $order->save(); - if($list->type ==1) { + if ($list->type == 1) { EvaluateService::testUpdate($trade_no); } } $order->save(); - $order->need_pay = ($result['price'] > 0)?1:0; - return ['code'=>0, 'data'=>$order]; + $order->need_pay = ($result['price'] > 0) ? 1 : 0; + return ['code' => 0, 'data' => $order]; } public function payShopOrder($request, $shop_id, $user_id, $openid) { $shop = MerchantShop::where('id', $shop_id)->where('is_show', 1)->first(); - if (!$shop) return ['code'=>1, 'msg'=>'你购买的商品不存在或已下架。']; + if (!$shop) + return ['code' => 1, 'msg' => '你购买的商品不存在或已下架。']; $sku_id = $request->sku_id; - if (!$sku_id && $shop->pay_type == 'wechat') return $this->failure('规格参数不存在,请稍后再试。'); + if (!$sku_id && $shop->pay_type == 'wechat') + return $this->failure('规格参数不存在,请稍后再试。'); if ($sku_id) { $skus = json_decode($shop->sku, true); $skus = array_column($skus, null, 'sku_id'); @@ -1291,7 +1455,7 @@ class OrderController extends Controller $order->price = floatval($pay_price); $order->pay_type = $shop->pay_type; $order->type = 'shop'; - $order->num = $request->num?:1; + $order->num = $request->num ?: 1; $order->type_id = $request->id; $order->trade_no = $trade_no; $order->desc = $desc; @@ -1299,8 +1463,8 @@ class OrderController extends Controller $order->share_channel_id = $request->share_channel_id; $order->merchant_id = $request->merchant_id ?? 0; $order->account_id = $user_id; - $link_name = $request->linkmen['name']??($request->linkmen[0]['name']??null); - $link_mobile = $request->linkmen['mobile']??($request->linkmen[0]['mobile']??''); + $link_name = $request->linkmen['name'] ?? ($request->linkmen[0]['name'] ?? null); + $link_mobile = $request->linkmen['mobile'] ?? ($request->linkmen[0]['mobile'] ?? ''); $order->name = $request->name ?? ($MerchantUser->nickname ?? $link_name); $order->mobile = $request->mobile ?? ($MerchantUser->mobile ?? $link_mobile); $order->withdrawal_radio = $anchor->withdrawal_radio ?? 100; @@ -1318,25 +1482,42 @@ class OrderController extends Controller $order->save(); $shop_recive->order_id = $order->id; $shop_recive->save(); -// $order->address = $request->address; + // $order->address = $request->address; //发送通知 $way = 'merchant'; //给用户 - \CommonUtilsService::sendBuySuccessNoticeToUser($shop, $order->open_id, $order->type, - $order->trade_no, $order->price); + \CommonUtilsService::sendBuySuccessNoticeToUser( + $shop, + $order->open_id, + $order->type, + $order->trade_no, + $order->price + ); //给商户 $merchant = MerchantAccount::where('id', $order->merchant_id)->first(); $merchant_openid = $merchant->openid ?? ''; if (!$merchant_openid) { $merchant_openid = Anchor::where('m_id', $shop->merchant_id)->value('openid'); } - \CommonUtilsService::sendBuySuccessNoticeToBusiness($shop, $merchant_openid, $way, $order->price, - $order->mobile, $order->name); + \CommonUtilsService::sendBuySuccessNoticeToBusiness( + $shop, + $merchant_openid, + $way, + $order->price, + $order->mobile, + $order->name + ); //发送推荐人 if ($order->from_openid && $order->from_openid != 'null') { $way = 'recommend'; - \CommonUtilsService::sendBuySuccessNoticeToBusiness($shop, $order->from_openid, $way, - $order->price, $order->mobile, $order->name); + \CommonUtilsService::sendBuySuccessNoticeToBusiness( + $shop, + $order->from_openid, + $way, + $order->price, + $order->mobile, + $order->name + ); } //短信通知商家 $jump_url = env('APP_URL') . '/pu_m/#/earningsRecord?merchant_id=' . $merchant->id; @@ -1358,15 +1539,21 @@ class OrderController extends Controller ]); //插入购买通知 $content = $order->name . '购买了【' . $shop->title . '】查看订单详情>>'; - SaasNotice::addRecord($order->merchant_id, $order->account_id, 'order', - $order->id, $content, 0); + SaasNotice::addRecord( + $order->merchant_id, + $order->account_id, + 'order', + $order->id, + $content, + 0 + ); } $order->save(); $shop_recive->order_id = $order->id; $shop_recive->save(); - $order->need_pay = ($price > 0)?1:0; - return ['code'=>0, 'data'=>$order]; + $order->need_pay = ($price > 0) ? 1 : 0; + return ['code' => 0, 'data' => $order]; } public function BusinessPayOrder(Request $request) @@ -1385,16 +1572,17 @@ class OrderController extends Controller //活动下单 if ($type == 'activity' || $type == 'service') { $result = $this->payCommunityOrder($request, $request->type_id, $user_id, $openid); - }elseif ($type == 'course') { + } elseif ($type == 'course') { $result = $this->payCourseOrder($request, $request->type_id, $user_id, $openid); - }elseif ($type == 'consult') { + } elseif ($type == 'consult') { $result = $this->payConsultOrder($request, $request->type_id, $user_id, $openid); - }elseif ($type == 'evaluate') { + } elseif ($type == 'evaluate') { $result = $this->payEvaluateOrder($request, $request->test_item_id, $user_id, $openid); - }elseif ($type == 'shop') { + } elseif ($type == 'shop') { $result = $this->payShopOrder($request, $request->type_id, $user_id, $openid); } - if($result['code'] == 1) return $this->failure($result['msg']); + if ($result['code'] == 1) + return $this->failure($result['msg']); $order = $result['data']; return $this->success('ok', $order); } catch (\Exception $e) { @@ -1407,7 +1595,7 @@ class OrderController extends Controller { try { $pay_status = Order::where('trade_no', $trade_no)->value('pay_status'); - $is_paid = $pay_status?1:0; + $is_paid = $pay_status ? 1 : 0; return $this->success('ok', compact('is_paid')); } catch (\Exception $e) { $this->getError($e); diff --git a/app/Http/Controllers/TestController.php b/app/Http/Controllers/TestController.php index 81ac09c..476577f 100644 --- a/app/Http/Controllers/TestController.php +++ b/app/Http/Controllers/TestController.php @@ -61,6 +61,7 @@ use App\Models\TouristOrder; use App\Models\User; use App\Models\Wechat; use App\Services\IMService; +use App\Services\OrderService; use App\Services\SaasVipService; use App\Services\TestService; use App\Utils\Http; @@ -171,8 +172,7 @@ class TestController extends Controller } public function test($request) { - $time = '2023-01-01 00:00'; - dd(date('Y-m-d', strtotime($time))); + } public function merchantEarningExport(Request $request) diff --git a/app/Models/Dma/DmaServiceUserRole.php b/app/Models/Dma/DmaServiceUserRole.php new file mode 100644 index 0000000..2ab2e7e --- /dev/null +++ b/app/Models/Dma/DmaServiceUserRole.php @@ -0,0 +1,11 @@ +user(); //购买的会员等级 $sub_rank_id = $request->input('sub_rank_id'); - $goods = '购买'.$rank_month.'个月'.$rank_name.'VIP'; + $goods = '购买' . $rank_month . '个月' . $rank_name . 'VIP'; //订单号 if ($trade_type == 'alipay') { $trade_no = \CommonUtilsService::getAliTradeNo(); - }else{ + } else { $trade_no = \CommonUtilsService::getTradeNO(); } //如果购买的会员是市级会员 @@ -44,31 +47,31 @@ class OrderService implements OrderContract 'user_id' => $user->id, 'trade_no' => $trade_no, 'pay_status' => 'PAID', - 'is_hooked' =>1, + 'is_hooked' => 1, 'cash' => 0, 'score' => 0, ); $order = array( - 'user_id'=>$user->id, - 'type_id'=>$sub_rank_id, - 'goods'=>$goods, - 'price'=>0, - 'num'=>1, - 'type'=>'rank', - 'trade_no'=>$trade_no, - 'pay_status'=>'PAID', + 'user_id' => $user->id, + 'type_id' => $sub_rank_id, + 'goods' => $goods, + 'price' => 0, + 'num' => 1, + 'type' => 'rank', + 'trade_no' => $trade_no, + 'pay_status' => 'PAID', ); $order_pay = PayOrder::create($pay_order); $order = Order::create($order); - }else{ + } else { $order_pay = PayOrder::where('trade_no', $order->trade_no)->first(); } $order_pay->wx_pay = []; $h = RankHistory::where('user_id', $user->id)->where('rank_id', 1)->first(); if (empty($h)) { RankHistory::create([ - 'user_id'=>$user->id, - 'rank_id'=>1, + 'user_id' => $user->id, + 'rank_id' => 1, ]); } return $order_pay; @@ -79,14 +82,14 @@ class OrderService implements OrderContract if ($score->remain_amount >= $discount_price) { $cash = 0; $score = $discount_price; - }else{ - $discount_price = (int)number_format($discount_price, 2, '', ''); - $remain_amount = (int)number_format($score->remain_amount, 2, '', ''); + } else { + $discount_price = (int) number_format($discount_price, 2, '', ''); + $remain_amount = (int) number_format($score->remain_amount, 2, '', ''); $cash = ($discount_price - $remain_amount) / 100; $score = $score->remain_amount; $discount_price = $discount_price / 100; } - }else{ + } else { $cash = $discount_price; $score = 0; } @@ -104,34 +107,34 @@ class OrderService implements OrderContract 'score' => $score, ); $order = array( - 'user_id'=>$user->id, - 'type_id'=>$sub_rank_id, - 'goods'=>$goods, - 'price'=>$discount_price, - 'num'=>1, - 'type'=>'rank', - 'trade_no'=>$trade_no, + 'user_id' => $user->id, + 'type_id' => $sub_rank_id, + 'goods' => $goods, + 'price' => $discount_price, + 'num' => 1, + 'type' => 'rank', + 'trade_no' => $trade_no, ); //支付订单 $order_pay = PayOrder::create($pay_order); $order = Order::create($order); $wx_pay = []; - if ($cash>0) { + if ($cash > 0) { if ($trade_type == 'h5') {//h5支付 if (strstr($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')) { $wx_pay = \WechatService::constructWXPay($pay_order, $user->id, $goods); - }else{ + } else { $wx_pay = \WechatService::constructWXH5Pay($pay_order, $user->id, $goods); } - }elseif ($trade_type == 'wechat_app') { + } elseif ($trade_type == 'wechat_app') { $wx_pay = \WechatService::constructWXAppPay($pay_order, $user->id, $goods); - }elseif ($trade_type == 'alipay_app') { + } elseif ($trade_type == 'alipay_app') { $subject = 'rank'; $wx_pay = \AlipayService::purchase($subject, $trade_no, $cash); } - }else{ + } else { $order_pay->pay_status = 'PAID'; $order_pay->is_hooked = 1; $order->pay_status = 'PAID'; @@ -157,9 +160,9 @@ class OrderService implements OrderContract $pay_order = PayOrder::where('trade_no', $order->trade_no)->first(); if ($pay_order->score > 0) { //扣除对应积分 - $result = $this->changeScore($order->user_id, $pay_order->score, 'used', $message='升级VIP'); + $result = $this->changeScore($order->user_id, $pay_order->score, 'used', $message = '升级VIP'); if (!$result) { - \Log::debug($order->trade_no.'订单查询异常: 支付回调失败, 福分溢出'); + \Log::debug($order->trade_no . '订单查询异常: 支付回调失败, 福分溢出'); // $this->sms->sentMessage('15872844805', '订单号:'.$order->trade_no.' 福分溢出'); // return $this->failure('支付失败福分溢出'); return false; @@ -188,43 +191,43 @@ class OrderService implements OrderContract * @param inte $other_user_id 其他人ID * @return bool 是否成功 */ - public function changeScore($user_id, $score, $type, $message='', $other_user_id=null) + public function changeScore($user_id, $score, $type, $message = '', $other_user_id = null) { - $score_obj = Score::where('user_id', $user_id)->first(); - if (empty($score_obj)) { - $score_obj = Score::create([ - 'user_id'=>$user_id, - ]); - } - if ($type == 'gained') { - //更新积分 + $score_obj = Score::where('user_id', $user_id)->first(); + if (empty($score_obj)) { + $score_obj = Score::create([ + 'user_id' => $user_id, + ]); + } + if ($type == 'gained') { + //更新积分 // $score_obj->increment('remain_amount', $score); - }else{ + } else { if ($score_obj->remain_amount >= $score) { $score_obj->decrement('remain_amount', $score); - }else{ + } else { // $score_obj->decrement('remain_amount', $score_obj->remain_amount); - $this->sms->sentMessage('15872844805', '用户id:'.$user_id.', 福分超额.'.$message); + $this->sms->sentMessage('15872844805', '用户id:' . $user_id . ', 福分超额.' . $message); return false; } $score_obj->increment('used_amount', $score); - } - //生成积分记录 - ScoreHistory::create([ - 'user_id'=>$user_id, - 'other_user_id'=>$other_user_id, - 'type'=>$type, - 'amount'=>$score, - 'value'=>$score_obj->remain_amount, - 'message'=>$message, - ]); + } + //生成积分记录 + ScoreHistory::create([ + 'user_id' => $user_id, + 'other_user_id' => $other_user_id, + 'type' => $type, + 'amount' => $score, + 'value' => $score_obj->remain_amount, + 'message' => $message, + ]); // $array['message'] = $message; // $array['user_id'] = $user_id; // $array['other_user_id'] = $other_user_id; // $array['type'] = $type; // $array['score'] = $score; // SyncScore::dispatch($array)->onQueue('love'); - return true; + return true; } /** @@ -241,7 +244,7 @@ class OrderService implements OrderContract return; } - /** + /** * 修改会员 * @return [type] [description] */ @@ -256,71 +259,71 @@ class OrderService implements OrderContract //购买月数 $rank_month = $sub_rank->month; if ($user->rank_id === 0) { - //创建对应会员 + //创建对应会员 RankHistory::create([ - 'user_id'=>$user_id, - 'rank_id'=>$sub_rank->rank_id, - 'deadline'=>date('Y-m-d H:i:s', strtotime('+'.$rank_month.' month')), + 'user_id' => $user_id, + 'rank_id' => $sub_rank->rank_id, + 'deadline' => date('Y-m-d H:i:s', strtotime('+' . $rank_month . ' month')), ]); $user->rank_id = $sub_rank->rank_id; $user->save(); - }elseif ($user->rank_id === 1) {//当前市级 + } elseif ($user->rank_id === 1) {//当前市级 if ($rank_history && $rank_history->deadline) {//期限内 //更新市级会员 - $rank_history->deadline = date('Y-m-d H:i:s', strtotime('+'.$rank_month.' month', strtotime($rank_history->deadline))); + $rank_history->deadline = date('Y-m-d H:i:s', strtotime('+' . $rank_month . ' month', strtotime($rank_history->deadline))); $rank_history->save(); } //创建对应会员 RankHistory::create([ - 'user_id'=>$user_id, - 'rank_id'=>$sub_rank->rank_id, - 'deadline'=>date('Y-m-d H:i:s', strtotime('+'.$rank_month.' month')), + 'user_id' => $user_id, + 'rank_id' => $sub_rank->rank_id, + 'deadline' => date('Y-m-d H:i:s', strtotime('+' . $rank_month . ' month')), ]); $user->rank_id = $sub_rank->rank_id; $user->save(); - }elseif ($user->rank_id === 2) {//当前黄金 + } elseif ($user->rank_id === 2) {//当前黄金 //市级会员记录 $city_rank_history = RankHistory::where('user_id', $user_id)->where('rank_id', 1)->orderBy('id', 'desc')->first(); if (!empty($city_rank_history) && !empty($city_rank_history->deadline)) {//市级会员在期限内 //更新市级会员 - $city_rank_history->deadline = date('Y-m-d H:i:s', strtotime('+'.$rank_month.' month', strtotime($city_rank_history->deadline))); + $city_rank_history->deadline = date('Y-m-d H:i:s', strtotime('+' . $rank_month . ' month', strtotime($city_rank_history->deadline))); $city_rank_history->save(); } if ($sub_rank->rank_id === 2) { if (!empty($rank_history)) { - //更新黄金会员 - $rank_history->deadline = date('Y-m-d H:i:s', strtotime('+'.$rank_month.' month', strtotime($rank_history->deadline))); + //更新黄金会员 + $rank_history->deadline = date('Y-m-d H:i:s', strtotime('+' . $rank_month . ' month', strtotime($rank_history->deadline))); $rank_history->save(); - }else{ + } else { RankHistory::create([ - 'user_id'=>$user_id, - 'rank_id'=>$sub_rank->rank_id, - 'deadline'=>date('Y-m-d H:i:s', strtotime('+'.$rank_month.' month')), + 'user_id' => $user_id, + 'rank_id' => $sub_rank->rank_id, + 'deadline' => date('Y-m-d H:i:s', strtotime('+' . $rank_month . ' month')), ]); } } if ($sub_rank->rank_id === 3) { //创建对应会员 RankHistory::create([ - 'user_id'=>$user_id, - 'rank_id'=>$sub_rank->rank_id, - 'deadline'=>date('Y-m-d H:i:s', strtotime('+'.$rank_month.' month')), + 'user_id' => $user_id, + 'rank_id' => $sub_rank->rank_id, + 'deadline' => date('Y-m-d H:i:s', strtotime('+' . $rank_month . ' month')), ]); $user->rank_id = $sub_rank->rank_id; $user->save(); } - }elseif ($user->rank_id === 3) {//当前钻石 + } elseif ($user->rank_id === 3) {//当前钻石 //市级会员记录 $city_rank_history = RankHistory::where('user_id', $user_id)->where('rank_id', 1)->orderBy('id', 'desc')->first(); if (!empty($city_rank_history) && !empty($city_rank_history->deadline)) {//市级会员在期限内 //更新市级会员 - $city_rank_history->deadline = date('Y-m-d H:i:s', strtotime('+'.$rank_month.' month', strtotime($city_rank_history->deadline))); + $city_rank_history->deadline = date('Y-m-d H:i:s', strtotime('+' . $rank_month . ' month', strtotime($city_rank_history->deadline))); $city_rank_history->save(); } @@ -328,13 +331,13 @@ class OrderService implements OrderContract $gold_rank_history = RankHistory::where('user_id', $user_id)->where('rank_id', 2)->orderBy('id', 'desc')->first(); if (!empty($gold_rank_history) && !empty($gold_rank_history->deadline)) {//黄金会员在期限内 //更新市级会员 - $gold_rank_history->deadline = date('Y-m-d H:i:s', strtotime('+'.$rank_month.' month', strtotime($gold_rank_history->deadline))); + $gold_rank_history->deadline = date('Y-m-d H:i:s', strtotime('+' . $rank_month . ' month', strtotime($gold_rank_history->deadline))); $gold_rank_history->save(); } //更新钻石会员 - $rank_history->deadline = date('Y-m-d H:i:s', strtotime('+'.$rank_month.' month', strtotime($rank_history->deadline))); + $rank_history->deadline = date('Y-m-d H:i:s', strtotime('+' . $rank_month . ' month', strtotime($rank_history->deadline))); $rank_history->save(); - }elseif ($user->rank_id === 9) {//当前超级会员 + } elseif ($user->rank_id === 9) {//当前超级会员 // $history = RankHistory::where('user_id', $user_id)->where('rank_id', $sub_rank->rank_id)->where('deadline', ">", date('Y-m-d H:i:s'))->first(); // if ($history) { // $history->deadline = date('Y-m-d H:i:s', strtotime('+'.$rank_month.' month', strtotime($history->deadline))); @@ -360,31 +363,31 @@ class OrderService implements OrderContract //推荐人 $user_id = Wechat::where('openid', $from_openid)->value('user_id'); if (empty($user_id)) { - return ; + return; } //是否交认证费 $approve_order = Order::where('user_id', $user_id)->where('type', 'approve')->where('pay_status', 'PAID')->first(); if (empty($approve_order)) { - return ; + return; } $approve_pay_order = PayOrder::where('user_id', $user_id)->where('trade_no', $approve_order->trade_no)->where('is_hooked', 1)->first(); if (empty($approve_pay_order)) { - return ; + return; } //是否已退 - $refund_order = RefundOrder::where('user_id', $user_id)->where('type','approve')->first(); + $refund_order = RefundOrder::where('user_id', $user_id)->where('type', 'approve')->first(); //生成退款记录 if (empty($refund_order)) { $refund_order = RefundOrder::create([ - 'user_id'=>$user_id, - 'type'=>'approve', - 'trade_no'=>$approve_order->trade_no, - 'refund_trade_no'=>\CommonUtilsService::getRefundTradeNo(), - 'total_fee'=>$approve_pay_order->cash, - 'refund_fee'=>$approve_pay_order->cash, + 'user_id' => $user_id, + 'type' => 'approve', + 'trade_no' => $approve_order->trade_no, + 'refund_trade_no' => \CommonUtilsService::getRefundTradeNo(), + 'total_fee' => $approve_pay_order->cash, + 'refund_fee' => $approve_pay_order->cash, ]); - }else{ - return ; + } else { + return; } $total = $refund_order->total_fee * 100; $desc = '用户实名认证费退款'; @@ -400,15 +403,15 @@ class OrderService implements OrderContract { // $order = Order::where('user_id', $user_id)->where('type', 'approve')->where('pay_status','PAID')->first(); // if (empty($order)) { - // $order = Order::create([ - // 'user_id'=>$user_id, - // 'type_id'=>0, - // 'type'=>"approve", - // 'goods'=>'赠送认证', - // 'pay_status'=>'PAID', - // 'price'=>10, - // 'trade_no'=>'123', - // ]); + // $order = Order::create([ + // 'user_id'=>$user_id, + // 'type_id'=>0, + // 'type'=>"approve", + // 'goods'=>'赠送认证', + // 'pay_status'=>'PAID', + // 'price'=>10, + // 'trade_no'=>'123', + // ]); // } return; @@ -417,7 +420,7 @@ class OrderService implements OrderContract /** * app支付生成订单 */ - public function makeAppOrder($request, $price, $type, $type_id=0, $goods, $linkmen=[], $detail='') + public function makeAppOrder($request, $price, $type, $type_id = 0, $goods, $linkmen = [], $detail = '') { try { $user = auth()->user(); @@ -435,21 +438,21 @@ class OrderService implements OrderContract $score = 0; $cash = $price; $order = array( - 'user_id'=>auth()->id(), - 'type_id'=>$type_id, - 'goods'=>$goods, - 'price'=>$price, - 'num'=>1, - 'type'=>$type, - 'trade_no'=>$trade_no, - 'pay_type'=>$pay_type, - 'linkmen'=>json_encode($request->input('linkmen', [])), + 'user_id' => auth()->id(), + 'type_id' => $type_id, + 'goods' => $goods, + 'price' => $price, + 'num' => 1, + 'type' => $type, + 'trade_no' => $trade_no, + 'pay_type' => $pay_type, + 'linkmen' => json_encode($request->input('linkmen', [])), ); if ($price == 0) { - $order['pay_status'] = 'PAID'; - $score = 0; - $cash = 0; - }else{ + $order['pay_status'] = 'PAID'; + $score = 0; + $cash = 0; + } else { //计算支付金额 if ($use_score) { //福气 @@ -457,12 +460,12 @@ class OrderService implements OrderContract $remain_score = 0; if (!empty($viewer_id)) { $asset = Asset::where('viewer_id', $viewer_id)->first(); - $remain_score = $asset?bcadd($asset->share_cash,$asset->cash,2):0; + $remain_score = $asset ? bcadd($asset->share_cash, $asset->cash, 2) : 0; } if (bccomp($price, $remain_score) > 0) { $cash = bcsub($price, $remain_score, 2); $score = $remain_score; - }else{ + } else { $cash = 0; $score = $price; } @@ -470,15 +473,16 @@ class OrderService implements OrderContract } $receipt = request()->input('apple_receipt'); $ios_version = $request->header('app-version', '1.0.0'); -// $result = \CommonUtilsService::contrastVersion($ios_version, '1.3.16'); + // $result = \CommonUtilsService::contrastVersion($ios_version, '1.3.16'); - $result = $ios_version == '1.3.17'?true:false; - if ($result && $pay_type == 'ios' and empty($receipt)) throw new \Exception("没有支付凭证", 1); + $result = $ios_version == '1.3.17' ? true : false; + if ($result && $pay_type == 'ios' and empty($receipt)) + throw new \Exception("没有支付凭证", 1); //生成支付订单 $pay_order = array( 'user_id' => auth()->id(), 'trade_no' => $trade_no, - 'pay_status' => $price == 0?'PAID':'UNPAID', + 'pay_status' => $price == 0 ? 'PAID' : 'UNPAID', 'cash' => $cash, 'score' => $score, 'pay_type' => $pay_type, @@ -498,14 +502,14 @@ class OrderService implements OrderContract $order_pay = PayOrder::create($pay_order); //支付订单 $order = Order::create($order); - if ($cash>0) { + if ($cash > 0) { if ($pay_type == 'wechat') { $ios_version = request()->header('app-version'); $and_version = request()->header('version-name'); - $callback = config('app.url').'/api/app/callback/orders/'.$pay_order['trade_no'].'?ios_version='.$ios_version.'&and_version='.$and_version; + $callback = config('app.url') . '/api/app/callback/orders/' . $pay_order['trade_no'] . '?ios_version=' . $ios_version . '&and_version=' . $and_version; $pay_config = \WechatService::constructWXAppPay($pay_order, auth()->id(), $detail, $callback); $order_pay->pay_config = $pay_config; - }elseif ($pay_type == 'alipay') { + } elseif ($pay_type == 'alipay') { $pay_config = \AlipayService::purchase($detail, $trade_no, $cash); $order_pay->pay_config = $pay_config; } @@ -519,7 +523,7 @@ class OrderService implements OrderContract } - /** + /** * 修改福气 * @param Request $request [description] * @return [type] [description] @@ -531,20 +535,20 @@ class OrderService implements OrderContract //福气 $asset = $user->userAsset(); if (!empty($asset)) { - $remain_score = $asset?bcadd($asset->share_cash,$asset->cash,2):0; + $remain_score = $asset ? bcadd($asset->share_cash, $asset->cash, 2) : 0; if ($remain_score < $score) {//总福气小于消耗福气 \DB::rollback(); - throw new \Exception("福气溢出 用户id:".$user->id, 1); + throw new \Exception("福气溢出 用户id:" . $user->id, 1); } //先扣除cash $cash = $asset->cash; $share_cash = $asset->share_cash; if ($cash >= $score) { $asset->decrement('cash', $score); - }else{ + } else { $asset->decrement('cash', $cash); //再扣除share_cash - $asset->decrement('share_cash', bcsub($score,$cash,2)); + $asset->decrement('share_cash', bcsub($score, $cash, 2)); } //生成消费记录 $log = new AssetLog; @@ -553,11 +557,11 @@ class OrderService implements OrderContract $log->real_num = $score; $log->type = 6; $log->is_hooked = 1; - $log->score = bcadd($asset->share_cash,$asset->cash,2); + $log->score = bcadd($asset->share_cash, $asset->cash, 2); $log->save(); - }else{ + } else { \DB::rollback(); - throw new \Exception("未查询到福气账号 用户id:".$user->id, 1); + throw new \Exception("未查询到福气账号 用户id:" . $user->id, 1); } \DB::commit(); return true; @@ -571,7 +575,8 @@ class OrderService implements OrderContract /**订单类型转换 代码转成中文*/ - public function orderTypeCodeSwitchChinese($type){ + public function orderTypeCodeSwitchChinese($type) + { if ($type === 'score') { return '福分充值'; } else if ($type === 'rank') { @@ -600,10 +605,95 @@ class OrderService implements OrderContract return '赠送礼物'; } else if ($type === 'course') { return '购买课程'; - }else{ + } else { return '其他'; } } + public function storeUftxCustomer($order): bool + { + try { + // 判断订单是否是uftx + if ($order->merchant_id != 44) { + Log::error("不是友福商户"); + return false; + } + + // 判断订单是否有分享人 + if (!$order->from_openid) { + Log::error("没有from_openid"); + return false; + } + // 判断下单人和分享人是否一致 + if ($order->openid == $order->from_openid) { + Log::error("分享人和下单人一致"); + return false; + } + + // 查询订单用户手机号和分享人用户手机号 + $wechat = Wechat::where("official_openid", $order->open_id)->first(); + if (empty($wechat)) { + Log::error("没有下单人wechat"); + return false; + } + $from_wechat = Wechat::where("official_openid", $order->from_openid)->first(); + if (empty($from_wechat)) { + Log::error("没有分享人wechat"); + return false; + } + $user = User::Where("id", $wechat->user_id)->first(); + if (empty($user)) { + Log::error("没有下单人user"); + return false; + } + $from_user = User::Where("id", $from_wechat->user_id)->first(); + if (empty($from_user)) { + Log::error("没有分享人user"); + return false; + } + $mobile = $user->mobile; + if (empty($mobile)) { + Log::error("没有下单人手机号"); + return false; + } + $from_mobile = $from_user->mobile; + if (empty($from_mobile)) { + Log::error("没有分享人手机号"); + return false; + } + + // 判断分享人是否在友福同享有服务端账号 + $serviceUser = DmaServiceUserRole::where("mobile", $from_mobile)->first(); + if (empty($serviceUser)) { + Log::error("分享人不是商户端用户"); + return false; + } + + // 判断是否已经是客户 + $customer = S2Customer::where(["user_id" => $serviceUser->user_id, "contacts_mobile" => $mobile])->first(); + if ($customer) { + Log::error("已成为客户"); + return false; + } + + // 创建客户 + S2Customer::create([ + "user_id" => $serviceUser->user_id, + "customer_name" => "", + "customer_type" => 101, + "contacts_name" => $user->nickname, + "contacts_mobile" => $mobile, + "intention" => 1, + "status" => 2 + ]); + Log::info("创建客户成功"); + return true; + } catch (\Throwable $th) { + $this->getError($th); + return false; + } + + } + } diff --git a/config/database.php b/config/database.php index 0989ca6..8d01cec 100644 --- a/config/database.php +++ b/config/database.php @@ -46,7 +46,7 @@ return [ ], 'write' => [ 'host' => env('DB_HOST_WRITE', '127.0.0.1'), - ],*/ + ],*/ 'host' => env('DB_HOST', '10.10.10.2'), 'port' => env('DB_PORT', '3306'), 'database' => env('DB_DATABASE', 'forge'), @@ -60,6 +60,22 @@ return [ 'engine' => null, ], + 'dma' => [ + 'driver' => 'mysql', + 'host' => env('DMA_DB_HOST', '192.168.6..10'), + 'port' => env('DMA_DB_PORT', '3306'), + 'database' => env('DMA_DB_DATABASE', 'health'), + 'username' => env('DMA_DB_USERNAME', 'root'), + 'password' => env('DMA_DB_PASSWORD', 'root'), + 'unix_socket' => env('DB_SOCKET', ''), + 'charset' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'prefix' => env('DB_PREFIX', ''), + 'strict' => false, + 'engine' => null, + ], + + 'pgsql' => [ 'driver' => 'pgsql', 'host' => env('DB_HOST', '127.0.0.1'),