123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697 |
- <?php
- namespace App\Http\Controllers;
- use App\Events\HelpOrderEvent;
- use App\Events\NewOrder;
- use App\Events\RetailOutboundEvent;
- use App\Http\Middleware\AssitMiddleware;
- use App\Models\Amount;
- use App\Models\Assit;
- use App\Models\DwbsUser;
- use App\Models\Goods;
- use App\Models\GoodSku;
- use App\Models\IntegralW;
- use App\Models\Order;
- use App\Models\OrderW;
- use App\Models\OrderDetailW;
- use App\Models\StoreGoods;
- use App\Models\StoreGoodsSku;
- use App\Models\InventoryW;
- use App\Models\Store;
- use App\Models\User;
- use App\Models\UserW;
- use App\Models\UserZ;
- use App\Models\VipLogW;
- use App\Models\LogW;
- use App\Models\ZbsBasic;
- use App\Models\ZbsEnroll;
- use App\Models\ZbsOrder;
- use App\Models\OrderOnceW;
- use EasyWeChat\Factory;
- use Carbon\Carbon;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\Cache;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- class PaymentController extends Controller
- {
- public function pay_test(Request $request)
- {
- $order_no=$request->input('order_no');
- $order=OrderW::where('order_no',$order_no)->lockForUpdate()->first();
- $store=Store::where('id',$order->store_id)->first();
- if(empty($store)){
- return $this->error('450001','','店铺不存在或者已被删除');
- }
- if($store->status==1){
- return $this->error('450001','','店铺已被禁用');
- }
- if($order->apply_cancel == 2){
- return $this->error('450001','','订单已取消');
- }
- if($order->is_pay != 0 || $order->status != 0){
- return $this->error('450001','','订单状态有误');
- }
- if($order->account <= 0){
- return $this->error('450001','','支付金额有误');
- }
- //修改订单状态
- $order->status = 1;
- $order->is_help = 1;
- $order->is_pay = 1;
- $order->pay_type = 1;
- $order->save();
- return response()->json([
- 'error_code'=>200,
- 'msg'=>'成功',
- ]);
- }
- public function pay(Request $request)
- {
- Log::info($request);
- $order_no=$request->input('order_no');
- $tradeType=$request->input('type','APP');//支付场景,APP/JSAPI
- $is_assit=$request->input('is_assit',0);
- if(!in_array($tradeType,['APP','JSAPI'])){
- return $this->error('450001','支付场景有误');
- }
- try{
- DB::transaction(function()use($order_no, $is_assit ,&$order ,&$seconds){
- $order=OrderW::where('order_no',$order_no)->lockForUpdate()->first();
- $seconds=Carbon::now()->subSeconds(60)->toDateTimeString();//限制调起支付60秒
- if(empty($order)){
- throw new \Exception("订单有误");
- }
- if($order->prepare_pay_at >= $seconds){
- throw new \Exception("订单正在支付中");
- }
- if($is_assit){
- $order->self_pay=2;
- }else{
- $order->self_pay=1;
- }
- $order->prepare_pay_at=Carbon::now();
- $order->save();
- });
- }catch(\Exception $e){
- return $this->error('450001',$e->getMessage());
- }
- $store=Store::where('id',$order->store_id)->first();
- if(empty($store)){
- return $this->error('450001','店铺不存在或者已被删除');
- }
- if($store->status==1){
- return $this->error('450001','店铺已被禁用');
- }
- if($order->apply_cancel == 2){
- return $this->error('450001','订单已取消');
- }
- if($order->is_pay != 0 || $order->status != 0){
- return $this->error('450001','订单状态有误');
- }
- if($order->account <= 0){
- return $this->error('450001','支付金额有误');
- }
- $options = $this->options($order->store_id,$tradeType);
- $payment = Factory::payment($options);
- $jssdk = $payment->jssdk;
- Log::info('订单支付金额:'.$order->account);
- $two_minutes=Carbon::now()->addSeconds(55)->toDateTimeString();//限制支付时间55秒
- $cancel_time=Carbon::parse($order->created_at)->addMinutes(59)->toDateTimeString();//系统自动取消时间前一分钟
- if(Carbon::now() >= $cancel_time){
- return $this->error('450001','订单将被取消');
- }
- if($two_minutes <= $cancel_time){
- $expire=date("YmdHis",strtotime($two_minutes));
- }else{
- $expire=date("YmdHis",strtotime($cancel_time));
- }
- $attributes = [
- 'time_expire' => $expire,
- // 'trade_type' => 'JSAPI',
- 'trade_type' => $tradeType, // 支付方式,小程序支付使用JSAPI、APP
- 'body' => '订单支付', // 订单说明
- 'out_trade_no' => mt_rand('1000','9999').'_'.$order_no, // 自定义订单号
- 'total_fee' => $order->account*100, // 单位:分
- // 'total_fee' => 1, // 单位:分
- 'profit_sharing' => 'Y' //分账
- ];
- if($tradeType=='JSAPI'){
- if($is_assit){ //助手支付
- $openid=Assit::where('agent_id',Auth::user()->id)->value('openid');
- if(empty($openid)){
- return $this->error('450001','参数有误,请重新登录助手帐号');
- }
- }else{
- $openid=User::where('id',Auth::user()->id)->value('openid');
- }
- $attributes['openid']=$openid; // 当前用户的openId
- }
- Log::info([$options,$attributes,$order->account*100]);
- $result = $payment->order->unify($attributes);
- if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {
- Log::info($result);
- $order_info['order']=$order_no;
- $order_info['price']=$order->account;
- Cache::put('prepay_id:'.$result['prepay_id'],$order_info,3600*2);
- $prepayId = $result['prepay_id'];
- if($tradeType == 'JSAPI'){
- $config = $jssdk->sdkConfig($prepayId, false);
- }else{
- $config = $jssdk->appConfig($prepayId);
- }
- Log::info($config);
- return response()->json([
- 'error_code'=>200,
- 'code'=>200,
- 'msg'=>'成功',
- 'data'=>$config
- ]);
- }
- if ($result['return_code'] == 'FAIL' && array_key_exists('return_msg', $result)) {
- Log::info('订单支付失败:'.$order->user_id.'/'.$order_no.'/'.$order->account.'/'.$result['return_msg']);
- return response()->json([
- 'error_code'=>4011,
- 'code'=>4011,
- 'msg'=> $result['return_msg'],
- ]);
- }
- Log::info('订单支付失败:'.$order->user_id.'/'.$order_no.'/'.$order->account.'/'.$result['err_code_des']);
- return response()->json([
- 'error_code'=>4011,
- 'code'=>4011,
- 'msg'=> $result['err_code_des'],
- ]);
- }
- public function getOrderNo(Request $request){
- $prepay_id=$request->input('prepay_id');
- $order_info=Cache::get('prepay_id:'.$prepay_id);
- if($order_info){
- Cache::forget('prepay_id:'.$prepay_id);
- }
- return $this->success($order_info);
- }
- protected function options($id,$type)
- {
- if($type=='APP'){
- $arr= [
- 'app_id' => config('wechat.daweiboshi_app.default.app_id'),
- 'key' => config('wechat.payment.test.key'),
- 'mch_id' => config('wechat.payment.test.mch_id'),
- 'notify_url' => url('api/payment/app_notify'),
- ];
- }else{
- $arr= [
- 'app_id' => config('wechat.payment.test.app_id'),
- 'key' => config('wechat.payment.test.key'),
- 'mch_id' => config('wechat.payment.test.mch_id'),
- 'notify_url' => url('api/payment/h5_notify'),
- ];
- }
- if($id){
- $arr['sub_mch_id'] = Store::where('id',$id)->value('sub_mchid');
- }
- return $arr;
- }
- public function h5_notify(Request $request)
- {
- Log::info('h5支付完成开始微信回调');
- $options = $this->options(null,'JSAPI');
- $payment = Factory::payment($options);
- $response = $payment->handlePaidNotify(function ($message, $fail)
- {
- // 根据返回的订单号查询订单数据
- Log::error($message);
- LogW::create([
- 'content'=>json_encode($message),
- 'type'=>1
- ]);
- $rand_no=explode('_',$message['out_trade_no'])[0];
- $message['out_trade_no']=explode('_',$message['out_trade_no'])[1];
- $order=OrderW::where('order_no',$message['out_trade_no'])->first();
- if ($order->is_pay==1){
- Log::info('订单号为:'.$message['out_trade_no'].'已经支付');
- if($order->wechat_pay_no != $message['transaction_id']){
- OrderOnceW::create([
- 'order_no'=>$message['out_trade_no'],
- 'open_id'=>$message['openid'],
- 'wechat_no'=>$message['transaction_id'],
- 'result_code'=>$message['result_code'],
- 'type'=> 1,
- ]);
- }
- return true;
- }
- if (!$order || $order->status == 1) {
- Log::info('订单不存在:'.$message['out_trade_no'].'/'.$message['transaction_id'].'/'.$message['result_code']);
- return true;//订单不存在 或者 订单已支付
- }
- if ($message['result_code'] === 'FAIL') { //支付失败
- Log::warning('[wechat-pay]:' . json_encode($message, true));
- return true;
- }
- if ($message['return_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
- // 支付成功后的业务逻辑
- if($message['result_code'] === 'SUCCESS') {
- //处理订单支付完整后的信息
- $this->settlement($order,$message,$rand_no);
- }
- Log::info('微信支付回调结束');
- return true;
- }else{
- Log::info('通信失败');
- return $fail('通信失败,请稍后再通知我');
- }
- });
- return $response;
- }
- public function app_notify(Request $request)
- {
- Log::info('app支付完成开始微信回调');
- $options = $this->options(null,'APP');
- $payment = Factory::payment($options);
- $response = $payment->handlePaidNotify(function ($message, $fail)
- {
- // 根据返回的订单号查询订单数据
- Log::error($message);
- LogW::create([
- 'content'=>json_encode($message),
- 'type'=>1
- ]);
- $rand_no=explode('_',$message['out_trade_no'])[0];
- $message['out_trade_no']=explode('_',$message['out_trade_no'])[1];
- $order=OrderW::where('order_no',$message['out_trade_no'])->first();
- if ($order->is_pay==1){
- Log::info('订单号为:'.$message['out_trade_no'].'已经支付');
- if($order->wechat_pay_no != $message['transaction_id']){
- OrderOnceW::create([
- 'order_no'=>$message['out_trade_no'],
- 'open_id'=>$message['openid'],
- 'wechat_no'=>$message['transaction_id'],
- 'result_code'=>$message['result_code'],
- 'type'=> 1,
- ]);
- }
- return true;
- }
- if (!$order || $order->status == 1) {
- Log::info('订单不存在:'.$message['out_trade_no'].'/'.$message['transaction_id'].'/'.$message['result_code']);
- return true;//订单不存在 或者 订单已支付
- }
- if ($message['result_code'] === 'FAIL') { //支付失败
- Log::warning('[wechat-pay]:' . json_encode($message, true));
- return true;
- }
- if ($message['return_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
- // 支付成功后的业务逻辑
- if($message['result_code'] === 'SUCCESS') {
- //处理订单支付完整后的信息
- $this->settlement($order,$message,$rand_no);
- }
- Log::info('微信支付回调结束');
- return true;
- }else{
- Log::info('通信失败');
- return $fail('通信失败,请稍后再通知我');
- }
- });
- return $response;
- }
- private function settlement($order,$message,$rand_no){
- $total_fee=round($message['total_fee']/100,2);
- DB::connection('mysql_w')->transaction(function()use($order,$message,$total_fee,$rand_no){
- // $basic=ZbsBasic::whereIn('keys',['round_start_time','round_end_time','season'])->pluck('value','keys')->toArray();
- // $start_time=$basic['round_start_time'];
- // $end_time=$basic['round_end_time'];
- // $season=$basic['season'];
- // Log::info('0000000-00000'.$start_time.'///'.$end_time.'///'.$season);
- // $sto=Store::where('id',$order->store_id)->first();
- // $userzs = UserZ::where('dwbs_id', $sto->user_id)->get();
- //
- // $order->is_zbs = 0;
- $integral=$order->total*2;
- $zbs=0; //不在争霸赛期间
- //
- // if(count($userzs) > 0) { //争霸赛存在该用户
- //// if(!empty($userz)) { //争霸赛存在该用户
- // $now = Carbon::now()->timestamp;
- // $pay_time=Carbon::parse($message['time_end'])->timestamp;
- // Log::info('<<<<<>>>>>'.$now.'///'.$start_time.'///'.$end_time.'///'.$pay_time);
- // if ($pay_time >= $start_time && $pay_time <= $end_time) { //在争霸赛期间
- // $uids = \Illuminate\Support\Facades\Cache::remember('uids', Carbon::now()->addHours(12), function () use ($season) {
- // return ZbsEnroll::where('season', $season)->where('is_refund', 0)->where('status', 0)->pluck('uid')->toArray();
- // });
- //
- // foreach($userzs as $key =>$val){
- // if (in_array($val->id, $uids)) {//报名了争霸赛
- // //标记争霸赛订单
- // $order->is_zbs = 1;
- // //学分变更
- // $integral=0;
- // $zbs=1; //在争霸赛期间
- // }
- // }
- // }
- // }
- $inte=IntegralW::where('order_no',$order->order_no)->where('store_id',$order->store_id)->where('type',1)->first();
- if(empty($inte)){
- IntegralW::create([
- 'store_id'=>$order->store_id,
- 'order_no'=>$order->order_no,
- 'num'=>$order->total,
- 'integral'=>$integral,
- 'integral_double'=>$integral,
- 'type'=>1,
- 'remark'=>'下单成功',
- 'is_zbs'=>$zbs,
- ]);
- }
- //修改订单状态
- $order->status = 1;
- $order->is_help = 1;
- $order->is_pay = 1;
- $order->pay_type = 1;
- $order->pay_money = $total_fee;
- $order->rand_no = $rand_no;
- $order->pay_open_id = $message['openid'];
- $order->self_pay = 1;
- $order->wechat_pay_no = $message['transaction_id'];
- $order->pay_at = $message['time_end'];
- $order->save();
- //店铺信息
- Log::info($message['out_trade_no']);
- Log::info($total_fee);
- $store=Store::where('id',$order->store_id)->lockForUpdate()->first();
- $start_money= $store->pending_amount;
- $store->pending_amount += $total_fee;
- $store->integral += $integral;
- $store->cycle_inte += $integral;
- $store->total += $order->total;
- $store->save();
- //规格销量
- $details=OrderDetailW::where('order_no',$order->order_no)->get();
- foreach($details as $key=>$val){
- $where=[];
- $where['goods_id']=$val->goods_id;
- $where['size']=$val->size;
- $where['type']=$val->type;
- $sku=StoreGoodsSku::where($where)->lockForUpdate()->first();
- $sku->sale_num += $val->num;
- $sku->save();
- //商品销量
- $goods=StoreGoods::where('id',$val->goods_id)->lockForUpdate()->first();
- $goods->sale_num += $val->num;
- $goods->save();
- //减微店代理库存
- $arr_test=Store::getTest();
- if(in_array($order->store_id,$arr_test)){ //判断是不是减库存代理
- Log::info('【'.$store->name.'的店铺-'.$goods->main_attr.'-'.$val->type.'-'.$val->size);
- $storeInventory=InventoryW::where(['store_id'=>$order->store_id,'goods_id'=>$val->goods_id,'sku_id'=>$val->sku_id])->lockForUpdate()->first();
- $storeInve_num=!empty($storeInventory)?$storeInventory->num:0;
- if($val->num > $storeInve_num){
- Log::info('【'.$store->name.'的店铺-'.$goods->main_attr.'-'.$val->type.'-'.$val->size.'】库存不足');
- }
- Log::info($val->num .'---'. $storeInve_num);
- $storeInventory->num-=$val->num;
- $storeInventory->save();
- }
- }
- //用户vip变更
- $vipLog=VipLogW::where('user_id',$order->user_id)
- ->where('store_id',$order->store_id)->first();
- if(empty($vipLog) && $order->total>=2){
- VipLogW::create([
- 'user_id'=>$order->user_id,
- 'store_id'=>$store->id,
- 'order_no'=>$message['out_trade_no'],
- 'type'=>2,//购买两套,添加vip
- 'remark'=>'购买自动添加vip'
- ]);
- OrderW::where('order_no',$message['out_trade_no'])->update([
- 'vip'=>1
- ]);
- }
- //支付日志
- Amount::create([
- 'user_id' => $order->user_id,
- 'store_id' => $order->store_id,
- 'order_no' => $message['out_trade_no'],
- 'transaction_id'=> $message['transaction_id'],
- 'money' => $total_fee,
- 'type' => 1, //支付
- 'status' => 1, //成功
- 'service_fee' => 0,
- 'start_money' => $start_money,
- 'end_money' => $store->pending_amount,
- 'start_amount' => $store->available_amount,//支付前可用金额
- 'end_amount' => $store->available_amount,//支付后可用金额
- 'remark' => '收款',
- ]);
- },5);
- //减库存
- DB::connection('mysql')->transaction(function()use($order) {
- event(new RetailOutboundEvent($order->order_no));
- },5);
- //算争霸赛学分
- // ZbsOrder::create([
- // 'order_id'=>$order->id,
- // 'status'=>0,
- // 'is_cancel'=>0,
- // ]);
- //代下单通知客户
- $user=UserW::where('id',$order->user_id)->first();
- $agent_id=Store::where('id',$order->store_id)->value('user_id');
- $agent = User::where('id',$agent_id)->first();
- if($user->openId){
- $data['openid']=$user->openId;
- $data['data']=[
- 'first' =>'代理【'.$agent->nickname .'】已帮您下单成功,请及时查看订单',
- 'keyword1' => $order->order_no,
- 'keyword2' => number_format($order->account, 2),
- 'keyword3' => $order->op_name,
- 'keyword4' => $agent->mobile,
- 'remark' => '点击链接进入系统,查看详情',
- ];
- event(new HelpOrderEvent($data));
- }
- //代下单通知代理
- //新订单通知
- // $store=Store::where('id',$order->store_id)->first();
- // $user=User::where('id',$store->user_id)->first();
- if($agent->openid){
- $data['openid']=$agent->openid;
- $data['data']=[
- 'first' => '您有新的客户订单,请及时处理',
- 'keyword1' => $user->nickname,
- 'keyword2' => number_format($order->account, 2),
- 'keyword3' => $order->order_no,
- 'keyword4' => $order->created_at
- ];
- event(new NewOrder($data));
- }
- }
- public function GetPay(){
- // 根据返回的订单号查询订单数据
- // $message=['appid' => 'wx5224793b7dc7f7b7',
- // 'bank_type' => 'OTHERS',
- // 'cash_fee' => '153700',
- // 'fee_type' => 'CNY',
- // 'is_subscribe' => 'Y',
- // 'mch_id' => '1603992271',
- // 'nonce_str' => '60628be3521c8',
- // 'openid' => 'ogTajwF_jHXaMTNcXLy1zT_XW-VU',
- // 'out_trade_no' => '2657_DX21033010243392320927494',
- // 'result_code' => 'SUCCESS',
- // 'return_code' => 'SUCCESS',
- // 'sign' => '8CC558CED364CB2384F188EBEF5D3255',
- // 'sub_mch_id' => '1607799110',
- // 'time_end' => '20210330102440',
- // 'total_fee' => '153700',
- // 'trade_type' => 'JSAPI',
- // 'transaction_id' => '4200000896202103308732225144',];
- // Log::error($message);
- Log::error('主动回调');
- $rand_no=explode('_',$message['out_trade_no'])[0];
- $message['out_trade_no']=explode('_',$message['out_trade_no'])[1];
- $order=OrderW::where('order_no',$message['out_trade_no'])->first();
- if (!$order || $order->status == 1) {
- Log::info('订单不存在:'.$message['out_trade_no'].'/'.$message['transaction_id'].'/'.$message['result_code']);
- return true;//订单不存在 或者 订单已支付
- }
- if ($message['result_code'] === 'FAIL') { //支付失败
- Log::warning('[wechat-pay]:' . json_encode($message, true));
- return true;
- }
- if ($message['return_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
- // 支付成功后的业务逻辑
- if($message['result_code'] === 'SUCCESS') {
- $total_fee=round($message['total_fee']/100,2);
- DB::connection('mysql_w')->transaction(function()use($order,$message,$total_fee,$rand_no){
- //修改订单状态
- $order->status = 1;
- $order->is_pay = 1;
- $order->pay_type = 1;
- $order->pay_money = $total_fee;
- $order->rand_no = $rand_no;
- $order->pay_open_id = $message['openid'];
- $order->self_pay = 1;
- $order->wechat_pay_no = $message['transaction_id'];
- $order->pay_at = $message['time_end'];
- $order->save();
- //店铺信息
- $store=Store::where('id',$order->store_id)->lockForUpdate()->first();
- $start_money= $store->pending_amount;
- Log::error($store->pending_amount);
- Log::error($total_fee);
- $store->pending_amount += $total_fee;
- $store->save();
- //规格销量
- $details=OrderDetailW::where('order_no',$order->order_no)->get();
- foreach($details as $key=>$val){
- $where=[];
- $where['goods_id']=$val->goods_id;
- $where['size']=$val->size;
- $where['type']=$val->type;
- $sku=StoreGoodsSku::where($where)->lockForUpdate()->first();
- $sku->sale_num += $val->num;
- $sku->save();
- //商品销量
- $goods=StoreGoods::where('id',$val->goods_id)->lockForUpdate()->first();
- $goods->sale_num += $val->num;
- $goods->save();
- }
- //用户vip变更
- $vipLog=VipLogW::where('user_id',$order->user_id)
- ->where('store_id',$order->store_id)->first();
- /*张奇新增**/
- UserW::where('id',$order->user_id)->update(['is_vip'=>1]);
- if(empty($vipLog) && $order->total>=2){
- VipLogW::create([
- 'user_id'=>$order->user_id,
- 'store_id'=>$store->id,
- 'order_no'=>$message['out_trade_no']
- ]);
- OrderW::where('order_no',$message['out_trade_no'])->update([
- 'vip'=>1
- ]);
- }
- //支付日志
- Amount::create([
- 'user_id' => $order->user_id,
- 'store_id' => $order->store_id,
- 'order_no' => $message['out_trade_no'],
- 'transaction_id'=> $message['transaction_id'],
- 'money' => $total_fee,
- 'type' => 1, //支付
- 'status' => 1, //成功
- 'service_fee' => 0,
- 'start_money' => $start_money,
- 'end_money' => $store->pending_amount,
- 'start_amount' => $store->available_amount,//支付前可用金额
- 'end_amount' => $store->available_amount,//支付后可用金额
- 'remark' => '收款',
- ]);
- },5);
- //减库存
- DB::connection('mysql')->transaction(function()use($order) {
- event(new RetailOutboundEvent($order->order_no));
- },5);
- //代下单通知客户
- $user=UserW::where('id',$order->user_id)->first();
- $agent_id=Store::where('id',$order->store_id)->value('user_id');
- $agent = User::where('id',$agent_id)->first();
- if($user->openId){
- $data['openid']=$user->openId;
- $data['data']=[
- 'first' =>'代理【'.$agent->nickname .'】已帮您下单成功,请及时查看订单',
- 'keyword1' => $order->order_no,
- 'keyword2' => number_format($order->account, 2),
- 'keyword3' => $order->op_name,
- 'keyword4' => $agent->mobile,
- 'remark' => '点击链接进入系统,查看详情',
- ];
- event(new HelpOrderEvent($data));
- }
- //代下单通知代理
- //新订单通知
- // $store=Store::where('id',$order->store_id)->first();
- // $user=User::where('id',$store->user_id)->first();
- if($agent->openid){
- $data['openid']=$agent->openid;
- $data['data']=[
- 'first' => '您有新的客户订单,请及时处理',
- 'keyword1' => $user->nickname,
- 'keyword2' => number_format($order->account, 2),
- 'keyword3' => $order->order_no,
- 'keyword4' => $order->created_at
- ];
- event(new NewOrder($data));
- }
- }
- return true;
- }
- }
- public function getc(){
- $arr=['DD21052507413880022425375','DD21052815445331406169875',
- 'DD21072617031211447413371',
- 'DD21072409242307226852652',
- 'DX21062619411395558884771',
- 'DX21060322150044423898976',
- 'DX21072722274881359336010',
- 'DX21072722054667762245663',
- 'DX21061221143924883861697',
- 'DX21081212124361685786288',
- 'DX21080516405831422592274',
- 'DX21081222191558554151936',
- 'DD21070114344465217624191',
- 'DX21062612370251221614394',
- 'DD21081810585174889697435',
- 'DD21081717423715556697940',
- 'DX21092320373487075958695',
- 'DD21091008310834739743203',
- 'DX21091516461172167273109',
- 'DX21091516485490330788346',
- 'DX21091421560651633921802',
- 'DX21091521223258511559791',
- 'DX21092320335761762613987'];
- $orders=OrderW::with(['store:id,name,phone','user:id,nickname,phone'])
- ->whereIn('order_no',$arr)
- ->select('order_no','status','store_id','user_id','signature','is_finish','express_info','express_time','created_at')
- ->orderBy('store_id')
- ->get();
- return $this->success($orders);
- }
- }
|