redis->get($redisKey); if ($robotInfo === false) { $WeChatService = WeChatService::instance(); // 如果 Redis 连接失败或没有找到机器人信息,从数据库中获取 $robotInfo = $WeChatService->getInfo($token); if($robotInfo && $robotInfo['status'] == 1){ // 将获取到的信息存入 Redis,以便下次快速访问 $this->redis->set($redisKey, json_encode($robotInfo), 3600); } else { return false; } } else { $robotInfo = json_decode($robotInfo, true); } return $robotInfo; } public function Call() { $RobotService = new WeChatBotC($this->app); $data = input(); // if(isset($data['token'])){ // $robotInfo = $this->getRobotInfo($data['token']); // if($robotInfo){ // $this->robotInfo = $robotInfo; // }else{ // return $this->response(['code'=>-1,'msg'=>'机器人不存在']); // } // }else{ // return $this->response(['code'=>-1,'msg'=>'参数错误']); // } # 判断是否为群组 if($data['is_group']){ $roomid = $data['roomid']; if( str_contains($data['xml'],'wxid_9iv1hha8g3ok29')){ if(str_contains($data['content'],' ')){ #判断微信用户中空格,转换成普通空格 $data['content'] = str_replace(' ', ' ', $data['content']); } $merchantService = MerchantService::instance(); $check_merchant = $merchantService->db()->whereLike('other_param', '%'.$roomid.'%')->findOrEmpty(); if($check_merchant){ $ac = $RobotService->get_contacts($data['sender']) ; if(!$ac){ $ac = ''; } if($roomid == '47576792968@chatroom'){ #内部群 if(str_starts_with($data['content'], '@发财-庚辰小秘设置管理 ') ||str_starts_with($data['content'], '@发财-庚辰小秘 设置管理 ') ||($data['content'] == '@发财-庚辰小秘登记管理'||$data['content'] == '@发财-庚辰小秘 登记管理')){ $redis = RedisService::getInstance(); if($data['sender'] !== '25984982683393974@openim' && ($data['content'] == '@发财-庚辰小秘登记管理'||$data['content'] == '@发财-庚辰小秘 登记管理')){ $name = $RobotService->get_contacts($data['sender']); $randomNumber = mt_rand(100000, 999999); $redis->set('wechat_wait_set_manage_'.$randomNumber,$data['sender'],300); return $RobotService->send_text('登记成功,请联系超级管理员输入验证码【 '.$randomNumber.'】设置管理员,验证码五分钟内有效。@'.$name,$data['roomid'],$data['sender']); }elseif(($data['content'] == '@发财-庚辰小秘登记管理'||$data['content'] == '@发财-庚辰小秘 登记管理')){ return $RobotService->send_text('无需登记',$data['roomid'],$data['sender']); }else{ $newString = strstr($data['content'], '设置管理 '); if ($newString) { $newString = substr($newString, strlen('设置管理 ')); }else{ $this->response(['code'=>1]); } $waitManage = $redis->get('wechat_wait_set_manage_'.$newString) ; if(!$waitManage){ return $RobotService->send_text('验证码错误或者超时,请重新获取',$data['roomid'],$data['sender']); } $set = $RobotService->set_manage($waitManage,1) ; if($set == 'fail'){ return $RobotService->send_text('设置管理失败,请重新设置',$data['roomid'],$data['sender']); } if($set == 'ok'){ $acm = $RobotService->get_contacts($waitManage) ; return $RobotService->send_text('设置管理成功,管理员名为:'.$acm,$data['roomid'],$data['sender']); } return $RobotService->send_text('其他提示:'.$set,$data['roomid'],$data['sender']); } } if(str_starts_with($data['content'], '@发财-庚辰小秘设置门禁 ') ||str_starts_with($data['content'], '@发财-庚辰小秘 设置门禁 ') ||($data['content'] == '@发财-庚辰小秘登记门禁'||$data['content'] == '@发财-庚辰小秘 登记门禁')){ $redis = RedisService::getInstance(); if($data['sender'] !== '25984982683393974@openim' && ($data['content'] == '@发财-庚辰小秘登记门禁'||$data['content'] == '@发财-庚辰小秘 登记门禁')){ $name = $RobotService->get_contacts($data['sender']); $randomNumber = mt_rand(100000, 999999); $redis->set('gcdat_wait_set_EntranceGuard_'.$randomNumber,$data['sender'],300); return $RobotService->send_text('登记成功,请联系超级管理员输入验证码【 '.$randomNumber.'】设置门禁,验证码五分钟内有效。@'.$name,$data['roomid'],$data['sender']); }elseif(($data['content'] == '@发财-庚辰小秘设置门禁'||$data['content'] == '@发财-庚辰小秘 设置门禁')){ return $RobotService->send_text('无需登记',$data['roomid'],$data['sender']); }else{ $newString = strstr($data['content'], '设置门禁 '); if ($newString) { $newString = substr($newString, strlen('设置门禁 ')); }else{ $this->response(['code'=>1]); } $waitManage = $redis->get('gcdat_wait_set_EntranceGuard_'.$newString) ; if(!$waitManage){ return $RobotService->send_text('验证码错误或者超时,请重新获取',$data['roomid'],$data['sender']); } $redis->delete('gcdat_wait_set_EntranceGuard_'.$newString); $name = $RobotService->get_contacts($waitManage); if($name){ $get = $redis->get('GCDAT_EntranceGuard_' . $waitManage); if($get){ if($get != $name){ $redis->set('GCDAT_EntranceGuard_' . $waitManage, $name); } return $RobotService->send_text('已经登记过门禁,无法重新设置',$data['roomid'],$data['sender']); } $redis->set('GCDAT_EntranceGuard_' . $waitManage, $name); $RobotService->send_text('登记门禁成功,门禁名为:'.$name,$data['roomid'],$data['sender']); return $RobotService->send_text('欢迎您登记GCDAT门禁系统,您的门禁名为:【'.$name."】\n您以后可以使用【开门】指令进行门禁操作,权限只限于您排班当天,且私聊即可使用,非排班时间请于本群发出【开门】指令。",$data['roomid'],$waitManage); } } return $RobotService->send_text('其他提示:设置失败或者其他错误',$data['roomid'],$data['sender']); } if(str_starts_with($data['content'], '@发财-庚辰小秘通知 ') ||str_starts_with($data['content'], '@发财-庚辰小秘 通知 ')||str_starts_with($data['content'], '@发财-庚辰小秘通知全部 ')){ $newString = strstr($data['content'], '通知全部 '); if ($newString) { $newString = substr($newString, strlen('通知全部 ')); }else{ $newString = strstr($data['content'], '通知 '); if ($newString) { $newString = substr($newString, strlen('通知 ')); }else{ $this->response(['code'=>1]); } } $merchantsList = $merchantService->db()->where(['merchant_type'=>1,'status'=>1])->whereLike('other_param','%Monitor_Balance_status%')->select()->toArray(); if(!$merchantsList)return $this->response(['code'=>1]); $tip_info=[]; $num = 0; foreach ($merchantsList as $merchant){ $other_param = json_decode($merchant['other_param'],true); $roomids = $other_param['QYWX_roomid']; $sender = $other_param['QYWX_sender']; if($roomids == $roomid){ continue; } // $acm = ''; $acm = $RobotService->get_contacts($sender) ; if(!$acm){ $acm = ''; } $RobotService->send_text("通知 \n ".$newString."\n 时间:".date('Y-m-d H:i:s')."\n @".$acm,$roomids,$sender); $tip_info[]=$merchant['name']; $num++; } $merchant_name = implode("\n", $tip_info); return $RobotService->send_text('通知完毕 共通知了'.$num."个商户:\n".$merchant_name.'@'.$ac,$data['roomid'],$data['sender']); } if(str_ends_with($data['content'], '余额') ){ if(str_ends_with($data['content'], '商户余额')){ $merchantsList = $merchantService->db()->where(['status'=>1])->whereLike('other_param','%Monitor_Balance_status%')->select()->toArray(); if(!$merchantsList)return $RobotService->send_text('暂无可查询商户@'.$ac,$data['roomid'],$data['sender']); $tip_info=[]; foreach ($merchantsList as $merchant){ $tip_info[]="商户:[".$merchant['name']."] --【".$merchant['account_surplus'].'】'; } if(!$tip_info)return $RobotService->send_text('暂无可查询商户@'.$ac,$data['roomid'],$data['sender']); $tip_infos = implode("\n", $tip_info); return $RobotService->send_text("商户余额查询完毕:\n".$tip_infos."\n@".$ac,$data['roomid'],$data['sender']); } $channelService = ChannelService::instance(); $channelList = $channelService->db()->where(['status'=>1])->whereLike('other_data','%Monitor_Balance_status%')->select()->toArray(); if(!$channelList)return $RobotService->send_text('暂无可查询渠道@'.$ac,$data['roomid'],$data['sender']); $count_sum= 0; $day = date('Y-m-d', strtotime('-1 day')); $tip_info=[]; foreach($channelList as $channel) { $other_param = json_decode($channel['other_data'], true); if (!$other_param) { continue; } $Monitor_Balance = $other_param['Monitor_Balance'] ?? null; if (!$Monitor_Balance) { continue; } try { $account_data = $channelService->call('account', $channel['id'], $day); if (is_array($account_data) && isset($account_data['account'])) { $balance = $account_data['account']; $tip_info[]='渠道:['.$channel['name']."] \n余额:【".$balance.'】元'; $count_sum++; } }catch (\Exception $e){ } } if(!$tip_info)return $RobotService->send_text('暂无可查询渠道@'.$ac,$data['roomid'],$data['sender']); $errorMsg = implode("\n", $tip_info); return $RobotService->send_text("渠道余额查询完毕,共查询了".$count_sum."个渠道:\n".$errorMsg."\n@".$ac,$data['roomid'],$data['sender']); } if(str_ends_with($data['content'], '成本')){ return $RobotService->send_text("成本报价测试@".$ac,$data['roomid'],$data['sender']); } } if(str_ends_with($data['content'], '余额') || str_ends_with($data['content'],'查余额')){ return $RobotService->send_text("商户[".$check_merchant['name']."] : \n 余额为:".$check_merchant['account_surplus']." @".$ac,$data['roomid'],$data['sender']); } # 拦截处理 if(str_starts_with($data['content'], '@发财-庚辰小秘拦截 1')||str_starts_with($data['content'], '@发财-庚辰小秘 拦截 1')||str_starts_with($data['content'], '@发财-庚辰小秘拦截 GC')||str_starts_with($data['content'], '@发财-庚辰小秘 拦截 GC')){ if(str_contains($data['content'], 'GC')){ #订单号 $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,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']); } } } if(str_starts_with($data['content'], '@发财-庚辰小秘1')||str_starts_with($data['content'], '@发财-庚辰小秘 1')){ $newString = strstr($data['content'], '1'); if (preg_match('/\b1[3-9]\d{9}\b/', $newString)) { // Log::write('Robot', 'wechat', $data); #查询订单 $msg = []; $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']])->select()->toArray(); if(!$order){ $orderLastweekHistoryService = OrderLastweekHistoryService::instance(); $order = $orderLastweekHistoryService->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']])->select()->toArray(); } if(!$order)return $RobotService->send_text("手机号格式正确,但是未找到订单,暂时支持当天和最近一周的订单筛选,更多请前往后台查询 @".$ac,$data['roomid'],$data['sender']); if (count($order) == 1) { $orders = $order[0]; $infos =$orderService->getOrderInfo($orders['cid'],$orders['mid'],$orders['pid']); $msg = [ '系统订单号:' . $orders['order_id'], '产品:' . $infos['p']['name']??'', '商户订单号:' . $orders['merchant_order_id'], '手机号:' . $orders['account'], '订单金额:' . $orders['cash'], '订单状态:' . ($orders['status'] == 2 ? '成功' : ($orders['status'] == 3 ? '失败' : '处理中')), '订单时间:' . $orders['create_at'], ]; if(str_contains($orders['param'], 'mnp_isp_array')){ $param_data = json_decode($orders['param'],true); if($param_data['mnp_isp_array']['old_isp'] == $param_data['mnp_isp_array']['new_isp']){ $msg[] = '携转检测:未携转'; }else{ $msg[] = '携转检测:已携转'; $isp_name = [ 1=>'移动', 2=>'联通', 3=>'电信', ]; $msg[] = '旧运营商:'.$isp_name[$param_data['mnp_isp_array']['old_isp']??0] ?? ''; $msg[] = '新运营商:'.$isp_name[$param_data['mnp_isp_array']['new_isp']??0] ?? ''; } } if(isset($orders['channel_callback_at']) && $orders['channel_callback_at']){ $msg[] = '完成时间:'.$orders['channel_callback_at']; } $m_msg= implode("\n", $msg); return $RobotService->send_text("已为您查询到订单信息:\n".$m_msg." \n@".$ac, $data['roomid'], $data['sender']); } else { return $RobotService->send_text("手机号格式正确,查询到多条订单,暂时只支持单条查询,更多请前往后台查询 @".$ac,$data['roomid'],$data['sender']); // foreach ($order as $singleOrder) { // // 在这里处理每一条订单数据 // // 例如:$RobotService->send_text("订单信息: " . $singleOrder['some_field'], $data['roomid'], $data['sender']); // } } } } if(str_starts_with($data['content'], '@发财-庚辰小秘检测 ')||str_starts_with($data['content'], '@发财-庚辰小秘 检测 ')){ $newString = strstr($data['content'], '1'); if (!preg_match('/\b1[3-9]\d{9}\b/', $newString)) return $RobotService->send_text("暂时只支持手机号码检测,其他请联系管理员 @".$ac,$data['roomid'],$data['sender']); $settingPhoneMNPStatus = sysconf('settingPhoneMNPStatus'); if ($settingPhoneMNPStatus == 1) { $mnp_cid = sysconf('PhoneMnp_cid'); $param = [ 'mobile' => $newString, ]; if ($mnp_cid) { $mnp_array = ChannelService::instance()->call('phone_mnp', $mnp_cid, $param); if (is_array($mnp_array) && isset($mnp_array['new_isp'])) { $msg = [ '手机号:' . $newString, '是否携转:' . ($mnp_array['new_isp'] == $mnp_array['old_isp'] ? '否' : '是'), '旧运营商:' . ($mnp_array['old_isp'] == 1 ? '移动' : ($mnp_array['old_isp'] == 2 ? '联通' : '电信')), '新运营商:' . ($mnp_array['new_isp'] == 1 ? '移动' : ($mnp_array['new_isp'] == 2 ? '联通' : '电信')), ]; $m_msg= implode("\n", $msg); return $RobotService->send_text("已经为您查询到手机号信息:\n".$m_msg." \n@".$ac, $data['roomid'], $data['sender']); } } } $isp = Service::instance()->isp($newString); $msg = [ '手机号:' . $newString, '是否携转:' . '未携转或者无法查询', '运营商:' . ($isp == 1 ? '移动' : ($isp == 2 ? '联通' : '电信')), ]; $m_msg= implode("\n", $msg); return $RobotService->send_text("已经为您查询到手机号信息:\n".$m_msg." \n@", $data['roomid'], $data['sender']); } $need_Manage_list = [ '返销','加款' ]; if(str_starts_with($data['content'], '@发财-庚辰小秘 ')){ $need_content = substr($data['content'], strlen('@发财-庚辰小秘 ')); }elseif(str_starts_with($data['content'], '@发财-庚辰小秘')){ $need_content = substr($data['content'], strlen('@发财-庚辰小秘')); }else{ $need_content = false; } foreach ($need_Manage_list as $need_Manage){ if($need_content && str_starts_with($need_content, $need_Manage)){ $redis = RedisService::getInstance(); $is_manage = $redis->get('Wechat_manage_'.$data['sender']); if(!$is_manage){ return $RobotService->send_text('您没有权限 @'.$ac,$data['roomid'],$data['sender']); } if(str_starts_with($need_content, '返销 GC')){ $order_id = substr($need_content, strlen('返销 ')); $orderService = OrderService::instance(); $order = $orderService->db()->field('id,pid,mid,order_id,merchant_order_id,product_key,account,cash,status,project_id,isp,channel_callback_at,create_at,buy_back')->where(['order_id'=>$order_id,'mid'=>$check_merchant['id']])->findOrEmpty(); if(!$order){ $orderService = OrderLastweekHistoryService::instance(); $order = $orderService->db()->field('id,cid,pid,mid,order_id,merchant_order_id,product_key,account,cash,status,project_id,isp,channel_callback_at,create_at,buy_back')->where(['order_id'=>$order_id,'mid'=>$check_merchant['id']])->findOrEmpty(); if(!$order){ return $RobotService->send_text('订单不存在,或者超过七天,超七天订单需要返销请前往后台手动处理 @'.$ac,$data['roomid'],$data['sender']); } } if($order['status'] != 2){ return $RobotService->send_text('订单状态不是成功,无法返销 @'.$ac,$data['roomid'],$data['sender']); } if(isset($order['buy_back']) && $order['buy_back'] == 1){ return $RobotService->send_text('订单已经返销,无需重复返销 @'.$ac,$data['roomid'],$data['sender']); } $state = MerchantService::instance()->buyBackFrozenAccount($order['id'], $order['order_id'], $order['mid'], $order['pid'], $order['product_key'], $order['cash'], $order['project_id'], $order['account'], $order['isp']); if ($state) { $log['type'] = 'account_fail'; $log['data'] = $order; $log['msg'] = '返销'; $this->log($log); $orderService->db()->where(['order_id'=>$order_id,'mid'=>$check_merchant['id']])->update(['status'=>3,'buy_back'=>1]); $check_merchants = $merchantService->db()->whereLike('other_param', '%'.$roomid.'%')->findOrEmpty(); return $RobotService->send_text("返销成功! \n返销订单:".$order_id."\n商户订单:".$order['merchant_order_id']."\n账号:".$order['account']."\n返销金额:".$state."\n返销后余额:".$check_merchants['account_surplus']."\n@".$ac,$data['roomid'],$data['sender']); } return $RobotService->send_text('返销失败,请后台人工核查 @'.$ac,$data['roomid'],$data['sender']); } if(str_starts_with($need_content, '加款 ')){ #加款格式 金额 备注 $jk_data = explode(' ', $need_content); if($jk_data[0] != '加款'){ return $RobotService->send_text('加款格式错误@'.$ac,$data['roomid'],$data['sender']); } $jk_money = $jk_data[1]; if(!$jk_money || !is_numeric($jk_money)){ return $RobotService->send_text('加款金额错误@'.$ac,$data['roomid'],$data['sender']); } if(!$jk_data[2]){ $desc = '机器人加款,加款人:'.$ac; }else{ $desc = $jk_data[2].',操作人:'.$ac; } if (MerchantLogService::instance()->add($check_merchant['id'], $jk_money, 1,1,$desc) !== false) { sysoplog('修改金额', '加款金额:'.$jk_money.'元,类型为:'. '余额账户'); $check_merchants = $merchantService->db()->where(['id'=>$check_merchant['id']])->findOrEmpty(); return $RobotService->send_text("加款成功! \n加款金额:【".$jk_money."】元 \n加款描述:".$desc."\n加款操作人:".$ac."\n加款时间:".date('Y-m-d H:i:s')."\n加款前余额:".$check_merchant['account_surplus']."\n加款后余额:".$check_merchants['account_surplus']."\n@".$ac,$data['roomid'],$data['sender']); } } return $RobotService->send_text('测试权限设置 @'.$ac,$data['roomid'],$data['sender']); } } return $RobotService->send_text('测试自动回复 @'.$ac,$data['roomid'],$data['sender']); }else{ $ChannelService = ChannelService::instance(); $check_channel = $ChannelService->db()->whereLike('other_data', '%'.$roomid.'%')->findOrEmpty(); 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']); } } } } $this->response(['code'=>1]); }else{ #不为群组 $sender = $data['sender'] ?? null; if(!$sender) return $this->response($data); $redis = RedisService::getInstance(); $is_manage = $redis->get('GCDAT_EntranceGuard_'.$sender); $ac = $RobotService->get_contacts($data['sender']) ; if(!$ac){ $ac = ''; } if($is_manage){ if($data['content'] == '开门'){ $url = 'http://nw.gcdat.com:6001/?command=c1'; $msg = $RobotService->curl('get',$url); if($msg == 'n1f1'){ return $RobotService->send_text('开门成功!时间:'.date('Y-m-d H:i:s').'!欢迎['.$ac.']来到庚辰数据',$data['sender']); }else{ return $RobotService->send_text('开门失败,请后台人工核查 ',$data['sender']); } } } } $this->response($data); } public function channel_logic($roomid,$check_channel,$data) { $RobotService = new WeChatBotC($this->app); $ac = $RobotService->get_contacts($data['sender']) ; if(!$ac){ $ac = ''; } if(str_starts_with($data['content'], '@发财-庚辰小秘检测 ')||str_starts_with($data['content'], '@发财-庚辰小秘 检测 ')){ $newString = strstr($data['content'], '1'); if (!preg_match('/\b1[3-9]\d{9}\b/', $newString)) return $RobotService->send_text("暂时只支持手机号码检测,其他请联系管理员 @".$ac,$data['roomid'],$data['sender']); $settingPhoneMNPStatus = sysconf('settingPhoneMNPStatus'); if ($settingPhoneMNPStatus == 1) { $mnp_cid = sysconf('PhoneMnp_cid'); $param = [ 'mobile' => $newString, ]; if ($mnp_cid) { $mnp_array = ChannelService::instance()->call('phone_mnp', $mnp_cid, $param); if (is_array($mnp_array) && isset($mnp_array['new_isp'])) { $msg = [ '手机号:' . $newString, '是否携转:' . ($mnp_array['new_isp'] == $mnp_array['old_isp'] ? '否' : '是'), '旧运营商:' . ($mnp_array['old_isp'] == 1 ? '移动' : ($mnp_array['old_isp'] == 2 ? '联通' : '电信')), '新运营商:' . ($mnp_array['new_isp'] == 1 ? '移动' : ($mnp_array['new_isp'] == 2 ? '联通' : '电信')), ]; $m_msg= implode("\n", $msg); return $RobotService->send_text("已经为您查询到手机号信息:\n".$m_msg." \n@".$ac, $data['roomid'], $data['sender']); } } } $isp = Service::instance()->isp($newString); $msg = [ '手机号:' . $newString, '是否携转:' . '未携转或者无法查询', '运营商:' . ($isp == 1 ? '移动' : ($isp == 2 ? '联通' : '电信')), ]; $m_msg= implode("\n", $msg); return $RobotService->send_text("已经为您查询到手机号信息:\n".$m_msg." \n@", $data['roomid'], $data['sender']); } return $RobotService->send_text('输入指令有误,或者其他错误! @'.$ac,$data['roomid'],$data['sender']); } public function manage_logic($openid) { } #拦截 public function intercept_order($order_id,$order = []) { if(!$order){ #未传入订单全部信息需要查询订单信息 $order = OrderService::instance()->db()->where(['order_id'=>$order_id])->findOrEmpty(); } if(!$order) return '没有订单信息'; if(in_array($order['status'], [2, 3])){ return '订单已完成,无需拦截或者无法拦截'; } 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 '订单状态异常,请联系管理员'; } } public function response($result) { throw new HttpResponseException(json($result)); } protected function maketime($v): float|false|int|string { if (!$v) { return ''; } if (is_numeric($v)) { return $v; } if (is_array($v)) { $v = $v[1]; } if (strstr($v, ' ')) { $t = explode(' ', $v); $v = $t[0]; $s = explode(':', $t[1]); } else { $s = array(0, 0, 0); } if (!isset($s[1])) { $s[1] = 0; } if (!isset($s[2])) { $s[2] = 0; } if (strstr($v, '-')) { $t = explode('-', $v); } elseif (strstr($v, '/')) { $u = explode('/', $v); $t[0] = $u[2]; $t[1] = $u[0]; $t[2] = $u[1]; } if (!isset($t)) { $t = array(0, 0, 0); } if (!isset($t[1])) { $t[1] = 0; } if (!isset($t[2])) { $t[2] = 0; } return mktime($s[0], $s[1], $s[2], $t[1], $t[2], $t[0]); } }