3829 lines
178 KiB
PHP
3829 lines
178 KiB
PHP
<?php
|
||
|
||
namespace app\index\controller\wms;
|
||
use app\index\controller\wms\Wms;
|
||
use app\common\controller\Frontend;
|
||
use addons\shopro\library\Wechat as WechatLibrary;
|
||
use think\Db;
|
||
use think\db\exception\BindParamException;
|
||
use think\db\exception\DataNotFoundException;
|
||
use think\db\exception\ModelNotFoundException;
|
||
use think\exception\DbException;
|
||
use think\exception\PDOException;
|
||
use app\index\library\Wsdl;
|
||
use app\common\model\UserRule;
|
||
use think\Config;
|
||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||
use think\Log;
|
||
use app\index\library\zopsdk\ZopClient;
|
||
use app\index\library\zopsdk\ZopProperties;
|
||
use app\index\library\zopsdk\ZopRequest;
|
||
use app\index\controller\wms\Wms as WmsController;
|
||
use fast\Http;
|
||
use fast\Random;
|
||
use app\index\library\chat\Forward;
|
||
class Chat extends Frontend
|
||
{
|
||
protected $noNeedLogin = 'OnMessage,OnMessage2,Message,Notify,Notify5,trace_test,tihuotest,Notify2,Notify3,kdroomMessageExplpde2,test,checkOnline,getAllWechatRooms,noticeConfirmApplyStorage';
|
||
protected $noNeedRight = 'OnMessage,OnMessage2,Message,Notify,Notify5,trace_test,tihuotest,Notify2,Notify3,kdroomMessageExplpde2,getStores,test,query_stock,order_push,save_and_push,cancel_order,change_order,checkOnline,getAllWechatRooms,get_express_ecnotes,noticeConfirmApplyStorage,get_interior_rooms,get_all_rooms,get_group_messages,send_group_message';
|
||
protected $layout = '';
|
||
public function _initialize()
|
||
{
|
||
parent::_initialize();
|
||
$this->OrderModel = new \app\common\model\wms\Order;
|
||
$this->OrderModel1 = new \app\common\model\wms\Order1;
|
||
$this->PostrelayModel = new \app\common\model\Postrelay;
|
||
$this->ExpressModel = new \app\common\model\wms\Express;
|
||
$this->DeliveryorderModel = new \app\common\model\wms\Deliveryorder;
|
||
$this->DeliveryorderModel1 = new \app\common\model\wms\Deliveryorder1;
|
||
$this->RoomsModel = new \app\common\model\Rooms;
|
||
$this->qiweLogModel = new \app\common\model\qiwe\chat\Log;
|
||
|
||
|
||
$this->qiweRoomsModel = new \app\common\model\qiwe\Rooms();
|
||
|
||
|
||
$this->RoomsExcludeModel = new \app\common\model\rooms\Exclude;
|
||
$this->Exceptionwmsorder = new \app\common\model\wms\Exceptionwmsorder;
|
||
$this->ChatLogModel = new \app\common\model\chat\Log;
|
||
$this->SkuModel = new \app\common\model\wms\Stock;
|
||
$this->StorageModel = new \app\common\model\wms\Storage;
|
||
$this->StoreModel = new \app\common\model\wms\Warestore;
|
||
$this->chatMethodsModel = new \app\common\model\chat\Methods;
|
||
$this->FailorderModel= new \app\common\model\Failorder;
|
||
$this->Worksmodel = new \app\common\model\workers\Works;
|
||
$this->ExpressconfigModel = new \app\common\model\wms\Expressconfig;
|
||
$this->redis = new \Redis();
|
||
$this->redis->connect('127.0.0.1', 6379);
|
||
$this->redis->auth('qwe2019@');
|
||
$this->redis->select(3);
|
||
$this->redis2 = new \Redis();
|
||
$this->redis2->connect('127.0.0.1', 6379);
|
||
$this->redis2->auth('qwe2019@');
|
||
$this->redis2->select(4);
|
||
//尝试获取请求头,看是否携带Source参数,区分来源
|
||
try {
|
||
$Source = $this->request->header('source');
|
||
if ($Source) {
|
||
$this->SOURCE = $Source;
|
||
} else {
|
||
$this->SOURCE = "wx"; //默认来源
|
||
}
|
||
} catch (Exception $e) {
|
||
$this->SOURCE = "wx"; //获取请求头失败,默认来源
|
||
}
|
||
$this->wechats = [[
|
||
"wechatServer"=>"42.194.235.215:8203",
|
||
"key"=>"8DE6CAD0E48D4DF84CF0593AD01DB62FE89D137B"
|
||
]
|
||
];
|
||
}
|
||
public function qiweOnMessage($logData,$myid){
|
||
\think\Log::error('在Chat模块处理: '.json_encode($logData));
|
||
$this->redis->set("message",json_encode($logData));
|
||
$pid = $logData["guid"];
|
||
$messageData = [
|
||
"method"=>"newmsg",
|
||
"myid"=>$myid,
|
||
"pid"=>$pid,
|
||
"type"=>1,
|
||
"data"=>[
|
||
"memid"=>$logData["sender_id"],
|
||
"nickName2"=>$logData["contact_info"]["real_name"]??"未知用户名", //发信人群昵称
|
||
"memname"=>$logData["contact_info"]["nickname"]??"未知用户名", //发信人名
|
||
"nickName"=>$logData["room_info"]["room_name"]??"未知群名",//群名
|
||
"id"=> $logData["msg_unique_identifier"],//消息id
|
||
"fromid"=>$logData["from_room_id"],//群id
|
||
"msg"=>$logData["content"],
|
||
]
|
||
];
|
||
$this->SOURCE = "qiwe";
|
||
$result = $this->MessageHandle($messageData,false);
|
||
\think\Log::error('处理结果: '.json_encode($result));
|
||
return $result;
|
||
}
|
||
public function OnMessage() {
|
||
$jsonData = file_get_contents('php://input');
|
||
$messageData=json_decode($jsonData,true);
|
||
$this->SOURCE = "wx";
|
||
return $this->MessageHandle($messageData);
|
||
}
|
||
//统一消息入口
|
||
private function MessageHandle($messageData, $isParse = true)
|
||
{
|
||
$msgId = $messageData['data']['id'];
|
||
$fromId = $messageData['data']['fromid'];
|
||
$msgContent = $messageData['data']['msg'];
|
||
Log::error("msgId".$msgId);
|
||
// 生成唯一锁键
|
||
$lockKey = "wxmsg:lock:{$msgId}";
|
||
$processedKey = "wxmsg:processed:{$msgId}";
|
||
|
||
// 第一层:快速检查是否已处理
|
||
if ($this->redis->get($processedKey)) {
|
||
return $this->buildResponse(['status' => 'ignored', 'reason' => 'duplicate'], $isParse);
|
||
}
|
||
|
||
// 第二层:获取分布式锁
|
||
$lockAcquired = $this->redis->set($lockKey, 1, ['NX', 'EX' => 15]);
|
||
if (!$lockAcquired) {
|
||
// 等待一下再检查是否已处理
|
||
usleep(100000); // 100ms
|
||
|
||
if ($this->redis->get($processedKey)) {
|
||
return $this->buildResponse(['status' => 'ignored', 'reason' => 'duplicate_after_wait'], $isParse);
|
||
}
|
||
|
||
return $this->buildResponse(['status' => 'ignored', 'reason' => 'processing_by_other'], $isParse);
|
||
}
|
||
|
||
try {
|
||
// 第三层:双重检查
|
||
if ($this->redis->get($processedKey)) {
|
||
return $this->buildResponse(['status' => 'ignored', 'reason' => 'duplicate_double_check'], $isParse);
|
||
}
|
||
|
||
// 处理消息业务逻辑
|
||
$result = $this->processMessage($messageData);
|
||
Log::error("返回信息".json_encode($result));
|
||
// 标记为已处理,有效期1小时
|
||
$this->redis->setex($processedKey, 3600, 1);
|
||
|
||
return $this->buildResponse($result, $isParse);
|
||
|
||
} catch (Exception $e) {
|
||
// 发生异常时释放锁,允许重试
|
||
$this->redis->del($lockKey);
|
||
throw $e;
|
||
} finally {
|
||
// 最终释放锁
|
||
$this->redis->del($lockKey);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 构建响应数据
|
||
* @param mixed $data 响应数据
|
||
* @param bool $isParse 是否返回JSON格式
|
||
* @return mixed
|
||
*/
|
||
private function buildResponse($data, $isParse)
|
||
{
|
||
if ($isParse) {
|
||
return json($data);
|
||
}
|
||
return $data;
|
||
}
|
||
public function postcode(){
|
||
if ($this->request->isPost()){
|
||
$params=$this->request->post();
|
||
$ParacodeModel = new \app\common\model\wms\Paracode;
|
||
$postCodeRows = $ParacodeModel->where(["TYPE"=>301])->select();
|
||
return json($postCodeRows);}
|
||
}
|
||
public function checkOnline(){
|
||
$infos = [];
|
||
foreach ($this->wechats as $wechat) {
|
||
$info = $this->ext_query(["method" => "list"], $wechat);
|
||
if($info){
|
||
$infoWithWechat = array_map(function($item) use ($wechat) {
|
||
$item['wechat_info'] = $wechat;
|
||
return $item;
|
||
}, $info);
|
||
$infos = array_merge($infos, $infoWithWechat);
|
||
}
|
||
}
|
||
|
||
$wxids = $this->getKeysByPattern($this->redis, 'wxid:*');
|
||
|
||
// 创建在线wxid的映射表,提高查找效率
|
||
$onlineWxidsMap = array();
|
||
foreach ($infos as $info) {
|
||
if ($info["isLogin"] == 1) {
|
||
$wxidKey = "wxid:" . $info['wxid'];
|
||
$onlineWxidsMap[$wxidKey] = $info;
|
||
}
|
||
}
|
||
|
||
// 处理所有wxid
|
||
foreach ($wxids as $wxid) {
|
||
$data = $this->redis->get($wxid);
|
||
$arr = explode(",", $data);
|
||
|
||
if (isset($onlineWxidsMap[$wxid])) {
|
||
$info = $onlineWxidsMap[$wxid];
|
||
$arr[1] = $info['pid']; // 在线的更新pid
|
||
$arr[2] = isset($info['wechat_info']['wechatServer']) ? $info['wechat_info']['wechatServer'] : '';
|
||
$arr[3] = isset($info['wechat_info']['key']) ? $info['wechat_info']['key'] : '';
|
||
} else {
|
||
$arr[1] = 0; // 不在线的pid设为0
|
||
}
|
||
|
||
$this->redis->set($wxid, implode(",", $arr));
|
||
}
|
||
|
||
// 获取并输出所有缓存数据
|
||
$allCacheData = array();
|
||
foreach ($wxids as $wxid) {
|
||
$allCacheData[$wxid] = $this->redis->get($wxid);
|
||
}
|
||
|
||
return json(array(
|
||
'online_infos' => $infos,
|
||
'all_cache_data' => $allCacheData
|
||
));
|
||
}
|
||
public function getAllWechatRooms(){
|
||
$onlineWechats = $this->getOnlineWechats();
|
||
// 这里可以继续处理获取微信群聊的逻辑
|
||
$rooms_arr = [];
|
||
foreach ($onlineWechats as $wechat){
|
||
$rooms = $this->getAllRooms(["wechatServer"=>$wechat["server"],"key"=>$wechat["key"]],$wechat['pid']);
|
||
array_push($rooms_arr,["wechat"=>$wechat,"room"=>$rooms]);
|
||
}
|
||
return json($rooms_arr);
|
||
}
|
||
|
||
private function getOnlineWechats(){
|
||
$wxids = $this->getKeysByPattern($this->redis, 'wxid:*');
|
||
|
||
$onlineWechats = [];
|
||
foreach ($wxids as $wxid) {
|
||
$data = $this->redis->get($wxid);
|
||
$parts = explode(',', $data);
|
||
|
||
$onlineWechats[$wxid] = [
|
||
'raw_data' => $data,
|
||
'wxid' => str_replace('wxid:', '', $wxid),
|
||
'warehouseId'=>intval($parts[0]) ?? 0,
|
||
'pid' => intval($parts[1]) ?? 0,
|
||
'server' => $parts[2] ?? '',
|
||
'key' => $parts[3] ?? '',
|
||
'is_online' => ($parts[1] ?? 0) != 0
|
||
];
|
||
}
|
||
|
||
return $onlineWechats;
|
||
}
|
||
private function getKeysByPattern($redis, $pattern) {
|
||
$keys = [];
|
||
$iterator = null;
|
||
|
||
do {
|
||
// SCAN 命令,每次迭代获取一部分键
|
||
$result = $redis->scan($iterator, $pattern, 100);
|
||
if ($result !== false) {
|
||
$keys = array_merge($keys, $result);
|
||
}
|
||
} while ($iterator > 0);
|
||
|
||
return $keys;
|
||
}
|
||
private function ext_query($params,$wechat){
|
||
$header = [
|
||
'Content-Type: application/x-www-form-urlencoded; charset=UTF-8'
|
||
];
|
||
$options = [
|
||
CURLOPT_HTTPHEADER => $header
|
||
];
|
||
$urlEncodedString = http_build_query($params);
|
||
$url = "http://{$wechat['wechatServer']}/api?json&key={$wechat['key']}";
|
||
$res = Http::sendRequest($url,$urlEncodedString,'POST',$options);
|
||
return json_decode($res["msg"],true)["data"];
|
||
}
|
||
public function Notify($value){
|
||
$type = intval($this->request->get('type'));
|
||
$WAREHOUSEID = intval($this->request->get('WAREHOUSEID'));
|
||
$text = $this->request->get('text');
|
||
switch($type){
|
||
case 1:
|
||
$rooms = $this->RoomsModel->where(["type"=>1,"WAREHOUSEID"=>$WAREHOUSEID])->select();
|
||
$redis = new \Redis();
|
||
$redis->connect('127.0.0.1', 6379);
|
||
$redis->auth('qwe2019@');
|
||
$redis->select(2);
|
||
foreach ($rooms as $room){
|
||
$msg = $this->to($room["room_id"],$text);
|
||
$redis->lpush("Message",json_encode($msg));
|
||
}
|
||
$redis->close();
|
||
break;
|
||
case 2:
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
/*public function Notify3(){
|
||
$text = "https://ye4s.wms.gztbyc.com/1.pdf";
|
||
$this->Notify4(1,5400,$text);
|
||
|
||
}*/
|
||
public function Notify3(){
|
||
$text = "重要通知\n明日(2月17日)仓库这边放假一天,白天无人值班,有特殊情况需要急出单号的统一晚上处理哦,出单号的订单于2月18日操作打包发货。";
|
||
$res = $this->Notify2(1,5400,$text);
|
||
return $res;
|
||
}
|
||
public function Notify4($type=1,$WAREHOUSEID=5400,$text="",$msgType = "text"){
|
||
$fi = [60600];
|
||
switch($type){
|
||
case 1:
|
||
$rooms = $this->RoomsModel->where(["type"=>1,"WAREHOUSEID"=>$WAREHOUSEID])->where("STOREID","not in",$fi)->select();
|
||
$redis = new \Redis();
|
||
$redis->connect('127.0.0.1', 6379);
|
||
$redis->auth('qwe2019@');
|
||
$redis->select(2);
|
||
foreach ($rooms as $room){
|
||
$msg = $this->backFile(["fromid"=>$room['room_id']],$text);
|
||
$redis->lpush("Message",json_encode($msg));
|
||
}
|
||
$redis->close();
|
||
break;
|
||
case 2:
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
/*public function Notify5($type=1,$WAREHOUSEID=5400,$text="https://ye4s.wms.gztbyc.com/msg/1.png"){
|
||
$fi = [60600];
|
||
switch($type){
|
||
case 1:
|
||
$rooms = $this->RoomsModel->where(["type"=>1,"WAREHOUSEID"=>$WAREHOUSEID])->where("STOREID","not in",$fi)->select();
|
||
$redis = new \Redis();
|
||
$redis->connect('127.0.0.1', 6379);
|
||
$redis->auth('qwe2019@');
|
||
$redis->select(2);
|
||
foreach ($rooms as $room){
|
||
$msg = $this->backImg($room['room_id'],$text);
|
||
$redis->lpush("Message",json_encode($msg));
|
||
}
|
||
$redis->close();
|
||
break;
|
||
case 2:
|
||
default:
|
||
break;
|
||
}
|
||
$this->Notify2(1,5400,"关于仓库入仓来货停止收货通知\n\n 尊敬的客户:\n感谢您一直以来对我们的支持和信任。临近春节为了保障春节期间的服务质量,我司根据实际情况现调整仓库入仓到货收货时间,仓库停止收货时间为:2026年2月10日至2026年2月23日(农历年二十三至正月初七),2月24日(年初八)仓库恢复正常收货,另春节期间仓库不操作大批量备货出库自提等操作,如有特殊情况请提前通知(如为保障春节期间发货小批量到货的可安排),仓库根据实际情况安排(收货组联系电话:18665616691/18212332570),请谅解!\n\n 顺祝商祺\n 2026年2月8日 \n 广州天豹云仓");
|
||
}*/
|
||
public function Notify2($type=1,$WAREHOUSEID=5400,$text=""){
|
||
switch($type){
|
||
case 1:
|
||
$rooms = $this->RoomsModel->where(["type"=>1,"WAREHOUSEID"=>$WAREHOUSEID])->select();
|
||
$redis = new \Redis();
|
||
$redis->connect('127.0.0.1', 6379);
|
||
$redis->auth('qwe2019@');
|
||
$redis->select(2);
|
||
foreach ($rooms as $room){
|
||
$msg = $this->to($room["room_id"],htmlspecialchars_decode($text));
|
||
$redis->lpush("Message",json_encode($msg));
|
||
}
|
||
$redis->close();
|
||
break;
|
||
case 2:
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
private function getMyInfoAndUpdate($myid, $pid) {
|
||
$wxidKey = "wxid:{$myid}";
|
||
$data = $this->redis->get($wxidKey);
|
||
|
||
$parts = $data ? explode(',', $data) : [0, 0, '', ''];
|
||
|
||
// 确保数组有足够的元素
|
||
$parts = array_pad($parts, 4, '');
|
||
|
||
if ($pid != $parts[1]) {
|
||
$parts[1] = (string)$pid;
|
||
$newData = implode(',', $parts);
|
||
$this->redis->set($wxidKey, $newData);
|
||
$data = $newData;
|
||
}
|
||
|
||
return [
|
||
'raw_data' => $data,
|
||
'wxid' => $myid,
|
||
'warehouseId' => intval($parts[0]),
|
||
'pid' => (int)$pid,
|
||
'server' => $parts[2],
|
||
'key' => $parts[3],
|
||
'is_online' => true
|
||
];
|
||
}
|
||
private function processMessage($params){
|
||
$info = "";
|
||
$roomtype=0;//群聊类型:0非群聊,1:货主群聊,2:内部群聊,3:快递群聊
|
||
$rules = [//货主类型群聊回复规则
|
||
["key"=>"取消拦截","func"=>"quxiaolanjie","tip"=>"如需取消拦截运单号,发送:取消拦截+快递号(多个使用任意分隔符)\n例:取消拦截7xxxx1,7xxxx2"],
|
||
["key"=>"取消采集订单","func"=>"cancelRoomOrder"],
|
||
["key"=>"拦截","func"=>"lanjie"],
|
||
["key"=>"建单","func"=>"createOrder"],
|
||
["key"=>"揽收","func"=>"lanshou"],
|
||
["key"=>"help|指令","func"=>"help"],
|
||
["key"=>"少发|发少","func"=>"less"],
|
||
["key"=>"重量|查重|核实重量|核重","func"=>"weight"],
|
||
["key"=>"错发|发错","func"=>"wrong"],
|
||
["key"=>"破损|坏了","func"=>"damaged"],
|
||
["key"=>"多发|发多","func"=>"multiple"],
|
||
["key"=>"查运费","func"=>"getPrict"],
|
||
["key"=>"改地址|改电话|改联系人|改收件人|地址更改|改手机|催退回|尽快安排派送|催促退回","func"=>"changeAddr"],
|
||
["key"=>"催件|催派|催促|未中转|物流停滞","func"=>"urgent"],
|
||
["key"=>"查退回|是否已退回","func"=>"Backrecord"],
|
||
["key"=>"退回|拒收","func"=>"backfunction"],
|
||
["key"=>"核实签收|未收到|是否发出|是否已经发货|核实|没有找到快递","func"=>"weishoudao"],
|
||
["key"=>"查库存","func"=>"kucun"],
|
||
["key"=>"轨迹|查物流|物流信息|查快递","func"=>"trace"],
|
||
["key"=>"出单|打单|打印单|催发货|分配快递号","func"=>"createPostnum"],
|
||
["key"=>"改圆通","func"=>"changep01"],
|
||
["key"=>"改中通","func"=>"changep04"],
|
||
["key"=>"改申通","func"=>"changep02"],
|
||
["key"=>"改极兔速递","func"=>"changep32"],
|
||
["key"=>"改韵达","func"=>"changep03"],
|
||
["key"=>"改顺丰","func"=>"changep05"],
|
||
["key"=>"改邮政小包","func"=>"changep22"],
|
||
["key"=>"改EMS","func"=>"changep07"],
|
||
["key"=>"改京东快递","func"=>"changep10"],
|
||
["key"=>"仓库地址","func"=>"myaddr"],
|
||
["key"=>"提货","func"=>"tihuo"],
|
||
["key"=>"打包视频","func"=>"dabaoVideo"],
|
||
["key"=>"到货|拉货|到访","func"=>"daohuo"],
|
||
["key"=>"好|OK|1|收到|谢谢|感谢|好了|可以|行了|对啊|是的","func"=>"nothing"]
|
||
];
|
||
$rules2 = [//内部类型群聊回复规则
|
||
["key"=>"取消拦截","func"=>"quxiaolanjie"],
|
||
["key"=>"拦截","func"=>"lanjie"],
|
||
["key"=>"揽收","func"=>"lanshou"],
|
||
["key"=>"help|查询指令","func"=>"help"],
|
||
["key"=>"快递号数据查询","func"=>"findPostnum"],
|
||
["key"=>"催件|催派|催促|未中转|物流停滞","func"=>"urgent"],
|
||
["key"=>"改地址|改电话|改联系人|改收件人|地址更改","func"=>"changeAddr"],
|
||
["key"=>"查退回2|是否已退回2","func"=>"Backrecord"],
|
||
["key"=>"查退回|是否已退回","func"=>"yituihui"],
|
||
["key"=>"退回","func"=>"backfunction"],
|
||
["key"=>"查询库存","func"=>"exportStorage"],
|
||
["key"=>"退件登记录入","func"=>"createBackRecordByPostnum"],
|
||
["key"=>"test","func"=>"test"],
|
||
["key"=>"奇门入库单号|一键上架","func"=>"fastruku"],
|
||
["key"=>"轨迹|查物流|物流信息|查快递","func"=>"trace"],
|
||
["key"=>"设置","func"=>"setting"],
|
||
["key"=>"中通重量","func"=>"getWeightForCustomer"],
|
||
["key"=>"错发","func"=>"wrong"],
|
||
["key"=>"重量|查重","func"=>"weight"],
|
||
["key"=>"出单|打单|打印单|催发货|分配快递号","func"=>"createPostnum"],
|
||
["key"=>"非批次错误","func"=>"clearFail"],
|
||
["key"=>"查运费","func"=>"carriage"],
|
||
["key"=>"改圆通","func"=>"changep01"],
|
||
["key"=>"改中通","func"=>"changep04"],
|
||
["key"=>"改申通","func"=>"changep02"],
|
||
["key"=>"改极兔速递","func"=>"changep32"],
|
||
["key"=>"改韵达","func"=>"changep03"],
|
||
["key"=>"改顺丰","func"=>"changep05"],
|
||
["key"=>"改邮政小包","func"=>"changep22"],
|
||
["key"=>"改EMS","func"=>"changep07"],
|
||
["key"=>"改京东快递","func"=>"changep10"],
|
||
["key"=>"查","func"=>"find"],
|
||
["key"=>"打包视频","func"=>"dabaoVideo"],
|
||
["key"=>"仓库地址","func"=>"myaddr"],
|
||
["key"=>"丰姿出库单","func"=>"fzckd"],
|
||
["key"=>"出库单","func"=>"ckd"],
|
||
["key"=>"开门2","func"=>"openD2"],
|
||
["key"=>"开门|開門","func"=>"openD"],
|
||
["key"=>"条码","func"=>"barcode"],
|
||
["key"=>"取消提货","func"=>"qxtihuo"],
|
||
["key"=>"提货","func"=>"tihuo"],
|
||
["key"=>"屏蔽我","func"=>"pinbi"],
|
||
["key"=>"取消屏蔽|解除屏蔽","func"=>"unpinbi"],
|
||
["key"=>"到货|拉货|到访","func"=>"daohuo"]
|
||
];
|
||
$rules3 = [//快递类型群聊回复规则
|
||
["key"=>"","func"=>"kd"]
|
||
];
|
||
$rules4 = [//店管家管理群
|
||
["key"=>"商家绑定","func"=>"bindStore"],
|
||
["key"=>"未绑定商家列表","func"=>"getMyagent"],
|
||
["key"=>"绑定关系查询","func"=>"getMyagentBind"],
|
||
["key"=>"更新","func"=>"updateStockOnce"],
|
||
["key"=>"SKU|sku|Sku|SKu|SkU|sKu|sKU","func"=>"skuLink"],
|
||
["key"=>"订单","func"=>"orderLink"],
|
||
["key"=>"解绑","func"=>"unbindStore"],
|
||
["key"=>"暂停自动分配","func"=>"stopPost"],
|
||
["key"=>"开始自动分配|恢复自动分配","func"=>"startPost"],
|
||
];
|
||
$this->pid = $params['pid'];
|
||
$info = $this->getMyInfoAndUpdate($params['myid'],$this->pid);
|
||
$WAREHOUSEID = $info["warehouseId"];
|
||
if(!$WAREHOUSEID){
|
||
throw new Exception('wxid'.$params['myid'].'未绑定仓库');
|
||
}
|
||
$this->redis->set("msg_params",json_encode($params));
|
||
$fromid = $params['data']['fromid'];
|
||
Log::error("判断是否群里信息".$fromid);
|
||
if (strpos($fromid, "@chatroom") === false && $this->SOURCE =="wx"){
|
||
Log::error("非群信息返回".$fromid);
|
||
return ["msg"=>'',"info"=>"非群聊信息"];
|
||
}
|
||
switch($this->SOURCE){
|
||
case "wx":
|
||
$roominfo = $this->RoomsModel->where(["room_id"=>$fromid])->find();
|
||
$roomtype = $roominfo['type'];
|
||
break;
|
||
case "qiwe":
|
||
$roominfo = $this->qiweRoomsModel->where(["room_id"=>$fromid])->find();
|
||
$roomtype = $roominfo['type'];
|
||
Log::error("企微的查找群信息".json_encode($roominfo));
|
||
break;
|
||
default:
|
||
return ["msg"=>"","info"=>"非定义的客户端信息,不做处理"];
|
||
}
|
||
|
||
//消息格式化start
|
||
$msgs = "";
|
||
$text = "";
|
||
try{
|
||
switch ($params['type']) {
|
||
case '1':
|
||
// code...
|
||
$text = $params['data']['msg'];
|
||
break;
|
||
case '49':
|
||
return ["msgs"=>'',"info"=>$info];
|
||
$xml = simplexml_load_string($params['data']['msg']);
|
||
$title = (string) $xml->appmsg->title;
|
||
$content = (string) $xml->appmsg->refermsg->content;
|
||
$text = $title . " " . $content;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}catch(Exception $e){
|
||
return ["msg"=>$text,"info"=>$e->getMessage()];
|
||
}
|
||
$msg_log_insert = [
|
||
"msg"=>$text,
|
||
"room_wxid"=>$params['data']['fromid'],
|
||
"sender_wxid"=>$params['data']['memid'],
|
||
"sender_name"=>$params['data']['memname'],
|
||
"sender_room_name"=>$params['data']['nickName2'],
|
||
"room_name"=>$params['data']['nickName'],
|
||
"room_type"=>$roomtype,
|
||
"task_params"=>json_encode($params),
|
||
"creatime"=>time()
|
||
];
|
||
$msg_log = $this->ChatLogModel->create($msg_log_insert);
|
||
$msgid = $msg_log['id'];
|
||
$postnums = $this->getPostNums($text);//获取快递号
|
||
//消息格式化end
|
||
|
||
// ── 转发到 WMS 开放接口 ──
|
||
// 如果 WMS 返回了处理结果,跳过本地关键词匹配直接返回
|
||
$forward = new Forward();
|
||
$forwardResult = $forward->handle($params, $this->SOURCE, $text);
|
||
if ($forwardResult !== null) {
|
||
if (!empty($forwardResult['msgs'])) {
|
||
$msg_log->save(["result" => json_encode($forwardResult['msgs'])]);
|
||
}
|
||
return $forwardResult;
|
||
}
|
||
|
||
switch($roomtype){
|
||
case 1:
|
||
//货主类型群聊
|
||
|
||
$me = $this->RoomsExcludeModel->where(['memid'=>$params['data']['memid']])->find();
|
||
|
||
if($me){//客服回复
|
||
$this->redis2->del("to:".$fromid);
|
||
return ["msgs"=>'',"info"=>$me];
|
||
}
|
||
$from = [
|
||
"memname"=>$this->reand($params['data']['memname']),
|
||
"memid"=>$params['data']['memid'],
|
||
"fromid"=>$fromid,
|
||
"storeid"=>$roominfo['STOREID'],
|
||
"nickName"=>$params['data']['nickName'],
|
||
"WAREHOUSEID"=>$WAREHOUSEID
|
||
];
|
||
$info = [];
|
||
$has2 = false;
|
||
foreach ($rules as $r){
|
||
$keyword = explode("|", $r['key']);
|
||
$has = false;
|
||
foreach ($keyword as $rr){
|
||
if(strpos($text, $rr) !== false){
|
||
$has = true;
|
||
$has2 = true;
|
||
}
|
||
}
|
||
array_push($info,["key"=>$r,"has"=>$has]);
|
||
if($has){//命中关键词
|
||
$msgs = call_user_func(array($this, $r['func']), $from,$postnums,$msgid,$text);
|
||
break;
|
||
}
|
||
}
|
||
//未命中关键词
|
||
if(!$has2 && $roominfo['noreply']==0){
|
||
$this->redis2->set("to:".$fromid,time()."|".$text);
|
||
}
|
||
break;
|
||
case 2:
|
||
//内部类型群聊
|
||
$me = $this->RoomsExcludeModel->where(['memid'=>$params['data']['memid'],"is_robot"=>1])->find();
|
||
|
||
if($me){//机器人回复
|
||
return ["msgs"=>'',"info"=>$me];
|
||
}
|
||
$from = [
|
||
"memname"=>$this->reand($params['data']['memname']),
|
||
"memid"=>$params['data']['memid'],
|
||
"fromid"=>$fromid,
|
||
"postcode"=>$roominfo['POSTCODE'],
|
||
"nickName"=>$params['data']['nickName'],
|
||
"isMe"=>true,
|
||
"WAREHOUSEID"=>$WAREHOUSEID
|
||
];
|
||
foreach ($rules2 as $r){
|
||
$keyword = explode("|", $r['key']);
|
||
$has = false;
|
||
foreach ($keyword as $rr){
|
||
if(strpos($text, $rr) !== false){
|
||
$has = true;
|
||
}
|
||
}
|
||
if($has){
|
||
$msgs = call_user_func(array($this, $r['func']), $from,$postnums,$msgid,$text);
|
||
break;
|
||
}
|
||
}
|
||
break;
|
||
case 3:
|
||
//快递类型群聊
|
||
$me = $this->RoomsExcludeModel->where(['memid'=>$params['data']['memid']])->find();
|
||
if($me){
|
||
return ["msgs"=>'',"info"=>$me];
|
||
}
|
||
$from = [
|
||
"memname"=>$this->reand($params['data']['memname']),
|
||
"memid"=>$params['data']['memid'],
|
||
"fromid"=>$fromid,
|
||
"storeid"=>$roominfo['STOREID'],
|
||
"nickName"=>$params['data']['nickName'],
|
||
"isMe"=>true
|
||
];
|
||
$msgs = $this->kd($from,$text);
|
||
break;
|
||
case 4:
|
||
$me = $this->RoomsExcludeModel->where(['memid'=>$params['data']['memid'],"is_robot"=>1])->find();
|
||
if($me){//机器人回复
|
||
return ["msgs"=>'',"info"=>$me];
|
||
}
|
||
$from = [
|
||
"memname"=>$this->reand($params['data']['memname']),
|
||
"memid"=>$params['data']['memid'],
|
||
"fromid"=>$fromid,
|
||
"postcode"=>$roominfo['POSTCODE'],
|
||
"nickName"=>$params['data']['nickName'],
|
||
"isMe"=>true,
|
||
"WAREHOUSEID"=>$WAREHOUSEID
|
||
];
|
||
foreach ($rules4 as $r){
|
||
$keyword = explode("|", $r['key']);
|
||
$has = false;
|
||
foreach ($keyword as $rr){
|
||
if(strpos($text, $rr) !== false){
|
||
$has = true;
|
||
}
|
||
}
|
||
if($has){
|
||
$msgs = call_user_func(array($this, $r['func']), $from,$postnums,$msgid,$text);
|
||
break;
|
||
}
|
||
}
|
||
break;
|
||
default:
|
||
return ["msgs"=>'',"info"=>"群聊类型未命中"];
|
||
}
|
||
$randomNumber = rand(1, 2);
|
||
sleep($randomNumber);
|
||
if($msgs && $roominfo['noreply']==0){
|
||
$msg_log->save(["result"=>json_encode($msgs)]);
|
||
return ["msgs"=>$msgs,"info"=>$info];
|
||
}else{
|
||
return ["msgs"=>'',"info"=>$info];
|
||
}
|
||
}
|
||
private function nothing($from,$postnums,$msgid,$info=""){
|
||
return [];
|
||
}
|
||
private function reand($input){
|
||
$output = str_replace("&", "", $input);
|
||
return $output;
|
||
}
|
||
private function getMyagent($from,$postnums,$msgid,$info=""){
|
||
$url = "https://ye4s.wms.gztbyc.com/index/wms/Dianguanjia/LoadMyAgentList1";
|
||
$res = Http::get($url);
|
||
}
|
||
private function getMyagentBind($from,$postnums,$msgid,$info=""){
|
||
$url = "https://ye4s.wms.gztbyc.com/index/wms/Dianguanjia/getMyagentBind";
|
||
$res = Http::get($url);
|
||
}
|
||
|
||
public function tihuotest(){
|
||
$from = [
|
||
"memname"=>"",
|
||
"memid"=>"",
|
||
"fromid"=>"xxxxxx",
|
||
"storeid"=>"15901",
|
||
"nickName"=>"",
|
||
"WAREHOUSEID"=>5400
|
||
];
|
||
$res = $this->tihuo($from,[],"6902689提货粤EH22E2");
|
||
return json($res);
|
||
}
|
||
private function fastruku($from,$postnums,$msgid,$info=""){
|
||
$msgs = [];
|
||
$ApplystorageModel = new \app\common\model\wms\Applystorage;
|
||
$PutindetailModel = new \app\common\model\wms\Putindetail;
|
||
$WarehouseModel = new \app\common\model\Warehouse;
|
||
$WAREHOUSEID = $from["WAREHOUSEID"];
|
||
$firstMatch = null;
|
||
$pattern = '/奇门入库单号([A-Z0-9-_]+)/';
|
||
preg_match_all($pattern, $info, $matches);
|
||
$results = $matches[1];
|
||
|
||
$this->redis->set("kdksjdksaj1",json_encode($results));
|
||
$WAREHOUSE = $WarehouseModel->field("kjrkSpaceId,operatorID")->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
$kjrkSpaceId = $WAREHOUSE['kjrkSpaceId']??0;
|
||
$userid = $WAREHOUSE["operatorID"];
|
||
if(!$kjrkSpaceId){
|
||
$backMsg = $this->backMsg($from,"仓库未设置快捷入库库位");
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
return $msgs;
|
||
}
|
||
foreach ($results as $r){
|
||
$backMsg = [];
|
||
$Applystorage = $ApplystorageModel->alias("apply")
|
||
->field("apply.ID as ID,store.TITLE as TITLE,apply.SERIALNUM as SERIALNUM,apply.STATUS as STATUS,apply.STOREID as STOREID,apply.NOTES as NOTES")
|
||
->where(["apply.NOTES"=>"奇门入库单号".$r,"WAREHOUSEID"=>$WAREHOUSEID])
|
||
->where("apply.STATUS","in",[0,4])
|
||
->join("yj_store store","store.STOREID=apply.STOREID")
|
||
->find();
|
||
$this->redis->set("kdksjdksaj2",json_encode($Applystorage));
|
||
|
||
if($Applystorage){
|
||
if($Applystorage['STATUS']==0){
|
||
//等待入库,改为随机入库
|
||
Wsdl::webservice([$WAREHOUSEID,$Applystorage['ID']],'createRandom');
|
||
}
|
||
$Applystorage = $ApplystorageModel->alias("apply")
|
||
->field("apply.ID as ID,store.TITLE as TITLE,apply.SERIALNUM as SERIALNUM,apply.STATUS as STATUS,apply.STOREID as STOREID,apply.NOTES as NOTES")
|
||
->where(["apply.NOTES"=>"奇门入库单号".$r,"WAREHOUSEID"=>$WAREHOUSEID])
|
||
->where("apply.STATUS","in",[0,4])
|
||
->join("yj_store store","store.STOREID=apply.STOREID")
|
||
->find();
|
||
$this->redis->set("kdksjdksaj3",json_encode($Applystorage));
|
||
$this->redis->set("kdksjdksaj",json_encode($Applystorage));
|
||
if($Applystorage['STATUS']==0){
|
||
$backMsg = $this->backMsg($from,"上架失败,{$Applystorage['NOTES']}修改为随机入库失败");
|
||
}else{
|
||
$data = $PutindetailModel
|
||
->alias("detail")
|
||
->field("detail.STOCKID as stock_id,detail.COUNT as count,COALESCE(SUM(storages.COUNT), 0) as putin_count,(detail.COUNT - COALESCE(SUM(storages.COUNT), 0)) as remaining_count,stock.BARCODE as BARCODE,stock.STYLE as style,stock.COLOR as color,stock.IMG as imgs,goods.NAME as title,stock.weight as weight")
|
||
->where(["detail.APPLYSTORAGEID"=>$Applystorage['ID']])
|
||
->join("yj_putinstorage storages","storages.APPLYSTORAGEID = detail.APPLYSTORAGEID and storages.STOCKID=detail.STOCKID","left")
|
||
->join("yj_stock stock","stock.STOCKID=detail.STOCKID")
|
||
->join("yj_goods goods","goods.goodsid=stock.goodsid")
|
||
->group("detail.STOCKID,storages.STOCKID")
|
||
->order("remaining_count","desc")
|
||
->select();
|
||
$inputStrs = [];
|
||
foreach ($data as $rr){
|
||
$inputStr = "{$rr['stock_id']}|{$rr['remaining_count']}|{$rr['count']}|{$rr['title']} {$rr['BARCODE']} {$rr['color']} {$rr['style']}|999|{$rr['putin_count']},@@{$kjrkSpaceId}@@";
|
||
array_push($inputStrs,$inputStr);
|
||
}
|
||
$inputStrs = implode("##",$inputStrs);
|
||
$res = Wsdl::webservicepda([$userid,$Applystorage["SERIALNUM"],$inputStrs],"confirmPutInR1");
|
||
$data = $PutindetailModel
|
||
->alias("detail")
|
||
->field("detail.STOCKID as stock_id,detail.COUNT as count,COALESCE(SUM(storages.COUNT), 0) as putin_count,(detail.COUNT - COALESCE(SUM(storages.COUNT), 0)) as remaining_count,stock.BARCODE as BARCODE,stock.STYLE as style,stock.COLOR as color,stock.IMG as imgs,goods.NAME as title,stock.weight as weight")
|
||
->where(["detail.APPLYSTORAGEID"=>$Applystorage['ID']])
|
||
->join("yj_putinstorage storages","storages.APPLYSTORAGEID = detail.APPLYSTORAGEID and storages.STOCKID=detail.STOCKID","left")
|
||
->join("yj_stock stock","stock.STOCKID=detail.STOCKID")
|
||
->join("yj_goods goods","goods.goodsid=stock.goodsid")
|
||
->group("detail.STOCKID,storages.STOCKID")
|
||
->order("remaining_count","desc")
|
||
->select();
|
||
$canConfirm = true;
|
||
foreach ($data as $rr){
|
||
if($rr['remaining_count']>0){
|
||
$canConfirm = false;
|
||
}
|
||
}
|
||
if($canConfirm){
|
||
$backMsg = $this->confirmApplyStorage($WAREHOUSEID,$userid,$Applystorage['ID']);
|
||
$msgs = array_merge($msgs,[$backMsg]);
|
||
$backMsg = $this->backMsg($from,"上架成功");
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"上架失败");
|
||
}
|
||
}
|
||
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"未找到入库单或已入库");
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
}
|
||
}
|
||
return $msgs;
|
||
}
|
||
|
||
private function confirmApplyStorage($WAREHOUSEID,$userId,$code){
|
||
$msg = $this->noticeConfirmApplyStorage($code);
|
||
$res = wsdl::webservice([intval($WAREHOUSEID),intval($userId),intval($code)],"bePutInStorageR");
|
||
return $msg;
|
||
}
|
||
public function noticeConfirmApplyStorage($code){
|
||
$ApplystorageModel = new \app\common\model\wms\Applystorage;
|
||
$PutindetailModel = new \app\common\model\wms\Putindetail;
|
||
$RoomsModel = new \app\common\model\Rooms;
|
||
$room = "";
|
||
$Applystorage = $ApplystorageModel->alias("apply")
|
||
->field("apply.ID as ID,store.TITLE as TITLE,apply.SERIALNUM as SERIALNUM,apply.status as status,apply.STOREID as STOREID,apply.NOTES as NOTES")
|
||
->where(["ID"=>$code])
|
||
->where("NOTES like '奇门入库单号%'")
|
||
->join("yj_store store","store.STOREID=apply.STOREID")
|
||
->find();
|
||
$tomsg = [];
|
||
if($Applystorage){
|
||
$info = "";
|
||
$infos = [];
|
||
$data = $PutindetailModel
|
||
->alias("detail")
|
||
->field("detail.STOCKID as stock_id,detail.COUNT as count,COALESCE(SUM(storages.COUNT), 0) as putin_count,(detail.COUNT - COALESCE(SUM(storages.COUNT), 0)) as remaining_count,stock.BARCODE as BARCODE,stock.STYLE as style,stock.COLOR as color,stock.IMG as imgs,goods.NAME as title,stock.weight as weight")
|
||
->where(["detail.APPLYSTORAGEID"=>$Applystorage['ID']])
|
||
->join("yj_putinstorage storages","storages.APPLYSTORAGEID = detail.APPLYSTORAGEID and storages.STOCKID=detail.STOCKID","left")
|
||
->join("yj_stock stock","stock.STOCKID=detail.STOCKID")
|
||
->join("yj_goods goods","goods.goodsid=stock.goodsid")
|
||
->group("detail.STOCKID,storages.STOCKID")
|
||
->order("remaining_count","desc")
|
||
->select();
|
||
foreach ($data as $r){
|
||
array_push($infos,"{$r['title']} {$r['stock_id']} {$r['style']} {$r['color']} {$r['BARCODE']} 数量:{$r['putin_count']}");
|
||
}
|
||
$info = implode("\n---\n",$infos);
|
||
$room = $RoomsModel->where(["isStorge"=>1,"STOREID"=>$Applystorage['STOREID'],"type"=>1])->find();
|
||
if(!$room){
|
||
$room = $RoomsModel->where(["isMain"=>1,"STOREID"=>$Applystorage['STOREID'],"type"=>1])->find();
|
||
}
|
||
$WmsController = new WmsController();
|
||
if($room){
|
||
[$aiteUser,$atids] = $WmsController->getAUser($room["room_id"],"资料员");
|
||
$STR = "{$Applystorage['NOTES']}\n {$info}\n 已入库完毕\n提示:如果需要@指定人员,请备注群昵称为XXXXXX资料员 ";
|
||
if($atids){
|
||
$STR.=$aiteUser;
|
||
$tomsg = $WmsController->toMsg($room["room_id"],$STR,$atids);
|
||
}else{
|
||
$tomsg = $WmsController->toMsg($room["room_id"],$STR);
|
||
}
|
||
}
|
||
}
|
||
return $tomsg;
|
||
}
|
||
private function daohuo($from,$postnums,$msgid,$info=""){
|
||
$msgs = [];
|
||
$WAREHOUSEID = $from["WAREHOUSEID"];
|
||
$STOREID = isset($from["storeid"])?$from["storeid"]:null;
|
||
$carnum = $this->extractLicensePlates($info);
|
||
if($carnum){
|
||
$this->redis->select(7);
|
||
$this->redis->set("{$WAREHOUSEID}_{$carnum[0]}", json_encode(["roomName"=>$from["nickName"],"UserName"=>$from["memname"],"STOREID"=>$STOREID,"type"=>"daohuo","from"=>$from]), ['NX', 'EX' => 6*60*60]);
|
||
$backMsg = $this->backMsg($from,"车牌{$carnum[0]}已加入临时通行,请在6小时内进场,超时需要重新登记车牌放行");
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"未识别到车牌号,如需到货登记车牌号,请发送到货+车牌号登记");
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
}
|
||
return $msgs;
|
||
}
|
||
private function getAddress($address){
|
||
|
||
$properties = new ZopProperties("872fa46bd87e9c0dcd7de", "35c4d02a1a45980282f1f80a0194ad0a");
|
||
$client = new ZopClient($properties);
|
||
$request = new ZopRequest();
|
||
$request->setUrl("https://japi.zto.com/zto.innovate.structureNamePhoneAddress");
|
||
$param = [
|
||
"address"=>$address
|
||
];
|
||
$request->setBody(json_encode($param));
|
||
|
||
return json_decode($client->execute($request));
|
||
}
|
||
|
||
public function test($room_id = ""){
|
||
$WmsController = new WmsController();
|
||
$res = $WmsController->getAUser($room_id,"客服");
|
||
return json($res);
|
||
}
|
||
private function createOrder($from,$postnums,$msgid,$info=""){
|
||
$WAREHOUSEID = $from["WAREHOUSEID"];
|
||
$msgs = [];
|
||
$OrdersLib = new \app\index\library\chat\Orders;
|
||
$result = $OrdersLib->extractAddressPhoneAndName($info);
|
||
$room_id = explode("@",$from['fromid']);
|
||
$creator_wxid = explode("_",$from['memid']);
|
||
$creator_wxid2 = explode("@",$from['memid']);
|
||
$time = time();
|
||
$text = null;
|
||
$rules = "快速建单规则:
|
||
建单+收件人+地址+电话+商品(商品【条码或名称】跟数量需要用符号*或x或X区分)+快递(暂支持:申通、中通、邮政、顺丰、韵达)+平台(暂支持:拼多多、抖音|抖店、小红书、快手、京东、淘宝、天猫、阿里巴巴、视频号)每种信息请使用换行、逗号或空格作为间隔
|
||
注意事项:
|
||
1.收件人地址电话顺序可以随意,具体看匹配情况。商品和其他备注信息如不带*xX有可能会被识别到地址收件人中去。
|
||
2.一条信息只能创建一单,多个订单请分别发送,避免不必要的麻烦。
|
||
3.快速建单主要是为了快速出手工单的单号所用,只要地址电话没有问题,出的单号就没有问题,具体发货内容物人工会根据信息原文复查一遍后发货,所以请务必所有的信息都编辑在一条信息里面,不要收件人跟商品分开发。
|
||
4.快速建单的截单时间与正常订单一致,出单时间如果过了当天的截单时间将不会当天发出,这种情况如果用群揽收可能导致的快递揽收后超时问题需商家自行承担。
|
||
5.快速建单是否可以成功出单号与仓库内暂有的快递以及商家是否有单号有关,如果没有可用单号,会导致出单失败,具体细节可以询问客服。
|
||
6.如未指定平台以及快递,会默认使用淘宝平台和韵达快递,请知悉。
|
||
7.如需携带平台的订单号请加入 单号xxxxxx,如抖店订单:单号69*******,单号和单号的字符需要连在一起。
|
||
示例消息1:
|
||
_______________________________________________________
|
||
建单测试人员[4942]
|
||
18000000000
|
||
云南省 保山市 腾冲市 文星幼儿园马帮旁 佰束防晒霜*2
|
||
拼多多 中通
|
||
_________________________________________________________
|
||
示例识别结果1:
|
||
收件人:测试人员[4942]
|
||
电话:18000000000
|
||
省:云南省
|
||
市:保山市
|
||
区:腾冲市
|
||
详细地址:云南省 保山市 腾冲市 文星幼儿园马帮旁
|
||
出单平台:拼多多
|
||
出单快递:中通
|
||
平台单号:
|
||
==============================
|
||
示例消息2:
|
||
_______________________________________________________
|
||
建单18000000000 测试人员[4942] 云南省 保山市 腾冲市 文星幼儿园马帮旁 佰束防晒霜x2 单号69154212656123
|
||
_________________________________________________________
|
||
示例识别结果2:
|
||
收件人:测试人员[4942]
|
||
电话:18000000000
|
||
省:云南省
|
||
市:保山市
|
||
区:腾冲市
|
||
详细地址:云南省 保山市 腾冲市 文星幼儿园马帮旁
|
||
出单平台:菜鸟
|
||
出单快递:申通
|
||
平台单号:69154212656123
|
||
";
|
||
$lastDate = $time-604800;
|
||
$orderModel = new \app\common\model\rooms\Order;
|
||
$addr_info = $this->getAddress($result['address']);
|
||
$RoomsModel = $this->SOURCE == "wx" ? $this->RoomsModel : $this->qiweRoomsModel;
|
||
$roominfo = $RoomsModel->where(["room_id"=>$from['fromid']])->find();//货主群聊
|
||
if(!$roominfo['isOrder']){
|
||
$text = "群未开启自动抓取建单,如有需要,联系客服开启\n";
|
||
}else{
|
||
if(!isset($addr_info->result->address)){
|
||
$text = "地址解析错误,".json_encode($result).json_encode($addr_info)."\n";
|
||
}else{
|
||
$address = $addr_info->result->address;
|
||
$inserData = [
|
||
"name"=>$result['name'],
|
||
"tel"=>$result['tel'],
|
||
"address"=>$result['address'],
|
||
"province"=>$address->province,
|
||
"city"=>$address->city,
|
||
"district"=>$address->county,
|
||
"ordercode"=>$room_id[0]."-".(isset($creator_wxid[1])?$creator_wxid[1]:$creator_wxid2[0])."-".$time,
|
||
"creator_wxid"=>$from['memid'],
|
||
"room_wxid"=>$from['fromid'],
|
||
"creator_name"=>$from['memname'],
|
||
"room_name"=>$from['nickName'],
|
||
"store_id"=>$from['storeid'],
|
||
"postnum"=>"",
|
||
"create_time"=>$time,
|
||
"reviewer_time"=>0,
|
||
"reviewer_id"=>0,
|
||
"reviewer_items"=>"",
|
||
"status"=>1,
|
||
"platform_code"=>$result['platform_code'],
|
||
"express_code"=>$result['express_code'],
|
||
"platform_order_id"=>$result['platform_order_id'],
|
||
"msg"=>$info,
|
||
"warehouseid"=>$WAREHOUSEID,
|
||
"source"=>$this->SOURCE
|
||
];
|
||
if(!$inserData['name']){
|
||
$text = "订单未识别到收件人\n";
|
||
}
|
||
if(!$inserData['address']){
|
||
$text = "订单未识别到地址\n";
|
||
}
|
||
if(!$inserData['province']){
|
||
$text = "订单未识别到省份\n";
|
||
}
|
||
if(!$inserData['city']){
|
||
$text = "订单未识别到城市\n";
|
||
}
|
||
if(!$inserData['district']){
|
||
$text = "订单未识别到区\n";
|
||
}
|
||
if(!$inserData['tel']){
|
||
$text = "订单未识别到收件人电话\n";
|
||
}
|
||
if(!$inserData['platform_order_id'] && $inserData['platform_code']==5){
|
||
$text = "抖店订单需要提供订单号才可以分配快递\n";
|
||
}
|
||
}
|
||
}
|
||
if($text){
|
||
$backMsg = $this->backMsg($from,"{$text}\n已取消建单任务,建单采集规则为:{$rules}");
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
}else{
|
||
$orderinfo = "收件人:{$inserData['name']}\n电话:{$inserData['tel']}\n省:{$inserData['province']}\n市:{$inserData['city']}\n区:{$inserData['district']}\n详细地址:{$inserData['address']}\n出单平台:{$OrdersLib->getplatformName($inserData['platform_code'])}\n出单快递:{$OrdersLib->getExpressName($inserData['express_code'])}\n平台单号:{$inserData['platform_order_id']}\n创建人:{$inserData['creator_name']}";
|
||
//创建订单到预处理数据库
|
||
if($result['platform_order_id']){//有外部订单编号,先检测是否已经推送到wms
|
||
|
||
$order = $this->OrderModel->field("ID,CREATIONDATE,POSTNUM")->where(["WAREHOUSEID"=>$WAREHOUSEID,"DISPLAYFLAG"=>0])->where("SOURCEORDERCODE='{$result['platform_order_id']}' or SOURCEID='{$result['platform_order_id']}'")->find();
|
||
if($order){
|
||
//订单已经在系统处理流程
|
||
$backMsg = $this->backMsg($from,"订单号:{$result['platform_order_id']},已经在WMS订单系统\n创建时间:".date("Y-m-d H:i:s", $order["CREATIONDATE"]/1000)."\n运单号:{$order['POSTNUM']}\n本次建单请求已取消。如果是需要补发,请修改订单号或订单号留空重新提交");
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
}else{
|
||
$order = $orderModel->where(["platform_order_id"=>$result['platform_order_id']])->where("status>0")->find();
|
||
if($order){
|
||
//订单已经在系统处理流程
|
||
$backMsg = $this->backMsg($from,"订单号:{$result['platform_order_id']},已经在待处理排队等待\n创建时间:".date("Y-m-d H:i:s", $order["create_time"])."\n请耐心等待处理,本次请求已取消");
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"订单已经提交到待处理,将会在3-5分钟出单号再发出通知\n____________\n订单明细:\n{$orderinfo}\n____________\n如需取消请在3分钟内回复:\n取消采集订单{$inserData['ordercode']}\n超时出了运单号,需走拦截流程处理");
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
$orderModel->save($inserData);
|
||
}
|
||
}
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"订单已经提交到待处理,将会在3-5分钟出单号再发出通知\n____________\n订单明细:\n{$orderinfo}____________\n如需取消请在3分钟内回复:\n取消采集订单{$inserData['ordercode']}");
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
$orderModel->save($inserData);
|
||
}
|
||
}
|
||
return $msgs;
|
||
}
|
||
private function qxtihuo($from,$postnums,$msgid,$info=""){
|
||
$msgs = [];
|
||
$WAREHOUSEID = $from["WAREHOUSEID"];
|
||
$STOREID = isset($from["storeid"])?$from["storeid"]:null;
|
||
$orderid = strstr($info, '取消提货', true);
|
||
$orderid = trim($orderid);
|
||
if($orderid){
|
||
$CkModel = new \app\common\model\wmsorder\Ck;
|
||
$CkModel_tmp = $CkModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("SOURCEID","like","%{$orderid}");
|
||
if(!isset($from["isMe"]) && $STOREID){
|
||
$CkModel_tmp->where(["STOREID"=>$STOREID]);
|
||
}
|
||
$order = $CkModel_tmp->find();
|
||
if($order){
|
||
$carnum = $this->extractLicensePlates($info);
|
||
$order->CARCODE = "";
|
||
$order->save();
|
||
$backMsg = $this->backMsg($from,"{$orderid}解绑成功");
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"没有找到出库单{$orderid},可能状态已经改变");
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
}
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"如需出库单取消绑定车牌号,发送出库单号+取消提货");
|
||
return $backMsg;
|
||
}
|
||
return $msgs;
|
||
}
|
||
/**
|
||
* 频闭我
|
||
*/
|
||
private function pinbi($from,$postnums,$msgid,$info=""){
|
||
$exits = $this->RoomsExcludeModel->where(['memid'=>$from["memid"]])->find();
|
||
if(!$exits){
|
||
$this->RoomsExcludeModel->save([
|
||
"memid"=>$from["memid"],
|
||
"is_robot"=>0
|
||
]);
|
||
}
|
||
$backMsg = $this->backMsg($from,"已在外部群屏蔽了你,将不再回复您发送的消息。");
|
||
return $backMsg;
|
||
}
|
||
private function unpinbi($from,$postnums,$msgid,$info=""){
|
||
$exits = $this->RoomsExcludeModel->where(['memid'=>$from["memid"]])->find();
|
||
if($exits){
|
||
$this->RoomsExcludeModel->where(['memid'=>$from["memid"]])->delete();
|
||
}
|
||
$backMsg = $this->backMsg($from,"已取消外部群屏蔽,将恢复回复您发送的消息。");
|
||
return $backMsg;
|
||
}
|
||
private function tihuo($from,$postnums,$msgid,$info=""){
|
||
$msgs = [];
|
||
$WAREHOUSEID = $from["WAREHOUSEID"];
|
||
$STOREID = isset($from["storeid"])?$from["storeid"]:null;
|
||
$orderid = strstr($info, '提货', true);
|
||
$orderid = trim($orderid);
|
||
if($orderid){
|
||
$CkModel = new \app\common\model\wmsorder\Ck;
|
||
$CkModel_tmp = $CkModel->where(["STATUS"=>3,"WAREHOUSEID"=>$WAREHOUSEID])->where("SOURCEID","like","%{$orderid}");
|
||
if(!isset($from["isMe"]) && $STOREID){
|
||
$CkModel_tmp->where(["STOREID"=>$STOREID]);
|
||
}
|
||
$order = $CkModel_tmp->find();
|
||
if($order){
|
||
$carnum = $this->extractLicensePlates($info);
|
||
if($carnum){
|
||
$order->CARCODE = $carnum[0];
|
||
$order->save();
|
||
$this->redis->select(7);
|
||
$rooms = $this->getAllRooms($this->wechats[0]);
|
||
foreach ($rooms as $room){
|
||
if($room["wxid"]==$from["fromid"]){
|
||
$roomName = $room["name"];
|
||
}
|
||
}
|
||
$this->redis->set("{$WAREHOUSEID}_{$carnum[0]}", json_encode(["roomName"=>$from["nickName"],"UserName"=>$from["memname"],"type"=>"tihuo"]), ['NX', 'EX' => 6*60*60]);
|
||
$backMsg = $this->backMsg($from,"{$orderid}成功绑定车牌{$carnum[0]},车牌已加入临时通行,请在6小时内进场,超时需要重新登记车牌放行");
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"未识别到车牌号");
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
}
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"没有找到出库单{$orderid}或不需要绑定车牌,可能状态已经改变");
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
}
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"如需出库单绑定车牌号,发送出库单号+提货+车牌号");
|
||
return $backMsg;
|
||
}
|
||
return $msgs;
|
||
}
|
||
private function extractLicensePlates($string) {
|
||
// 定义车牌号正则表达式
|
||
$pattern = '/
|
||
(?:[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z]| # 普通省份简称+字母
|
||
京[A-Z]| # 北京特殊格式
|
||
沪[A-Z]| # 上海特殊格式
|
||
浙[A-Z]| # 浙江特殊格式
|
||
苏[A-Z]| # 江苏特殊格式
|
||
粤Z) # 港澳车牌
|
||
[A-Z0-9]{4,6} # 4-5位字母数字组合
|
||
|WJ\d{4}[A-Z0-9] # 武警车牌
|
||
|[军海空北沈兰济南广成]\w{5} # 军车车牌
|
||
|\d{6}使 # 使馆车牌另一种格式
|
||
/xu';
|
||
|
||
preg_match_all($pattern, $string, $matches);
|
||
|
||
return $matches[0] ?? [];
|
||
}
|
||
private function fzckd($from,$postnums,$msgid,$info=""){
|
||
$msgs = [];
|
||
$backMsg = $this->backMsg($from,"https://ye4s.wms.gztbyc.com/index/wms/wms/fzCkd/code/{$postnums[0]}");
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
return $msgs;
|
||
}
|
||
private function ckd($from,$postnums,$msgid,$info=""){
|
||
$msgs = [];
|
||
$backMsg = $this->backMsg($from,"https://ye4s.wms.gztbyc.com/index/wms/wms/ckd/code/{$postnums[0]}");
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
return $msgs;
|
||
}
|
||
private function skuLink($from,$postnums,$msgid,$info=""){
|
||
$msgs = [];
|
||
$backMsg = $this->backMsg($from,"https://ye4s.wms.gztbyc.com/index/wms/Dianguanjia/stock");
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
return $msgs;
|
||
}
|
||
private function orderLink($from,$postnums,$msgid,$info=""){
|
||
$msgs = [];
|
||
$backMsg = $this->backMsg($from,"https://ye4s.wms.gztbyc.com/index/wms/Dianguanjia/orders");
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
return $msgs;
|
||
}
|
||
private function stopPost($from,$postnums,$msgid,$info=""){
|
||
$this->redis->select(1);
|
||
$this->redis->set("stopPost",1,['NX', 'EX' => 3600]);
|
||
$backMsg = $this->backMsg($from,"店管家已暂停自动分配快递号,1小时后自动恢复");
|
||
return $backMsg;
|
||
}
|
||
private function startPost($from,$postnums,$msgid,$info=""){
|
||
$this->redis->select(1);
|
||
$this->redis->del("stopPost");
|
||
$backMsg = $this->backMsg($from,"自动分配快递号已恢复");
|
||
return $backMsg;
|
||
}
|
||
private function unbindStore($from,$postnums,$msgid,$info=""){
|
||
$list = explode("\n",$info);
|
||
$lists = [];
|
||
$this->MyagentModel = new \app\common\model\dgj\Myagent;
|
||
$this->StoreModel = new \app\common\model\wms\Store;
|
||
foreach($list as $r){
|
||
if (intval($r)>0){
|
||
$data = intval($r);
|
||
|
||
$line = $this->MyagentModel->where(["Mobile"=>trim($data)])->find();
|
||
if($line){
|
||
$line->STOREID = 0;
|
||
$line->save();
|
||
$text = "{$data}已经解除绑定";
|
||
array_push($lists,$text);
|
||
}else{
|
||
$text = "{$data}没有找到商家或店铺";
|
||
array_push($lists,$text);
|
||
}
|
||
|
||
}
|
||
}
|
||
$msgs = [];
|
||
$text = implode("\n",$lists);
|
||
$backMsg = $this->backMsg($from,$text);
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
return $msgs;
|
||
}
|
||
private function updateStockOnce($from,$postnums,$msgid,$info=""){
|
||
try{
|
||
$DianguanjiaModel = new \app\index\controller\wms\Dianguanjia;
|
||
$postnums = $this->getStocks($info);//获取快递号
|
||
$ress = [];
|
||
$msgs = [];
|
||
foreach ($postnums as $postnum){
|
||
$res = $DianguanjiaModel->updateStockOnce($postnum);
|
||
array_push($ress,$postnum);
|
||
}
|
||
$backMsg = $this->backMsg($from,implode("\n",$postnums)."更新完成");
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
}catch(Exception $e){
|
||
$backMsg = $this->backMsg($from,"更新出错".$e);
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
}
|
||
return $msgs;
|
||
}
|
||
private function bindStore($from,$postnums,$msgid,$info=""){
|
||
$list = explode("\n",$info);
|
||
$lists = [];
|
||
$this->MyagentModel = new \app\common\model\dgj\Myagent;
|
||
$this->StoreModel = new \app\common\model\wms\Store;
|
||
foreach($list as $r){
|
||
if (strpos($r, ',') !== false){
|
||
$data = explode(',',$r);
|
||
|
||
$line = $this->MyagentModel->where(["Mobile"=>trim($data[0])])->find();
|
||
if($line){
|
||
$STORE = $this->StoreModel->where(["STOREID"=>trim($data[1])])->find();
|
||
if($STORE){
|
||
$text = "{$line['Mobile']}({$line['UserName']})已经成功绑定货主{$STORE['TITLE']}";
|
||
array_push($lists,$text);
|
||
$line->STOREID = trim($data[1]);
|
||
$line->save();
|
||
}else{
|
||
$text = "{$data[0]}绑定货主失败,没有找到货主ID:{$data[1]}";
|
||
array_push($lists,$text);
|
||
}
|
||
}else{
|
||
$text = "{$data[0]}绑定货主失败,店管家没有找到:{$data[0]},先同步后再试";
|
||
array_push($lists,$text);
|
||
}
|
||
|
||
}
|
||
}
|
||
$msgs = [];
|
||
$text = implode("\n",$lists);
|
||
$backMsg = $this->backMsg($from,$text);
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
return $msgs;
|
||
}
|
||
private function kd($from,$info=""){
|
||
$arr = explode("\n",$info);
|
||
$msgs = [];
|
||
foreach ($arr as $k => $r){
|
||
$postnums = $this->getPostNums(trim($r));//获取快递号
|
||
if($postnums){
|
||
$order = $this->getOrderInfoByPostnum($postnums[0],$from);
|
||
if($order){
|
||
$tmp = [
|
||
"STORENAME"=>isset($order["STORENAME"])?$order["STORENAME"]:'',
|
||
"STOREID"=>$order["STOREID"],
|
||
"POSTNUM"=>$postnums[0],
|
||
"MSG"=>trim(str_replace($postnums[0], "", trim($r)))
|
||
];
|
||
for($i=count($msgs)-1;$i>=0;$i--){
|
||
if($msgs[$i]["MSG"]==""){
|
||
$msgs[$i]["MSG"]=trim(str_replace($postnums[0], "", trim($r)));
|
||
}else{
|
||
break;
|
||
}
|
||
}
|
||
array_push($msgs,$tmp);
|
||
}else{
|
||
$text = "快递群反馈的单号".$postnums[0]."没有找到订单";
|
||
}
|
||
}else{
|
||
for($i=count($msgs)-1;$i>=0;$i--){
|
||
if($msgs[$i]["MSG"]==""){
|
||
$msgs[$i]["MSG"]=trim($r);
|
||
}else{
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
foreach ($msgs as $r){
|
||
if($r["MSG"]!=""){
|
||
$this->redis->lpush('kdroomMessageExplpde2',json_encode($r));
|
||
}
|
||
}
|
||
}
|
||
public function kdroomMessageExplpde2(){
|
||
$RoomsModel = new \app\common\model\Rooms;
|
||
$this->redis->select(2);
|
||
$has = true;
|
||
$msg_arr = [];
|
||
$count = 1000;
|
||
do{
|
||
$this->redis->select(3);
|
||
$msg = $this->redis->rpop('kdroomMessageExplpde2');
|
||
if(!$msg){
|
||
$has = false;
|
||
}else{
|
||
$count --;
|
||
$msg = json_decode($msg,true);
|
||
$room = $RoomsModel->where(["STOREID"=>$msg["STOREID"],"auto_feedback_active"=>1])->find();
|
||
$Model = new \app\common\model\wms\Exceptionwmsorder;
|
||
$Exceptionwmsorder_row = $Model->where(["POSTNUM"=>$msg["POSTNUM"]])->find();
|
||
if($Exceptionwmsorder_row){
|
||
$Exceptionwmsorder_row->DEAL .= ($Exceptionwmsorder_row->DEAL==""?"":"|")."快递群反馈:".$msg["MSG"];
|
||
$Exceptionwmsorder_row->save();
|
||
}
|
||
if($room && $Exceptionwmsorder_row && $this->excludeWords($msg["MSG"])){
|
||
$msg = $this->toMsg($room["room_id"],$msg["STORENAME"]."运单号:".$msg["POSTNUM"]."运方反馈信息:".$msg["MSG"]);
|
||
array_push($msg_arr,$msg);
|
||
$this->redis->select(2);
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
}
|
||
}
|
||
if($count==0){
|
||
$has = false;
|
||
}
|
||
}while($has);
|
||
return json($msg_arr);
|
||
}
|
||
private function excludeWords($str) {
|
||
$excludeWords = array("未发", "未发出", "月结", "理赔", "重量","无需重复通知","交接","揽收","无需重复登记","我们尽快联系网点核实","已催件","拦截请求发送成功","已录入拦截","已登记查件");
|
||
foreach ($excludeWords as $word) {
|
||
if (strpos($str, $word) !== false) {
|
||
return false; // 如果包含任何一个排除词汇,返回 false
|
||
}
|
||
}
|
||
|
||
return true; // 如果不包含任何一个排除词汇,返回 true
|
||
}
|
||
public function getStoreRooms(){
|
||
if ($this->request->isPost()){
|
||
$params = $this->request->post();
|
||
$page = $params['page'];
|
||
$pagesize = $params['pagesize'];
|
||
$keyword = $params['keyword'];
|
||
$wheres = ['1=1'];
|
||
if($keyword){
|
||
array_push($wheres,'NAME like "%'.$keyword.'%"');
|
||
}
|
||
$where = implode($wheres," and ");
|
||
$list = $this->RoomsModel->where($where)->limit(($page-1)*$pagesize,$pagesize)->order('id','desc')->select();
|
||
$count = $this->RoomsModel->where($where)->count();
|
||
return json(["rows"=>$list,"count"=>$count]);
|
||
}
|
||
}
|
||
public function getMethods(){
|
||
if ($this->request->isPost()){
|
||
$params = $this->request->post();
|
||
$page = $params['page'];
|
||
$pagesize = $params['pagesize'];
|
||
$keyword = $params['keyword'];
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$wheres = ['WAREHOUSEID='.$WAREHOUSEID];
|
||
if($keyword){
|
||
array_push($wheres,'NAME like "%'.$keyword.'%"');
|
||
}
|
||
$where = implode($wheres," and ");
|
||
$list = $this->chatMethodsModel->where($where)->limit(($page-1)*$pagesize,$pagesize)->order('id','desc')->select();
|
||
$count = $this->chatMethodsModel->where($where)->count();
|
||
return json(["rows"=>$list,"count"=>$count]);
|
||
}
|
||
}
|
||
public function methodsText(){
|
||
return json(Config::get('site.method'));
|
||
}
|
||
public function getInsideRooms(){
|
||
if ($this->request->isPost()){
|
||
$params = $this->request->post();
|
||
$page = $params['page'];
|
||
$pagesize = $params['pagesize'];
|
||
$keyword = $params['keyword'];
|
||
$wheres = ['type=2'];
|
||
if($keyword){
|
||
array_push($wheres,'NAME like "%'.$keyword.'%"');
|
||
}
|
||
$where = implode($wheres," and ");
|
||
$list = $this->RoomsModel->where($where)->limit(($page-1)*$pagesize,$pagesize)->select();
|
||
$count = $this->RoomsModel->where($where)->count();
|
||
return json(["rows"=>$list,"count"=>$count]);
|
||
}
|
||
}
|
||
public function del_rooms(){
|
||
if ($this->request->isPost()){
|
||
$params=$this->request->post();
|
||
$id = $params['id'];
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$RoomsModel = $this->SOURCE == "wx" ? $this->RoomsModel : $this->qiweRoomsModel;
|
||
$rooms = $RoomsModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"room_id"=>$id])->find();
|
||
$res = 0;
|
||
if($rooms){
|
||
$rooms->type = null;
|
||
$res = $rooms->save();
|
||
}
|
||
return json(["res"=>$res,"source"=>$this->SOURCE,"rooms"=>$rooms]);
|
||
}
|
||
}
|
||
public function save_room(){
|
||
if ($this->request->isPost()){
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$params = $this->request->post();
|
||
$data = $params['data'];
|
||
$RoomsModel = $this->SOURCE == "wx" ? $this->RoomsModel : $this->qiweRoomsModel;
|
||
$room = $RoomsModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"room_id"=>$params['data']['room_id']])->find();
|
||
if($room){
|
||
$room->save([
|
||
"STOREID"=>$params['data']['STOREID'],
|
||
"isStorge"=>$params['data']['isStorge'],
|
||
"isMain"=>$params['data']['isMain'],
|
||
"islanshow"=>isset($params['data']['islanshow'])?$params['data']['islanshow']:0,
|
||
"isBack"=>isset($params['data']['isBack'])?$params['data']['isBack']:0,
|
||
"isOrder"=>isset($params['data']['isOrder'])?$params['data']['isOrder']:0,
|
||
"POSTCODE"=>$params['data']['POSTCODE'],
|
||
"ECNOTES"=>isset($params['data']['ECNOTES'])&&$params['data']['ECNOTES']?implode(",",$params['data']['ECNOTES']):null,
|
||
"type"=>$params['data']['type'],
|
||
"noreply"=>$params['data']['noreply']??0,
|
||
"auto_feedback_active"=>isset($params['data']['auto_feedback_active'])?$params['data']['auto_feedback_active']:0,
|
||
"sub_type"=>isset($params['data']['sub_type'])&& $params['data']['sub_type']?$params['data']['sub_type']:null
|
||
]);
|
||
}else{
|
||
$this->RoomsModel->save([
|
||
"STOREID"=>$params['data']['STOREID'],
|
||
"isMain"=>$params['data']['isMain'],
|
||
"isStorge"=>$params['data']['isStorge'],
|
||
"islanshow"=>isset($params['data']['islanshow'])?$params['data']['islanshow']:0,
|
||
"isBack"=>isset($params['data']['isBack'])?$params['data']['isBack']:0,
|
||
"isOrder"=>isset($params['data']['isOrder'])?$params['data']['isOrder']:0,
|
||
"type"=>$params['data']['type'],
|
||
"ECNOTES"=>isset($params['data']['ECNOTES'])?implode(",",$params['data']['ECNOTES']):null,
|
||
"WAREHOUSEID"=>$WAREHOUSEID,
|
||
"noreply"=>$params['data']['noreply']??0,
|
||
"room_id"=>$params['data']['room_id'],
|
||
"POSTCODE"=>$params['data']['POSTCODE'],
|
||
"auto_feedback_active"=>isset($params['data']['auto_feedback_active'])?$params['data']['auto_feedback_active']:0,
|
||
"status"=>1
|
||
]);
|
||
}
|
||
return 1;
|
||
}
|
||
}
|
||
public function findRoom(){
|
||
if ($this->request->isPost()){
|
||
$params = $this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$room_id = $params["room_id"];
|
||
$data = $list = $this->RoomsModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"room_id"=>$room_id])->find();
|
||
return json($data);
|
||
}
|
||
}
|
||
public function get_all_nobing_rooms(){
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$wechat_rooms = $this->getAllRooms($this->wechats[0]);
|
||
$roomList = [];
|
||
$RoomsModel = $this->SOURCE == "wx" ? $this->RoomsModel : $this->qiweRoomsModel;
|
||
$rooms = $RoomsModel->where('WAREHOUSEID='.$WAREHOUSEID)->select();
|
||
foreach ($wechat_rooms as $wechat_room){
|
||
$has = false;
|
||
foreach ($rooms as $room){
|
||
if($wechat_room["wxid"]==$room["room_id"] && $room["type"]){
|
||
$has = true;
|
||
}
|
||
}
|
||
if(!$has){
|
||
array_push($roomList,["value"=>$wechat_room["wxid"],"text"=>$wechat_room["name"]]);
|
||
}
|
||
}
|
||
return json(["roomList"=>$roomList,"source"=>$this->SOURCE,"rooms"=>$rooms]);
|
||
}
|
||
public function get_all_rooms(){
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$wechat_rooms = $this->getAllRooms($this->wechats[0]);
|
||
$RoomsModel = $this->SOURCE == "wx" ? $this->RoomsModel : $this->qiweRoomsModel;
|
||
$rooms = $RoomsModel->where('WAREHOUSEID='.$WAREHOUSEID)->select();
|
||
foreach ($rooms as $room){
|
||
$TITLE = "";
|
||
foreach ($wechat_rooms as $wechat_room){
|
||
if($room["room_id"]==$wechat_room["wxid"]){
|
||
$TITLE = $wechat_room["name"];
|
||
}
|
||
}
|
||
$room["name"] = $TITLE;
|
||
}
|
||
return json(["source"=>$this->SOURCE,"roomList"=>$rooms]);
|
||
}
|
||
public function get_express_rooms(){
|
||
if ($this->request->isPost()){
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$wechat_rooms = $this->getAllRooms($this->wechats[0]);
|
||
$params = $this->request->post();
|
||
$page = $params['page'];
|
||
$pagesize = $params['pagesize'];
|
||
$keyword = $params['keyword'];
|
||
$ParacodeModel = new \app\common\model\wms\Paracode;
|
||
$ParacodeModel->where(["TYPE"=>301]);
|
||
if($keyword){
|
||
$ParacodeModel->where('NAME like "%'.$keyword.'%"');
|
||
}
|
||
$postCodeRows = $ParacodeModel->select();
|
||
$POSTCODE = [];
|
||
foreach ($postCodeRows as $postCodeRow){
|
||
array_push($POSTCODE,$postCodeRow["CODE"]);
|
||
}
|
||
$RoomsModel = $this->SOURCE == "wx" ? $this->RoomsModel : $this->qiweRoomsModel;
|
||
$rooms = $RoomsModel->where("POSTCODE","in",$POSTCODE)->select();
|
||
foreach ($rooms as $room){
|
||
$TITLE = "";
|
||
foreach ($wechat_rooms as $wechat_room){
|
||
if($room["room_id"]==$wechat_room["wxid"] && $room["type"]==3){
|
||
$TITLE = $wechat_room["name"];
|
||
}
|
||
}
|
||
$room["name"] = $TITLE;
|
||
}
|
||
foreach ($postCodeRows as $postCodeRow){
|
||
$tmp_rooms = [];
|
||
foreach ($rooms as $room){
|
||
if($room["POSTCODE"]==$postCodeRow["CODE"] && $room["type"]==3){
|
||
array_push($tmp_rooms,$room);
|
||
}
|
||
}
|
||
$postCodeRow["rooms"] = $tmp_rooms;
|
||
}
|
||
return json($postCodeRows);
|
||
}
|
||
}
|
||
public function get_store_rooms(){
|
||
if ($this->request->isPost()){
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$wechat_rooms = $this->getAllRooms($this->wechats[0]);
|
||
$params = $this->request->post();
|
||
$page = $params['page'];
|
||
$pagesize = $params['pagesize'];
|
||
$keyword = $params['keyword'];
|
||
$wheres = ['WAREHOUSEID='.$WAREHOUSEID];
|
||
if($keyword){
|
||
array_push($wheres,'TITLE like "%'.$keyword.'%"');
|
||
}
|
||
$where = implode($wheres," and ");
|
||
$RoomsModel = $this->SOURCE == "wx" ? $this->RoomsModel : $this->qiweRoomsModel;
|
||
$list = $this->StoreModel->where($where)->limit(($page-1)*$pagesize,$pagesize)->select();
|
||
$storeids = [];
|
||
foreach ($list as $r){
|
||
array_push($storeids,$r["STOREID"]);
|
||
}
|
||
$rooms = $RoomsModel->where("STOREID","in",$storeids)->select();
|
||
foreach ($rooms as $room){
|
||
$TITLE = "";
|
||
foreach ($wechat_rooms as $wechat_room){
|
||
if($room["room_id"]==$wechat_room["wxid"]){
|
||
$TITLE = $wechat_room["name"];
|
||
}
|
||
}
|
||
$room["name"] = $TITLE;
|
||
}
|
||
foreach ($list as $r){
|
||
$tmp_rooms = [];
|
||
foreach ($rooms as $room){
|
||
if($room["STOREID"]==$r["STOREID"] && $room["type"]==1){
|
||
array_push($tmp_rooms,$room);
|
||
}
|
||
}
|
||
$r["rooms"] = $tmp_rooms;
|
||
}
|
||
$count = $this->StoreModel->where($where)->count();
|
||
return json(["rows"=>$list,"count"=>$count]);
|
||
}
|
||
}
|
||
private function getAllRooms($wechat,$pid=0){
|
||
//判断来源wx的访问getGroup接口,qiwe的直接读取数据库
|
||
if($this->SOURCE == "wx"){
|
||
|
||
$requsetData = [
|
||
'method'=>'getGroup',
|
||
'pid'=>$pid
|
||
];
|
||
return $this->ext_query($requsetData,$wechat);
|
||
}else{
|
||
$list = $this->qiweRoomsModel->where(["WAREHOUSEID"=>$this->auth->warehouseid])->select();
|
||
//$list 转格式
|
||
$transformedList = [];
|
||
foreach ($list as $item){
|
||
$tmp = [
|
||
"count"=>count($list),
|
||
"name"=>$item["room_name"],
|
||
"wxid"=>$item["room_id"]
|
||
];
|
||
array_push($transformedList,$tmp);
|
||
}
|
||
return $transformedList;
|
||
}
|
||
}
|
||
|
||
private function truncateString($string, $length = 30, $ellipsis = '...') {
|
||
if (mb_strlen($string) > $length) {
|
||
$string = mb_substr($string, 0, $length) . $ellipsis;
|
||
}
|
||
return $string;
|
||
}
|
||
private function backMsg($from,$text){
|
||
$msgs = [];
|
||
$texts = $this->mb_str_split($text,1500);
|
||
foreach ($texts as $r){
|
||
array_push($msgs,[
|
||
"method"=>"sendText",
|
||
"wxid"=> $from['fromid'],
|
||
"msg"=> "@".$from['memname']." ".$r,
|
||
"atid"=> $from['memid'],
|
||
"pid"=> $this->pid??0
|
||
]);
|
||
}
|
||
return $msgs;
|
||
}
|
||
|
||
private function backImg($to,$url){
|
||
return [
|
||
"method"=>"sendImage",
|
||
"wxid"=> $to,
|
||
"img"=> $url,
|
||
"imgType"=> "url",
|
||
"pid"=> 0
|
||
];
|
||
}
|
||
private function backFile($from,$url){
|
||
return [
|
||
"method"=>"sendFile",
|
||
"wxid"=> $from['fromid'],
|
||
"file"=> $url,
|
||
"fileType"=> 'url',
|
||
"pid"=> $this->pid??0
|
||
];
|
||
}
|
||
private function to($to,$text){
|
||
return [
|
||
"method"=>"sendText",
|
||
"wxid"=> $to,
|
||
"msg"=> $text,
|
||
"atid"=> '',
|
||
"pid"=> $this->pid??0
|
||
];
|
||
}
|
||
private function getPostNums($text){
|
||
preg_match_all('/\b[\w-]{13,}\b/', $text, $matches);
|
||
|
||
return array_filter($matches[0], function($item) {
|
||
// 1. 排除纯手机号(11位,1开头)
|
||
if (preg_match('/^1\d{10}$/', $item)) {
|
||
return false;
|
||
}
|
||
|
||
// 2. 排除手机号+分机号格式
|
||
// 格式如:13800138000-123、13800138000x123、13800138000#123等
|
||
if (preg_match('/^1\d{10}[-xX#]\d+$/', $item)) {
|
||
return false;
|
||
}
|
||
|
||
// 3. 排除带国际区号的手机号(如:+8613800138000)
|
||
if (preg_match('/^\+?86[- ]?1\d{10}$/', $item)) {
|
||
return false;
|
||
}
|
||
|
||
// 4. 排除手机号+分机号的变体(包含空格、括号等)
|
||
// 如:13800138000 ext123、13800138000(123)
|
||
if (preg_match('/^1\d{10}[\s-_]?(ext|extension|x)[\s-_]?\d+$/i', $item)) {
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
});
|
||
}
|
||
private function getStocks($text){
|
||
preg_match_all('/\b\w{6,}\b/', $text, $matches);
|
||
return $matches[0];
|
||
}
|
||
private function getSkus($text){
|
||
preg_match_all('/\b\w{5,}\b/', $text, $matches);
|
||
return $matches[0];
|
||
}
|
||
private function getsourceOrderCode($text){
|
||
preg_match_all('/[a-zA-Z0-9-]{13,}/', $text, $matches);
|
||
return $matches[0];
|
||
}
|
||
|
||
private function setting($from,$postnums,$msgid,$info=""){
|
||
$backMsg = $this->backMsg($from,"后台管理地址:http://wms.gztbyc.com/public/wechat_1.0.6/index.html#/");
|
||
return $backMsg;
|
||
}
|
||
private function quxiaolanjie($from,$postnums,$msgid,$info=""){
|
||
$redis = new \Redis();
|
||
if(count($postnums)>0){
|
||
$msgs = [];
|
||
$text = "";
|
||
$posttype = [];
|
||
foreach($postnums as $postnum){
|
||
$status = 0;
|
||
$order = $this->getOrderInfoByPostnum($postnum,$from);
|
||
if($order){
|
||
if($order["status"]==1){
|
||
$status = $order["FLAG"]==1 ?1:2;
|
||
}else{
|
||
$status = 3;
|
||
}
|
||
}
|
||
if($status>0){
|
||
if(array_key_exists($order["POSTCODE"], $posttype)){
|
||
array_push($posttype[$order["POSTCODE"]],[$postnum,$order['ECNOTES']]);
|
||
}else{
|
||
$posttype[$order["POSTCODE"]] = [[$postnum,$order['ECNOTES']]];
|
||
}
|
||
}
|
||
switch($status){
|
||
case 0:
|
||
$text.="运单号:".$postnum." 未找到运单号,劳烦@客服处理\n";
|
||
break;
|
||
case 1:
|
||
$this->updateInterceptorder($order["ID"],1);
|
||
$this->createExceptionWmsOrder(0,$order["ID"],"群取消拦截",$postnum);
|
||
$text.="运单号:".$postnum." 已取消库内拦截,即将发货\n";
|
||
break;
|
||
case 2:
|
||
$this->updateInterceptorder($order["ID"],1);
|
||
$this->createExceptionWmsOrder(0,$order["ID"],"群取消拦截",$postnum);
|
||
$text.="运单号:".$postnum." 未设置拦截\n";
|
||
break;
|
||
case 3:
|
||
$this->createExceptionWmsOrder(0,$order["ID"],"群取消拦截",$postnum);
|
||
$text.="运单号:".$postnum." 已通知快递取消拦截\n";
|
||
break;
|
||
}
|
||
//检查是否有拦截的异常跟踪单,有的话删除
|
||
$res = $this->Exceptionwmsorder->where(["WMSORDERID"=>$order["ID"],"STATUS"=>12])->select();
|
||
foreach ($res as $r){
|
||
$r->delete();
|
||
}
|
||
}
|
||
|
||
$redis->connect('127.0.0.1', 6379);
|
||
$redis->auth('qwe2019@');
|
||
$redis->select(3);
|
||
|
||
foreach ($posttype as $k => $r){
|
||
$relayMsg = $this->sendToExplessRoom($from['WAREHOUSEID'],$r,$k,"取消拦截");
|
||
if($relayMsg){
|
||
array_push($msgs,$relayMsg);
|
||
}
|
||
$res = [];
|
||
if($k=="p02"){//申通快递自动API取消拦截
|
||
foreach ($r as $kk){
|
||
$res = $this->create_standard_sto($kk,0);
|
||
|
||
}
|
||
}
|
||
if($k=="p01"){
|
||
foreach ($r as $kk){
|
||
$res = $this->create_standard_ytos($kk,0);
|
||
}
|
||
}
|
||
if($k=="p04"){
|
||
foreach ($r as $kk){
|
||
$res = $this->create_standard_zto($kk,0);
|
||
}
|
||
}
|
||
$redis->set('qxljres',json_encode($res));
|
||
}
|
||
$backMsg = $this->backMsg($from,$text);
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
|
||
return $msgs;
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"如需取消拦截运单号,发送:取消拦截+快递号(多个使用任意分隔符)\n例:取消拦截7xxxx1,7xxxx2\n如需更多帮助发送help查看");
|
||
return $backMsg;
|
||
}
|
||
}
|
||
public function get_express_ecnotes(){
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$params = $this->request->post();
|
||
$POSTCODE = $params["POSTCODE"]??"";
|
||
$list = $this->ExpressconfigModel->field("NOTES as name,ID as value")->where(["WAREHOUSEID"=>$WAREHOUSEID,"CODE"=>$POSTCODE,"DISPLAYFLAG"=>0])->select();
|
||
return json($list);
|
||
}
|
||
private function sendToExplessRoom($warehoueId,$orders,$postCode,$methodName){
|
||
try {
|
||
|
||
$this->redis->select(5);
|
||
$methodName = preg_replace("/\b[\w-]{13,}\b/", "", $methodName);
|
||
$jiekous = [];
|
||
foreach($orders as $r){
|
||
$key = $r[1] ? (explode("|", (string)$r[1])[1] ?? 'default') : 'default';
|
||
if(array_key_exists($key, $jiekous)){
|
||
array_push($jiekous[$key],$r[0]);
|
||
}else{
|
||
$jiekous[$key] = [$r[0]];
|
||
}
|
||
}
|
||
|
||
$msg = [];
|
||
foreach ($jiekous as $key => $r){
|
||
switch($this->SOURCE){
|
||
case "wx":
|
||
$RoomsModel = new \app\common\model\Rooms;
|
||
break;
|
||
case "qiwe":
|
||
$RoomsModel = $this->qiweRoomsModel;
|
||
break;
|
||
default:
|
||
$key = "";
|
||
}
|
||
$relay = $RoomsModel->where(["WAREHOUSEID"=>$warehoueId,"POSTCODE"=>$postCode,"type"=>3])->where("ECNOTES like '%{$key}%'");
|
||
Log::error("接口:{$methodName},快递:{$postCode},ECNOTES:{$key},查询的SQL:".json_encode($relay->getLastSql()));
|
||
if($methodName=="揽收"){
|
||
$relay->where(["islanshow"=>1]);
|
||
}else{
|
||
$relay->where(["islanshow"=>0]);
|
||
}
|
||
$relay = $relay->order("islanshow","asc")->find();
|
||
if(!$relay){
|
||
$relay = $RoomsModel->where(["WAREHOUSEID"=>$warehoueId,"POSTCODE"=>$postCode,"type"=>3])->order("islanshow","asc")->find();
|
||
}
|
||
Log::error("最后的last2".json_encode($relay->getLastSql()));
|
||
if($relay){
|
||
$relayMsg = $this->to($relay["room_id"],implode("\n", $r)."\n{$methodName}");
|
||
$msg = array_merge($msg,$relayMsg);
|
||
}
|
||
}
|
||
} catch (Exception $e) {
|
||
Log::error($e);
|
||
$this->redis->set("keys_error",json_encode($e));
|
||
}
|
||
return $msg;
|
||
}
|
||
private function yituihui($from,$postnums,$msgid,$info=""){
|
||
if(count($postnums)>0){
|
||
$msgs = [];
|
||
$text = "";
|
||
$posttype = [];
|
||
foreach($postnums as $postnum){
|
||
$status = 0;
|
||
$order = $this->getOrderInfoByPostnum($postnum,$from);
|
||
if($order){
|
||
if($order["status"]==1){
|
||
$status = $order["FLAG"]==1 ?1:2;
|
||
}else{
|
||
$status = 3;
|
||
}
|
||
}
|
||
if($status>0){
|
||
if(array_key_exists($order["POSTCODE"], $posttype)){
|
||
array_push($posttype[$order["POSTCODE"]],[$postnum,$order['ECNOTES']]);
|
||
}else{
|
||
$posttype[$order["POSTCODE"]] = [[$postnum,$order['ECNOTES']]];
|
||
}
|
||
}
|
||
switch($status){
|
||
case 0:
|
||
$text.="运单号:".$postnum." 未找到运单号,劳烦@客服处理\n";
|
||
break;
|
||
default:
|
||
$BackrecordModel = new \app\common\model\wms\Backrecord;
|
||
|
||
$orderitems = $BackrecordModel->alias('a')->field('`POSTNUM`,`YDFLAG`,a.`COUNT` as COUNT,a.`NOTES` as NOTES,`STORENAME`,a.`STATUS` as STATUS,`SOURCEORDERCODE`,a.`POSTNAME` as POSTNAME,goods.NAME AS GOODSNAME,stock.BARCODE AS BARCODE,stock.STYLE AS STYLE,stock.COLOR AS COLOR ')->where("a.POSTNUM","like","%{$postnum}%")->join('yj_stock stock','stock.STOCKID=a.STOCKID')->join('yj_goods goods','goods.GOODSID = stock.GOODSID')->select();
|
||
|
||
$BackrecordcustomerModel = new \app\common\model\wms\Backrecordcustomer;
|
||
$data = $BackrecordModel->where(["POSTNUM"=>$postnum])->select();
|
||
if($data){
|
||
|
||
$datainfos = $this->getBackinfos($orderitems,0);
|
||
$text.="运单号:".$postnum." 已退回仓库\n{$datainfos}";
|
||
$text.="--------------------------------------------\n";
|
||
}else{
|
||
$text.="运单号:".$postnum." 未退回仓库,如有退回,拆包后将通知。\n";
|
||
$BackrecordcustomerModel->save(["POSTNUM"=>$postnum,"STOREID"=>$from["storeid"],"createTime"=>time(),"notified"=>0]);
|
||
}
|
||
}
|
||
}
|
||
$backMsg = $this->backMsg($from,$text);
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
return $msgs;
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"如需查询运单号是否已退回,发送:查询退回+快递号(多个使用任意分隔符)\n例:查询退回7xxxx1,7xxxx2\n如需更多帮助发送help查看");
|
||
return $backMsg;
|
||
}
|
||
}
|
||
private function Backrecord($from,$postnums,$msgid,$info=""){
|
||
$BackrecordModel = new \app\common\model\wms\Backrecord;
|
||
$ListsbackrecordModel = new \app\common\model\backrecord\Lists;
|
||
$BackrecordbackModel = new \app\common\model\wms\Backrecordback;
|
||
$BackrecordunknowModel = new \app\common\model\wms\Backrecordunknow;
|
||
$BackrecordcustomerModel = new \app\common\model\wms\Backrecordcustomer;
|
||
if(count($postnums)>0){
|
||
$msgs = [];
|
||
foreach($postnums as $postnum){
|
||
$orderitems = $BackrecordModel->alias('a')->field('`POSTNUM`,`YDFLAG`,a.`COUNT` as COUNT,a.`NOTES` as NOTES,`STORENAME`,a.`STATUS` as STATUS,`SOURCEORDERCODE`,a.`POSTNAME` as POSTNAME,goods.NAME AS GOODSNAME,stock.BARCODE AS BARCODE,stock.STYLE AS STYLE,stock.COLOR AS COLOR ')->where(["a.STOREID"=>$from["storeid"]])->where("a.POSTNUM","like","%{$postnum}%")->join('yj_stock stock','stock.STOCKID=a.STOCKID')->join('yj_goods goods','goods.GOODSID = stock.GOODSID')->select();
|
||
|
||
$orderitems2 = $BackrecordunknowModel->alias('a')->field('`POSTNUM`,`YDFLAG`,a.`COUNT` as COUNT,a.`NOTES` as NOTES,`STORENAME`,a.`STATUS` as STATUS,`SOURCEORDERCODE`,"未知" as POSTNAME,"无记录产品" AS GOODSNAME,`BARCODE`,"" AS STYLE,"" AS COLOR')->where(["a.STOREID"=>$from["storeid"]])->where("a.POSTNUM","like","%{$postnum}%")->select();
|
||
if(count($orderitems)==0 && count($orderitems2)==0){
|
||
$errRecordline = $BackrecordunknowModel->where(["POSTNUM"=>$postnum])->select();
|
||
if(count($errRecordline)>0){
|
||
$datainfos = $this->getBackinfos($errRecordline,1);
|
||
//待处理退件根据货主过滤后转入退件登记信息
|
||
|
||
$BackrecordcustomerModel->save(["POSTNUM"=>$postnum,"STOREID"=>$from["storeid"],"createTime"=>time(),"notified"=>1]);
|
||
$text = "{$postnum}认领成功,登记信息为:\n{$datainfos}";
|
||
$time = time();
|
||
foreach($errRecordline as $r){
|
||
$r->save(["out"=>1,"outTime"=>$time,"STOREID"=>$from["storeid"]]);
|
||
}
|
||
}else{
|
||
$has = $BackrecordcustomerModel->where(["POSTNUM"=>$postnum])->find();
|
||
if($has){
|
||
$text = "${postnum}尚未退回仓库,已经在未退回表中登记,等待包裹退件登记后,将自动发送通知包裹信息";
|
||
}else{
|
||
$BackrecordcustomerModel->save(["POSTNUM"=>$postnum,"STOREID"=>$from["storeid"],"createTime"=>time(),"notified"=>0]);
|
||
$text = "{$postnum}尚未退回仓库,已在未退回表中登记成功,等待包裹退件登记后,将自动发送通知包裹信息";
|
||
}
|
||
}
|
||
|
||
}else{
|
||
$orderitems = array_merge($orderitems, $orderitems2);
|
||
$datainfos = $this->getBackinfos($orderitems,0);
|
||
$has = $BackrecordcustomerModel->where(["POSTNUM"=>$postnum])->find();
|
||
if(!$has){
|
||
$BackrecordcustomerModel->save(["POSTNUM"=>$postnum,"STOREID"=>$from["storeid"],"createTime"=>time(),"notified"=>1]);
|
||
}
|
||
$text = "{$postnum}在已退件中登记,登记信息为:\n{$datainfos}";
|
||
}
|
||
$backMsg = $this->backMsg($from,$text);
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
}
|
||
return $msgs;
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"如需登记非原单退回运单号,发送:退回登记+快递号(多个使用任意分隔符)\n例:退回登记7xxxx1,7xxxx2\n退回登记后如果天豹云仓收到退回件做退件登记后,将会发送拆包通知,如需更多帮助发送help查看");
|
||
return $backMsg;
|
||
}
|
||
}
|
||
private function getBackinfos($data,$type){
|
||
$text = "";
|
||
$yesorno = [
|
||
"否",
|
||
"是"
|
||
];
|
||
switch($type){
|
||
case 0:
|
||
$text = "\n运单号:{$data[0]['POSTNUM']}\n是否原单:{$yesorno[$data[0]['YDFLAG']]}\n交易单号:{$data[0]['SOURCEORDERCODE']}\n快递:{$data[0]['POSTNAME']}\n店铺名称:{$data[0]['STORENAME']}\n天豹云仓收到且已拆包,拆包明细为:\n";
|
||
foreach ($data as $r){
|
||
$text.="商品名称:{$r['GOODSNAME']}{$r['STYLE']}{$r['COLOR']}\n条码:{$r['BARCODE']}\n数量:{$r['COUNT']}\n是否破损:{$yesorno[$r['STATUS']]}\n\n";
|
||
}
|
||
$TuijianModel = new \app\common\model\file\Tuijian;
|
||
$splist = $TuijianModel->where(["name"=>$data[0]['POSTNUM']])->select();
|
||
$text.="退件录像地址为:\n";
|
||
foreach($splist as $r){
|
||
$text.="http://file.gztbyc.com{$r['path']}\n";
|
||
}
|
||
$text.="拆包视频保存会有延迟,可以在稍后发送:查退回+运单号,查询";
|
||
break;
|
||
case 1:
|
||
break;
|
||
}
|
||
return $text;
|
||
}
|
||
|
||
private function lanjie($from,$postnums,$msgid,$info=""){
|
||
if(count($postnums)>0){
|
||
$msgs = [];
|
||
$text = "";
|
||
$posttype = [];
|
||
foreach($postnums as $postnum){
|
||
$status = 0;
|
||
$order = $this->getOrderInfoByPostnum($postnum,$from);
|
||
if($order){
|
||
if($order["status"]==1){
|
||
if($order['PRINTTIMES']==1){
|
||
if(strpos($order["GRABNUM"],"B")!==false){
|
||
if($order["PLSENDFLAG"]==0){
|
||
$status = 1;
|
||
}else{
|
||
$status = 2;
|
||
}
|
||
}else{
|
||
if($order["WEIGHT"]>0){
|
||
$status = 2;
|
||
}else{
|
||
$status = 1;
|
||
}
|
||
}
|
||
}else{
|
||
$status = 4;
|
||
}
|
||
}else{
|
||
$status = 3;
|
||
}
|
||
}
|
||
if($status>0){
|
||
if(array_key_exists($order["POSTCODE"], $posttype)){
|
||
array_push($posttype[$order["POSTCODE"]],[$postnum,$order['ECNOTES']]);
|
||
}else{
|
||
$posttype[$order["POSTCODE"]] = [[$postnum,$order['ECNOTES']]];
|
||
}
|
||
}
|
||
$redis = new \Redis();
|
||
$redis->connect('127.0.0.1', 6379);
|
||
$redis->auth('qwe2019@');
|
||
$redis->select(2);
|
||
switch($status){
|
||
case 0:
|
||
$text.="运单号:".$postnum." 未找到运单号,劳烦@客服处理\n";
|
||
break;
|
||
case 1:
|
||
$this->updateInterceptorder($order["ID"],0);
|
||
$lsnjieres = $this->createExceptionWmsOrder(12,$order["ID"],"群发起拦截",$postnum);
|
||
|
||
if($order["POSTCODE"]=="p02"){//申通快递自动API拦截
|
||
$res = json_decode($this->create_standard_sto($postnum, 1), true);
|
||
if(isset($res['data']["errorReason"])){
|
||
$text .= "运单号:" . $postnum . "运方拦截接口返回:" . $res["data"]["errorReason"] . ",已生成工单,已同时通知快递拦截处理,劳烦通知顾客拒收\n";
|
||
}else{
|
||
$text.="运单号:".$postnum." ,已生成工单,已同时通知快递拦截处理,劳烦通知顾客拒收,如需继续发货,请发送取消拦截+快递号继续发货\n";
|
||
}
|
||
}else{
|
||
$text.="运单号:".$postnum." 已生成工单,已同时通知快递拦截处理,劳烦通知顾客拒收,如需继续发货,请发送取消拦截+快递号继续发货\n";
|
||
}
|
||
break;
|
||
case 2:
|
||
$lsnjieres = $this->createExceptionWmsOrder(12,$order["ID"],"群发起拦截",$postnum);
|
||
if($order["POSTCODE"]=="p02"){//申通快递自动API拦截
|
||
$res = json_decode($this->create_standard_sto($postnum, 1), true);
|
||
if(isset($res['data']["errorReason"])){
|
||
$text .= "运单号:" . $postnum . "运方拦截接口返回:" . $res["data"]["errorReason"] . ",已生成工单,已同时通知快递拦截处理,劳烦通知顾客拒收,如需继续发货,请发送取消拦截+快递号继续发货\n";
|
||
}else{
|
||
$text.="运单号:".$postnum." 已生成工单,已同时通知快递拦截处理,劳烦通知顾客拒收,如需继续发货,请发送取消拦截+快递号继续发货\n";
|
||
}
|
||
}else{
|
||
$text.="运单号:".$postnum." 已生成工单,已同时通知快递拦截处理,劳烦通知顾客拒收,如需继续发货,请发送取消拦截+快递号继续发货\n";
|
||
}
|
||
break;
|
||
case 3:
|
||
$lsnjieres = $this->createExceptionWmsOrder(12,$order["ID"],"群发起拦截",$postnum);
|
||
if($order["POSTCODE"]=="p02"){//申通快递自动API拦截
|
||
$res = json_decode($this->create_standard_sto($postnum, 1), true);
|
||
if(isset($res['data']["errorReason"])){
|
||
$text .= "运单号:" . $postnum . "运方拦截接口返回:" . $res["data"]["errorReason"] . ",已生成工单,已同时通知快递拦截处理,劳烦通知顾客拒收,如需继续发货,请发送取消拦截+快递号继续发货\n";
|
||
}else{
|
||
$text.="运单号:".$postnum." 已生成工单,已同时通知快递拦截处理,劳烦通知顾客拒收,如需继续发货,请发送取消拦截+快递号继续发货\n";
|
||
}
|
||
}else{
|
||
$text.="运单号:".$postnum." 已生成工单,已同时通知快递拦截处理,劳烦通知顾客拒收,如需继续发货,请发送取消拦截+快递号继续发货\n";
|
||
}
|
||
break;
|
||
case 4:
|
||
$this->updateInterceptorder($order["ID"],0);
|
||
$this->pushLanjie($order);
|
||
$text.="运单号:".$postnum." 已生成工单,已同时通知快递拦截处理,劳烦通知顾客拒收,如需继续发货,请发送取消拦截+快递号继续发货\n";
|
||
break;
|
||
}
|
||
}
|
||
foreach ($posttype as $k => $r){
|
||
if($k=="p01"){
|
||
$res = $this->create_standard_ytos($r, 1);
|
||
$redis->set('lanjieyto',json_encode([$r,$res]));
|
||
}
|
||
if($k=="p04"){
|
||
$this->create_standard_zto($r, 1);
|
||
}
|
||
if($k=="p32"){//申通快递自动API拦截
|
||
$res = $this->create_standard_jtexpress($r, 1);
|
||
}
|
||
$relayMsg = $this->sendToExplessRoom($from['WAREHOUSEID'],$r,$k,"拦截");
|
||
array_push($msgs,$relayMsg);
|
||
}
|
||
if($info=="test"){
|
||
$text = $text.json_encode($lsnjieres);
|
||
}
|
||
$backMsg = $this->backMsg($from,$text);
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
|
||
|
||
return $msgs;
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"如需拦截运单号,发送:拦截+快递号(多个使用任意分隔符)\n例:拦截7xxxx1,7xxxx2\n如需更多帮助发送help查看");
|
||
return $backMsg;
|
||
}
|
||
}
|
||
public function trace_test(){
|
||
$from = [
|
||
"memname"=>"test",
|
||
"memid"=>"test",
|
||
"fromid"=>"test",
|
||
"postcode"=>"test",
|
||
"nickName"=>"test",
|
||
"isMe"=>true
|
||
];
|
||
$res = $this->trace($from,["773361284774644"],"轨迹773361284774644");
|
||
return json($res);
|
||
}
|
||
private function trace($from,$postnums,$msgid,$info=""){
|
||
if(count($postnums)>0){
|
||
$msgs = [];
|
||
foreach($postnums as $postnum){
|
||
$status = 0;
|
||
$text = "";
|
||
$order = $this->getOrderInfoByPostnum($postnum,$from);
|
||
if($order){
|
||
$status = 1;
|
||
}
|
||
switch($status){
|
||
case 0:
|
||
$text.="运单号:".$postnum." 未找到运单号,劳烦@客服处理\n";
|
||
break;
|
||
default:
|
||
$text.="运单号:".$postnum." \n";
|
||
$text.= $this->queryTask($order);
|
||
}
|
||
$backMsg = $this->backMsg($from,$text);
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
}
|
||
return $msgs;
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"查询运单号轨迹,发送:轨迹+快递号(多个使用任意分隔符)\n例:轨迹7xxxx1,7xxxx2\n如需更多帮助发送help查看");
|
||
return $backMsg;
|
||
}
|
||
}
|
||
private function queryTask($order){
|
||
$url = "http://express.gztbyc.com/query_tasks";
|
||
$requsetData = [
|
||
$order["POSTNUM"]."|".$order["ID"]."|".$order["POSTCODE"]
|
||
];
|
||
$header = ['Content-Type: application/json'];
|
||
$options = [
|
||
CURLOPT_HTTPHEADER => $header
|
||
];
|
||
$urlEncodedString = json_encode($requsetData);
|
||
$res = Http::post($url,$urlEncodedString,$options);
|
||
return $res;
|
||
}
|
||
private function lanshou($from,$postnums,$msgid,$info=""){
|
||
if(count($postnums)>0){
|
||
$redis = new \Redis();
|
||
$redis->connect('47.100.78.112', 6379);
|
||
$redis->auth('qwe2019');
|
||
$redis->select(2);
|
||
$msgs = [];
|
||
$text = "";
|
||
$posttype = [];
|
||
foreach($postnums as $postnum){
|
||
$status = 0;
|
||
$order = $this->getOrderInfoByPostnum($postnum,$from);
|
||
if($order){
|
||
if($order["status"]==1){
|
||
$status = $order["FLAG"]==1 || $order["STATUS"]==5?1:2;
|
||
}else{
|
||
$status = 3;
|
||
$status = $order["FLAG"]==1 || $order["STATUS"]==5?1:2;
|
||
}
|
||
}
|
||
if($status>1){
|
||
if(array_key_exists($order["POSTCODE"], $posttype)){
|
||
array_push($posttype[$order["POSTCODE"]],[$postnum,$order['ECNOTES']]);
|
||
}else{
|
||
$posttype[$order["POSTCODE"]] = [[$postnum,$order['ECNOTES']]];
|
||
}
|
||
}
|
||
switch($status){
|
||
case 0:
|
||
$text.="运单号:".$postnum." 未找到运单号,劳烦@客服处理\n";
|
||
break;
|
||
case 1:
|
||
$text.="运单号:".$postnum." 已取消或已拦截,不揽收\n";
|
||
break;
|
||
default:
|
||
$this->createExceptionWmsOrder(0,$order["ID"],"客户群自动揽收",$postnum);
|
||
$text.="运单号:".$postnum." 已提交揽收,等待揽收\n";
|
||
}
|
||
}
|
||
foreach ($posttype as $k => $r){
|
||
$relayMsg = $this->sendToExplessRoom($from['WAREHOUSEID'],$r,$k,"揽收");
|
||
if($k=="p02" || $k=="p01" || $k=="p03"){
|
||
//申通快递自动API揽收
|
||
foreach($r as $rr){
|
||
$dd = $redis->lpush("GalaxyReceive_5400",$rr[0]);
|
||
}
|
||
}
|
||
}
|
||
$backMsg = $this->backMsg($from,$text);
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
$redis->close();
|
||
return $msgs;
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"如需揽收运单号,发送:揽收+快递号(多个使用任意分隔符)\n例:揽收7xxxx1,7xxxx2\n如需更多帮助发送help查看");
|
||
return $backMsg;
|
||
}
|
||
}
|
||
private function createBackRecordByPostnum($from,$postnums,$msgid,$info=""){
|
||
$msg = "";
|
||
foreach ($postnums as $postnum){
|
||
$order = $this->getOrderInfoByPostnum($postnum,$from);
|
||
/*if($order){*/
|
||
$data = Wsdl::webservice([$order["WAREHOUSEID"]?$order["WAREHOUSEID"]:5400,106300,$postnum],'createBackRecordByPostnum');
|
||
if($data==1){
|
||
$msg.=$postnum."登记成功\n";
|
||
}else{
|
||
$msg.=$postnum."登记失败\n".json_encode([$order["WAREHOUSEID"]?$order["WAREHOUSEID"]:5400,106300,$postnum])."\n";
|
||
}
|
||
/*}else{
|
||
$msg.=$postnum."无记录\n";
|
||
}*/
|
||
}
|
||
$backMsg = $this->backMsg($from,$msg);
|
||
return $backMsg;
|
||
}
|
||
private function mb_str_split($string, $split_length = 1) {
|
||
$split_length = ($split_length <= 0) ? 1 : $split_length;
|
||
$result = [];
|
||
for ($i = 0; $i < mb_strlen($string, 'UTF-8'); $i += $split_length) {
|
||
$result[] = mb_substr($string, $i, $split_length, 'UTF-8');
|
||
}
|
||
return $result;
|
||
}
|
||
private function urgent($from,$postnums,$msgid,$info=""){//催件
|
||
if(count($postnums)>0){
|
||
$msgs = [];
|
||
$text = "";
|
||
$posttype = [];
|
||
foreach($postnums as $postnum){
|
||
$status = 0;
|
||
$order = $this->getOrderInfoByPostnum($postnum,$from);
|
||
if($order){
|
||
if($order["status"]==1){
|
||
$status = $order["FLAG"]==1 ?1:2;
|
||
}else{
|
||
$status = 3;
|
||
}
|
||
}
|
||
if($status>0){
|
||
$this->checkFail($order,1);
|
||
if(array_key_exists($order["POSTCODE"], $posttype)){
|
||
array_push($posttype[$order["POSTCODE"]],[$postnum,$order['ECNOTES']]);
|
||
}else{
|
||
$posttype[$order["POSTCODE"]] = [[$postnum,$order['ECNOTES']]];
|
||
}
|
||
}
|
||
switch($status){
|
||
case 0:
|
||
$text.="运单号:".$postnum." 未找到运单号,劳烦@客服处理\n";
|
||
break;
|
||
default:
|
||
$text.="运单号:".$postnum." 已催件,等待物流更新\n";
|
||
}
|
||
|
||
}
|
||
foreach ($posttype as $k => $r){
|
||
$relayMsg = $this->sendToExplessRoom($from['WAREHOUSEID'],$r,$k,"催件");
|
||
array_push($msgs,$relayMsg);
|
||
if($k=="p02"){
|
||
foreach ($r as $kk){
|
||
$res = $this->cuijian($kk,1);
|
||
}
|
||
}
|
||
}
|
||
$backMsg = $this->backMsg($from,$text);
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
return $msgs;
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"如需催件运单号,发送:催件+快递号(多个使用任意分隔符)\n例:催件7xxxx1,7xxxx2\n如需更多帮助发送help查看");
|
||
return $backMsg;
|
||
}
|
||
}
|
||
|
||
|
||
private function weight($from,$postnums,$msgid,$info=""){
|
||
if(count($postnums)>0){
|
||
$msgs = [];
|
||
$text = "";
|
||
$posttype = [];
|
||
foreach($postnums as $postnum){
|
||
$status = 0;
|
||
$order = $this->getOrderInfoByPostnum($postnum,$from);
|
||
if($order){
|
||
$type = strpos($order["GRABNUM"],"B")!==false?"准确":"准确";
|
||
$text.="运单号:".$postnum."(库内".$type."称重:".$order['WEIGHT']."克)\n";
|
||
}else{
|
||
$text.="运单号:".$postnum."没找到运单\n";
|
||
}
|
||
}
|
||
$backMsg = $this->backMsg($from,$text);
|
||
return $backMsg;
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"如需查询运单号库内称重,发送:称重+快递号(多个使用任意分隔符)\n例:称重7xxxx1,7xxxx2\n如需更多帮助发送help查看");
|
||
return $backMsg;
|
||
}
|
||
}
|
||
private function dabaoVideo($from,$postnums,$msgid,$info=""){
|
||
$Expressmodel = new \app\common\model\wms\Express;
|
||
if(count($postnums)>0){
|
||
$msgs = [];
|
||
$text = "";
|
||
$posttype = [];
|
||
foreach($postnums as $postnum){
|
||
$status = 0;
|
||
$order = $this->getOrderInfoByPostnum($postnum,$from);
|
||
$order_ck = $this->getCkOrderInfoByCode($postnum,$from);
|
||
if($order){
|
||
$text.="运单号:{$postnum}\n";
|
||
$dabaoModel = new \app\common\model\file\Dabao;
|
||
$data = $dabaoModel->where("name='".$postnum."' or name='".$order["GRABNUM"]."'")->find();
|
||
if($data){
|
||
$text.="视频地址:http://file.gztbyc.com/public{$data["path"]}\n";
|
||
}else{
|
||
//查找操作记录
|
||
$isGrab = strpos($order["GRABNUM"],"B")!==false?1:0;
|
||
if($isGrab){
|
||
$work = $this->Worksmodel->where(['grabnum'=>$order["GRABNUM"]])->where("dabaos>0")->find();
|
||
}else{
|
||
$work = $this->Worksmodel->where(['POSTNUM'=>$postnum])->where("dabaos>0")->find();
|
||
}
|
||
if(!$work){
|
||
$text.="没有找到操作记录\n";
|
||
}else{
|
||
$this->reRecord($from['WAREHOUSEID'],$work['id'],$msgid);
|
||
$text.="已提交到后台重新录制,录制完成后通知";
|
||
}
|
||
}
|
||
}elseif($order_ck){
|
||
$text.="出库单:{$order_ck['SOURCEID']}\n";
|
||
$dabaoModel = new \app\common\model\file\Dabao;
|
||
$datas = $dabaoModel->where(["name"=>$order_ck["ID"]])->group("path")->select();
|
||
if($datas){
|
||
$text.="视频地址:\n";
|
||
foreach ($datas as $data){
|
||
$text.="http://file.gztbyc.com/public{$data["path"]}\n";
|
||
}
|
||
}else{
|
||
if(!$order_ck['packer_name']){
|
||
$text.="没有打包记录\n";
|
||
}else{
|
||
$this->reRecord2($from['WAREHOUSEID'],$order_ck['pack_id'],$msgid);
|
||
$text.="已提交到后台重新录制,录制完成后通知";
|
||
}
|
||
}
|
||
}else{
|
||
$text.="运单号:".$postnum."没找到运单\n";
|
||
}
|
||
}
|
||
$backMsg = $this->backMsg($from,$text);
|
||
return $backMsg;
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"如需查询运单号打包视频,发送:打包视频+快递号(多个使用任意分隔符)\n例:打包视频7xxxx1,7xxxx2\n如需更多帮助发送help查看");
|
||
return $backMsg;
|
||
}
|
||
}
|
||
private function reRecord($WAREHOUSEID,$workId,$msgId){
|
||
$redis = new \Redis();
|
||
$redis->connect('47.100.78.112', 6379);
|
||
$redis->auth('qwe2019');
|
||
$redis->select(3);
|
||
$redis->lpush("ware:{$WAREHOUSEID}:reRecord",json_encode([$workId,$msgId]));
|
||
}
|
||
private function reRecord2($WAREHOUSEID,$workId,$msgId){
|
||
$redis = new \Redis();
|
||
$redis->connect('47.100.78.112', 6379);
|
||
$redis->auth('qwe2019');
|
||
$redis->select(3);
|
||
$redis->lpush("ware:{$WAREHOUSEID}:reRecord2",json_encode([$workId,$msgId]));
|
||
}
|
||
private function find($from,$postnums,$msgid,$info=""){
|
||
$Expressmodel = new \app\common\model\wms\Express;
|
||
if(count($postnums)>0){
|
||
$msgs = [];
|
||
$text = "";
|
||
$posttype = [];
|
||
foreach($postnums as $postnum){
|
||
$status = 0;
|
||
$order = $this->getOrderInfoByPostnum($postnum,$from);
|
||
if($order){
|
||
$text.="运单号:{$postnum}\n";
|
||
$text.="波次号:{$order["GRABNUM"]}\n";
|
||
$text.="平台单号:{$order["SOURCEORDERCODE"]}\n";
|
||
$OPERATERECORDS = explode("|",$order["OPERATERECORDS"]);
|
||
$text.="操作记录:\n";
|
||
foreach ($OPERATERECORDS as $r){
|
||
$text.="{$r}\n";
|
||
}
|
||
$text.="店铺:{$order["STORENAME"]}\n";
|
||
$text.="称重重量:{$order["WEIGHT"]}\n";
|
||
$text.="SKU:\n";
|
||
$ITEMS = explode("|",$order["ITEMS"]);
|
||
foreach ($ITEMS as $r){
|
||
$text.="{$r}\n";
|
||
}
|
||
$hasChild = $Expressmodel->where(["ORIGINPOSTNUM"=>$postnum])->select();
|
||
if($hasChild){
|
||
$text.="子单号:\n";
|
||
foreach($hasChild as $r){
|
||
$text.="{$r["POSTNUM"]}\n";
|
||
}
|
||
}
|
||
}else{
|
||
$text.="运单号:".$postnum."没找到运单\n";
|
||
}
|
||
}
|
||
$backMsg = $this->backMsg($from,$text);
|
||
return $backMsg;
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"如需查询运单号订单信息,发送:订单数据查询+快递号(多个使用任意分隔符)\n例:称重7xxxx1,7xxxx2\n如需更多帮助发送help查看");
|
||
return $backMsg;
|
||
}
|
||
}
|
||
private function findPostnum($from,$postnums,$msgid,$info=""){
|
||
if(count($postnums)>0){
|
||
$msgs = [];
|
||
$text = "";
|
||
$posttype = [];
|
||
foreach($postnums as $postnum){
|
||
$status = 0;
|
||
$order = $this->getOrderInfoByPostnum2($postnum,$from);
|
||
if($order){
|
||
$text.="运单号:".$postnum.json_encode($order)."\n";
|
||
}else{
|
||
$text.="运单号:".$postnum."没找到运单\n";
|
||
}
|
||
}
|
||
$backMsg = $this->backMsg($from,$text);
|
||
return $backMsg;
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"如需查询运单号订单信息,发送:快递号数据查询+快递号(多个使用任意分隔符)\n例:快递号数据查询7xxxx1,7xxxx2\n如需更多帮助发送help查看");
|
||
return $backMsg;
|
||
}
|
||
}
|
||
private function kucun($from,$postnums,$msgid,$info=""){
|
||
$skus = $this->getSkus($info);
|
||
if(count($skus)>0){
|
||
$msgs = [];
|
||
$text = "";
|
||
$posttype = [];
|
||
foreach($skus as $sku){
|
||
$status = 0;
|
||
$stock = $this->getSKUInfoBycode($sku,$from);
|
||
if($stock){
|
||
$text.="条码/SKU:".$sku."仅供参考可下单库存数:".$stock["COUNT"]."\n";
|
||
}else{
|
||
$text.="条码/SKU:".$sku."没找到SKU\n";
|
||
}
|
||
}
|
||
$backMsg = $this->backMsg($from,$text);
|
||
return $backMsg;
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"如需查询库存,发送:查库存+商品条码/SKU(多个使用任意分隔符)\n例:查库存69xxxx1,69xxxx2\n如需更多帮助发送help查看");
|
||
return $backMsg;
|
||
}
|
||
}
|
||
|
||
private function clearFail($from,$postnums,$msgid,$info=""){
|
||
$msgs = [];
|
||
$text = "";
|
||
$postnums = $this->getSkus($info);
|
||
if(count($postnums)==1){
|
||
$postnum = $postnums[0];
|
||
$lines = $this->FailorderModel->where(["GRABNUM"=>$postnum])->select();
|
||
foreach ($lines as $line){
|
||
$line->save(["out"=>1]);
|
||
}
|
||
$text.="已标记批次{$postnum}为非批量错误,后续将不再预警";
|
||
$backMsg = $this->backMsg($from,$text);
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"如需标记非批量错误波次,发送:非批次错误+波次号\n例:非批次错误B11111111\n如需更多帮助发送help查看");
|
||
return $backMsg;
|
||
}
|
||
return $msgs;
|
||
}
|
||
private function changePostcode($from,$postnums,$info,$postcode,$postname){
|
||
$msgs = [];
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
|
||
$WAREHOUSEMODEL = new \app\common\model\Warehouse;
|
||
$postnums = $this->getsourceOrderCode($info);
|
||
if(count($postnums)>0){
|
||
foreach ($postnums as $postnum){
|
||
$text = "";
|
||
Db::startTrans();
|
||
try {
|
||
if(isset($from["isMe"])){
|
||
$where = '(SOURCEORDERCODE = "'.$postnum.'")';
|
||
}else{
|
||
$where = '(SOURCEORDERCODE = "'.$postnum.'") and STOREID='.$from["storeid"];
|
||
}
|
||
$order = $orderModel->where($where)->where(["DISPLAYFLAG"=>0])->lock()->find();
|
||
if($order){
|
||
if($order["POSTFLAG"]==1){
|
||
$text = "平台单号:{$postnum} 已分配快递号,不能修改\n";
|
||
}else if($order["FLAG"]==1){
|
||
$text = "平台单号:{$postnum} 已拦截,不能修改\n";
|
||
}else if($order["ISLOCK"]==1){
|
||
$text = "平台单号:{$postnum} 已锁定,不能修改\n";
|
||
}else if($order["POSTCODE"]==$postcode){
|
||
$text = "平台单号:{$postnum} 已是{$postname}快递\n";
|
||
}else{
|
||
$current_time = date("Y年m月d日 H:i:s");
|
||
$OPERATERECORDSTEXT = $order["OPERATERECORDS"]."更改快递为{$postname};{$current_time};客服机器人|";
|
||
$order->save(["POSTCODE"=>$postcode,"POSTNAME"=>"{$postname}","OPERATERECORDS"=>$OPERATERECORDSTEXT]);
|
||
$text = "平台单号:{$postnum} 已修改为{$postname}快递\n";
|
||
}
|
||
}else{
|
||
$text = "平台单号:{$postnum} 未提交到天豹云仓的WMS系统\n";
|
||
}
|
||
Db::commit();
|
||
} catch (ValidateException|PDOException|Exception $e) {
|
||
Db::rollback();
|
||
$text = "平台单号:{$postnum} 修改快递失败,失败原因:$e\n";
|
||
}
|
||
$backMsg = $this->backMsg($from,$text);
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
}
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"如需修改订单快递类型为{$postname},发送:改{$postname}+平台交易单号 例:XXXXXXXX改{$postname}\n如需更多帮助发送help查看");
|
||
return $backMsg;
|
||
}
|
||
return $msgs;
|
||
}
|
||
|
||
private function tihuo2(){
|
||
$backMsg = $this->backMsg($from,"如需出库单绑定车牌号,发送出库单号+提货+车牌号");
|
||
return $backMsg;
|
||
}
|
||
private function myaddr($from,$postnums,$msgid,$info){
|
||
$backMsg = $this->backMsg($from,"地址:广东省广州市白云区钟落潭良沙二路32号天豹云仓供应链管理有限公司\n仓库电话:18665616691\n备用电话:18212332570\n\n送货一定要有纸质送货单,尽量不要放在货里面,方便清点数字\n送货单上应该有以下基本内容:产品名称,数量,客户名字,电话\n来货的车辆如果是大于或等于4米2的。货物要堆放到拖盘上面,并选择有尾板的车,否则会有卸货费。\n\n仓库收货时间:\n上午:10:00—12:00\n下午:13:00—18:00\n晚上:18:30—21:00\n其他时间需要送货请提前预约联系好");
|
||
return $backMsg;
|
||
}
|
||
private function changep01($from,$postnums,$msgid,$info){
|
||
$msgs = $this->changePostcode($from,$postnums,$info,"p01","圆通");
|
||
return $msgs;
|
||
}
|
||
private function changep02($from,$postnums,$msgid,$info){
|
||
$msgs = $this->changePostcode($from,$postnums,$info,"p02","申通");
|
||
return $msgs;
|
||
}
|
||
private function changep04($from,$postnums,$msgid,$info){
|
||
$msgs = $this->changePostcode($from,$postnums,$info,"p04","中通");
|
||
return $msgs;
|
||
}
|
||
private function changep32($from,$postnums,$msgid,$info){
|
||
$msgs = $this->changePostcode($from,$postnums,$info,"p32","极兔速递");
|
||
return $msgs;
|
||
}
|
||
private function changep03($from,$postnums,$msgid,$info){
|
||
$msgs = $this->changePostcode($from,$postnums,$info,"p03","韵达");
|
||
return $msgs;
|
||
}
|
||
private function changep05($from,$postnums,$msgid,$info){
|
||
$msgs = $this->changePostcode($from,$postnums,$info,"p05","顺丰");
|
||
return $msgs;
|
||
}
|
||
private function changep22($from,$postnums,$msgid,$info){
|
||
$msgs = $this->changePostcode($from,$postnums,$info,"p22","邮政小包");
|
||
return $msgs;
|
||
}
|
||
private function changep07($from,$postnums,$msgid,$info){
|
||
$msgs = $this->changePostcode($from,$postnums,$info,"p07","EMS");
|
||
return $msgs;
|
||
}
|
||
private function changep10($from,$postnums,$msgid,$info){
|
||
$msgs = $this->changePostcode($from,$postnums,$info,"p10","京东快递");
|
||
return $msgs;
|
||
}
|
||
|
||
private function createPostnum($from,$postnums,$msgid,$info=""){
|
||
$msgs = [];
|
||
$WAREHOUSEMODEL = new \app\common\model\Warehouse;
|
||
$postnums = $this->getsourceOrderCode($info);
|
||
if(count($postnums)>0){
|
||
foreach ($postnums as $postnum){
|
||
$text = "";
|
||
$order = $this->getOrderInfoBySourceOrderCode($postnum,$from);
|
||
if(isset($order["ID"])){
|
||
$ids = implode(",",[$order["ID"]]);
|
||
$WAREHOUSE = $WAREHOUSEMODEL->where(["WAREHOUSEID"=>$order["WAREHOUSEID"]])->find();
|
||
if($order["POSTNUM"] && $order["POSTFLAG"]){
|
||
$text.="平台单号:".$postnum." 已分配快递单号,运单号:{$order["POSTNUM"]}\n";
|
||
if($order["SYNFLAG"]){
|
||
$text.="已回传单号。\n";
|
||
}else{
|
||
$text.="执行回传任务...\n";
|
||
try {
|
||
$data = Wsdl::webservice([$WAREHOUSE["WAREHOUSEID"],intval($WAREHOUSE["operatorID"]),$ids],'synOrder');
|
||
$text.="回传任务结束,正在检查...\n";
|
||
$order = $this->getOrderInfoBySourceOrderCode($postnum,$from);
|
||
if($order["SYNFLAG"]){
|
||
$text.="回传单号成功。\n";
|
||
}else{
|
||
$text.="回传单号失败,等待人工处理。\n";
|
||
}
|
||
} catch (Exception $e ) {
|
||
|
||
}
|
||
}
|
||
}else{
|
||
$text.="平台单号:".$postnum." 未分配快递单号,开始分配...\n";
|
||
try {
|
||
$data = Wsdl::webservice([$WAREHOUSE["WAREHOUSEID"],intval($WAREHOUSE["operatorID"]),$ids],'createPostNum');
|
||
} catch (Exception $e ) {
|
||
}
|
||
$text.="分配任务结束,正在检查单号...\n";
|
||
$order = $this->getOrderInfoBySourceOrderCode($postnum,$from);
|
||
if($order["POSTNUM"] && $order["POSTFLAG"]){
|
||
$text.="分配运单号成功,运单号:{$order["POSTNUM"]},执行回传任务...\n";
|
||
try {
|
||
$data = Wsdl::webservice([$WAREHOUSE["WAREHOUSEID"],intval($WAREHOUSE["operatorID"]),$ids],'synOrder');
|
||
$text.="回传任务结束,正在检查...\n";
|
||
$order = $this->getOrderInfoBySourceOrderCode($postnum,$from);
|
||
if($order["SYNFLAG"]){
|
||
$text.="回传单号成功。\n";
|
||
}else{
|
||
$text.="回传单号失败,等待人工处理。\n";
|
||
}
|
||
} catch (Exception $e ) {
|
||
|
||
}
|
||
}else{
|
||
$text.="分配运单号失败,等待人工处理";
|
||
}
|
||
}
|
||
}else{
|
||
$text.="平台单号:".$postnum." 未提交到天豹云仓的WMS系统\n";
|
||
}
|
||
$backMsg = $this->backMsg($from,$text);
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
}
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"如需出单,发送:出单+平台交易单号 例:XXXXXXXX出单\n如需更多帮助发送help查看");
|
||
return $backMsg;
|
||
}
|
||
return $msgs;
|
||
}
|
||
private function barcode($from,$postnums,$msgid,$info=""){
|
||
$msgs = [];
|
||
$barcode = $result = trim(preg_replace('/\s+/', ' ', str_replace("条码", "", $info)));
|
||
$this->redis->select(2);
|
||
$this->redis->set("barcode",$barcode);
|
||
$msg = $this->backFile($from,"https://ye4s.wms.gztbyc.com/barcode/{$barcode}/C128/%23000000/2/30.png");
|
||
return [$msg];
|
||
}
|
||
private function openD(){
|
||
$this->redis->select(2);
|
||
$data = $this->redis->set("5400_channelNum0",1);
|
||
}
|
||
private function openD2(){
|
||
$this->redis->select(2);
|
||
$data = $this->redis->set("5400_channelNum1",1);
|
||
}
|
||
public function testChangeAddr(){
|
||
$text = "772055960773146改地址:收件人:李女士(1989),联系电话:17876042671-1989,所在地址:山东省枣庄市薛城区新城街道国运花苑5号楼二单元 (拨打请输入分机号1989)";
|
||
|
||
}
|
||
private function changeAddr($from,$postnums,$msgid,$info=""){
|
||
$msgs = [];
|
||
$text = "";
|
||
$posttype = [];
|
||
if(count($postnums)>0){
|
||
if(count($postnums)>1){
|
||
$backMsg = $this->backMsg($from,"如需修改地址|修改电话|修改联系人|修改收件人,发送:修改地址|修改电话|修改联系人|修改收件人+信息 例:修改地址7xxxx1,广东省XXXXXXX\n暂时不支持多个运单号");
|
||
return $backMsg;
|
||
}
|
||
$postnum = $postnums[0];
|
||
$order = $this->getOrderInfoByPostnum($postnum,$from);
|
||
if($order){
|
||
if(array_key_exists($order["POSTCODE"], $posttype)){
|
||
array_push($posttype[$order["POSTCODE"]],[$postnum,$order['ECNOTES']]);
|
||
}else{
|
||
$posttype[$order["POSTCODE"]] = [[$postnum,$order['ECNOTES']]];
|
||
}
|
||
$text.="运单号:".$postnum." 信息已通知运方\n";
|
||
$backMsg = $this->backMsg($from,$text);
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
foreach ($posttype as $k => $r){
|
||
$relayMsg = $this->sendToExplessRoom($from['WAREHOUSEID'],$r,$k,$info);
|
||
array_push($msgs,$relayMsg);
|
||
}
|
||
}else{
|
||
$text.="运单号:".$postnum." 未找到运单号\n";
|
||
$backMsg = $this->backMsg($from,$text);
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
}
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"如需修改地址|修改电话|修改联系人|修改收件人,发送:修改地址|修改电话|修改联系人|修改收件人+信息 例:修改地址7xxxx1,广东省XXXXXXX\n如需更多帮助发送help查看");
|
||
return $backMsg;
|
||
}
|
||
return $msgs;
|
||
}
|
||
private function backfunction($from,$postnums,$msgid,$info=""){
|
||
$msgs = [];
|
||
$text = "";
|
||
$posttype = [];
|
||
if(count($postnums)>0){
|
||
$frist = true;
|
||
foreach($postnums as $postnum){
|
||
$order = $this->getOrderInfoByPostnum($postnum,$from);
|
||
if($order){
|
||
if(array_key_exists($order["POSTCODE"], $posttype)){
|
||
array_push($posttype[$order["POSTCODE"]],[$postnum,$order['ECNOTES']]);
|
||
}else{
|
||
$posttype[$order["POSTCODE"]] = [[$postnum,$order['ECNOTES']]];
|
||
}
|
||
$text.="运单号:".$postnum." 已通知运方\n";
|
||
}else{
|
||
$text.="运单号:".$postnum." 未找到运单号\n";
|
||
}
|
||
$frist = false;
|
||
}
|
||
foreach ($posttype as $k => $r){
|
||
$relayMsg = $this->sendToExplessRoom($from['WAREHOUSEID'],$r,$k,$info);
|
||
array_push($msgs,$relayMsg);
|
||
}
|
||
$backMsg = $this->backMsg($from,$text);
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"如需通知退回,发送:退回+快递号 例:退回7xxxx1\n如需更多帮助发送help查看");
|
||
return $backMsg;
|
||
}
|
||
return $msgs;
|
||
}
|
||
private function weishoudao($from,$postnums,$msgid,$info=""){
|
||
$msgs = [];
|
||
$text = "";
|
||
$posttype = [];
|
||
if(count($postnums)>0){
|
||
foreach($postnums as $postnum){
|
||
$order = $this->getOrderInfoByPostnum($postnum,$from);
|
||
if($order){
|
||
if(array_key_exists($order["POSTCODE"], $posttype)){
|
||
array_push($posttype[$order["POSTCODE"]],[$postnum,$order['ECNOTES']]);
|
||
}else{
|
||
$posttype[$order["POSTCODE"]] = [[$postnum,$order['ECNOTES']]];
|
||
}
|
||
$this->checkFail($order,0);
|
||
$text.="运单号:".$postnum." 核实签收记录工单并通知运方,等待运方处理。\n";
|
||
$this->createExceptionWmsOrder(1,$order["ID"],"客户群核实签收",$postnum);
|
||
$backMsg = $this->backMsg($from,$text);
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
foreach ($posttype as $k => $r){
|
||
$relayMsg = $this->sendToExplessRoom($from['WAREHOUSEID'],$r,$k,$info);
|
||
array_push($msgs,$relayMsg);
|
||
}
|
||
}else{
|
||
$text.="运单号:".$postnum." 未找到运单号\n";
|
||
$backMsg = $this->backMsg($from,$text);
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
}
|
||
}
|
||
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"如需核实签收,发送:核实签收+信息 例:核实签收7xxxx1,7XXXXXXX1\n如需更多帮助发送help查看");
|
||
$msgs = array_merge($msgs,$backMsg);
|
||
}
|
||
return $msgs;
|
||
}
|
||
private function less($from,$postnums,$msgid,$info=""){
|
||
if(count($postnums)>0){
|
||
$msgs = [];
|
||
$text = "";
|
||
$posttype = [];
|
||
foreach($postnums as $postnum){
|
||
$status = 0;
|
||
$order = $this->getOrderInfoByPostnum($postnum,$from);
|
||
if($order){
|
||
$text.="运单号:".$postnum."少发已登记工单,劳烦提供证据等待人工核实\n";
|
||
$this->createExceptionWmsOrder(7,$order["ID"],"客户群少发登记",$postnum);
|
||
$this->checkFail($order,2);
|
||
}else{
|
||
$text.="运单号:".$postnum."没找到运单\n";
|
||
}
|
||
}
|
||
$backMsg = $this->backMsg($from,$text);
|
||
return $backMsg;
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"如需提供少发售后服务,发送:少发+快递号(多个使用任意分隔符)\n例:少发7xxxx1,7xxxx2\n如需更多帮助发送help查看");
|
||
return $backMsg;
|
||
}
|
||
}
|
||
|
||
private function wrong($from,$postnums,$msgid,$info=""){
|
||
if(count($postnums)>0){
|
||
$msgs = [];
|
||
$text = "";
|
||
$posttype = [];
|
||
foreach($postnums as $postnum){
|
||
$status = 0;
|
||
$order = $this->getOrderInfoByPostnum($postnum,$from);
|
||
if($order){
|
||
$text.="运单号:".$postnum."错发已登记工单,劳烦提供证据等待人工核实\n";
|
||
$this->createExceptionWmsOrder(11,$order["ID"],"客户群错发登记",$postnum);
|
||
$this->checkFail($order,3);
|
||
}else{
|
||
$text.="运单号:".$postnum."没找到运单\n";
|
||
}
|
||
}
|
||
$backMsg = $this->backMsg($from,$text);
|
||
return $backMsg;
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"如需提供错发售后服务,发送:错发+快递号(多个使用任意分隔符)\n例:错发7xxxx1,7xxxx2\n如需更多帮助发送help查看");
|
||
return $backMsg;
|
||
}
|
||
}
|
||
private function damaged($from,$postnums,$msgid,$info=""){
|
||
if(count($postnums)>0){
|
||
$msgs = [];
|
||
$text = "";
|
||
$posttype = [];
|
||
foreach($postnums as $postnum){
|
||
$status = 0;
|
||
$order = $this->getOrderInfoByPostnum($postnum,$from);
|
||
if($order){
|
||
$text.="运单号:".$postnum."破损已登记工单,劳烦提供证据等待人工核实\n";
|
||
$this->createExceptionWmsOrder(6,$order["ID"],"客户群破损登记",$postnum);
|
||
}else{
|
||
$text.="运单号:".$postnum."没找到运单\n";
|
||
}
|
||
}
|
||
$backMsg = $this->backMsg($from,$text);
|
||
return $backMsg;
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"如需提供破损售后服务,发送:破损+快递号(多个使用任意分隔符)\n例:破损7xxxx1,7xxxx2\n如需更多帮助发送help查看");
|
||
return $backMsg;
|
||
}
|
||
}
|
||
private function multiple($from,$postnums,$msgid,$info=""){
|
||
if(count($postnums)>0){
|
||
$msgs = [];
|
||
$text = "";
|
||
$posttype = [];
|
||
foreach($postnums as $postnum){
|
||
$status = 0;
|
||
$order = $this->getOrderInfoByPostnum($postnum,$from);
|
||
if($order){
|
||
$text.="运单号:".$postnum."多发已登记工单,劳烦提供证据等待人工核实\n";
|
||
$this->createExceptionWmsOrder(8,$order["ID"],"客户群多发登记",$postnum);
|
||
$this->checkFail($order,4);
|
||
}else{
|
||
$text.="运单号:".$postnum."没找到运单\n";
|
||
}
|
||
}
|
||
$backMsg = $this->backMsg($from,$text);
|
||
return $backMsg;
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"如需提供多发售后服务,发送:多发+快递号(多个使用任意分隔符)\n例:多发7xxxx1,7xxxx2\n如需更多帮助发送help查看");
|
||
return $backMsg;
|
||
}
|
||
}
|
||
private function carriage($from,$postnums,$msgid,$info){
|
||
|
||
$HisorderModel = new \app\common\model\Hisorder;
|
||
$RuleModel = new \app\common\model\cost\Rules;
|
||
$PackModel = new \app\common\model\cost\Pack;
|
||
$PackingModel = new \app\common\model\cost\Packing;
|
||
if(count($postnums)>0){
|
||
foreach($postnums as $postnum){
|
||
try{
|
||
$order = $this->getOrderInfoByPostnum($postnum,$from);
|
||
if($order["ID"]){
|
||
$text = "{$postnum}\n";
|
||
$STOREID = $order["STOREID"];
|
||
$WAREHOUSEID = $order["WAREHOUSEID"];
|
||
$STOCKIDS = [];
|
||
$STOCKS = explode("|",$order["ITEMS"]);
|
||
$STOCKS = array_filter($STOCKS);
|
||
foreach ($STOCKS as $stock){
|
||
$stocks_tmp = explode(",",$stock);
|
||
array_push($STOCKIDS,["STOCKS"=>$stocks_tmp[0],"COUNT"=>$stocks_tmp[1]]);
|
||
}
|
||
usort($STOCKIDS, function($a, $b) {
|
||
return $a['STOCKS'] - $b['STOCKS'];
|
||
});
|
||
$STOCKS = "";
|
||
$GOODSCOUNT = 0;
|
||
$STOCKSCOUNT = count($STOCKIDS);
|
||
foreach ($STOCKIDS as $stockid){
|
||
$STOCKS.=$stockid["STOCKS"].$stockid["COUNT"];
|
||
$GOODSCOUNT+=$stockid["COUNT"];
|
||
}
|
||
$ITEMS = "";
|
||
foreach ($STOCKIDS as $r){
|
||
$ITEMS.=$r["STOCKS"].$r["COUNT"];
|
||
}
|
||
$line = [
|
||
"ID"=>$order["ID"],
|
||
"POSTNUM"=>$order["POSTNUM"],
|
||
"sendDate"=>intval($order["SENDDATE"]),
|
||
"createDate"=>intval($order["CREATIONDATE"]),
|
||
"POSTCODE"=>$order["POSTCODE"],
|
||
"WEIGHT"=>$order["WEIGHT"],
|
||
"STOREID"=>$order["STOREID"],
|
||
"GOODSCOUNT"=>$GOODSCOUNT,
|
||
"STOCKSCOUNT"=>$STOCKSCOUNT,
|
||
"ITEMS"=>$order["ITEMS"],
|
||
"PROVINCE"=>$order["PROVINCE"],
|
||
"SOURCEORDERCODE"=>$order["SOURCEORDERCODE"],
|
||
"PACKID"=>$order["PACKID"],
|
||
"WAREHOUSEID"=>$order["WAREHOUSEID"],
|
||
];
|
||
$rules = $RuleModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"STOREID"=>0])->order("weight","desc")->select();
|
||
$rulesout = $RuleModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"STOREID"=>$STOREID])->order("weight","desc")->select();
|
||
$rulePack = $PackModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("STOREID=0 or STOREID=".$STOREID)->select();
|
||
$rulePacking = $PackingModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"STOREID"=>$STOREID])->select();
|
||
[$ruleb1,$ruleb2,$ruleb3,$ruleb4,$ruleb5,$end] = Wms::getOrderRule($line,$rules,$rulesout,$rulePack,$rulePacking);
|
||
$price = Wms::getOrderPrice($line,$ruleb2);
|
||
$text.="重量:{$order["WEIGHT"]}\n";
|
||
$text.="报价快递费:{$price}\n";
|
||
if(isset($ruleb3["price"])){
|
||
$text.="使用耗材ID:{$order["PACKID"]}\n";
|
||
$text.="使用耗材费用:{$ruleb3["price"]}\n";
|
||
}
|
||
if($ruleb5){
|
||
$tmpPrice = Wms::getPackingprice($line,$ruleb5);
|
||
$text.="商品总数:{$GOODSCOUNT}\n";
|
||
$text.="SKU总数:{$STOCKSCOUNT}\n";
|
||
$text.="打包费用:{$tmpPrice}\n";
|
||
}
|
||
[$pack1,$pack2,$weight] =$this->getPack($ITEMS,$order["PACKID"]);
|
||
$text.="推荐包装:{$pack1}\n";
|
||
$text.="推荐重量:{$weight}\n";
|
||
$text.="扫描包装:{$pack2}\n";
|
||
}else{
|
||
$text.="{$postnum}未找到运单号";
|
||
}
|
||
} catch (Exception $e) {
|
||
$text = $e;
|
||
}
|
||
$backMsg = $this->backMsg($from,$text);
|
||
return $backMsg;
|
||
}
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"查询运费,发送:查运费+快递号(多个使用任意分隔符)\n例:查运费7xxxx1,7xxxx2\n如需更多帮助发送help查看");
|
||
return $backMsg;
|
||
}
|
||
}
|
||
private function getPack($stocks,$packid){
|
||
$ItemsinfoModel = new \app\common\model\stocks\Weightandpack;
|
||
$data = $ItemsinfoModel->where(["STOCKS"=>$stocks])->find();
|
||
$PackModel = new \app\common\model\wms\Pack;
|
||
if($data){
|
||
$pack1 = $PackModel->where(["ID"=>$data["PACKID"]])->find();
|
||
}else{
|
||
$pack1 = null;
|
||
}
|
||
if($packid){
|
||
$pack2 = $PackModel->where(["ID"=>$packid])->find();
|
||
}else{
|
||
$pack2 = null;
|
||
}
|
||
$pack1Name = $pack1?$pack1["NAME"]:"无";
|
||
$pack2Name = $pack2?$pack2["NAME"]:"无";
|
||
$weight = $data?$data["WEIGHT"]:"无";
|
||
return [$pack1Name,$pack2Name,$weight];
|
||
}
|
||
private function help($from,$postnum,$msgid,$info=""){
|
||
$backMsg = $this->backMsg($from,"如需取消拦截运单号,发送:取消拦截+快递号(多个使用任意分隔符)\n例:取消拦截7xxxx1,7xxxx2\n\n如需拦截运单号,发送:拦截+快递号(多个使用任意分隔符)\n例:拦截7xxxx1,7xxxx2\n\n如需揽收运单号,发送:揽收+快递号(多个使用任意分隔符)\n例:揽收7xxxx1,7xxxx2\n\n如需催件运单号,发送:催件+快递号(多个使用任意分隔符)\n例:催件7xxxx1,7xxxx2");
|
||
return $backMsg;
|
||
}
|
||
private function getCkOrderInfoByCode($postnum,$from){
|
||
$CkModel = new \app\common\model\wmsorder\Ck;
|
||
$order = $CkModel->alias('order')->field('order.ID,packed.packer_name as packer_name,order.SOURCEID as SOURCEID,packed.id as pack_id')->join("ye4s_wmsorder_ck_packed packed","packed.order_id=order.ID","left")->where("order.SOURCEID","like","%{$postnum}%");
|
||
if(!isset($from["isMe"])){
|
||
$order->where(["STOREID"=>$from["storeid"]]);
|
||
}
|
||
$order = $order->find();
|
||
return $order;
|
||
}
|
||
private function getOrderInfoByPostnum($postnum,$from){
|
||
$status = 0;
|
||
$expressRow = $this->ExpressModel->where(["POSTNUM"=>$postnum])->find();
|
||
if(isset($from["isMe"])){
|
||
if(!$expressRow["TRADEORDER"]){
|
||
$where = '(POSTNUM = "'.$postnum.'")';
|
||
}else{
|
||
$where = '(SOURCEID="'.$expressRow["TRADEORDER"].'" or POSTNUM = "'.$postnum.'")';
|
||
}
|
||
}else{
|
||
if(!$expressRow["TRADEORDER"]){
|
||
$where = '(POSTNUM = "'.$postnum.'") and STOREID='.$from["storeid"];
|
||
}else{
|
||
$where = '(SOURCEID="'.$expressRow["TRADEORDER"].'" or POSTNUM = "'.$postnum.'") and STOREID='.$from["storeid"];
|
||
}
|
||
|
||
}
|
||
$order = $this->OrderModel->where($where)->find();
|
||
if($order){
|
||
$status = 1;
|
||
}else{//不在待处理
|
||
$status = 2;
|
||
$order = $this->DeliveryorderModel->where($where)->find();
|
||
if(!$order){//不在配送
|
||
$order = $this->OrderModel1->where($where)->find();
|
||
if(!$order){//不在历史
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
$order["status"] = $status;
|
||
return $order;
|
||
}
|
||
private function getOrderInfoBySourceOrderCode($postnum,$from){
|
||
$status = 0;
|
||
if(isset($from["isMe"])){
|
||
$where = '(SOURCEORDERCODE = "'.$postnum.'")';
|
||
}else{
|
||
$where = '(SOURCEORDERCODE = "'.$postnum.'") and STOREID='.$from["storeid"];
|
||
}
|
||
$order = $this->OrderModel->where($where)->find();
|
||
if($order){
|
||
$status = 1;
|
||
}
|
||
$order["status"] = $status;
|
||
return $order;
|
||
}
|
||
private function getOrderInfoByPostnum2($postnum,$from){
|
||
$status = 0;
|
||
$expressRow = $this->ExpressModel->where(["POSTNUM"=>$postnum])->find();
|
||
if($expressRow){
|
||
$status = 1;
|
||
}else{//不在待处理
|
||
return false;
|
||
}
|
||
$order["status"] = $status;
|
||
return $expressRow;
|
||
}
|
||
private function getSKUInfoBycode($code,$from){
|
||
$expressRow = $this->SkuModel->where('(stock.BARCODE="'.$code.'" or stock.STOCKID="'.$code.'")')->with(['goods'])->find();
|
||
if(!$expressRow){
|
||
return false;
|
||
}
|
||
$data = $this->StorageModel->field("SUM(copycount) as COUNT")->where(["STOCKID"=>$expressRow['STOCKID'],"STOREID"=>$from["storeid"]])->group("STOCKID")->find();
|
||
return $data;
|
||
}
|
||
private function search($from,$postnums){
|
||
$backMsg = $this->backMsg($from,"已通知揽收:\n".implode("\n", $postnums));
|
||
return $backMsg;
|
||
}
|
||
private function updateInterceptorder($orders,$status){
|
||
$data = Wsdl::webservice([106300,$orders,$status],'updateInterceptorder');
|
||
|
||
}
|
||
private function createExceptionWmsOrder($status,$order,$text,$postnum,$qz=false,$isretry=false,$Push=1){
|
||
$redis = new \Redis();
|
||
$redis->connect('127.0.0.1', 6379);
|
||
$redis->auth('qwe2019@');
|
||
$redis->select(2);
|
||
|
||
$res = $this->Exceptionwmsorder->where(["WMSORDERID"=>$order,"STATUS"=>$status])->find();
|
||
if($qz){
|
||
$res = false;
|
||
}
|
||
if(!$res){
|
||
$data = [$status,$text,"","",106300,$order];
|
||
$ress = Wsdl::webservice($data,'createExceptionWmsOrder');
|
||
if($ress==0){
|
||
if($Push==1){
|
||
$redis->lpush("createExceptionWmsOrderBack",json_encode([$postnum,$data,$ress]));
|
||
}
|
||
if(!$isretry){
|
||
$this->createExceptionWmsOrder($status,$order,$text,$postnum,$qz,true);
|
||
}
|
||
}
|
||
return $ress;
|
||
}
|
||
return $res;
|
||
}
|
||
private function create_standard_sto($postnum,$type) {
|
||
$url = 'https://cloudinter-linkgateway.sto.cn/gateway/link.do';
|
||
|
||
$subscribeInfoList = array(
|
||
'waybillNo' => $postnum
|
||
);
|
||
$content = json_encode($subscribeInfoList);
|
||
$secret='VPSZ0blR6oD35OQnHXzI9880c0AWPEBT';//签名
|
||
$requsetData = [
|
||
'api_name'=>$type==1?'INTERCEPT_CREATE_STANDARD':'INTERCEPT_DEL_STANDARD',
|
||
'content'=>$content,
|
||
'from_appkey'=>'CAKbwrQxOfqYOMZ',
|
||
'from_code'=>'CAKbwrQxOfqYOMZ',
|
||
'to_appkey'=>'reverse-center',
|
||
'to_code'=>'reverse-center',
|
||
'data_digest'=>base64_encode(md5($content . $secret, true))
|
||
];
|
||
$res = Http::post($url,$requsetData);
|
||
$msg = json_decode($res,true);
|
||
if(isset($msg["data"]) && isset($msg["data"]["errorReason"]) && strpos($msg["data"]["errorReason"],"当前商家拦截协议未审核")!=false){
|
||
$msg = $this->toMsg("43668530427@chatroom",$postnum." ".$msg["data"]["errorReason"]);
|
||
$redis = new \Redis();
|
||
$redis->connect('127.0.0.1', 6379);
|
||
$redis->auth('qwe2019@');
|
||
$redis->select(2);
|
||
$redis->lpush("Message",json_encode($msg));
|
||
$redis->close();
|
||
}
|
||
return $res;
|
||
}
|
||
private function getWeightForCustomer($from,$postnums,$msgid,$info=""){
|
||
$properties = new ZopProperties("872fa46bd87e9c0dcd7de", "35c4d02a1a45980282f1f80a0194ad0a");
|
||
$client = new ZopClient($properties);
|
||
$request = new ZopRequest();
|
||
if(count($postnums)>0){
|
||
$request->setUrl("https://japi.zto.com/zto.zdz.getWeightForCustomer");
|
||
$param = [
|
||
"billCode"=>$postnums,
|
||
"companyCode"=>"GPG1576724269",
|
||
"scanType"=>"TRAN"
|
||
];
|
||
$request->setBody(json_encode($param));
|
||
|
||
$text = $client->execute($request);
|
||
$backMsg = $this->backMsg($from,json_encode($param));
|
||
return $backMsg;
|
||
}else{
|
||
$backMsg = $this->backMsg($from,"如需查询运单号订单信息,发送:快递号数据查询+快递号(多个使用任意分隔符)\n例:快递号数据查询7xxxx1,7xxxx2\n如需更多帮助发送help查看");
|
||
return $backMsg;
|
||
}
|
||
}
|
||
|
||
|
||
private function create_standard_zto($postnum,$type=1) {
|
||
$properties = new ZopProperties("872fa46bd87e9c0dcd7de", "35c4d02a1a45980282f1f80a0194ad0a");
|
||
$client = new ZopClient($properties);
|
||
$request = new ZopRequest();
|
||
switch($type){
|
||
case 1:
|
||
$request->setUrl("https://japi.zto.com/thirdcenter.createIntercept");
|
||
$param = [
|
||
"billCode"=>$postnum,
|
||
"requestId"=>Random::uuid(),
|
||
"destinationType"=>2,
|
||
"thirdBizNo"=>$postnum
|
||
];
|
||
break;
|
||
default:
|
||
$request->setUrl("https://japi.zto.com/thirdcenter.cancelIntercept");
|
||
$param = [
|
||
"billCode"=>$postnum,
|
||
"thirdBizNo"=>$postnum
|
||
];
|
||
}
|
||
$request->setBody(json_encode($param));
|
||
|
||
return $client->execute($request);
|
||
}
|
||
private function create_standard_ytos($postnums,$type){
|
||
$ress = [];
|
||
foreach ($postnums as $r){
|
||
$res = $this->create_standard_yto($r,$type);
|
||
array_push($ress,$res);
|
||
}
|
||
return $ress;
|
||
}
|
||
private function create_standard_yto($postnum,$type=1) {
|
||
$url = $type==1?'https://openapi.yto.net.cn:11443/open/wanted_report_adapter/v1/gjPCdo/K200426892':'https://openapi.yto.net.cn:11443/open/wanted_cancel_adapter/v1/gjPCdo/K200426892';
|
||
$param = json_encode(array(
|
||
'waybillNo' => $postnum,
|
||
'wantedDesc'=>$type==1?'拦截退回':'取消拦截',
|
||
'dealRemark'=>$type==1?'拦截退回':'取消拦截,继续发货',
|
||
));
|
||
$data = $type==1?$param."wanted_report_adapter"."v1":$param."wanted_cancel_adapter"."v1";
|
||
$partnerId = "PUy60w8p";
|
||
$contentToSign = $data.$partnerId;
|
||
// 计算 MD5
|
||
//return $contentToSign;
|
||
$md5Hash = md5($contentToSign, true); // 使用 true 参数获取原始二进制数据而非十六进制字符串
|
||
$sign = base64_encode($md5Hash);
|
||
|
||
$requsetData = [
|
||
'sign'=>$sign,
|
||
'timestamp'=>time()*1000,
|
||
'param'=>$param,
|
||
'format'=>"JSON"
|
||
];
|
||
$header = ['Content-Type: application/json'];
|
||
$data = json_encode($requsetData);
|
||
|
||
$options = [
|
||
CURLOPT_HTTPHEADER => $header
|
||
];
|
||
|
||
$res = Http::post($url, $data, $options);
|
||
return [$res,$requsetData];
|
||
}
|
||
private function create_standard_jtexpress($postnum,$type=1) {
|
||
$privateKey = "4a8ae8a67ed84bb19f8f0fd2545abf29";
|
||
$apiAccount = "540707233063768102";
|
||
$url = 'https://openapi.jtexpress.com.cn/webopenplatformapi/api/waybill/intercept';
|
||
|
||
$param = [
|
||
'mailNo' => $postnum,
|
||
'applyTypeCode'=>4
|
||
];
|
||
$paramJson = json_encode($param);
|
||
$md5Hash = md5($paramJson . $privateKey, true);
|
||
$digest = base64_encode($md5Hash);
|
||
$time = time() * 1000; // 时间戳需转换为毫秒
|
||
|
||
$data = "bizContent=".$paramJson;
|
||
$header = [
|
||
'Content-Type: application/x-www-form-urlencoded',
|
||
'apiAccount: ' . $apiAccount,
|
||
'timestamp: ' . $time,
|
||
'digest: ' . $digest
|
||
];
|
||
$options = [
|
||
CURLOPT_HTTPHEADER => $header
|
||
];
|
||
|
||
$res = Http::post($url, $data, $options);
|
||
return [$res,$paramJson];
|
||
}
|
||
private function cuijian($postnum){
|
||
$url = 'https://cloudinter-linkgateway.sto.cn/gateway/link.do';
|
||
$subscribeInfoList = array(
|
||
'billCode' => [$postnum],
|
||
'shopKey'=>'258D6DF6E13724E5972B332D7F6883EA',
|
||
'ticketType'=>2
|
||
);
|
||
$content = json_encode($subscribeInfoList);
|
||
$secret='TgKCcea1wgmhK7vauDSKitbSgwzNBKHP';//签名
|
||
$requsetData = [
|
||
'api_name'=>'CHAOSHANG_CREATE_AFTERSALE',
|
||
'content'=>$content,
|
||
'from_appkey'=>'CAKvftdLKGgzWSV',
|
||
'from_code'=>'CAKvftdLKGgzWSV',
|
||
'to_appkey'=>'sto_merchant',
|
||
'to_code'=>'sto_merchant',
|
||
'data_digest'=>base64_encode(md5($content . $secret, true))
|
||
];
|
||
$res = Http::post($url,$requsetData);
|
||
$msg = json_decode($res,true);
|
||
if(isset($msg["data"]) && isset($msg["data"]["errorReason"]) && strpos($msg["data"]["errorReason"],"当前商家拦截协议未审核")!=false){
|
||
$msg = $this->toMsg("43668530427@chatroom",$postnum." ".$msg["data"]["errorReason"]);
|
||
$redis = new \Redis();
|
||
$redis->connect('127.0.0.1', 6379);
|
||
$redis->auth('qwe2019@');
|
||
$redis->select(2);
|
||
$redis->lpush("Message",json_encode($msg));
|
||
$redis->close();
|
||
}
|
||
return $res;
|
||
}
|
||
public function Message(){
|
||
$this->setMessage();
|
||
}
|
||
|
||
private function setMessage(){
|
||
$redis = new \Redis();
|
||
$redis->connect('127.0.0.1', 6379);
|
||
$redis->auth('qwe2019@');
|
||
$redis->select(2);
|
||
$data = $redis->rpop("Message");
|
||
if(!$data){
|
||
return false;
|
||
}
|
||
$requsetData = json_decode($data);
|
||
foreach($this->wechats as $wechat){
|
||
$this->ext_query($requsetData,$wechat);
|
||
}
|
||
return $data;
|
||
}
|
||
private function confirmExceptionWmsOrder(){
|
||
$data = Wsdl::webservice([106300,'b293d1c239a3456785cc9691a08553e7'],'confirmExceptionWmsOrder');
|
||
return $data;
|
||
}
|
||
private function pushLanjie($data){
|
||
$this->createExceptionWmsOrder(12,$data["ID"],"库内拦截成功",$data["POSTNUM"],true);
|
||
$redis = new \Redis();
|
||
$redis->connect('127.0.0.1', 6379);
|
||
$redis->auth('qwe2019@');
|
||
$redis->select(2);
|
||
$redis->lpush("lanjies",json_encode($data));
|
||
$redis->close();
|
||
}
|
||
private function exportStorage($from,$STOCKIDS,$msgid,$info){
|
||
$spreadsheet = new Spreadsheet();
|
||
$worksheet = $spreadsheet->getActiveSheet();
|
||
$title = '库存';
|
||
$worksheet->setTitle($title);
|
||
$worksheet->fromArray(
|
||
[
|
||
['库位','条码','名称','数量','生产日期','有效期至']
|
||
], '', 'A1' );
|
||
$STOCKIDS = $this->getStocks($info);
|
||
$StorageModel = new \app\common\model\wms\Storage;
|
||
$data = $StorageModel->field('space.CUSTOMNUM as kw,stock.BARCODE as tm,goods.NAME as mc,sum(a.copycount) as sl,a.EXPIREDATE as EXPIREDATE,a.PRODUCTDATE as PRODUCTDATE')->alias('a')
|
||
->join('yj_space space', 'space.ID=a.SPACEID')
|
||
->join('yj_stock stock', 'stock.STOCKID=a.STOCKID')
|
||
->join('yj_goods goods', 'goods.GOODSID=a.GOODSID')
|
||
->where('a.copycount >0')->where("a.STOCKID","in",$STOCKIDS)->group('a.SPACEID,a.STOCKID')->order('space.IDX')->select();
|
||
$workers = [
|
||
];
|
||
foreach ($data as $r){
|
||
array_push($workers,[$r["kw"],strval($r["tm"]),$r["mc"],$r["sl"],$r["PRODUCTDATE"],$r["EXPIREDATE"]]);
|
||
};
|
||
$worksheet->fromArray(
|
||
$workers, '', 'A2' );
|
||
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||
|
||
$filename= "kccx".time();
|
||
$tempPath = '/www/wwwroot/ye4s.wms.gztbyc.com/public/file/'.$filename.'.xlsx';
|
||
$writer->save($tempPath);
|
||
$msg = $this->backFile($from,"https://ye4s.wms.gztbyc.com/file/".$filename.".xlsx");
|
||
return [$msg];
|
||
}
|
||
private function checkFail($ORDER,$TYPE){
|
||
if(!isset($ORDER["GRABNUM"])||$ORDER["GRABNUM"]==""){
|
||
return false;
|
||
}
|
||
$failcount = $this->FailorderModel->where('POSTNUM<>"'.$ORDER["POSTNUM"].'"')->where(["GRABNUM"=>$ORDER["GRABNUM"],"TYPE"=>$TYPE])->count();
|
||
$line = $this->FailorderModel->where(["POSTNUM"=>$ORDER["POSTNUM"],"TYPE"=>$TYPE])->find();
|
||
$isout = $this->FailorderModel->where(["GRABNUM"=>$ORDER["GRABNUM"],"out"=>1])->find();
|
||
if($isout && $line){
|
||
return false;
|
||
}
|
||
if($failcount>0 && !$line){
|
||
$this->early_warning($TYPE,$ORDER["GRABNUM"],$failcount+1);
|
||
}
|
||
if(!$line){
|
||
$this->FailorderModel->save(["POSTNUM"=>$ORDER["POSTNUM"],"GRABNUM"=>$ORDER["GRABNUM"],"TYPE"=>$TYPE]);
|
||
}
|
||
}
|
||
private function early_warning($TYPE,$GRABNUM,$count){
|
||
$this->redis->select(2);
|
||
$TYPES = [
|
||
"核实签收",
|
||
"催件",
|
||
"少发",
|
||
"错发",
|
||
"多发"
|
||
];
|
||
$msg = $this->toMsg("43668530427@chatroom",$GRABNUM."预警(".$TYPES[$TYPE].")".$count."条相同售后在此波次.如核实非批次错误,请回复\n非批次错误{$GRABNUM}");
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
}
|
||
private function toMsg($to,$text,$at=null){
|
||
return [
|
||
"method"=>"sendText",
|
||
"wxid"=> $to,
|
||
"msg"=> $text,
|
||
"atid"=> ($at !== null) ? $at : [],
|
||
"pid"=> $this->pid??0
|
||
];
|
||
}
|
||
public function change_order(){
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$params = $this->request->post();
|
||
$data = isset($params['data'])?$params['data']:null;
|
||
$orderModel = new \app\common\model\rooms\Order;
|
||
$order = $orderModel->where(["ordercode"=>$data['ordercode'],"WAREHOUSEID"=>$WAREHOUSEID])->where("status>-1")->find();
|
||
if($order){
|
||
unset($data['ordercode']);
|
||
if($order['postnum']){
|
||
//有单号,提交到快递修改
|
||
$str = "{$order['postnum']}修改收件人信息:{$data['name']} {$data['tel']} {$data['address']}\n";
|
||
unset($data['platform_code']);
|
||
unset($data['express_code']);
|
||
$order->save($data);
|
||
$relay = $this->RoomsModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"POSTCODE"=>$order['express_code'],"type"=>3,"islanshow"=>0])->where("ECNOTES like '%default%'")->find();
|
||
if(!$relay){
|
||
$relay = $this->RoomsModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"POSTCODE"=>$order['express_code'],"type"=>3])->where("ECNOTES like '%default%'")->find();
|
||
}
|
||
if(!$relay){
|
||
$relay = $this->RoomsModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"POSTCODE"=>$order['express_code'],"type"=>3])->find();
|
||
}
|
||
if($relay){
|
||
$relayMsg = $this->to($relay["room_id"],$str);
|
||
$redis = new \Redis();
|
||
$redis->connect('127.0.0.1', 6379);
|
||
$redis->auth('qwe2019@');
|
||
$redis->select(2);
|
||
$redis->lpush("Message",json_encode($relayMsg));
|
||
return json(["msg"=>"订单已出单号,已通知快递更改收件人信息"]);
|
||
}else{
|
||
return json(["msg"=>"订单已出单号,未设置快递群,请自行通知快递修改信息"]);
|
||
}
|
||
|
||
}else{
|
||
$order->save($data);
|
||
return json(["msg"=>"订单未出单号,信息修改成功"]);
|
||
}
|
||
}else{
|
||
return json(["msg"=>"订单已不存在,刷新重试"]);
|
||
}
|
||
}
|
||
public function orders(){
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$OrdersLib = new \app\index\library\chat\Orders;
|
||
$orderModel = new \app\common\model\rooms\Order;
|
||
$StoreModel = new \app\common\model\wms\Store;
|
||
$params = $this->request->post();
|
||
$page = isset($params['page'])?$params['page']:1;
|
||
$wheres = isset($params['where'])?$params['where']:[];
|
||
$where = [];
|
||
foreach ($wheres as $k => $r){
|
||
switch($k){
|
||
case "POSTCODE":
|
||
if($r){
|
||
array_push($where,"express_code='{$r}'");
|
||
}
|
||
break;
|
||
case "name":
|
||
if($r){
|
||
array_push($where,"name like '%{$r}%'");
|
||
}
|
||
break;
|
||
case "platform":
|
||
if($r){
|
||
array_push($where,"platform_code ={$r}");
|
||
}
|
||
break;
|
||
case "postnum":
|
||
if($r){
|
||
array_push($where,"postnum like '%{$r}%'");
|
||
}
|
||
break;
|
||
case "startTime":
|
||
if($r){
|
||
$startTime = strtotime($r[0]);
|
||
$endTime = strtotime($r[1])+86399;
|
||
array_push($where,"create_time between {$startTime} and {$endTime}");
|
||
}
|
||
break;
|
||
case "store_id":
|
||
if($r){
|
||
array_push($where,"store_id= {$r}");
|
||
}
|
||
break;
|
||
case "tel":
|
||
if($r){
|
||
array_push($where,"tel like '%{$r}%'");
|
||
}
|
||
break;
|
||
case "storeName":
|
||
if($r){
|
||
array_push($where,"province like '%{$r}%'");
|
||
}
|
||
break;
|
||
case "status":
|
||
if($r){
|
||
array_push($where,"m.status={$r}");
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
$sort = "create_time";
|
||
$order = "desc";
|
||
$pagesize = isset($params["pagesize"])?$params["pagesize"]:20;
|
||
$offset = $pagesize*($page-1);
|
||
$list =$orderModel->alias('m')
|
||
->field("m.*,user.real_name as reviewer_name")
|
||
->where(implode(" and ",$where))
|
||
->where("m.status>-1")
|
||
->where(["m.WAREHOUSEID"=>$WAREHOUSEID])
|
||
->join("ye4s_user user","user.id=m.reviewer_id","left")
|
||
->order($sort, $order)
|
||
->paginate($pagesize);
|
||
$rows = $list->items();
|
||
$storeids = [];
|
||
foreach ($rows as $row){
|
||
$row["expressName"] = $OrdersLib->getExpressName($row['express_code']);
|
||
$row["platformName"] = $OrdersLib->getplatformName($row['platform_code']);
|
||
array_push($storeids,$row['store_id']);
|
||
}
|
||
$stores = $StoreModel->where("STOREID","in",$storeids)->select();
|
||
foreach ($rows as $row){
|
||
$storeName = "";
|
||
foreach ($stores as $r){
|
||
if($row['store_id']==$r["STOREID"]){
|
||
$storeName = $r["TITLE"];
|
||
}
|
||
}
|
||
$row["STORENAME"] = $storeName;
|
||
}
|
||
$result = ['total' => $list->total(), 'rows' =>$rows,'pagesize'=>$params ];
|
||
return json($result);
|
||
}
|
||
public function query_stock(){
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$params = $this->request->post();
|
||
$storeid = $params['storeid'];
|
||
$keyword = $params['keyword'];
|
||
if(!$storeid){
|
||
return json([]);
|
||
}
|
||
$stockModel = new \app\common\model\wms\Stock;
|
||
$list = $stockModel->alias("stock")->field('stock.BARCODE as BARCODE,goods.NAME as NAME,stock.IMG as IMG,stock.COLOR as COLOR,stock.STYLE as STYLE,stock.STOCKID as STOCKID')->join('yj_goods goods','goods.GOODSID=stock.GOODSID','left')->join('yj_warestore warestore','warestore.ID=stock.WARESTOREID','left')->where(["stock.WAREHOUSEID"=>$WAREHOUSEID])->where("warestore.STOREID={$storeid}")->where("stock.BARCODE like '%{$keyword}%' or stock.COLOR like '%{$keyword}%' or stock.STYLE like '%{$keyword}%' or goods.NAME like '%{$keyword}%' or stock.STOCKID like '%{$keyword}%'")->limit(100)->order("stock.STOCKID","desc")->select();
|
||
return json($list);
|
||
}
|
||
public function order_push(){
|
||
$OrdersLib = new \app\index\library\chat\Orders;
|
||
$orderModel = new \app\common\model\rooms\Order;
|
||
$lockTimeout = 180;
|
||
$time = time();
|
||
$iterator = null;
|
||
$pattern = 'dd_*'; // 匹配所有以 dd_ 开头的键
|
||
$keys = [];
|
||
|
||
do {
|
||
// 每次扫描返回一批匹配的键
|
||
$result = $this->redis->scan($iterator, $pattern);
|
||
|
||
if ($result !== false) {
|
||
foreach ($result as $key){
|
||
$cleanKey = substr($key, 3);
|
||
$keys[] = $cleanKey;
|
||
}
|
||
}
|
||
} while ($iterator > 0);
|
||
$params = $this->request->post();
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$IDS = isset($params["ids"])?explode(",",$params["ids"]):[];
|
||
$orders = $orderModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("status","in",[1,2])->where("ordercode","in",$IDS);
|
||
if(count($keys)>0){
|
||
$orders->where("ordercode","not in",$keys);
|
||
}
|
||
$orders = $orders->order('create_time')->select();
|
||
$datas = [];
|
||
foreach ($orders as $order){
|
||
$this->redis->set("dd_".$order["ordercode"], 1, ['NX', 'EX' => $lockTimeout]);
|
||
[$code,$msg,$data] = $OrdersLib->createOrderToWms($order);
|
||
if($code==1){
|
||
$order->status = 3;
|
||
$tomsg = $this->toMsg($order["room_wxid"],"@{$order['creator_name']} \n================================\n{$order['msg']}\n================================\n已出运单号:{$data}\n",$order["creator_wxid"]);
|
||
$this->redis->select(2);
|
||
$this->redis->lpush("Message",json_encode($tomsg));
|
||
$order->postnum = $data;
|
||
$order->save();
|
||
}else{
|
||
$order->status = $code;
|
||
$order->error = $msg;
|
||
$tomsg = $this->toMsg($order["room_wxid"],"@{$order['creator_name']} \n================================\n{$order['msg']}\n================================\n出单失败:{$msg}\n三分钟后重试出单",$order["creator_wxid"]);
|
||
$this->redis->select(2);
|
||
$this->redis->lpush("Message",json_encode($tomsg));
|
||
$order->save();
|
||
}
|
||
array_push($datas,[$code,$msg,$data]);
|
||
}
|
||
return json($datas);
|
||
}
|
||
|
||
private function cancelRoomOrder($from,$postnums,$msgid,$info=""){
|
||
$orderModel = new \app\common\model\rooms\Order;
|
||
$msgs = [];
|
||
$WAREHOUSEID = $from["WAREHOUSEID"];
|
||
if(count($postnums)>0){
|
||
$orders = $orderModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where(["store_id"=>$from["storeid"]])->where("status>0")->where("ordercode","in",$postnums)->select();
|
||
foreach ($orders as $order){
|
||
$postnum_text = $order["postnum"]?"已出运单号{$order['postnum']}已发送到运方拦截":"";
|
||
$tomsg = $this->toMsg($order["room_wxid"],"@{$order['creator_name']} \n================================\n{$order['msg']}\n================================\n订单已经被{$from['memname']}取消\n{$postnum_text}",$order["creator_wxid"]);
|
||
$this->redis->select(2);
|
||
$this->redis->lpush("Message",json_encode($tomsg));
|
||
if($postnum_text){
|
||
//通知运方拦截
|
||
$roomsModel = $this->SOURCE=="qiwe"?$this->qiweRoomsModel:$this->RoomsModel;
|
||
$rooms = $roomsModel->where(["POSTCODE"=>$order['express_code'],"islanshow"=>0])->select();
|
||
if(!$rooms){
|
||
$rooms = $roomsModel->where(["POSTCODE"=>$order['express_code']])->select();
|
||
}
|
||
if($rooms){
|
||
$tomsg = $this->toMsg($rooms[0]["room_id"],"拦截\n{$order['postnum']}");
|
||
$this->redis->lpush("Message",json_encode($tomsg));
|
||
}
|
||
}
|
||
$order->status = -1;
|
||
$order->save();
|
||
}
|
||
}
|
||
}
|
||
public function cancel_order(){
|
||
$orderModel = new \app\common\model\rooms\Order;
|
||
$params = $this->request->post();
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$IDS = isset($params["ids"])?explode(",",$params["ids"]):[];
|
||
$orders = $orderModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("status>0")->where("ordercode","in",$IDS);
|
||
$orders = $orders->select();
|
||
$real_name = $this->auth->real_name;
|
||
foreach ($orders as $order){
|
||
$postnum_text = $order["postnum"]?"已出运单号{$order['postnum']}已发送到运方拦截":"";
|
||
$tomsg = $this->toMsg($order["room_wxid"],"@{$order['creator_name']} \n================================\n{$order['msg']}\n================================\n订单已经被{$real_name}取消\n{$postnum_text}",$order["creator_wxid"]);
|
||
$this->redis->select(2);
|
||
$this->redis->lpush("Message",json_encode($tomsg));
|
||
if($postnum_text){
|
||
//通知运方拦截
|
||
$roomsModel = $this->SOURCE=="qiwe"? $this->qiweRoomsModel : $this->RoomsModel;
|
||
$rooms = $roomsModel->where(["POSTCODE"=>$order['express_code'],"islanshow"=>0])->select();
|
||
if(!$rooms){
|
||
$rooms = $roomsModel->where(["POSTCODE"=>$order['express_code']])->select();
|
||
}
|
||
if($rooms){
|
||
$tomsg = $this->toMsg($rooms[0]["room_id"],"拦截\n{$order['postnum']}");
|
||
$this->redis->lpush("Message",json_encode($tomsg));
|
||
}
|
||
}
|
||
$order->status = -1;
|
||
$order->save();
|
||
}
|
||
return 1;
|
||
}
|
||
public function save_and_push(){
|
||
$result_data = [
|
||
"msg"=>"",
|
||
"code"=>-1,
|
||
];
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$USERID = $this->auth->id;
|
||
$real_name = $this->auth->real_name;
|
||
$OrdersLib = new \app\index\library\chat\Orders;
|
||
$orderModel = new \app\common\model\rooms\Order;
|
||
$stockModel = new \app\common\model\wms\Stock;
|
||
$params = $this->request->post();
|
||
$ordercode = isset($params["order_id"])?$params["order_id"]:0;
|
||
$items = isset($params["items"])?$params["items"]:"";
|
||
//检验参数是否合法
|
||
if(!$ordercode){
|
||
$result_data["msg"] = "非法参数";
|
||
return json($result_data);
|
||
}else{
|
||
$order = $orderModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"ordercode"=>$ordercode])->find();
|
||
}
|
||
$storeid = $order->store_id;
|
||
if(!$order){
|
||
$result_data["msg"] = "非法参数";
|
||
return json($result_data);
|
||
}
|
||
if(!$items){
|
||
$result_data["msg"] = "非法参数";
|
||
return json($result_data);
|
||
}else{
|
||
$has_error = false;
|
||
$items_tmp = explode("|",$items);
|
||
$stockids = [];
|
||
foreach ($items_tmp as $r){
|
||
$stock_tmp = explode(",",$r);
|
||
if(intval($stock_tmp[1])<1){
|
||
$has_error = true;
|
||
}
|
||
array_push($stockids,$stock_tmp[0]);
|
||
}
|
||
$stocks = $stockModel->alias("stock")->field('stock.BARCODE as BARCODE,goods.NAME as NAME,stock.IMG as IMG,stock.COLOR as COLOR,stock.STYLE as STYLE,stock.STOCKID as STOCKID')->join('yj_goods goods','goods.GOODSID=stock.GOODSID','left')->join('yj_warestore warestore','warestore.ID=stock.WARESTOREID','left')->where(["stock.WAREHOUSEID"=>$WAREHOUSEID])->where("warestore.STOREID={$storeid}")->where("stock.STOCKID","in",$stockids)->order("stock.STOCKID","desc")->select();
|
||
if(count($stocks)!=count($items_tmp)){
|
||
$has_error = true;
|
||
}
|
||
if($has_error){
|
||
$result_data["msg"] = "非法参数";
|
||
return json($result_data);
|
||
}
|
||
}
|
||
$order->reviewer_items = $items;
|
||
$order->reviewer_id = $USERID;
|
||
$order->reviewer_time = time();
|
||
[$code,$msg,$data] = $OrdersLib->createOrderToWms($order,1);
|
||
if($code==1){
|
||
$order->status = 0;
|
||
$order->save();
|
||
$result_data["msg"] = "推送成功";
|
||
$result_data["code"] = 1;
|
||
return json($result_data);
|
||
}else{
|
||
$order->status = $code;
|
||
$order->error = $msg;
|
||
$order->save();
|
||
$result_data["msg"] = "推送失败,错误信息为:{$msg}";
|
||
return json($result_data);
|
||
}
|
||
|
||
}
|
||
public function get_interior_rooms(){
|
||
if ($this->request->isPost()){
|
||
$WAREHOUSEID = $this->auth->warehouseid;
|
||
$wechat_rooms = $this->getAllRooms($this->wechats[0]);
|
||
$params = $this->request->post();
|
||
$keyword = isset($params['keyword']) ? $params['keyword'] : '';
|
||
$RoomsModel = $this->SOURCE=="qiwe"? $this->qiweRoomsModel : $this->RoomsModel;
|
||
$where = ["WAREHOUSEID"=>$WAREHOUSEID,"type"=>2];
|
||
if($keyword){
|
||
$where["TITLE"] = ["like", "%{$keyword}%"];
|
||
}
|
||
$rooms = $RoomsModel->where($where)->select();
|
||
//补全群名
|
||
foreach ($rooms as $room){
|
||
$TITLE = "";
|
||
foreach ($wechat_rooms as $wechat_room){
|
||
if($room["room_id"]==$wechat_room["wxid"] && $room["type"]==2){
|
||
$TITLE = $wechat_room["name"];
|
||
}
|
||
}
|
||
$room["name"] = $TITLE;
|
||
}
|
||
return json(["rows"=>$rooms]);
|
||
}
|
||
}
|
||
public function get_group_messages(){
|
||
$logModel = $this->SOURCE =="qiwe"? $this->qiweLogModel : $this->ChatLogModel;
|
||
$params = $this->request->post();
|
||
$room_id = isset($params['room_id']) ? $params['room_id'] : '';
|
||
$page = isset($params['page']) ? $params['page'] : 1;
|
||
$pagesize = isset($params['pagesize']) ? $params['pagesize'] : 20;
|
||
$offset = ($page - 1) * $pagesize;
|
||
|
||
//分别格式化不同来源的消息内容
|
||
$message_types = [
|
||
1=>"文本",
|
||
3=>"图片",
|
||
34=>"语音",
|
||
42=>"名片",
|
||
43=>"视频",
|
||
47=>"表情",
|
||
49=>"文件",
|
||
];
|
||
$messages = [];
|
||
switch($this->SOURCE){
|
||
case "qiwe":
|
||
$where = ["from_room_id"=>$room_id];
|
||
$list = $logModel->where($where)->where("msg_type","not in",[2001])->order("id desc")->limit($offset, $pagesize)->select();
|
||
foreach ($list as $item){
|
||
$contact_info = json_decode($item["contact_info"],true);
|
||
$tmp_item = [
|
||
"sender_name"=>$contact_info["nickname"]??"未知用户",
|
||
"content" =>$item["content"],
|
||
"time"=>$item["timestamp"],
|
||
"back_content_json"=>json_decode($item["back_content_json"],true),
|
||
];
|
||
array_push($messages,$tmp_item);
|
||
}
|
||
$total = $logModel->where($where)->where("msg_type","not in",[2001])->count();
|
||
break;
|
||
case "wx":
|
||
$where = ["room_wxid"=>$room_id];
|
||
$list = $logModel->where($where)->order("id desc")->limit($offset, $pagesize)->select();
|
||
foreach ($list as $item){
|
||
$tmp_item = [
|
||
"sender_name"=>$item["sender_name"]??"未知用户",
|
||
"content" =>$item["msg"],
|
||
"time"=>$item["creatime"],
|
||
"back_content_json"=>json_decode($item["result"],true),
|
||
];
|
||
array_push($messages,$tmp_item);
|
||
}
|
||
$total = $logModel->where($where)->count();
|
||
break;
|
||
}
|
||
return json(["total"=>$total,"rows"=>$messages]);
|
||
}
|
||
public function send_group_message(){
|
||
$params = $this->request->post();
|
||
$room_id = isset($params['room_id']) ? $params['room_id'] : '';
|
||
$content = isset($params['content']) ? $params['content'] : '';
|
||
$type = isset($params['type']) ? $params['type'] : 1;
|
||
$atList = isset($params['atList']) ? $params['atList'] : [];
|
||
if(!$room_id || !$content){
|
||
return json(["code"=>-1,"msg"=>"参数错误"]);
|
||
}
|
||
switch($type){
|
||
case 1:
|
||
$ids = null;
|
||
if($atList){
|
||
$atTexts = [];
|
||
$atIds = [];
|
||
foreach ($atList as $at){
|
||
$atTexts[] = "@{$at['nickname']}";
|
||
$atIds[] = $at['wxid']??$at['id'];
|
||
}
|
||
$content = implode(" ", $atTexts)." ".$content;
|
||
$ids = implode(",",$atIds);
|
||
}
|
||
$tomsg = $this->toMsg($room_id,$content,$ids);
|
||
break;
|
||
case 3:
|
||
break;
|
||
default:
|
||
}
|
||
$this->redis->select(2);
|
||
$MessageKey = $this->SOURCE=="qiwe"?"QiweMessage":"Message";
|
||
Log::error("发送群消息:{$MessageKey}".json_encode($tomsg));
|
||
$this->redis->lpush($MessageKey,json_encode($tomsg));
|
||
return json(["code"=>1,"msg"=>"消息发送成功"]);
|
||
}
|
||
} |