diff --git a/app/channel/service/system/Lingshi.php b/app/channel/service/system/Lingshi.php new file mode 100644 index 0000000..91ce1f8 --- /dev/null +++ b/app/channel/service/system/Lingshi.php @@ -0,0 +1,207 @@ + 'account', + 'cash'=>'faceValue', + 'isp'=>'isp' + ); + $param['isp'] = 1031; + + + $this->api='api/create/dy'; + $this->sign = array('account', 'appId', 'faceValue', 'notify', 'orderId'); + + return $this->submit($param, $check); + } + + # 通知处理 主要返回状态 2是成功 3是失败 + public function notify($data) + { + $result = array(); + $result['cash'] = 1; + $result['status'] = 4; + #以上基本不要变 + + if(isset($data['query_status'])){ + if ($data['query_status'] == 200) { + $result['status'] = 2; + } else if($data['query_status'] == 500) { + $result['status'] = 3; + }else { + $result['status'] = 4; + } + }else{ + if ($data['code'] == '0') { + $result['status'] = 2; + } else if($data['code'] == 1) { + $result['status'] = 3; + }else { + $result['status'] = 4; + } + } + +// if(isset($data['kami'])&&$data['kami']){ +// $result['kami']=$data['kami']; +// } + + if (isset($data['msg']) && $data['msg']) { + # 流水号 + $data['s_number'] = $result['s_number'] = $data['msg']; + } + $result['yes'] = 'success'; //响应给上游的数据 + + $result['data'] = $data; + + return $result; + } + public function query($order){ +// $request['appId'] = $this->mid; +// $request['orderId'] = $order['channel_order_id']; +// $request['sign'] = $this->_sign($request, ['appId','orderId']); +// $url = $this->host . 'api/order/query'; +// $response = $this->curl('post', $url, $request); +// +// #记录日志 +// $log['type'] = 'query_response'; +// $log['data'] = $response; +// $log['config'] = $this->data; +// $this->log($log); +// #记录借宿 +// +// $array = $this->json_decode($response,true); +// +// $result = array(); +// $result['status'] = 4; +// if ($array['code']=='ok' ) { +// if($array['state'] ==200){ +// $result['query_status'] = 200; +// +// $result['status'] = 2; +// }elseif ($array['state'] == 500){ +// $result['query_status'] = 500; +// $result['status'] = 3; +// } +// +// } +// if(isset($array['data']['cards'])){ +// $result['kami']=array( +// 'cardno' => isset($array['data']['cards'][0]['card_no'])?$array['data']['cards'][0]['card_no']:'', +// 'cardpwd' => $array['data']['cards'][0]['card_password'], +// 'expired' => $array['data']['cards'][0]['expired_at'], +// ); +// } +// return $result; + } + # 数据响应格式处理 + public function response($data) + { + $log['type'] = 'response'; + $log['data'] = $data; + $log['config'] = $this->data; + $this->log($log); + + #以上不要做任何变动 + + + + $array = $this->json_decode($data); //响应数据为json + #如果响应为XML格式 +// $array = (array) simplexml_load_string($data); + + if (!$array) { + $msg = 'error'; + } elseif (isset($array['code']) && $array['code']=='0') { //修改判断逻辑为确定提交成功即可 + # 正确 + $msg = 'ok'; + } else { + # 错误 + $msg = $array['msg'] ?? 'error'; //前面message根据响应内容改成对应的错误提示 + } + + return array + ( + 'msg' => $msg, + 'data' => $data, + 'array' => $array, + ); + } + + # 查询余额接口 + public function account($day) + { + $request['appId'] = $this->mid; + $request['sign'] = $this->_sign($request,['appId']); + $url = $this->host . 'api/balance'; + $response = $this->curl('post', $url, $request,true); + $response = $this->response($response); + + $datas = $response['array']; + if(is_array($datas) && isset($datas['balance']) && $datas['balance'] ){ + $datas['account'] = $datas['balance']; //此处为余额 + } + + return $datas; + } + + + # 提交数据 + private function submit($param, $check) + { + #提交处理 + $param = $this->param($param, $check); + if (is_string($param) || (is_array($param) && $param['status'] == 1)) { + return $param; + } + $request = $param['detail']; //上面替换剩下的 + #结束初步 + + $request['appId']=$this->mid; + + + $request['notify']=$this->getNotify($param['order'], 1); //回调方法默认不用改 + $request['orderId']=$param['order']; //我方系统订单号 + + $request['sign'] = $this->_sign($request, $this->sign); + $url = $this->host . $this->api; //组装地址 + + $response = $this->curl('post', $url, $request,true); //为post请求,json提交 + + + $response = $this->response($response); + $channel_order_id = ''; + #如果出现响应有上游订单号,可以如下 + if (isset($response["array"]['orderId'])) { + $channel_order_id = $response["array"]['orderId']; + } + + $this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']); + return $response['msg']; + } + + private function _sign($request, $param) + { + //ksort($request); + $signature_string = ''; + foreach ($param as $k => $v) { + if (isset($request[$v])) { + $signature_string .= $v . '=' . $request[$v] . '&'; + } + } + $signature_string .= 'key=' . $this->token; + return md5($signature_string); + } +} \ No newline at end of file diff --git a/app/order/controller/Order.php b/app/order/controller/Order.php index 5f9cfe5..f01dff1 100644 --- a/app/order/controller/Order.php +++ b/app/order/controller/Order.php @@ -982,7 +982,7 @@ class Order extends Controller $order = OrderAutoService::instance(); } - $where = ['order_id' => $order_id]; + $where = ['order_id' => $orderInfo['order_id']]; if($channelInfo['suoka_status'] == 1){ diff --git a/app/private_api/controller/robotApi/WeChatBot.php b/app/private_api/controller/robotApi/WeChatBot.php index bc30d00..8e0c969 100644 --- a/app/private_api/controller/robotApi/WeChatBot.php +++ b/app/private_api/controller/robotApi/WeChatBot.php @@ -288,29 +288,45 @@ class WeChatBot extends Core #订单号 $newString = strstr($data['content'], 'G'); $order_id = strstr($newString, 'G'); + + $intercept_msg = $this->intercept_order($order_id); + + return $RobotService->send_text($intercept_msg."\n@".$ac,$data['roomid'],$data['sender']); + }else{ $newString = strstr($data['content'], '1'); if (preg_match('/\b1[3-9]\d{9}\b/', $newString)) { $orderService = OrderService::instance(); - $order = $orderService->db()->field('cid,pid,mid,order_id,merchant_order_id,param,account,cash,status,channel_callback_at,create_at')->where(['account'=>$newString,'mid'=>$check_merchant['id']])->whereNotIn('status', '2,3')->select()->toArray(); + $order = $orderService->db()->field('cid,pid,mid,order_id,merchant_order_id,param,account,cash,status,apply_refund,channel_callback_at,create_at')->where(['account'=>$newString,'mid'=>$check_merchant['id']])->whereNotIn('status', '2,3')->select()->toArray(); if(!$order){ return $RobotService->send_text("您输入的手机号暂无找到可拦截订单,请核对手机号或者是否有已经充值成功或失败 @".$ac,$data['roomid'],$data['sender']); } + $tip_info = []; + $num = 0; + foreach ($order as $k => $v){ + $order_id = $v['order_id']; + $intercept_msg = $this->intercept_order($order_id,$v); + $tip_info[]="订单号:".$order_id.':'.$intercept_msg; + $num++; + } + $msg = implode("\n", $tip_info); + return $RobotService->send_text("手机号: ".$newString."\n查询到".$num."订单,处理结果:\n".$msg."\n@".$ac,$data['roomid'],$data['sender']); + + + + }else{ + return $RobotService->send_text("您输入的手机号格式错误,请重新核对格式 @".$ac,$data['roomid'],$data['sender']); } } + + } - -// $content_array = explode(' ', $data['content']); - - - - if(str_starts_with($data['content'], '@发财-庚辰小秘1')||str_starts_with($data['content'], '@发财-庚辰小秘 1')){ $newString = strstr($data['content'], '1'); @@ -422,12 +438,6 @@ class WeChatBot extends Core '返销','加款' ]; - - - - - - if(str_starts_with($data['content'], '@发财-庚辰小秘 ')){ $need_content = substr($data['content'], strlen('@发财-庚辰小秘 ')); }elseif(str_starts_with($data['content'], '@发财-庚辰小秘')){ @@ -523,6 +533,29 @@ class WeChatBot extends Core if($check_channel){ return $this->channel_logic($roomid, $check_channel, $data); } + + #其他初始化设置 + if($data['sender'] == '25984982683393974@openim'){ + #设置渠道 + if(str_starts_with($data['content'], '@发财-庚辰小秘设置渠道 ')||str_starts_with($data['content'], '@发财-庚辰小秘 设置渠道 ')){ + + #渠道id + $newString = strstr($data['content'], '渠道 '); + $cid = substr($newString, strlen("渠道 ")); + #查找渠道 + $channel_info = $ChannelService->db()->where(['id'=>$cid])->findOrEmpty(); + if(!$channel_info)return $RobotService->send_text('渠道不存在!请重新核对',$data['roomid'],$data['sender']); + + $array = json_decode($channel_info['other_data'],true); + if($channel_info['other_data'] && !is_array($array))return $RobotService->send_text('渠道数据格式错误!请重新核对',$data['roomid'],$data['sender']); + if(!is_array($array))$array = []; + $array['QYWX_roomid'] = $roomid; + $up = $ChannelService->db()->where(['id'=>$cid])->update(['other_data'=>json_encode($array)]); + return $RobotService->send_text('设置成功!渠道名称:'.$channel_info['name'].',渠道id:'.$channel_info['id'].',设置时间:'.date('Y-m-d H:i:s').'!',$data['roomid'],$data['sender']); + } + + } + } } @@ -548,7 +581,7 @@ class WeChatBot extends Core if($msg == 'n1f1'){ - return $RobotService->send_text('开门成功!欢迎来到庚辰数据',$data['sender']); + return $RobotService->send_text('开门成功!时间:'.date('Y-m-d H:i:s').'!欢迎['.$ac.']来到庚辰数据',$data['sender']); }else{ return $RobotService->send_text('开门失败,请后台人工核查 ',$data['sender']); } @@ -633,7 +666,6 @@ class WeChatBot extends Core { if(!$order){ #未传入订单全部信息需要查询订单信息 - $order = OrderService::instance()->db()->where(['order_id'=>$order_id])->findOrEmpty(); } @@ -645,7 +677,40 @@ class WeChatBot extends Core } if($order['status'] == 4){ - #判断 + #判断渠道 + #登记订单状态拦截 apply_refund ==1 + #TODO 待优化,本次未进行自动化拦截,仅支持微信消息推送。 + if($order['apply_refund'] !=0){ + if($order['apply_refund'] == 2)return '订单拦截成功,请核实订单状态'; + if($order['apply_refund'] == 3)return '订单拦截失败,请核实订单状态'; + #待优化,后续可以使用redis记录用户催促数据,着急的可以使用定时任务或者队列反复提醒 + return '订单正在拦截中,请耐心等待'; + } + $orderService = OrderService::instance(); + $upApply_refund = $orderService->db()->where(['order_id'=>$order_id])->update(['apply_refund'=>1]); + if(!$upApply_refund)return '拦截订单登记失败,请联系管理员'; + #发送拦截信息给对应的渠道 + $channel_id = $order['cid']; + $channel_info = ChannelService::instance()->get($channel_id); + $json = $channel_info['other_data']??''; + $array = json_decode($json, true); + if(!$array || !is_array($array) || !isset($array['QYWX_roomid']))return '已登记拦截订单,请核实拦截消息'; + $WX_Group = $array['QYWX_roomid']; + $intercept_msg = '我方订单号:'.$order_id."\n手机号:".$order['account'].",\n需要催促拦截处理,请尽快核实订单状态"; + $RobotService = new WeChatBotC($this->app); + #待优化 未做消息查询判断 + $send = $RobotService->send_text($intercept_msg, $WX_Group, ''); + return '已登记拦截订单,并尝试拦截中,请耐心等待'; + + }elseif($order['status'] == 1 || $order['status'] == -4 || $order['status'] == -5){ + $orderService = OrderService::instance(); + $upApply_refund = $orderService->db()->where(['order_id'=>$order_id])->update(['apply_refund'=>2,'status'=>3]); + if(!$upApply_refund)return '拦截订单登记失败,请联系管理员'; + return '订单拦截成功,请核实订单状态'; + }else{ + $orderService = OrderService::instance(); + $upApply_refund = $orderService->db()->where(['order_id'=>$order_id])->update(['apply_refund'=>1]); + return '订单状态异常,请联系管理员'; } diff --git a/app/queue/command/kami91order/KamiOrderChanelNotify.php b/app/queue/command/kami91order/KamiOrderChanelNotify.php index 94b5848..41437c1 100644 --- a/app/queue/command/kami91order/KamiOrderChanelNotify.php +++ b/app/queue/command/kami91order/KamiOrderChanelNotify.php @@ -163,7 +163,7 @@ class KamiOrderChanelNotify extends Command try{ $redis = RedisService::getInstance(); $redis_key = 'mSD_query'.$info['merchant_order_id']; - $getRedisData = $redis->set($redis_key,[1,time()],600); + $getRedisData = $redis->set($redis_key,time(),600); #设置查询时间 }catch (\Exception $e){ @@ -233,28 +233,15 @@ class KamiOrderChanelNotify extends Command $redis_key = 'mSD_query'.$info['merchant_order_id']; $getRedisData = $redis->get($redis_key); if($getRedisData){ - $num = $getRedisData[0]; - $time = $getRedisData[1]; - if(time() - $time < 10){ + $times = time() - $getRedisData; + if($times < 10){ $check = $maSuDa->queryFaka($info['merchant_order_id'],$uid,$secretKey); - $num++; - $redis->set($redis_key,[ - $num, - $time - ],600); if ($check == 'ok') { $kami91server->db()->where(['order_id' => $vo['order_id']])->update(['status' => 2]); $maSuDa->huidiao($vo['order_id']); } }else{ - $num++; - $redis->set($redis_key,[ - $num, - $time - ],600); - - #num 可以被10整除则发送消息 - if($num % 10 == 0){ + $redis->set($redis_key,time(),600); $up_msg = $maSuDa->notify($info['notifyurl'], $param,$getMerchantInfo); if($up_msg == 'success'){ $kami91server->upStatus($vo['order_id'], 6, $up_msg); @@ -265,14 +252,7 @@ class KamiOrderChanelNotify extends Command $maSuDa->huidiao($vo['order_id']); } } - }else{ - $check = $maSuDa->queryFaka($info['merchant_order_id'],$uid,$secretKey); - if ($check == 'ok') { - $redis->delete($redis_key); - $kami91server->db()->where(['order_id' => $vo['order_id']])->update(['status' => 2]); - $maSuDa->huidiao($vo['order_id']); - } - } + } }