一、open_basedir 不能再写 /tmp(7.4 池子把白名单收紧,Monolog/EasyWeChat 会抛异常)
- addons/shopro/library/Wechat.php:easywechat 日志改到 runtime/easywechat/
- addons/epay/library/Yansongda/Supports/Logger.php:epay 日志默认路径改到 runtime/epay/
- application/admin/library/traits/Backend.php:CSV 导入临时文件改到 runtime/temp/
二、implode 参数反序(7.4 起 E_DEPRECATED,TP5 会抛异常)
- application/api/controller/Datas.php
- application/index/controller/wms/Pda.php
- 另修正 Wms.php 中 1 处(拆分面单提示)
三、null 取下标(7.4 起 "Trying to access array offset on value of type null")
- 覆盖 71 个文件 135 行:find()/value()/json_decode()/redis get 等结果未判空即取下标处,
统一 (\['k'] ?? null) 兜底;foreach 目标用 ?? [];in_array/count 等数组参数用 ?? []
- 涉及 api/*、admin/shopro/*、addons/shopro/*、addons/epay/*、index/wms/* 等
四、嵌套三元未加括号(7.4 弃用)
- application/index/controller/wms/Wms.php getPackingprice 2 处,补括号后与旧版本解析顺序一致
验证:74 个文件、148 行改动,逐行括号/引号配平与 HEAD 一致,未改动 vendor/ 与 thinkphp/;
剩余扫描命中均为写目标、unset、或已被 if(!\){error()} 拦截的假阳性。
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
11908 lines
534 KiB
PHP
11908 lines
534 KiB
PHP
<?php
|
||
|
||
namespace app\index\controller\wms;
|
||
use app\common\controller\Frontend;
|
||
use app\common\library\Auth;
|
||
use addons\shopro\library\Wechat as WechatLibrary;
|
||
use think\Db;
|
||
use think\Exception;
|
||
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\exception\ValidateException;
|
||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||
use GuzzleHttp\Client;
|
||
use GuzzleHttp\Exception\RequestException;
|
||
use GuzzleHttp\Psr7\Request;
|
||
use GuzzleHttp\Psr7\MultipartStream as MultipartStream;
|
||
use fast\Http;
|
||
use fast\Random;
|
||
use app\index\library\Webhook;
|
||
use think\Config;
|
||
use think\Log;
|
||
class Wms extends Frontend
|
||
{
|
||
|
||
protected $noNeedLogin = '*';
|
||
protected $noNeedRight = '*';
|
||
protected $layout = '';
|
||
const NEW_WMS_API = 'http://qimen.wms.gztbyc.com/system';
|
||
public function _initialize()
|
||
{
|
||
parent::_initialize();
|
||
$this->redis = new \Redis();
|
||
$this->redis->connect('127.0.0.1', 6379);
|
||
$this->redis->auth('qwe2019@');
|
||
$this->redis->select(2);
|
||
$this->express_redis = new \Redis();
|
||
$this->express_redis->connect('127.0.0.1', 6379);
|
||
$this->express_redis->auth('qwe2019@');
|
||
$this->express_redis->select(15);
|
||
$this->postcodeList = [];
|
||
$this->RulesModel = new \app\common\model\wms\PickingRules;
|
||
$this->wechatServer = "42.194.235.215";
|
||
$this->key = "8DE6CAD0E48D4DF84CF0593AD01DB62FE89D137B";
|
||
$this->Webhook_lib = new Webhook('https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=cd417ebc-4252-4583-9b07-107e954cd0cf');
|
||
}
|
||
public function top()
|
||
{
|
||
$t3 = date('Y-m-d')." 01:00:00";
|
||
|
||
$model = new \app\common\model\jianhuo\Item;
|
||
$data = $model->field('userid, bocihao, ordercount')
|
||
->group('bocihao')
|
||
->where('starttime', '>', strtotime($t3))
|
||
->where('bocihao', 'like', '%B%')
|
||
->select();
|
||
$data3 = $model->field('count(DISTINCT bocihao) as sums, userid')
|
||
->group('userid')
|
||
->where('starttime', '>', strtotime($t3))
|
||
->where('bocihao', 'like', '%B%')
|
||
->select();
|
||
|
||
$tmps = [];
|
||
$tmps2 = [];
|
||
foreach ($data as $b){
|
||
if(isset($tmps[$b['userid']])){
|
||
$tmps[$b['userid']] += $b['ordercount'];
|
||
}else{
|
||
$tmps[$b['userid']] = $b['ordercount'];
|
||
}
|
||
}
|
||
foreach ($tmps as $k => $c){
|
||
$modelUser = new \app\common\model\wms\User;
|
||
$dd = $modelUser->where(['userId'=>$k])->find();
|
||
$name = ($dd['name'] ?? null);
|
||
$sums = 0;
|
||
foreach ($data3 as $f){
|
||
if($f['userid']==$k){
|
||
$sums = $f['sums'];
|
||
}
|
||
}
|
||
array_push($tmps2,["name"=>$name,"count"=>$c,"userid"=>$k,"sums"=>$sums]);
|
||
}
|
||
|
||
$data2 = $model->order('endtime','desc')
|
||
->where('locate("B",bocihao)')->limit(5)->select();
|
||
foreach ($data2 as $d){
|
||
$modelUser = new \app\common\model\wms\User;
|
||
$dd = $modelUser->where(['userId'=>$d['userid']])->find();
|
||
$d['name'] = ($dd['name'] ?? null);
|
||
}
|
||
return json(["top"=>$tmps2,"list"=>$data2]);
|
||
}
|
||
public function getBackOrder(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = isset($params["WAREHOUSEID"])?$params["WAREHOUSEID"]:0;
|
||
$postnum = $params["postnum"];
|
||
$stores = $this->getStoresArray($WAREHOUSEID);
|
||
$res = [
|
||
"POSTNUM"=>Random::uuid().time(),
|
||
"items"=>[],
|
||
"stores"=>json_decode(json_encode($stores)),
|
||
"YDFLAG"=>0,
|
||
"STOCKS"=>[]
|
||
];
|
||
if($postnum!="noorder"){
|
||
$res["POSTNUM"] = $postnum;
|
||
$BackrecordModel = new \app\common\model\wms\Backrecord;
|
||
$BackrecordunknowModel = new \app\common\model\wms\Backrecordunknow;
|
||
$backInfo = $BackrecordModel->field("YDFLAG,STOREID,yj_stock.BARCODE as BARCODE,backrecord.COUNT as COUNT,backrecord.STATUS as STATUS,yj_goods.NAME as NAME,backrecord.NOTES as NOTES,backrecord.STOCKID as STOCKID")->where(["POSTNUM"=>$postnum])->alias("backrecord")->join("yj_stock yj_stock","yj_stock.STOCKID=backrecord.STOCKID")->join("yj_goods yj_goods","yj_stock.GOODSID=yj_goods.GOODSID")->select();
|
||
$backInfo2 = $BackrecordunknowModel->alias('a')->field('`YDFLAG`,`STOREID`,a.`COUNT` as COUNT,a.`NOTES` as NOTES,a.`STATUS` as STATUS,"无记录产品" AS NAME,BARCODE AS BARCODE,`stocks`,-1 as STOCKID')->where(["a.POSTNUM"=>$postnum])->select();
|
||
foreach ($backInfo as $r){
|
||
$r['stocks'] = [];
|
||
}
|
||
foreach ($backInfo2 as $r){
|
||
$tmp_r = $r['stocks']?json_decode($r['stocks'],true):[];
|
||
foreach ($tmp_r as $index=>$rr){
|
||
$tmp_r[$index]['STOCKID'] = intval($rr['STOCKID']);
|
||
$tmp_r[$index]['STOREID'] = intval($rr['STOREID']);
|
||
}
|
||
$r['stocks'] = $tmp_r;
|
||
}
|
||
$backInfo = array_merge($backInfo, $backInfo2);
|
||
if(count($backInfo)>0){
|
||
//print_r($backInfo[0]);die();
|
||
$res["YDFLAG"] = $backInfo[0]["YDFLAG"];
|
||
if($res["YDFLAG"]==1){
|
||
$order = $this->getOrderInfoByPostnum($postnum);
|
||
$items = $this->getStocksByItem(($order["ITEMS"] ?? null));
|
||
//$res["STOCKS"] = $items;
|
||
}
|
||
$tmp_store = [];
|
||
foreach ($stores as $store){
|
||
if(intval($backInfo[0]["STOREID"])==intval($store["STOREID"])){
|
||
$tmp_store = $store;
|
||
}
|
||
}
|
||
$res["items"] = $backInfo;
|
||
$res["stores"] = $tmp_store?[$tmp_store]:[];
|
||
}else{
|
||
$order = $this->getOrderInfoByPostnum($postnum);
|
||
if($order){
|
||
$items = $this->getStocksByItem($order["ITEMS"]);
|
||
//$res["STOCKS"] = $items;
|
||
$tmp_store = null;
|
||
$res["YDFLAG"] = 1;
|
||
foreach ($stores as $store){
|
||
if(intval($order["STOREID"])==intval($store["STOREID"])){
|
||
$tmp_store = $store;
|
||
}
|
||
}
|
||
$res["stores"] = [$tmp_store];
|
||
}else{
|
||
//非原单且无登记记录,查询是否有货主已登记
|
||
$BackrecordcustomerModel = new \app\common\model\wms\Backrecordcustomer;
|
||
$order = $BackrecordcustomerModel->where(["POSTNUM"=>$postnum])->find();
|
||
if($order){
|
||
foreach ($stores as $store){
|
||
if(intval($order["STOREID"])==intval($store["STOREID"])){
|
||
$tmp_store = $store;
|
||
}
|
||
}
|
||
$res["stores"] = [$tmp_store];
|
||
}
|
||
$res["YDFLAG"] = 0;
|
||
}
|
||
}
|
||
}
|
||
return json($res);
|
||
}
|
||
private function getStocksByItem($items){
|
||
$itemsArr = array_filter(explode("|",$items),'trim');
|
||
$SKUS = [];
|
||
foreach ($itemsArr as $r){
|
||
$sotcks_arr = array_filter(explode(",",$r),'trim');
|
||
array_push($SKUS,$sotcks_arr[0]);
|
||
}
|
||
$StockModel = new \app\common\model\wms\Stock;
|
||
$stocks = $StockModel->where("STOCKID","in",$SKUS)->with(["goods"])->select();
|
||
foreach ($stocks as $k => $r){
|
||
foreach ($itemsArr as $rr){
|
||
$sotcks_arr = array_filter(explode(",",$rr),'trim');
|
||
if($sotcks_arr[0]==$r["STOCKID"]){
|
||
$stocks[$k]["count"] = $sotcks_arr[1];
|
||
}
|
||
}
|
||
}
|
||
return $stocks;
|
||
}
|
||
private function getOrderInfoByPostnum($postnum){
|
||
$status = 0;
|
||
$ExpressModel = new \app\common\model\wms\Express;
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$OrderModel1 = new \app\common\model\wms\Order1;
|
||
$DeliveryorderModel = new \app\common\model\wms\Deliveryorder;
|
||
$expressRow = $ExpressModel->where(["POSTNUM"=>$postnum])->find();
|
||
if(!$expressRow){
|
||
return false;
|
||
}
|
||
if(!$expressRow["TRADEORDER"]){
|
||
$where = '(POSTNUM = "'.$postnum.'")';
|
||
}else{
|
||
$where = '(SOURCEID="'.$expressRow["TRADEORDER"].'" or POSTNUM = "'.$postnum.'")';
|
||
}
|
||
$order = $OrderModel->where($where)->find();
|
||
if($order){
|
||
$status = 1;
|
||
}else{//不在待处理
|
||
$status = 2;
|
||
$order = $OrderModel1->where($where)->find();
|
||
if(!$order){//不在配送
|
||
$order = $DeliveryorderModel->where($where)->find();
|
||
if(!$order){//不在历史
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
$order["status"] = $status;
|
||
return $order;
|
||
}
|
||
public function getStores(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = isset($params["WAREHOUSEID"])?$params["WAREHOUSEID"]:0;
|
||
$StoreModel = new \app\common\model\wms\Warestore;
|
||
$list = $StoreModel->field('TITLE,STOREID')->where(["WAREHOUSEID"=>$WAREHOUSEID])->select();
|
||
$this->view->assign('list', $list);
|
||
return $this->view->fetch();
|
||
}
|
||
public function getGzts($WAREHOUSEID=null){
|
||
if(!$WAREHOUSEID){
|
||
return "";
|
||
}
|
||
$GztModel = new \app\common\model\Gzt;
|
||
$list = $GztModel->field('username,name')->where(["WAREHOUSEID"=>$WAREHOUSEID,"type"=>1])->select();
|
||
foreach($list as $k => $r){
|
||
$list[$k]["BARCODE"] = base64_encode(json_encode(["username"=>$r["username"],"password"=>str_replace("C", "c", $r["username"])]));
|
||
}
|
||
//return json($list);
|
||
$this->view->assign('list', $list);
|
||
return $this->view->fetch();
|
||
}
|
||
|
||
public function getPacks($WAREHOUSEID=5400){
|
||
$params=$this->request->post();
|
||
$PackModel = new \app\common\model\wms\Pack;
|
||
$list = $PackModel->field('NAME,BARCODE')->where(["WAREHOUSEID"=>$WAREHOUSEID])->order("NAME")->select();
|
||
$this->view->assign('list', $list);
|
||
return $this->view->fetch();
|
||
}
|
||
public function getStoresAjax(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = isset($params["WAREHOUSEID"])?$params["WAREHOUSEID"]:0;
|
||
$StoreModel = new \app\common\model\wms\Warestore;
|
||
$list = $StoreModel->alias('Warestore')->field('Warestore.TITLE,store.STOREID as STOREID')->join('yj_store store','store.STOREID=Warestore.STOREID','left')->where(["WAREHOUSEID"=>$WAREHOUSEID])->select();
|
||
return json($list);
|
||
}
|
||
private function getStoresArray($WAREHOUSEID = 0){
|
||
$StoreModel = new \app\common\model\wms\Warestore;
|
||
$list = $StoreModel->field('TITLE,STOREID as STOREID')->where(["WAREHOUSEID"=>$WAREHOUSEID])->select();
|
||
return json_decode(json_encode($list),true);
|
||
}
|
||
public function sandan(){
|
||
//打包
|
||
$WAREHOUSEID = $this->request->get("WAREHOUSEID");
|
||
$model = new \app\common\model\wms\Order;
|
||
$list = $model->where(["WAREHOUSEID"=>$WAREHOUSEID,"PRINTTIMES"=>1])
|
||
->where('GRABNUM not like \'%B%\'')
|
||
->field('OPERATERECORDS,GOODSCOUNT,POSTNUM,ITEMS')
|
||
->select();
|
||
$dabaolist = [];
|
||
foreach($list as $r){
|
||
$tmp = explode("|",$r['OPERATERECORDS']);
|
||
$tmpitems = explode("|",$r['ITEMS']);
|
||
$r['skusum'] = count($tmpitems)-1;
|
||
$isfh = false;
|
||
foreach($tmp as $dd){
|
||
$tmp2 = explode(";",$dd);
|
||
if($tmp2[0]=="打包"){
|
||
$isfh = true;
|
||
}
|
||
}
|
||
if($isfh){
|
||
array_push($dabaolist,$r);
|
||
}
|
||
}
|
||
foreach($dabaolist as $k => $d){
|
||
$tmp = explode("|",$d['OPERATERECORDS']);
|
||
$d['endtime'] = -1;
|
||
foreach($tmp as $dd){
|
||
$tmp2 = explode(";",$dd);
|
||
if($tmp2[0]=="打包"){
|
||
$d['username']=$tmp2[2];
|
||
$dateTime = date_create_from_format('Y年m月d日 H:i:s', $tmp2[1]);
|
||
$tmpt = strtotime(date_format($dateTime, 'Y-m-d H:i:s'));
|
||
$d['endtime'] = $tmpt;
|
||
$d['time'] = date('Y-m-d H:i:s', $tmpt);
|
||
unset($d['OPERATERECORDS']);
|
||
}
|
||
}
|
||
}
|
||
usort($dabaolist, function($a, $b) {
|
||
return $b['endtime'] - $a['endtime'];
|
||
});
|
||
$dabaoTops = [];
|
||
foreach($dabaolist as $r){
|
||
$hasUser = -1;
|
||
foreach ($dabaoTops as $k=> $rr){
|
||
if($rr['username']==$r['username']){
|
||
$hasUser = $k;
|
||
}
|
||
}
|
||
if($hasUser == -1){
|
||
array_push($dabaoTops,["username"=>$r['username'],"count"=>1,"goodscount"=>$r['GOODSCOUNT'],"skusum"=>$r['skusum']]);
|
||
}else{
|
||
$dabaoTops[$hasUser]['goodscount']+=$r['GOODSCOUNT'];
|
||
$dabaoTops[$hasUser]['skusum']+=$r['skusum'];
|
||
$dabaoTops[$hasUser]['count']+=1;
|
||
}
|
||
}
|
||
|
||
usort($dabaoTops, function($a, $b) {
|
||
return $b['count'] - $a['count'];
|
||
});
|
||
//拣货
|
||
$model = new \app\common\model\wms\Order;
|
||
$jianhuolist = $model->where(["WAREHOUSEID"=>$WAREHOUSEID,"PICKINGFLAG"=>3])
|
||
->where('GRABNUM not like \'%B%\'')
|
||
->group('GRABNUM')
|
||
->field('OPERATERECORDS,sum(GOODSCOUNT) as GOODSCOUNT,count(*) as ordercount,GRABNUM')
|
||
->select();
|
||
foreach($jianhuolist as $k => $d){
|
||
$tmp = explode("|",$d['OPERATERECORDS']);
|
||
$d['endtime'] = -1;
|
||
$d['username']='';
|
||
foreach($tmp as $dd){
|
||
$tmp2 = explode(";",$dd);
|
||
if(strpos($tmp2[0],"拣货")!==false){
|
||
$d['username']=$tmp2[2];
|
||
$dateTime = date_create_from_format('Y年m月d日 H:i:s', $tmp2[1]);
|
||
$tmpt = strtotime(date_format($dateTime, 'Y-m-d H:i:s'));
|
||
$d['endtime'] = $tmpt;
|
||
$d['time'] = date('Y-m-d H:i:s', $tmpt);
|
||
unset($d['OPERATERECORDS']);
|
||
}
|
||
}
|
||
}
|
||
usort($jianhuolist, function($a, $b) {
|
||
return $b['endtime'] - $a['endtime'];
|
||
});
|
||
$jianhuoTops = [];
|
||
foreach($jianhuolist as $r){
|
||
$hasUser = -1;
|
||
foreach ($jianhuoTops as $k=> $rr){
|
||
if($rr['username']==$r['username']){
|
||
$hasUser = $k;
|
||
}
|
||
}
|
||
if($hasUser == -1){
|
||
array_push($jianhuoTops,["username"=>$r['username'],"count"=>1,"goodscount"=>$r['GOODSCOUNT'],"ordercount"=>$r['ordercount']]);
|
||
}else{
|
||
$jianhuoTops[$hasUser]['goodscount']+=$r['GOODSCOUNT'];
|
||
$jianhuoTops[$hasUser]['ordercount']+=$r['ordercount'];
|
||
$jianhuoTops[$hasUser]['count']+=1;
|
||
}
|
||
}
|
||
|
||
usort($jianhuoTops, function($a, $b) {
|
||
return $b['ordercount'] - $a['ordercount'];
|
||
});
|
||
//复核
|
||
$list = $model->where(["WAREHOUSEID"=>$WAREHOUSEID,"pickingFlag"=>3])
|
||
->where('GRABNUM not like \'%B%\'')
|
||
->field('OPERATERECORDS,GOODSCOUNT,POSTNUM,ITEMS')
|
||
->select();
|
||
$fhlist = [];
|
||
foreach($list as $r){
|
||
$tmp = explode("|",$r['OPERATERECORDS']);
|
||
$tmpitems = explode("|",$r['ITEMS']);
|
||
$r['skusum'] = count($tmpitems)-1;
|
||
$isfh = false;
|
||
foreach($tmp as $dd){
|
||
$tmp2 = explode(";",$dd);
|
||
if(strpos($tmp2[0],"发货")!==false){
|
||
$isfh = true;
|
||
}
|
||
}
|
||
if($isfh){
|
||
array_push($fhlist,$r);
|
||
}
|
||
}
|
||
foreach($fhlist as $k => $d){
|
||
$tmp = explode("|",$d['OPERATERECORDS']);
|
||
$d['endtime'] = -1;
|
||
$notfh = false;
|
||
foreach($tmp as $dd){
|
||
$tmp2 = explode(";",$dd);
|
||
if(strpos($tmp2[0],"发货")!==false){
|
||
$d['username']=$tmp2[2];
|
||
$dateTime = date_create_from_format('Y年m月d日 H:i:s', $tmp2[1]);
|
||
$tmpt = strtotime(date_format($dateTime, 'Y-m-d H:i:s'));
|
||
$d['endtime'] = $tmpt;
|
||
$d['time'] = date('Y-m-d H:i:s', $tmpt);
|
||
unset($d['OPERATERECORDS']);
|
||
}
|
||
}
|
||
if($notfh){
|
||
unset($fhlist[$k]);
|
||
}
|
||
}
|
||
usort($fhlist, function($a, $b) {
|
||
return $b['endtime'] - $a['endtime'];
|
||
});
|
||
$fuheTops = [];
|
||
foreach($fhlist as $r){
|
||
$hasUser = -1;
|
||
foreach ($fuheTops as $k=> $rr){
|
||
if($rr['username']==$r['username']){
|
||
$hasUser = $k;
|
||
}
|
||
}
|
||
if($hasUser == -1){
|
||
array_push($fuheTops,["username"=>$r['username'],"count"=>1,"goodscount"=>$r['GOODSCOUNT'],"skusum"=>$r['skusum']]);
|
||
}else{
|
||
$fuheTops[$hasUser]['goodscount']+=$r['GOODSCOUNT'];
|
||
$fuheTops[$hasUser]['skusum']+=$r['skusum'];
|
||
$fuheTops[$hasUser]['count']+=1;
|
||
}
|
||
}
|
||
|
||
usort($fuheTops, function($a, $b) {
|
||
return $b['count'] - $a['count'];
|
||
});
|
||
//退货
|
||
$t3 = date('Y-m-d')." 01:00:00";
|
||
$model = new \app\common\model\wms\Backrecord;
|
||
$list = $model->field('MAX(cast(CREATIONDATE as signed)) as time,sum(COUNT) as COUNT,USERID,POSTNUM')->where(["WAREHOUSEID"=>$WAREHOUSEID])->where('cast(CREATIONDATE as signed)>'.strtotime($t3)*1000)->group('POSTNUM')->select();
|
||
$tuihuolist = [];
|
||
foreach($list as $r){
|
||
$r['lasttime'] = date('Y-m-d H:i:s', $r['time']/1000);
|
||
if($r['POSTNUM']!=''){
|
||
$modelUser = new \app\common\model\wms\User;
|
||
|
||
$dd = $modelUser->where(['userId'=>$r['USERID']])->find();
|
||
$name = ($dd['name'] ?? null);
|
||
$r['username'] = $name;
|
||
array_push($tuihuolist,$r);
|
||
}
|
||
}
|
||
usort($tuihuolist, function($a, $b) {
|
||
return $b['time'] - $a['time'];
|
||
});
|
||
$tuihuoTops = [];
|
||
foreach($tuihuolist as $r){
|
||
$hasUser = -1;
|
||
foreach ($tuihuoTops as $k=> $rr){
|
||
if($rr['USERID']==$r['USERID']){
|
||
$hasUser = $k;
|
||
}
|
||
}
|
||
if($hasUser == -1){
|
||
array_push($tuihuoTops,["username"=>$r['username'],"USERID"=>$r['USERID'],"count"=>1,"goodscount"=>$r['COUNT']]);
|
||
}else{
|
||
$tuihuoTops[$hasUser]['goodscount']+=$r['COUNT'];
|
||
$tuihuoTops[$hasUser]['count']+=1;
|
||
}
|
||
}
|
||
|
||
usort($tuihuoTops, function($a, $b) {
|
||
return $b['count'] - $a['count'];
|
||
});
|
||
return json(["jianhuoTop"=>$jianhuoTops,"jianhuoList"=>$jianhuolist,"fuheList"=>$fhlist,"fuheTop"=>$fuheTops,"tuihuoList"=>$tuihuolist,"tuihuoTop"=>$tuihuoTops,"dabaoList"=>$dabaolist,"dabaoTop"=>$dabaoTops]);
|
||
}
|
||
public function findboci(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$model = new \app\common\model\wms\Order;
|
||
$data = $model->where(["WAREHOUSEID"=>$WAREHOUSEID,"POSTNUM"=>str_replace("-1-1-", "", $params['sn']),"PRINTTIMES"=>1])->find();
|
||
if($data){
|
||
$isLingliao = strpos($data['OPERATERECORDS'],'领取快递面单') ||strpos($data['OPERATERECORDS'],'领料');
|
||
|
||
$GRABNUM = $isLingliao?0:($data['GRABNUM']?$data['GRABNUM']:0);
|
||
}else{
|
||
$GRABNUM = null;
|
||
return json(["GRABNUM"=>$GRABNUM,"data"=>$data]);
|
||
}
|
||
$model2 = new \app\common\model\wms\Order;
|
||
$data2 = $model2->where(["WAREHOUSEID"=>$WAREHOUSEID,"POSTNUM"=>'',"GRABNUM"=>$GRABNUM])->find();
|
||
if($data2){
|
||
return json(["GRABNUM"=>-1,"data"=>$data]);
|
||
}
|
||
return json(["GRABNUM"=>$GRABNUM,"data"=>$data]);
|
||
}
|
||
public function getinfo(){
|
||
$params=$this->request->post();
|
||
$model = new \app\common\model\wms\Order;
|
||
$Paracodemodel = new \app\common\model\wms\Paracode;
|
||
$Expressmodel = new \app\common\model\wms\Express;
|
||
$POSTNUM = "";
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$hasorder = $Expressmodel->where(["POSTNUM"=>str_replace("-1-1-", "", $params['sn'])])->where(["WAREHOUSEID"=>$WAREHOUSEID])->select();
|
||
$isChild = false;
|
||
$OPAS=null;
|
||
$lastTime = 0;
|
||
if($hasorder){
|
||
$data = $model->where(["POSTNUM"=>str_replace("-1-1-", "", $params['sn'])])->with(['pack'])->where(["order.WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
$hasChild = $Expressmodel->where(["ORIGINPOSTNUM"=>str_replace("-1-1-", "", $params['sn'])])->where(["WAREHOUSEID"=>$WAREHOUSEID])->select();
|
||
if(!$data){
|
||
$model = new \app\common\model\wms\Deliveryorder;
|
||
$data = $model->where(["POSTNUM"=>str_replace("-1-1-", "", $params['sn'])])->with(['pack'])->find();
|
||
if($data){
|
||
$items = $data["ITEMS"];
|
||
$tmp = explode("|",$items);
|
||
$stocks = [];
|
||
foreach ($tmp as $r){
|
||
if($r){
|
||
$tmp2 = explode(",",$r);
|
||
array_push($stocks,[$tmp2[0],$tmp2[1]]);
|
||
}
|
||
}
|
||
usort($stocks, function($a, $b) {
|
||
return $b[0] - $a[0];
|
||
});
|
||
$STOCKS_tmp = "";
|
||
foreach ($stocks as $r){
|
||
$STOCKS_tmp.=$r[0].$r[1];
|
||
}
|
||
$data["STOCKS"] = $STOCKS_tmp;
|
||
}
|
||
}
|
||
if(!$data){
|
||
$data = $Expressmodel->where(["POSTNUM"=>str_replace("-1-1-", "", $params['sn'])])->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
if($data){
|
||
$isChild = true;
|
||
$POSTNUM = str_replace("-1-1-", "", $params['sn']);
|
||
$model = new \app\common\model\wms\Order1;
|
||
$data = $model->where(["POSTNUM"=>($data['ORIGINPOSTNUM'] ?? null),"PLSENDFLAG"=>1])->where(["WAREHOUSEID"=>$WAREHOUSEID])->with(['pack'])->find();
|
||
}
|
||
}
|
||
if(!$isChild && $data){
|
||
$match = null;
|
||
$OPERATERECORDS = isset($data['OPERATERECORDS'])?$data['OPERATERECORDS']:$data['NOTES'];
|
||
if (preg_match("/.*设置重量;([^;]+);([^|]+)/i", $OPERATERECORDS, $match)){
|
||
$OPAS = $match;
|
||
}
|
||
if($OPAS[1]){
|
||
$lastTime = $OPAS[1];
|
||
}
|
||
}
|
||
}else{
|
||
$data = false;
|
||
}
|
||
$GRABNUM2= "";
|
||
if($data){
|
||
$GRABNUM = $POSTNUM?$POSTNUM:$data['POSTNUM'];
|
||
$GRABNUM2 = $data['GRABNUM'];
|
||
$pack = $data['pack']['NAME'];
|
||
$data2=$Paracodemodel->where(["TYPE"=>"301","CODE"=>$data['POSTCODE']])->find();
|
||
$POSTNAME = ($data2["NAME"] ?? null);
|
||
$WEIGHT = isset($data["ORDERWEIGHT"])?$data["ORDERWEIGHT"]:0;
|
||
$hasChild = !!$hasChild;
|
||
$FLAG = $data['FLAG'];
|
||
$STOCKS = $data["STOCKS"];
|
||
$ITEMS = $data["ITEMS"];
|
||
$PLSENDFLAG = $data["PLSENDFLAG"];
|
||
}else{
|
||
$GRABNUM = null;
|
||
$pack = null;
|
||
$POSTNAME=null;
|
||
$WEIGHT = 0;
|
||
$hasChild = false;
|
||
$FLAG = 0;
|
||
$STOCKS = null;
|
||
$ITEMS = null;
|
||
$PLSENDFLAG = 0;
|
||
}
|
||
return json(["GRABNUM"=>$GRABNUM,"PLSENDFLAG"=>$PLSENDFLAG,"GRABNUM2"=>$GRABNUM2,"pack"=>$pack,"POSTNAME"=>$POSTNAME,"ORDERWEIGHT"=>$WEIGHT,"hasChild"=>$hasChild,"isChild"=>$isChild,"OPAS"=>$lastTime,"FLAG"=>$FLAG,"STOCKS"=>$STOCKS,"ITEMS"=>$ITEMS]);
|
||
}
|
||
public function POSTNUMList(){
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$data = $OrderModel
|
||
->field('A.POSTNUM')
|
||
->alias('A')
|
||
->join(['yj_express B'], 'A.POSTNUM = B.POSTNUM','left')
|
||
->where('B.POSTNUM', 'NULL', 'IS')
|
||
->where('A.POSTCODE<>"p30" and A.POSTCODE<>"p27"')
|
||
->where(["A.WAREHOUSEID"=>5400,"A.DISPLAYFLAG"=>0,"A.POSTFLAG"=>1])
|
||
->select();
|
||
foreach ($data as $k => $r){
|
||
$res = Wsdl::webservice([$r['POSTNUM'],5400],"createExpress1");
|
||
$data[$k]["res"] = $res;
|
||
}
|
||
return json($data);
|
||
}
|
||
public function getinfo3(){
|
||
$params=$this->request->post();
|
||
$model = new \app\common\model\wms\Order;
|
||
$Paracodemodel = new \app\common\model\wms\Paracode;
|
||
$Expressmodel = new \app\common\model\wms\Express;
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$POSTNUM = str_replace("-1-1-", "", $params['sn']);
|
||
$hasorder = $Expressmodel->where(["POSTNUM"=>$POSTNUM])->where(["WAREHOUSEID"=>$WAREHOUSEID])->select();
|
||
$isChild = false;
|
||
$OPAS=null;
|
||
$lastTime = 0;
|
||
if($hasorder){
|
||
$data = $model->where(["POSTNUM"=>$POSTNUM])->with(['pack'])->where(["order.WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
$hasChild = $Expressmodel->where(["ORIGINPOSTNUM"=>$POSTNUM])->where(["WAREHOUSEID"=>$WAREHOUSEID])->select();
|
||
if(!$data){
|
||
$model = new \app\common\model\wms\Deliveryorder;
|
||
$data = $model->where(["POSTNUM"=>$POSTNUM])->where(["order.WAREHOUSEID"=>$WAREHOUSEID])->with(['pack'])->find();
|
||
if($data){
|
||
$items = $data["ITEMS"];
|
||
$tmp = explode("|",$items);
|
||
$stocks = [];
|
||
foreach ($tmp as $r){
|
||
if($r){
|
||
$tmp2 = explode(",",$r);
|
||
array_push($stocks,[$tmp2[0],$tmp2[1]]);
|
||
}
|
||
}
|
||
usort($stocks, function($a, $b) {
|
||
return $b[0] - $a[0];
|
||
});
|
||
$STOCKS_tmp = "";
|
||
foreach ($stocks as $r){
|
||
$STOCKS_tmp.=$r[0].$r[1];
|
||
}
|
||
$data["STOCKS"] = $STOCKS_tmp;
|
||
}
|
||
}
|
||
if(!$data){
|
||
$data = $Expressmodel->where(["POSTNUM"=>str_replace("-1-1-", "", $params['sn'])])->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
if($data){
|
||
$isChild = true;
|
||
$POSTNUM = str_replace("-1-1-", "", $params['sn']);
|
||
$model = new \app\common\model\wms\Order1;
|
||
$data = $model->where(["POSTNUM"=>($data['ORIGINPOSTNUM'] ?? null),"PLSENDFLAG"=>1])->where(["order.WAREHOUSEID"=>$WAREHOUSEID])->with(['pack'])->find();
|
||
}
|
||
}
|
||
if(!$isChild && $data){
|
||
$match = null;
|
||
$OPERATERECORDS = isset($data['OPERATERECORDS'])?$data['OPERATERECORDS']:$data['NOTES'];
|
||
if (preg_match("/.*设置重量;([^;]+);([^|]+)/i", $OPERATERECORDS, $match)){
|
||
$OPAS = $match;
|
||
}
|
||
if($OPAS[1]){
|
||
$lastTime = $OPAS[1];
|
||
}
|
||
}
|
||
}else{
|
||
$data = false;
|
||
}
|
||
// ===== 本地未查到,回退查询 new_wms 外部WMS =====
|
||
$fromNewWms = false;
|
||
if(!$data){
|
||
$wmsResult = $this->_queryNewWms($POSTNUM);
|
||
if($wmsResult && isset($wmsResult['flag']) && $wmsResult['flag'] === 'success' && !empty($wmsResult['order'])){
|
||
$fromNewWms = true;
|
||
$wmsOrder = $wmsResult['order'];
|
||
$wmsItems = isset($wmsResult['items']) ? $wmsResult['items'] : [];
|
||
$wmsExpress = isset($wmsResult['express']) ? $wmsResult['express'] : [];
|
||
$ITEMS_arr = [];
|
||
$STOCKS_arr = [];
|
||
foreach($wmsItems as $it){
|
||
$code = isset($it['item_code']) ? $it['item_code'] : '';
|
||
$qty = isset($it['plan_qty']) ? $it['plan_qty'] : 1;
|
||
$name = isset($it['item_name']) ? $it['item_name'] : '';
|
||
$ITEMS_arr[] = $code . ',' . $qty . ',' . $name;
|
||
$STOCKS_arr[] = $code . $qty;
|
||
}
|
||
$GRABNUM = (isset($wmsOrder['wave_no']) && $wmsOrder['wave_no']) ? $wmsOrder['wave_no'] : $POSTNUM;
|
||
$GRABNUM2 = '';
|
||
$pack = isset($wmsExpress['package_material_name']) ? $wmsExpress['package_material_name'] : '';
|
||
$POSTNAME = isset($wmsOrder['logistics_name']) ? $wmsOrder['logistics_name'] : null;
|
||
$WEIGHT = isset($wmsOrder['items_weight']) ? $wmsOrder['items_weight'] : 0;
|
||
$hasChild = false;
|
||
$isChild = false;
|
||
$OPAS = null;
|
||
$lastTime = 0;
|
||
$FLAG = 0;
|
||
$STOCKS = implode('', $STOCKS_arr);
|
||
$ITEMS = implode('|', $ITEMS_arr);
|
||
$PLSENDFLAG = (isset($wmsOrder['recheck_status']) && $wmsOrder['recheck_status'] === 'fin') ? 1 : 0;
|
||
$hasorder = true;
|
||
}
|
||
}
|
||
// ===== new_wms 回退结束 =====
|
||
if(!$fromNewWms){
|
||
$GRABNUM2= "";
|
||
if($data){
|
||
$GRABNUM = $POSTNUM?$POSTNUM:$data['POSTNUM'];
|
||
$GRABNUM2 = $data['GRABNUM'];
|
||
$pack = $data['pack']['NAME'];
|
||
$data2=$Paracodemodel->where(["TYPE"=>"301","CODE"=>$data['POSTCODE']])->find();
|
||
$POSTNAME = ($data2["NAME"] ?? null);
|
||
$WEIGHT = isset($data["ORDERWEIGHT"])?$data["ORDERWEIGHT"]:0;
|
||
$hasChild = !!$hasChild;
|
||
$FLAG = $data['FLAG'];
|
||
$STOCKS = $data["STOCKS"];
|
||
$ITEMS = $data["ITEMS"];
|
||
$PLSENDFLAG = isset($data["PLSENDFLAG"])?$data["PLSENDFLAG"]:1;
|
||
}else{
|
||
$GRABNUM = null;
|
||
$pack = null;
|
||
$POSTNAME=null;
|
||
$WEIGHT = 0;
|
||
$hasChild = false;
|
||
$FLAG = 0;
|
||
$STOCKS = null;
|
||
$ITEMS = null;
|
||
$PLSENDFLAG = 0;
|
||
}
|
||
}
|
||
return json(["GRABNUM"=>$GRABNUM,"PLSENDFLAG"=>$PLSENDFLAG,"GRABNUM2"=>$GRABNUM2,"pack"=>$pack,"POSTNAME"=>$POSTNAME,"ORDERWEIGHT"=>$WEIGHT,"hasChild"=>$hasChild,"isChild"=>$isChild,"OPAS"=>$lastTime,"FLAG"=>$FLAG,"STOCKS"=>$STOCKS,"ITEMS"=>$ITEMS,"hasorder"=>$hasorder,"POSTNUM"=>$POSTNUM,"isNewWms"=>$fromNewWms?1:0]);
|
||
}
|
||
public function sendWeight(){
|
||
$params = $this->request->post();
|
||
$sn = isset($params['sn']) ? $params['sn'] : '';
|
||
$weight = isset($params['weight']) ? $params['weight'] : '';
|
||
if(!$sn){
|
||
return json(['flag'=>'fail','message'=>'缺少 sn']);
|
||
}
|
||
$url = self::NEW_WMS_API;
|
||
$url .= '?method=workbench.business&v=1.0×tamp=' . time();
|
||
$postData = json_encode([
|
||
'name' => 'sendWeight',
|
||
'data' => [
|
||
'barcode' => $sn,
|
||
'weight' => $weight,
|
||
'warehouseId' => '1000028',
|
||
]
|
||
]);
|
||
$ch = curl_init();
|
||
curl_setopt_array($ch, [
|
||
CURLOPT_URL => $url,
|
||
CURLOPT_POST => true,
|
||
CURLOPT_POSTFIELDS => $postData,
|
||
CURLOPT_HTTPHEADER => [
|
||
'Content-Type: application/json',
|
||
'platform: web',
|
||
'project: all',
|
||
],
|
||
CURLOPT_RETURNTRANSFER => true,
|
||
CURLOPT_TIMEOUT => 5,
|
||
]);
|
||
$response = curl_exec($ch);
|
||
curl_close($ch);
|
||
$result = json_decode($response, true);
|
||
return json($result ?: ['flag'=>'fail','message'=>'new_wms 无响应']);
|
||
}
|
||
// ===== new_wms 外部WMS查单(供 getinfo3 本地无结果时回退) =====
|
||
private function _queryNewWms($barcode){
|
||
$url = self::NEW_WMS_API;
|
||
$url .= '?method=workbench.business&v=1.0×tamp=' . time();
|
||
$postData = json_encode([
|
||
'name' => 'queryOrder',
|
||
'data' => ['barcode' => $barcode, 'warehouseId' => '1000028']
|
||
]);
|
||
$ch = curl_init();
|
||
curl_setopt_array($ch, [
|
||
CURLOPT_URL => $url,
|
||
CURLOPT_POST => true,
|
||
CURLOPT_POSTFIELDS => $postData,
|
||
CURLOPT_HTTPHEADER => [
|
||
'Content-Type: application/json',
|
||
'platform: web',
|
||
'project: all',
|
||
],
|
||
CURLOPT_RETURNTRANSFER => true,
|
||
CURLOPT_TIMEOUT => 5,
|
||
]);
|
||
$response = curl_exec($ch);
|
||
curl_close($ch);
|
||
return json_decode($response, true);
|
||
}
|
||
// ===== new_wms 发送外部打包 =====
|
||
private function _packNewWms($params){
|
||
$url = self::NEW_WMS_API;
|
||
$url .= '?method=workbench.business&v=1.0×tamp=' . time();
|
||
$postData = json_encode([
|
||
'name' => 'packOrder',
|
||
'data' => [
|
||
'delivery_order_code' => $params['deliveryOrderCode'],
|
||
'wave_no'=> isset($params['waveNo']) ? $params['waveNo'] : '',
|
||
'workbench_id'=>$params['workbenchIdRaw'] ?? [],
|
||
'status'=> isset($params['packStatus']) ? $params['packStatus'] : 1,
|
||
'pack_time'=> isset($params['packTime']) ? $params['packTime'] : time(),
|
||
'wave_total_orders'=> isset($params['waveTotalOrders']) ? $params['waveTotalOrders'] : 1,
|
||
'items_count'=> isset($params['itemsCount']) ? $params['itemsCount'] : 1,
|
||
'items_total'=> isset($params['itemsTotal']) ? $params['itemsTotal'] : 1,
|
||
'users'=> isset($params['usersParam']) ? $params['usersParam'] : [],
|
||
'warehouse_id' => '1000028'
|
||
]
|
||
]);
|
||
|
||
\think\Log::error('_packNewWms newWms query: ' . json_encode($postData, JSON_UNESCAPED_UNICODE));
|
||
|
||
$ch = curl_init();
|
||
curl_setopt_array($ch, [
|
||
CURLOPT_URL => $url,
|
||
CURLOPT_POST => true,
|
||
CURLOPT_POSTFIELDS => $postData,
|
||
CURLOPT_HTTPHEADER => [
|
||
'Content-Type: application/json',
|
||
'platform: web',
|
||
'project: all',
|
||
],
|
||
CURLOPT_RETURNTRANSFER => true,
|
||
CURLOPT_TIMEOUT => 5,
|
||
]);
|
||
$response = curl_exec($ch);
|
||
curl_close($ch);
|
||
return json_decode($response, true);
|
||
}
|
||
|
||
public function getinfo4(){
|
||
$params=$this->request->post();
|
||
$model = new \app\common\model\wms\Order;
|
||
$WAREHOUSEID = isset($params['WAREHOUSEID'])?$params['WAREHOUSEID']:5400;
|
||
$Paracodemodel = new \app\common\model\wms\Paracode;
|
||
$Expressmodel = new \app\common\model\wms\Express;
|
||
$POSTNUM = str_replace("-1-1-", "", $params['sn']);
|
||
$hasorder = $Expressmodel->where(["POSTNUM"=>$POSTNUM])->select();
|
||
$isChild = false;
|
||
$OPAS=null;
|
||
$lastTime = 0;
|
||
$type = 1;
|
||
$data = null;
|
||
$fromNewWms = false;
|
||
if($hasorder){
|
||
$data = $model->where(["order.WAREHOUSEID"=>$WAREHOUSEID])->where(["POSTNUM"=>$POSTNUM])->with(['pack'])->find();
|
||
if(!$data){
|
||
$type = 2;
|
||
$model = new \app\common\model\wms\Deliveryorder;
|
||
$data = $model->where(["order.WAREHOUSEID"=>$WAREHOUSEID])->where(["POSTNUM"=>$POSTNUM])->with(['pack'])->find();
|
||
if($data){
|
||
$data->PLSENDFLAG =1;
|
||
}
|
||
}
|
||
if($data){
|
||
$GRABNUM = $data["GRABNUM"];
|
||
if(strpos($GRABNUM,"B")===false){
|
||
return json(["isSandan"=>true]);
|
||
}
|
||
$model = $type==1?new \app\common\model\wms\Order:new \app\common\model\wms\Deliveryorder;
|
||
if($type==1){
|
||
$data = $model->where(["WAREHOUSEID"=>$WAREHOUSEID])->field('count(*) as count,ITEMS,STOREID,GRABNUM,max(PLSENDFLAG) as PLSENDFLAG')->where(["GRABNUM"=>$GRABNUM,"FLAG"=>0])->select();
|
||
}else{
|
||
$data = $model->where(["WAREHOUSEID"=>$WAREHOUSEID])->field('count(*) as count,ITEMS,STOREID,GRABNUM,1 as PLSENDFLAG')->where(["GRABNUM"=>$GRABNUM,"FLAG"=>0])->select();
|
||
}
|
||
$Worksmodel = new \app\common\model\workers\Works;
|
||
$lastTime = time() - 259200;
|
||
$isPack = $Worksmodel->where(["grabnum"=>$GRABNUM])->where("dabaos>0")->where("workDate>{$lastTime}")->find();
|
||
if($data){
|
||
$data = $data[0];
|
||
$data["POSTNUM"] = $POSTNUM;
|
||
if($isPack){
|
||
$data["isPack"] = true;
|
||
}else{
|
||
$items_tmp = [];
|
||
$StoreModel = new \app\common\model\wms\Store;
|
||
$store = $StoreModel->where(["STOREID"=>$data["STOREID"]])->find();
|
||
$data["STORE"] = ($store["TITLE"] ?? null);
|
||
$items = array_filter(explode("|",$data['ITEMS']),'trim');
|
||
foreach ($items as $r){
|
||
$STOCKINFO = explode(",",$r);
|
||
$model = new \app\common\model\wms\Stock;
|
||
$STOCK = $model->where(["WAREHOUSEID"=>$WAREHOUSEID])->where(["STOCKID"=>$STOCKINFO[0]])->find();
|
||
if(isset($STOCKINFO[2]) && strpos($STOCKINFO[2],'yc#zy')==false){
|
||
$imgs = $this->getStockImgs($STOCKINFO[0]);
|
||
array_push($items_tmp,['STOCKIDS'=>$STOCKINFO[0],'count'=>$STOCKINFO[1],'title'=>$STOCKINFO[2],'ercode'=>($STOCK['BARCODE'] ?? null),'COLOR'=>($STOCK['COLOR'] ?? null),'STYLE'=>($STOCK['STYLE'] ?? null),'IMG'=>($STOCK['IMG'] ?? null),'ispick'=>!!($STOCK['SCANFLAG'] ?? null),"fhcount"=>0,"imgs"=>$imgs]);
|
||
}
|
||
}
|
||
$data["items"] = $items_tmp;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
// ===== 本地未查到,回退查询 new_wms 外部WMS =====
|
||
if(!$data){
|
||
$wmsResult = $this->_queryNewWms($POSTNUM);
|
||
\think\Log::error('getinfo4 newWms result: ' . json_encode($wmsResult, JSON_UNESCAPED_UNICODE));
|
||
if($wmsResult && isset($wmsResult['flag']) && $wmsResult['flag'] === 'success' && !empty($wmsResult['order'])){
|
||
$fromNewWms = true;
|
||
$wmsOrder = $wmsResult['order'];
|
||
$wmsItems = isset($wmsResult['items']) ? $wmsResult['items'] : [];
|
||
$wmsBatch = isset($wmsResult['batch']) ? $wmsResult['batch'] : [];
|
||
$ITEMS_arr = [];
|
||
$STOCKS_arr = [];
|
||
foreach($wmsItems as $it){
|
||
$code = isset($it['item_code']) ? $it['item_code'] : '';
|
||
$qty = isset($it['plan_qty']) ? $it['plan_qty'] : 1;
|
||
$name = isset($it['item_name']) ? $it['item_name'] : '';
|
||
$ITEMS_arr[] = $code . ',' . $qty . ',' . $name;
|
||
$STOCKS_arr[] = $code . $qty;
|
||
}
|
||
$GRABNUM = (isset($wmsOrder['wave_no']) && $wmsOrder['wave_no']) ? $wmsOrder['wave_no'] : $POSTNUM;
|
||
$PLSENDFLAG = (isset($wmsOrder['recheck_status']) && $wmsOrder['recheck_status'] === 'fin') ? 1 : 0;
|
||
$isPACK = (isset($wmsOrder['pack_status']) && $wmsOrder['pack_status'] != 'none') ? 1 : 0;
|
||
$STOREID = isset($wmsOrder['store_id']) ? $wmsOrder['store_id'] : 0;
|
||
$STORE = isset($wmsResult['store_remark']) ? $wmsResult['store_remark'] : '';
|
||
$ITEMS = implode('|', $ITEMS_arr);
|
||
$STOCKS = implode('', $STOCKS_arr);
|
||
$totalOrders = isset($wmsBatch['total_orders']) ? intval($wmsBatch['total_orders']) : 1;
|
||
// 构造与本地查询一致的返回结构
|
||
$data = [
|
||
'count' => $totalOrders,
|
||
'ITEMS' => $ITEMS,
|
||
'STOREID' => $STOREID,
|
||
'GRABNUM' => $GRABNUM,
|
||
'PLSENDFLAG' => $PLSENDFLAG,
|
||
'POSTNUM' => $POSTNUM,
|
||
'STORE' => $STORE,
|
||
'STOCKS' => $STOCKS,
|
||
"isPack" => $isPACK,
|
||
];
|
||
// 构建 items 数组
|
||
$items_tmp = [];
|
||
foreach($wmsItems as $it){
|
||
$code = isset($it['item_code']) ? $it['item_code'] : '';
|
||
$qty = isset($it['plan_qty']) ? $it['plan_qty'] : 1;
|
||
$name = isset($it['item_name']) ? $it['item_name'] : '';
|
||
$barcode = '';
|
||
if(!empty($it['barcodes']) && isset($it['barcodes'][0]['barcode'])){
|
||
$barcode = $it['barcodes'][0]['barcode'];
|
||
}
|
||
$imgs = isset($it['image_url']) ? $it['image_url'] : [];
|
||
$items_tmp[] = [
|
||
'STOCKIDS' => $code,
|
||
'count' => $qty,
|
||
'title' => $name,
|
||
'ercode' => $barcode,
|
||
'COLOR' => '',
|
||
'STYLE' => '',
|
||
'IMG' => !empty($imgs) ? $imgs[0] : '',
|
||
'ispick' => false,
|
||
'fhcount' => 0,
|
||
'imgs' => $imgs,
|
||
];
|
||
}
|
||
$newWmsData = [
|
||
'deliveryOrderCode'=> isset($wmsOrder['delivery_order_code']) ? $wmsOrder['delivery_order_code'] : '',
|
||
'waveNo' => isset($wmsOrder['wave_no']) ? $wmsOrder['wave_no'] : '',
|
||
'packStatus' => isset($wmsBatch['wave_type']) ? $wmsBatch['wave_type'] : 1,
|
||
'waveTotalOrders' => $totalOrders,
|
||
'itemsCount' => count($wmsItems),
|
||
'itemsTotal' => count($wmsItems),
|
||
''
|
||
];
|
||
|
||
|
||
|
||
$data['items'] = $items_tmp;
|
||
// 缓存 newWmsData 供 startWork 打包时拉取,不传给前端
|
||
$this->redis->set("newWmsData:{$POSTNUM}", json_encode($newWmsData, JSON_UNESCAPED_UNICODE), 3600);
|
||
}
|
||
}
|
||
// ===== new_wms 回退结束 =====
|
||
if($data && !is_array($data)){
|
||
$data['isNewWms'] = $fromNewWms ? 1 : 0;
|
||
}
|
||
if(is_array($data)){
|
||
$data['isNewWms'] = $fromNewWms ? 1 : 0;
|
||
}
|
||
return json($data);
|
||
}
|
||
public function getinfo2(){
|
||
$params=$this->request->post();
|
||
$model = new \app\common\model\wms\Order;
|
||
$data = $model->where(["POSTNUM"=>str_replace("-1-1-", "", $params['sn'])])->find();
|
||
if(!$data){
|
||
$model = new \app\common\model\wms\Order1;
|
||
$data = $model->where(["POSTNUM"=>str_replace("-1-1-", "", $params['sn'])])->find();
|
||
}
|
||
$Expreemodel = new \app\common\model\wms\Express;
|
||
$subExpress = $Expreemodel->where(["ORIGINPOSTNUM"=>str_replace("-1-1-", "", $params['sn'])])->select();
|
||
if($data){
|
||
$GRABNUM = $data['POSTNUM'];
|
||
$subExpress = $subExpress;
|
||
}else{
|
||
$GRABNUM = null;
|
||
$subExpress = [];
|
||
}
|
||
return json(["GRABNUM"=>$GRABNUM,"subExpress"=>$subExpress]);
|
||
}
|
||
public function getorderinfo3(){
|
||
$time = time();
|
||
$params=$this->request->post();
|
||
$model = new \app\common\model\wms\Order;
|
||
$data = $model->where(["WAREHOUSEID"=>5400,"POSTNUM"=>str_replace("-1-1-", "", $params['sn'])])->find();
|
||
if(!$data){
|
||
$model1 = new \app\common\model\wms\Order1;
|
||
$data = $model1->where(["WAREHOUSEID"=>5400,"POSTNUM"=>str_replace("-1-1-", "", $params['sn'])])->find();
|
||
}
|
||
$newdata = [];
|
||
$GRABLISTFLAGS = [];
|
||
$recommendedPackaging = "";
|
||
if($data){
|
||
$items = array_filter(explode("|",$data['ITEMS']),'trim');
|
||
$model = new \app\common\model\wms\Grabstock;
|
||
$infos = $model->where(["WAREHOUSEID"=>5400,"GRABNUM"=>$data["GRABNUM"]])->find();
|
||
if(!$infos){
|
||
$model = new \app\common\model\workers\Works;
|
||
$infos = $model->where(["WAREHOUSEID"=>5400,"grabnum"=>$data["GRABNUM"]])->find();
|
||
$STOCKIDS = ($infos['items'] ?? null);
|
||
}else{
|
||
$STOCKIDS = ($infos['STOCKIDS'] ?? null);
|
||
}
|
||
$model = new \app\common\model\wms\Warestore;
|
||
$Warestore = $model->where(["WAREHOUSEID"=>5400,"STOREID"=>$data["STOREID"]])->find();
|
||
$model = new \app\common\model\wms\Pack;
|
||
$PACKdata = $model->where(["WAREHOUSEID"=>5400,"NAME"=>$data['PACKNAME']])->find();
|
||
$idss = [];
|
||
if($STOCKIDS && strpos($data["GRABNUM"],"B")===false && strpos($data["GRABNUM"],"E")===false){
|
||
$ids = explode(";",$STOCKIDS);
|
||
foreach ($ids as $r){
|
||
if($r!=""){
|
||
$sids = explode("|",$r);
|
||
$idss[$sids[1]] = $sids[0];
|
||
}
|
||
}
|
||
}
|
||
$items_tmp = [];
|
||
foreach ($items as $r){
|
||
$STOCKINFO = explode(",",$r);
|
||
$tmp_lanhao = "";
|
||
foreach ($idss as $k=>$rr){
|
||
if($rr==$STOCKINFO[0]){
|
||
$tmp_lanhao = $k;
|
||
}
|
||
}
|
||
$model = new \app\common\model\wms\Stock;
|
||
$STOCK = $model->where(["STOCKID"=>$STOCKINFO[0]])->find();
|
||
if(isset($STOCKINFO[2]) && strpos($STOCKINFO[2],'yc#zy')==false){
|
||
array_push($items_tmp,['STOCKIDS'=>$STOCKINFO[0],'count'=>$STOCKINFO[1],'title'=>$STOCKINFO[2],'ercode'=>($STOCK['BARCODE'] ?? null),'lanhao'=>$tmp_lanhao,'COLOR'=>($STOCK['COLOR'] ?? null),'STYLE'=>($STOCK['STYLE'] ?? null),'IMG'=>($STOCK['IMG'] ?? null),'ispick'=>!!($STOCK['SCANFLAG'] ?? null)]);
|
||
}
|
||
}
|
||
if($items_tmp[0]['lanhao']!=''){
|
||
usort($items_tmp, function($a, $b) {
|
||
return ($a['lanhao']?$a['lanhao']:0) - ($b['lanhao']?$b['lanhao']:0);
|
||
});
|
||
}
|
||
if(strpos($data['GRABNUM'],'B')!==false){
|
||
//团购波次返回拦截单号序列号;
|
||
$model = new \app\common\model\wms\Order;
|
||
$GRABLIST = $model
|
||
->field('CREATIONDATE+0 as date,FLAG,OPERATERECORDS,POSTNUM')
|
||
->where(["GRABNUM"=>$data['GRABNUM']])
|
||
->order("date","desc")
|
||
->select();
|
||
foreach($GRABLIST as $k => $r){
|
||
if($r['FLAG']==1){
|
||
$tmp = explode("|",$r['OPERATERECORDS']);
|
||
$orderby = $r['POSTNUM'];
|
||
foreach ($tmp as $rr){
|
||
$tmp2 = explode(";",$rr);
|
||
if(strpos($tmp2[0],"-")!==false){
|
||
$orderby = $tmp2[0];
|
||
}
|
||
}
|
||
array_push($GRABLISTFLAGS,$orderby);
|
||
}
|
||
}
|
||
$model = new \app\common\model\wms\Wmstuan;
|
||
$wmstuandata = $model->where(["GRABNUM"=>$data["GRABNUM"]])->find();
|
||
$recommendedPackaging = ($wmstuandata['PACK'] ?? null);
|
||
}
|
||
$PICKER = "";
|
||
$match = null;
|
||
$OPAS = null;
|
||
if (preg_match("/拣货完成;[^;]+;([^|]+)/i", $data['OPERATERECORDS'], $match))
|
||
$OPAS = $match;
|
||
}
|
||
$newdata = ["items"=>$items_tmp,"order_items"=>$data['ITEMS'],"GRABNUM"=>$data["GRABNUM"],"POSTNUM"=>$data["POSTNUM"],"PACKNAME"=>$data["PACKNAME"],"OPAS"=>$OPAS,"SendFlag"=>$data["PLSENDFLAG"],"FLAG"=>$data["FLAG"],"PACKID"=>$PACKdata?$PACKdata['ID']:0,"GRABLISTFLAGS"=>$GRABLISTFLAGS,"recommendedPackaging"=>$recommendedPackaging,"weight"=>$data["WEIGHT"],"ORDERWEIGHT"=>isset($data["ORDERWEIGHT"])?$data["ORDERWEIGHT"]:0,"PICKINGFLAG"=>$data['PICKINGFLAG'],"Warestore"=>($Warestore['TITLE'] ?? null)];
|
||
|
||
$newdata['t'] = time()-$time;
|
||
return json($newdata);
|
||
}
|
||
public function createCache($WAREHOUSEID,$POSTNUM){
|
||
$body = [
|
||
'WAREHOUSEID'=>$WAREHOUSEID,
|
||
'POSTNUM'=>$POSTNUM
|
||
];
|
||
$url="http://wms.gztbyc.com/sandan/createCache";
|
||
$options = [
|
||
CURLOPT_TIMEOUT =>30
|
||
];
|
||
$urlEncodedString = http_build_query($body);
|
||
$req = Http::sendRequest($url, $urlEncodedString, 'POST', $options);
|
||
return json($req);
|
||
}
|
||
public function getorderinfo(){
|
||
$time = time();
|
||
$items_tmp = [];
|
||
$OPAS = null;
|
||
$PACKdata = NULL;
|
||
$ordercount = 0;
|
||
$params=$this->request->post();
|
||
$model = new \app\common\model\wms\Order;
|
||
$actualWeight = isset($params['actualWeight'])?true:false;
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$data = $model->field('ITEMS,GRABNUM,STOREID,PACKNAME,OPERATERECORDS,NOTES,STOCKS,WEIGHT,POSTNUM,PLSENDFLAG,PRINTTIMES,FLAG,PICKINGFLAG,NAME,TEL')->where(["WAREHOUSEID"=>$WAREHOUSEID,"POSTNUM"=>str_replace("-1-1-", "", $params['sn'])])->find();
|
||
if(!$data){
|
||
$newdata = [];
|
||
return json($newdata);
|
||
}
|
||
$newdata = [];
|
||
$GRABLISTFLAGS = [];
|
||
$recommendedPackaging = "";
|
||
$lanhao = -1;
|
||
if($data){
|
||
$items = array_filter(explode("|",$data['ITEMS']),'trim');
|
||
$model = new \app\common\model\wms\Grabstock;
|
||
$infos = $model->where(["WAREHOUSEID"=>$WAREHOUSEID,"GRABNUM"=>$data["GRABNUM"]])->find();
|
||
if(!$infos){
|
||
$model = new \app\common\model\workers\Works;
|
||
$infos = $model->where(["WAREHOUSEID"=>$WAREHOUSEID,"grabnum"=>$data["GRABNUM"]])->find();
|
||
$STOCKIDS = ($infos['items'] ?? null);
|
||
}else{
|
||
$STOCKIDS = ($infos['STOCKIDS'] ?? null);
|
||
}
|
||
$model = new \app\common\model\wms\Warestore;
|
||
$Warestore = $model->where(["WAREHOUSEID"=>$WAREHOUSEID,"STOREID"=>$data["STOREID"]])->find();
|
||
$model = new \app\common\model\wms\Pack;
|
||
$PACKdata = $model->where(["WAREHOUSEID"=>$WAREHOUSEID,"NAME"=>$data['PACKNAME']])->find();
|
||
$idss = [];
|
||
/*if($STOCKIDS && strpos($data["GRABNUM"],"F")!==false){
|
||
$ids = explode(";",$STOCKIDS);
|
||
foreach ($ids as $r){
|
||
if($r!=""){
|
||
$sids = explode("|",$r);
|
||
$idss[$sids[1]] = $sids[0];
|
||
}
|
||
}
|
||
}*/
|
||
$lanhao_E = 0;
|
||
if(strpos($data["GRABNUM"],"E")!==false){
|
||
$WorksModel = new \app\common\model\workers\Works;
|
||
$work = $WorksModel->where(["grabnum"=>$data["GRABNUM"]])->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("picks>0")->find();
|
||
$orders = explode(";",($work["orders"] ?? null));
|
||
foreach ($orders as $r){
|
||
$order = explode("|",$r);
|
||
if($data["POSTNUM"]==$order[0]){
|
||
$lanhao_E = $order[1];
|
||
$lanhao = $order[1];
|
||
}
|
||
}
|
||
}
|
||
if(strpos($data["GRABNUM"],"B")!==false){
|
||
$MergeModel = new \app\common\model\tuan\Merge;
|
||
$grabRow = Db::table('ye4s_tuan_merge_grabnum')->where('grabnum', $data["GRABNUM"])->find();
|
||
if($grabRow){
|
||
$work = $MergeModel->where('id', $grabRow['merge_id'])->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
$lanhao_E = $grabRow['position'] + 1;
|
||
$lanhao = $grabRow['position'] + 1;
|
||
$grabs = explode(",",($work["GRABS"] ?? null));
|
||
}
|
||
}
|
||
foreach ($items as $r){
|
||
$STOCKINFO = explode(",",$r);
|
||
if(strpos($data["GRABNUM"],"E")!==false){
|
||
$tmp_lanhao = $lanhao_E;
|
||
}else{
|
||
$tmp_lanhao = "";
|
||
foreach ($idss as $k=>$rr){
|
||
if($rr==$STOCKINFO[0]){
|
||
$tmp_lanhao = $k;
|
||
}
|
||
}
|
||
}
|
||
$model = new \app\common\model\wms\Stock;
|
||
$STOCK = $model->where(["STOCKID"=>$STOCKINFO[0]])->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
if(isset($STOCKINFO[2]) && strpos($STOCKINFO[2],'yc#zy')==false){
|
||
$imgs = $this->getStockImgs($STOCKINFO[0]);
|
||
array_push($items_tmp,['STOCKIDS'=>$STOCKINFO[0],'count'=>$STOCKINFO[1],'title'=>$STOCKINFO[2],'ercode'=>($STOCK['BARCODE'] ?? null),'lanhao'=>$tmp_lanhao,'COLOR'=>($STOCK['COLOR'] ?? null),'STYLE'=>($STOCK['STYLE'] ?? null),'IMG'=>($STOCK['IMG'] ?? null),'ispick'=>!!($STOCK['SCANFLAG'] ?? null),"imgs"=>$imgs]);
|
||
}
|
||
}
|
||
if($items_tmp[0]['lanhao']!=''){
|
||
usort($items_tmp, function($a, $b) {
|
||
return ($a['lanhao']?$a['lanhao']:0) - ($b['lanhao']?$b['lanhao']:0);
|
||
});
|
||
}
|
||
if(strpos($data['GRABNUM'],'B')!==false){
|
||
//团购波次返回拦截单号序列号;
|
||
$model = new \app\common\model\wms\Order;
|
||
$GRABLIST = $model->alias("order")
|
||
->field('order.POSTNUM as POSTNUM,printexpress.GRABNUM as GRABNUM,order.FLAG as FLAG')
|
||
->where(["order.GRABNUM"=>$data['GRABNUM']])->where(["order.WAREHOUSEID"=>$WAREHOUSEID])
|
||
->join('yj_printexpress printexpress', 'order.ID = printexpress.WMSORDERID')
|
||
->select();
|
||
$ordercount = $model->where(['GRABNUM'=>$data['GRABNUM'],"FLAG"=>0])->count();
|
||
foreach($GRABLIST as $r){
|
||
if($r['FLAG']==1){
|
||
$orderby = $r['POSTNUM'].'-'.$r['GRABNUM'];
|
||
array_push($GRABLISTFLAGS,$orderby);
|
||
}
|
||
}
|
||
$model = new \app\common\model\wms\Wmstuan;
|
||
$wmstuandata = $model->where(["GRABNUM"=>$data["GRABNUM"]])->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
$recommendedPackaging = ($wmstuandata['PACK'] ?? null);
|
||
}
|
||
$PICKER = "";
|
||
$match = null;
|
||
if(isset($data['OPERATERECORDS'])){
|
||
if (preg_match("/拣货完成;[^;]+;([^|]+)/i", $data['OPERATERECORDS'], $match)){
|
||
$OPAS = $match;
|
||
}
|
||
}else{
|
||
if (preg_match("/拣货完成;[^;]+;([^|]+)/i", $data['NOTES'], $match)){
|
||
$OPAS = $match;
|
||
}
|
||
}
|
||
$ItemsinfoModel = new \app\common\model\stocks\Weightandpack;
|
||
$PackModel = new \app\common\model\wms\Pack;
|
||
$data_stocks = $ItemsinfoModel->where(["STOCKS"=>$data['STOCKS']])->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
$ID_s=0;
|
||
$PACKNAME_s="";
|
||
$weight_s = $data['WEIGHT'];
|
||
if($data_stocks){
|
||
$PACK = $PackModel->where(["ID"=>$data_stocks['PACKID']])->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
$ID_s = !!$PACK?$PACK['ID']:$ID_s;
|
||
$PACKNAME_s = $PACK['NAME'];
|
||
if($actualWeight){
|
||
$weight_s = $data_stocks['WEIGHT'];
|
||
}
|
||
}
|
||
$newdata = ["items"=>$items_tmp,"order_items"=>$data['ITEMS'],"GRABNUM"=>$data["GRABNUM"],"POSTNUM"=>$data["POSTNUM"],"PACKNAME"=>$PACKNAME_s,"OPAS"=>$OPAS,"SendFlag"=>$data["PLSENDFLAG"],"PRINTTIMES"=>$data["PRINTTIMES"],"FLAG"=>$data["FLAG"],"PACKID"=>$ID_s,"GRABLISTFLAGS"=>$GRABLISTFLAGS,"recommendedPackaging"=>$recommendedPackaging,"weight"=>$weight_s,"ORDERWEIGHT"=>isset($data["ORDERWEIGHT"])?$data["ORDERWEIGHT"]:0,"PICKINGFLAG"=>$data['PICKINGFLAG'],"Warestore"=>($Warestore['TITLE'] ?? null),"ordercount"=>$ordercount,"STOCKS"=>$data['STOCKS'],"name"=>$data["NAME"],"tel"=>$data["TEL"]];
|
||
if(strpos($data["GRABNUM"],"E")!==false||strpos($data["GRABNUM"],"B")!==false){
|
||
$newdata['lanhao'] = $lanhao;
|
||
}
|
||
}else{
|
||
$newdata = [];
|
||
}
|
||
$newdata['t'] = time()-$time;
|
||
return json($newdata);
|
||
}
|
||
public function getorderinfo2(){
|
||
$time = time();
|
||
$items_tmp = [];
|
||
$OPAS = null;
|
||
$PACKdata = NULL;
|
||
$ordercount = 0;
|
||
$params=$this->request->post();
|
||
$model = new \app\common\model\wms\Order;
|
||
$actualWeight = isset($params['actualWeight'])?true:false;
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$data = $model->where(["WAREHOUSEID"=>$WAREHOUSEID,"POSTNUM"=>str_replace("-1-1-", "", $params['sn'])])->find();
|
||
if(!$data){
|
||
$model1 = new \app\common\model\wms\Order1;
|
||
$data = $model1->where(["WAREHOUSEID"=>$WAREHOUSEID,"POSTNUM"=>str_replace("-1-1-", "", $params['sn'])])->find();
|
||
}
|
||
$newdata = [];
|
||
$GRABLISTFLAGS = [];
|
||
$recommendedPackaging = "";
|
||
$lanhao = -1;
|
||
if($data){
|
||
$items = array_filter(explode("|",$data['ITEMS']),'trim');
|
||
$model = new \app\common\model\wms\Grabstock;
|
||
$infos = $model->where(["WAREHOUSEID"=>$WAREHOUSEID,"GRABNUM"=>$data["GRABNUM"]])->find();
|
||
if(!$infos){
|
||
$model = new \app\common\model\workers\Works;
|
||
$infos = $model->where(["WAREHOUSEID"=>$WAREHOUSEID,"grabnum"=>$data["GRABNUM"]])->find();
|
||
$STOCKIDS = ($infos['items'] ?? null);
|
||
}else{
|
||
$STOCKIDS = ($infos['STOCKIDS'] ?? null);
|
||
}
|
||
$model = new \app\common\model\wms\Warestore;
|
||
$Warestore = $model->where(["WAREHOUSEID"=>$WAREHOUSEID,"STOREID"=>$data["STOREID"]])->find();
|
||
$model = new \app\common\model\wms\Pack;
|
||
$PACKdata = $model->where(["WAREHOUSEID"=>$WAREHOUSEID,"NAME"=>$data['PACKNAME']])->find();
|
||
$idss = [];
|
||
/*if($STOCKIDS && strpos($data["GRABNUM"],"F")!==false){
|
||
$ids = explode("|",$STOCKIDS);
|
||
foreach ($ids as $r){
|
||
if($r!=""){
|
||
$sids = explode(";",$r);
|
||
$idss[$sids[1]] = $sids[0];
|
||
}
|
||
}
|
||
}*/
|
||
$lanhao_E = 0;
|
||
if(strpos($data["GRABNUM"],"E")!==false){
|
||
$WorksModel = new \app\common\model\workers\Works;
|
||
$work = $WorksModel->where(["grabnum"=>$data["GRABNUM"]])->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("picks>0")->find();
|
||
$orders = explode(";",($work["orders"] ?? null));
|
||
foreach ($orders as $r){
|
||
$order = explode("|",$r);
|
||
if($data["POSTNUM"]==$order[0]){
|
||
$lanhao_E = $order[1];
|
||
$lanhao = $order[1];
|
||
}
|
||
}
|
||
}
|
||
if(strpos($data["GRABNUM"],"B")!==false){
|
||
$MergeModel = new \app\common\model\tuan\Merge;
|
||
$grabRow = Db::table('ye4s_tuan_merge_grabnum')->where('grabnum', $data["GRABNUM"])->find();
|
||
if($grabRow){
|
||
$work = $MergeModel->where('id', $grabRow['merge_id'])->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
$lanhao_E = $grabRow['position'] + 1;
|
||
$lanhao = $grabRow['position'] + 1;
|
||
$grabs = explode(",",($work["GRABS"] ?? null));
|
||
}
|
||
}
|
||
foreach ($items as $r){
|
||
$STOCKINFO = explode(",",$r);
|
||
if(strpos($data["GRABNUM"],"E")!==false){
|
||
$tmp_lanhao = $lanhao_E;
|
||
}else{
|
||
$tmp_lanhao = "";
|
||
foreach ($idss as $k=>$rr){
|
||
if($rr==$STOCKINFO[0]){
|
||
$tmp_lanhao = $k;
|
||
}
|
||
}
|
||
}
|
||
$model = new \app\common\model\wms\Stock;
|
||
$STOCK = $model->where(["STOCKID"=>$STOCKINFO[0]])->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
if(isset($STOCKINFO[2]) && strpos($STOCKINFO[2],'yc#zy')==false){
|
||
array_push($items_tmp,['STOCKIDS'=>$STOCKINFO[0],'count'=>$STOCKINFO[1],'title'=>$STOCKINFO[2],'ercode'=>($STOCK['BARCODE'] ?? null),'lanhao'=>$tmp_lanhao,'COLOR'=>($STOCK['COLOR'] ?? null),'STYLE'=>($STOCK['STYLE'] ?? null),'IMG'=>($STOCK['IMG'] ?? null),'ispick'=>!!($STOCK['SCANFLAG'] ?? null)]);
|
||
}
|
||
}
|
||
if($items_tmp[0]['lanhao']!=''){
|
||
usort($items_tmp, function($a, $b) {
|
||
return ($a['lanhao']?$a['lanhao']:0) - ($b['lanhao']?$b['lanhao']:0);
|
||
});
|
||
}
|
||
if(strpos($data['GRABNUM'],'B')!==false){
|
||
//团购波次返回拦截单号序列号;
|
||
$model = new \app\common\model\wms\Order;
|
||
$GRABLIST = $model->alias("order")
|
||
->field('order.POSTNUM as POSTNUM,printexpress.GRABNUM as GRABNUM,order.FLAG as FLAG')
|
||
->where(["order.GRABNUM"=>$data['GRABNUM']])->where(["order.WAREHOUSEID"=>$WAREHOUSEID])
|
||
->join('yj_printexpress printexpress', 'order.ID = printexpress.WMSORDERID')
|
||
->select();
|
||
$ordercount = $model->where(['GRABNUM'=>$data['GRABNUM'],"FLAG"=>0])->count();
|
||
foreach($GRABLIST as $r){
|
||
if($r['FLAG']==1){
|
||
$orderby = $r['POSTNUM'].'-'.$r['GRABNUM'];
|
||
array_push($GRABLISTFLAGS,$orderby);
|
||
}
|
||
}
|
||
$model = new \app\common\model\wms\Wmstuan;
|
||
$wmstuandata = $model->where(["GRABNUM"=>$data["GRABNUM"]])->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
$recommendedPackaging = ($wmstuandata['PACK'] ?? null);
|
||
}
|
||
$PICKER = "";
|
||
$match = null;
|
||
if(isset($data['OPERATERECORDS'])){
|
||
if (preg_match("/拣货完成;[^;]+;([^|]+)/i", $data['OPERATERECORDS'], $match)){
|
||
$OPAS = $match;
|
||
}
|
||
}else{
|
||
if (preg_match("/拣货完成;[^;]+;([^|]+)/i", $data['NOTES'], $match)){
|
||
$OPAS = $match;
|
||
}
|
||
}
|
||
$ItemsinfoModel = new \app\common\model\stocks\Weightandpack;
|
||
$PackModel = new \app\common\model\wms\Pack;
|
||
$data_stocks = $ItemsinfoModel->where(["STOCKS"=>$data['STOCKS']])->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
$ID_s=0;
|
||
$PACKNAME_s="";
|
||
$weight_s = $data['WEIGHT'];
|
||
if($data_stocks){
|
||
$PACK = $PackModel->where(["ID"=>$data_stocks['PACKID']])->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
$ID_s = !!$PACK?$PACK['ID']:$ID_s;
|
||
$PACKNAME_s = $PACK['NAME'];
|
||
if($actualWeight){
|
||
$weight_s = $data_stocks['WEIGHT'];
|
||
}
|
||
}
|
||
$newdata = ["items"=>$items_tmp,"order_items"=>$data['ITEMS'],"GRABNUM"=>$data["GRABNUM"],"POSTNUM"=>$data["POSTNUM"],"PACKNAME"=>$PACKNAME_s,"OPAS"=>$OPAS,"SendFlag"=>$data["PLSENDFLAG"],"PRINTTIMES"=>$data["PRINTTIMES"],"FLAG"=>$data["FLAG"],"PACKID"=>$ID_s,"GRABLISTFLAGS"=>$GRABLISTFLAGS,"recommendedPackaging"=>$recommendedPackaging,"weight"=>$weight_s,"ORDERWEIGHT"=>isset($data["ORDERWEIGHT"])?$data["ORDERWEIGHT"]:0,"PICKINGFLAG"=>$data['PICKINGFLAG'],"Warestore"=>($Warestore['TITLE'] ?? null),"ordercount"=>$ordercount,"STOCKS"=>$data['STOCKS'],"name"=>$data["NAME"],"tel"=>$data["TEL"]];
|
||
if(strpos($data["GRABNUM"],"E")!==false||strpos($data["GRABNUM"],"B")!==false){
|
||
$newdata['lanhao'] = $lanhao;
|
||
}
|
||
}else{
|
||
$newdata = [];
|
||
}
|
||
$newdata['t'] = time()-$time;
|
||
return json($newdata);
|
||
}
|
||
public function getPackByGRABNUM(){
|
||
$params = json_decode(file_get_contents('php://input'), true);
|
||
$model = new \app\common\model\wms\Order;
|
||
$ItemsinfoModel = new \app\common\model\stocks\Weightandpack;
|
||
$PackModel = new \app\common\model\wms\Pack;
|
||
$STOCKS = $model->where(["GRABNUM"=>($params["GRABNUM"] ?? null)])->find();
|
||
$data_stocks = $ItemsinfoModel->where(["STOCKS"=>($STOCKS["STOCKS"] ?? null)])->find();
|
||
$packinfo = ["PACKNAME"=>""];
|
||
if($data_stocks){
|
||
$PACK = $PackModel->where(["ID"=>$data_stocks['PACKID']])->find();
|
||
$packinfo["PACKNAME"] = ($PACK['NAME'] ?? null);
|
||
}
|
||
|
||
return $packinfo["PACKNAME"];
|
||
}
|
||
public function getpack(){
|
||
$params=$this->request->post();
|
||
$model = new \app\common\model\wms\Pack;
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$data = $model->where(["WAREHOUSEID"=>$WAREHOUSEID,"BARCODE"=>str_replace("-1-1-", "", $params['sn'])])->find();
|
||
return json($data);
|
||
}
|
||
public function dywl(){
|
||
$model = new \app\common\model\wms\Order;
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$list = $model->where(["WAREHOUSEID"=>$WAREHOUSEID])
|
||
->where('GRABNUM like \'%B%\'')
|
||
->where(['PRINTTIMES'=>1,'PLSENDFLAG'=>0])
|
||
->field('OPERATERECORDS,sum(GOODSCOUNT) as GOODSCOUNT,POSTNUM,count(*) as ordercount,ITEMS,GRABNUM,GRABDATE')
|
||
->group('GRABNUM')
|
||
->select();
|
||
$djhlist = [];
|
||
foreach($list as $r){
|
||
$tmp = explode("|",$r['OPERATERECORDS']);
|
||
$tmpitems = explode("|",$r['ITEMS']);
|
||
$r['skusum'] = count($tmpitems)-1;
|
||
$islingliao = false;
|
||
foreach($tmp as $dd){
|
||
$tmp2 = explode(";",$dd);
|
||
if(strpos($tmp2[0],"领取快递面单")!==false){
|
||
$islingliao = true;
|
||
}
|
||
}
|
||
$r['endtime'] = intval($r['GRABDATE'])/1000;
|
||
$r['time'] = date('Y-m-d H:i:s', $r['endtime']);
|
||
if(!$islingliao){
|
||
array_push($djhlist,$r);
|
||
}
|
||
}
|
||
usort($djhlist, function($a, $b) {
|
||
return $a['endtime'] - $b['endtime'];
|
||
});
|
||
return json($djhlist);
|
||
}
|
||
public function llwj(){
|
||
$model = new \app\common\model\wms\Order;
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$list = $model->where(["WAREHOUSEID"=>$WAREHOUSEID])
|
||
->where('GRABNUM like \'%B%\'')
|
||
->where(['PICKINGFLAG'=>0])
|
||
->field('OPERATERECORDS,sum(GOODSCOUNT) as GOODSCOUNT,POSTNUM,count(*) as ordercount,ITEMS,GRABNUM')
|
||
->group('GRABNUM')
|
||
->select();
|
||
$djhlist = [];
|
||
foreach($list as $r){
|
||
$tmp = explode("|",$r['OPERATERECORDS']);
|
||
$tmpitems = explode("|",$r['ITEMS']);
|
||
$r['skusum'] = count($tmpitems)-1;
|
||
$islingliao = false;
|
||
foreach($tmp as $dd){
|
||
$tmp2 = explode(";",$dd);
|
||
if(strpos($tmp2[0],"领取快递面单")!==false){
|
||
$islingliao = true;
|
||
$r['username']=$tmp2[2];
|
||
$dateTime = date_create_from_format('Y年m月d日 H:i:s', $tmp2[1]);
|
||
$tmpt = strtotime(date_format($dateTime, 'Y-m-d H:i:s'));
|
||
$r['endtime'] = $tmpt;
|
||
$r['time'] = date('Y-m-d H:i:s', $tmpt);
|
||
}
|
||
}
|
||
if($islingliao){
|
||
array_push($djhlist,$r);
|
||
}
|
||
}
|
||
usort($djhlist, function($a, $b) {
|
||
return $a['endtime'] - $b['endtime'];
|
||
});
|
||
return json($djhlist);
|
||
}
|
||
public function fhwdb(){
|
||
$model = new \app\common\model\wms\Order;
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$list = $model->where(["WAREHOUSEID"=>$WAREHOUSEID,"PLSENDFLAG"=>1])
|
||
->where('GRABNUM like \'%B%\'')
|
||
->field('OPERATERECORDS,sum(GOODSCOUNT) as GOODSCOUNT,POSTNUM,count(*) as ordercount,ITEMS,GRABNUM')
|
||
->group('GRABNUM')
|
||
->select();
|
||
$fhlist = [];
|
||
foreach($list as $r){
|
||
$tmp = explode("|",$r['OPERATERECORDS']);
|
||
$tmpitems = explode("|",$r['ITEMS']);
|
||
$r['skusum'] = count($tmpitems)-1;
|
||
$r['endtime'] = 0;
|
||
$isdabao = false;
|
||
foreach($tmp as $dd){
|
||
$tmp2 = explode(";",$dd);
|
||
if(strpos($tmp2[0],"发货")!==false || strpos($tmp2[0],"复核")!==false){
|
||
$r['username']=$tmp2[2];
|
||
$dateTime = date_create_from_format('Y年m月d日 H:i:s', $tmp2[1]);
|
||
$tmpt = strtotime(date_format($dateTime, 'Y-m-d H:i:s'));
|
||
$r['endtime'] = $tmpt;
|
||
$r['time'] = date('Y-m-d H:i:s', $tmpt);
|
||
}
|
||
if(strpos($tmp2[0],"打包")!==false){
|
||
$isdabao = true;
|
||
}
|
||
}
|
||
if(!$isdabao){
|
||
array_push($fhlist,$r);
|
||
}
|
||
}
|
||
usort($fhlist, function($a, $b) {
|
||
return $a['endtime'] - $b['endtime'];
|
||
});
|
||
return json($fhlist);
|
||
}
|
||
public function jhwf(){
|
||
$model = new \app\common\model\wms\Order;
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$listtmp = $model->where(['WAREHOUSEID'=>$WAREHOUSEID,'PICKINGFLAG'=>3,'PLSENDFLAG'=>0,'FLAG'=>0])->field('POSTNUM,GRABNUM,OPERATERECORDS,PLSENDFLAG')->where('GRABNUM', 'like', '%B%')->group('GRABNUM')->select();
|
||
$list = [];
|
||
$list2 = [];
|
||
foreach ($listtmp as $r){
|
||
$tmp = explode("|",$r['OPERATERECORDS']);
|
||
foreach ($tmp as $rr){
|
||
$tmp2 = explode(";",$rr);
|
||
if(strpos($tmp2[0],'拣货') !== false){
|
||
$r['username']=$tmp2[2];
|
||
$dateTime = date_create_from_format('Y年m月d日 H:i:s', $tmp2[1]);
|
||
$tmpt = strtotime(date_format($dateTime, 'Y-m-d H:i:s'));
|
||
$r['endtime'] = $tmpt;
|
||
$r['time'] = date('Y-m-d H:i:s', $tmpt);
|
||
$isjianhuo = true;
|
||
}
|
||
}
|
||
array_push($list,$r);
|
||
}
|
||
|
||
usort($list, function($a, $b) {
|
||
return $a['endtime'] - $b['endtime'];
|
||
});
|
||
return json($list);
|
||
}
|
||
public function czwf(){
|
||
$model = new \app\common\model\wms\Order;
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$listtmp = $model->where(['WAREHOUSEID'=>$WAREHOUSEID,'PRINTTIMES'=>1])->field('POSTNUM,GRABNUM,OPERATERECORDS,PLSENDFLAG')->where('GRABNUM', 'like', '%B%')->group('GRABNUM')->select();
|
||
$list = [];
|
||
$list2 = [];
|
||
foreach ($listtmp as $r){
|
||
$isfahuo = $r['PLSENDFLAG']==1?true:false;
|
||
$isjianhuo = false;
|
||
$tmp = explode("|",$r['OPERATERECORDS']);
|
||
foreach ($tmp as $rr){
|
||
$tmp2 = explode(";",$rr);
|
||
if($tmp2[0] == "设置重量"){
|
||
$isjianhuo = true;
|
||
}
|
||
}
|
||
if(!$isfahuo && $isjianhuo){
|
||
array_push($list,$r);
|
||
}
|
||
}
|
||
return json($list);
|
||
}
|
||
public function sdjhwf(){
|
||
$model = new \app\common\model\wms\Order;
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$listtmp = $model->where(['WAREHOUSEID'=>$WAREHOUSEID,'PRINTTIMES'=>1])->field('POSTNUM,GRABNUM,OPERATERECORDS,PLSENDFLAG')->where("GRABNUM not like '%B%'")->select();
|
||
$list = [];
|
||
$list2 = [];
|
||
foreach ($listtmp as $r){
|
||
$isfahuo = $r['PLSENDFLAG']==1?true:false;
|
||
$isjianhuo = false;
|
||
$tmp = explode("|",$r['OPERATERECORDS']);
|
||
foreach ($tmp as $rr){
|
||
$tmp2 = explode(";",$rr);
|
||
if($tmp2[0] == "拣货"){
|
||
$isjianhuo = true;
|
||
}
|
||
}
|
||
if(!$isfahuo && $isjianhuo){
|
||
array_push($list,$r);
|
||
}
|
||
}
|
||
return json($list);
|
||
}
|
||
|
||
public function fhwj(){
|
||
$model = new \app\common\model\wms\Order;
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$listtmp = $model->where(['WAREHOUSEID'=>$WAREHOUSEID,'PRINTTIMES'=>1])->field('POSTNUM,GRABNUM,OPERATERECORDS,PLSENDFLAG,GRABDATE+0 as GRABDATE')->where('GRABNUM', 'like', '%B%')->group('GRABNUM')->select();
|
||
$list = [];
|
||
$list2 = [];
|
||
foreach ($listtmp as $r){
|
||
$isfahuo = $r['PLSENDFLAG']==1?true:false;
|
||
$isjianhuo = false;
|
||
$tmp = explode("|",$r['OPERATERECORDS']);
|
||
foreach ($tmp as $rr){
|
||
$tmp2 = explode(";",$rr);
|
||
if($tmp2[0] == "拣货"){
|
||
$isjianhuo = true;
|
||
}
|
||
}
|
||
if($isfahuo && !$isjianhuo){
|
||
array_push($list,$r);
|
||
}
|
||
}
|
||
return json($list);
|
||
}
|
||
public function jhwj(){
|
||
$model = new \app\common\model\wms\Order;
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$listtmp = $model->field('POSTNUM,GRABNUM,OPERATERECORDS,ITEMS')->where('GRABNUM', 'like', '%B%')->where(['WAREHOUSEID'=>$WAREHOUSEID,'PICKINGFLAG'=>0])->group('GRABNUM')->select();
|
||
$list = [];
|
||
foreach ($listtmp as $r){
|
||
$OPERATERECORDS = explode("|",$r["OPERATERECORDS"]);
|
||
$isjianhuo = false;
|
||
foreach ($OPERATERECORDS as $rr){
|
||
$tmp = explode(";",$rr);
|
||
if(strpos($tmp[0],"结束拣货")!==false){
|
||
$isjianhuo = true;
|
||
}
|
||
if($tmp[0]=="拣货" ){
|
||
$isjianhuo = true;
|
||
}
|
||
if(strpos($tmp[0],"发货")!==false){
|
||
$isjianhuo = true;
|
||
}
|
||
}
|
||
if($isjianhuo){
|
||
array_push($list,$r);
|
||
}
|
||
}
|
||
return json($list);
|
||
}
|
||
|
||
public function findlast(){
|
||
$model = new \app\common\model\wms\Order;
|
||
$params=$this->request->post();
|
||
$list = $model->field('POSTNUM,OPERATERECORDS,GRABNUM')->where(['WAREHOUSEID'=>$params['WAREHOUSEID'],'PICKINGFLAG'=>0])->group('GRABNUM')->select();
|
||
$item = [];
|
||
foreach ($list as $k => $r){
|
||
$OPERATERECORDS = explode("|",$r["OPERATERECORDS"]);
|
||
$kaishijianhuo = false;
|
||
foreach ($OPERATERECORDS as $rr){
|
||
$tmp = explode(";",$rr);
|
||
if(strpos($tmp[0],"开始拣货")!==false && $tmp[2]==$params['name']){
|
||
$kaishijianhuo = true;
|
||
}
|
||
if(strpos($tmp[0],"中止拣货")!==false && $tmp[2]==$params['name']){
|
||
$kaishijianhuo = false;
|
||
}
|
||
}
|
||
if($kaishijianhuo){
|
||
$item = $r;
|
||
}
|
||
}
|
||
return json($item);
|
||
}
|
||
public function getSame(){
|
||
$model = new \app\common\model\wms\Order;
|
||
$params=$this->request->post();
|
||
$list = [];
|
||
if(strpos($params['GRABNUM'],'B')!==false){
|
||
$listtmp = $model->field('ITEMS')->where(['WAREHOUSEID'=>$params['WAREHOUSEID'],'GRABNUM'=>$params['GRABNUM']])->find();
|
||
$item = ($listtmp['ITEMS'] ?? null);
|
||
$list = $model->field('GRABNUM')->where("GRABNUM", "<>",$params['GRABNUM'])->where(['WAREHOUSEID'=>$params['WAREHOUSEID'],'ITEMS'=>$item,'PRINTTIMES'=>1,'PICKINGFLAG'=>0])->where('GRABNUM','like','%B%')->group("GRABNUM")->select();
|
||
}
|
||
|
||
$model = new \app\common\model\wms\Wmstuan;
|
||
$wmstuandata = $model->where(["GRABNUM"=>$params['GRABNUM']])->find();
|
||
$recommendedPackaging = ($wmstuandata['PACK'] ?? null);
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
$order = $orderModel->where(['GRABNUM'=>$params['GRABNUM'],'WAREHOUSEID'=>$params['WAREHOUSEID']])->find();
|
||
return json(["recommendedPackaging"=>$recommendedPackaging,"list"=>$list,"isprint"=>strpos(($order['OPERATERECORDS'] ?? null),"领料") || strpos(($order['OPERATERECORDS'] ?? null),"领取快递面单"),"POSTNUM"=>($order['POSTNUM'] ?? null),"isPICKING"=>($order['PICKINGFLAG'] ?? null),"OPERATERECORDS"=>$order
|
||
]);
|
||
}
|
||
public function isGzt(){
|
||
$model = new \app\common\model\wms\Gzt;
|
||
$params=$this->request->post();
|
||
$gzt = $model->where(["userId"=>$params['userId']])->find();
|
||
return json($gzt);
|
||
}
|
||
public function packCkOrderInit(){
|
||
$params=$this->request->post();
|
||
$CkModel = new \app\common\model\wmsorder\Ck;
|
||
$WAREHOUSEID = $params['WAREHOUSEID']??5400;
|
||
$packerName = $params['packer_name']??null;
|
||
$order = $CkModel->alias('order')->field("order.ID,packed.packer_name as packer_name,order.STORENAME,order.SOURCEID as SOURCEID,order.NAME as NAME")->join("ye4s_wmsorder_ck_packed packed","packed.order_id=order.ID","left")->where(["WAREHOUSEID"=>$WAREHOUSEID,"packed.packer_name"=>$packerName,"packed.end_time"=>0])->find();
|
||
return $order;
|
||
}
|
||
public function packOrder(){
|
||
|
||
$CkModel = new \app\common\model\wmsorder\Ck;
|
||
$CkpackModel = new \app\common\model\wmsorder\Ckpack;
|
||
$gztModel = new \app\common\model\wms\Gzt;
|
||
$result = [
|
||
"code"=>0,
|
||
"message"=>"",
|
||
"data"=>[]
|
||
];
|
||
$params=$this->request->post();
|
||
$oldOrderId = $params['old_Order_id']??0;
|
||
$newOrderId = $params['new_Order_id']??0;
|
||
$gztId = $params['gzt_id']??0;
|
||
$WAREHOUSEID = $params['WAREHOUSEID']??5400;
|
||
$packerName = $params['packer_name']??null;
|
||
if(!$packerName){
|
||
$result['message'] = "非法参数";
|
||
return json($result);
|
||
}
|
||
$CkModel->startTrans();
|
||
try {
|
||
$newOrder = null;
|
||
if($newOrderId){
|
||
$newOrder = $CkModel->alias("order")->field("order.ID,packed.packer_name as packer_name,order.STORENAME,order.SOURCEID as SOURCEID,order.NAME as NAME")->join("ye4s_wmsorder_ck_packed packed","packed.order_id=order.ID","left")->where(["order.ID"=>$newOrderId,"WAREHOUSEID"=>$WAREHOUSEID])->lock(true)->find();
|
||
if(!$newOrder){
|
||
$result['message'] = "无记录";
|
||
return json($result);
|
||
}
|
||
if($newOrder['packer_name']){
|
||
$result['message'] = "订单已被{$newOrder['packer_name']}打包";
|
||
return json($result);
|
||
}
|
||
$gzt = $gztModel->find($gztId);
|
||
if(!$gzt){
|
||
$result['message'] = "工作台不存在,请重新扫描工作台";
|
||
return json($result);
|
||
}
|
||
$packinfo = [
|
||
"order_id"=>$newOrder["ID"],
|
||
"gzt_id"=>$gzt->id,
|
||
"start_time"=>time(),
|
||
"end_time"=>0,
|
||
"rtsp_urls"=>$gzt->backup_rtsp_url,
|
||
"packer_name"=>$packerName,
|
||
];
|
||
$CkpackModel->insert($packinfo);
|
||
}
|
||
//结束打包
|
||
if($oldOrderId){
|
||
$oldOrder = $CkModel->alias("order")->field("order.ID,packed.packer_name as packer_name")->join("ye4s_wmsorder_ck_packed packed","packed.order_id=order.ID","left")->where(["order.ID"=>$oldOrderId,"WAREHOUSEID"=>$WAREHOUSEID])->lock(true)->find();
|
||
if($oldOrder && ($oldOrder['packer_name'] ?? null)){
|
||
$packedInfo = $CkpackModel->where(["order_id"=>$oldOrder->ID])->find();
|
||
$packedInfo->end_time = time();
|
||
$packedInfo->save();
|
||
$redis = new \Redis();
|
||
$redis->connect('127.0.0.1', 6379);
|
||
$redis->auth('qwe2019@');
|
||
$redis->select(3);
|
||
$redis->lpush("ware:{$WAREHOUSEID}:reRecord2",json_encode([$packedInfo->id,0]));
|
||
}
|
||
}
|
||
$CkModel->commit();
|
||
if($newOrder){
|
||
$result['message'] = "获取成功";
|
||
$result['code'] = 1;
|
||
$result['data'] = $newOrder;
|
||
}
|
||
return json($result);
|
||
} catch (ValidateException|PDOException|Exception $e) {
|
||
$CkModel->rollback();
|
||
|
||
$result['message'] = $e->getMessage();
|
||
return json($result);
|
||
}
|
||
}
|
||
public function getGztInfo(){
|
||
$model = new \app\common\model\wms\Gzt;
|
||
$params=$this->request->post();
|
||
$username = isset($params['username'])?$params['username']:null;
|
||
if($username){
|
||
$gzt = $model->where(["username"=>$username])->find();
|
||
return json($gzt);
|
||
}
|
||
$id = isset($params['id'])?$params['id']:null;
|
||
$gzt = $model->where(["userId"=>$id])->find();
|
||
$WarehouseModel = new \app\common\model\Warehouse;
|
||
$WAREHOUSE = $WarehouseModel->where(["WAREHOUSEID"=>($gzt["wareHouseId"] ?? null)])->find();
|
||
$WorksModel = new \app\common\model\workers\Works;
|
||
$gztWorkData = $WorksModel->field('SUM(dabaos) as ordercount,COUNT(*) as grabcount')->where(["WAREHOUSEID"=>($gzt["wareHouseId"] ?? null),"userId"=>$id,"workDate"=>($WAREHOUSE["workDate"] ?? null)])->group("userId")->select();
|
||
if($gztWorkData){
|
||
$gzt["ordercount"] = $gztWorkData[0]["ordercount"];
|
||
$gzt["grabcount"] = $gztWorkData[0]["grabcount"];
|
||
}
|
||
$gzt["pickName"] = "";
|
||
$picks = $WorksModel->where("picks>0")->where(["grabnum"=>$gzt->grabnum])->find();
|
||
if($picks){
|
||
$Usermodel = new \app\common\model\wms\User;
|
||
$user = $Usermodel->where(["userID"=>$picks->userId])->find();
|
||
if($user){
|
||
$gzt["pickName"] = $user->name;
|
||
}
|
||
}
|
||
return json($gzt);
|
||
}
|
||
public function getSerial(){
|
||
return json("请升级版本");
|
||
}
|
||
public function storgeErr(){
|
||
$notifications = new \app\index\library\notifications\Warehouse;
|
||
$params=$this->request->post();
|
||
$type = isset($params['type'])?$params['type']:1;
|
||
$Warehousemodel = new \app\common\model\Apps;
|
||
$usermodel = new \app\common\model\User;
|
||
$Warehouseerrmodel = new \app\common\model\Warehouseerr;
|
||
$his = $Warehouseerrmodel->where(["wareHouseId"=>$params['wareHouseId'],"storageId"=>$params['storageId'],"barCode"=>$params['barCode'],"status"=>0,"type"=>$params['type']])->find();
|
||
if($his){
|
||
$his->save(["count"=>$his['count']+1]);
|
||
}else{
|
||
$Warehouseerrmodel->save([
|
||
"wareHouseId" =>$params['wareHouseId'],
|
||
"type"=>$params['type'],
|
||
"barCode" => $params["barCode"],
|
||
"storageId"=>$params["storageId"],
|
||
"tempGoodsname"=>$params["tempGoodsname"],
|
||
"tempSerialNum"=>$params["tempSerialNum"],
|
||
"skubarcode"=>$params["skubarcode"],
|
||
"userId"=>$params["userId"],
|
||
"count"=>1
|
||
]);
|
||
$his = ["id"=>$Warehouseerrmodel->id];
|
||
}
|
||
try{
|
||
$Warehouse = $Warehousemodel->where(['warehouse_id'=>$params['wareHouseId'],'type'=>'wxOfficialAccount'])->find();
|
||
$users = $usermodel->where(['warehouseid'=>$params['wareHouseId']])->where("group_id","in",[5,7,2])->select();
|
||
$param = [
|
||
"data"=>[
|
||
"touser"=>"",
|
||
"template_id"=>"UUWQHSyS7t14J_8Au5QrwKmXHIEgaT_b9azH-PzOtWc",
|
||
"miniprogram"=>[
|
||
"appid"=>"",
|
||
"pagepath"=>""
|
||
],
|
||
"url"=>"",
|
||
"client_msg_id"=>md5($params['tempSerialNum'].$params['tempGoodsname'].time()),
|
||
"data"=>[
|
||
"time1"=>date('Y-m-d H:i:s'),
|
||
"thing6"=>$params['tempSerialNum'],
|
||
"thing4"=>mb_strimwidth($params['tempGoodsname'],0,16,'...'),
|
||
]
|
||
],
|
||
"id"=>$his["id"],
|
||
"code"=>($Warehouse['app_id'] ?? null)
|
||
];
|
||
foreach($users as $r){
|
||
$notifications->toWxOfficeAccount($r['id'],'storgeErr',$param);
|
||
}
|
||
}catch(Exception $e){
|
||
return json(["status"=>0]);
|
||
}
|
||
return json(["status"=>1]);
|
||
}
|
||
public function getApplyLists(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = isset($params['warehouseId'])?$params['warehouseId']:'0';
|
||
$StorageModel = new \app\common\model\Storage;
|
||
$list = $StorageModel->where(['WAREHOUSEID'=>$WAREHOUSEID,'STATUS'=>0])->select();
|
||
$WarehouseModel = new \app\common\model\Warehouse;
|
||
$WAREHOUSEconfig = $WarehouseModel->where(['WAREHOUSEID'=>$WAREHOUSEID])->find();
|
||
$whereLike = isset($params['sn'])&& $params['sn']?"storage.BARCODE like '%".str_replace("-1-1-", "", $params['sn'])."%'":'';
|
||
if($WAREHOUSEconfig && $list){
|
||
$whereinAPPLYSTORAGENUM = [];
|
||
$wmsStorageModel = new \app\common\model\wms\Storage;
|
||
foreach($list as $r){
|
||
array_push($whereinAPPLYSTORAGENUM,$r['APPLYSTORAGENUM']);
|
||
}
|
||
$slist = $wmsStorageModel->with(['employees','goods'])->where(['storage.WAREHOUSEID'=>$WAREHOUSEID,'storage.SPACEID'=>($WAREHOUSEconfig['SPACEID'] ?? null)])->where('storage.APPLYSTORAGENUM','in',$whereinAPPLYSTORAGENUM)->where($whereLike)->select();
|
||
return json(["status"=>0,'list'=>$slist]);
|
||
}else{
|
||
return json(["status"=>-1]);
|
||
}
|
||
|
||
}
|
||
public function getRemainingOrders(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = isset($params['warehouseId'])?$params['warehouseId']:'0';
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
$count = $orderModel->where(['WAREHOUSEID'=>$WAREHOUSEID,"PLSENDFLAG"=>0,"FLAG"=>0])->where("GRABNUM not like '%B%' and GRABNUM <> ''")->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000)->count();
|
||
return json(["remainingCount"=>$count]);
|
||
}
|
||
public function getGrabList(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = isset($params['warehouseId'])?$params['warehouseId']:'0';
|
||
$GRABNUM = isset($params['GRABNUM'])?$params['GRABNUM']:'0';
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
$list = $orderModel->field('POSTNUM,PRINTTIMES,ITEMS,PLSENDFLAG,FLAG,GRABNUM')->where(['WAREHOUSEID'=>$WAREHOUSEID,"PLSENDFLAG"=>0,"FLAG"=>0,"GRABNUM"=>$GRABNUM])->order('ITEMS')->select();
|
||
return json(["list"=>$list,"GRABNUM"=>$GRABNUM]);
|
||
}
|
||
|
||
public function getStock(){
|
||
$params=$this->request->post();
|
||
$STOCKID = $params['STOCKID'];
|
||
$StockModel = new \app\common\model\wms\Stock;
|
||
$data = $StockModel->with(['goods','box'])->where(["stock.STOCKID"=>$STOCKID])->find();
|
||
return json($data);
|
||
}
|
||
public function getStockByBarcode(){
|
||
$params=$this->request->post();
|
||
$warehouseId = $params['warehouseId'];
|
||
$barCode = $params['barCode'];
|
||
$storeId = $params['storeId'];
|
||
$StockModel = new \app\common\model\wms\Stock;
|
||
$data = $StockModel->where(["stock.STOCKID"=>$STOCKID])->find();
|
||
return json($data);
|
||
}
|
||
public function getStocksByPostnum(){
|
||
$params=$this->request->post();
|
||
$BARCODE = isset($params['BARCODE'])?$params['BARCODE']:0;
|
||
$WAREHOUSEID = isset($params['WAREHOUSEID'])?$params['WAREHOUSEID']:0;
|
||
$storeId = isset($params['storeId'])?$params['storeId']:0;
|
||
$StockModel = new \app\common\model\wms\Stock;
|
||
$StockImgsModel = new \app\common\model\wms\StockImgs;
|
||
$StockBoxsModel = new \app\common\model\wms\StockBoxs;
|
||
$datas = [];
|
||
if($BARCODE && $WAREHOUSEID){
|
||
$datas = $StockModel->alias("stock")
|
||
->field("
|
||
stock.BARCODE as BARCODE,
|
||
stock.IMG as IMG,
|
||
goods.NAME as NAME,
|
||
stock.STOCKID as STOCKID,
|
||
stock.WEIGHT as WEIGHT,
|
||
stock.YXQ as YXQ,
|
||
(COALESCE(storage_total.copycount, 0) - COALESCE(wmsitem_total.count_sum, 0)) as DISPLAYCOUNT
|
||
")
|
||
->join('yj_warestore warestore','warestore.ID=stock.WARESTOREID')
|
||
->join('yj_goods goods', 'stock.GOODSID = goods.GOODSID')
|
||
// 添加 storage 子查询
|
||
->join('(SELECT STOCKID, SUM(COUNT) as copycount FROM yj_storage GROUP BY STOCKID) storage_total', 'stock.STOCKID = storage_total.STOCKID', 'LEFT')
|
||
// 添加 wmsitem 子查询
|
||
->join('(SELECT wmsitem.STOCKID, SUM(wmsitem.COUNT) as count_sum FROM yj_wmsitem wmsitem INNER JOIN yj_wmsorder wmsorder ON wmsitem.WMSORDERID = wmsorder.ID WHERE wmsitem.DISPLAYFLAG = 0 GROUP BY wmsitem.STOCKID) wmsitem_total', 'stock.STOCKID = wmsitem_total.STOCKID', 'LEFT')
|
||
->where("stock.BARCODE","like","%{$BARCODE}%")->where(["stock.WAREHOUSEID"=>$WAREHOUSEID]);
|
||
if($storeId){
|
||
$datas->where(["warestore.STOREID"=>$storeId]);
|
||
}
|
||
$datas = $datas->select();
|
||
$STOCKIDS = [];
|
||
foreach ($datas as $data){
|
||
array_push($STOCKIDS,$data["STOCKID"]);
|
||
}
|
||
//print_r($STOCKIDS);
|
||
if(count($STOCKIDS)>0){
|
||
$imgs = $StockImgsModel->where("stock_id","in",$STOCKIDS)->select();
|
||
$boxs = $StockBoxsModel->where("stock_id","in",$STOCKIDS)->select();
|
||
foreach ($datas as $key =>$data){
|
||
$imgs_temp = [];
|
||
foreach ($imgs as $img){
|
||
if($data["STOCKID"]==$img['stock_id']){
|
||
array_push($imgs_temp,$img['url']);
|
||
}
|
||
}
|
||
$datas[$key]['IMGS'] = $imgs_temp;
|
||
|
||
$boxs_temp = [
|
||
"large"=>[
|
||
"count"=>0,
|
||
"length"=>0,
|
||
"width"=>0,
|
||
"height"=>0
|
||
],
|
||
"medium"=>[
|
||
"count"=>0,
|
||
"length"=>0,
|
||
"width"=>0,
|
||
"height"=>0
|
||
],
|
||
];
|
||
foreach ($boxs as $box){
|
||
if($data["STOCKID"]==$box['stock_id']){
|
||
$boxs_temp[$box->type] = [
|
||
"count"=>$box->count,
|
||
"length"=>$box->length,
|
||
"width"=>$box->width,
|
||
"height"=>$box->height
|
||
];
|
||
}
|
||
}
|
||
$datas[$key]['boxs'] = $boxs_temp;
|
||
}
|
||
}
|
||
}
|
||
return json($datas);
|
||
}
|
||
public function getStockByStock(){
|
||
$params=$this->request->post();
|
||
$STOCKID = isset($params['STOCKID'])?$params['STOCKID']:0;
|
||
$StockModel = new \app\common\model\wms\Stock;
|
||
$StockImgsModel = new \app\common\model\wms\StockImgs;
|
||
$StockBoxsModel = new \app\common\model\wms\StockBoxs;
|
||
$data = [];
|
||
if($STOCKID){
|
||
$data = $StockModel->alias("stock")
|
||
->field("
|
||
stock.BARCODE as BARCODE,
|
||
stock.IMG as IMG,
|
||
goods.NAME as NAME,
|
||
stock.STOCKID as STOCKID,
|
||
stock.WEIGHT as WEIGHT,
|
||
stock.YXQ as YXQ,
|
||
(COALESCE(storage_total.copycount, 0) - COALESCE(wmsitem_total.count_sum, 0)) as DISPLAYCOUNT
|
||
")
|
||
->join('yj_goods goods', 'stock.GOODSID = goods.GOODSID')
|
||
// 添加 storage 子查询
|
||
->join('(SELECT STOCKID, SUM(COUNT) as copycount FROM yj_storage GROUP BY STOCKID) storage_total', 'stock.STOCKID = storage_total.STOCKID', 'LEFT')
|
||
// 添加 wmsitem 子查询
|
||
->join('(SELECT wmsitem.STOCKID, SUM(wmsitem.COUNT) as count_sum FROM yj_wmsitem wmsitem INNER JOIN yj_wmsorder wmsorder ON wmsitem.WMSORDERID = wmsorder.ID WHERE wmsitem.DISPLAYFLAG = 0 GROUP BY wmsitem.STOCKID) wmsitem_total', 'stock.STOCKID = wmsitem_total.STOCKID', 'LEFT')
|
||
->where(["stock.STOCKID"=>$STOCKID])->find();
|
||
if($data){
|
||
$imgs = $StockImgsModel->where(["stock_id"=>$STOCKID])->select();
|
||
$boxs = $StockBoxsModel->where(["stock_id"=>$STOCKID])->select();
|
||
|
||
$imgs_temp = [];
|
||
foreach ($imgs as $img){
|
||
array_push($imgs_temp,$img['url']);
|
||
}
|
||
$data['IMGS'] = $imgs_temp;
|
||
|
||
$boxs_temp = [
|
||
"large"=>[
|
||
"count"=>0,
|
||
"length"=>0,
|
||
"width"=>0,
|
||
"height"=>0
|
||
],
|
||
"medium"=>[
|
||
"count"=>0,
|
||
"length"=>0,
|
||
"width"=>0,
|
||
"height"=>0
|
||
],
|
||
];
|
||
foreach ($boxs as $box){
|
||
$boxs_temp[$box->type] = [
|
||
"count"=>$box->count,
|
||
"length"=>$box->length,
|
||
"width"=>$box->width,
|
||
"height"=>$box->height
|
||
];
|
||
}
|
||
$data['boxs'] = $boxs_temp;
|
||
}
|
||
}
|
||
return json($data);
|
||
}
|
||
public function getStockHistory(){
|
||
$params=$this->request->post();
|
||
$STOCKID = $params['STOCKID'];
|
||
$MovestorageModel = new \app\common\model\wms\Movestorage;
|
||
$data = $MovestorageModel->alias("movestorage")->field("DATE_FORMAT(FROM_UNIXTIME(movestorage.CREATIONDATE / 1000),'%Y-%m-%d %H:%i:%s') as CREATIONDATE,spacein.CUSTOMNUM as INCUSTOMNUM,spaceout.CUSTOMNUM as OUTCUSTOMNUM,name")->join("yj_operationrecord operationrecord","operationrecord.CREATIONDATE=movestorage.CREATIONDATE")->join("yj_user user","user.userID=operationrecord.userID")->join("yj_space spacein","spacein.BARCODE=movestorage.INBARCODE")->join("yj_space spaceout","spaceout.BARCODE=movestorage.OUTBARCODE")->where(["movestorage.STOCKID"=>$STOCKID])->order("CREATIONDATE desc")->select();
|
||
return json($data);
|
||
}
|
||
public function getStock2(){
|
||
$params=$this->request->post();
|
||
$StockModel = new \app\common\model\wms\Stock;
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$BARCODE = $params['BARCODE'];
|
||
$data = $StockModel->with(['goods','box'])->where(["stock.WAREHOUSEID"=>$WAREHOUSEID])->where("stock.BARCODE like '%".$BARCODE."%'")->select();
|
||
return json($data);
|
||
}
|
||
public function loginByUuid(){
|
||
$userModel = new \app\common\model\User;
|
||
$params=$this->request->post();
|
||
$uuid = base64_encode(json_encode(["uuid"=>$params['uuid']]));
|
||
$userinfo = $userModel->where(["tmp_code"=>$uuid])->find();
|
||
if(!$userinfo || !($userinfo['wms_userid'] ?? null)){
|
||
return json(['code'=>-1,'msg'=>'登录失败','data'=>[]]);
|
||
}
|
||
$wmsuserModel = new \app\common\model\wms\User;
|
||
$wmsuser = $wmsuserModel->where(['userID'=>($userinfo['wms_userid'] ?? null)])->find();
|
||
if($wmsuser){
|
||
$data = [
|
||
"username"=>$wmsuser['username'],
|
||
"userId"=> $wmsuser['userID'],
|
||
"name"=>$wmsuser['name'],
|
||
"wareHouseId"=>($userinfo['warehouseid'] ?? null)
|
||
];
|
||
return json(['code'=>1,'msg'=>'登录成功','data'=>$data]);
|
||
}
|
||
return json(['code'=>-1,'msg'=>'登录失败','data'=>[]]);
|
||
}
|
||
public function loginByUuid2(){
|
||
$userModel = new \app\common\model\User;
|
||
$params=$this->request->post();
|
||
$uuid = base64_encode(json_encode(["uuid"=>$params['uuid']]));
|
||
$user = $userModel->where(["tmp_code"=>$uuid])->find();
|
||
if(!$user){
|
||
return json(['code'=>-1,'msg'=>'登录失败','data'=>[]]);
|
||
}
|
||
$has = false;
|
||
try{
|
||
if($user){
|
||
$group = $user->group;
|
||
$rules = explode(',', $group->rules);
|
||
$rules = UserRule::where('status', 'normal')->where('id', 'in', $rules)->field('id,pid,name,title,ismenu')->select();
|
||
$rules2 = [];
|
||
foreach ($rules as $k => $v) {
|
||
$rules2[] = $v['name'];
|
||
}
|
||
$path = "express_login";
|
||
$module = '';
|
||
$url = ($module ? $module : request()->module()) . '/' . (is_null($path) ? $this->getRequestUri() : $path);
|
||
$url = strtolower(str_replace('.', '/', $url));
|
||
$has = in_array($url, $rules2) ? true : false;
|
||
}
|
||
}catch(Exception $e){
|
||
$has = false;
|
||
}
|
||
if($has){
|
||
return json(['code'=>1,'msg'=>'登录成功','data'=>["username"=>$user['nickname'],"userId"=>$user['id'],"name"=>$user['nickname'],"wareHouseId"=>$user['warehouseid'],"loginFlag"=>1]]);
|
||
}else{
|
||
return json(['code'=>-1,'msg'=>'登录失败','data'=>[]]);
|
||
}
|
||
}
|
||
private function getStockImgs($STOCKID){
|
||
$StockImgsModel = new \app\common\model\wms\StockImgs;
|
||
$imgs = $StockImgsModel->where(["stock_id"=>$STOCKID])->select();
|
||
$img_arr = [];
|
||
foreach ($imgs as $img){
|
||
array_push($img_arr,$img['url']);
|
||
}
|
||
return $img_arr;
|
||
}
|
||
public function printGrabPickings(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$POSTNUM = $params['POSTNUM'];
|
||
$canback = isset($params['back'])?$params['back']:false;
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
$tmporder = $orderModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"POSTNUM"=>$POSTNUM])->find();
|
||
if(!$tmporder){
|
||
return json(["datas"=>[],"GRABNUM"=>"","order_count"=>0]);
|
||
}
|
||
$GRABNUM = $tmporder["GRABNUM"];
|
||
if(!$GRABNUM){
|
||
return json(["datas"=>[],"GRABNUM"=>"","order_count"=>0,"orders3"=>false]);
|
||
}
|
||
$orders = $orderModel->field("ID")->where(["WAREHOUSEID"=>$WAREHOUSEID,"GRABNUM"=>$GRABNUM,"PLSENDFLAG"=>0,"FLAG"=>0])->select();;
|
||
$ids = [];
|
||
foreach($orders as $r){
|
||
array_push($ids,$r['ID']);
|
||
}
|
||
$orderModel = new \app\common\model\wms\Picking;
|
||
$STOCKIDs = $orderModel->field('COUNT,DETAILS,SPACEID,STOCKID')->where("WMSORDERID","in",$ids)->with(["space","stock"])->select();
|
||
$STOCKS = [];
|
||
foreach($STOCKIDs as $kk => $r){
|
||
$hasSKU = false;
|
||
$STOCKIDs[$kk]['IMGS'] = $this->getStockImgs($r['STOCKID']);
|
||
foreach ($STOCKS as $k => $rr){
|
||
if($rr['STOCKID']==$r['STOCKID']){
|
||
$rr['COUNT']+=$r['COUNT'];
|
||
$rr['IMGS']=$r['IMGS'];
|
||
$hasSKU = true;
|
||
}
|
||
}
|
||
if(!$hasSKU){
|
||
array_push($STOCKS,$r);
|
||
}
|
||
}
|
||
usort($STOCKS,function($a,$b){
|
||
return $a['space']['IDX'] - $b['space']['IDX'];
|
||
});
|
||
$WorksModel = new \app\common\model\workers\Works;
|
||
$time = time()-(60*60*24*3);
|
||
if(count($STOCKS)==0){
|
||
$work = $WorksModel->where(["grabnum"=>$GRABNUM])->where("createtime>$time")->where("picks>0")->find();
|
||
if($work && !$canback){
|
||
$work->save(["updatetime"=>time()]);
|
||
}
|
||
}else{
|
||
$work = $WorksModel->where(["grabnum"=>$GRABNUM])->where("createtime>$time")->where("picks>0")->find();
|
||
$STOCKSS = [];
|
||
foreach ($STOCKS as $k=> $r){
|
||
array_push($STOCKSS,$r["STOCKID"]."|".($k+1));
|
||
}
|
||
$ITEMS = implode(";",$STOCKSS);
|
||
|
||
$orders3 = "";
|
||
if((strpos($GRABNUM,"E")>-1 || strpos($GRABNUM,"H")>-1) && !($work['orders'] ?? null)&& !$canback){
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
$list = $orderModel->where(['WAREHOUSEID'=>$WAREHOUSEID,"PLSENDFLAG"=>0,"FLAG"=>0,"GRABNUM"=>$GRABNUM])->order('ITEMS')->select();
|
||
$orders2 = [];
|
||
foreach ($list as $index =>$r){
|
||
array_push($orders2,$r["POSTNUM"]."|".($index+1));
|
||
}
|
||
$orders3 = implode(";",$orders2);
|
||
$work->save(["orders"=>$orders3]);
|
||
//last
|
||
}
|
||
if($work && !$canback){
|
||
$work->save(["items"=>$ITEMS]);
|
||
}
|
||
}
|
||
return json(["datas"=>$STOCKS,"GRABNUM"=>$GRABNUM,"order_count"=>count($orders),"orders3"=>!($work['orders'] ?? null)]);
|
||
}
|
||
private function printGrabPickings_private($WAREHOUSEID,$GRABNUM){
|
||
$params=$this->request->post();
|
||
$canback = true;
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
$tmporder = $orderModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"GRABNUM"=>$GRABNUM])->find();
|
||
if(!$tmporder){
|
||
return ["datas"=>[],"GRABNUM"=>"","order_count"=>0];
|
||
}
|
||
$GRABNUM = $tmporder["GRABNUM"];
|
||
$orders = $orderModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"GRABNUM"=>$GRABNUM,"PLSENDFLAG"=>0])->select();;
|
||
$ids = [];
|
||
foreach($orders as $r){
|
||
array_push($ids,$r['ID']);
|
||
}
|
||
$orderModel = new \app\common\model\wms\Picking;
|
||
$STOCKIDs = $orderModel->field('COUNT,DETAILS,SPACEID,STOCKID')->where("WMSORDERID","in",$ids)->with(["space","stock"])->select();
|
||
$STOCKS = [];
|
||
foreach($STOCKIDs as $r){
|
||
$hasSKU = false;
|
||
foreach ($STOCKS as $k => $rr){
|
||
if($rr['STOCKID']==$r['STOCKID']){
|
||
$rr['COUNT']+=$r['COUNT'];
|
||
$hasSKU = true;
|
||
}
|
||
}
|
||
if(!$hasSKU){
|
||
array_push($STOCKS,$r);
|
||
}
|
||
}
|
||
usort($STOCKS,function($a,$b){
|
||
return $a['space']['IDX'] - $b['space']['IDX'];
|
||
});
|
||
$WorksModel = new \app\common\model\workers\Works;
|
||
if(count($STOCKS)==0){
|
||
$work = $WorksModel->where(["grabnum"=>$GRABNUM])->where("picks>0")->find();
|
||
if($work && !$canback){
|
||
$work->save(["updatetime"=>time()]);
|
||
}
|
||
}else{
|
||
$work = $WorksModel->where(["grabnum"=>$GRABNUM])->where("picks>0")->find();
|
||
$STOCKSS = [];
|
||
foreach ($STOCKS as $k=> $r){
|
||
array_push($STOCKSS,$r["STOCKID"]."|".($k+1));
|
||
}
|
||
$ITEMS = implode(";",$STOCKSS);
|
||
|
||
$orders3 = "";
|
||
if((strpos($GRABNUM,"E")>-1 || strpos($GRABNUM,"H")>-1) && !($work['orders'] ?? null)&& !$canback){
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
$list = $orderModel->where(['WAREHOUSEID'=>$WAREHOUSEID,"PLSENDFLAG"=>0,"FLAG"=>0,"GRABNUM"=>$GRABNUM])->order('ITEMS')->select();
|
||
$orders2 = [];
|
||
foreach ($list as $index =>$r){
|
||
array_push($orders2,$r["POSTNUM"]."|".($index+1));
|
||
}
|
||
$orders3 = implode(";",$orders2);
|
||
$work->save(["orders"=>$orders3]);
|
||
//last
|
||
}
|
||
if($work && !$canback){
|
||
$work->save(["items"=>$ITEMS]);
|
||
}
|
||
}
|
||
return ["datas"=>$STOCKS,"GRABNUM"=>$GRABNUM,"order_count"=>count($orders),"orders3"=>!($work['orders'] ?? null)];
|
||
}
|
||
public function getOrdersbypicking(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['warehouseId'];
|
||
$GRABNUM = $params['GRABNUM'];
|
||
$WorksModel = new \app\common\model\workers\Works;
|
||
$work = $WorksModel->where(["grabnum"=>$GRABNUM])->where("picks>0")->find();
|
||
return json($work);
|
||
}
|
||
public function getStockBoxcount(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$STOCKID = $params['STOCKID'];
|
||
$BoxModel = new \app\common\model\wms\Box;
|
||
$box = $BoxModel->where(['WAREHOUSEID'=>$WAREHOUSEID,'STOCKID'=>$STOCKID])->find();
|
||
$count = 0;
|
||
if($box){
|
||
$count = $box['COUNT'];
|
||
}
|
||
return $count;
|
||
}
|
||
public function get_print_setting(){
|
||
$params=$this->request->post();
|
||
$has = false;
|
||
try{
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$userid = $params['userid'];
|
||
$UserModel = new \app\common\model\User;
|
||
$user = $UserModel->where(['wms_userid'=>$userid])->find();
|
||
if($user){
|
||
$group = $user->group;
|
||
$rules = explode(',', $group->rules);
|
||
$rules = UserRule::where('status', 'normal')->where('id', 'in', $rules)->field('id,pid,name,title,ismenu')->select();
|
||
$rules2 = [];
|
||
foreach ($rules as $k => $v) {
|
||
$rules2[] = $v['name'];
|
||
}
|
||
$path = "pda_print";
|
||
$module = '';
|
||
$url = ($module ? $module : request()->module()) . '/' . (is_null($path) ? $this->getRequestUri() : $path);
|
||
$url = strtolower(str_replace('.', '/', $url));
|
||
$has = in_array($url, $rules2) ? true : false;
|
||
}
|
||
}catch(Exception $e){
|
||
$has = false;
|
||
}
|
||
return json(["Authorized"=>$has]);
|
||
}
|
||
public function getPrinter(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$printer = $params['printer'];
|
||
$PrinterModel = new \app\common\model\Printer;
|
||
$printerdata = $PrinterModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"id"=>intval($printer)])->find();
|
||
if($printerdata){
|
||
return json(["printer_name"=>$printerdata->name,"Address"=>$printerdata->address,"defaultPrinter"=>$printerdata->defaultprinter,"Names"=>json_decode($printerdata->config,true)]);
|
||
}else{
|
||
return json([]);
|
||
}
|
||
|
||
}
|
||
public function get_post_grabnum(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$postnum = $params['postnum'];
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
$GRABNUM = 0;
|
||
$GRABNUM = $orderModel->field('GRABNUM')->where(['WAREHOUSEID'=>$WAREHOUSEID])->where('POSTNUM="'.$postnum.'" or GRABNUM="'.$postnum.'"')->find();
|
||
if(!$GRABNUM){
|
||
$orderModel1 = new \app\common\model\wms\Deliveryorder;
|
||
$GRABNUM = $orderModel1->field('GRABNUM')->where(['WAREHOUSEID'=>$WAREHOUSEID])->where('POSTNUM="'.$postnum.'" or GRABNUM="'.$postnum.'"')->find();
|
||
}
|
||
if(!($GRABNUM["GRABNUM"] ?? null)|| !$GRABNUM){
|
||
return json(["GRABNUM"=>null]);
|
||
}else{
|
||
return json($GRABNUM);
|
||
}
|
||
}
|
||
|
||
public function get_sandan_list(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
$list = $orderModel->field("GROUP_CONCAT(assignFlag) as assignFlags,GRABNUM,GROUP_CONCAT(POSTNUM) as POSTNUMs,min(CREATIONDATE) as GRABDATE,POSTNUM")->where(['WAREHOUSEID'=>$WAREHOUSEID])->where(['PLSENDFLAG'=>0])->where("GRABNUM like '%F%' and postcode<>'p18'")->where("GRABNUM <>''")->group('GRABNUM')->select();
|
||
$reslist = [];
|
||
foreach ($list as $r){
|
||
$postnums = explode(',',$r['POSTNUMs']);
|
||
if(strpos($r['assignFlags'],"0") === false && !in_array('', $postnums)){
|
||
array_push($reslist,["GRABNUM"=>$r['GRABNUM'],"GRABDATE"=>intval($r['GRABDATE']),"POSTNUM"=>$r["POSTNUM"]]);
|
||
}
|
||
}
|
||
return json(["list"=>$reslist]);
|
||
}
|
||
public function sandan_locker(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$GRABNUM = $params['GRABNUM'];
|
||
$userid = $params['userid'];
|
||
if(!$WAREHOUSEID){
|
||
return json(['code'=>-2]);
|
||
}
|
||
if(!$GRABNUM || !$userid){
|
||
return json(['code'=>-1]);
|
||
}
|
||
$params = ["GRABNUM"=>$GRABNUM,"userid"=>$userid];
|
||
$model = new \app\common\model\wms\sandan\Locker;
|
||
Db::startTrans();
|
||
try {
|
||
$result = $model->save($params);
|
||
Db::commit();
|
||
return json(['code'=>1]);
|
||
} catch (ValidateException|PDOException|Exception $e) {
|
||
Db::rollback();
|
||
$data = $model->where($params);
|
||
if($data){
|
||
return json(['code'=>1,'car'=>$data['cardNum']]);
|
||
}
|
||
return json(['code'=>0]);
|
||
}
|
||
}
|
||
|
||
public function getgrabnumtype($GRABNUM){
|
||
//$params=$this->request->post();
|
||
//$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
//$GRABNUM = $params['GRABNUM'];
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
$list = $orderModel->field('ID')->where([/*"WAREHOUSEID"=>$WAREHOUSEID,*/"GRABNUM"=>$GRABNUM,"FLAG"=>0])->select();
|
||
$IDS = [];
|
||
foreach ($list as $r){
|
||
array_push($IDS,$r['ID']);
|
||
}
|
||
$IDSSTR = implode(',',$IDS);
|
||
$pickingModel = new \app\common\model\wms\Picking;
|
||
$space_list = $pickingModel->where("WMSORDERID","in",$IDSSTR)->with('space')->group('SPACEID')->select();
|
||
$space_list_res = [];
|
||
foreach($space_list as $r){
|
||
$quwei = $r->space->CUSTOMNUM;
|
||
$tmp = [];
|
||
$pattern = '/([A-Z0-9]+)(区|区\-)[0-9]+/';
|
||
if(preg_match($pattern, $r->space->CUSTOMNUM, $tmp)){
|
||
$quwei = $tmp[0];
|
||
}
|
||
array_push($space_list_res,$quwei);
|
||
}
|
||
$space_list_unique = array_unique($space_list_res);
|
||
return isset($space_list_unique[0])?$space_list_unique[0]:'';
|
||
}
|
||
public function findgrab(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$POSTNUM = $params['POSTNUM'];
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
$data= $orderModel->where(['WAREHOUSEID'=>$WAREHOUSEID,'POSTNUM'=>$POSTNUM])->find();
|
||
$GRABNUM = ($data['GRABNUM'] ?? null);
|
||
$datas = $orderModel->field('SUM(CASE WHEN PRINTTIMES=0 THEN 1 ELSE 0 END) AS wdy,SUM(CASE WHEN OPERATERECORDS not like "%领取快递面单%" THEN 1 ELSE 0 END) AS wll,SUM(CASE WHEN PICKINGFLAG=3 THEN 1 ELSE 0 END) AS yjh,GRABNUM,count(*) as count')->where(['GRABNUM'=>$GRABNUM])->group('GRABNUM')->find();
|
||
return $datas;
|
||
}
|
||
public function getpickinglist(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$grabnumList = $params['grabnumList'];
|
||
if(count($grabnumList)==0){
|
||
return json([]);
|
||
}
|
||
//$grabnumList = implode(',',$grabnumList);
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
$list = $orderModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"FLAG"=>0])->where("GRABNUM","in",$grabnumList)->select();
|
||
$ids = [];
|
||
foreach($list as $r){
|
||
array_push($ids,$r['ID']);
|
||
}
|
||
$pickingModel = new \app\common\model\wms\Picking;
|
||
$stock_list = $pickingModel->field('WMSORDERID,COUNT,STOCKID')->where("WMSORDERID","in",$ids)->with(['order'])->select();
|
||
$space_list = $pickingModel->field('SPACEID,STOCKID,GOODSID')->where("WMSORDERID","in",$ids)->with(['space','stock','goods'])->group('STOCKID')->order('space.IDX')->select();
|
||
foreach($space_list as $list1){
|
||
$list1['count'] = 0;
|
||
$GRABNUMS = [];
|
||
foreach($stock_list as $list2){
|
||
if($list1->STOCKID==$list2->STOCKID){
|
||
$list1['count']+=$list2['COUNT'];
|
||
$index = $this->getindex($grabnumList,$list2['order']['GRABNUM']);
|
||
if(!isset($GRABNUMS['篮号'.$index])){
|
||
$GRABNUMS['篮号'.$index] = $list2['COUNT'];
|
||
}else{
|
||
$GRABNUMS['篮号'.$index] += $list2['COUNT'];
|
||
}
|
||
}
|
||
}
|
||
$list1['box'] = $GRABNUMS;
|
||
$list1['img'] = 'http://file2.gztbyc.com/dl/'.$list1['stock']['IMG'];
|
||
$list1['imgs'] = $this->getStockImgs($list1['STOCKID']);
|
||
$list1['NAME'] = $list1['goods']['NAME'];
|
||
$list1['STYLE'] =$list1['stock']['STYLE'];
|
||
$list1['COLOR'] = $list1['stock']['COLOR'];
|
||
$list1['BARCODE'] = $list1['stock']['BARCODE'];
|
||
$list1['CUSTOMNUM'] = $list1['space']['CUSTOMNUM'];
|
||
$list1['barCode'] = $list1['space']['BARCODE'];
|
||
$list1['picked'] = false;
|
||
unset($list1['stock']);
|
||
unset($list1['goods']);
|
||
unset($list1['space']);
|
||
}
|
||
return json($space_list);
|
||
}
|
||
private function getindex($grabnumList,$value){
|
||
$tmpk = -1;
|
||
foreach ($grabnumList as $k=>$r){
|
||
if($value==$r){
|
||
$tmpk = $k;
|
||
}
|
||
}
|
||
return $tmpk;
|
||
}
|
||
public function get_pack_and_weight(){
|
||
$params=$this->request->post();
|
||
$STOCKS = $params['STOCKS'];
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$ItemsinfoModel = new \app\common\model\stocks\Weightandpack;
|
||
$PackModel = new \app\common\model\wms\Pack;
|
||
$data = $ItemsinfoModel->where(["STOCKS"=>$STOCKS,"WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
if($data){
|
||
$PACK = $PackModel->where(["ID"=>$data['PACKID']])->find();
|
||
$data["PACKNAME"] = ($PACK['NAME'] ?? null);
|
||
}
|
||
return $data;
|
||
}
|
||
public function check_pack_and_weight(){
|
||
$params=$this->request->post();
|
||
$ITEMS = $params['STOCKSINFO'];
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$ItemsinfoModel = new \app\common\model\stocks\Weightandpack;
|
||
$PackModel = new \app\common\model\wms\Pack;
|
||
$WEIGHT = $ITEMS['WEIGHT'];
|
||
$PACKID = $ITEMS['PACKID'];
|
||
$STOCKS = $ITEMS['STOCKS'];
|
||
$ITEMSS = isset($ITEMS['ITEMS'])?$ITEMS['ITEMS']:'';
|
||
$data = $ItemsinfoModel->where(["STOCKS"=>$STOCKS,"WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
$res=[];
|
||
if($data){
|
||
if($data["PACKID"]!=$PACKID && $data["WEIGHT"]!=$WEIGHT && $data["ISLOCK"]==0){
|
||
$res = $data->save(["Misses"=>intval($data["Misses"])+1]);
|
||
}
|
||
if($data["WEIGHT"]==0 && $WEIGHT>0){
|
||
$data->save(["WEIGHT"=>$WEIGHT]);
|
||
}
|
||
}else{
|
||
$res = $ItemsinfoModel->save(["STOCKS"=>$STOCKS,"PACKID"=>$PACKID,"WEIGHT"=>$WEIGHT,"WAREHOUSEID"=>$WAREHOUSEID,"ISLOCK"=>0,"ITEMS"=>$ITEMSS]);
|
||
}
|
||
return json($res);
|
||
}
|
||
public function updateStockList(){
|
||
$wmsStorageModel = new \app\common\model\wms\Storage;
|
||
$list = $wmsStorageModel->join('yj_space space', 'yj_storage.SPACEID=space.ID')->where(["yj_storage.WAREHOUSEID"=>5400,"SPACECODE"=>"cc11","space.FIRSTFLAG"=>1])->select();
|
||
$stocks = [];
|
||
foreach ($list as $r){
|
||
array_push($stocks,$r["STOCKID"]);
|
||
}
|
||
$stocks = array_values(array_unique($stocks));
|
||
$this->redis->set("tmp_stock_list",implode(",",$stocks));
|
||
return implode(",",$stocks);
|
||
}
|
||
public function get_sandan_rule_count_new(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$type = $params['type'];
|
||
$RulesModel = $this->RulesModel;
|
||
$ItemsinfoModel = new \app\common\model\stocks\Weightandpack;
|
||
$Rules = $RulesModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"status"=>1,"type"=>1]);
|
||
switch($type){
|
||
case 1:
|
||
$Rules = $Rules->where("grabtype<>5")->select();
|
||
break;
|
||
case 2:
|
||
$Rules = $Rules->where("grabtype=5")->select();
|
||
break;
|
||
}
|
||
$sameordercount = 0;
|
||
$sameordercount2 = 1000;
|
||
foreach($Rules as $r){
|
||
$sameordercount = $r['sameordercountgt']>$sameordercount?$r['sameordercountgt']:$sameordercount;
|
||
$sameordercount2 = $r['sameordercountlt']<$sameordercount2?$r['sameordercountlt']:$sameordercount2;
|
||
}
|
||
|
||
//符合散单的数据集
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$itemsgroup = $OrderModel->field('ITEMS,count(*) count,STOREID,POSTCODE,STOCKS')->where(["WAREHOUSEID"=>$WAREHOUSEID,"FLAG"=>0,"PLSENDFLAG"=>0,"POSTFLAG"=>1,"ISLOCK"=>0])->where('GRABNUM IS NULL or GRABNUM=""')->group("STOCKS,POSTCODE")->select();
|
||
$itemsgroupList = [];
|
||
$itemsgroupList2 = [];
|
||
|
||
foreach ($itemsgroup as $r){
|
||
if($r["count"]<=$sameordercount && $r["count"]>=$sameordercount2){
|
||
array_push($itemsgroupList,[$r["STOCKS"],$r["POSTCODE"],$r["count"]]);
|
||
}
|
||
}
|
||
$where = [];
|
||
foreach ($itemsgroupList as $r){
|
||
array_push($where,'STOCKS="'.$r[0].'" and POSTCODE="'.$r[1].'"');
|
||
}
|
||
$where = implode(" or ",$where);
|
||
if(!$where){
|
||
$Allitems = [];
|
||
}else{
|
||
$Allitems = $OrderModel->field('ID,STOREID,POSTCODE,ITEMS,STOREID,JDFLAG,GOODSCOUNT,POSTNUM,PROVINCE,STOCKS,STORENAME')->where(["WAREHOUSEID"=>$WAREHOUSEID,"plSendFlag"=>0,"FLAG"=>0,"POSTFLAG"=>1,"ISLOCK"=>0])->where('GRABNUM IS NULL or GRABNUM=""')->where(["ASSIGNFLAG"=>1])->where($where)->select();
|
||
}
|
||
|
||
|
||
$STOCKSarr = [];
|
||
foreach ($Allitems as $order){
|
||
array_push($STOCKSarr,$order["STOCKS"]);
|
||
}
|
||
$PACKS = $ItemsinfoModel->where("STOCKS","in",$STOCKSarr)->select();
|
||
foreach ($Allitems as $order){
|
||
$has = false;
|
||
foreach ($PACKS as $PACK){
|
||
if($order["STOCKS"]==$PACK["STOCKS"]){
|
||
$order["PACKID"]=$PACK["PACKID"];
|
||
$has = true;
|
||
}
|
||
}
|
||
if(!$has){
|
||
$order["PACKID"]=0;
|
||
}
|
||
}
|
||
foreach ($Allitems as $r){
|
||
$r['skucount'] = substr_count($r['ITEMS'],"|");
|
||
}
|
||
foreach($Rules as $k => $r){
|
||
$r['ordercount']=0;
|
||
$tmpordercount = count($Allitems);
|
||
$tmporders = [];
|
||
$tmporders_ex = [
|
||
"1"=>[],
|
||
"2"=>[],
|
||
"3"=>[],
|
||
"4"=>[],
|
||
"5"=>[],
|
||
"6"=>[],
|
||
"7"=>[],
|
||
"8"=>[],
|
||
"9"=>[],
|
||
"10"=>[],
|
||
"11"=>[]
|
||
];
|
||
foreach ($Allitems as $rr){
|
||
if($r['goodscountgt']!=0 && $rr['GOODSCOUNT']>$r['goodscountgt']){
|
||
$tmpordercount-- ;
|
||
array_push($tmporders_ex['1'],$rr);
|
||
continue;
|
||
}
|
||
if($r['goodscountlt']!=0 && $rr['GOODSCOUNT']<$r['goodscountlt']){
|
||
$tmpordercount-- ;
|
||
array_push($tmporders_ex['2'],$rr);
|
||
continue;
|
||
}
|
||
if($r['skucountlt']!=0 && $rr['skucount']<$r['skucountlt']){
|
||
$tmpordercount-- ;
|
||
array_push($tmporders_ex['3'],$rr);
|
||
continue;
|
||
}
|
||
if($r['skucountgt']!=0 && $rr['skucount']>$r['skucountgt']){
|
||
$tmpordercount-- ;
|
||
array_push($tmporders_ex['4'],$rr);
|
||
continue;
|
||
}
|
||
$exclude_store = explode(",",$r['store_ids']);
|
||
$exclude_store = array_filter($exclude_store);
|
||
if(!in_array($rr['STOREID'],$exclude_store)){
|
||
$tmpordercount-- ;
|
||
array_push($tmporders_ex['5'],$rr);
|
||
continue;
|
||
}
|
||
$exclude_post = explode(",",$r['post_codes']);
|
||
$exclude_post = array_filter($exclude_post);
|
||
if(!in_array($rr['POSTCODE'],$exclude_post)){
|
||
$tmpordercount-- ;
|
||
array_push($tmporders_ex['6'],$rr);
|
||
continue;
|
||
}
|
||
$exclude_province = explode(",",$r['provinces']);
|
||
$exclude_province = array_filter($exclude_province);
|
||
if(!in_array($rr['PROVINCE'],$exclude_province)){
|
||
array_push($tmporders_ex['7'],$rr);
|
||
$tmpordercount-- ;
|
||
continue;
|
||
}
|
||
$exclude_JDFLAG = explode(",",$r['JDFLAGs']);
|
||
//$exclude_JDFLAG = array_filter($exclude_JDFLAG);
|
||
if(!in_array($rr['JDFLAG'],$exclude_JDFLAG)){
|
||
$tmpordercount-- ;
|
||
array_push($tmporders_ex['8'],$rr);
|
||
continue;
|
||
}
|
||
$skuss = [];
|
||
$skus = explode('|',$rr['ITEMS']);
|
||
$skus = array_filter($skus);
|
||
foreach($skus as $rrr){
|
||
$items = explode(',',$rrr);
|
||
array_push($skuss,$items[0]);
|
||
}
|
||
$rr['stocks'] = $skuss;
|
||
|
||
|
||
array_push($tmporders,$rr);
|
||
}
|
||
$r['ordercount'] = $tmpordercount;
|
||
$tmpskus = [];
|
||
$tmpskuss = [];
|
||
switch ($r['grabtype']) {
|
||
case 1:
|
||
// 单品单件
|
||
$tmpskuss = $this->generateCombinations1($tmporders,$r['ordercountgt'],$r['group'],$r['posttype']);
|
||
break;
|
||
case 2:
|
||
// 边拣边分
|
||
$tmpskuss = $this->generateCombinations2($tmporders,$r['grabskucountgt'],$r['group'],$r['posttype'],$r['ordercountgt'],true);
|
||
break;
|
||
case 3:
|
||
// 边拣边分
|
||
$tmpskuss = $this->generateCombinations3($tmporders,$r['ordercountgt'],$r['group'],$r['posttype']);
|
||
break;
|
||
case 4:
|
||
// 边拣边分
|
||
$tmpskuss = $this->generateCombinations3($tmporders,$r['ordercountgt'],$r['group'],$r['posttype']);
|
||
break;
|
||
case 5:
|
||
// 团购
|
||
$tmpskuss = $this->generateCombinations5($tmporders,$r['ordercountgt'],$r['group'],$r['posttype']);
|
||
break;
|
||
case 6:
|
||
$tmpskuss = $this->generateCombinations3($tmporders,$r['ordercountgt'],$r['group'],$r['posttype']);
|
||
break;
|
||
}
|
||
//$r['allorders'] = $tmporders;
|
||
$r['ordercount'] = count($tmporders);
|
||
$r['tmpskus'] = $tmpskuss;
|
||
$r['tmporder'] = $tmporders_ex;
|
||
}
|
||
usort($Rules,function($a,$b){
|
||
if(isset($a['tmpskus']['order_count']) && isset($b['tmpskus']['order_count'])){
|
||
return $b['tmpskus']['order_count'] - $a['tmpskus']['order_count'];
|
||
}
|
||
});
|
||
print_r(json_encode(["rules"=>$Rules,"count"=>count($Allitems)]));
|
||
}
|
||
public function getPostCodeName($postcode){
|
||
if(!$this->postcodeList){
|
||
$Paracodemodel = new \app\common\model\wms\Paracode;
|
||
$data2=$Paracodemodel->where(["TYPE"=>"301"])->select();
|
||
$this->postcodeList = $data2;
|
||
}
|
||
$name = "";
|
||
foreach ($this->postcodeList as $r){
|
||
if($r["CODE"]==$postcode){
|
||
$name = $r["NAME"];
|
||
}
|
||
}
|
||
return mb_substr($name, 0, 1, "UTF-8");
|
||
}
|
||
public function get_sandan_rule_count(){
|
||
$times = [];
|
||
$startTime = time();
|
||
$lastTime = $startTime;
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$type = $params['type'];
|
||
//散单规则池
|
||
$RulesModel = $this->RulesModel;
|
||
$ItemsinfoModel = new \app\common\model\stocks\Weightandpack;
|
||
array_push($times,time()-$lastTime);
|
||
$lastTime = time();
|
||
$Rules = $RulesModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"status"=>1,"type"=>0]);
|
||
array_push($times,time()-$lastTime);
|
||
$lastTime = time();
|
||
switch($type){
|
||
case 1:
|
||
$Rules = $Rules->where("grabtype<>5")->select();
|
||
break;
|
||
case 2:
|
||
$Rules = $Rules->where("grabtype=5")->select();
|
||
break;
|
||
}
|
||
|
||
array_push($times,time()-$lastTime);
|
||
$lastTime = time();
|
||
$sameordercount = 0;
|
||
$sameordercount2 = 1000;
|
||
foreach($Rules as $r){
|
||
$include_posts = explode(",",$r["post_codes"]);
|
||
if(count($include_posts)>1){
|
||
$r["tag"] = "混";
|
||
}else{
|
||
$r["tag"] = $this->getPostCodeName($include_posts[0]);
|
||
}
|
||
$sameordercount = $r['sameordercountgt']>$sameordercount?$r['sameordercountgt']:$sameordercount;
|
||
$sameordercount2 = $r['sameordercountlt']<$sameordercount2?$r['sameordercountlt']:$sameordercount2;
|
||
}
|
||
|
||
array_push($times,time()-$lastTime);
|
||
$lastTime = time();
|
||
//符合散单的数据集
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$itemsgroup = $OrderModel->field('ITEMS,count(*) count,STOREID,POSTCODE,STOCKS')->where(["WAREHOUSEID"=>$WAREHOUSEID,"FLAG"=>0,"PLSENDFLAG"=>0,"POSTFLAG"=>1,"ISLOCK"=>0])->where('GRABNUM IS NULL or GRABNUM=""')->group("STOCKS,POSTCODE")->select();
|
||
|
||
array_push($times,time()-$lastTime);
|
||
$lastTime = time();
|
||
$itemsgroupList = [];
|
||
$itemsgroupList2 = [];
|
||
|
||
foreach ($itemsgroup as $r){
|
||
if($r["count"]<=$sameordercount && $r["count"]>=$sameordercount2){
|
||
array_push($itemsgroupList,[$r["STOCKS"],$r["POSTCODE"],$r["count"]]);
|
||
}
|
||
}
|
||
$where = [];
|
||
foreach ($itemsgroupList as $r){
|
||
array_push($where,'STOCKS="'.$r[0].'" and POSTCODE="'.$r[1].'"');
|
||
}
|
||
$where = implode(" or ",$where);
|
||
if(!$where){
|
||
$Allitems = [];
|
||
}else{
|
||
$Allitems = $OrderModel->field('ID,STOREID,POSTCODE,ITEMS,STOREID,JDFLAG,GOODSCOUNT,POSTNUM,PROVINCE,STOCKS,STORENAME,ECNOTES')->where(["WAREHOUSEID"=>$WAREHOUSEID,"PLSENDFLAG"=>0,"FLAG"=>0,"POSTFLAG"=>1,"ISLOCK"=>0])->where('GRABNUM IS NULL or GRABNUM=""')->where(["ASSIGNFLAG"=>1])->where($where)->select();
|
||
}
|
||
|
||
|
||
array_push($times,time()-$lastTime);
|
||
$lastTime = time();
|
||
$STOCKSarr = [];
|
||
foreach ($Allitems as $order){
|
||
array_push($STOCKSarr,$order["STOCKS"]);
|
||
}
|
||
$PACKS = $ItemsinfoModel->where("STOCKS","in",$STOCKSarr)->select();
|
||
|
||
array_push($times,time()-$lastTime);
|
||
$lastTime = time();
|
||
foreach ($Allitems as $order){
|
||
$has = false;
|
||
foreach ($PACKS as $PACK){
|
||
if($order["STOCKS"]==$PACK["STOCKS"]){
|
||
$order["PACKID"]=$PACK["PACKID"];
|
||
$has = true;
|
||
}
|
||
}
|
||
if(!$has){
|
||
$order["PACKID"]=0;
|
||
}
|
||
}
|
||
|
||
array_push($times,time()-$lastTime);
|
||
$lastTime = time();
|
||
foreach ($Allitems as $r){
|
||
$r['skucount'] = substr_count($r['ITEMS'],"|");
|
||
}
|
||
foreach($Rules as $k => $r){
|
||
$r['ordercount']=0;
|
||
$tmpordercount = count($Allitems);
|
||
$tmporders = [];
|
||
$tmporders_ex = [
|
||
"1"=>[],
|
||
"2"=>[],
|
||
"3"=>[],
|
||
"4"=>[],
|
||
"5"=>[],
|
||
"6"=>[],
|
||
"7"=>[],
|
||
"8"=>[],
|
||
"9"=>[],
|
||
"10"=>[],
|
||
"11"=>[]
|
||
];
|
||
foreach ($Allitems as $rr){
|
||
|
||
if($r['goodscountgt']!=0 && $rr['GOODSCOUNT']>$r['goodscountgt']){
|
||
$tmpordercount-- ;
|
||
array_push($tmporders_ex['1'],$rr);
|
||
continue;
|
||
}
|
||
if($r['goodscountlt']!=0 && $rr['GOODSCOUNT']<$r['goodscountlt']){
|
||
$tmpordercount-- ;
|
||
array_push($tmporders_ex['2'],$rr);
|
||
continue;
|
||
}
|
||
if($r['skucountlt']!=0 && $rr['skucount']<$r['skucountlt']){
|
||
$tmpordercount-- ;
|
||
array_push($tmporders_ex['3'],$rr);
|
||
continue;
|
||
}
|
||
if($r['skucountgt']!=0 && $rr['skucount']>$r['skucountgt']){
|
||
$tmpordercount-- ;
|
||
array_push($tmporders_ex['4'],$rr);
|
||
continue;
|
||
}
|
||
$exclude_store = explode(",",$r['store_ids']);
|
||
$exclude_store = array_filter($exclude_store);
|
||
if(!in_array($rr['STOREID'],$exclude_store)){
|
||
$tmpordercount-- ;
|
||
array_push($tmporders_ex['5'],$rr);
|
||
continue;
|
||
}
|
||
$exclude_post = explode(",",$r['post_codes']);
|
||
$exclude_post = array_filter($exclude_post);
|
||
if(!in_array($rr['POSTCODE'],$exclude_post)){
|
||
$tmpordercount-- ;
|
||
array_push($tmporders_ex['6'],$rr);
|
||
continue;
|
||
}
|
||
$exclude_province = explode(",",$r['provinces']);
|
||
$exclude_province = array_filter($exclude_province);
|
||
if(!in_array($rr['PROVINCE'],$exclude_province)){
|
||
array_push($tmporders_ex['7'],$rr);
|
||
$tmpordercount-- ;
|
||
continue;
|
||
}
|
||
$exclude_JDFLAG = explode(",",$r['JDFLAGs']);
|
||
//$exclude_JDFLAG = array_filter($exclude_JDFLAG);
|
||
if(!in_array($rr['JDFLAG'],$exclude_JDFLAG)){
|
||
$tmpordercount-- ;
|
||
array_push($tmporders_ex['8'],$rr);
|
||
continue;
|
||
}
|
||
$exclude_JDFLAG = explode(",",$r['ecnotes']);
|
||
if(in_array($rr['ECNOTES'],$exclude_JDFLAG)){
|
||
$tmpordercount-- ;
|
||
array_push($tmporders_ex['11'],$rr);
|
||
continue;
|
||
}
|
||
$skuss = [];
|
||
$skus = explode('|',$rr['ITEMS']);
|
||
$skus = array_filter($skus);
|
||
foreach($skus as $rrr){
|
||
$items = explode(',',$rrr);
|
||
array_push($skuss,$items[0]);
|
||
}
|
||
$rr['stocks'] = $skuss;
|
||
array_push($tmporders,$rr);
|
||
}
|
||
$r['ordercount'] = $tmpordercount;
|
||
$tmpskus = [];
|
||
$tmpskuss = [];
|
||
switch ($r['grabtype']) {
|
||
case 1:
|
||
// 单品单件
|
||
$tmpskuss = $this->generateCombinations1($tmporders,$r['ordercountgt'],$r['group'],$r['posttype']);
|
||
break;
|
||
case 2:
|
||
// 边拣边分
|
||
$tmpskuss = $this->generateCombinations2($tmporders,$r['grabskucountgt'],$r['group'],$r['posttype'],$r['ordercountgt'],true);
|
||
break;
|
||
case 3:
|
||
// 边拣边分
|
||
$tmpskuss = $this->generateCombinations3($tmporders,$r['ordercountgt'],$r['group'],$r['posttype']);
|
||
break;
|
||
case 4:
|
||
// 边拣边分
|
||
$tmpskuss = $this->generateCombinations3($tmporders,$r['ordercountgt'],$r['group'],$r['posttype']);
|
||
break;
|
||
case 5:
|
||
// 团购
|
||
$tmpskuss = $this->generateCombinations5($tmporders,$r['ordercountgt'],$r['group'],$r['posttype']);
|
||
break;
|
||
case 6:
|
||
$tmpskuss = $this->generateCombinations3($tmporders,$r['ordercountgt'],$r['group'],$r['posttype']);
|
||
break;
|
||
}
|
||
//$r['allorders'] = $tmporders;
|
||
$r['ordercount'] = count($tmporders);
|
||
$r['tmpskus'] = $tmpskuss;
|
||
$r['tmporder'] = $tmporders_ex;
|
||
}
|
||
|
||
array_push($times,"纯计算_".(time()-$lastTime));
|
||
$lastTime = time();
|
||
usort($Rules,function($a,$b){
|
||
if(isset($a['tmpskus']['order_count']) && isset($b['tmpskus']['order_count'])){
|
||
return $b['tmpskus']['order_count'] - $a['tmpskus']['order_count'];
|
||
}
|
||
});
|
||
array_push($times,time()-$lastTime);
|
||
$this->redis->lpush("rule_times",json_encode($times));
|
||
print_r(json_encode(["rules"=>$Rules,"count"=>count($Allitems)]));
|
||
}
|
||
public function createGrab_New(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$userID = $params['userid'];
|
||
$ItemsinfoModel = new \app\common\model\stocks\Weightandpack;
|
||
$WAREHOUSEMODEL = new \app\common\model\Warehouse;
|
||
$WorksEMODEL = new \app\common\model\workers\Works;
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$WAREHOUSE = $WAREHOUSEMODEL->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
$WORKDATE = ($WAREHOUSE['workDate'] ?? null);
|
||
$last = $WorksEMODEL->where(["WAREHOUSEID"=>$WAREHOUSEID,"userId"=>$userID,"isSandan"=>0])->where('picks>0 and updatetime is null')->find();
|
||
//print_r($last["grabnum"]);
|
||
if(($last["grabnum"] ?? null)){
|
||
$orders = $OrderModel->where(["GRABNUM"=>($last["grabnum"] ?? null)])->select();
|
||
//print_r($orders);
|
||
if(!$orders){
|
||
$last->save(["updatetime"=>time()]);
|
||
$last = false;
|
||
}
|
||
return json([]);
|
||
}
|
||
$params=$this->request->post();
|
||
$RULEID = $params['RULEID'];
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$RulesModel = $this->RulesModel;
|
||
$Rule = $RulesModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"id"=>$RULEID])->find();
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$itemsgroup = $OrderModel->field('ITEMS,count(*) count,STOREID,POSTCODE,STOCKS')->where(["WAREHOUSEID"=>$WAREHOUSEID,"FLAG"=>0,"PLSENDFLAG"=>0,"POSTFLAG"=>1,"ASSIGNFLAG"=>1,"ISLOCK"=>0])->where('GRABNUM IS NULL or GRABNUM=""')->group("STOCKS,POSTCODE")->select();
|
||
$itemsgroupList = [];
|
||
$sameordercount = ($Rule['sameordercountgt'] ?? null);
|
||
$sameordercount2 = ($Rule['sameordercountlt'] ?? null);
|
||
foreach ($itemsgroup as $r){
|
||
if($r["count"]<=$sameordercount && $r["count"]>=$sameordercount2){
|
||
array_push($itemsgroupList,[$r["STOCKS"],$r["POSTCODE"]]);
|
||
}
|
||
}
|
||
$where = [];
|
||
|
||
foreach ($itemsgroupList as $r){
|
||
array_push($where,'STOCKS="'.$r[0].'" and POSTCODE="'.$r[1].'"');
|
||
}
|
||
$where = implode(" or ",$where);
|
||
if(!$where){
|
||
$Allitems = [];
|
||
}else{
|
||
$Allitems = $OrderModel->field('ID,STOREID,POSTCODE,ITEMS,STOREID,JDFLAG,ID,GOODSCOUNT,PROVINCE,STOCKS,STORENAME')->where(["WAREHOUSEID"=>$WAREHOUSEID,"plSendFlag"=>0,"ASSIGNFLAG"=>1,"POSTFLAG"=>1,"ISLOCK"=>0,"FLAG"=>0])->where('GRABNUM IS NULL or GRABNUM=""')->where($where)->select();
|
||
}
|
||
|
||
|
||
$STOCKSarr = [];
|
||
foreach ($Allitems as $order){
|
||
array_push($STOCKSarr,$order["STOCKS"]);
|
||
}
|
||
$PACKS = $ItemsinfoModel->where("STOCKS","in",$STOCKSarr)->select();
|
||
foreach ($Allitems as $order){
|
||
$has = false;
|
||
foreach ($PACKS as $PACK){
|
||
if($order["STOCKS"]==$PACK["STOCKS"]){
|
||
$order["PACKID"]=$PACK["PACKID"];
|
||
$has = true;
|
||
}
|
||
}
|
||
if(!$has){
|
||
$order["PACKID"]=0;
|
||
}
|
||
}
|
||
foreach ($Allitems as $r){
|
||
$r['skucount'] = substr_count($r['ITEMS'],"|");
|
||
}
|
||
$tmpordercount = count($Allitems);
|
||
$tmporders = [];
|
||
foreach ($Allitems as $rr){
|
||
|
||
if(($Rule['goodscountgt'] ?? null)!=0 && $rr['GOODSCOUNT']>($Rule['goodscountgt'] ?? null)){
|
||
$tmpordercount-- ;
|
||
continue;
|
||
}
|
||
if(($Rule['goodscountlt'] ?? null)!=0 && $rr['GOODSCOUNT']<($Rule['goodscountlt'] ?? null)){
|
||
$tmpordercount-- ;
|
||
continue;
|
||
}
|
||
if(($Rule['skucountlt'] ?? null)!=0 && $rr['skucount']<($Rule['skucountlt'] ?? null)){
|
||
$tmpordercount-- ;
|
||
continue;
|
||
}
|
||
if(($Rule['skucountgt'] ?? null)!=0 && $rr['skucount']>($Rule['skucountgt'] ?? null)){
|
||
$tmpordercount-- ;
|
||
continue;
|
||
}
|
||
$exclude_store = explode(",",($Rule['store_ids'] ?? null));
|
||
$exclude_store = array_filter($exclude_store);
|
||
if(!in_array($rr['STOREID'],$exclude_store)){
|
||
$tmpordercount-- ;
|
||
continue;
|
||
}
|
||
$exclude_post = explode(",",($Rule['post_codes'] ?? null));
|
||
$exclude_post = array_filter($exclude_post);
|
||
if(!in_array($rr['POSTCODE'],$exclude_post)){
|
||
$tmpordercount-- ;
|
||
continue;
|
||
}
|
||
$exclude_province = explode(",",($Rule['provinces'] ?? null));
|
||
$exclude_province = array_filter($exclude_province);
|
||
if(!in_array($rr['PROVINCE'],$exclude_province)){
|
||
$tmpordercount-- ;
|
||
continue;
|
||
}
|
||
$exclude_JDFLAG = explode(",",($Rule['JDFLAGs'] ?? null));
|
||
if(!in_array($rr['JDFLAG'],$exclude_JDFLAG)){
|
||
$tmpordercount-- ;
|
||
continue;
|
||
}
|
||
$skuss = [];
|
||
$skus = explode('|',$rr['ITEMS']);
|
||
$skus = array_filter($skus);
|
||
foreach($skus as $rrr){
|
||
$items = explode(',',$rrr);
|
||
array_push($skuss,$items[0]);
|
||
}
|
||
$rr['stocks'] = $skuss;
|
||
array_push($tmporders,$rr);
|
||
}
|
||
$tmpskus = [];
|
||
$tmpskuss = [];
|
||
$G = "A";
|
||
switch (($Rule['grabtype'] ?? null)) {
|
||
case 1:
|
||
// 单品单件
|
||
$tmpskuss = $this->generateCombinations1($tmporders,($Rule['ordercountgt'] ?? null),($Rule['group'] ?? null),($Rule['posttype'] ?? null),true);
|
||
$G = "D";
|
||
break;
|
||
case 2:
|
||
// 先拣后分
|
||
$tmpskuss = $this->generateCombinations2($tmporders,($Rule['grabskucountgt'] ?? null),($Rule['group'] ?? null),($Rule['posttype'] ?? null),($Rule['ordercountgt'] ?? null),true);
|
||
$G = "F";
|
||
break;
|
||
case 3:
|
||
// 边拣边分
|
||
$tmpskuss = $this->generateCombinations3($tmporders,($Rule['ordercountgt'] ?? null),($Rule['group'] ?? null),($Rule['posttype'] ?? null),true);
|
||
$G = "E";
|
||
break;
|
||
case 4:
|
||
// 边拣边分
|
||
$tmpskuss = $this->generateCombinations3($tmporders,($Rule['ordercountgt'] ?? null),($Rule['group'] ?? null),($Rule['posttype'] ?? null));
|
||
$G = "H";
|
||
break;
|
||
case 5:
|
||
// 边拣边分
|
||
$tmpskuss = $this->generateCombinations5($tmporders,($Rule['ordercountgt'] ?? null),($Rule['group'] ?? null),($Rule['posttype'] ?? null));
|
||
$G = "B";
|
||
break;
|
||
case 6:
|
||
// 大订单
|
||
$tmpskuss = $this->generateCombinations3($tmporders,($Rule['ordercountgt'] ?? null),($Rule['group'] ?? null),($Rule['posttype'] ?? null));
|
||
$G = "S";
|
||
break;
|
||
}
|
||
$list = [];
|
||
foreach($tmpskuss['order'] as $r){
|
||
array_push($list,$r['ID']);
|
||
}
|
||
$list2 = implode(",",$list);
|
||
$data = Wsdl::webservice([$WAREHOUSEID,$userID,$G,$list2],'createGrabOrders');
|
||
if($data){
|
||
$grabnum = '';
|
||
$data2 = $OrderModel->where("ID","in",$list)->where("GRABNUM<>'' and GRABNUM is not null")->find();
|
||
$postnum = ($data2["POSTNUM"] ?? null);
|
||
$grabnum = ($data2["GRABNUM"] ?? null);
|
||
$data3 = $OrderModel->field('ITEMS,sum(GOODSCOUNT) as GOODSCOUNT,count(*) as ordercount,GRABNUM')->where(['GRABNUM'=>$grabnum])->group('GRABNUM')->find();
|
||
$WorksEMODEL = new \app\common\model\workers\Works;
|
||
$insetData = [
|
||
'picks'=>($data3['ordercount'] ?? null),
|
||
'workDate'=>$WORKDATE,
|
||
'grabnum'=>$grabnum,
|
||
'GOODSCOUNT'=>($data3['GOODSCOUNT'] ?? null),
|
||
'isSandan'=>0,
|
||
'WAREHOUSEID'=>$WAREHOUSEID,
|
||
'createtime'=>time(),
|
||
'userId'=>$userID,
|
||
'POSTNUM'=>$postnum,
|
||
'workers'=>'',
|
||
'items'=>'',
|
||
'orders'=>''
|
||
];
|
||
$data4 = $WorksEMODEL->save($insetData);
|
||
return json_encode(["msg"=>$data,"order"=>$list2,"grabnum"=>$postnum,'jilu'=>$data4,'insetData'=>$insetData]);
|
||
}else{
|
||
return json_encode(["msg"=>$data,"order"=>$tmpskuss]);
|
||
}
|
||
}
|
||
public function createGrab(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$userID = $params['userid'];
|
||
$ItemsinfoModel = new \app\common\model\stocks\Weightandpack;
|
||
$WAREHOUSEMODEL = new \app\common\model\Warehouse;
|
||
$WorksEMODEL = new \app\common\model\workers\Works;
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$WAREHOUSE = $WAREHOUSEMODEL->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
$WORKDATE = $WAREHOUSE['workDate']??strtotime('today');
|
||
$last = $WorksEMODEL->where(["WAREHOUSEID"=>$WAREHOUSEID,"userId"=>$userID,"isSandan"=>0])->where('picks>0 and updatetime is null')->find();
|
||
//print_r($last["grabnum"]);
|
||
if(($last["grabnum"] ?? null)){
|
||
$orders = $OrderModel->where(["GRABNUM"=>($last["grabnum"] ?? null)])->select();
|
||
//print_r($orders);
|
||
if(!$orders){
|
||
$last->save(["updatetime"=>time()]);
|
||
$last = false;
|
||
}
|
||
return json([]);
|
||
}
|
||
$params=$this->request->post();
|
||
$RULEID = $params['RULEID'];
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$RulesModel = $this->RulesModel;
|
||
$Rule = $RulesModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"id"=>$RULEID])->find();
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$itemsgroup = $OrderModel->field('ITEMS,count(*) count,STOREID,POSTCODE,STOCKS')->where(["WAREHOUSEID"=>$WAREHOUSEID,"FLAG"=>0,"PLSENDFLAG"=>0,"POSTFLAG"=>1,"ASSIGNFLAG"=>1,"ISLOCK"=>0])->where('GRABNUM IS NULL or GRABNUM=""')->group("STOCKS,POSTCODE")->select();
|
||
$itemsgroupList = [];
|
||
$sameordercount = ($Rule['sameordercountgt'] ?? null);
|
||
$sameordercount2 = ($Rule['sameordercountlt'] ?? null);
|
||
foreach ($itemsgroup as $r){
|
||
if($r["count"]<=$sameordercount && $r["count"]>=$sameordercount2){
|
||
array_push($itemsgroupList,[$r["STOCKS"],$r["POSTCODE"]]);
|
||
}
|
||
}
|
||
$where = [];
|
||
|
||
foreach ($itemsgroupList as $r){
|
||
array_push($where,'STOCKS="'.$r[0].'" and POSTCODE="'.$r[1].'"');
|
||
}
|
||
$where = implode(" or ",$where);
|
||
if(!$where){
|
||
$Allitems = [];
|
||
}else{
|
||
$Allitems = $OrderModel->field('ID,STOREID,POSTCODE,ITEMS,STOREID,JDFLAG,ID,GOODSCOUNT,PROVINCE,STOCKS,STORENAME,ECNOTES')->where(["WAREHOUSEID"=>$WAREHOUSEID,"plSendFlag"=>0,"ASSIGNFLAG"=>1,"POSTFLAG"=>1,"ISLOCK"=>0,"FLAG"=>0])->where('GRABNUM IS NULL or GRABNUM=""')->where($where)->select();
|
||
}
|
||
|
||
|
||
$STOCKSarr = [];
|
||
foreach ($Allitems as $order){
|
||
array_push($STOCKSarr,$order["STOCKS"]);
|
||
}
|
||
$PACKS = $ItemsinfoModel->where("STOCKS","in",$STOCKSarr)->select();
|
||
foreach ($Allitems as $order){
|
||
$has = false;
|
||
foreach ($PACKS as $PACK){
|
||
if($order["STOCKS"]==$PACK["STOCKS"]){
|
||
$order["PACKID"]=$PACK["PACKID"];
|
||
$has = true;
|
||
}
|
||
}
|
||
if(!$has){
|
||
$order["PACKID"]=0;
|
||
}
|
||
}
|
||
foreach ($Allitems as $r){
|
||
$r['skucount'] = substr_count($r['ITEMS'],"|");
|
||
}
|
||
$tmpordercount = count($Allitems);
|
||
$tmporders = [];
|
||
foreach ($Allitems as $rr){
|
||
|
||
if(($Rule['goodscountgt'] ?? null)!=0 && $rr['GOODSCOUNT']>($Rule['goodscountgt'] ?? null)){
|
||
$tmpordercount-- ;
|
||
continue;
|
||
}
|
||
if(($Rule['goodscountlt'] ?? null)!=0 && $rr['GOODSCOUNT']<($Rule['goodscountlt'] ?? null)){
|
||
$tmpordercount-- ;
|
||
continue;
|
||
}
|
||
if(($Rule['skucountlt'] ?? null)!=0 && $rr['skucount']<($Rule['skucountlt'] ?? null)){
|
||
$tmpordercount-- ;
|
||
continue;
|
||
}
|
||
if(($Rule['skucountgt'] ?? null)!=0 && $rr['skucount']>($Rule['skucountgt'] ?? null)){
|
||
$tmpordercount-- ;
|
||
continue;
|
||
}
|
||
$exclude_store = explode(",",($Rule['store_ids'] ?? null));
|
||
$exclude_store = array_filter($exclude_store);
|
||
if(!in_array($rr['STOREID'],$exclude_store)){
|
||
$tmpordercount-- ;
|
||
continue;
|
||
}
|
||
$exclude_post = explode(",",($Rule['post_codes'] ?? null));
|
||
$exclude_post = array_filter($exclude_post);
|
||
if(!in_array($rr['POSTCODE'],$exclude_post)){
|
||
$tmpordercount-- ;
|
||
continue;
|
||
}
|
||
$exclude_province = explode(",",($Rule['provinces'] ?? null));
|
||
$exclude_province = array_filter($exclude_province);
|
||
if(!in_array($rr['PROVINCE'],$exclude_province)){
|
||
$tmpordercount-- ;
|
||
continue;
|
||
}
|
||
|
||
$exclude_JDFLAG = explode(",",($Rule['ecnotes'] ?? null));
|
||
if(in_array($rr['ECNOTES'],$exclude_JDFLAG)){
|
||
$tmpordercount-- ;
|
||
continue;
|
||
}
|
||
$exclude_JDFLAG = explode(",",($Rule['JDFLAGs'] ?? null));
|
||
if(!in_array($rr['JDFLAG'],$exclude_JDFLAG)){
|
||
$tmpordercount-- ;
|
||
continue;
|
||
}
|
||
$skuss = [];
|
||
$skus = explode('|',$rr['ITEMS']);
|
||
$skus = array_filter($skus);
|
||
foreach($skus as $rrr){
|
||
$items = explode(',',$rrr);
|
||
array_push($skuss,$items[0]);
|
||
}
|
||
$rr['stocks'] = $skuss;
|
||
array_push($tmporders,$rr);
|
||
}
|
||
$tmpskus = [];
|
||
$tmpskuss = [];
|
||
$G = "A";
|
||
switch (($Rule['grabtype'] ?? null)) {
|
||
case 1:
|
||
// 单品单件
|
||
$tmpskuss = $this->generateCombinations1($tmporders,($Rule['ordercountgt'] ?? null),($Rule['group'] ?? null),($Rule['posttype'] ?? null),true);
|
||
$G = "D";
|
||
break;
|
||
case 2:
|
||
// 先拣后分
|
||
$tmpskuss = $this->generateCombinations2($tmporders,($Rule['grabskucountgt'] ?? null),($Rule['group'] ?? null),($Rule['posttype'] ?? null),($Rule['ordercountgt'] ?? null),true);
|
||
$G = "F";
|
||
break;
|
||
case 3:
|
||
// 边拣边分
|
||
$tmpskuss = $this->generateCombinations3($tmporders,($Rule['ordercountgt'] ?? null),($Rule['group'] ?? null),($Rule['posttype'] ?? null),true);
|
||
$G = "E";
|
||
break;
|
||
case 4:
|
||
// 边拣边分
|
||
$tmpskuss = $this->generateCombinations3($tmporders,($Rule['ordercountgt'] ?? null),($Rule['group'] ?? null),($Rule['posttype'] ?? null));
|
||
$G = "H";
|
||
break;
|
||
case 5:
|
||
// 边拣边分
|
||
$tmpskuss = $this->generateCombinations5($tmporders,($Rule['ordercountgt'] ?? null),($Rule['group'] ?? null),($Rule['posttype'] ?? null));
|
||
$G = "B";
|
||
break;
|
||
case 6:
|
||
// 大订单
|
||
$tmpskuss = $this->generateCombinations3($tmporders,($Rule['ordercountgt'] ?? null),($Rule['group'] ?? null),($Rule['posttype'] ?? null));
|
||
$G = "S";
|
||
break;
|
||
}
|
||
$list = [];
|
||
foreach($tmpskuss['order'] as $r){
|
||
array_push($list,$r['ID']);
|
||
}
|
||
$list2 = implode(",",$list);
|
||
$data = Wsdl::webservice([$WAREHOUSEID,$userID,$G,$list2],'createGrabOrders');
|
||
if($data){
|
||
$grabnum = '';
|
||
$data2 = $OrderModel->where("ID","in",$list)->where("GRABNUM<>'' and GRABNUM is not null")->find();
|
||
$postnum = ($data2["POSTNUM"] ?? null);
|
||
$grabnum = ($data2["GRABNUM"] ?? null);
|
||
$data3 = $OrderModel->field('ITEMS,sum(GOODSCOUNT) as GOODSCOUNT,count(*) as ordercount,GRABNUM')->where(['GRABNUM'=>$grabnum])->group('GRABNUM')->find();
|
||
$WorksEMODEL = new \app\common\model\workers\Works;
|
||
$insetData = [
|
||
'picks'=>($data3['ordercount'] ?? null),
|
||
'workDate'=>$WORKDATE,
|
||
'grabnum'=>$grabnum,
|
||
'GOODSCOUNT'=>($data3['GOODSCOUNT'] ?? null),
|
||
'isSandan'=>0,
|
||
'WAREHOUSEID'=>$WAREHOUSEID,
|
||
'createtime'=>time(),
|
||
'userId'=>$userID,
|
||
'POSTNUM'=>$postnum,
|
||
'workers'=>'',
|
||
'items'=>'',
|
||
'orders'=>''
|
||
];
|
||
$data4 = $WorksEMODEL->save($insetData);
|
||
return json_encode(["msg"=>$data,"order"=>$list2,"grabnum"=>$postnum,'jilu'=>$data4,'insetData'=>$insetData]);
|
||
}else{
|
||
return json_encode(["msg"=>$data,"order"=>$tmpskuss]);
|
||
}
|
||
}
|
||
public function create_work(){
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$grabnum = "D887379";
|
||
$WAREHOUSEID=5400;
|
||
$userID=0;
|
||
$postnum="434910442894357";
|
||
$data3 = $OrderModel->field('ITEMS,sum(GOODSCOUNT) as GOODSCOUNT,count(*) as ordercount,GRABNUM')->where(['GRABNUM'=>$grabnum])->group('GRABNUM')->find();
|
||
$WorksEMODEL = new \app\common\model\workers\Works;
|
||
$insetData = [
|
||
'picks'=>($data3['ordercount'] ?? null),
|
||
'workDate'=>0,
|
||
'grabnum'=>$grabnum,
|
||
'GOODSCOUNT'=>($data3['GOODSCOUNT'] ?? null),
|
||
'isSandan'=>0,
|
||
'WAREHOUSEID'=>$WAREHOUSEID,
|
||
'createtime'=>time(),
|
||
'userId'=>$userID,
|
||
'POSTNUM'=>$postnum,
|
||
'workers'=>'',
|
||
'items'=>'',
|
||
'orders'=>''
|
||
];
|
||
$data4 = $WorksEMODEL->save($insetData);
|
||
}
|
||
public function get_pick_data(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$GRABNUM = $params['GRABNUM'];
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
$orders = $orderModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"GRABNUM"=>$GRABNUM,"PLSENDFLAG"=>0,"FLAG"=>0])->select();;
|
||
$ids = [];
|
||
foreach($orders as $r){
|
||
array_push($ids,[$r['ID'],$r['POSTNUM'],$r["POSTNAME"]]);
|
||
}
|
||
$orderModel = new \app\common\model\wms\Picking;
|
||
$orders_pick_arr = [];
|
||
foreach ($ids as $r){
|
||
$STOCKIDs = $orderModel->field('COUNT,DETAILS,SPACEID,STOCKID')->where(["WMSORDERID"=>$r[0]])->with(["space","stock"])->select();
|
||
$STOCKS = [];
|
||
foreach($STOCKIDs as $rrr){
|
||
$hasSKU = false;
|
||
foreach ($STOCKS as $k => $rr){
|
||
if($rr['STOCKID']==$rrr['STOCKID']){
|
||
$rr['COUNT']+=$rrr['COUNT'];
|
||
$hasSKU = true;
|
||
}
|
||
}
|
||
if(!$hasSKU){
|
||
array_push($STOCKS,$rrr);
|
||
}
|
||
}
|
||
usort($STOCKS,function($a,$b){
|
||
return $a['space']['IDX'] - $b['space']['IDX'];
|
||
});
|
||
array_push($orders_pick_arr,["datas"=>$STOCKS,"POSTNUM"=>$r[1],"POSTNAME"=>$r[2]]);
|
||
}
|
||
$printerdata = [];
|
||
foreach ($orders_pick_arr as $r){
|
||
$stocks = [];
|
||
$goods_count = 0;
|
||
foreach ($r["datas"] as $k => $rr){
|
||
$line = $k+1;
|
||
$goods_count+=$rr['COUNT'];
|
||
$goodsModel = new \app\common\model\wms\Goods;
|
||
$goods = $goodsModel->where(["GOODSID"=>$rr['stock']['GOODSID']])->find();
|
||
$goodsName = ($goods["NAME"] ?? null);
|
||
array_push($stocks,"{$line}、{$rr['space']['CUSTOMNUM']} {$goodsName}-{$rr['stock']['BARCODE']} 【{$rr['COUNT']}】");
|
||
}
|
||
$tmp = [
|
||
"tmp"=>implode("\n",$stocks),
|
||
"POSTNUM"=>$r["POSTNUM"],
|
||
"POSTNUM1"=>$r["POSTNAME"]."|".$r["POSTNUM"],
|
||
"count"=>"商品总数:".$goods_count
|
||
];
|
||
$printerdata_item = [
|
||
"tempStandardTemplate"=>"https://ye4s.wms.gztbyc.com/picking.xml",
|
||
"tempPrintdata"=>json_encode($tmp),
|
||
"tempZdyTemplate"=>null,
|
||
"tempZdy"=>"",
|
||
"postNum"=>$r["POSTNUM"]
|
||
];
|
||
array_push($printerdata,$printerdata_item);
|
||
}
|
||
|
||
$printer_data = [
|
||
["printData"=>json_encode($printerdata),"dayin"=>"菜鸟","serialNum"=>"pickinginfo_{$GRABNUM}"]
|
||
];
|
||
return json($printer_data);
|
||
}
|
||
public function createGrab2(){
|
||
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
try{
|
||
Db::startTrans();
|
||
$LockerModel = new \app\common\model\Locker;
|
||
$row = $LockerModel->where(['WAREHOUSEID'=>$WAREHOUSEID])->lock(true)->find();
|
||
$MergeModel = new \app\common\model\tuan\Merge;
|
||
$userID = $params['userid'];
|
||
$data2 = $MergeModel->where(['userid'=>$userID,'status'=>1])->find();
|
||
if($data2){
|
||
return json(["status"=>0]);
|
||
}
|
||
$WAREHOUSEMODEL = new \app\common\model\Warehouse;
|
||
$WorksEMODEL = new \app\common\model\workers\Works;
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$WAREHOUSE = $WAREHOUSEMODEL->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
$WORKDATE = ($WAREHOUSE['workDate'] ?? null);
|
||
$last = $WorksEMODEL->where(["WAREHOUSEID"=>$WAREHOUSEID,"userId"=>$userID,"isSandan"=>0])->where('picks>0 and updatetime is null')->find();
|
||
//print_r($last["grabnum"]);
|
||
if(($last["grabnum"] ?? null)){
|
||
$orders = $OrderModel->where(["GRABNUM"=>($last["grabnum"] ?? null)])->select();
|
||
//print_r($orders);
|
||
if(!$orders){
|
||
$last->save(["updatetime"=>time()]);
|
||
$last = false;
|
||
}
|
||
return json([]);
|
||
}
|
||
$params=$this->request->post();
|
||
$RULEID = $params['RULEID'];
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$RulesModel = $this->RulesModel;
|
||
$Rule = $RulesModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"id"=>$RULEID])->find();
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$itemsgroup = $OrderModel->field('ITEMS,count(*) count,STOREID,POSTCODE,STOCKS')->where(["WAREHOUSEID"=>$WAREHOUSEID,"FLAG"=>0,"PLSENDFLAG"=>0,"POSTFLAG"=>1,"ASSIGNFLAG"=>1,"ISLOCK"=>0])->where('GRABNUM IS NULL or GRABNUM=""')->group("STOCKS,POSTCODE")->select();
|
||
$itemsgroupList = [];
|
||
$sameordercount = ($Rule['sameordercountgt'] ?? null);
|
||
$sameordercount2 = ($Rule['sameordercountlt'] ?? null);
|
||
foreach ($itemsgroup as $r){
|
||
if($r["count"]<=$sameordercount && $r["count"]>=$sameordercount2){
|
||
array_push($itemsgroupList,[$r["STOCKS"],$r["POSTCODE"],$r["count"]]);
|
||
}
|
||
}
|
||
$where = [];
|
||
foreach ($itemsgroupList as $r){
|
||
array_push($where,'STOCKS="'.$r[0].'" and POSTCODE="'.$r[1].'"');
|
||
}
|
||
$where = implode(" or ",$where);
|
||
if(!$where){
|
||
$Allitems = [];
|
||
}else{
|
||
$Allitems = $OrderModel->field('ID,STOREID,POSTCODE,ITEMS,STOREID,JDFLAG,GOODSCOUNT,POSTNUM,PROVINCE,STOCKS,STORENAME,ECNOTES')->where(["WAREHOUSEID"=>$WAREHOUSEID,"plSendFlag"=>0,"FLAG"=>0,"POSTFLAG"=>1,"ISLOCK"=>0])->where('GRABNUM IS NULL or GRABNUM=""')->where(["ASSIGNFLAG"=>1])->where($where)->select();
|
||
}
|
||
|
||
// 按订单ID去重:避免同一订单被重复计入,导致 ordercount 虚高(显示N单/抓取N-1单)
|
||
$__dedup = [];
|
||
$__seen = [];
|
||
foreach ($Allitems as $__it){
|
||
$__oid = $__it['ID'];
|
||
if (isset($__seen[$__oid])) continue;
|
||
$__seen[$__oid] = true;
|
||
$__dedup[] = $__it;
|
||
}
|
||
$Allitems = $__dedup;
|
||
foreach ($Allitems as $r){
|
||
$r['skucount'] = substr_count($r['ITEMS'],"|");
|
||
}
|
||
$tmpordercount = count($Allitems);
|
||
$tmporders = [];
|
||
$tmporders_ex = [
|
||
"1"=>[],
|
||
"2"=>[],
|
||
"3"=>[],
|
||
"4"=>[],
|
||
"5"=>[],
|
||
"6"=>[],
|
||
"7"=>[],
|
||
"8"=>[],
|
||
"9"=>[],
|
||
"10"=>[]
|
||
];
|
||
foreach ($Allitems as $rr){
|
||
|
||
if(($Rule['goodscountgt'] ?? null)!=0 && $rr['GOODSCOUNT']>($Rule['goodscountgt'] ?? null)){
|
||
$tmpordercount-- ;
|
||
array_push($tmporders_ex['1'],$rr);
|
||
continue;
|
||
}
|
||
if(($Rule['goodscountlt'] ?? null)!=0 && $rr['GOODSCOUNT']<($Rule['goodscountlt'] ?? null)){
|
||
$tmpordercount-- ;
|
||
array_push($tmporders_ex['2'],$rr);
|
||
continue;
|
||
}
|
||
if(($Rule['skucountlt'] ?? null)!=0 && $rr['skucount']<($Rule['skucountlt'] ?? null)){
|
||
$tmpordercount-- ;
|
||
array_push($tmporders_ex['3'],$rr);
|
||
continue;
|
||
}
|
||
if(($Rule['skucountgt'] ?? null)!=0 && $rr['skucount']>($Rule['skucountgt'] ?? null)){
|
||
$tmpordercount-- ;
|
||
array_push($tmporders_ex['4'],$rr);
|
||
continue;
|
||
}
|
||
$exclude_store = explode(",",($Rule['store_ids'] ?? null));
|
||
$exclude_store = array_filter($exclude_store);
|
||
if(!in_array($rr['STOREID'],$exclude_store)){
|
||
$tmpordercount-- ;
|
||
array_push($tmporders_ex['5'],$rr);
|
||
continue;
|
||
}
|
||
$exclude_post = explode(",",($Rule['post_codes'] ?? null));
|
||
$exclude_post = array_filter($exclude_post);
|
||
if(!in_array($rr['POSTCODE'],$exclude_post)){
|
||
$tmpordercount-- ;
|
||
array_push($tmporders_ex['6'],$rr);
|
||
continue;
|
||
}
|
||
$exclude_province = explode(",",($Rule['provinces'] ?? null));
|
||
$exclude_province = array_filter($exclude_province);
|
||
if(!in_array($rr['PROVINCE'],$exclude_province)){
|
||
array_push($tmporders_ex['7'],$rr);
|
||
$tmpordercount-- ;
|
||
continue;
|
||
}
|
||
|
||
$exclude_JDFLAG = explode(",",($Rule['ecnotes'] ?? null));
|
||
if(in_array($rr['ECNOTES'],$exclude_JDFLAG)){
|
||
$tmpordercount-- ;
|
||
continue;
|
||
}
|
||
$exclude_JDFLAG = explode(",",($Rule['JDFLAGs'] ?? null));
|
||
//$exclude_JDFLAG = array_filter($exclude_JDFLAG);
|
||
if(!in_array($rr['JDFLAG'],$exclude_JDFLAG)){
|
||
$tmpordercount-- ;
|
||
array_push($tmporders_ex['8'],$rr);
|
||
continue;
|
||
}
|
||
$skuss = [];
|
||
$skus = explode('|',$rr['ITEMS']);
|
||
$skus = array_filter($skus);
|
||
foreach($skus as $rrr){
|
||
$items = explode(',',$rrr);
|
||
array_push($skuss,$items[0]);
|
||
}
|
||
$rr['stocks'] = $skuss;
|
||
array_push($tmporders,$rr);
|
||
}
|
||
$tmpskus = [];
|
||
$tmpskuss = [];
|
||
$G = "A";
|
||
switch (($Rule['grabtype'] ?? null)) {
|
||
case 1:
|
||
// 单品单件
|
||
$tmpskuss = $this->generateCombinations1($tmporders,($Rule['ordercountgt'] ?? null),($Rule['group'] ?? null),($Rule['posttype'] ?? null),true);
|
||
$G = "D";
|
||
break;
|
||
case 2:
|
||
// 先拣后分
|
||
$tmpskuss = $this->generateCombinations2($tmporders,($Rule['grabskucountgt'] ?? null),($Rule['group'] ?? null),($Rule['posttype'] ?? null),($Rule['ordercountgt'] ?? null),true);
|
||
$G = "F";
|
||
break;
|
||
case 3:
|
||
// 边拣边分
|
||
$tmpskuss = $this->generateCombinations3($tmporders,($Rule['ordercountgt'] ?? null),($Rule['group'] ?? null),($Rule['posttype'] ?? null),true);
|
||
$G = "E";
|
||
break;
|
||
case 4:
|
||
// 边拣边分
|
||
$tmpskuss = $this->generateCombinations3($tmporders,($Rule['ordercountgt'] ?? null),($Rule['group'] ?? null),($Rule['posttype'] ?? null));
|
||
$G = "H";
|
||
break;
|
||
case 5:
|
||
// 边拣边分
|
||
$tmpskuss = $this->generateCombinations5($tmporders,($Rule['ordercountgt'] ?? null),($Rule['group'] ?? null),($Rule['posttype'] ?? null));
|
||
$G = "B";
|
||
break;
|
||
}
|
||
if($tmpskuss['grbscount']==0){
|
||
return json(["status"=>1]);
|
||
}
|
||
$myGrabs = [];
|
||
$datass = [];
|
||
foreach($tmpskuss['order'] as $rr){
|
||
$list = [];
|
||
foreach ($rr['list'] as $r){
|
||
array_push($list,$r['ID']);
|
||
}
|
||
$list = implode(",",$list);
|
||
$data = Wsdl::webservice([$WAREHOUSEID,$userID,$G,$list],'createGrabOrders');
|
||
if($data){
|
||
array_push($myGrabs,$data);
|
||
Wsdl::webservice([$WAREHOUSEID,$userID,$data,0],'doWmsOrderGrabNum');
|
||
array_push($datass,["grabnum"=>$data,"list"=>$list]);
|
||
}
|
||
}
|
||
Db::commit();
|
||
$GRABS = implode(",",$myGrabs);
|
||
if(count($myGrabs)>0){
|
||
$datass = json_encode($datass);
|
||
$MergeModel->save(['userid'=>$userID,'createtime'=>time(),'status'=>1,'GRABS'=>$GRABS,'WAREHOUSEID'=>$WAREHOUSEID,'infos'=>$datass]);
|
||
$mergeId = $MergeModel->id;
|
||
if($mergeId){
|
||
$insertData = [];
|
||
foreach ($myGrabs as $pos => $grab) {
|
||
$insertData[] = ['merge_id' => $mergeId, 'grabnum' => $grab, 'position' => $pos];
|
||
}
|
||
Db::table('ye4s_tuan_merge_grabnum')->insertAll($insertData);
|
||
}
|
||
}
|
||
return json(['status'=>2]);
|
||
}catch(\Exception $e){
|
||
echo $e;
|
||
Db::rollback();
|
||
}
|
||
|
||
}
|
||
|
||
|
||
public function createPostNum(){
|
||
$WAREHOUSEMODEL = new \app\common\model\Warehouse;
|
||
$WAREHOUSEID = request()->get('warehouse');
|
||
$WAREHOUSE = $WAREHOUSEMODEL->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
$exclude = explode("|",($WAREHOUSE["exclude_express"] ?? null));
|
||
$where = [];
|
||
foreach ($exclude as $r){
|
||
array_push($where,'LEAVEMESSAGE not like "%'.$r.'%"');
|
||
}
|
||
$where_str = implode(" and ",$where);
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$res = $OrderModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where('POSTNUM="" or POSTNUM is NULL')->where($where_str)->where("STOREID<>24701 and STOREID<>16101")->where("POSTCODE<>'p18' and POSTCODE<>'p30'")->select();
|
||
$ids = [];
|
||
foreach ($res as $r){
|
||
array_push($ids,$r['ID']);
|
||
}
|
||
$ids = implode(",",$ids);
|
||
$data = Wsdl::webservice([$WAREHOUSEID,31201,$ids],'createPostNum');
|
||
return json($data);
|
||
}
|
||
public function getcar(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$car = isset($params['car'])?$params['car']:'';
|
||
if(!$car){
|
||
return json([]);
|
||
}
|
||
$WorksModel = new \app\common\model\workers\Works;
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$work = $WorksModel->where(["carid"=>$car,"WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
if($work){
|
||
$data = $OrderModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"GRABNUM"=>$work["grabnum"],"PRINTTIMES"=>0])->select();
|
||
if(!$data){
|
||
$work->save(["carid"=>""]);
|
||
$work = null;
|
||
}
|
||
}
|
||
return json($work);
|
||
}
|
||
public function getcar2(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$car = isset($params['car'])?$params['car']:'';
|
||
if(!$car){
|
||
return json([]);
|
||
}
|
||
$MergeModel = new \app\common\model\tuan\Merge;
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$UserModel = new \app\common\model\wms\User;
|
||
$work = $MergeModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where('carid', $car)->find();
|
||
if(!$work){
|
||
$grabRow = Db::table('ye4s_tuan_merge_grabnum')->where('grabnum', $car)->find();
|
||
if($grabRow){
|
||
$work = $MergeModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where('id', $grabRow['merge_id'])->find();
|
||
}
|
||
}
|
||
|
||
$data = [];
|
||
if($work){
|
||
$GRABS = explode(",",$work['GRABS']);
|
||
$data = $OrderModel->field('POSTNUM,GRABNUM,PRINTTIMES')->where(["WAREHOUSEID"=>$WAREHOUSEID,"PLSENDFLAG"=>0])->where("GRABNUM","in",$GRABS)->group("GRABNUM")->select();
|
||
$data2 = $OrderModel->field('POSTNUM,GRABNUM,PRINTTIMES')->where(["WAREHOUSEID"=>$WAREHOUSEID,"PRINTTIMES"=>0])->where("GRABNUM","in",$GRABS)->group("GRABNUM")->select();
|
||
$data3 = $OrderModel->field('POSTNUM,GRABNUM,PRINTTIMES')->where(["WAREHOUSEID"=>$WAREHOUSEID,"PICKINGFLAG"=>0])->where("GRABNUM","in",$GRABS)->group("GRABNUM")->select();
|
||
foreach ($GRABS as $k => $r){
|
||
foreach ($data as $rr){
|
||
if($rr["GRABNUM"]==$r){
|
||
$rr['index']=$k+1;
|
||
}
|
||
}
|
||
}
|
||
if($data3){
|
||
$user = $UserModel->where(["userID"=>$work["userid"]])->find();
|
||
$username = ($user["username"] ?? null);
|
||
foreach ($data3 as $r){
|
||
Wsdl::webservice([$WAREHOUSEID,$r['GRABNUM'],$username],'confirmPick');
|
||
$requsetData = [
|
||
'userId'=>$work["userid"],
|
||
'POSTNUM'=>$r["POSTNUM"],
|
||
'method'=>'picks'
|
||
];
|
||
// 端口故障转移:优先 7071/7072 保活端口,7001 作兜底
|
||
$res = '';
|
||
foreach (['7071','7072','7001'] as $port) {
|
||
$url = "http://127.0.0.1:{$port}/test";
|
||
$res = Http::post($url,$requsetData);
|
||
if ($res !== '') {
|
||
break;
|
||
}
|
||
}
|
||
if ($res === '') {
|
||
\think\Log::error("[getcar2] picks 通知发送失败,所有端口均不可用: " . json_encode($requsetData, JSON_UNESCAPED_UNICODE));
|
||
}
|
||
}
|
||
}
|
||
if(!$data2){
|
||
$work->save(["carid"=>null]);
|
||
}
|
||
}
|
||
usort($data,function($a,$b){
|
||
return intval($a['index'])-intval($b['index']);
|
||
});
|
||
return json($data);
|
||
}
|
||
public function clearcar2(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$MergeModel = new \app\common\model\tuan\Merge;
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$work = $MergeModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("carid<>'' and carid is not null")->select();
|
||
$grabnums = [];
|
||
foreach ($work as $r){
|
||
$grabs = explode(',',$r['GRABS']);
|
||
$orders = $OrderModel->field('GRABNUM,POSTNUM')->where(['WAREHOUSEID'=>$WAREHOUSEID,'PRINTTIMES'=>0,'PLSENDFLAG'=>0])->where('GRABNUM','in',$grabs)->group('GRABNUM')->select();
|
||
if(!$orders){
|
||
$r->save(["carid"=>null]);
|
||
}
|
||
}
|
||
return json([]);
|
||
}
|
||
public function clearcar(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$WorksModel = new \app\common\model\workers\Works;
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$work = $WorksModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("carid<>'' and carid is not null")->select();
|
||
$grabnums = [];
|
||
foreach ($work as $r){
|
||
array_push($grabnums,$r['grabnum']);
|
||
}
|
||
$orders = $OrderModel->field('SUM(CASE WHEN PLSENDFLAG=0 and PRINTTIMES=0 THEN 1 ELSE 0 END) AS wfh,GRABNUM')->where(['WAREHOUSEID'=>$WAREHOUSEID])->where('GRABNUM','in',$grabnums)->group('GRABNUM')->select();
|
||
foreach ($orders as $r){
|
||
if(intval($r['wfh'])==0){
|
||
echo $r['GRABNUM'];
|
||
foreach ($work as $rr){
|
||
if($rr["grabnum"]==$r['GRABNUM']){
|
||
$rr->save(["carid"=>'']);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return json($work);
|
||
}
|
||
/**
|
||
* 边拣边分算法 - 根据仓库库位和订单属性对订单进行分组优化(仅添加日志)
|
||
*
|
||
* @param array $tmporders 原始订单数组
|
||
* @param int $len 返回的最大订单数量限制,0表示不限制
|
||
* @param int $group 是否按店铺分组:1=是,其他=否
|
||
* @param mixed $posttype 邮编筛选类型,1=筛选最多订单的邮编
|
||
* @param bool $rtorder 是否返回订单详情
|
||
* @return array 返回包含SKU数量、订单数量和订单详情的数组
|
||
*/
|
||
/**
|
||
* 边拣边分算法 - 优化版本
|
||
*/
|
||
private function generateCombinations3($tmporders, $len = 20, $group = 1, $posttype, $rtorder = false){
|
||
// 开始计时
|
||
$startTime = microtime(true);
|
||
$logId = date('YmdHis') . '_' . mt_rand(1000, 9999);
|
||
|
||
$tmpstores = [];
|
||
$tmppostcodes = [];
|
||
$orders_ids = [];
|
||
foreach ($tmporders as $r){
|
||
array_push($orders_ids,$r["ID"]);
|
||
}
|
||
|
||
// ========== 优化点1:提前准备数据 ==========
|
||
$stageStart = microtime(true);
|
||
$PickingModel = new \app\common\model\wms\Picking;
|
||
$STOCKIDs = $PickingModel->field('COUNT,DETAILS,SPACEID,STOCKID')->where("WMSORDERID","in",$orders_ids)->with(["space","stock"])->select();
|
||
|
||
$queryTime = round((microtime(true) - $stageStart) * 1000, 2);
|
||
// ========== 优化点2:重构库位特征计算 ==========
|
||
$stageStart = microtime(true);
|
||
|
||
// 1. 建立STOCKID到库位信息的映射(快速查找)
|
||
$stockSpaceMap = [];
|
||
foreach ($STOCKIDs as $rr) {
|
||
$stockId = $rr["STOCKID"];
|
||
if (!isset($stockSpaceMap[$stockId])) {
|
||
$stockSpaceMap[$stockId] = [
|
||
'space_letter' => mb_substr($rr["space"]["CUSTOMNUM"] ?? '', 0, 1),
|
||
'space_idx' => $rr["space"]["IDX"] ?? 0,
|
||
'space_code' => $rr["space"]["CODE"] ?? ''
|
||
];
|
||
}
|
||
}
|
||
|
||
// 2. 使用哈希集合优化查找
|
||
$multiSpaceOrders = 0;
|
||
foreach($tmporders as &$r){
|
||
$space = [];
|
||
$space2 = [];
|
||
$space3 = [];
|
||
|
||
// 优化:将$r['stocks']转为哈希集合用于快速查找
|
||
$stockSet = array_flip($r['stocks']); // 键值互换,O(1)查找
|
||
|
||
foreach ($stockSpaceMap as $stockId => $spaceInfo) {
|
||
if (isset($stockSet[$stockId])) { // O(1)查找
|
||
$space[] = $spaceInfo['space_letter'];
|
||
$space2[] = $spaceInfo['space_idx'];
|
||
$space3[] = $spaceInfo['space_code'];
|
||
}
|
||
}
|
||
|
||
if (!empty($space)) {
|
||
$space = array_unique($space);
|
||
$space2 = array_unique($space2);
|
||
$space3 = array_unique($space3);
|
||
|
||
asort($space);
|
||
rsort($space2);
|
||
$space2 = array_values($space2);
|
||
|
||
$r["SPACE"] = implode("",$space);
|
||
$r["SPACEINDEX"] = $space2[0] ?? 0;
|
||
|
||
if(count($space3) > 1){
|
||
$r["SPACEINDEX"] = $space2[0] * 10000;
|
||
$multiSpaceOrders++;
|
||
}
|
||
} else {
|
||
$r["SPACE"] = "";
|
||
$r["SPACEINDEX"] = 0;
|
||
}
|
||
}
|
||
unset($r);
|
||
|
||
$calcTime = round((microtime(true) - $stageStart) * 1000, 2);
|
||
// ========== 优化点3:重构包裹统计 ==========
|
||
$stageStart = microtime(true);
|
||
$packs = [];
|
||
$packCountMap = [];
|
||
|
||
// 使用数组键值统计,避免嵌套循环
|
||
foreach ($tmporders as $r) {
|
||
$packId = $r["PACKID"];
|
||
if (isset($packCountMap[$packId])) {
|
||
$packCountMap[$packId]++;
|
||
} else {
|
||
$packCountMap[$packId] = 1;
|
||
}
|
||
}
|
||
|
||
// 转换为packs数组格式
|
||
foreach ($packCountMap as $packId => $count) {
|
||
$packs[] = ["PACKID" => $packId, "COUNT" => $count];
|
||
}
|
||
|
||
// 为订单添加packindex
|
||
foreach ($tmporders as &$r) {
|
||
$r["packindex"] = $packCountMap[$r["PACKID"]] ?? 0;
|
||
}
|
||
unset($r);
|
||
|
||
$packTime = round((microtime(true) - $stageStart) * 1000, 2);
|
||
// ========== 后续代码保持不变,但速度会提升 ==========
|
||
$stageStart = microtime(true);
|
||
usort($tmporders,function($a,$b){
|
||
return $a['SPACEINDEX'] <=> $b['SPACEINDEX'];
|
||
});
|
||
$sort1Time = round((microtime(true) - $stageStart) * 1000, 2);
|
||
if(count($tmporders)>20){
|
||
$this->redis->set("tmporders",json_encode($tmporders));
|
||
}
|
||
|
||
$stageStart = microtime(true);
|
||
$spaces= [];
|
||
foreach($tmporders as $r){
|
||
$spaceKey = $r['SPACE'];
|
||
if(!isset($spaces[$spaceKey])){
|
||
$spaces[$spaceKey] = [$r];
|
||
}else{
|
||
$spaces[$spaceKey][] = $r;
|
||
}
|
||
}
|
||
usort($spaces,function($a,$b){
|
||
return count($b)-count($a);
|
||
});
|
||
$tmporders = [];
|
||
foreach ($spaces as $r){
|
||
foreach ($r as $rr){
|
||
array_push($tmporders,$rr);
|
||
}
|
||
}
|
||
$groupTime = round((microtime(true) - $stageStart) * 1000, 2);
|
||
$stageStart = microtime(true);
|
||
foreach ($tmporders as $r){
|
||
$postcode = $r['POSTCODE'];
|
||
if(!isset($tmppostcodes[$postcode])){
|
||
$tmppostcodes[$postcode] = ["POSTCODE"=>$postcode,"ordercount"=>1];
|
||
}else{
|
||
$tmppostcodes[$postcode]['ordercount'] ++;
|
||
}
|
||
}
|
||
usort($tmppostcodes,function($a,$b){
|
||
return $b["ordercount"]-$a["ordercount"];
|
||
});
|
||
$POSTCODE = $posttype==1 && isset($tmppostcodes[0]['POSTCODE'])?$tmppostcodes[0]['POSTCODE']:-1;
|
||
if($POSTCODE!=-1){
|
||
$tmporders = array_values(array_filter($tmporders, function($r) use ($POSTCODE) {
|
||
return $r['POSTCODE'] == $POSTCODE;
|
||
}));
|
||
}
|
||
|
||
$postcodeTime = round((microtime(true) - $stageStart) * 1000, 2);
|
||
$stageStart = microtime(true);
|
||
foreach ($tmporders as $r){
|
||
$storeId = $r['STOREID'];
|
||
if(!isset($tmpstores[$storeId])){
|
||
$tmpstores[$storeId] = ["STOREID"=>$storeId,"ordercount"=>1];
|
||
}else{
|
||
$tmpstores[$storeId]['ordercount'] ++;
|
||
}
|
||
}
|
||
usort($tmpstores,function($a,$b){
|
||
return $b["ordercount"]-$a["ordercount"];
|
||
});
|
||
$STOREID = $group==1 && isset($tmpstores[0]['STOREID'])?$tmpstores[0]['STOREID']:-1;
|
||
if($STOREID!=-1){
|
||
$tmporders = array_values(array_filter($tmporders, function($r) use ($STOREID) {
|
||
return $r['STOREID'] == $STOREID;
|
||
}));
|
||
}
|
||
$storeTime = round((microtime(true) - $stageStart) * 1000, 2);
|
||
$stageStart = microtime(true);
|
||
if($len>0){
|
||
$orders = array_slice($tmporders,0,$len);
|
||
}else{
|
||
$orders = $tmporders;
|
||
}
|
||
$tmpskus2 = [];
|
||
foreach ($orders as $r){
|
||
$tmpskus2 = array_merge($tmpskus2,$r['stocks']);
|
||
}
|
||
$tmpskus2 = array_unique($tmpskus2);
|
||
|
||
$finalTime = round((microtime(true) - $stageStart) * 1000, 2);
|
||
$totalTime = round((microtime(true) - $startTime) * 1000, 2);
|
||
|
||
// 如果总耗时超过3秒,记录警告
|
||
if ($totalTime > 3000) {
|
||
\think\Log::warning("[拣货算法 {$logId}] 执行时间过长:{$totalTime}ms,建议优化");
|
||
}
|
||
|
||
return [
|
||
"skuscount" => count($tmpskus2),
|
||
"order_count" => count($orders),
|
||
"order" => $orders
|
||
];
|
||
}
|
||
//先捡后分算法
|
||
private function generateCombinations2($tmporders, $len = 20, $group = 1,$posttype = 2,$ordercountgt = 50,$rtorder=false){
|
||
$stores = [];
|
||
$postcodes = [];
|
||
$mergedArray = [];
|
||
$stores1 = [];
|
||
$postcodes1 = [];
|
||
$mergedArray1 = [];
|
||
if($group==1){
|
||
foreach($tmporders as $r){
|
||
if(!array_key_exists($r['STOREID'],$stores)){
|
||
$stores[$r['STOREID']] = [$r];
|
||
}else{
|
||
array_push($stores[$r['STOREID']],$r);
|
||
}
|
||
}
|
||
}
|
||
if($posttype ==1){
|
||
foreach($tmporders as $r){
|
||
if(!array_key_exists($r['POSTCODE'],$postcodes)){
|
||
$postcodes[$r['POSTCODE']] = [$r];
|
||
}else{
|
||
array_push($postcodes[$r['POSTCODE']],$r);
|
||
}
|
||
}
|
||
}
|
||
if($group==1 && $posttype ==1){
|
||
foreach ($stores as $keyA => $valueA) {
|
||
foreach ($postcodes as $keyB => $valueB) {
|
||
$mergedKey = $keyA . $keyB;
|
||
$mergedValue = array_intersect($valueA, $valueB);
|
||
$mergedArray[$mergedKey] = $mergedValue;
|
||
}
|
||
}
|
||
foreach ($mergedArray as $k => $r){
|
||
$skus = $this->getorderstockAll($r,$len);
|
||
$mergedArray1[$k] = $this->getorders($r,$skus);
|
||
}
|
||
//print_r($mergedArray1);
|
||
usort($mergedArray1,function($a,$b){
|
||
return strlen(count($b))-strlen(count($a));
|
||
});
|
||
$orders = isset($mergedArray1[0])?$mergedArray1[0]:[];
|
||
}else{
|
||
if($posttype ==1){
|
||
foreach ($postcodes as $k => $r){
|
||
$skus = $this->getorderstockAll($r,$len);
|
||
$mergedArray1[$k] = $this->getorders($r,$skus);
|
||
}
|
||
usort($postcodes1,function($a,$b){
|
||
return strlen(count($b))-strlen(count($a));
|
||
});
|
||
$orders = isset($postcodes1[0])?$postcodes1[0]:[];
|
||
}else if($group==1){
|
||
foreach ($stores as $k => $r){
|
||
$skus = $this->getorderstockAll($r,$len);
|
||
$stores1[$k] = $this->getorders($r,$skus);
|
||
}
|
||
usort($stores1,function($a,$b){
|
||
return strlen(count($b))-strlen(count($a));
|
||
});
|
||
//print_r($stores);
|
||
$orders = isset($stores1[0])?$stores1[0]:[];
|
||
}else{
|
||
$skus = $this->getorderstockAll($tmporders,$len);
|
||
$tmpskus2 = $this->getorderstockAll($tmporders,$len);
|
||
$orders = $this->getorders($tmporders,$skus);
|
||
}
|
||
|
||
}
|
||
$orders = array_slice($orders, 0, $ordercountgt, true);
|
||
if($rtorder){
|
||
return ["order_count"=>count($orders),"order"=>$orders,"skuscount"=>count($this->getStocks($orders))];
|
||
}else{
|
||
return ["order_count"=>count($orders),"order"=>$orders,"skuscount"=>count($this->getStocks($orders))];
|
||
}
|
||
}
|
||
//单品单件算法
|
||
private function generateCombinations1($tmporders, $len = 20, $group = 1,$posttype = 2,$ordercountgt = 50,$rtorder=false){
|
||
|
||
$tmpstores = [];
|
||
$tmppostcodes = [];
|
||
usort($tmporders,function($a,$b){
|
||
return strlen($a['ITEMS'])-strlen($b['ITEMS']);
|
||
});
|
||
foreach ($tmporders as $r){
|
||
if(!array_key_exists($r['POSTCODE'],$tmppostcodes)){
|
||
$tmppostcodes[$r['POSTCODE']] = ["POSTCODE"=>$r["POSTCODE"],"ordercount"=>1];
|
||
}else{
|
||
$tmppostcodes[$r['POSTCODE']]['ordercount'] ++;
|
||
}
|
||
}
|
||
usort($tmppostcodes,function($a,$b){
|
||
return $b["ordercount"]-$a["ordercount"];
|
||
});
|
||
$POSTCODE = $posttype==1 && isset($tmppostcodes[0]['POSTCODE'])?$tmppostcodes[0]['POSTCODE']:-1;
|
||
if($POSTCODE!=-1){
|
||
foreach($tmporders as $k => $r){
|
||
if($r['POSTCODE']!=$POSTCODE){
|
||
unset($tmporders[$k]);
|
||
}
|
||
}
|
||
}
|
||
foreach ($tmporders as $r){
|
||
if(!array_key_exists($r['STOREID'],$tmpstores)){
|
||
$tmpstores[$r['STOREID']] = ["STOREID"=>$r["STOREID"],"ordercount"=>1];
|
||
}else{
|
||
$tmpstores[$r['STOREID']]['ordercount'] ++;
|
||
}
|
||
}
|
||
usort($tmpstores,function($a,$b){
|
||
return $b["ordercount"]-$a["ordercount"];
|
||
});
|
||
$STOREID = $group==1 && isset($tmpstores[0]['STOREID'])?$tmpstores[0]['STOREID']:-1;
|
||
if($STOREID!=-1){
|
||
foreach($tmporders as $k => $r){
|
||
if($r['STOREID']!=$STOREID){
|
||
unset($tmporders[$k]);
|
||
}
|
||
}
|
||
}
|
||
if($len>0){
|
||
$orders = array_slice($tmporders,0,$len);
|
||
}else{
|
||
$orders = $tmporders;
|
||
}
|
||
$tmpskus2 = [];
|
||
foreach ($orders as $r){
|
||
$tmpskus2 = array_merge($tmpskus2,$r['stocks']);
|
||
}
|
||
$tmpskus2 = array_unique($tmpskus2);
|
||
$orderModel = new \app\common\model\wms\Picking;
|
||
$orders_ids = [];
|
||
foreach ($orders as $r){
|
||
array_push($orders_ids,$r["ID"]);
|
||
}
|
||
$STOCKIDs = $orderModel->field('COUNT,DETAILS,SPACEID,STOCKID')->where("WMSORDERID","in",$orders_ids)->with(["space","stock"])->select();
|
||
$order_group = [];
|
||
|
||
|
||
foreach($orders as $r){
|
||
foreach ($STOCKIDs as $rr){
|
||
if($r["stocks"][0] == $rr["STOCKID"]){
|
||
$r["SPACEA"] = mb_substr($rr["space"]["CUSTOMNUM"],0,1);
|
||
if(isset($order_group[$r["SPACEA"]])){
|
||
array_push($order_group[$r["SPACEA"]],$r);
|
||
}else{
|
||
$order_group[$r["SPACEA"]] = [$r];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
$ordercount = 0;
|
||
foreach ($order_group as $r){
|
||
if(count($r)>$ordercount){
|
||
$orders = $r;
|
||
$ordercount = count($r);
|
||
}
|
||
}
|
||
$orders = array_unique($orders);
|
||
if($rtorder){
|
||
return ["order_count"=>count($orders),"order"=>$orders,"skuscount"=>count($this->getStocks($orders))];
|
||
}else{
|
||
return ["order_count"=>count($orders),"order"=>$orders,"skuscount"=>count($this->getStocks($orders))];
|
||
}
|
||
}
|
||
private function getorders($orders,$skus){
|
||
|
||
|
||
$orders2 = [];
|
||
foreach ($orders as $r){
|
||
//print_r(json_encode($r));
|
||
$hasOther = false;
|
||
foreach ($r['stocks'] as $rr){
|
||
|
||
//print_r($r);
|
||
if(!in_array($rr,$skus)){
|
||
$hasOther = true;
|
||
}
|
||
}
|
||
if(!$hasOther){
|
||
array_push($orders2,$r);
|
||
}
|
||
}
|
||
return $orders2;
|
||
}
|
||
//边拣边分
|
||
private function generateCombinations5($tmporders,$len, $group = 1,$posttype,$rtorder=false){
|
||
$tmpstores = [];
|
||
$tmppostcodes = [];
|
||
$orders_ids = [];
|
||
$types = [];
|
||
if(count($tmporders)==0){
|
||
return ["skuscount"=>0,"order_count"=>0,"order"=>[],"grbscount"=>0];
|
||
}
|
||
foreach($tmporders as $r){
|
||
array_push($orders_ids,$r["ID"]);
|
||
}
|
||
$orderModel = new \app\common\model\wms\Picking;
|
||
$STOCKIDs = $orderModel->field('COUNT,DETAILS,SPACEID,STOCKID')->where("WMSORDERID","in",$orders_ids)->with(["space","stock"])->select();
|
||
$post_count = [];
|
||
foreach($tmporders as $r){
|
||
$space = [];
|
||
$space2 = [];
|
||
$space3 = [];
|
||
foreach ($STOCKIDs as $rr){
|
||
if(in_array($rr["STOCKID"],$r["stocks"])){
|
||
$SPACEA = mb_substr($rr["space"]["CUSTOMNUM"],0,1);
|
||
$SPACEB = $rr["space"]["IDX"];
|
||
$SPACEC = $rr["space"]["CODE"];
|
||
array_push($space,$SPACEA);
|
||
array_push($space2,$SPACEB);
|
||
array_push($space3,$SPACEC);
|
||
}
|
||
}
|
||
$space = array_unique($space);
|
||
$space2 = array_unique($space2);
|
||
$space3 = array_unique($space3);
|
||
asort($space);
|
||
rsort($space2);
|
||
$space2 = array_values($space2);
|
||
$space = implode("",$space);
|
||
$r["SPACE"] = $space;
|
||
$r["SPACEINDEX"] = $space2[0];
|
||
if(count($space3)>1){
|
||
$r["SPACEINDEX"] = $space2[0]*10000;
|
||
}
|
||
if(!array_key_exists($r['POSTCODE'],$post_count)){
|
||
$post_count[$r['POSTCODE']] = 1;
|
||
}else{
|
||
$post_count[$r['POSTCODE']] ++;
|
||
}
|
||
}
|
||
$tmp_POSTCODE = null;
|
||
$tmp_count = 0;
|
||
foreach ($post_count as $k => $r){
|
||
if($r>$tmp_count){
|
||
$tmp_POSTCODE = $k;
|
||
$tmp_count = $r;
|
||
}
|
||
}
|
||
foreach ($tmporders as $r){
|
||
if(!array_key_exists($r['POSTCODE'].$r['STOCKS'],$types)){
|
||
if($tmp_POSTCODE){
|
||
if($r['POSTCODE']==$tmp_POSTCODE){
|
||
$types[$r['POSTCODE'].$r['STOCKS']] = ['list'=>[$r],'SPACE'=>$r['SPACE'],'SPACEINDEX'=>$r['SPACEINDEX'],'POSTCODE'=>$r['POSTCODE']];
|
||
}
|
||
}else{
|
||
$tmp_POSTCODE = $r['POSTCODE'];
|
||
$types[$r['POSTCODE'].$r['STOCKS']] = ['list'=>[$r],'SPACE'=>$r['SPACE'],'SPACEINDEX'=>$r['SPACEINDEX'],'POSTCODE'=>$r['POSTCODE']];
|
||
}
|
||
|
||
}else{
|
||
if($r['POSTCODE']==$tmp_POSTCODE){
|
||
array_push($types[$r['POSTCODE'].$r['STOCKS']]['list'],$r);
|
||
}
|
||
}
|
||
}
|
||
$tmpkey = "";
|
||
$tmpcountmax = 0;
|
||
foreach ($types as $k => $r){
|
||
if(count($r)>$tmpcountmax){
|
||
$tmpcountmax = count($r);
|
||
$tmpkey = $k;
|
||
}
|
||
}
|
||
usort($types,function($a,$b){
|
||
return ($a['SPACEINDEX'] > $b['SPACEINDEX']);
|
||
});
|
||
if($len>0){
|
||
$orders = array_slice($types,0,$len);
|
||
}else{
|
||
$orders = $types;
|
||
}
|
||
if($rtorder){
|
||
return ["order"=>$orders,"grbscount"=>count($orders)];
|
||
}else{
|
||
return ["order"=>$orders,"grbscount"=>count($orders)];
|
||
}
|
||
}
|
||
//装载数据
|
||
private function fororders($arr,$skus,$group,$start = 0,$len,$ordercountgt,$rtorder=false){
|
||
if(count($arr)==0){
|
||
return ["skuscount"=>0,"order_count"=>0,/*"order"=>$orders*/];
|
||
}
|
||
$skusc = [$skus[$start]['STOCKID']];
|
||
$orders = [];
|
||
for($i = 1;$i<$len;$i++){
|
||
$skusc = $this->AddOneSku($skusc,$arr,$i,$group,$skus[$start]['STOREID']);
|
||
//print_r($skusc);
|
||
}
|
||
foreach ($arr as $r){
|
||
$hasOther = false;
|
||
foreach ($r['stocks'] as $rr){
|
||
if(!in_array($rr,$skusc)){
|
||
$hasOther = true;
|
||
}
|
||
}
|
||
if(!$hasOther){
|
||
array_push($orders,$r);
|
||
}
|
||
}
|
||
$tmpskus2 = [];
|
||
$orders = array_slice($orders,0,$ordercountgt);
|
||
foreach ($orders as $r){
|
||
$tmpskus2 = array_merge($tmpskus2,$r['stocks']);
|
||
}
|
||
$skusc = array_unique($tmpskus2);
|
||
if($rtorder){
|
||
return ["skuscount"=>count($skusc),"order_count"=>count($orders),"order"=>$orders];
|
||
}else{
|
||
return ["skuscount"=>count($skusc),"order_count"=>count($orders),/*"order"=>$orders*/];
|
||
}
|
||
}
|
||
private function getorderstockAll($orders, $n){
|
||
$skus1 = $this->getorderstock($orders, $n);
|
||
$skus2 = $this->getorderstock2($orders, $n);
|
||
$orders1 = $this->getorders($orders,$skus1);
|
||
$orders2 = $this->getorders($orders,$skus2);
|
||
$skuss = count($orders1)>count($orders2)?$skus1:$skus2;
|
||
return $skuss;
|
||
}
|
||
private function getorderstock($orders, $n, $skusss=[],$k = 0){
|
||
$otherOrders = $this->otherOrder($orders,$skusss);
|
||
$skus = $this->calculateMaxGoods($otherOrders,$n - count($skusss));
|
||
$skus = array_merge($skusss,$skus);
|
||
$skusss = array_unique($skus);
|
||
$tmporders = $this->getorders($orders,$skusss);
|
||
$skusss = $this->getStocks($tmporders);
|
||
if(count($skusss)<$n && count($tmporders)<count($orders) && $k<150){
|
||
$skus = $this->getorderstock($orders,$n,$skusss,$k+1);
|
||
$skusss = array_merge($skusss,$skus);
|
||
}
|
||
return array_unique($skusss);
|
||
}
|
||
private function getorderstock2($orders, $n, $skusss=[],$k = 0){
|
||
usort($orders,function($a,$b){
|
||
return count($b["stocks"])-count($a["stocks"]);
|
||
});
|
||
foreach ($orders as $r){
|
||
$tmpskus = [];
|
||
foreach ($r['stocks'] as $stocks){
|
||
if(!in_array($stocks,$skusss)){
|
||
array_push($tmpskus,$stocks);
|
||
}
|
||
}
|
||
if(count($skusss)+count($tmpskus)<=$n){
|
||
$skusss = array_merge($skusss,$tmpskus);
|
||
}
|
||
}
|
||
return $skusss;
|
||
}
|
||
private function otherOrder($orders,$skus){
|
||
$newOrder = [];
|
||
foreach ($orders as $r){
|
||
$ingood = true;
|
||
foreach ($r['stocks'] as $stocks){
|
||
if(!in_array($stocks,$skus)){
|
||
$ingood = false;
|
||
}
|
||
}
|
||
if(!$ingood){
|
||
array_push($newOrder,$r);
|
||
}
|
||
}
|
||
return $newOrder;
|
||
}
|
||
private function getStocks($orders){
|
||
$skus = [];
|
||
foreach ($orders as $r){
|
||
foreach ($r['stocks'] as $stocks){
|
||
array_push($skus,$stocks);
|
||
}
|
||
}
|
||
return array_unique($skus);
|
||
}
|
||
//获取订单中SKU组合包含最多订单的SKU组合
|
||
private function calculateMaxGoods($orders, $n) {
|
||
$goodsDict = array();
|
||
|
||
// 遍历每个订单
|
||
foreach ($orders as $order) {
|
||
$goods = $order["stocks"];
|
||
|
||
// 遍历订单中的每个goods
|
||
foreach ($goods as $good) {
|
||
if (isset($goodsDict[$good])) {
|
||
// goods已存在,将订单编号添加到值中
|
||
$goodsDict[$good][] = $order["ID"];
|
||
} else {
|
||
// goods不存在,创建新的键值对
|
||
$goodsDict[$good] = array($order["ID"]);
|
||
}
|
||
}
|
||
}
|
||
|
||
// 按订单数量降序排序
|
||
arsort($goodsDict);
|
||
|
||
// 获取订单数量最多的n种商品
|
||
$maxGoods = array_slice(array_keys($goodsDict), 0, $n);
|
||
|
||
// 返回能装的所有订单数量最多的n种商品的集合
|
||
return $maxGoods;
|
||
}
|
||
public function getLoginercode(){
|
||
$uuid = Random::uuid();
|
||
$loginModel = new \app\common\model\Logins;
|
||
$loginModel->save(["token"=>$uuid]);
|
||
return json(["token"=>$uuid]);
|
||
}
|
||
public function getloginstatus(){
|
||
$params=$this->request->post();
|
||
$token = isset($params["token"])?$params["token"]:null;
|
||
$loginModel = new \app\common\model\Logins;
|
||
if($token){
|
||
$data = $loginModel->where(["token"=>$token])->find();
|
||
return json($data);
|
||
}else{
|
||
return null;
|
||
}
|
||
}
|
||
public function confirmPrint(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$POSTNUM = $params["POSTNUM"];
|
||
$data = Wsdl::webservice([$WAREHOUSEID,$POSTNUM,'caige01'],'confirmPrint');
|
||
}
|
||
public function getPickingGrab(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$userid = $params["userid"];
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$tmps = $OrderModel->field("SUM(CASE WHEN PLSENDFLAG=1 THEN 1 ELSE 0 END) AS yfh,SUM(CASE WHEN PLSENDFLAG=0 THEN 1 ELSE 0 END) AS wfh,GRABNUM,POSTNUM,PICKINGFLAG")->where(["WAREHOUSEID"=>$WAREHOUSEID,"FLAG"=>0])->where("GRABNUM not like '%B%' and GRABNUM is not null and GRABNUM <> ''")->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-7 day")))*1000)->group("GRABNUM")->select();
|
||
$grabs = [];
|
||
$tmp2s = [];
|
||
$grabnums = [];
|
||
foreach ($tmps as $r){
|
||
if($r['wfh']>0){
|
||
array_push($tmp2s,$r);
|
||
array_push($grabnums,$r['GRABNUM']);
|
||
}
|
||
}
|
||
$WorksModel = new \app\common\model\workers\Works;
|
||
$works = $WorksModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("grabnum","in",$grabnums)->where("picks>0")->select();
|
||
//print_r($works);
|
||
$userids = [];
|
||
foreach ($tmp2s as $r){
|
||
$r['userid'] = 0;
|
||
foreach ($works as $rr){
|
||
if($r['GRABNUM']==$rr['grabnum']){
|
||
$r['userid'] = $rr['userId'];
|
||
array_push($userids,$rr['userId']);
|
||
}
|
||
}
|
||
}
|
||
//print_r($userids);
|
||
$wmsuserModel = new \app\common\model\wms\User;
|
||
$users = $wmsuserModel->where("userID","in",$userids)->select();
|
||
foreach ($tmp2s as $r){
|
||
foreach ($users as $rr){
|
||
if($r['userid']==$rr['userID']){
|
||
$r['username'] = $rr['name'];
|
||
}
|
||
}
|
||
if($userid){
|
||
if($userid==$r['userid']){
|
||
array_push($grabs,$r);
|
||
}
|
||
}else{
|
||
array_push($grabs,$r);
|
||
}
|
||
}
|
||
$GRABNUMS = [];
|
||
foreach ($grabs as $k => $r){
|
||
foreach ($works as $rr){
|
||
if($r["GRABNUM"]==$rr['grabnum']){
|
||
$grabs[$k]['carid']=$rr['carid'];
|
||
}
|
||
}
|
||
}
|
||
|
||
return json(["list"=>$grabs]);
|
||
}
|
||
public function getPickingGrab2(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$userid = $params["userid"];
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$tmps = $OrderModel->field("SUM(CASE WHEN PLSENDFLAG=1 THEN 1 ELSE 0 END) AS yfh,SUM(CASE WHEN PLSENDFLAG=0 THEN 1 ELSE 0 END) AS wfh,GRABNUM")->where(["WAREHOUSEID"=>$WAREHOUSEID,"PICKINGFLAG"=>3,"FLAG"=>0])->where("GRABNUM like '%B%'")->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-7 day")))*1000)->group("GRABNUM")->select();
|
||
|
||
$grabs = [];
|
||
$tmp2s = [];
|
||
$grabnums = [];
|
||
foreach ($tmps as $r){
|
||
if($r['wfh']>0){
|
||
array_push($tmp2s,$r);
|
||
array_push($grabnums,$r['GRABNUM']);
|
||
}
|
||
}
|
||
$WorksModel = new \app\common\model\workers\Works;
|
||
$works = $WorksModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("grabnum","in",$grabnums)->where("picks>0")->select();
|
||
//print_r($works);
|
||
$userids = [];
|
||
foreach ($tmp2s as $r){
|
||
$r['userid'] = 0;
|
||
foreach ($works as $rr){
|
||
if($r['GRABNUM']==$rr['grabnum']){
|
||
$r['userid'] = $rr['userId'];
|
||
array_push($userids,$rr['userId']);
|
||
}
|
||
}
|
||
}
|
||
//print_r($userids);
|
||
$wmsuserModel = new \app\common\model\wms\User;
|
||
$users = $wmsuserModel->where("userID","in",$userids)->select();
|
||
foreach ($tmp2s as $r){
|
||
foreach ($users as $rr){
|
||
if($r['userid']==$rr['userID']){
|
||
$r['username'] = $rr['name'];
|
||
}
|
||
}
|
||
if($userid){
|
||
if($userid==$r['userid']){
|
||
array_push($grabs,$r);
|
||
}
|
||
}else{
|
||
array_push($grabs,$r);
|
||
}
|
||
}
|
||
return json(["list"=>$grabs]);
|
||
}
|
||
public function getnotfhOrders(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$GRABNUM = $params["GRABNUM"];
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$tmps = $OrderModel->where(["GRABNUM"=>$GRABNUM,"PLSENDFLAG"=>0,"FLAG"=>0])->select();
|
||
$orders = [];
|
||
foreach ($tmps as $r){
|
||
array_push($orders,$r["POSTNUM"]);
|
||
}
|
||
return json(["orders"=>$orders]);
|
||
}
|
||
public function autoCreateWmsTuan(){
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$WmstuanModel = new \app\common\model\wms\Wmstuan;
|
||
$WAREHOUSEID = $this->request->get('WAREHOUSEID');
|
||
$userid = $this->request->get('userid');
|
||
//删除团购或把待处理加入团购
|
||
$current_hour = intval(date('H', time()));
|
||
$addtuan = [];
|
||
$cancelGrabWmsOrder = [];
|
||
if($current_hour>6 && $current_hour<18){
|
||
$grabs = $OrderModel->field('count(*) as count,GRABNUM,POSTCODE,STOCKS')->where(["WAREHOUSEID"=>$WAREHOUSEID,"PRINTTIMES"=>0,"FLAG"=>0,"ISLOCK"=>0])->where("GRABNUM like '%B%'")->group('GRABNUM')->select();
|
||
|
||
|
||
foreach($grabs as $r){
|
||
$orders = $OrderModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"STOCKS"=>$r["STOCKS"],"POSTCODE"=>$r["POSTCODE"],"FLAG"=>0,"ISLOCK"=>0])->where("GRABNUM is NULL or GRABNUM=''")->select();
|
||
$isgrab = $WmstuanModel->where(["GRABNUM"=>$r["GRABNUM"]])->find();
|
||
if($isgrab){
|
||
if($r['count']+count($orders)>=4){
|
||
$ids = [];
|
||
foreach ($orders as $rr){
|
||
array_push($ids,$rr['ID']);
|
||
}
|
||
$ids = implode(',',$ids);
|
||
Wsdl::webservice([$WAREHOUSEID,$userid,$ids,$r["GRABNUM"]],"addTuan");
|
||
array_push($addtuan,["GRABNUM"=>$r["GRABNUM"],"orders"=>$ids]);
|
||
}else{
|
||
Wsdl::webservice([$WAREHOUSEID,$userid,$r["GRABNUM"]],"cancelGrabWmsOrder");
|
||
array_push($cancelGrabWmsOrder,["GRABNUM"=>$r["GRABNUM"]]);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//分配储位
|
||
$res = $OrderModel->field('ID')->where(["WAREHOUSEID"=>$WAREHOUSEID])->where(["ASSIGNFLAG"=>0,"FLAG"=>0,"ISLOCK"=>0])->where("GRABNUM not like '%B%'")->where("STOREID<>24701 and STOREID<>16101")->where("POSTCODE<>'p18' and POSTCODE<>'p30'")->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-3 day")))*1000)->select();
|
||
$ids = [];
|
||
foreach ($res as $r){
|
||
$data = Wsdl::webservice([$WAREHOUSEID,$userid,$r['ID'],1],'assignWmsOrder');
|
||
}
|
||
return json(["addTuan"=>$addtuan,"cancelGrabWmsOrder"=>$cancelGrabWmsOrder,"chuwei"=>$res]);
|
||
}
|
||
public function bindcar(){
|
||
$params=$this->request->post();
|
||
$GRABNUM = $params['GRABNUM'];
|
||
$WAREHOUSEMODEL = new \app\common\model\Warehouse;
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$WAREHOUSE = $WAREHOUSEMODEL->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
$WORKDATE = ($WAREHOUSE['workDate'] ?? null);
|
||
$carid = $params['carid'];
|
||
$model = new \app\common\model\workers\Works;
|
||
$data = $model->where(['WAREHOUSEID'=>$WAREHOUSEID,"grabnum"=>$GRABNUM])->find();
|
||
if($carid==1){
|
||
$data->save(['updatetime'=>time()]);
|
||
return json(["hascar"=>false]);
|
||
}
|
||
$hascar = $model->where(['WAREHOUSEID'=>$WAREHOUSEID,"carid"=>$carid])->find();
|
||
if($hascar && ($hascar['grabnum'] ?? null)!=$GRABNUM){
|
||
return json(["hascar"=>true]);
|
||
}else{
|
||
$data->save(['carid'=>$carid]);
|
||
return json(["hascar"=>false,"car"=>$carid]);
|
||
}
|
||
}
|
||
public function testDBLock(){
|
||
try{
|
||
Db::startTrans();
|
||
$PrinterModel = new \app\common\model\Printer;
|
||
$row = $PrinterModel->where('id=3')->lock(true)->find();
|
||
$row->save(['defaultprinter'=>'31111']);
|
||
sleep(20);
|
||
Db::commit();
|
||
return json($row);
|
||
}catch(\Exception $e){
|
||
echo $e;
|
||
Db::rollback();
|
||
}
|
||
}
|
||
public function testChange(){
|
||
$PrinterModel = new \app\common\model\Printer;
|
||
$row = $PrinterModel->where('idss','in',[1,2])->lock(true)->select();
|
||
try{
|
||
Db::startTrans();
|
||
|
||
|
||
//$row->save(['defaultprinter'=>211111]);
|
||
Db::commit();
|
||
return json($row);
|
||
}catch(\Exception $e){
|
||
echo $e;
|
||
Db::rollback();
|
||
}
|
||
}
|
||
public function secondaryAllocation(){
|
||
$model = new \app\common\model\workers\Works;
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
$params = $this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$carid = $params['carid'];
|
||
$data = $model->field('items,orders,grabnum')->where(['WAREHOUSEID'=>$WAREHOUSEID,'carid'=>$carid])->find();
|
||
|
||
if(!$data){
|
||
$data = $orderModel->where(['WAREHOUSEID'=>$WAREHOUSEID,'POSTNUM'=>$carid])->find();
|
||
if(!$data){
|
||
return json([]);
|
||
}else{
|
||
$GRABNUM = $data['GRABNUM'];
|
||
}
|
||
|
||
}else{
|
||
$GRABNUM = $data['grabnum'];
|
||
}
|
||
|
||
$list = $orderModel->where(['WAREHOUSEID'=>$WAREHOUSEID,"PLSENDFLAG"=>0,"FLAG"=>0,"GRABNUM"=>$GRABNUM])->order('ITEMS')->select();
|
||
$items_tmp = [];
|
||
$list2 = $orderModel->where(['WAREHOUSEID'=>$WAREHOUSEID,"PLSENDFLAG"=>0,"FLAG"=>0,"GRABNUM"=>$GRABNUM])->order('ITEMS')->select();
|
||
foreach ($list as $k => $r){
|
||
$items = array_filter(explode("|",$r['ITEMS']),'trim');
|
||
foreach ($items as $r){
|
||
$STOCKINFO = explode(",",$r);
|
||
$tmp_lanhao = $k+1;
|
||
$model = new \app\common\model\wms\Stock;
|
||
$STOCK = $model->where(["STOCKID"=>$STOCKINFO[0]])->find();
|
||
if(isset($STOCKINFO[2]) && strpos($STOCKINFO[2],'yc#zy')==false){
|
||
array_push($items_tmp,['STOCKIDS'=>$STOCKINFO[0],'count'=>$STOCKINFO[1],'title'=>$STOCKINFO[2],'ercode'=>($STOCK['BARCODE'] ?? null),'lanhao'=>$tmp_lanhao,'COLOR'=>($STOCK['COLOR'] ?? null),'STYLE'=>($STOCK['STYLE'] ?? null),'IMG'=>($STOCK['IMG'] ?? null),'ispick'=>!!($STOCK['SCANFLAG'] ?? null)]);
|
||
}
|
||
}
|
||
}
|
||
return json(['stocks'=>$items_tmp,'orders'=>$list2,'grabnum'=>$GRABNUM]);
|
||
}
|
||
public function scan_task(){
|
||
$params = $this->request->post();
|
||
$WAREHOUSEID = $params['warehouseid'];
|
||
$orderModel1 = new \app\common\model\wms\Order1;
|
||
$orderModel2 = new \app\common\model\wms\Order2;
|
||
$BackcodeModel = new \app\common\model\task\Backcode;
|
||
try{
|
||
Db::startTrans();
|
||
$data2 = $BackcodeModel->where(['WAREHOUSEID'=>$WAREHOUSEID,'CODE'=>$params['code']])->lock(true)->find();
|
||
if($data2){
|
||
if($data2['check']==1){
|
||
return 3;
|
||
}
|
||
$data = $orderModel1->where(['WAREHOUSEID'=>$WAREHOUSEID,'POSTNUM'=>$params['code']])->find();
|
||
if(!$data){
|
||
$data = $orderModel2->where(['WAREHOUSEID'=>$WAREHOUSEID,'POSTNUM'=>$params['code']])->find();
|
||
}
|
||
Db::commit();
|
||
if(!$data){
|
||
$data2->save(['check'=>1,'has'=>-1,'created_time'=>$params['scanTime']]);
|
||
return 2;
|
||
}else{
|
||
$data2->save(['check'=>1,'has'=>1,'created_time'=>$params['scanTime']]);
|
||
return 1;
|
||
}
|
||
}else{
|
||
return 4;
|
||
}
|
||
}catch(\Exception $e){
|
||
echo $e;
|
||
Db::rollback();
|
||
}
|
||
}
|
||
public function lastgrabs(){
|
||
$params = $this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$USERID = $params['USERID'];
|
||
$MergeModel = new \app\common\model\tuan\Merge;
|
||
$pickinfoModel = new \app\common\model\tuan\Pickinfo;
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
$PickingModel = new \app\common\model\wms\Picking;
|
||
$WorksModel = new \app\common\model\workers\Works;
|
||
$MergeData = $MergeModel->where(['userid'=>$USERID,'status'=>1])->find();
|
||
if(!$MergeData){
|
||
return json([]);
|
||
}
|
||
$grabstmp = explode(",",$MergeData['GRABS']);
|
||
if(!$MergeData['GRABS']){
|
||
$MergeData->save(['status'=>0]);
|
||
return json([]);
|
||
}else{
|
||
$orders2 = $orderModel->field('ITEMS,COUNT(*) as COUNT,GRABNUM,POSTNUM')->where(["WAREHOUSEID"=>$WAREHOUSEID,"PLSENDFLAG"=>0,"FLAG"=>0])->where("GRABNUM","in",$grabstmp)->group('GRABNUM')->select();
|
||
if(!$orders2){
|
||
$MergeData->save(['status'=>0]);
|
||
return json([]);
|
||
}
|
||
}
|
||
foreach ($orders2 as $r){
|
||
$items = array_filter(explode("|",$r['ITEMS']),'trim');
|
||
$stocks = [];
|
||
foreach ($items as $stock){
|
||
$info = array_filter(explode(",",$stock),'trim');
|
||
array_push($stocks,["id"=>$info[0],"count"=>intval($info[1])*$r['COUNT']]);
|
||
}
|
||
$r['stock'] = $stocks;
|
||
}
|
||
$pickingData = [];
|
||
$ids = [];
|
||
$orders = $orderModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"PLSENDFLAG"=>0,"FLAG"=>0])->where("GRABNUM","in",$grabstmp)->select();
|
||
|
||
foreach($orders as $r){
|
||
array_push($ids,$r['ID']);
|
||
}
|
||
$STOCKIDs = $PickingModel->field('COUNT,DETAILS,SPACEID,STOCKID')->where("WMSORDERID","in",$ids)->with(["space","stock"])->select();
|
||
$STOCKS = [];
|
||
foreach($STOCKIDs as $r){
|
||
$hasSKU = false;
|
||
foreach ($STOCKS as $k => $rr){
|
||
if($rr['STOCKID']==$r['STOCKID']){
|
||
$rr['COUNT']+=$r['COUNT'];
|
||
$hasSKU = true;
|
||
}
|
||
}
|
||
if(!$hasSKU){
|
||
array_push($STOCKS,$r);
|
||
}
|
||
}
|
||
usort($STOCKS,function($a,$b){
|
||
return $a['space']['IDX'] - $b['space']['IDX'];
|
||
});
|
||
|
||
$pickinfoModel->insert([
|
||
"tuan_id"=>$MergeData['id'],
|
||
"info"=>json_encode($STOCKS),
|
||
"create_time"=>time()
|
||
]);
|
||
return json(['grabs'=>$orders2,'pickingData'=>$STOCKS,'taskID'=>isset($MergeData['id'])?$MergeData['id']:-1]);
|
||
}
|
||
public function lastgrabs2(){
|
||
$params = $this->request->post();
|
||
$WAREHOUSEID = 5400;
|
||
$MergeModel = new \app\common\model\tuan\Merge;
|
||
$pickinfoModel = new \app\common\model\tuan\Pickinfo;
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
$PickingModel = new \app\common\model\wms\Picking;
|
||
$WorksModel = new \app\common\model\workers\Works;
|
||
$MergeData = $MergeModel->where(['id'=>24697])->find();
|
||
if(!$MergeData){
|
||
return json([]);
|
||
}
|
||
$grabstmp = explode(",",$MergeData['GRABS']);
|
||
$STOCKS = [];
|
||
if(!$MergeData['GRABS']){
|
||
$MergeData->save(['status'=>0]);
|
||
return json([]);
|
||
}else{
|
||
$orders2 = $orderModel->field('ITEMS,COUNT(*) as COUNT,GRABNUM,POSTNUM')->where(["WAREHOUSEID"=>$WAREHOUSEID,"PLSENDFLAG"=>0,"FLAG"=>0])->where("GRABNUM","in",$grabstmp)->group('GRABNUM')->select();
|
||
if(!$orders2){
|
||
$MergeData->save(['status'=>0]);
|
||
return json([]);
|
||
}
|
||
}
|
||
foreach ($orders2 as $r){
|
||
$items = array_filter(explode("|",$r['ITEMS']),'trim');
|
||
$stocks = [];
|
||
foreach ($items as $stock){
|
||
$info = array_filter(explode(",",$stock),'trim');
|
||
array_push($stocks,["id"=>$info[0],"count"=>intval($info[1])*$r['COUNT']]);
|
||
}
|
||
$r['stock'] = $stocks;
|
||
}
|
||
$pickingData = [];
|
||
$ids = [];
|
||
$orders = $orderModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"PLSENDFLAG"=>0,"FLAG"=>0])->where("GRABNUM","in",$grabstmp)->select();
|
||
|
||
foreach($orders as $r){
|
||
array_push($ids,$r['ID']);
|
||
}
|
||
$STOCKIDs = $PickingModel->field('COUNT,DETAILS,SPACEID,STOCKID')->where("WMSORDERID","in",$ids)->with(["space","stock"])->select();
|
||
$STOCKS = [];
|
||
foreach($STOCKIDs as $r){
|
||
$hasSKU = false;
|
||
foreach ($STOCKS as $k => $rr){
|
||
if($rr['STOCKID']==$r['STOCKID']){
|
||
$rr['COUNT']+=$r['COUNT'];
|
||
$hasSKU = true;
|
||
}
|
||
}
|
||
if(!$hasSKU){
|
||
array_push($STOCKS,$r);
|
||
}
|
||
}
|
||
usort($STOCKS,function($a,$b){
|
||
return $a['space']['IDX'] - $b['space']['IDX'];
|
||
});
|
||
|
||
$pickinfoModel->insert([
|
||
"tuan_id"=>$MergeData['id'],
|
||
"info"=>json_encode($STOCKS),
|
||
"create_time"=>time()
|
||
]);
|
||
return json(['grabs'=>$orders2,'pickingData'=>$STOCKS,'taskID'=>isset($MergeData['id'])?$MergeData['id']:-1]);
|
||
}
|
||
public function closetask(){
|
||
$params = $this->request->post();
|
||
$MergeModel = new \app\common\model\tuan\Merge;
|
||
$row = $MergeModel->where(['id'=>$params['taskID']])->find();
|
||
$row->save(['status'=>0]);
|
||
}
|
||
public function bindcar2(){
|
||
$params = $this->request->post();
|
||
$MergeModel = new \app\common\model\tuan\Merge;
|
||
$row = $MergeModel->where(['carid'=>$params['carid'],'WAREHOUSEID'=>$params['WAREHOUSEID']])->find();
|
||
if($row){
|
||
return json(["status"=>false]);
|
||
}
|
||
$row = $MergeModel->where(['id'=>$params['taskID']])->find();
|
||
$row->save(['status'=>0,'carid'=>$params['carid']]);
|
||
return json(["status"=>true]);
|
||
}
|
||
public function createTask(){
|
||
$params = $this->request->post();
|
||
$userID = $params['userid'];
|
||
$data = $params['grabs'];
|
||
$MergeModel = new \app\common\model\tuan\Merge;
|
||
$row = $MergeModel->where(['userid'=>$params['userid'],'status'=>1])->find();
|
||
if($row){
|
||
return json(['status'=>false]);
|
||
}else{
|
||
Db::startTrans();
|
||
try {
|
||
$MergeModel->save(['userid'=>$userID,'createtime'=>time(),'status'=>1,'GRABS'=>$data]);
|
||
$mergeId = $MergeModel->id;
|
||
if($mergeId && $data){
|
||
$grabsArr = explode(',', $data);
|
||
$insertData = [];
|
||
foreach ($grabsArr as $pos => $grab) {
|
||
$insertData[] = ['merge_id' => $mergeId, 'grabnum' => $grab, 'position' => $pos];
|
||
}
|
||
Db::table('ye4s_tuan_merge_grabnum')->insertAll($insertData);
|
||
}
|
||
Db::commit();
|
||
return json(['status'=>true]);
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
return json(['status'=>false, 'msg'=>$e->getMessage()]);
|
||
}
|
||
}
|
||
}
|
||
public function get_sandan_last(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$userID = $params['userid'];
|
||
$WAREHOUSEMODEL = new \app\common\model\Warehouse;
|
||
$WorksEMODEL = new \app\common\model\workers\Works;
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$WAREHOUSE = $WAREHOUSEMODEL->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
$WORKDATE = ($WAREHOUSE['workDate'] ?? null);
|
||
$last = $WorksEMODEL->where(["WAREHOUSEID"=>$WAREHOUSEID,"userId"=>$userID,"isSandan"=>0])->where('picks>0 and updatetime is null')->find();
|
||
//print_r($last["grabnum"]);
|
||
if(($last["grabnum"] ?? null)){
|
||
$orders = $OrderModel->where(["GRABNUM"=>($last["grabnum"] ?? null),"PICKINGFLAG"=>0])->select();
|
||
//print_r($orders);
|
||
if(!$orders){
|
||
$last->save(["updatetime"=>time()]);
|
||
$last = [];
|
||
}
|
||
return json($last);
|
||
}else{
|
||
return null;
|
||
}
|
||
}
|
||
public function getmylastOrder(){
|
||
$params=$this->request->post();
|
||
$grabnum = isset($params['grabnum'])?$grabnum:null;
|
||
$WAREHOUSEID = isset($params['warehouseId'])?$params['warehouseId']:'0';
|
||
$userid = isset($params['userid'])?$params['userid']:'0';
|
||
$WorksModel = new \app\common\model\workers\Works;
|
||
if($grabnum){
|
||
|
||
}else{
|
||
$list = $WorksModel->field('POSTNUM,grabnum')->where(['userId'=>$userid])->where('fuhe>0')->order('id','desc')->limit(100)->select();
|
||
$tmplist = [];
|
||
$grabnums = [];
|
||
foreach($list as $r){
|
||
array_push($grabnums,$r['grabnum']);
|
||
}
|
||
$grabnums = $WorksModel->field('orders,grabnum')->where('grabnum','in',$grabnums)->where('picks>0')->select();
|
||
foreach($list as $r){
|
||
$grabnumData = null;
|
||
foreach ($grabnums as $rr){
|
||
if($r['grabnum']==$rr['grabnum'] && $rr['orders']){
|
||
$grabnumData = $rr['orders'];
|
||
}
|
||
}
|
||
$index = null;
|
||
$orders = null;
|
||
if($grabnumData){
|
||
$orders = explode(';',$grabnumData);
|
||
foreach ($orders as $rr){
|
||
$tmp = explode('|',$rr);
|
||
if($tmp[0]==$r['POSTNUM']){
|
||
$index = $tmp[1];
|
||
}
|
||
}
|
||
}
|
||
array_push($tmplist,['index'=>$index,'GRABNUM'=>$r['grabnum'],'POSTNUM'=>$r['POSTNUM'],'orders'=>$orders]);
|
||
}
|
||
}
|
||
//print_r($grabnums);
|
||
return json($tmplist);
|
||
}
|
||
public function get_tuan_history(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = isset($params['warehouseId'])?$params['warehouseId']:'0';
|
||
$userid = isset($params['userid'])?$params['userid']:'0';
|
||
$WorksModel = new \app\common\model\workers\Works;
|
||
$MergeModel = new \app\common\model\tuan\Merge;
|
||
$list = $WorksModel->field('POSTNUM,grabnum')->where(['userId'=>$userid])->where("grabnum like 'B%'")->where('fuhe>0')->order('id','desc')->limit(100)->select();
|
||
$tmplist = [];
|
||
$grabnumsToFind = [];
|
||
foreach($list as $r){
|
||
$grabnumsToFind[] = $r['grabnum'];
|
||
}
|
||
$grabnumMap = [];
|
||
if(!empty($grabnumsToFind)){
|
||
$grabRows = Db::table('ye4s_tuan_merge_grabnum')->where('grabnum', 'in', $grabnumsToFind)->select();
|
||
foreach($grabRows as $gr){
|
||
$grabnumMap[$gr['grabnum']] = $gr;
|
||
}
|
||
}
|
||
foreach($list as $r){
|
||
$index = null;
|
||
if(isset($grabnumMap[$r['grabnum']])){
|
||
$index = $grabnumMap[$r['grabnum']]['position'] + 1;
|
||
}
|
||
array_push($tmplist,['index'=>$index,'GRABNUM'=>$r['grabnum'],'POSTNUM'=>$r['POSTNUM']]);
|
||
}
|
||
return json(["list"=>$tmplist,"as"=>[]]);
|
||
}
|
||
public function palletsPrintConfirm(){
|
||
$params=$this->request->post();
|
||
$palletsMode = new \app\common\model\Pallets;
|
||
Db::startTrans();
|
||
try {
|
||
$list = $palletsMode->where("id","in",$ids)->select();
|
||
foreach ($list as $item){
|
||
$item->save(["print_date"=>time()]);
|
||
}
|
||
Db::commit();
|
||
return json(['code'=>1]);
|
||
} catch (ValidateException|PDOException|Exception $e) {
|
||
Db::rollback();
|
||
$data = $model->where($params);
|
||
if($data){
|
||
return json(['code'=>1,'car'=>$data['cardNum']]);
|
||
}
|
||
return json(['code'=>0]);
|
||
}
|
||
}
|
||
public function AddPallets(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEMODEL = new \app\common\model\Warehouse;
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$WAREHOUSE = $WAREHOUSEMODEL->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
$WORKDATE = ($WAREHOUSE['workDate'] ?? null);
|
||
$insetData = [
|
||
"workDate"=>$WORKDATE,
|
||
"userId"=>$params["userId"],
|
||
"storeName"=>$params["storeName"],
|
||
"WAREHOUSEID"=>$params["WAREHOUSEID"],
|
||
"goodsName"=>$params["goodsName"],
|
||
"boxsize"=>$params["boxsize"],
|
||
"barcode"=>$params["barcode"],
|
||
"STOCKID"=>$params["STOCKID"],
|
||
"production_date"=>strtotime($params["production_date"]),
|
||
"expiration_date"=>strtotime($params["expiration_date"]),
|
||
"created_date"=>time(),
|
||
"count"=>$params["count"],
|
||
"applystorageid"=>$params["applystorageid"],
|
||
"print_date"=>0
|
||
];
|
||
|
||
Db::startTrans();
|
||
try {
|
||
$results = [];
|
||
$insetDatas = [];
|
||
for($i = 0; $i<intval($params["pallets"]);$i++){
|
||
array_push($insetDatas,$insetData);
|
||
}
|
||
foreach ($insetDatas as $item){
|
||
$palletsMode = new \app\common\model\Pallets;
|
||
array_push($results,$palletsMode->save($item));
|
||
}
|
||
Db::commit();
|
||
return json(['code'=>1,"data"=>$params["pallets"],"result"=>$results]);
|
||
} catch (ValidateException|PDOException|Exception $e) {
|
||
Db::rollback();
|
||
$data = $model->where($params);
|
||
if($data){
|
||
return json(['code'=>1,'car'=>$data['cardNum']]);
|
||
}
|
||
return json(['code'=>0]);
|
||
}
|
||
}
|
||
public function del_pallets(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$id = $params["id"];
|
||
$palletsMode = new \app\common\model\Pallets;
|
||
$data = $palletsMode->where(['WAREHOUSEID'=>$WAREHOUSEID,'id'=>$id,'status'=>1])->find();
|
||
if($data){
|
||
$data->delete();
|
||
return 1;
|
||
}else{
|
||
return 0;
|
||
}
|
||
}
|
||
public function getpallets(){
|
||
$params=$this->request->post();
|
||
$palletsMode = new \app\common\model\Pallets;
|
||
$res = $palletsMode->where(["workDate"=>strtotime($params['date']),"userId"=>$params['userId']])->select();
|
||
return json(["list"=>$res]);
|
||
}
|
||
public function getpalletsinfo(){
|
||
|
||
return json("请升级PDA版本");
|
||
}
|
||
public function getapplystorageList(){
|
||
$params=$this->request->post();
|
||
$pagesize = 20;
|
||
$page = isset($params['page'])?$params['page']:1;
|
||
$flag = isset($params['flag'])?$params['flag']:0;
|
||
$storeid = isset($params['storeid'])?$params['storeid']:0;
|
||
$listType = $params['listType'];
|
||
$WAREHOUSEID = isset($params['warehouseId'])?$params['warehouseId']:'0';
|
||
$ApplystorageModel = new \app\common\model\wms\Applystorage;
|
||
$ApplystorageLocalModel = new \app\common\model\Applystorage;
|
||
switch($listType){
|
||
case 0:
|
||
$list = $ApplystorageModel
|
||
->field('store.TITLE as storeName,a.ERPNOTES as ERPNOTES,a.STATUS,a.NOTES as NOTES,a.CREATIONDATE as CREATIONDATE,a.ID as ID,a.SERIALNUM as SERIALNUM,a.FLAG as FLAG')
|
||
->alias("a")
|
||
->join('yj_store store', 'store.STOREID = a.STOREID')
|
||
->where(["a.WAREHOUSEID"=>$WAREHOUSEID,"a.STATUS"=>$params['STATUS'],"a.FLAG"=>$flag])
|
||
->order("id","desc")
|
||
->limit(($page-1)*$pagesize,$pagesize);
|
||
if($storeid>0){
|
||
$list = $list->where(["a.STOREID"=>$storeid]);
|
||
}
|
||
$list = $list->select();
|
||
break;
|
||
case 1:
|
||
$list = $ApplystorageLocalModel
|
||
->field("a.TITLE as TITLE,a.APPLYSTORAGEID as APPLYSTORAGEID,a.id as ID,(SELECT COUNT(*) FROM ye4s_pallets WHERE applystorageid = a.id) AS count")
|
||
->alias("a")
|
||
->where(["WAREHOUSEID"=>$WAREHOUSEID,"STATUS"=>1])
|
||
->order("id","desc")
|
||
->limit(($page-1)*$pagesize,$pagesize)
|
||
->select();
|
||
}
|
||
return json(["list"=>$list]);
|
||
}
|
||
public function createRandom(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$ApplystorageLocalModel = new \app\common\model\Applystorage;
|
||
$TITLE = $params["title"];
|
||
$applyStorageId = isset($params['applyStorageId'])?$params['applyStorageId']:0;
|
||
$applyStorage = null;
|
||
$insertedId = 0;
|
||
if($applyStorageId>0){
|
||
$applyStorage = $ApplystorageLocalModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"APPLYSTORAGEID"=>$applyStorageId])->find();
|
||
$data = Wsdl::webservice([$WAREHOUSEID,$applyStorageId],'createRandom');
|
||
$data = $ApplystorageLocalModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"APPLYSTORAGEID"=>$applyStorageId])->find();
|
||
if($data){
|
||
$msg = "创建失败,入库单已创建了收货单";
|
||
$insertedId = $data["id"];
|
||
}
|
||
}
|
||
if(!$applyStorage and $insertedId==0){
|
||
$msg = "创建成功";
|
||
$insertedId = $ApplystorageLocalModel->insertDataAndGetId(["WAREHOUSEID"=>$WAREHOUSEID,"APPLYSTORAGEID"=>$applyStorageId,"TITLE"=>$TITLE,"STATUS"=>1]);
|
||
}
|
||
return json(["id"=>$insertedId,"msg"=>$msg]);
|
||
}
|
||
public function bindapplystorage(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$ApplystorageLocalModel = new \app\common\model\Applystorage;
|
||
$list = $ApplystorageLocalModel
|
||
->field("a.TITLE as TITLE,a.id as ID,(SELECT COUNT(*) FROM ye4s_pallets WHERE applystorageid = a.id) AS count")
|
||
->alias("a")
|
||
->where(["a.WAREHOUSEID"=>$WAREHOUSEID,"STATUS"=>1])
|
||
->order("id","desc")
|
||
->limit(0,20)
|
||
->select();
|
||
return json($list);
|
||
}
|
||
public function bindingapplystorage(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['warehouseId'];
|
||
$ApplystorageModel = new \app\common\model\wms\Applystorage;
|
||
$ApplystorageLocalModel = new \app\common\model\Applystorage;
|
||
// 启动事务
|
||
Db::startTrans();
|
||
try {
|
||
$data = $ApplystorageLocalModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"id"=>$params["id"],"APPLYSTORAGEID"=>0])->lock(true)->find();
|
||
if(!$data){
|
||
$msg = "绑定失败,找不到预收货单";
|
||
}else{
|
||
$data->save(["APPLYSTORAGEID"=>$params["applyid"]]);
|
||
$nocreate = $ApplystorageModel->where(["ID"=>$params["applyid"],"STATUS"=>0])->find();
|
||
if($nocreate){
|
||
$data = Wsdl::webservice([$WAREHOUSEID,$params["applyid"]],'createRandom');
|
||
}
|
||
$msg = "绑定成功";
|
||
}
|
||
// 提交事务
|
||
Db::commit();
|
||
echo '事务提交成功';
|
||
} catch (\Exception $e) {
|
||
// 发生异常时回滚事务
|
||
Db::rollback();
|
||
$msg = "绑定失败,未知原因";
|
||
}
|
||
return json(["status"=>1,"msg"=>$msg]);
|
||
}
|
||
public function getpalletsList(){
|
||
$ApplystorageModel = new \app\common\model\wms\Applystorage;
|
||
$ApplystorageLocalModel = new \app\common\model\Applystorage;
|
||
$PutindetailModel = new \app\common\model\wms\Putindetail;
|
||
$palletsMode = new \app\common\model\Pallets;
|
||
$wmsStorageModel = new \app\common\model\wms\Storage;
|
||
$params=$this->request->post();
|
||
$applyid = $params['id'];
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$data = $ApplystorageLocalModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"id"=>$applyid])->find();
|
||
if(!$data){
|
||
return json(["status"=>-1,"msg"=>"无收货单记录"]);
|
||
}
|
||
$id = $data['APPLYSTORAGEID'];
|
||
$list = $palletsMode->where(["applystorageid"=>$applyid])->select();
|
||
$skus = $PutindetailModel->field('goods.NAME as NAME,stock.IMG as IMG,stock.BARCODE as barcode,a.COUNT as COUNT,a.STOCKID as STOCKID')
|
||
->alias('a')
|
||
->join('yj_stock stock', 'stock.STOCKID = a.STOCKID')
|
||
->join('yj_goods goods', 'goods.GOODSID = stock.GOODSID')
|
||
->where(['a.APPLYSTORAGEID'=>$id])
|
||
->select();
|
||
$skuids = [];
|
||
|
||
foreach ($skus as $r){
|
||
array_push($skuids,$r['STOCKID']);
|
||
$r["putin"] = 0;
|
||
$r["pallets"] = 0;
|
||
}
|
||
$storages = $wmsStorageModel->field('sum(ACTUALCOUNT) as ACTUALCOUNT,STOCKID')->where("STOCKID","in",$skuids)->where(["APPLYSTORAGEID"=>$id])->group("STOCKID")->select();
|
||
foreach ($skus as $r){
|
||
foreach ($storages as $rr){
|
||
if($r["STOCKID"]==$rr["STOCKID"]){
|
||
$r["putin"] = intval($rr["ACTUALCOUNT"]);
|
||
}
|
||
}
|
||
}
|
||
|
||
$storages2 = $palletsMode->field('sum(count) as ACTUALCOUNT,STOCKID')->where("STOCKID","in",$skuids)->where(["applystorageid"=>$applyid,"status"=>1])->group("STOCKID")->select();
|
||
foreach ($skus as $r){
|
||
foreach ($storages2 as $rr){
|
||
if($r["STOCKID"]==$rr["STOCKID"]){
|
||
$r["pallets"] = intval($rr["ACTUALCOUNT"]);
|
||
}
|
||
}
|
||
}
|
||
return json(["Pallets"=>$list,"skus"=>$skus]);
|
||
}
|
||
public function checkbind(){
|
||
$ApplystorageModel = new \app\common\model\wms\Applystorage;
|
||
$ApplystorageLocalModel = new \app\common\model\Applystorage;
|
||
$palletsMode = new \app\common\model\Pallets;
|
||
$params=$this->request->post();
|
||
$applyid = $params['id'];
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$data = $ApplystorageLocalModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"id"=>$applyid])->find();
|
||
if(!$data){
|
||
return json(["status"=>-1,"msg"=>"无收货单记录"]);
|
||
}
|
||
$id = $data['APPLYSTORAGEID'];
|
||
if($id>0){
|
||
return 1;
|
||
}else{
|
||
return 0;
|
||
}
|
||
}
|
||
public function stores(){
|
||
if ($this->request->isPost()){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$StoreModel = new \app\common\model\wms\Warestore;
|
||
$list = $StoreModel->with(['employees'])->where(["WAREHOUSEID"=>$WAREHOUSEID])->select();
|
||
return json($list);
|
||
}
|
||
}
|
||
|
||
public function confirmPutInR(){
|
||
$palletsMode = new \app\common\model\Pallets;
|
||
$params=$this->request->post();
|
||
$xm = $params['xm'];
|
||
$data = Wsdl::webservicepda([$params['userid'],$params['serialNum'],$params['spaceId'],$params['storages'],$params['scrq']],"confirmPutInR");
|
||
if($data==1){
|
||
$pallet = $palletsMode->where(["id"=>substr($xm, 2)])->find();
|
||
$pallet->save(["status"=>0]);
|
||
}
|
||
return $data;
|
||
}
|
||
public function sto_galaxy_receive(){
|
||
$params=$this->request->post();
|
||
$waybillNo = $params["waybillNo"];
|
||
$weight = $params["weight"];
|
||
$opTime = date('Y-m-d H:i:s');
|
||
$url = "https://cloudinter-linkgateway.sto.cn/gateway/link.do";
|
||
$orders = [[$waybillNo,$weight]];
|
||
$waybillNos = [];
|
||
foreach ($orders as $r){
|
||
array_push($waybillNos,["waybillNo"=>$r[0],"weight"=>$r[1],"opTime"=>$opTime]);
|
||
}
|
||
$subscribeInfoList = [
|
||
"whCode"=>"CN5400",
|
||
"orgCode"=>"510902",
|
||
"userCode"=>"5109024514",
|
||
"packages"=>$waybillNos
|
||
];
|
||
$content = json_encode($subscribeInfoList);
|
||
$secret='TgKCcea1wgmhK7vauDSKitbSgwzNBKHP';//签名
|
||
$requsetData = [
|
||
'api_name'=>'GALAXY_CANGKU_AUTO_NEW',
|
||
'content'=>$content,
|
||
'from_appkey'=>'CAKvftdLKGgzWSV',
|
||
'from_code'=>'CAKvftdLKGgzWSV',
|
||
'to_appkey'=>'galaxy_receive',
|
||
'to_code'=>'galaxy_receive',
|
||
'data_digest'=>base64_encode(md5($content . $secret, true)),
|
||
];
|
||
$res = Http::post($url,$requsetData);
|
||
return $res;
|
||
}
|
||
public function sto_billcode_open(){
|
||
$url = "https://cloudinter-linkgateway.sto.cn/gateway/link.do";
|
||
$subscribeInfoList = [
|
||
"waybillNoList"=>[
|
||
"773329769493455"
|
||
]
|
||
];
|
||
$content = json_encode($subscribeInfoList);
|
||
$secret='TgKCcea1wgmhK7vauDSKitbSgwzNBKHP';//签名
|
||
$requsetData = [
|
||
'api_name'=>'STO_TRACE_QUERY_COMMON',
|
||
'content'=>$content,
|
||
'from_appkey'=>'CAKvftdLKGgzWSV',
|
||
'from_code'=>'CAKvftdLKGgzWSV',
|
||
'to_appkey'=>'sto_trace_query',
|
||
'to_code'=>'sto_trace_query',
|
||
'data_digest'=>base64_encode(md5($content . $secret, true)),
|
||
];
|
||
$res = Http::post($url,$requsetData);
|
||
return $res;
|
||
}
|
||
public function printAndGalaxyReceive(){
|
||
$params=$this->request->post();
|
||
if(!$params){
|
||
$params = json_decode(file_get_contents('php://input'), true);
|
||
}
|
||
/*$WAREHOUSEID = isset($params['WAREHOUSEID'])?$params['WAREHOUSEID']:'';
|
||
$SN = isset(str_replace("-1-1-", "", $params['sn']))?str_replace("-1-1-", "", $params['sn']):'';
|
||
$model = new \app\common\model\wms\Order;
|
||
$WarehouseModel = new \app\common\model\Warehouse;
|
||
$WAREHOUSEconfig = $WarehouseModel->where(['WAREHOUSEID'=>$WAREHOUSEID])->find();
|
||
if(!$WAREHOUSEconfig){
|
||
return false;
|
||
}
|
||
$GRAB = $model->where(["GRABNUM"=>$SN,"WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
if($GRAB){
|
||
$orders = $model->field('ID')->where(["GRABNUM"=>$SN,"WAREHOUSEID"=>$WAREHOUSEID,"FLAG"=>0])->select();
|
||
}else{
|
||
$orders = $model->field('ID')->where(["POSTNUM"=>$SN,"WAREHOUSEID"=>$WAREHOUSEID,"FLAG"=>0])->select();
|
||
}
|
||
if($orders){
|
||
foreach ($orders as $r){
|
||
$this->express_redis->lpush('GalaxyReceive_'.$WAREHOUSEID,$r["ID"]);
|
||
}
|
||
$this->express_redis->close();
|
||
}*/
|
||
return 1;
|
||
}
|
||
public function sendAndSubscribe(){
|
||
/*
|
||
$params=$this->request->post();
|
||
if(!$params){
|
||
$params = json_decode(file_get_contents('php://input'), true);
|
||
}
|
||
$WAREHOUSEID = isset($params['WAREHOUSEID'])?$params['WAREHOUSEID']:'';
|
||
$SN = isset($params['sn'])?str_replace("-1-1-", "", $params['sn']):'';
|
||
$model = new \app\common\model\wms\Order;
|
||
$WarehouseModel = new \app\common\model\Warehouse;
|
||
$ItemsinfoModel = new \app\common\model\stocks\Weightandpack;
|
||
$WAREHOUSEconfig = $WarehouseModel->where(['WAREHOUSEID'=>$WAREHOUSEID])->find();
|
||
if(!$WAREHOUSEconfig){
|
||
return 0;
|
||
}
|
||
$GRAB = $model->where(["GRABNUM"=>$SN,"WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
if($GRAB){
|
||
$orders = $model->field('ID,WEIGHT,STOCKS')->where(["GRABNUM"=>$SN,"WAREHOUSEID"=>$WAREHOUSEID,"FLAG"=>0])->select();
|
||
}else{
|
||
$orders = $model->field('ID,WEIGHT,STOCKS')->where(["POSTNUM"=>$SN,"WAREHOUSEID"=>$WAREHOUSEID,"FLAG"=>0])->select();
|
||
}
|
||
if($orders){
|
||
foreach ($orders as $r){
|
||
$this->express_redis->lpush('Subscribe_'.$WAREHOUSEID,$r["ID"]);
|
||
$unWeight = $ItemsinfoModel->where(["STOCKS"=>$r["STOCKS"],"WEIGHT"=>0])->find();
|
||
if($unWeight){
|
||
$unWeight->save(["WEIGHT"=>$r["WEIGHT"]]);
|
||
}
|
||
}
|
||
$this->express_redis->close();
|
||
}*/
|
||
return 1;
|
||
}
|
||
public function upateStockYXQ(){
|
||
$params=$this->request->post();
|
||
$STOCKID = isset($params['STOCKID'])?$params['STOCKID']:0;
|
||
if(!$STOCKID){
|
||
return 0;
|
||
}
|
||
$model = new \app\common\model\wms\Stock;
|
||
$STOCK = $model->where(["STOCKID"=>$STOCKID])->find();
|
||
if(!$STOCK){
|
||
return 0;
|
||
}
|
||
$YXQ = isset($params['production_date'])?$params['production_date']:0;
|
||
$updataData = [$STOCKID,$STOCK["WEIGHT"],0,0,0,$STOCK["IMG"],$YXQ];
|
||
$data = Wsdl::webservice([$STOCKID,$STOCK["WEIGHT"],0,0,0,$STOCK["IMG"],$YXQ],'upateStock');
|
||
return json($data);
|
||
}
|
||
public function boxs(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$PackModel = new \app\common\model\wms\Pack;
|
||
$rows = $PackModel->field('NAME as text,BARCODE as value')->where(["WAREHOUSEID"=>$WAREHOUSEID])->select();
|
||
return json($rows);
|
||
}
|
||
public function getMycount(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$userid = $params["userid"];
|
||
$WarehouseModel = new \app\common\model\Warehouse;
|
||
$WAREHOUSEconfig = $WarehouseModel->where(['WAREHOUSEID'=>$WAREHOUSEID])->find();
|
||
$workDate = ($WAREHOUSEconfig['workDate'] ?? null);
|
||
$WorksModel = new \app\common\model\workers\Works;
|
||
$count = $WorksModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"userId"=>$userid,"dabaos"=>1,"workDate"=>$workDate])->where("GRABNUM not like 'B%'")->count();
|
||
return $count;
|
||
}
|
||
public function getMycount2(){
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$userid = $params["userid"];
|
||
$WarehouseModel = new \app\common\model\Warehouse;
|
||
$WAREHOUSEconfig = $WarehouseModel->where(['WAREHOUSEID'=>$WAREHOUSEID])->find();
|
||
$workDate = ($WAREHOUSEconfig['workDate'] ?? null);
|
||
$WorksModel = new \app\common\model\workers\Works;
|
||
$count = $WorksModel->field('SUM(tiedan) AS count, COUNT(*) AS bccount')->where(["WAREHOUSEID"=>$WAREHOUSEID,"userId"=>$userid,"workDate"=>$workDate])->where("GRABNUM like 'B%'")->where("tiedan>0")->select();
|
||
return json($count);
|
||
}
|
||
public function InterceptRecord(){
|
||
$params=$this->request->post();
|
||
$code = $params["sn"];
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$status = 0;
|
||
$Ordermodel = new \app\common\model\wms\Order;
|
||
$Order1model = new \app\common\model\wms\Deliveryorder;
|
||
$data = $Ordermodel->where(["POSTNUM"=>$code])->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
if(!$data){
|
||
$data = $Order1model->where(["POSTNUM"=>$code])->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
}
|
||
$res = "";
|
||
if($data){
|
||
$isFlag = $data["FLAG"];
|
||
if($isFlag){
|
||
$status = 1;
|
||
$this->pushLanjie($data);
|
||
$res = $this->revordAndMessage($data,$WAREHOUSEID);
|
||
}else{
|
||
$status = 2;
|
||
}
|
||
}
|
||
return json(["code"=>$code,"status"=>$status,"res"=>$res]);
|
||
}
|
||
public function NotifiSplitOrder(){
|
||
$WAREHOUSEID = $this->request->get("WAREHOUSEID");
|
||
$CREATIONDATE = $this->redis->get("lasttime");
|
||
$Expressmodel = new \app\common\model\wms\Express;
|
||
$Ordermodel = new \app\common\model\wms\Order;
|
||
$Ordermodel2 = new \app\common\model\wms\Deliveryorder;
|
||
$RoomsModel = new \app\common\model\Rooms;
|
||
$datas = $Expressmodel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where('CREATIONDATE>'.$CREATIONDATE)->where('ORIGINPOSTNUM<>""')->order("CREATIONDATE","desc")->select();
|
||
if($datas){
|
||
$this->redis->set("lasttime",$datas[0]["CREATIONDATE"]);
|
||
}
|
||
$ORIGINPOSTNUM = [];
|
||
foreach ($datas as $r){
|
||
if(!array_key_exists($r['ORIGINPOSTNUM'],$ORIGINPOSTNUM)){
|
||
$ORIGINPOSTNUM[$r['ORIGINPOSTNUM']]["items"] = [$r["POSTNUM"]];
|
||
$ORIGINPOSTNUM[$r['ORIGINPOSTNUM']]["STOREID"] = $r["STOREID"];
|
||
$ORIGINPOSTNUM[$r['ORIGINPOSTNUM']]["TRADEORDER"] = $r["TRADEORDER"];
|
||
}else{
|
||
array_push($ORIGINPOSTNUM[$r['ORIGINPOSTNUM']]["items"],$r["POSTNUM"]);
|
||
}
|
||
}
|
||
try{
|
||
foreach($ORIGINPOSTNUM as $k=> $r){
|
||
if($r["STOREID"]>0){
|
||
$SOURCEORDERCODE = "";
|
||
$tmporder = $Ordermodel->where(["POSTNUM"=>$k])->find();
|
||
if(!$tmporder){
|
||
$tmporder = $Ordermodel2->where(["POSTNUM"=>$k])->find();
|
||
}
|
||
if($tmporder){
|
||
$SOURCEORDERCODE = " 平台交易单号:".$tmporder["SOURCEORDERCODE"];
|
||
}
|
||
$msg = "主面单号:".$k.$SOURCEORDERCODE."\n已拆分为子面单号\n".implode("\n",$r["items"])."\n发出,望通知顾客。";
|
||
$this->pushMsgToOwner($msg, $WAREHOUSEID, $r["STOREID"]);
|
||
$ORIGINPOSTNUM[$k]["msg"] = $msg;
|
||
}
|
||
}
|
||
}
|
||
catch(Exception $e){
|
||
return $e;
|
||
}
|
||
return json($ORIGINPOSTNUM);
|
||
}
|
||
private function pushLanjie($data){
|
||
$this->redis->lpush("lanjies",json_encode($data));
|
||
}
|
||
|
||
private function createExceptionWmsOrder($status,$order,$text,$postnum,$isretry=false){
|
||
$this->Exceptionwmsorder = new \app\common\model\wms\Exceptionwmsorder;
|
||
$res = $this->Exceptionwmsorder->where(["WMSORDERID"=>$order,"TYPE"=>$status])->find();
|
||
if(!$res){
|
||
$data = [$status,$text,"","",106300,$order];
|
||
$ress = Wsdl::webservice($data,'createExceptionWmsOrder');
|
||
if($ress==0){
|
||
$this->redis->lpush("createExceptionWmsOrderBack",json_encode([$postnum,$data,$ress]));
|
||
if(!$isretry){
|
||
$this->createExceptionWmsOrder($status,$order,$text,$postnum,true);
|
||
}
|
||
}
|
||
}
|
||
return $ress;
|
||
}
|
||
private function revordAndMessage($data,$WAREHOUSEID){
|
||
|
||
$msg = $this->toMsg("44379703923@chatroom",$data["POSTNUM"]."库内拦截成功");
|
||
$res = $this->redis->lpush("Message",json_encode($msg));
|
||
return $res;
|
||
//拦截工单完结接口
|
||
}
|
||
public function toMsg($to,$text,$atid=""){
|
||
return [
|
||
"method"=>"sendText",
|
||
"wxid"=> $to,
|
||
"msg"=> $text,
|
||
"atid"=> $atid,
|
||
"pid"=> 0
|
||
];
|
||
}
|
||
public function tongbuWmsOrder(){
|
||
$WAREHOUSEID = $this->request->get('WAREHOUSEID');
|
||
$ress = Wsdl::webservice([$WAREHOUSEID],'tongbuWmsOrder');
|
||
return json($ress);
|
||
}
|
||
/**
|
||
* 自动创建快递单号
|
||
* 根据仓库配置和时间条件,自动为符合条件的订单生成快递单号
|
||
* 主要处理逻辑:
|
||
* 1. 判断当前时间是否在18:00-0:00之间(不出单时间段)
|
||
* 2. 在出单时间段内,遍历所有仓库处理符合条件的订单
|
||
* 3. 调用外部接口批量生成快递单号
|
||
*
|
||
* @return \think\response\Json 返回处理结果数组和一次性处理标志
|
||
*/
|
||
public function AutoCreatePostNum(){
|
||
|
||
// 判断当前时间是否在18:00-0:00之间(不出单时间段)
|
||
$current_time = time();
|
||
$current_hour = date('H', $current_time);
|
||
$hour18_today = strtotime(date("Y-m-d") . " 18:00:00");
|
||
$hour0_tomorrow = strtotime(date("Y-m-d") . " 23:59:59") + 1; // 次日0:00
|
||
|
||
// 如果当前时间在18:00-0:00之间,直接返回空结果
|
||
if ($current_time >= $hour18_today && $current_time < $hour0_tomorrow) {
|
||
// 记录日志(可选)
|
||
// Log::info("当前时间{$current_hour}点在18:00-0:00不出单时间段,跳过处理");
|
||
$this->redis->set("current_hour", $current_hour);
|
||
$this->redis->set("skip_reason", "18:00-0:00不出单时间段");
|
||
return json([[], [], [], false, "skip" => true, "reason" => "18:00-0:00不出单时间段"]);
|
||
}
|
||
|
||
// 初始化模型
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$WAREHOUSEMODEL = new \app\common\model\Warehouse;
|
||
|
||
// 获取所有仓库配置
|
||
$WAREHOUSES = $WAREHOUSEMODEL->select();
|
||
|
||
// 初始化结果数组
|
||
$datas = []; // 存储18:00前订单的处理结果
|
||
$datas2 = []; // 存储一键生成订单的处理结果
|
||
$datas3 = []; // 存储18:00-21:30订单的处理结果
|
||
|
||
// 获取当前小时并存入Redis
|
||
$current_hour = date('H', time());
|
||
$this->redis->set("current_hour", $current_hour);
|
||
|
||
// 设置时间点
|
||
// 前一天18:00(减去24小时)
|
||
$hour18 = strtotime(date("Y-m-d"). " 18:00:00") - 60*60*24;
|
||
// 当天21:30
|
||
$hour21half = strtotime(date("Y-m-d"). " 21:30:00");
|
||
|
||
// 格式化时间戳(前补两个0,后补三个0)
|
||
$time = "00" . $hour18 . "000";
|
||
$time2 = "00" . $hour21half . "000";
|
||
|
||
// 如果当前时间大于7点,使用当天18:00的时间
|
||
if($current_hour > 7){
|
||
$time = "00" . strtotime(date("Y-m-d"). " 18:00:00") . "000";
|
||
$this->redis->set("time", $time);
|
||
}
|
||
|
||
// 判断是否为凌晨0-7点的一次性处理时间
|
||
$onceTime = false;
|
||
if($current_hour <= 7 && $current_hour >= 0){
|
||
$onceTime = true;
|
||
$this->redis->set("onceTime", $onceTime);
|
||
}
|
||
|
||
// 遍历所有仓库
|
||
foreach ($WAREHOUSES as $WAREHOUSE){
|
||
// 处理仓库排除的快递类型条件
|
||
$exclude = explode("|", $WAREHOUSE["exclude_express"]);
|
||
$where = [];
|
||
foreach ($exclude as $r){
|
||
array_push($where, 'LEAVEMESSAGE not like "%'.$r.'%"');
|
||
}
|
||
$where_str = implode(" and ", $where);
|
||
|
||
// ========== 处理普通自动生成快递单的店铺 ==========
|
||
$STOREIDS = explode(",", $WAREHOUSE["autoCreatePostnumStoreId"]);
|
||
foreach ($STOREIDS as $STOREID){
|
||
// 查询符合条件的订单ID(18:00前的订单)
|
||
$IDS = $OrderModel->field("ID")
|
||
->where($where_str)
|
||
->where([
|
||
"POSTFLAG" => 0, // 未生成快递单号
|
||
"STOREID" => $STOREID, // 指定店铺
|
||
"FLAG" => 0, // 有效订单
|
||
"ISLOCK" => 0, // 未锁定
|
||
"DISPLAYFLAG" => 0 // 显示状态
|
||
])
|
||
->where("CREATIONDATE<=".$time." and SOURCECODE <>'Z01' and SOURCECODE <>'Z15' and OPERATERECORDS not like \"%克隆%\"")
|
||
->limit(1000)
|
||
->select();
|
||
|
||
// 提取订单ID数组
|
||
$orders_ids = [];
|
||
foreach($IDS as $ID){
|
||
array_push($orders_ids, $ID["ID"]);
|
||
}
|
||
|
||
// 每50个订单ID为一组进行批量处理
|
||
$chunks = array_chunk($orders_ids, 50);
|
||
foreach ($chunks as $chunk){
|
||
$ids = implode(",", $chunk);
|
||
// 调用外部接口生成快递单号
|
||
$data = Wsdl::webservice([
|
||
$WAREHOUSE["WAREHOUSEID"], // 仓库ID
|
||
intval($WAREHOUSE["operatorID"]), // 操作员ID
|
||
$ids // 订单ID列表
|
||
], 'createPostNum');
|
||
|
||
// 保存处理结果
|
||
array_push($datas, ["return"=>$data, "IDS"=>$ids]);
|
||
}
|
||
}
|
||
|
||
// ========== 处理18:00-21:30时间段订单的店铺 ==========
|
||
$STOREIDS = explode(",", $WAREHOUSE["autoCreatePostnumStoreId2"]);
|
||
foreach ($STOREIDS as $STOREID){
|
||
// 查询18:00-21:30时间段的订单
|
||
$IDS = $OrderModel->field("ID")
|
||
->where($where_str)
|
||
->where([
|
||
"POSTFLAG" => 0,
|
||
"STOREID" => $STOREID,
|
||
"FLAG" => 0,
|
||
"ISLOCK" => 0,
|
||
"DISPLAYFLAG" => 0
|
||
])
|
||
->where("CREATIONDATE>".$time." and CREATIONDATE<=".$time2." and SOURCECODE <>'Z01' and SOURCECODE <>'Z15' and OPERATERECORDS not like \"%克隆%\"")
|
||
->limit(1000)
|
||
->select();
|
||
|
||
$orders_ids = [];
|
||
foreach($IDS as $ID){
|
||
array_push($orders_ids, $ID["ID"]);
|
||
}
|
||
|
||
$chunks = array_chunk($orders_ids, 50);
|
||
foreach ($chunks as $chunk){
|
||
$ids = implode(",", $chunk);
|
||
$data = Wsdl::webservice([$WAREHOUSE["WAREHOUSEID"], intval($WAREHOUSE["operatorID"]), $ids], 'createPostNum');
|
||
array_push($datas3, ["return"=>$data, "IDS"=>$ids]);
|
||
}
|
||
}
|
||
|
||
// ========== 处理一键生成快递单的店铺 ==========
|
||
$STOREIDS2 = explode(",", $WAREHOUSE["autoCreateOnePostnumStoreId"]);
|
||
foreach ($STOREIDS2 as $STOREID){
|
||
// 查询所有符合条件的订单(不限时间)
|
||
$IDS = $OrderModel->field("ID")
|
||
->where($where_str)
|
||
->where([
|
||
"POSTFLAG" => 0,
|
||
"STOREID" => $STOREID,
|
||
"FLAG" => 0,
|
||
"ISLOCK" => 0,
|
||
"DISPLAYFLAG" => 0
|
||
])
|
||
->where("SOURCECODE <>'Z01' and SOURCECODE <>'Z15' and OPERATERECORDS not like \"%克隆%\"")
|
||
->limit(1000)
|
||
->select();
|
||
|
||
$orders_ids = [];
|
||
foreach($IDS as $ID){
|
||
array_push($orders_ids, $ID["ID"]);
|
||
}
|
||
|
||
// 每10个订单ID为一组(比普通处理更小的批量)
|
||
$chunks = array_chunk($orders_ids, 10);
|
||
foreach ($chunks as $chunk){
|
||
$ids = implode(",", $chunk);
|
||
$data = Wsdl::webservice([$WAREHOUSE["WAREHOUSEID"], intval($WAREHOUSE["operatorID"]), $ids], 'createPostNum');
|
||
array_push($datas2, ["return"=>$data, "IDS"=>$ids]);
|
||
}
|
||
}
|
||
}
|
||
|
||
// 返回所有处理结果
|
||
return json([$datas, $datas2, $datas3, $onceTime]);
|
||
}
|
||
public function autocheckStorag(){
|
||
$StorageModel = new \app\common\model\wms\Storage;
|
||
$WAREHOUSEMODEL = new \app\common\model\Warehouse;
|
||
$WAREHOUSES = $WAREHOUSEMODEL->select();
|
||
$datas = [];
|
||
$RoomsModel = new \app\common\model\Rooms;
|
||
foreach ($WAREHOUSES as $WAREHOUSE){
|
||
$STOREIDS = explode(",",$WAREHOUSE["autocheckStoragStoreId"]);
|
||
foreach ($STOREIDS as $STOREID){
|
||
$SKUS = $StorageModel->field('sum(copycount) as count,storege.STOCKID as STOCKID,goods.NAME as NAME,stock.SAFECOUNT as SAFECOUNT,stock.WARESTOREID,stock.COLOR as COLOR,stock.STYLE as STYLE,stock.BARCODE as BARCODE')->alias('storege')->join('yj_goods goods','goods.GOODSID=storege.GOODSID')->join('yj_stock stock','stock.STOCKID=storege.STOCKID')->where(["STOREID"=>$STOREID])->where("stock.WARESTOREID>0")->where("stock.SAFECOUNT>0")->group("STOCKID")->select();
|
||
if(count($SKUS)>0){
|
||
$msg = null;
|
||
$SKUSS = [];
|
||
$now = date('Y-m-d H:i:s');
|
||
$STR = "{$now}库存预警:\n";
|
||
$index = 1;
|
||
foreach ($SKUS as $r){
|
||
if(intval($r["count"]<$r["SAFECOUNT"])){
|
||
$STR.="{$index}. {$r['NAME']} {$r['BARCODE']} {$r['STYLE']} {$r['COLOR']} ,已不足{$r['SAFECOUNT']};\n\n";
|
||
array_push($SKUSS,$r);
|
||
$index++;
|
||
}
|
||
}
|
||
if(count($SKUSS)==0){
|
||
continue;
|
||
}
|
||
$STR.="此消息为天豹云仓提醒补货,数据仅取当前状态,如已补货在途,请忽略;如需修改库存预警数量,请联系其他客服。";
|
||
$this->pushMsgToOwner($STR, $WAREHOUSE["WAREHOUSEID"], $STOREID,"isStorge");
|
||
array_push($datas,$STR);
|
||
}
|
||
}
|
||
|
||
}
|
||
$this->autocheckStorag2();
|
||
return json($datas);
|
||
}
|
||
public function autocheckStorag2(){
|
||
$StorageModel = new \app\common\model\wms\Storage;
|
||
$WAREHOUSEMODEL = new \app\common\model\Warehouse;
|
||
$WAREHOUSES = $WAREHOUSEMODEL->select();
|
||
$datas = [];
|
||
$RoomsModel = new \app\common\model\Rooms;
|
||
foreach ($WAREHOUSES as $WAREHOUSE){
|
||
$STOREIDS2 = explode(",",$WAREHOUSE["autocheckStoragStoreId2"]);
|
||
$STOREIDS2 = array_filter($STOREIDS2);
|
||
$now = date('Y-m-d H:i:s');
|
||
foreach ($STOREIDS2 as $STOREID){
|
||
$fileUrl = $this->putout_putin_storage7($STOREID);
|
||
|
||
if($fileUrl){
|
||
$STR="{$now}补货预警文件已发送,注意接收。";
|
||
$room = $RoomsModel->where(["STOREID"=>$STOREID,"isStorge"=>1])->find();
|
||
array_push($datas,$STOREID);
|
||
if(!$room){
|
||
$room = $RoomsModel->where(["STOREID"=>$STOREID,"isMain"=>1])->find();
|
||
}
|
||
if(!$room){
|
||
$room = $RoomsModel->where(["STOREID"=>$STOREID])->find();
|
||
}
|
||
if($room){
|
||
[$aiteUser,$atids] = $this->getAUser($room["room_id"],"采购");
|
||
if($atids){
|
||
$STR.=$aiteUser;
|
||
$msg = $this->toMsg($room["room_id"],$STR,$atids);
|
||
}else{
|
||
$msg = $this->toMsg($room["room_id"],$STR);
|
||
}
|
||
$msg2 = $this->backFile(["fromid"=>$room["room_id"]],$fileUrl);
|
||
}
|
||
$this->redis->lpush("Message",json_encode($msg2));
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
array_push($datas,$STR);
|
||
}
|
||
}
|
||
}
|
||
return json($datas);
|
||
}
|
||
public function getAUser($room_id,$name){
|
||
$users = $this->getRoomUsers($room_id);
|
||
$a_user = [];
|
||
$a_userName = [];
|
||
foreach ($users as $user){
|
||
if(strpos($user["nickName2"],$name)!==false){
|
||
array_push($a_user,$user['wxid']);
|
||
array_push($a_userName,"@".$user['nickName2']);
|
||
}
|
||
}
|
||
$atids = implode(",",$a_user);
|
||
$aiteUser = implode("",$a_userName);
|
||
return [$aiteUser,$atids];
|
||
}
|
||
private function getRoomUsers($room_id){
|
||
$requsetData = [
|
||
'method'=>'getGroupUser',
|
||
'wxid'=>$room_id,
|
||
'pid'=>0
|
||
];
|
||
$header = [
|
||
'Content-Type: application/x-www-form-urlencoded; charset=UTF-8'
|
||
];
|
||
$options = [
|
||
CURLOPT_HTTPHEADER => $header
|
||
];
|
||
$urlEncodedString = http_build_query($requsetData);
|
||
$url = "http://{$this->wechatServer}:8203/api?json&key={$this->key}";
|
||
$res = Http::sendRequest($url,$urlEncodedString,'POST',$options);
|
||
return json_decode($res["msg"],true)["data"];
|
||
}
|
||
public function createDatas($times=""){
|
||
$OrderModel = new \app\common\model\wms\Deliveryorder;
|
||
$WAREHOUSEMODEL = new \app\common\model\Warehouse;
|
||
$poscountMODEL = new \app\common\model\datas\Poscount;
|
||
$OrderstructureModel = new \app\common\model\datas\Orderstructure;
|
||
$OrdercomboModel = new \app\common\model\datas\Ordercombo;
|
||
$PackModel = new \app\common\model\datas\Pack;
|
||
$HisorderModel = new \app\common\model\Hisorder;
|
||
|
||
$WAREHOUSES = $WAREHOUSEMODEL->where(["auto_datas" => 1])->select();
|
||
$yesterday_start = $times ? $times : strtotime('yesterday', strtotime('00:00:00'));
|
||
$sendStart = '00' . $yesterday_start . '000';
|
||
$sendEnd = '00' . ($yesterday_start + 86399) . '000';
|
||
|
||
foreach ($WAREHOUSES as $WAREHOUSE) {
|
||
$warehouseId = $WAREHOUSE["WAREHOUSEID"];
|
||
$data = $OrderModel
|
||
->field('ID,ITEMS,POSTCODE,PACKID,WEIGHT,STOREID,SOURCEORDERCODE,PROVINCE,POSTNUM,SENDDATE,CREATIONDATE')
|
||
->where(["WAREHOUSEID" => $warehouseId, "STATUS" => 1, "DISPLAYFLAG" => 0, "FLAG" => 0])
|
||
->where('SENDDATE', 'BETWEEN', [$sendStart, $sendEnd])
|
||
->select();
|
||
|
||
if (empty($data)) {
|
||
continue;
|
||
}
|
||
|
||
$storeGroups = [];
|
||
$orderStats = [];
|
||
|
||
foreach ($data as $r) {
|
||
$metrics = $this->buildCreateDatasOrderMetrics($r["ITEMS"], $r["WEIGHT"]);
|
||
$storeId = $r["STOREID"];
|
||
$orderId = $r["ID"];
|
||
|
||
if (!isset($storeGroups[$storeId])) {
|
||
$storeGroups[$storeId] = [
|
||
"w1" => ["w1" => 0, "w2" => 0, "w3" => 0, "w4" => 0],
|
||
"w2" => ["w1" => 0, "w2" => 0, "w3" => 0, "w4" => 0],
|
||
"postcodes" => [],
|
||
"items" => [],
|
||
"packs" => [],
|
||
];
|
||
}
|
||
|
||
$storeGroups[$storeId]["w1"][$metrics["goods_bucket"]]++;
|
||
// 保持原逻辑行为:w2 依赖 w1 同 bucket 的计数
|
||
$storeGroups[$storeId]["w2"][$metrics["stocks_bucket"]] = $storeGroups[$storeId]["w1"][$metrics["stocks_bucket"]] + 1;
|
||
|
||
$postcode = $r["POSTCODE"];
|
||
if (!isset($storeGroups[$storeId]["postcodes"][$postcode])) {
|
||
$storeGroups[$storeId]["postcodes"][$postcode] = [
|
||
"POSTCODE" => $postcode,
|
||
"count" => 0,
|
||
"weights" => ["w1" => 0, "w2" => 0, "w3" => 0, "w4" => 0, "w5" => 0, "w6" => 0, "w7" => 0, "w8" => 0],
|
||
];
|
||
}
|
||
$storeGroups[$storeId]["postcodes"][$postcode]["count"]++;
|
||
$storeGroups[$storeId]["postcodes"][$postcode]["weights"][$metrics["weight_bucket"]]++;
|
||
|
||
$stocksKey = $metrics["stocks_signature"];
|
||
if (!isset($storeGroups[$storeId]["items"][$stocksKey])) {
|
||
$storeGroups[$storeId]["items"][$stocksKey] = ["STOCKS" => $stocksKey, "count" => 1, "ITEMS" => $r["ITEMS"]];
|
||
} else {
|
||
$storeGroups[$storeId]["items"][$stocksKey]["count"]++;
|
||
}
|
||
|
||
$packId = $r["PACKID"];
|
||
if (!isset($storeGroups[$storeId]["packs"][$packId])) {
|
||
$storeGroups[$storeId]["packs"][$packId] = ["PACKID" => $packId, "count" => 1];
|
||
} else {
|
||
$storeGroups[$storeId]["packs"][$packId]["count"]++;
|
||
}
|
||
|
||
$orderStats[$orderId] = $metrics;
|
||
}
|
||
|
||
foreach ($storeGroups as $storeId => $group) {
|
||
$lineTmp = $OrderstructureModel
|
||
->where(["create_date" => $yesterday_start, "WAREHOUSEID" => $warehouseId, "STOREID" => $storeId])
|
||
->find();
|
||
if (!$lineTmp) {
|
||
$lineTmp = new \app\common\model\datas\Orderstructure;
|
||
}
|
||
$lineTmp->save([
|
||
"create_date" => $yesterday_start,
|
||
"w1" => json_encode($group["w1"]),
|
||
"w2" => json_encode($group["w2"]),
|
||
"WAREHOUSEID" => $warehouseId,
|
||
"STOREID" => $storeId,
|
||
]);
|
||
|
||
foreach ($group["postcodes"] as $row) {
|
||
$line = $poscountMODEL
|
||
->where(["create_date" => $yesterday_start, "postcode" => $row["POSTCODE"], "WAREHOUSEID" => $warehouseId, "STOREID" => $storeId])
|
||
->find();
|
||
if (!$line) {
|
||
$line = new \app\common\model\datas\Poscount;
|
||
}
|
||
$line->save([
|
||
"create_date" => $yesterday_start,
|
||
"postcode" => $row["POSTCODE"],
|
||
"count" => $row["count"],
|
||
"WAREHOUSEID" => $warehouseId,
|
||
"weights" => json_encode($row["weights"]),
|
||
"STOREID" => $storeId,
|
||
]);
|
||
}
|
||
|
||
foreach ($group["items"] as $row) {
|
||
$line = $OrdercomboModel
|
||
->where(["create_date" => $yesterday_start, "STOCKS" => $row["STOCKS"], "WAREHOUSEID" => $warehouseId, "STOREID" => $storeId])
|
||
->find();
|
||
if (!$line) {
|
||
$line = new \app\common\model\datas\Ordercombo;
|
||
}
|
||
$line->save([
|
||
"create_date" => $yesterday_start,
|
||
"STOCKS" => $row["STOCKS"],
|
||
"ITEMS" => $row["ITEMS"],
|
||
"count" => $row["count"],
|
||
"WAREHOUSEID" => $warehouseId,
|
||
"STOREID" => $storeId,
|
||
]);
|
||
}
|
||
|
||
foreach ($group["packs"] as $row) {
|
||
$line = $PackModel
|
||
->where(["create_date" => $yesterday_start, "PACKID" => $row["PACKID"], "WAREHOUSEID" => $warehouseId, "STOREID" => $storeId])
|
||
->find();
|
||
if (!$line) {
|
||
$line = new \app\common\model\datas\Pack;
|
||
}
|
||
$line->save([
|
||
"create_date" => $yesterday_start,
|
||
"PACKID" => $row["PACKID"],
|
||
"count" => $row["count"],
|
||
"WAREHOUSEID" => $warehouseId,
|
||
"STOREID" => $storeId,
|
||
]);
|
||
}
|
||
}
|
||
|
||
foreach ($data as $r) {
|
||
$metrics = isset($orderStats[$r["ID"]]) ? $orderStats[$r["ID"]] : $this->buildCreateDatasOrderMetrics($r["ITEMS"], $r["WEIGHT"]);
|
||
$line = $HisorderModel->field("ID")->where(["ID" => $r["ID"]])->find();
|
||
if (!$line) {
|
||
$HisorderModel->save([
|
||
"ID" => $r["ID"],
|
||
"PACKID" => $r["PACKID"],
|
||
"POSTNUM" => $r["POSTNUM"],
|
||
"sendDate" => intval($r["SENDDATE"]),
|
||
"createDate" => intval($r["CREATIONDATE"]),
|
||
"POSTCODE" => $r["POSTCODE"],
|
||
"WEIGHT" => $r["WEIGHT"],
|
||
"STOREID" => $r["STOREID"],
|
||
"GOODSCOUNT" => $metrics["goods_count"],
|
||
"STOCKSCOUNT" => $metrics["stocks_count"],
|
||
"ITEMS" => $r["ITEMS"],
|
||
"PROVINCE" => $r["PROVINCE"],
|
||
"SOURCEORDERCODE" => $r["SOURCEORDERCODE"],
|
||
"WAREHOUSEID" => $warehouseId,
|
||
]);
|
||
}
|
||
}
|
||
}
|
||
|
||
return $yesterday_start;
|
||
}
|
||
|
||
private function buildCreateDatasOrderMetrics($items, $weight)
|
||
{
|
||
$stockIds = [];
|
||
$stocks = explode("|", (string)$items);
|
||
$stocks = array_filter($stocks);
|
||
|
||
foreach ($stocks as $stock) {
|
||
$stockTmp = explode(",", $stock);
|
||
if (!isset($stockTmp[0]) || !isset($stockTmp[1])) {
|
||
continue;
|
||
}
|
||
$stockIds[] = [
|
||
"STOCKS" => intval($stockTmp[0]),
|
||
"COUNT" => intval($stockTmp[1]),
|
||
];
|
||
}
|
||
|
||
usort($stockIds, function ($a, $b) {
|
||
return $a['STOCKS'] - $b['STOCKS'];
|
||
});
|
||
|
||
$stocksSignature = "";
|
||
$goodsCount = 0;
|
||
$stocksCount = count($stockIds);
|
||
foreach ($stockIds as $stockId) {
|
||
$stocksSignature .= $stockId["STOCKS"] . $stockId["COUNT"];
|
||
$goodsCount += $stockId["COUNT"];
|
||
}
|
||
|
||
$weightBucket = "w1";
|
||
if ($weight > 300 && $weight <= 500) {
|
||
$weightBucket = "w2";
|
||
} elseif ($weight > 500 && $weight <= 1000) {
|
||
$weightBucket = "w3";
|
||
} elseif ($weight > 1000 && $weight <= 1500) {
|
||
$weightBucket = "w4";
|
||
} elseif ($weight > 1500 && $weight <= 2000) {
|
||
$weightBucket = "w5";
|
||
} elseif ($weight > 2000 && $weight <= 2500) {
|
||
$weightBucket = "w6";
|
||
} elseif ($weight > 2500 && $weight <= 3000) {
|
||
$weightBucket = "w7";
|
||
} elseif ($weight > 3000) {
|
||
$weightBucket = "w8";
|
||
}
|
||
|
||
$goodsBucket = "w1";
|
||
if ($goodsCount > 1 && $goodsCount <= 3) {
|
||
$goodsBucket = "w2";
|
||
} elseif ($goodsCount > 3 && $goodsCount <= 5) {
|
||
$goodsBucket = "w3";
|
||
} elseif ($goodsCount > 5) {
|
||
$goodsBucket = "w4";
|
||
}
|
||
|
||
$stocksBucket = "w1";
|
||
if ($stocksCount > 2 && $stocksCount <= 3) {
|
||
$stocksBucket = "w2";
|
||
} elseif ($stocksCount > 3 && $stocksCount <= 5) {
|
||
$stocksBucket = "w3";
|
||
} elseif ($stocksCount > 5) {
|
||
$stocksBucket = "w4";
|
||
}
|
||
|
||
return [
|
||
"stocks_signature" => $stocksSignature,
|
||
"goods_count" => $goodsCount,
|
||
"stocks_count" => $stocksCount,
|
||
"weight_bucket" => $weightBucket,
|
||
"goods_bucket" => $goodsBucket,
|
||
"stocks_bucket" => $stocksBucket,
|
||
];
|
||
}
|
||
public function autoRuku(){
|
||
|
||
$ExceptionwmsorderModel = new \app\common\model\wms\Exceptionwmsorder;
|
||
$WAREHOUSEMODEL = new \app\common\model\Warehouse;
|
||
$WAREHOUSES = $WAREHOUSEMODEL->select();
|
||
$datas = [];
|
||
$current_hour = date('H', time());
|
||
$this->redis->set("current_hour",$current_hour);
|
||
$lasttime = $this->redis->get("lasttime_createBackRecordByPostnum");
|
||
if($current_hour>8){
|
||
$time = "00".strtotime(date("Y-m-d"). " 18:00:00")."000";
|
||
$this->redis->set("time",$time);
|
||
}
|
||
$WAREHOUSESS = [];
|
||
foreach ($WAREHOUSES as $WAREHOUSE){
|
||
array_push($WAREHOUSESS,$WAREHOUSE["WAREHOUSEID"]);
|
||
}
|
||
$IDS = $ExceptionwmsorderModel->field("POSTNUM,CREATIONDATE")->where(["STATUS"=>12,"problem"=>"库内拦截成功"])->where("CREATIONDATE>".$lasttime)->where("WAREHOUSEID","in",$WAREHOUSESS)->order("CREATIONDATE","asc")->find();
|
||
return json($IDS);
|
||
}
|
||
public function getMouthExpressPrice($WAREHOUSEID=5400){
|
||
// 获取当前年份和月份
|
||
$currentYear = date("Y");
|
||
$currentMonth = date("m");
|
||
|
||
// 获取本月月初的时间戳
|
||
$firstDayOfMonth = mktime(0, 0, 0, $currentMonth, 1, $currentYear);
|
||
|
||
// 获取下个月月初的时间戳
|
||
if ($currentMonth == 12) {
|
||
$nextMonth = 1;
|
||
$nextYear = $currentYear + 1;
|
||
} else {
|
||
$nextMonth = $currentMonth + 1;
|
||
$nextYear = $currentYear;
|
||
}
|
||
$firstDayOfNextMonth = mktime(0, 0, 0, $nextMonth, 1, $nextYear);
|
||
|
||
// 将时间戳转换为微秒时间戳
|
||
$firstDayMicrotime = intval($firstDayOfMonth . "000");
|
||
$firstDayOfNextMonthMicrotime = intval($firstDayOfNextMonth . "000")-1;
|
||
$HisorderModel = new \app\common\model\Hisorder;
|
||
$all = $HisorderModel->field("count(ID) as COUNT")->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("sendDate","BETWEEN",[$firstDayMicrotime,$firstDayOfNextMonthMicrotime])->select();
|
||
return json($all);
|
||
}
|
||
public function CalculateTheAverageWeight(){
|
||
$WAREHOUSEID = $this->request->get('WAREHOUSEID');
|
||
if(!$WAREHOUSEID){
|
||
return false;
|
||
}
|
||
|
||
$yesterday_timestamp = strtotime('yesterday');
|
||
$yesterday_start_of_day = strtotime('midnight', $yesterday_timestamp);
|
||
$AverageWeightModel = new \app\common\model\datas\AverageWeight;
|
||
$SummaryModel = new \app\common\model\cost\Summary;
|
||
$HisordersummaryModel = new \app\common\model\Hisordersummary;
|
||
$RuleModel = new \app\common\model\cost\Rules;
|
||
$PackModel = new \app\common\model\cost\Pack;
|
||
$PackingModel = new \app\common\model\cost\Packing;
|
||
$Time = $this->request->get('Time')?$this->request->get('Time'):$yesterday_start_of_day;
|
||
$AverageWeightModel->where(["create_date"=>$Time,"WAREHOUSEID"=>$WAREHOUSEID])->delete();
|
||
$SummaryModel->where(["createTime"=>$Time,"WAREHOUSEID"=>$WAREHOUSEID])->delete();
|
||
$startOfMonth = strtotime('first day of', $Time);
|
||
$endOfMonth = strtotime('last day of', $Time) + 86399;
|
||
$rules = $RuleModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"STOREID"=>0])->order("weight","desc")->select();
|
||
$daydata = [];
|
||
$HisorderModel = new \app\common\model\Hisorder;
|
||
$daydata = $HisorderModel->where("sendDate","BETWEEN",[$Time.'000',($Time+86399).'999'])->select();
|
||
$averageWeight = [];
|
||
$allcount = count($daydata);
|
||
$STORES = [];
|
||
$RemainingQuantity = 0;
|
||
foreach ($rules as $rule){
|
||
array_push($averageWeight,["ruleid"=>$rule["id"],"type"=>$rule["type"],"weight"=>0,"count"=>0,"WAREHOUSEID"=>$WAREHOUSEID,"POSTCODE"=>$rule["POSTCODE"],"meney"=>0,"meney2"=>0]);
|
||
}
|
||
foreach ($daydata as $line){
|
||
$has = false;
|
||
foreach ($STORES as $k => $STORE){
|
||
if($STORE["STOREID"]==$line["STOREID"]){
|
||
$has = true;
|
||
array_push($STORES[$k]["orders"],$line);
|
||
}
|
||
}
|
||
if(!$has){
|
||
array_push($STORES,["STOREID"=>$line["STOREID"],"orders"=>[$line],"rules"=>[],"costrules"=>[],"price"=>0,"costprice"=>0,"price2"=>0,"costprice2"=>0,"packprice"=>0,"packpricecost"=>0,"packingprice"=>0]);
|
||
}
|
||
}
|
||
|
||
$datas = [];
|
||
foreach($STORES as $key => $r){
|
||
$STORESRemainingQuantity = 0;
|
||
$STORESRemainingQuantity2 = 0;
|
||
$STORESRemainingQuantity3 = 0;
|
||
$STORESRemainingQuantity4 = 0;
|
||
$rulesout = $RuleModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"STOREID"=>$r["STOREID"]])->order("weight","desc")->select();
|
||
foreach ($rulesout as $rule){
|
||
array_push($STORES[$key]["rules"],["ruleid"=>$rule["id"],"type"=>$rule["type"],"weight"=>0,"count"=>0,"WAREHOUSEID"=>$WAREHOUSEID,"POSTCODE"=>$rule["POSTCODE"],"meney"=>0,"meney2"=>0]);
|
||
}
|
||
foreach ($rules as $rule){
|
||
array_push($STORES[$key]["costrules"],["ruleid"=>$rule["id"],"type"=>$rule["type"],"weight"=>0,"count"=>0,"WAREHOUSEID"=>$WAREHOUSEID,"POSTCODE"=>$rule["POSTCODE"],"meney"=>0,"meney2"=>0]);
|
||
}
|
||
//return json($rules);die();
|
||
$rulePack = $PackModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("STOREID=0 or STOREID=".$r["STOREID"])->where("starttime<=".$Time)->where("endtime>".$Time." or endtime=0")->select();
|
||
$rulePacking = $PackingModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"STOREID"=>$r["STOREID"]])->where("starttime<=".$Time)->where("endtime>".$Time." or endtime=0")->select();
|
||
$arr_insert = [];
|
||
|
||
foreach ($r["orders"] as $key2 => $line){
|
||
[$ruleb1,$ruleb2,$ruleb3,$ruleb4,$ruleb5,$end] = $this->getOrderRule($line,$rules,$rulesout,$rulePack,$rulePacking);
|
||
|
||
$orderLine = $HisordersummaryModel->where(["ID"=>$line["ID"]])->find();
|
||
|
||
$data = [
|
||
"ID"=>$line["ID"],
|
||
"PACKID"=>$line["PACKID"],
|
||
"POSTNUM"=>$line["POSTNUM"],
|
||
"sendDate"=>$line["sendDate"],
|
||
"createDate"=>$line["createDate"],
|
||
"POSTCODE"=>$line["POSTCODE"],
|
||
"WEIGHT"=>$line["WEIGHT"],
|
||
"STOREID"=>$line["STOREID"],
|
||
"GOODSCOUNT"=>$line["GOODSCOUNT"],
|
||
"STOCKSCOUNT"=>$line["STOCKSCOUNT"],
|
||
"ITEMS"=>$line["ITEMS"],
|
||
"PROVINCE"=>$line["PROVINCE"],
|
||
"SOURCEORDERCODE"=>$line["SOURCEORDERCODE"],
|
||
"costprice"=>0,
|
||
"price"=>0,
|
||
"packprice"=>0,
|
||
"packpricecost"=>0,
|
||
"packingprice"=>0,
|
||
"WAREHOUSEID"=>$line["WAREHOUSEID"]
|
||
];
|
||
if($ruleb1){
|
||
foreach ($averageWeight as $k=> $rr){
|
||
if($rr["ruleid"]==$ruleb1["id"]){
|
||
$weight=0;
|
||
$averageWeight[$k]["count"] += 1;
|
||
$averageWeight[$k]["weight"] += $line["WEIGHT"];
|
||
$STORES[$key]["costrules"][$k]["count"] += 1;
|
||
$STORES[$key]["costrules"][$k]["weight"] += $line["WEIGHT"];
|
||
$tmpPrice = $this->getOrderPrice($line,$ruleb1,$weight);
|
||
if($ruleb1["type"]==2){
|
||
$averageWeight[$k]["meney2"] = round($tmpPrice+$averageWeight[$k]["meney2"],2);
|
||
$STORES[$key]["costprice2"] = round($tmpPrice+$STORES[$key]["costprice2"],2);
|
||
}else{
|
||
$averageWeight[$k]["meney"] = round($tmpPrice+$averageWeight[$k]["meney"],2);
|
||
$STORES[$key]["costprice"] = round($tmpPrice+$STORES[$key]["costprice"],2);
|
||
}
|
||
$data["costprice"] = $tmpPrice;
|
||
/**/
|
||
}
|
||
}
|
||
$data["costpressruleid"] = $ruleb1["id"];
|
||
$STORESRemainingQuantity4++;
|
||
}else{
|
||
$RemainingQuantity++;
|
||
$STORESRemainingQuantity2++;
|
||
}
|
||
if($ruleb2){
|
||
foreach ($STORES[$key]["rules"] as $k=> $rr){
|
||
if($rr["ruleid"]==$ruleb2["id"]){
|
||
$weight=0;
|
||
$STORES[$key]["rules"][$k]["count"] += 1;
|
||
$STORES[$key]["rules"][$k]["weight"] += $line["WEIGHT"];
|
||
$tmpPrice = $this->getOrderPrice($line,$ruleb2,$weight);
|
||
if($ruleb2["type"]==2){
|
||
$STORES[$key]["rules"][$k]["meney2"] = round($tmpPrice+$STORES[$key]["rules"][$k]["meney2"],2);
|
||
$STORES[$key]["price2"] = round($tmpPrice+$STORES[$key]["price2"],2);
|
||
}else{
|
||
$STORES[$key]["rules"][$k]["meney"] = round($tmpPrice+$STORES[$key]["rules"][$k]["meney"],2);
|
||
$STORES[$key]["price"] = round($tmpPrice+$STORES[$key]["price"],2);
|
||
}
|
||
$data["price"] = $tmpPrice;
|
||
}
|
||
}
|
||
$data["pressruleid"] = $ruleb2["id"];
|
||
$STORESRemainingQuantity3++;
|
||
}else{
|
||
$STORESRemainingQuantity++;
|
||
}
|
||
if($ruleb3){
|
||
$data["packprice"] = $ruleb3["price"];
|
||
$STORES[$key]["packprice"] = round($ruleb3["price"]+$STORES[$key]["packprice"],2);
|
||
}
|
||
if($ruleb4){
|
||
$data["packpricecost"] = $ruleb4["price"];
|
||
$STORES[$key]["packpricecost"] = round($ruleb4["price"]+$STORES[$key]["packpricecost"],2);
|
||
}
|
||
if($ruleb5){
|
||
$tmpPrice = $this->getPackingprice($line,$ruleb5);
|
||
$data["packingprice"] = $tmpPrice;
|
||
$STORES[$key]["packingprice"] = round($tmpPrice+$STORES[$key]["packingprice"],2);
|
||
}
|
||
if($orderLine){
|
||
$orderLine->save($data);
|
||
}else{
|
||
array_push($arr_insert);
|
||
}
|
||
}
|
||
$orderLine = new \app\common\model\Hisordersummary;
|
||
$orderLine->saveAll($arr_insert);
|
||
foreach ($STORES[$key]["rules"] as $rule){
|
||
if($rule["type"]==2){
|
||
$updata = [
|
||
"create_date"=>$Time,
|
||
"WAREHOUSEID"=>$WAREHOUSEID,
|
||
"count"=>$rule["count"],
|
||
"ruluid"=>$rule["ruleid"],
|
||
"weight"=>$rule["weight"],
|
||
"POSTCODE"=>$rule["POSTCODE"],
|
||
"STOREID"=>$r["STOREID"],
|
||
"iscost"=>0
|
||
];
|
||
if($rule["count"]>0){
|
||
$AverageWeightLine = new \app\common\model\datas\AverageWeight;
|
||
$AverageWeightLine->save($updata);
|
||
}
|
||
}
|
||
}
|
||
foreach ($STORES[$key]["costrules"] as $rule){
|
||
if($rule["type"]==2){
|
||
$updata = [
|
||
"create_date"=>$Time,
|
||
"WAREHOUSEID"=>$WAREHOUSEID,
|
||
"count"=>$rule["count"],
|
||
"ruluid"=>$rule["ruleid"],
|
||
"weight"=>$rule["weight"],
|
||
"POSTCODE"=>$rule["POSTCODE"],
|
||
"STOREID"=>$r["STOREID"],
|
||
"iscost"=>1
|
||
];
|
||
if($rule["count"]>0){
|
||
$AverageWeightLine = new \app\common\model\datas\AverageWeight;
|
||
$AverageWeightLine->save($updata);
|
||
}
|
||
}
|
||
}
|
||
$STORES[$key]["orders"] = $STORESRemainingQuantity;
|
||
$STORES[$key]["orders2"] = $STORESRemainingQuantity2;
|
||
$STORES[$key]["orders3"] = $STORESRemainingQuantity3;
|
||
$STORES[$key]["orders4"] = $STORESRemainingQuantity4;
|
||
}
|
||
foreach ($averageWeight as $rule){
|
||
if($rule["type"]==2){
|
||
$updata = [
|
||
"create_date"=>$Time,
|
||
"WAREHOUSEID"=>$WAREHOUSEID,
|
||
"count"=>$rule["count"],
|
||
"ruluid"=>$rule["ruleid"],
|
||
"weight"=>$rule["weight"],
|
||
"POSTCODE"=>$rule["POSTCODE"],
|
||
"STOREID"=>0,
|
||
"iscost"=>1
|
||
];
|
||
|
||
if($rule["count"]>0){
|
||
$AverageWeightLine = new \app\common\model\datas\AverageWeight;
|
||
$AverageWeightLine->save($updata);
|
||
}
|
||
}
|
||
}
|
||
foreach ($STORES as $STORE){
|
||
$data = [
|
||
"WAREHOUSEID"=>$WAREHOUSEID,
|
||
"STOREID"=>$STORE["STOREID"],
|
||
"unrulescount"=>$STORE["orders"],
|
||
"rulescount"=>$STORE["orders3"],
|
||
"totalprice"=>$STORE["price"],
|
||
"totalprice2"=>$STORE["price2"],
|
||
"costtotalprice"=>$STORE["costprice"],
|
||
"costtotalprice2"=>$STORE["costprice2"],
|
||
"costunrulescount"=>$STORE["orders2"],
|
||
"costrulescount"=>$STORE["orders4"],
|
||
"createTime"=>$Time,
|
||
"packprice"=>$STORE["packprice"],
|
||
"packpricecost"=>$STORE["packpricecost"],
|
||
"packingprice"=>$STORE["packingprice"]
|
||
];
|
||
$SummaryLine = new \app\common\model\cost\Summary;
|
||
$SummaryLine->save($data);
|
||
}
|
||
return json(["allcount"=>$allcount,"rule"=>$averageWeight,"RemainingQuantity"=>$RemainingQuantity,"STORES"=>$STORES,"startOfMonth"=>$startOfMonth,"endOfMonth"=>$endOfMonth,"datas"=>$datas]);
|
||
}
|
||
public static function getOrderPrice($order,$rule,$AverageWeight=0){
|
||
$price = 0;
|
||
if(!$rule){
|
||
return $price = 0 ;
|
||
}
|
||
switch($rule['type']){
|
||
case 1:
|
||
$price+=$order["WEIGHT"]<$rule["fristweight"]?$rule["firstprice"]:round(ceil(($order["WEIGHT"]-$rule["fristweight"])/$rule["continuedweight"])*$rule["continuedweightprice"]+$rule["firstprice"]+$rule["surcharge"],2);
|
||
break;
|
||
case 2:
|
||
if($AverageWeight>0){
|
||
$price+=$AverageWeight<$rule["fristweight"]?$rule["firstprice"]:round((($AverageWeight-$rule["fristweight"])/$rule["continuedweight"])*$rule["continuedweightprice"]+$rule["firstprice"]+$rule["surcharge"],2);
|
||
}
|
||
break;
|
||
case 3:
|
||
try {
|
||
$kilogramsegment = $rule["kilogramsegment"]?json_decode($rule["kilogramsegment"],true):[];
|
||
if(is_array($kilogramsegment)){
|
||
foreach ($kilogramsegment as $r){
|
||
if($order["WEIGHT"]>=$r["min"] && $order["WEIGHT"]<=$r["max"]){
|
||
$price = $r["price"]+$rule["surcharge"];
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
} catch (Exception $e) {
|
||
}
|
||
break;
|
||
case 4:
|
||
try {
|
||
$STOCKS = explode("|",$order["ITEMS"]);
|
||
$STOCKS = array_filter($STOCKS);
|
||
$STOCKIDS = [];
|
||
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'];
|
||
});
|
||
$ITEMS = "";
|
||
foreach ($STOCKIDS as $r){
|
||
$ITEMS.=$r["STOCKS"].$r["COUNT"];
|
||
}
|
||
//type为特定组合
|
||
$kilogramsegment = json_decode($rule["kilogramsegment"],true);
|
||
|
||
$isin = false;
|
||
foreach ($kilogramsegment as $r){
|
||
$skus = explode(",",$r["skus"]);
|
||
$STOCKIDS = [];
|
||
foreach ($skus as $rr){
|
||
$stocktmp = explode("|",$rr);
|
||
array_push($STOCKIDS,["STOCKS"=>$stocktmp[0],"COUNT"=>$stocktmp[1]]);
|
||
}
|
||
usort($STOCKIDS, function($a, $b) {
|
||
return $a['STOCKS'] - $b['STOCKS'];
|
||
});
|
||
$ITEMS2="";
|
||
foreach ($STOCKIDS as $rr){
|
||
$ITEMS2.=$rr["STOCKS"].$rr["COUNT"];
|
||
}
|
||
if($ITEMS2==$ITEMS){
|
||
$price = $r["price"]+$rule["surcharge"];
|
||
}
|
||
}
|
||
}catch (Exception $e) {
|
||
}
|
||
break;
|
||
}
|
||
return round($price,2);
|
||
}
|
||
public static function getPackingprice($order,$rule){
|
||
$price = 0;
|
||
switch($rule['type']){
|
||
case 1:
|
||
$price=$rule["continuedcount"]>0?($order["GOODSCOUNT"]<$rule["fristcount"]?$rule["fristprice"]:round(ceil(($order["GOODSCOUNT"]-$rule["fristcount"])/$rule["continuedcount"])*$rule["continuedprice"]+$rule["fristprice"],2)):0;
|
||
break;
|
||
case 2:
|
||
$price=$rule["continuedcount"]>0?($order["STOCKSCOUNT"]<$rule["fristcount"]?$rule["fristprice"]:round((($order["STOCKSCOUNT"]-$rule["fristcount"])/$rule["continuedcount"])*$rule["continuedprice"]+$rule["fristprice"],2)):0;
|
||
break;
|
||
}
|
||
return round($price,2);
|
||
}
|
||
public static function getOrderRule($order,$rule1=[],$rule2=[],$rule3=[],$rule4=[]){
|
||
$rule1r = [];
|
||
$rule2r = [];
|
||
$rule3r = [];
|
||
$rule4r = [];
|
||
$rule5r = [];
|
||
$end = false;
|
||
$rule2s = [];
|
||
foreach ($rule1 as $k=>$rule){
|
||
//匹配地区
|
||
$UnfilteredRegions = false;
|
||
if($rule["region"]=="*"){
|
||
$UnfilteredRegions = true;
|
||
}else{
|
||
$Regions = explode('|',$rule["region"]);
|
||
$UnfilteredRegions = false;
|
||
}
|
||
$has = false;
|
||
if(!$UnfilteredRegions){
|
||
foreach ($Regions as $r){
|
||
if (strpos($order["PROVINCE"], $r) !== false){
|
||
$has = true;
|
||
}
|
||
}
|
||
}else{
|
||
$has = true;
|
||
}
|
||
//匹配快递
|
||
$UnfilteredRegions2 = false;
|
||
if($rule["POSTCODE"]=="*"){
|
||
$UnfilteredRegions2 = true;
|
||
}else{
|
||
$Regions = explode('|',$rule["POSTCODE"]);
|
||
$UnfilteredRegions2 = false;
|
||
}
|
||
$has2 = false;
|
||
$has3 = false;
|
||
$has4 = false;
|
||
$has5 = false;
|
||
if(!$UnfilteredRegions2){
|
||
foreach ($Regions as $r){
|
||
if (strpos($order["POSTCODE"], $r) !== false){
|
||
$has2 = true;
|
||
}
|
||
}
|
||
}else{
|
||
$has2 = true;
|
||
}
|
||
//匹配时间
|
||
$inDate = true;
|
||
if($order["sendDate"]<($rule["startTime"]*1000) && $rule['startTime']>0){
|
||
$inDate = false;
|
||
}
|
||
if($order["sendDate"]>($rule["endTime"]*1000+86399999) && $rule['endTime']>0){
|
||
$inDate = false;
|
||
}
|
||
|
||
$STOCKS = explode("|",$order["ITEMS"]);
|
||
$STOCKS = array_filter($STOCKS);
|
||
$STOCKIDS = [];
|
||
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'];
|
||
});
|
||
$ITEMS = "";
|
||
foreach ($STOCKIDS as $r){
|
||
$ITEMS.=$r["STOCKS"].$r["COUNT"];
|
||
}
|
||
//仅包含指定SKU
|
||
if($rule["onlyStocks"]){
|
||
$onlyStocks = explode("|",$rule["onlyStocks"]);
|
||
$isin = true;
|
||
foreach ($STOCKIDS as $r){
|
||
|
||
if(!in_array($r["STOCKS"],$onlyStocks)){
|
||
$isin = false;
|
||
}
|
||
}
|
||
if($isin){
|
||
$has3 = true;
|
||
}
|
||
}else{
|
||
$has3 = true;
|
||
}
|
||
//type为特定组合
|
||
if($rule["type"]==4){
|
||
$kilogramsegment = json_decode($rule["kilogramsegment"],true);
|
||
$isin = false;
|
||
foreach ($kilogramsegment as $rr){
|
||
$skus = explode(",",$rr["skus"]);
|
||
$STOCKIDS = [];
|
||
foreach ($skus as $r){
|
||
$stocktmp = explode("|",$r);
|
||
array_push($STOCKIDS,["STOCKS"=>$stocktmp[0],"COUNT"=>$stocktmp[1]]);
|
||
}
|
||
usort($STOCKIDS, function($a, $b) {
|
||
return $a['STOCKS'] - $b['STOCKS'];
|
||
});
|
||
$ITEMS2="";
|
||
foreach ($STOCKIDS as $r){
|
||
$ITEMS2.=$r["STOCKS"].$r["COUNT"];
|
||
}
|
||
if($ITEMS2==$ITEMS){
|
||
$isin = true;
|
||
}
|
||
}
|
||
if($isin){
|
||
$has4 = true;
|
||
}
|
||
}else{
|
||
$has4 = true;
|
||
}
|
||
if(($rule["maxcount"]>=$order["GOODSCOUNT"] && $rule["maxcount"]>0) && ($rule["mincount"]<=$order["GOODSCOUNT"] && $rule["maxcount"]>0)){
|
||
$has5 = true;
|
||
}
|
||
if(($rule["mincount"]==0 && $rule["maxcount"]==0)){
|
||
$has5 = true;
|
||
}
|
||
$rule2s[$k] = [$rule['id'].$rule['NAME'],$has,$has2,$has3,'11111',$rule["endTime"]*1000+86399999,$has4,$inDate,$order["WEIGHT"]>=$rule["minweight"],$order["WEIGHT"]<=$rule["maxweight"]];
|
||
//匹配重量
|
||
if($order["WEIGHT"]>=$rule["minweight"] && $order["WEIGHT"]<=$rule["maxweight"] && $has && $has2 && $has3 && $has4 && $has5 && $inDate){
|
||
$rule1r = $rule;
|
||
break;
|
||
}
|
||
}
|
||
//print_r($rule2s);die();
|
||
$rule2ss = [];
|
||
foreach ($rule2 as $k=>$rule){
|
||
//匹配地区
|
||
$UnfilteredRegions = false;
|
||
if($rule["region"]=="*"){
|
||
$UnfilteredRegions = true;
|
||
}else{
|
||
$Regions = explode('|',$rule["region"]);
|
||
$UnfilteredRegions = false;
|
||
}
|
||
$has = false;
|
||
if(!$UnfilteredRegions){
|
||
foreach ($Regions as $r){
|
||
if (strpos($order["PROVINCE"], $r) !== false){
|
||
$has = true;
|
||
}
|
||
}
|
||
}else{
|
||
$has = true;
|
||
}
|
||
//匹配快递
|
||
$UnfilteredRegions2 = false;
|
||
if($rule["POSTCODE"]=="*"){
|
||
$UnfilteredRegions2 = true;
|
||
}else{
|
||
$Regions = explode('|',$rule["POSTCODE"]);
|
||
$UnfilteredRegions2 = false;
|
||
}
|
||
$has2 = false;
|
||
$has3 = false;
|
||
$has4 = false;
|
||
$has5 = false;
|
||
if(!$UnfilteredRegions2){
|
||
foreach ($Regions as $r){
|
||
if (strpos($order["POSTCODE"], $r) !== false){
|
||
$has2 = true;
|
||
}
|
||
}
|
||
}else{
|
||
$has2 = true;
|
||
}
|
||
//匹配时间
|
||
$inDate = true;
|
||
if($order["sendDate"]<($rule["startTime"]*1000) && $rule['startTime']>0){
|
||
$inDate = false;
|
||
}
|
||
if($order["sendDate"]>($rule["endTime"]*1000+86399999) && $rule['endTime']>0){
|
||
$inDate = false;
|
||
}
|
||
|
||
$STOCKS = explode("|",$order["ITEMS"]);
|
||
$STOCKS = array_filter($STOCKS);
|
||
$STOCKIDS = [];
|
||
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'];
|
||
});
|
||
$ITEMS = "";
|
||
foreach ($STOCKIDS as $r){
|
||
$ITEMS.=$r["STOCKS"].$r["COUNT"];
|
||
}
|
||
//仅包含指定SKU
|
||
if($rule["onlyStocks"]){
|
||
$onlyStocks = explode("|",$rule["onlyStocks"]);
|
||
$isin = true;
|
||
foreach ($STOCKIDS as $r){
|
||
if(!in_array($r["STOCKS"],$onlyStocks)){
|
||
$isin = false;
|
||
}
|
||
}
|
||
if($isin){
|
||
$has3 = true;
|
||
}
|
||
}else{
|
||
$has3 = true;
|
||
}
|
||
//type为特定组合
|
||
if($rule["type"]==4){
|
||
$kilogramsegment = json_decode($rule["kilogramsegment"],true);
|
||
$isin = false;
|
||
foreach ($kilogramsegment as $rr){
|
||
$skus = explode(",",$rr["skus"]);
|
||
$STOCKIDS = [];
|
||
foreach ($skus as $r){
|
||
$stocktmp = explode("|",$r);
|
||
array_push($STOCKIDS,["STOCKS"=>$stocktmp[0],"COUNT"=>$stocktmp[1]]);
|
||
}
|
||
usort($STOCKIDS, function($a, $b) {
|
||
return $a['STOCKS'] - $b['STOCKS'];
|
||
});
|
||
$ITEMS2="";
|
||
foreach ($STOCKIDS as $r){
|
||
$ITEMS2.=$r["STOCKS"].$r["COUNT"];
|
||
}
|
||
if($ITEMS2==$ITEMS){
|
||
$isin = true;
|
||
}
|
||
}
|
||
if($isin){
|
||
$has4 = true;
|
||
}
|
||
}else{
|
||
$has4 = true;
|
||
}
|
||
|
||
if(($rule["maxcount"]>=$order["GOODSCOUNT"] && $rule["maxcount"]>0) && ($rule["mincount"]<=$order["GOODSCOUNT"] && $rule["maxcount"]>0)){
|
||
$has5 = true;
|
||
}
|
||
if(($rule["mincount"]==0 && $rule["maxcount"]==0)){
|
||
$has5 = true;
|
||
}
|
||
$rule2ss[$k] = [$rule['id'].$rule['NAME'],$has,$has2,$has3,$has4,$inDate,$order["WEIGHT"]>=$rule["minweight"],$order["WEIGHT"]<=$rule["maxweight"]];
|
||
//匹配重量
|
||
if($order["WEIGHT"]>=$rule["minweight"] && $order["WEIGHT"]<=$rule["maxweight"] && $has && $has2 && $has3 && $has4 && $has5 && $inDate){
|
||
$rule2r = $rule;
|
||
break;
|
||
}
|
||
}
|
||
//print_r($rule2ss);die();
|
||
foreach ($rule3 as $r){
|
||
if($r["packid"]==$order["PACKID"] && $r["STOREID"]==$order["STOREID"]){
|
||
$rule3r = $r;
|
||
}
|
||
if($r["packid"]==$order["PACKID"] && $r["STOREID"]==0){
|
||
$rule4r = $r;
|
||
}
|
||
}
|
||
foreach ($rule4 as $r){
|
||
if($r["STOREID"]==$order["STOREID"]){
|
||
$rule5r = $r;
|
||
}
|
||
}
|
||
return [$rule1r,$rule2r,$rule3r,$rule4r,$rule5r,$end];
|
||
}
|
||
public function repackingGRABS(){
|
||
$WAREHOUSEID = $this->request->get("WAREHOUSEID");
|
||
$model = new \app\common\model\wms\Order;
|
||
$WorksModel = new \app\common\model\workers\Works;
|
||
$GRABS = $model->where("GRABNUM like '%B%' and OPERATERECORDS not like '%打包%' and DISPLAYFLAG=1")->group("GRABNUM")->select();
|
||
$GRAB_ARRAY=[];
|
||
foreach ($GRABS as $r){
|
||
array_push($GRAB_ARRAY,$r["GRABNUM"]);
|
||
}
|
||
$workers = $WorksModel->where("dabaos>0")->where("grabnum","in",$GRAB_ARRAY)->select();
|
||
//return json($workers);
|
||
$filteredArray = [];
|
||
foreach ($GRAB_ARRAY as $k => $r){
|
||
foreach ($workers as $rr){
|
||
if($r==$rr["grabnum"]){
|
||
array_push($filteredArray,$rr);
|
||
}
|
||
}
|
||
}
|
||
$filteredArray_out = [];
|
||
foreach ($filteredArray as $k => $r){
|
||
$user = $this->getSystemUserName($r["userId"]);
|
||
array_push($filteredArray_out,[$r["WAREHOUSEID"],$r["grabnum"],$user["username"],$r["workers"]."已打包"]);
|
||
$data = Wsdl::webservice([$r["WAREHOUSEID"],$r["grabnum"],$user["username"],$r["workers"]."已打包"],'addOperate');
|
||
}
|
||
return json($filteredArray_out);
|
||
}
|
||
private function getSystemUserName($userid){
|
||
$modelUser = new \app\common\model\wms\User;
|
||
$dd = $modelUser->where(['userId'=>$userid])->find();
|
||
return $dd;
|
||
}
|
||
public function exportOrdertask(){
|
||
try{
|
||
$exportModel = new \app\common\model\export\Orders;
|
||
$HisorderModel = new \app\common\model\Hisorder;
|
||
$task = $exportModel->where(["status"=>0])->order("id")->find();
|
||
if(!$task){
|
||
return 0;
|
||
}
|
||
$count = $HisorderModel->where($task->where)->count();
|
||
if($task->current==$count){
|
||
$task->save(["status"=>1]);
|
||
}
|
||
if($task->count==0){
|
||
$task->save(["count"=>$count]);
|
||
}
|
||
$orders = $HisorderModel->where($task->where)->limit($task->current,1000)->select();
|
||
$rootpath = dirname(__DIR__);
|
||
$filePath = "{$rootpath}/../../../public/export/{$task->filename}.xlsx";
|
||
if (file_exists($filePath)) {
|
||
$spreadsheet = IOFactory::load($filePath);
|
||
}else{
|
||
$spreadsheet = new Spreadsheet();
|
||
}
|
||
$sheet = $spreadsheet->getActiveSheet();
|
||
$lists = [];
|
||
foreach ($orders as $r){
|
||
array_push($lists,[
|
||
$r["ID"],
|
||
$r["POSTNUM"],
|
||
$r["sendDate"],
|
||
$r["createDate"],
|
||
$r["POSTCODE"],
|
||
$r["WEIGHT"],
|
||
$r["STOREID"],
|
||
$r["GOODSCOUNT"],
|
||
$r["STOCKSCOUNT"],
|
||
$r["ITEMS"],
|
||
$r["PROVINCE"],
|
||
$r["SOURCEORDERCODE"],
|
||
$r["PACKID"]
|
||
]);
|
||
}
|
||
$sheet->fromArray(
|
||
$lists, '', 'A'.($task->current+2) );
|
||
$write = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||
$res = $write->save($filePath);
|
||
|
||
$task->save(["current"=>$task->current+count($orders)]);
|
||
return json($res);
|
||
}catch(Exception $e){
|
||
return $e;
|
||
}
|
||
}
|
||
public function checkNum(){
|
||
$params = $this->request->post();
|
||
$POSTNUM = $params["POSTNUM"];
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$PdataskModel = new \app\common\model\Pdatask;
|
||
$line = $PdataskModel->where(["POSTNUM"=>$POSTNUM])->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
if($line){
|
||
return json(["msg"=>"成功"]);
|
||
}else{
|
||
return json(["msg"=>"不存在"]);
|
||
}
|
||
}
|
||
public function queryStock(){
|
||
$params = $this->request->post();
|
||
$warehouseId = $params["warehouseId"];
|
||
$stores = $params["stores"];
|
||
|
||
$code = $params["code"];
|
||
$StockModel = new \app\common\model\wms\Stock;
|
||
$stocks = $StockModel->where(["stock.WAREHOUSEID"=>$warehouseId])->where("stock.BARCODE like '%".$code."%'")->where("store.STOREID","in",$stores)->with(["goods","store"])->select();
|
||
$stocks = json_decode(json_encode($stocks),true);
|
||
$stores = [];
|
||
foreach ($stocks as $r){
|
||
array_push($stores,$r["store"]["STOREID"]);
|
||
}
|
||
$StoreModel = new \app\common\model\wms\Warestore;
|
||
$stores = $StoreModel->field('TITLE,STOREID as STOREID')->where(["WAREHOUSEID"=>$warehouseId])->where("STOREID","in",$stores)->select();
|
||
return json([$stocks,$stores]);
|
||
}
|
||
public function queryStock2(){
|
||
$params = $this->request->post();
|
||
$warehouseId = $params["warehouseId"];
|
||
$stores = $params["stores"];
|
||
|
||
$code = $params["code"];
|
||
$StockModel = new \app\common\model\wms\Stock;
|
||
$stocks = $StockModel->where(["stock.WAREHOUSEID"=>$warehouseId])->where("stock.BARCODE like '%".$code."%'")->where("store.STOREID","in",$stores)->with(["goods","store"])->select();
|
||
$stocks = json_decode(json_encode($stocks),true);
|
||
$stores = [];
|
||
foreach ($stocks as $r){
|
||
array_push($stores,$r["store"]["STOREID"]);
|
||
}
|
||
$StoreModel = new \app\common\model\wms\Warestore;
|
||
$stores = $StoreModel->field('TITLE,STOREID as STOREID')->where(["WAREHOUSEID"=>$warehouseId])->where("STOREID","in",$stores)->select();
|
||
|
||
foreach ($stocks as $k => $r){
|
||
$stocks[$k]["NAME"] = $r["goods"]["NAME"];
|
||
$stocks[$k]["STOREID"] = $r["store"]["STOREID"];
|
||
}
|
||
return json(["stock"=>$stocks,"stores"=>$stores]);
|
||
}
|
||
public function saveBackrecord(){
|
||
$BackrecordModel = new \app\common\model\wms\Backrecord;
|
||
$BackrecordbackModel = new \app\common\model\wms\Backrecordback;
|
||
$BackrecordunknowModel = new \app\common\model\wms\Backrecordunknow;
|
||
$BackrecordcustomerModel = new \app\common\model\wms\Backrecordcustomer;
|
||
$RoomsModel = new \app\common\model\Rooms;
|
||
$params = $this->request->post();
|
||
$data = $params["data"];
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$time = time();
|
||
$GOODSCOUNT = 0;
|
||
foreach ($data["items"] as $k => $r){
|
||
$GOODSCOUNT+=$r["COUNT"];
|
||
}
|
||
$key = "back_POSTNUM:".$data["POSTNUM"];
|
||
$lockValue = 1;
|
||
$lockTimeout = 60;
|
||
$lockAcquired = $this->redis->set($key, $lockValue, ['NX', 'EX' => $lockTimeout]);
|
||
if (!$lockAcquired) {
|
||
return json(["msg"=>"已锁定,等待1分钟后再提交"]);
|
||
}
|
||
$this->setTuijianwork($params["userid"],$data["POSTNUM"],$GOODSCOUNT,$WAREHOUSEID);
|
||
$yesorno = [
|
||
"否",
|
||
"是"
|
||
];
|
||
$msg="";
|
||
if(count($data["stores"])>1){
|
||
//查询异常表是否有记录
|
||
$line2 = $BackrecordunknowModel->where(["POSTNUM"=>$data["POSTNUM"]])->select();
|
||
foreach ($line2 as $r){
|
||
$r->delete();
|
||
}
|
||
$stores = [];
|
||
foreach ($data["stores"] as $store){
|
||
array_push($stores,$store["STOREID"]);
|
||
}
|
||
$hidePostmun = $this->hidePostNum($data["POSTNUM"]);
|
||
$text = "\n非原单号退回的运单号:{$hidePostmun} 疑是贵司退件,退件扫描明细为:\n";
|
||
foreach ($data["items"] as $k => $r){
|
||
$line_data = [
|
||
"STOREID"=>0,
|
||
"STOCKID"=>0,
|
||
"WAREHOUSEID"=>$WAREHOUSEID,
|
||
"COUNT"=>$r["COUNT"],
|
||
"CREATIONDATE"=>"00{$time}000",
|
||
"USERID"=>$params["userid"],
|
||
"STATUS"=>$r["STATUS"],
|
||
"POSTNUM"=>$data["POSTNUM"],
|
||
"FLAG"=>0,
|
||
"NOTES"=>$r["NOTES"],
|
||
"YDFLAG"=>0,
|
||
"STORENAME"=>'',
|
||
"POSTNAME"=>'',
|
||
"SOURCEORDERCODE"=>'',
|
||
"BARCODE"=>$r["BARCODE"],
|
||
"stocks"=>json_encode($r["stocks"]),
|
||
"STOREIDS"=>json_encode($stores)
|
||
];
|
||
$text.="{$k}、条码:{$r['BARCODE']} 数量:{$r['COUNT']}\n";
|
||
$BackrecordunknowModel->save($line_data);
|
||
}
|
||
$text.="如需认领,请回复完整的运单号+查退回认领,如非贵司退件,请忽略本消息。\n建议处理售后客户自行退回件输入查退回+运单号(多个使用任意分割符,如换行)登记退回,退回后仓库如收到退件拆包登记后将自动通知,以降低退回丢件率风险。";
|
||
|
||
foreach ($stores as $store) {
|
||
//$this->pushMsgToOwner($text,$WAREHOUSEID,$store);
|
||
}
|
||
$msg = "包含多个货主,已通知客户认领";
|
||
|
||
}else{
|
||
$has = false;
|
||
foreach ($data["items"] as $r){
|
||
if(count($r["stocks"])>0){
|
||
$msg = "单个货主相同条码有多个SKU,请手动选择后再提交";
|
||
$has = true;
|
||
}
|
||
}
|
||
if($has){
|
||
$msg = "单个货主相同条码有多个SKU,请手动选择后再提交";
|
||
}else{
|
||
//初始化变量
|
||
$hasDefective = false;
|
||
$hasAbnormal = false;
|
||
$YDFLAG = 0;
|
||
$SOURCEORDERCODE = "";
|
||
$POSTNAME = "";
|
||
$STORENAME = "";
|
||
$lineModel = [
|
||
"STOREID"=>0,
|
||
"STOCKID"=>0,
|
||
"WAREHOUSEID"=>$WAREHOUSEID,
|
||
"COUNT"=>0,
|
||
"CREATIONDATE"=>"00{$time}000",
|
||
"USERID"=>$params["userid"],
|
||
"STATUS"=>0,
|
||
"POSTNUM"=>$data["POSTNUM"],
|
||
"FLAG"=>0,
|
||
"NOTES"=>"",
|
||
"YDFLAG"=>0,
|
||
"STORENAME"=>"",
|
||
"POSTNAME"=>"",
|
||
"SOURCEORDERCODE"=>"",
|
||
];
|
||
//无记录查询是否有原单
|
||
$order = $this->getOrderInfoByPostnum($data["POSTNUM"]);
|
||
if(($order["ID"] ?? null)){
|
||
$YDFLAG=1;
|
||
$SOURCEORDERCODE = ($order["SOURCEORDERCODE"] ?? null);
|
||
$POSTNAME = isset($order["POSTNAME"])?$order["POSTNAME"]:"";
|
||
$STORENAME = $order["STORENAME"];
|
||
}
|
||
//分析数据是否有残品,记录状态
|
||
//分析数据是否有异常品,记录状态
|
||
$lines = [];
|
||
$lines2 = [];
|
||
$linesn = [];
|
||
$linesn2 = [];
|
||
foreach ($data["items"] as $r){
|
||
if($r["STOCKID"]==-1){
|
||
$hasAbnormal = true;
|
||
$line_data = [
|
||
"STOREID"=>$data["stores"][0]["STOREID"],
|
||
"STOCKID"=>0,
|
||
"WAREHOUSEID"=>$WAREHOUSEID,
|
||
"COUNT"=>$r["COUNT"],
|
||
"CREATIONDATE"=>"00{$time}000",
|
||
"USERID"=>$params["userid"],
|
||
"STATUS"=>0,
|
||
"POSTNUM"=>$data["POSTNUM"],
|
||
"FLAG"=>0,
|
||
"NOTES"=>$r['NOTES'],
|
||
"YDFLAG"=>$YDFLAG,
|
||
"STORENAME"=>$STORENAME,
|
||
"POSTNAME"=>$POSTNAME,
|
||
"SOURCEORDERCODE"=>$SOURCEORDERCODE,
|
||
"BARCODE"=>$r["BARCODE"]
|
||
];
|
||
|
||
array_push($linesn2,$r);
|
||
array_push($lines2,$line_data);
|
||
}else{
|
||
if($r["STATUS"]==1){
|
||
$hasAbnormal = true;
|
||
}
|
||
$line_data = [
|
||
"STOREID"=>$data["stores"][0]["STOREID"],
|
||
"STOCKID"=>$r["STOCKID"],
|
||
"WAREHOUSEID"=>$WAREHOUSEID,
|
||
"COUNT"=>$r["COUNT"],
|
||
"CREATIONDATE"=>"00{$time}000",
|
||
"USERID"=>$params["userid"],
|
||
"STATUS"=>$r["STATUS"],
|
||
"POSTNUM"=>$data["POSTNUM"],
|
||
"FLAG"=>0,
|
||
"NOTES"=>$r["NOTES"],
|
||
"YDFLAG"=>$YDFLAG,
|
||
"STORENAME"=>$STORENAME,
|
||
"POSTNAME"=>$POSTNAME,
|
||
"SOURCEORDERCODE"=>$SOURCEORDERCODE
|
||
];
|
||
array_push($linesn,$r);
|
||
array_push($lines,$line_data);
|
||
}
|
||
}
|
||
|
||
//查询记录
|
||
$line = $BackrecordModel->where(["POSTNUM"=>$data["POSTNUM"]])->select();
|
||
foreach ($line as $r){
|
||
$r->delete();
|
||
}
|
||
//是否有记录
|
||
$line2 = $BackrecordunknowModel->where(["POSTNUM"=>$data["POSTNUM"]])->select();
|
||
foreach ($line2 as $r){
|
||
$r->delete();
|
||
}
|
||
foreach ($lines as $r){
|
||
Wsdl::webservice([$r["WAREHOUSEID"],$r["STOREID"],$r["STORENAME"],$r["STOCKID"],$r["COUNT"],$r["USERID"],$r["STATUS"],$r["FLAG"],$r["YDFLAG"],$r["NOTES"],$r["POSTNUM"],$r["POSTNAME"],$r['SOURCEORDERCODE']],'createBackRecord');
|
||
}
|
||
foreach ($lines2 as $r){
|
||
$BackrecordunknowModel->save($r);
|
||
}
|
||
//查询单号待通知是否有记录
|
||
$notific = $BackrecordcustomerModel->where(["POSTNUM"=>$data["POSTNUM"],"notified"=>0])->find();
|
||
|
||
//查询单号是否拦截异常跟踪单
|
||
$order = $this->getOrderInfoByPostnumB($data["POSTNUM"]);
|
||
//构建通知消息
|
||
$msg = "退件已收登记提醒:\n运单号:{$data['POSTNUM']}\n是否原单:{$yesorno[$YDFLAG]}\n交易单号:{$SOURCEORDERCODE}\n快递:{$POSTNAME}\n店铺名称:{$STORENAME}\n天豹云仓收到且已拆包,拆包明细为:\n";
|
||
foreach ($data["items"] as $r){
|
||
$msg.="商品名称:{$r['NAME']}\n条码:{$r['BARCODE']}\n数量:{$r['COUNT']}\n是否破损:{$yesorno[$r['STATUS']]}\n备注:{$r['NOTES']}\n\n";
|
||
}
|
||
$msg.="拆包视频保存会有延迟,可以在稍后发送:查退回+运单号,查询";
|
||
|
||
if(isset($order["ID"])){
|
||
$room = $RoomsModel->where(["STOREID"=>$data["stores"][0]["STOREID"],"isBack"=>1])->find();
|
||
if($room){
|
||
$msg = "{$data['POSTNUM']}已退回仓库并登记";
|
||
$msg = $this->toMsg($room["room_id"],$msg);
|
||
//lpush信息到货主的房间号,通知货主
|
||
$this->redis->lpush("Message_back",json_encode([$room["room_id"],$data["POSTNUM"]]));
|
||
$this->redis->lpush("Message_back3",json_encode([$room["room_id"],$data["POSTNUM"]]));
|
||
}
|
||
$Exceptionwmsorder = new \app\common\model\wms\Exceptionwmsorder;
|
||
//是拦截,结束拦截,写入处理结果为仓库已拆包;
|
||
$ress = $Exceptionwmsorder->where(["WMSORDERID"=>$order["ID"],"STATUS"=>12,"TYPE"=>0])->select();
|
||
foreach ($ress as $res){
|
||
Wsdl::webservice(['','','快递退回拆包扫描',$res["ID"]],'updateExceptionWmsOrder');
|
||
Wsdl::webservice([$res["ID"]],'confirmExceptionWmsOrder');
|
||
}
|
||
}else if($notific){
|
||
//获取货主房间号
|
||
$room = $RoomsModel->where(["STOREID"=>$data["stores"][0]["STOREID"],"isMain"=>1])->find();
|
||
if($room){
|
||
|
||
$msg = $this->toMsg($room["room_id"],$msg);
|
||
//lpush信息到货主的房间号,通知货主
|
||
$this->redis->lpush("Message_text",json_encode($msg));
|
||
}
|
||
//通知完成关闭通知
|
||
$notific->save(["notified"=>1]);
|
||
}
|
||
$msg = "记录成功";
|
||
}
|
||
}
|
||
$this->redis->del($key);
|
||
return json(["msg"=>$msg]);
|
||
}
|
||
public function video5400($id){
|
||
$postnum = str_replace(".webm","",$id);
|
||
$TuijianModel = new \app\common\model\file\Tuijian;
|
||
$splist = $TuijianModel->where(["name"=>$postnum])->find();
|
||
|
||
$new_url = "http://192.168.9.101:3000".$splist["path"];
|
||
return $new_url;
|
||
die();
|
||
// 发送302重定向状态码
|
||
header("HTTP/1.1 302 Found");
|
||
header("Location: " . $new_url);
|
||
|
||
// 确保重定向之后,后续代码不会执行
|
||
exit();
|
||
}
|
||
public function clearDataBaseOrder(){
|
||
$BackrecordModel = new \app\common\model\wms\Backrecord;
|
||
$BackrecordunknowModel = new \app\common\model\wms\Backrecordunknow;
|
||
$params = $this->request->post();
|
||
$POSTNUM = $params["POSTNUM"];
|
||
$WAREHOUSEID = $params["warehouseId"];
|
||
$line = $BackrecordModel->where(["POSTNUM"=>$POSTNUM])->select();
|
||
foreach ($line as $r){
|
||
$r->delete();
|
||
}
|
||
$line = $BackrecordunknowModel->where(["POSTNUM"=>$POSTNUM])->select();
|
||
foreach ($line as $r){
|
||
$r->delete();
|
||
}
|
||
return "清除成功";
|
||
}
|
||
private function hidePostNum($string){
|
||
$length = strlen($string);
|
||
$newString = substr($string, 0, 4) . str_repeat('*', $length - 8) . substr($string, -4);
|
||
return $newString;
|
||
}
|
||
public function getBackWorkCount(){
|
||
$BackrecordModel = new \app\common\model\wms\Backrecord;
|
||
$BackrecordunknowModel = new \app\common\model\wms\Backrecordunknow;
|
||
$params = $this->request->post();
|
||
$userid = $params["userid"];
|
||
$WAREHOUSEID = $params["warehouseId"];
|
||
[$startTime,$endTime] = $this->getToday();
|
||
$line = $BackrecordModel->where(["USERID"=>$userid,"WAREHOUSEID"=>$WAREHOUSEID])->where("CREATIONDATE BETWEEN '00{$startTime}' and '00{$endTime}'")->select();
|
||
$line2 = $BackrecordunknowModel->where(["USERID"=>$userid,"WAREHOUSEID"=>$WAREHOUSEID])->where("CREATIONDATE BETWEEN '00{$startTime}' and '00{$endTime}'")->select();
|
||
$line = array_merge($line,$line2);
|
||
$count = 0;
|
||
$ordercount = 0;
|
||
$orders = [];
|
||
foreach ($line as $r){
|
||
$count+=$r["COUNT"];
|
||
if (!in_array($r["POSTNUM"], $orders)){
|
||
array_push($orders,$r["POSTNUM"]);
|
||
}
|
||
}
|
||
$ordercount = count($orders);
|
||
return json(["count"=>$count,"orderCount"=>$ordercount]);
|
||
}
|
||
private function getToday(){
|
||
$currentTimestamp = time(); // 获取当前时间戳
|
||
$todayStartTimestamp = strtotime('today 06:00'); // 今天的6点时间戳
|
||
$yesterdayStartTimestamp = strtotime('yesterday 06:00'); // 昨天的6点时间戳
|
||
|
||
if ($currentTimestamp < $todayStartTimestamp) {
|
||
// 如果当前时间在今天6点之前
|
||
$startTime = $yesterdayStartTimestamp;
|
||
} else {
|
||
// 如果当前时间在今天6点之后
|
||
$startTime = $todayStartTimestamp;
|
||
}
|
||
|
||
// 结束时间为开始时间的第二天的6点减一秒
|
||
$endTime = strtotime('+1 day', $startTime);
|
||
return [$startTime*1000,$endTime*1000-1];
|
||
}
|
||
private function getToday18(){
|
||
$currentTimestamp = time(); // 获取当前时间戳
|
||
$todayStartTimestamp = strtotime('today 18:00'); // 今天的6点时间戳
|
||
$yesterdayStartTimestamp = strtotime('yesterday 18:00'); // 昨天的6点时间戳
|
||
|
||
if ($currentTimestamp < $todayStartTimestamp) {
|
||
// 如果当前时间在今天6点之前
|
||
$startTime = $yesterdayStartTimestamp;
|
||
} else {
|
||
// 如果当前时间在今天6点之后
|
||
$startTime = $todayStartTimestamp;
|
||
}
|
||
|
||
// 结束时间为开始时间的第二天的6点减一秒
|
||
$endTime = strtotime('+1 day', $startTime);
|
||
return [$startTime*1000,$endTime*1000-1];
|
||
}
|
||
public function intercepts_zto(){
|
||
$RoomsModel = new \app\common\model\Rooms;
|
||
$datas = [];
|
||
for($i=0;$i<50;$i++){
|
||
$data = $this->express_redis->rpop("intercepts_3");
|
||
if($data){
|
||
$result = json_decode($data,true);
|
||
array_push($datas,$result);
|
||
$order = $this->getOrderInfoByPostnumB(($result["waybillCode"] ?? null));
|
||
if($order && isset($order["STOREID"])){
|
||
$room = $RoomsModel->where(["STOREID"=>$order["STOREID"],"isMain"=>1])->find();
|
||
if($room){
|
||
$msg = $this->toMsg($room["room_id"],"快递通知:运单号 ".($result["waybillCode"] ?? null)."状态 ".($result["serviceOrderStatusMsg"] ?? null).($result["interceptName"] ?? null).",尚未退回到天豹云仓");
|
||
$this->redis->lpush("Message_intercepts",json_encode($msg));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return json($datas);
|
||
}
|
||
public function intercepts_yto(){
|
||
$RoomsModel = new \app\common\model\Rooms;
|
||
$datas = [];
|
||
for($i=0;$i<50;$i++){
|
||
$data = $this->express_redis->rpop("intercepts_1");
|
||
if($data){
|
||
$result = json_decode($data,true);
|
||
array_push($datas,$result);
|
||
$order = $this->getOrderInfoByPostnumB(($result["waybillNo"] ?? null));
|
||
if($order){
|
||
$room = $RoomsModel->where(["STOREID"=>$order["STOREID"],"isMain"=>1])->find();
|
||
if($room){
|
||
$msg = $this->toMsg($room["room_id"],"快递通知:运单号 ".($result["waybillNo"] ?? null)."状态 ".($result["result"] ?? null).",尚未退回到天豹云仓");
|
||
$this->redis->lpush("Message_intercepts",json_encode($msg));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return json($datas);
|
||
}
|
||
public function intercepts_jtexpress(){
|
||
$RoomsModel = new \app\common\model\Rooms;
|
||
$datas = [];
|
||
for($i=0;$i<50;$i++){
|
||
$data = $this->express_redis->rpop("intercepts_2");
|
||
|
||
if($data){
|
||
$result = json_decode($data,true);
|
||
$result = json_decode($result,true);
|
||
array_push($datas,$result);
|
||
$mailNos = isset($result["mailNo"])?json_decode($result["mailNo"],true):[];
|
||
//print_r($mailNos);
|
||
foreach ($mailNos as $r){
|
||
$order = $this->getOrderInfoByPostnumB($r);
|
||
if($order){
|
||
$room = $RoomsModel->where(["STOREID"=>$order["STOREID"],"isMain"=>1])->find();
|
||
if($room){
|
||
$msg = $this->toMsg($room["room_id"],"快递通知:运单号 ".$r."拦截状态 已更新,尚未退回到天豹云仓");
|
||
$this->redis->lpush("Message_intercepts",json_encode($msg));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return json($datas);
|
||
}
|
||
public function sendMessage_intercepts(){
|
||
$count = 0;
|
||
$lcount = 1;
|
||
$tmp_msg = "";
|
||
$orders = [];
|
||
do{
|
||
$jsontext = $this->redis->rpop("Message_intercepts");
|
||
|
||
if($jsontext){
|
||
$data = json_decode($jsontext,true);
|
||
if(isset($orders[($data['wxid'] ?? null)])){
|
||
array_push($orders[($data['wxid'] ?? null)],($data['msg'] ?? null));
|
||
}else{
|
||
$orders[($data['wxid'] ?? null)] = [($data['msg'] ?? null)];
|
||
}
|
||
$count++;
|
||
}
|
||
}while($jsontext);
|
||
foreach ($orders as $rooomid =>$r){
|
||
$lcount = 1;
|
||
$tmp_msg = "";
|
||
foreach ($r as $k=>$rr){
|
||
$tmp_msg.= "{$rr}\n";
|
||
if($lcount%30==0){
|
||
$msg = $this->toMsg($rooomid,$tmp_msg);
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
$tmp_msg = "";
|
||
}
|
||
$lcount++;
|
||
}
|
||
$msg = $this->toMsg($rooomid,$tmp_msg);
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
}
|
||
$orders = [];
|
||
do{
|
||
$jsontext = $this->redis->rpop("Message_back");
|
||
if($jsontext){
|
||
$data = json_decode($jsontext,true);
|
||
if(isset($orders[($data[0] ?? null)])){
|
||
array_push($orders[($data[0] ?? null)],($data[1] ?? null));
|
||
}else{
|
||
$orders[($data[0] ?? null)] = [($data[1] ?? null)];
|
||
}
|
||
}
|
||
}while($jsontext);
|
||
foreach ($orders as $rooomid =>$r){
|
||
$TuijianModel = new \app\common\model\file\Tuijian;
|
||
$lcount = 1;
|
||
$tmp_msg = "";
|
||
foreach ($r as $k=>$rr){
|
||
$splist = $TuijianModel->where(["name"=>$rr])->select();
|
||
$tmp_msg.= "{$rr}已退回仓库并登记,登记录像为:\n";
|
||
foreach($splist as $rrr){
|
||
$tmp_msg.="http://file.gztbyc.com:3000{$rrr['path']}\n";
|
||
}
|
||
if($lcount%15==0){
|
||
$msg = $this->toMsg($rooomid,$tmp_msg);
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
$tmp_msg = "";
|
||
}
|
||
$lcount++;
|
||
}
|
||
$msg = $this->toMsg($rooomid,$tmp_msg);
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
}
|
||
return $count;
|
||
}
|
||
public function intercepts_sto(){
|
||
$RoomsModel = new \app\common\model\Rooms;
|
||
$datas = [];
|
||
for($i=0;$i<50;$i++){
|
||
$data = $this->express_redis->rpop("intercepts_5");
|
||
array_push($datas,$data);
|
||
if($data){
|
||
$order = $this->getOrderInfoByPostnumB($data);
|
||
if($order && isset($order["STOREID"])){
|
||
$room = $RoomsModel->where(["STOREID"=>$order["STOREID"],"isMain"=>1])->find();
|
||
if($room){
|
||
$msg = $this->toMsg($room["room_id"],"快递通知:运单号 ".$data."拦截状态 已更新,尚未退回到天豹云仓");
|
||
$this->redis->lpush("Message_intercepts",json_encode($msg));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return json($datas);
|
||
}
|
||
|
||
private function getOrderInfoByPostnumB($postnum){
|
||
$status = 0;
|
||
$ExpressModel = new \app\common\model\wms\Express;
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$OrderModel1 = new \app\common\model\wms\Order1;
|
||
$DeliveryorderModel = new \app\common\model\wms\Deliveryorder;
|
||
$expressRow = $ExpressModel->where(["POSTNUM"=>$postnum])->find();
|
||
if(!$expressRow){
|
||
return false;
|
||
}
|
||
if(!$expressRow["TRADEORDER"]){
|
||
$where = '(POSTNUM = "'.$postnum.'")';
|
||
}else{
|
||
$where = '(SOURCEID="'.$expressRow["TRADEORDER"].'" or POSTNUM = "'.$postnum.'")';
|
||
}
|
||
$order = $OrderModel->where($where)->find();
|
||
if($order){
|
||
$status = 1;
|
||
}else{//不在待处理
|
||
$status = 2;
|
||
$order = $DeliveryorderModel->where($where)->find();
|
||
if(!$order){//不在配送
|
||
$order = $OrderModel1->where($where)->find();
|
||
if(!$order){//不在历史
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
$Exceptionwmsorder = new \app\common\model\wms\Exceptionwmsorder;
|
||
$res = $Exceptionwmsorder->where(["WMSORDERID"=>$order["ID"],"STATUS"=>12])->find();
|
||
if(!$res){
|
||
$order = ["status"=>0];
|
||
}else{
|
||
$order["status"] = $status;
|
||
}
|
||
return $order;
|
||
}
|
||
private function getOrderInfoBySOURCEORDERCODE($SOURCEID){
|
||
$status = 0;
|
||
$ExpressModel = new \app\common\model\wms\Express;
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$OrderModel1 = new \app\common\model\wms\Order1;
|
||
$DeliveryorderModel = new \app\common\model\wms\Deliveryorder;
|
||
$where = '(SOURCEORDERCODE="'.$SOURCEID.'")';
|
||
$order = $OrderModel->where($where)->find();
|
||
if($order){
|
||
$status = 1;
|
||
}else{//不在待处理
|
||
$status = 2;
|
||
$order = $DeliveryorderModel->where($where)->find();
|
||
if(!$order){//不在配送
|
||
$order = $OrderModel1->where($where)->find();
|
||
if(!$order){//不在历史
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
return $order;
|
||
}
|
||
public function getbackList(){
|
||
$BackrecordModel = new \app\common\model\wms\Backrecord;
|
||
$list = $BackrecordModel->where("CREATIONDATE>'001735596000000'")->group("POSTNUM")->select();
|
||
$POSTNUMS = [];
|
||
foreach ($list as $r){
|
||
array_push($POSTNUMS,$r["POSTNUM"]);
|
||
}
|
||
$TuijianModel = new \app\common\model\file\Tuijian;
|
||
$spList = $TuijianModel->where("name","in",$POSTNUMS)->select();
|
||
foreach ($list as $r){
|
||
$splist = [];
|
||
foreach ($spList as $rr){
|
||
if($r["POSTNUM"]==$rr["name"]){
|
||
array_push($splist,"http://file.gztbyc.com:3000".$rr["path"]);
|
||
}
|
||
}
|
||
$r["SPLIST"] = $splist;
|
||
}
|
||
$tmpList = [];
|
||
foreach ($tmpList as $r){
|
||
if(count($r["SPLIST"])==0){
|
||
array_push($tmpList,$r);
|
||
}
|
||
}
|
||
return json([$tmpList,$list]);
|
||
}
|
||
public function autoAssignWmsOrder(){
|
||
$currentHour = date('G'); // 获取当前时间的小时数(24小时制)
|
||
$key = 'lock_autoAssignWmsOrder';
|
||
$lockValue = 'autoAssignWmsOrder';
|
||
$lockTimeout = 300; // 5分钟
|
||
$lockAcquired = $this->redis->set($key, $lockValue, ['NX', 'EX' => $lockTimeout]);
|
||
if (!$lockAcquired) {
|
||
return "已上锁";
|
||
}
|
||
if ($currentHour < 9 || $currentHour>20) {
|
||
$this->redis->del($key);
|
||
return "不在自动分配时间";
|
||
}
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
$WAREHOUSEMODEL = new \app\common\model\Warehouse;
|
||
$WAREHOUSES = $WAREHOUSEMODEL->where(["autoTuan"=>1])->select();
|
||
$autoTuanLasttime = $this->redis->get("autoTuanLasttime");
|
||
$autoTuanLasttime = $autoTuanLasttime?json_decode($autoTuanLasttime,true):[];
|
||
$IDSARRAY = [];
|
||
foreach ($WAREHOUSES as $WAREHOUSE){ //仓库循环
|
||
//
|
||
$IDS = [];
|
||
$lasttime = isset($autoTuanLasttime[$WAREHOUSE["WAREHOUSEID"]])?$autoTuanLasttime[$WAREHOUSE["WAREHOUSEID"]]:0;
|
||
$list = $orderModel->field("CREATIONDATE,ID")->where(["WAREHOUSEID"=>$WAREHOUSE["WAREHOUSEID"],"ASSIGNFLAG"=>0,"FLAG"=>0,"ISLOCK"=>0,"DISPLAYFLAG"=>0,"POSTFLAG"=>1])->where("GRABNUM not like '%B%' and POSTCODE<>'p18' and POSTCODE<>'p30'")->where("LEAVEMESSAGE not like '%占用单%'")->where("CREATIONDATE>'{$lasttime}'")->where("STOREID","not in",[17305])->order("CREATIONDATE desc")->select();
|
||
if(count($list)>0){
|
||
$lasttime = $list[0]["CREATIONDATE"];
|
||
foreach ($list as $r){
|
||
array_push($IDS,[$r["ID"]]);
|
||
Wsdl::webservice([$WAREHOUSE["WAREHOUSEID"],$WAREHOUSE["operatorID"],$r["ID"],1],"assignWmsOrder");
|
||
}
|
||
}
|
||
$autoTuanLasttime[$WAREHOUSE["WAREHOUSEID"]] = $lasttime;
|
||
$IDSARRAY[$WAREHOUSE["WAREHOUSEID"]] = $IDS;
|
||
}
|
||
$this->redis->set("autoTuanLasttime",json_encode($autoTuanLasttime));
|
||
$this->redis->del($key);
|
||
return json([$autoTuanLasttime,$IDSARRAY,count($list)]);
|
||
}
|
||
public function autoAssignWmsOrder_new($WAREHOUSEID=null){
|
||
|
||
$WAREHOUSEMODEL = new \app\common\model\Warehouse;
|
||
$WAREHOUSES = $WAREHOUSEMODEL->where(["autoTuan"=>1])->select();
|
||
$WmsitemModel = new \app\common\model\wms\Wmsitem;
|
||
$blist = [];
|
||
foreach ($WAREHOUSES as $WAREHOUSE){
|
||
$ltime = time()-24*60*60*3;
|
||
$data = $WmsitemModel
|
||
->alias('wmsitem')
|
||
->field('wmsitem.STOCKID, SUM(wmsitem.COUNT) AS wfpcw, IFNULL(CAST(STORAGE1.copycount AS SIGNED),0) AS fjsl, CASE WHEN SUM(wmsitem.COUNT) - IFNULL(CAST(STORAGE1.copycount AS SIGNED), 0) < 0 THEN 0 ELSE SUM(wmsitem.COUNT) - IFNULL(CAST(STORAGE1.copycount AS SIGNED), 0) END AS qhs, IFNULL(CAST(STORAGE2.copycount AS SIGNED),0) AS ccl, LEAST(IFNULL(CAST(putoutstorage.COUNT AS SIGNED),0)+(SUM(wmsitem.COUNT)- IFNULL(CAST(STORAGE1.copycount AS SIGNED),0)),IFNULL(CAST(STORAGE2.copycount AS SIGNED),0)) as tjbhl')
|
||
->join('(
|
||
SELECT STOCKID, sum(copycount) AS copycount
|
||
FROM yj_storage
|
||
LEFT JOIN yj_space space ON space.ID = yj_storage.SPACEID
|
||
WHERE space.FIRSTFLAG = 1
|
||
GROUP BY STOCKID
|
||
) AS STORAGE1', 'STORAGE1.STOCKID = wmsitem.STOCKID','left')
|
||
->join('(
|
||
SELECT STOCKID, sum(copycount) AS copycount
|
||
FROM yj_storage
|
||
LEFT JOIN yj_space space ON space.ID = yj_storage.SPACEID
|
||
WHERE space.FIRSTFLAG = 2
|
||
GROUP BY STOCKID
|
||
) AS STORAGE2', 'STORAGE2.STOCKID = wmsitem.STOCKID','left')
|
||
->join('(
|
||
SELECT STOCKID, sum(yj_putoutstorage.COUNT) AS COUNT
|
||
FROM yj_putoutstorage
|
||
WHERE CREATIONDATE > "00'.$ltime.'000"
|
||
GROUP BY STOCKID
|
||
) AS putoutstorage', 'putoutstorage.STOCKID = wmsitem.STOCKID','left')
|
||
->join('yj_wmsorder wmsorder', 'wmsorder.ID = wmsitem.WMSORDERID')
|
||
->where('wmsorder.WAREHOUSEID', $WAREHOUSE["WAREHOUSEID"])
|
||
->where('wmsorder.ASSIGNFLAG', 0)
|
||
->where('wmsorder.DISPLAYFLAG', 0)
|
||
->group('STOCKID')
|
||
->order('qhs DESC, tjbhl DESC')
|
||
->select();
|
||
$list = [];
|
||
foreach ($data as $row){
|
||
if(intval($row->qhs)>0){
|
||
array_push($list,"ITEMS not like '%{$row['STOCKID']}%'");
|
||
}
|
||
}
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
$where = implode(" and ",$list);
|
||
$newlist = $orderModel->field("ID")->where($where)->where(["WAREHOUSEID"=>$WAREHOUSE["WAREHOUSEID"]])->where(["ASSIGNFLAG"=>0,"FLAG"=>0,"ISLOCK"=>0,"DISPLAYFLAG"=>0])->where("GRABNUM not like '%B%' and POSTCODE<>'p18' and POSTCODE<>'p30'")->select();
|
||
array_push($blist,$newlist);
|
||
foreach ($newlist as $r){
|
||
Wsdl::webservice([$WAREHOUSE["WAREHOUSEID"],$WAREHOUSE["operatorID"],$r["ID"],1],"assignWmsOrder");
|
||
}
|
||
}
|
||
return json($blist);
|
||
}
|
||
public function autoTuan(){
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
//$WAREHOUSEMODEL = new \app\common\model\Warehouse;
|
||
$WmstuanModel = new \app\common\model\wms\Wmstuan;
|
||
$pickingRules = new \app\common\model\wms\PickingRules;
|
||
$currentHour = date('G'); // 获取当前时间的小时数(24小时制)
|
||
$key = 'lock_autoTuan';
|
||
$lockValue = 'autoTuan';
|
||
$lockTimeout = 300; // 5分钟
|
||
$lockAcquired = $this->redis->set($key, $lockValue, ['NX', 'EX' => $lockTimeout]);
|
||
if (!$lockAcquired) {
|
||
return "已上锁";
|
||
}
|
||
$addTuans = [];
|
||
$cancelGrabWmsOrder = [];
|
||
//$WAREHOUSES = $WAREHOUSEMODEL->field("WAREHOUSEID,operatorID")->where(["autoTuan"=>1])->select();
|
||
$rules = $pickingRules->alias('picking_rules')->field('picking_rules.WAREHOUSEID as WAREHOUSEID,max(picking_rules.sameordercountgt) as count,operator.USERID as operatorID')->join('yj_operator operator','operator.WAREHOUSEID=picking_rules.WAREHOUSEID','left')->where('picking_rules.type=0')->group('picking_rules.WAREHOUSEID')->select();
|
||
$data_time = time()-259200;
|
||
try {
|
||
foreach ($rules as $WAREHOUSE){ //仓库循环
|
||
if(!$WAREHOUSE["operatorID"]){
|
||
echo "仓库{$WAREHOUSE['WAREHOUSEID']},未有工号";
|
||
continue;
|
||
}
|
||
if($currentHour>6 && $currentHour<18){
|
||
$grabs = $orderModel->field('count(*) as count,GRABNUM,POSTCODE,STOCKS')->where(['WAREHOUSEID'=>$WAREHOUSE['WAREHOUSEID'],'PRINTTIMES'=>0,'FLAG'=>0,'ISLOCK'=>0,'DISPLAYFLAG'=>0])->where("GRABNUM like '%B%'")->group('GRABNUM')->select();
|
||
foreach ($grabs as $grab){
|
||
$orders = $orderModel->field('ID')->where('GRABNUM="" or GRABNUM is null')->where(['WAREHOUSEID'=>$WAREHOUSE['WAREHOUSEID'],'STOCKS'=>$grab['STOCKS'],'POSTCODE'=>$grab['POSTCODE'],'FLAG'=>0,'ISLOCK'=>0,'DISPLAYFLAG'=>0])->select();
|
||
$isgrab = $WmstuanModel->where(["GRABNUM"=>$grab['GRABNUM']])->find();
|
||
if($isgrab){//是否自动加团中
|
||
$count = count($orders)+$grab['count'];
|
||
if($count>=$WAREHOUSE['count']){
|
||
$order_ids = [];
|
||
foreach ($orders as $r){
|
||
array_push($order_ids,$r['ID']);
|
||
}
|
||
if(count($order_ids)>0){
|
||
$IDSSTR = implode(",",$order_ids);
|
||
array_push($addTuans,["grab"=>$grab['GRABNUM'],"orders"=>$IDSSTR]);
|
||
Wsdl::webservice([$WAREHOUSE["WAREHOUSEID"],$WAREHOUSE["operatorID"],$IDSSTR,$grab['GRABNUM']],"addTuan");
|
||
}
|
||
}else{
|
||
$MergeModel = new \app\common\model\tuan\Merge;
|
||
|
||
$grabRow = Db::table('ye4s_tuan_merge_grabnum')->where('grabnum', $grab['GRABNUM'])->find();
|
||
if($grabRow){
|
||
$task = $MergeModel->field('id')->where(["WAREHOUSEID"=>$WAREHOUSE["WAREHOUSEID"]])->where("createtime>{$data_time}")->where('id', $grabRow['merge_id'])->find();
|
||
}else{
|
||
$task = null;
|
||
}
|
||
if(!$task){
|
||
Wsdl::webservice([$WAREHOUSE["WAREHOUSEID"],$WAREHOUSE["operatorID"],$grab['GRABNUM']],"cancelGrabWmsOrder");
|
||
array_push($cancelGrabWmsOrder,["grab"=>$grab['GRABNUM']]);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}else{
|
||
return "不在开启时间";
|
||
}
|
||
}
|
||
$this->redis->del($key);
|
||
return json([$addTuans,$cancelGrabWmsOrder]);
|
||
} catch (Exception $e) {
|
||
$this->redis->del($key);
|
||
return json(["error"=>$e]);
|
||
}
|
||
}
|
||
public function asyncOrder(){
|
||
$startTime = round(microtime(true) * 1000);
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
$WAREHOUSEMODEL = new \app\common\model\Warehouse;
|
||
$WAREHOUSES = $WAREHOUSEMODEL->where(["autoTuan"=>1])->select();
|
||
$IDSARRAY = [];
|
||
$lasttime=time()-60;
|
||
foreach ($WAREHOUSES as $WAREHOUSE){ //仓库循环
|
||
$IDS = [];
|
||
$list = $orderModel->field("ID")->where(["WAREHOUSEID"=>$WAREHOUSE["WAREHOUSEID"],"SYNFLAG"=>0,"POSTFLAG"=>1,"FLAG"=>0,"ISLOCK"=>0,"SOURCECODE"=>"Z05","DISPLAYFLAG"=>0])->where("CREATIONDATE<'00{$lasttime}000'")->order("CREATIONDATE desc")->select();
|
||
if(count($list)>0){
|
||
foreach ($list as $r){
|
||
array_push($IDS,$r["ID"]);
|
||
}
|
||
$IDSSTR = implode(",",$IDS);
|
||
Wsdl::webservice([$WAREHOUSE["WAREHOUSEID"],$WAREHOUSE["operatorID"],$IDSSTR],"synOrder");
|
||
}
|
||
$IDSARRAY[$WAREHOUSE["WAREHOUSEID"]] = $IDS;
|
||
}
|
||
return json([round(microtime(true) * 1000)-$startTime,$IDSARRAY]);
|
||
}
|
||
public function clearUser(){//自动清除用户,暂不用
|
||
$GztModel = new \app\common\model\Gzt;
|
||
$WAREHOUSEID = 5400;
|
||
$UserModel = new \app\admin\model\User;
|
||
$WMSUserModel = new \app\common\model\wms\User;
|
||
$list = $UserModel
|
||
->where(["WAREHOUSEID"=>$WAREHOUSEID])
|
||
->where('status', 'normal')
|
||
->where('wms_userid<>""')
|
||
->order("id","desc")
|
||
->select();
|
||
$list2 = $GztModel->where(["warehouseId"=>$WAREHOUSEID])->select();
|
||
$wms_userid = [];
|
||
foreach ($list as $r){
|
||
array_push($wms_userid,$r["wms_userid"]);
|
||
}
|
||
foreach ($list2 as $r){
|
||
array_push($wms_userid,$r["userid"]);
|
||
}
|
||
$OperatorModel = new \app\common\model\wms\Operator;
|
||
$list = $OperatorModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("USERID","not in",$wms_userid)->select();
|
||
$userids = [];
|
||
foreach($list as $r){
|
||
array_push($userids,$r["USERID"]);
|
||
$r->delete();
|
||
}
|
||
if(count($userids)>0){
|
||
$list = $WMSUserModel->where("userID","in",$userids)->select();
|
||
foreach ($list as $r){
|
||
$r->delete();
|
||
}
|
||
}
|
||
//$this->success("获取成功",$list);
|
||
return json($list);
|
||
}
|
||
public function createUser(){//创建用户,授权暂不使用
|
||
$res = Wsdl::webservice([5400,'wangyan003251','王燕','wangyan003251','入库,盘点,打包,拣货,移库,出库,分播,收货,快捷出入库,快递操作,不复核发货,线下出库'],"createUser");
|
||
return json($res);
|
||
}
|
||
public function getSpace(){
|
||
$params = $this->request->post();
|
||
$WAREHOUSEID = $params["WAREHOUSEID"]?$params["WAREHOUSEID"]:0;
|
||
$barcode = $params["BARCODE"]?$params["BARCODE"]:"";
|
||
$SpaceModel = new \app\common\model\wms\Space;
|
||
$space = $SpaceModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"BARCODE"=>$barcode])->find();
|
||
if(!$space){
|
||
return json(["msg"=>"库位不存在","spaceId"=>-1,"spaceName"=>""]);
|
||
}else{
|
||
return json(["msg"=>"库位".$space["CUSTOMNUM"],"spaceId"=>$space["ID"],"spaceName"=>$space["CUSTOMNUM"],"spaceIndex"=>$space["IDX"]]);
|
||
}
|
||
}
|
||
public function backrecord_back(){
|
||
$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;
|
||
$params = $this->request->post();
|
||
$STOCKID = $params["stockId"];
|
||
$space_id = $params["spaceId"];
|
||
$COUNT = $params["count"];
|
||
$date = ["00".strtotime($params["selectTime"][0])."000","00".(strtotime($params["selectTime"][1])+86399)."000"];
|
||
$STOCKS_tmp = $BackrecordModel->field("ID,a.STOCKID as STOCKID,COUNT as COUNT2,(SELECT sum(COUNT) as COUNT FROM yj_backrecord_back back WHERE back.back_id = a.ID and back.fake_stockid=0) AS COUNT")->alias("a")->where("a.CREATIONDATE","BETWEEN",$date)->where(["STATUS"=>0,"STOCKID"=>$STOCKID])->order('CREATIONDATE')->select();
|
||
$time = time();
|
||
$insetData = [];
|
||
foreach ($STOCKS_tmp as $r){
|
||
$r["COUNT"] = intval($r["COUNT"]);
|
||
if($r["COUNT2"]>$r["COUNT"]){
|
||
$count = $r["COUNT2"]-$r["COUNT"];
|
||
$count = $COUNT>$count?$count:$COUNT;
|
||
$COUNT-= $count;
|
||
if($count>0){
|
||
array_push($insetData,["backTime"=>$time,"back_id"=>$r["ID"],"SPACE_ID"=>$space_id,"fake_stockid"=>0,"COUNT"=>$count]);
|
||
}
|
||
}
|
||
}
|
||
$res = $BackrecordbackModel->saveAll($insetData);
|
||
return json(["msg"=>"归还库位成功","datas"=>[$res,$STOCKS_tmp,$insetData]]);
|
||
}
|
||
private function extractLastNumber($input) {
|
||
// 正则表达式匹配最后出现的数字及其前后部分
|
||
// 正则表达式匹配最后出现的数字及其前部分
|
||
preg_match('/^(.*?)(\d+)\D*$/', $input, $matches);
|
||
|
||
// 提取匹配到的字符串并存储到数组中
|
||
if (!empty($matches)) {
|
||
$result = array($matches[1], $matches[2]);
|
||
return $result;
|
||
} else {
|
||
return "未找到匹配的数字";
|
||
}
|
||
}
|
||
public function split_excel(){
|
||
$list = [];
|
||
$rootpath = dirname(__DIR__);
|
||
if ($this->request->isPost()){
|
||
try {
|
||
|
||
$file = request()->file('file'); // 从请求中获取上传的文件
|
||
if(!$file){
|
||
return json(['status'=>'error','msg'=>'未收到上传文件,请确认表单字段名为 file']);
|
||
}
|
||
$info = $file->validate(['size'=>15678000,'ext'=>'xls,xlsx'])->move( '../uploads');
|
||
if($info){
|
||
$filename = $info->getSaveName();
|
||
$filePath = '../uploads/' . $filename;
|
||
|
||
// 使用 PhpSpreadsheet 解析 Excel 文件
|
||
$spreadsheet = IOFactory::load($filePath);
|
||
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
||
$rowCount = count($sheetData);
|
||
for($i=2;$i<$rowCount;$i++){
|
||
$item = $sheetData[$i] ?? [];
|
||
$goods = explode(",",$item['E'] ?? '');
|
||
$goods = array_filter($goods, 'strlen');
|
||
foreach ($goods as $r){
|
||
$matches = $this->extractLastNumber($r);
|
||
//print_r($matches);die();
|
||
array_push($list,[$item['B'] ?? '',$item['C'] ?? '',$item['D'] ?? '',isset($matches[0])?$matches[0]:'',isset($matches[1])?$matches[1]:'']);
|
||
}
|
||
|
||
}
|
||
// 删除上传的临时文件
|
||
if(is_file($filePath)){
|
||
unlink($filePath);
|
||
}
|
||
$spreadsheet = new Spreadsheet();
|
||
$worksheet = $spreadsheet->getActiveSheet();
|
||
$title = '导出数据';
|
||
$worksheet->setTitle($title);
|
||
$worksheet->fromArray(
|
||
[
|
||
['姓名','电话','地址','商品名称','数量']
|
||
], '', 'A1' );
|
||
$worksheet->fromArray($list, '', 'A2' );
|
||
// 获取当前时间的秒数和微秒数
|
||
list($usec, $sec) = explode(" ", microtime());
|
||
// 将秒数转换为毫秒并拼接微秒数
|
||
$millisecondTimestamp = (int)($sec * 1000) + (int)($usec * 1000);
|
||
|
||
$exportDir = "{$rootpath}/../../../public/export";
|
||
if(!is_dir($exportDir)){
|
||
@mkdir($exportDir, 0777, true);
|
||
}
|
||
if(!is_writable($exportDir)){
|
||
@chmod($exportDir, 0777);
|
||
}
|
||
if(!is_writable($exportDir)){
|
||
$perm = substr(sprintf('%o', @fileperms($exportDir)), -4);
|
||
$ownerInfo = function_exists('posix_getpwuid') ? @posix_getpwuid(@fileowner($exportDir)) : null;
|
||
$userInfo = function_exists('posix_geteuid') ? @posix_getpwuid(posix_geteuid()) : null;
|
||
$owner = is_array($ownerInfo) ? $ownerInfo['name'] : 'unknown';
|
||
$user = is_array($userInfo) ? $userInfo['name'] : 'unknown';
|
||
$msg = "导出目录不可写:{$exportDir}(属主 {$owner},权限 {$perm},PHP 运行用户 {$user})";
|
||
\think\Log::error('[split_excel] ' . $msg);
|
||
return json(['status'=>'error','msg'=>$msg.',请在服务器执行:chown -R www:www '.$exportDir.' && chmod -R 775 '.$exportDir]);
|
||
}
|
||
$filePath = "{$exportDir}/{$millisecondTimestamp}.xlsx";
|
||
$url = "https://ye4s.wms.gztbyc.com/export/{$millisecondTimestamp}.xlsx";
|
||
$write = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||
$res = $write->save($filePath);
|
||
return json(['status' => 'true', 'message' => $file->getError(),'url'=>$url]);
|
||
} else {
|
||
return json(['status' => 'error', 'message' => $file->getError()]);
|
||
}
|
||
} catch (\Throwable $e) {
|
||
\think\Log::error('[split_excel] ' . $e->getMessage() . ' @ ' . $e->getFile() . ':' . $e->getLine());
|
||
return json(['status' => 'error', 'msg' => $e->getMessage(), 'at' => $e->getFile() . ':' . $e->getLine()]);
|
||
}
|
||
}
|
||
return $this->view->fetch();
|
||
}
|
||
public function storege_hasMore($WAREHOUSEID=""){//单个SKU占用多个分拣库位,移库预警
|
||
if(!$WAREHOUSEID){
|
||
return false;
|
||
}
|
||
$StorageModel = new \app\common\model\wms\Storage;
|
||
$kws = $StorageModel->alias('a')
|
||
->field('a.STOCKID as STOCKID,a.copycount as copycount,a.count as count,a.BARCODE as BARCODE,a.PRODUCTDATE as PRODUCTDATE,b.CUSTOMNUM as CUSTOMNUM,a.SPACEID as SPACEID,b.FIRSTFLAG as FIRSTFLAG,a.PRODUCTDATE as PRRODUCTDATE,b.IDX as IDX')
|
||
->join('yj_space b','b.ID=a.SPACEID','left')
|
||
->join('yj_stock stock','stock.STOCKID=a.STOCKID','left')
|
||
->where(['a.FLAG'=>0,'a.STATUS'=>1])
|
||
->where(['SPACECODE'=>"cc11"])
|
||
->where('a.count>0 and b.FIRSTFLAG=1 and a.WAREHOUSEID='.$WAREHOUSEID.' and stock.WARESTOREID>0')
|
||
->group('a.SPACEID,a.STOCKID')
|
||
->order('a.PRODUCTDATE')
|
||
->select();
|
||
$stocks = [];
|
||
$storages = [];
|
||
foreach ($kws as $r){
|
||
if(isset($storages[$r["STOCKID"]])){
|
||
$storages[$r["STOCKID"]]+=1;
|
||
}else{
|
||
$storages[$r["STOCKID"]]=1;
|
||
}
|
||
}
|
||
foreach ($storages as $k => $r){
|
||
if($r>1){
|
||
array_push($stocks,$k);
|
||
}
|
||
}
|
||
$StockModel = new \app\common\model\wms\Stock;
|
||
$list = $StockModel->where("STOCKID","in",$stocks)->with(['goods'])->select();
|
||
//print_r($list);die();
|
||
$spreadsheet = new Spreadsheet();
|
||
$worksheet = $spreadsheet->getActiveSheet();
|
||
$title = '需库位调整SKU数据';
|
||
$worksheet->setTitle($title);
|
||
$worksheet->fromArray(
|
||
[
|
||
['商品名称','颜色','规格','条码','库位']
|
||
], '', 'A1' );
|
||
$lists = [];
|
||
foreach ($list as $r){
|
||
$kwss = [];
|
||
foreach ($kws as $rr){
|
||
if($r["STOCKID"]==$rr["STOCKID"]){
|
||
array_push($kwss,$rr["CUSTOMNUM"]);
|
||
}
|
||
}
|
||
array_push($lists,[$r["goods"]["NAME"],$r["COLOR"],$r["STYLE"],$r["BARCODE"],implode('|',$kwss)]);
|
||
}
|
||
if(count($lists)==0){
|
||
return false;
|
||
}
|
||
$worksheet->fromArray($lists, '', 'A2' );
|
||
// 获取当前时间的秒数和微秒数
|
||
list($usec, $sec) = explode(" ", microtime());
|
||
// 将秒数转换为毫秒并拼接微秒数
|
||
$millisecondTimestamp = (int)($sec * 1000) + (int)($usec * 1000);
|
||
$rootpath = dirname(__DIR__);
|
||
$filePath = "{$rootpath}/../../../public/hasMoreExport/{$millisecondTimestamp}.xlsx";
|
||
$url = "https://ye4s.wms.gztbyc.com/hasMoreExport/{$millisecondTimestamp}.xlsx";
|
||
$write = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||
$res = $write->save($filePath);
|
||
$msg = $this->backFile(["fromid"=>"44379703923@chatroom"],$url);
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
$msg2 = $this->toMsg("44379703923@chatroom",date('Y/m/d')." 单个SKU占用多个分拣库位,需调整库位,文件名为{$millisecondTimestamp}.xlsx,请打印移交仓库内作业。");
|
||
$this->redis->lpush("Message",json_encode($msg2));
|
||
}
|
||
public function backFile($from,$url){
|
||
return [
|
||
"method"=>"sendFile",
|
||
"wxid"=> $from['fromid'],
|
||
"file"=> $url,
|
||
"fileType"=> 'url',
|
||
"pid"=> 0
|
||
];
|
||
}
|
||
public function storege_remaining(){//分拣库位数量过低,补货预警,暂未启用
|
||
$WAREHOUSEID = $this->request->get("WAREHOUSEID");
|
||
$room_id = $this->request->get("room_id");
|
||
$StorageModel = new \app\common\model\wms\Storage;
|
||
$kws = $StorageModel->alias('a')
|
||
->field('a.STOCKID as STOCKID,a.copycount as copycount,a.count as count,a.BARCODE as BARCODE,a.PRODUCTDATE as PRODUCTDATE,b.CUSTOMNUM as CUSTOMNUM,a.SPACEID as SPACEID,b.FIRSTFLAG as FIRSTFLAG,a.PRODUCTDATE as PRRODUCTDATE,b.IDX as IDX,stock.FJCOUNT as FJCOUNT')
|
||
->join('yj_space b','b.ID=a.SPACEID','left')
|
||
->join('yj_stock stock','stock.STOCKID=a.STOCKID','left')
|
||
->where(['a.FLAG'=>0,'a.STATUS'=>1])
|
||
->where('a.count>0 and b.FIRSTFLAG=1 and a.WAREHOUSEID='.$WAREHOUSEID.' and stock.WARESTOREID>0')
|
||
->group('a.SPACEID,a.STOCKID')
|
||
->order('a.PRODUCTDATE')
|
||
->select();
|
||
$stocks = [];
|
||
$storages = [];
|
||
foreach ($kws as $r){
|
||
if(isset($storages[$r["STOCKID"]])){
|
||
$storages[$r["STOCKID"]]+=1;
|
||
}else{
|
||
if($r["FJCOUNT"]>$r["copycount"] || ($r["FJCOUNT"]==0 && $r["copycount"]<500)){
|
||
$storages[$r["STOCKID"]]=1;
|
||
}
|
||
}
|
||
}
|
||
foreach ($storages as $k => $r){
|
||
if($r==1){
|
||
array_push($stocks,$k);
|
||
}
|
||
}
|
||
|
||
return json($stocks);
|
||
}
|
||
public function getGrabnum(){
|
||
|
||
$WarehouseModel = new \app\common\model\Warehouse;
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$GRABS = $OrderModel->field("WAREHOUSEID,SUM(GOODSCOUNT) as GOODSCOUNT,POSTNUM,GRABNUM,ITEMS,COUNT(*) as COUNT,OPERATERECORDS")->where("GRABNUM not like '%B%' and GRABNUM <>'' and WAREHOUSEID=5400")->where("DISPLAYFLAG=0")->group("GRABNUM")->select();
|
||
$GRABNUMS = [];
|
||
foreach ($GRABS as $r){
|
||
array_push($GRABNUMS,$r["GRABNUM"]);
|
||
}
|
||
$WorksModel = new \app\common\model\workers\Works;
|
||
$works = $WorksModel->where("grabnum","in",$GRABNUMS)->where("picks<>0")->select();
|
||
$out_GRABNUM = [];
|
||
$GRABNUMS2 = [];
|
||
foreach ($works as $r){
|
||
array_push($GRABNUMS2,$r["grabnum"]);
|
||
}
|
||
foreach ($GRABNUMS as $R){
|
||
if(!in_array($R,$GRABNUMS2)){
|
||
array_push($out_GRABNUM,$R);
|
||
}
|
||
}
|
||
$tmp = [];
|
||
foreach ($out_GRABNUM as $r){
|
||
foreach ($GRABS as $rr){
|
||
if($rr["GRABNUM"]==$r && (strpos($rr["OPERATERECORDS"], "拣货") !== false)){
|
||
array_push($tmp,$rr);
|
||
}
|
||
}
|
||
}
|
||
$WAREHOUSEconfig = $WarehouseModel->where(['WAREHOUSEID'=>5400])->find();
|
||
$workDate = ($WAREHOUSEconfig['workDate'] ?? null);
|
||
$update = [];
|
||
$time = time();
|
||
foreach ($tmp as $r){
|
||
$OPERATERECORDS = explode("|",$r["OPERATERECORDS"]);
|
||
$userid = 0;
|
||
foreach ($OPERATERECORDS as $rr){
|
||
$tmpdata = explode(";",$rr);
|
||
if(strpos($tmpdata[0],"拣货")!==false){
|
||
$username = $tmpdata[2];
|
||
$userid = $this->getNameByuser($username);
|
||
}
|
||
}
|
||
$tmp_update = [
|
||
"lingliaos"=>0,
|
||
"picks"=>$r["COUNT"],
|
||
"fuhe"=>0,
|
||
"dabaos"=>0,
|
||
"workDate"=>$workDate,
|
||
"userId"=>$userid,
|
||
"grabnum"=>$r["GRABNUM"],
|
||
"POSTNUM"=>$r["POSTNUM"],
|
||
"WAREHOUSEID"=>$r["WAREHOUSEID"],
|
||
"updatetime"=>0,
|
||
"createtime"=>$time,
|
||
"workers"=>"",
|
||
"GOODSCOUNT"=>$r["GOODSCOUNT"],
|
||
"items"=>"",
|
||
"carid"=>"",
|
||
"isSandan"=>0,
|
||
"updatetime"=>0,
|
||
"orders"=>"",
|
||
"types"=>0,
|
||
"count"=>0
|
||
];
|
||
array_push($update,$tmp_update);
|
||
}
|
||
$WorksModel->saveAll($update);
|
||
return json($update);
|
||
}
|
||
private function getNameByuser($username){
|
||
$id = 0 ;
|
||
$UserModel = new \app\common\model\wms\User;
|
||
$user = $UserModel->where(["name"=>$username])->find();
|
||
if($user){
|
||
$id = $user->userID;
|
||
}
|
||
return $id;
|
||
}
|
||
public function fileInfo(){
|
||
$redis = $this->express_redis;
|
||
$rawData = $redis->rpoplpush("file_infos", "file_infos_processing");
|
||
if (!$rawData) {
|
||
\think\Log::info("队列为空,退出");
|
||
return "0";
|
||
}
|
||
|
||
\think\Log::info("========== 开始消费 ==========");
|
||
\think\Log::info("原始数据: " . $rawData);
|
||
|
||
try {
|
||
$decoded = json_decode($rawData, true);
|
||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||
throw new \Exception("Invalid JSON: " . json_last_error_msg());
|
||
}
|
||
if (empty(($decoded['method_name'] ?? null)) || empty(($decoded['data'] ?? null))) {
|
||
$decoded['method_name'] = "tuijian";
|
||
//throw new \Exception("Missing method_name or data");
|
||
}
|
||
|
||
$method_name = ($decoded['method_name'] ?? null);
|
||
$data = ($decoded['data'] ?? null);
|
||
|
||
$insetData = [
|
||
'time' => $data['time'] ?? 0,
|
||
'name' => $data['name'] ?? '',
|
||
'user_id' => $data['userId'] ?? 0,
|
||
'path' => $data['path'] ?? '',
|
||
'update_time' => $data['data_time'] ?? time(),
|
||
'create_time' => $data['data_time'] ?? time(),
|
||
];
|
||
|
||
\think\Log::info("组装后的入库数据: " . json_encode($insetData));
|
||
|
||
$class = "\\app\\common\\model\\file\\" . ucfirst($method_name);
|
||
if (!class_exists($class)) {
|
||
throw new \Exception("Class {$class} not found");
|
||
}
|
||
$model = new $class();
|
||
|
||
// ====== 防重检查 ======
|
||
\think\Log::info("防重查询条件: name = " . $insetData['name']);
|
||
$exist = $model->where(['name'=>$insetData['name'],'path'=>$insetData['path']])->find();
|
||
if ($exist) {
|
||
\think\Log::info("数据已存在,跳过插入,删除队列元素");
|
||
$redis->lrem("file_infos_processing", $rawData, 1);
|
||
return json(['code' => 0, 'msg' => '数据已存在,跳过']);
|
||
} else {
|
||
\think\Log::info("数据不存在,准备插入");
|
||
}
|
||
|
||
// ====== 插入 ======
|
||
try {
|
||
$res = $model->saveAll([$insetData]);
|
||
\think\Log::info("saveAll 执行结果: " . json_encode($res));
|
||
if ($res === false) {
|
||
throw new \Exception("Database save failed (返回false)");
|
||
}
|
||
} catch (\Exception $e) {
|
||
\think\Log::error("插入时发生异常: " . $e->getMessage() . "\n追踪:" . $e->getTraceAsString());
|
||
throw $e; // 重新抛出给外层捕获
|
||
}
|
||
|
||
// ====== 成功删除队列 ======
|
||
$redis->lrem("file_infos_processing", $rawData, 1);
|
||
\think\Log::info("消费成功,队列已删除");
|
||
return json($res);
|
||
|
||
} catch (\Exception $e) {
|
||
\think\Log::error("fileInfo消费失败: " . $e->getMessage() . "\n原始数据: " . $rawData . "\n追踪: " . $e->getTraceAsString());
|
||
// 真正的异常才进入死信
|
||
$redis->rpush("file_infos_dead", $rawData);
|
||
$redis->lrem("file_infos_processing", $rawData, 1);
|
||
return "0";
|
||
}
|
||
}
|
||
public function getPath(){
|
||
$params = $this->request->post();
|
||
$method_name = "\\app\\common\\model\\file\\".ucfirst($params["method"]);
|
||
$mode = new $method_name();
|
||
$data = $mode->where(["name"=>$params["name"]])->select();
|
||
return json($data);
|
||
}
|
||
public function lanjieNotic(){
|
||
$res = $this->redis->rpop("lanjies");
|
||
if($res){
|
||
$order = json_decode($res,true);
|
||
if($order && isset($order["ID"])){
|
||
$this->closeLanjie($order["ID"]);
|
||
}
|
||
}
|
||
return "";
|
||
}
|
||
private function closeLanjie($ID){
|
||
$Model = new \app\common\model\wms\Exceptionwmsorder;
|
||
$rows = $Model->where(["WMSORDERID"=>$ID,"STATUS"=>12])->select();
|
||
foreach ($rows as $r){
|
||
$res = Wsdl::webservice(['','','库内拦截成功',$r["ID"]],"updateExceptionWmsOrder");
|
||
$res = Wsdl::webservice([$r["ID"]],"confirmExceptionWmsOrder");
|
||
}
|
||
}
|
||
public function saveSpace(){
|
||
$params = $this->request->post();
|
||
$WAREHOUSEID = $params["WAREHOUSEID"]?$params["WAREHOUSEID"]:0;
|
||
$barcode = $params["spaceInfo"]["spaceId"]?$params["spaceInfo"]["spaceId"]:"";
|
||
$SpaceModel = new \app\common\model\wms\Space;
|
||
$space = $SpaceModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"ID"=>$barcode])->find();
|
||
$CUSTOMNUM = str_replace(['上', '下'], '', ($space["CUSTOMNUM"] ?? null));
|
||
$CUSTOMNUM = substr($CUSTOMNUM, 0, -2);
|
||
$arr = [];
|
||
if($CUSTOMNUM=="B1区06-" || $CUSTOMNUM=="B2区13-"){
|
||
array_push($arr,$space);
|
||
$space->IDX = $params["spaceInfo"]["spaceIndex"];
|
||
$space->save();
|
||
}else{
|
||
$spaces = $SpaceModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("CUSTOMNUM like '%".$CUSTOMNUM."%'")->select();
|
||
|
||
foreach ($spaces as $r){
|
||
$r->IDX = $params["spaceInfo"]["spaceIndex"];
|
||
array_push($arr,$r);
|
||
$r->save();
|
||
}
|
||
}
|
||
return json(["msg"=>"设置成功","data"=>$arr]);
|
||
}
|
||
public function deleteOrder($WAREHOUSEID=""){
|
||
if(!$WAREHOUSEID){
|
||
return json([]);
|
||
}
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$WarehouseModel = new \app\common\model\Warehouse;
|
||
$WAREHOUSE = $WarehouseModel->field('operatorID')->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
$list = $OrderModel->field("ID")->where("WAREHOUSEID={$WAREHOUSEID} and DISPLAYFLAG=0 and FLAG=1 and PLSENDFLAG=0 and GRABNUM not like '%B%' and GRABNUM is not null and GRABNUM<>''")->select();
|
||
$arr = [];
|
||
foreach ($list as $r){
|
||
array_push($arr,$r["ID"]);
|
||
}
|
||
$ids = implode(",",$arr);
|
||
$res = Wsdl::webservice([$WAREHOUSEID,($WAREHOUSE["operatorID"] ?? null),$ids],"deleteOrder");
|
||
return json($res);
|
||
}
|
||
public function weChatLog(){
|
||
$count = 0;
|
||
$lcount = 1;
|
||
$tmp_msg = "";
|
||
$orders = [];
|
||
do{
|
||
$jsontext = $this->redis->rpop("msgsin2");
|
||
|
||
if($jsontext){
|
||
$data = json_decode($jsontext,true);
|
||
if(isset($orders[($data['wxid'] ?? null)])){
|
||
array_push($orders[($data['wxid'] ?? null)],($data['msg'] ?? null));
|
||
}else{
|
||
$orders[($data['wxid'] ?? null)] = [($data['msg'] ?? null)];
|
||
}
|
||
$count++;
|
||
}
|
||
}while($jsontext&&$count<=200);
|
||
}
|
||
public function checkBackOrder(){
|
||
$params = $this->request->post();
|
||
$wareHouseId = $params["wareHouseId"];
|
||
$userId = $params["userid"];
|
||
$postnum = $params["postnum"];
|
||
$postnum_length = strlen($postnum);
|
||
if($postnum_length>20 || $postnum_length<8){
|
||
return json(["msg"=>"扫描失败,条码长度不合法","status"=>0,"text"=>"","POSTNUM"=>""]);
|
||
}
|
||
$Backorderrecord = new \app\common\model\Backorderrecord;
|
||
$data = $Backorderrecord->where(["POSTNUM"=>$postnum])->find();
|
||
if($data){
|
||
return json(["msg"=>"已扫描","status"=>0,"POSTNUM"=>$postnum,"remask"=>$data["remask"]]);
|
||
}else{
|
||
$this->express_redis->lpush("tuihuisaomiao_{$wareHouseId}",$postnum);
|
||
$this->express_redis->close();
|
||
$res = Wsdl::webservice([$wareHouseId,$userId,$postnum],"checkBackOrder");
|
||
$res = json_decode($res,true);
|
||
$res = $res[0];
|
||
$pattern = '/快递号\s*:\s*([A-Za-z0-9]+)/';
|
||
$expressNumber = null;
|
||
// 用正则表达式匹配快递号
|
||
if (preg_match($pattern, $res["info"], $matches)) {
|
||
$expressNumber = $matches[1];
|
||
}
|
||
$tip ="";
|
||
$order = $this->getOrderInfoByPostnum($postnum);
|
||
if($order && (($order["STOREID"] ?? null)==17501||($order["STOREID"] ?? null)==57601||($order["STOREID"] ?? null)==57602||($order["STOREID"] ?? null)==57603||($order["STOREID"] ?? null)==57702)){
|
||
$tip = "丰姿原单";
|
||
}
|
||
if($expressNumber){
|
||
$Backorderrecord->save(["POSTNUM"=>$postnum,"USERID"=>$userId,"CREATIONDATE"=>time(),"WAREHOUSEID"=>$wareHouseId]);
|
||
return json(["msg"=>"扫描成功{$tip}".$res["tips"],"status"=>1,"text"=>$res,"POSTNUM"=>$expressNumber]);
|
||
}else{
|
||
return json(["msg"=>"扫描失败","status"=>0,"text"=>$res,"POSTNUM"=>$expressNumber]);
|
||
}
|
||
}
|
||
}
|
||
public function tuihuisaomiaochujilu(){
|
||
$count = 0;
|
||
$msgs = [];
|
||
$has = true;
|
||
$WAREHOUSEID = $this->request->get("WAREHOUSEID");
|
||
$WAREHOUSENAME = $this->request->get("WAREHOUSENAME");
|
||
do{
|
||
$data = $this->express_redis->rpop("tuihuisaomiao_{$WAREHOUSEID}");
|
||
if(!$data){
|
||
$has = false;
|
||
}else{
|
||
//查异常跟踪单表是拦截且未结束
|
||
$model = new \app\common\model\wms\Exceptionwmsorder;
|
||
$datas = $model->where(["POSTNUM"=>$data,"STATUS"=>12,"TYPE"=>0])->where(["WAREHOUSEID"=>$WAREHOUSEID])->select();
|
||
//判断是否有
|
||
if($datas){
|
||
//有拦截未结束,通知货主主群
|
||
$storeID = $datas[0]["STOREID"];
|
||
//所有行完结
|
||
foreach($datas as $r){
|
||
$res = Wsdl::webservice(['','','拦截成功',$r["ID"]],"updateExceptionWmsOrder");
|
||
$res = Wsdl::webservice([$r["ID"]],"confirmExceptionWmsOrder");
|
||
}
|
||
//获取货主主群
|
||
$RoomsModel = new \app\common\model\Rooms;
|
||
$room = $RoomsModel->where(["STOREID"=>$storeID,"isMain"=>1])->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
if($room){
|
||
if(array_key_exists($room['room_id'], $msgs)){
|
||
$msgs[$room['room_id']]['text'] .="\n".$data;
|
||
}else{
|
||
$msgs[$room['room_id']]['text'] = $data;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}while($has);
|
||
foreach ($msgs as $k => $r){
|
||
$msg = $this->toMsg($k,"快递退回扫描通知:\n".$r["text"]."\n已退回{$WAREHOUSENAME}等待拆包");
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
}
|
||
}
|
||
public function checkBackOrderRemask(){
|
||
$params = $this->request->post();
|
||
$remask = $params["remask"];
|
||
$postnum = $params["postnum"];
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$Backorderrecord = new \app\common\model\Backorderrecord;
|
||
|
||
$data = $Backorderrecord->where(["POSTNUM"=>$postnum])->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
if($data){
|
||
$data->remask = $remask;
|
||
$data->save();
|
||
return json(["msg"=>"记录成功"]);
|
||
}else{
|
||
return json(["msg"=>"无扫描记录"]);
|
||
}
|
||
}
|
||
private function getTimestampRange() {
|
||
// 获取昨天早上9点的时间戳
|
||
$yesterdayTimestamp = strtotime('yesterday 9:00');
|
||
|
||
// 获取今天早上8点59分59秒的时间戳
|
||
$todayEndTimestamp = strtotime('today 8:59:59');
|
||
|
||
return array($yesterdayTimestamp, $todayEndTimestamp);
|
||
}
|
||
private function setTuijianwork($userId,$postnum,$GOODSCOUNT,$WAREHOUSEID){
|
||
$WarehouseModel = new \app\common\model\Warehouse;
|
||
$WAREHOUSEconfig = $WarehouseModel->where(['WAREHOUSEID'=>$WAREHOUSEID])->find();
|
||
$workDate = ($WAREHOUSEconfig['workDate'] ?? null);
|
||
$Model = new \app\common\model\workers\Works;
|
||
$data = $Model->where(["POSTNUM"=>$postnum,"tuijian"=>1])->find();
|
||
if($data){
|
||
return json(["code"=> -1,"data"=> null,"msg"=> "已记录"]);
|
||
}else{
|
||
$insetData = [
|
||
"tuijian"=>1,
|
||
"POSTNUM"=>$postnum,
|
||
"grabnum"=>"0",
|
||
"WAREHOUSEID"=>$WAREHOUSEID,
|
||
"workDate"=>$workDate,
|
||
"GOODSCOUNT"=>$GOODSCOUNT,
|
||
"userId"=>$userId
|
||
];
|
||
$res = $Model->save($insetData);
|
||
return json(["code"=> 1,"data"=> $res,"msg"=> "记录成功"]);
|
||
}
|
||
}
|
||
public function setTiedanWork(){
|
||
$WarehouseModel = new \app\common\model\Warehouse;
|
||
$params = $this->request->post();
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$WAREHOUSEconfig = $WarehouseModel->where(['WAREHOUSEID'=>$WAREHOUSEID])->find();
|
||
$workDate = ($WAREHOUSEconfig['workDate'] ?? null);
|
||
$POSTNUM = $params["POSTNUM"];
|
||
$GRABNUM = $params["GRABNUM"];
|
||
$userId = $params["userId"];
|
||
$WorksModel = new \app\common\model\workers\Works;
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$model = new \app\common\model\wms\Deliveryorder;
|
||
$line = $WorksModel->where(["grabnum"=>$GRABNUM])->where("tiedan>0")->find();
|
||
if($line){
|
||
return "已记录";
|
||
}
|
||
$order = $OrderModel->where(["GRABNUM"=>$GRABNUM,"FLAG"=>0])->count();
|
||
if(!$order){
|
||
$order = $model->where(["GRABNUM"=>$GRABNUM,"FLAG"=>0])->count();
|
||
}
|
||
$count = $order;
|
||
$insetData = [
|
||
"tiedan"=>$count,
|
||
"POSTNUM"=>$POSTNUM,
|
||
"grabnum"=>$GRABNUM,
|
||
"WAREHOUSEID"=>$WAREHOUSEID,
|
||
"workDate"=>$workDate,
|
||
"GOODSCOUNT"=>0,
|
||
"userId"=>$userId
|
||
];
|
||
$res = $WorksModel->save($insetData);
|
||
return json([$res,$count,$insetData]);
|
||
}
|
||
private function getRoomID($WAREHOUSEID,$count){
|
||
$WarehouseModel = new \app\common\model\Warehouse;
|
||
$info = $WarehouseModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
$roomkey = "room{$count}";
|
||
return ($info[$roomkey] ?? null);
|
||
}
|
||
public function sendBackorderecord(){
|
||
$Backorderrecord = new \app\common\model\Backorderrecord;
|
||
$BackorderrecordWMS = new \app\common\model\wms\Backorderrecord;
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$Order1Model = new \app\common\model\wms\Order1;
|
||
$model = new \app\common\model\wms\Deliveryorder;
|
||
$StoreModel = new \app\common\model\wms\Warestore;
|
||
$OperatorModel = new \app\common\model\wms\Operator;
|
||
$WAREHOUSEID = $this->request->get("WAREHOUSEID");
|
||
$room_id = $this->getRoomID($WAREHOUSEID,1);
|
||
[$startTime,$endTime] = $this->getTimestampRange();
|
||
$list = $Backorderrecord->field("POSTNUM,USERID")->where("CREATIONDATE","BETWEEN",[$startTime,$endTime])->select();
|
||
$list2 = $BackorderrecordWMS->field("POSTNUM,USERID")->where("WAREHOUSEID=".$WAREHOUSEID)->where("CREATIONDATE","BETWEEN",["00".$startTime."000","00".$endTime."999"])->select();
|
||
$tmplist1 = [];
|
||
$tmplist2 = [];
|
||
foreach ($list as $r){
|
||
array_push($tmplist1,$r["POSTNUM"]);
|
||
}
|
||
foreach ($list2 as $r){
|
||
array_push($tmplist2,$r["POSTNUM"]);
|
||
}
|
||
$mergedArray = array_values(array_unique(array_merge($list, $list2)));
|
||
$POSTNUMS=[];
|
||
foreach($mergedArray as $r){
|
||
array_push($POSTNUMS,$r["POSTNUM"]);
|
||
}
|
||
$list1 = $OrderModel->field("POSTNUM,STOREID")->where("POSTNUM","in",$POSTNUMS)->select();
|
||
$list2 = $Order1Model->field("POSTNUM,STOREID")->where("POSTNUM","in",$POSTNUMS)->select();
|
||
$list3 = $model->field("POSTNUM,STOREID")->where("POSTNUM","in",$POSTNUMS)->select();
|
||
$list = array_values(array_unique(array_merge(array_merge($list1,$list2),$list3)));
|
||
$Storelist = $StoreModel->with(['employees'])->where(["WAREHOUSEID"=>$WAREHOUSEID])->select();
|
||
$userlist = $OperatorModel->field('USERID as id,USERID')->where(["WAREHOUSEID"=>$WAREHOUSEID])->with(['user'])->group("USERID")->select();
|
||
foreach($userlist as $r){
|
||
$r['name'] = $r->user->name;
|
||
unset($r['user']);
|
||
}
|
||
$stores_data = [];
|
||
foreach ($mergedArray as $k => $rr){
|
||
foreach ($list as $r){
|
||
if($rr["POSTNUM"]==$r["POSTNUM"]){
|
||
$mergedArray[$k]["STOREID"] = $r["STOREID"];
|
||
}
|
||
}
|
||
$mergedArray[$k]["remask"] = isset($rr["remask"])?$rr["remask"]:"";
|
||
$mergedArray[$k]["STORENAME"] = isset($rr["STOREID"])?$this->getStoreName($Storelist,$rr["STOREID"]):'';
|
||
$mergedArray[$k]["USERNAME"] = $this->getUserName($userlist,$rr["USERID"]);
|
||
if(isset($rr["STOREID"])){
|
||
if(!array_key_exists($rr['STOREID'],$stores_data)){
|
||
$stores_data[$rr['STOREID']] = [$rr];
|
||
}else{
|
||
array_push($stores_data[$rr['STOREID']],$rr);
|
||
}
|
||
}
|
||
}
|
||
$this->sendtuihuoTohuozhu($WAREHOUSEID,$stores_data);
|
||
$spreadsheet = new Spreadsheet();
|
||
$worksheet = $spreadsheet->getActiveSheet();
|
||
$title = '退回收件扫描数据';
|
||
$worksheet->setTitle($title);
|
||
$worksheet->fromArray(
|
||
[
|
||
['快递号','货主','扫描人','备注']
|
||
], '', 'A1' );
|
||
$lists = [];
|
||
foreach ($mergedArray as $r){
|
||
array_push($lists,[$r["POSTNUM"],$r["STORENAME"],$r["USERNAME"],$r["remask"]]);
|
||
}
|
||
if(count($lists)==0){
|
||
return false;
|
||
}
|
||
$worksheet->fromArray($lists, '', 'A2' );
|
||
// 获取当前时间的秒数和微秒数
|
||
list($usec, $sec) = explode(" ", microtime());
|
||
// 将秒数转换为毫秒并拼接微秒数
|
||
$millisecondTimestamp = (int)($sec * 1000) + (int)($usec * 1000);
|
||
$rootpath = dirname(__DIR__);
|
||
$filePath = "{$rootpath}/../../../public/tuihuiSacn/{$millisecondTimestamp}.xlsx";
|
||
$url = "https://ye4s.wms.gztbyc.com/tuihuiSacn/{$millisecondTimestamp}.xlsx";
|
||
$write = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||
$res = $write->save($filePath);
|
||
$msg = $this->backFile(["fromid"=>$room_id],$url);
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
$msg2 = $this->toMsg($room_id,date('Y/m/d')." 昨日退回收件扫描数据,文件名为{$millisecondTimestamp}.xlsx");
|
||
$this->redis->lpush("Message",json_encode($msg2));
|
||
return json([$mergedArray,$startTime,$endTime]);
|
||
}
|
||
private function getStoreName($list,$id){
|
||
$NAME = "";
|
||
foreach ($list as $r){
|
||
if($r["STOREID"]==$id){
|
||
$NAME = $r["TITLE"];
|
||
}
|
||
}
|
||
return $NAME;
|
||
}
|
||
private function getUserName($list,$id){
|
||
$NAME = "";
|
||
foreach ($list as $r){
|
||
if($r["USERID"]==$id){
|
||
$NAME = $r["name"];
|
||
}
|
||
}
|
||
return $NAME;
|
||
}
|
||
private function sendtuihuoTohuozhu($WAREHOUSEID,$data){
|
||
$RoomsModel = new \app\common\model\Rooms;
|
||
foreach($data as $k => $rr){
|
||
$room = $RoomsModel->where(["STOREID"=>$k,"isMain"=>1])->find();
|
||
if($room){
|
||
$spreadsheet = new Spreadsheet();
|
||
$worksheet = $spreadsheet->getActiveSheet();
|
||
$title = '退回收件扫描数据';
|
||
$worksheet->setTitle($title);
|
||
$worksheet->fromArray(
|
||
[
|
||
['快递号','扫描人','备注']
|
||
], '', 'A1' );
|
||
$lists = [];
|
||
foreach ($rr as $r){
|
||
array_push($lists,[$r["POSTNUM"],$r["USERNAME"],$r["remask"]]);
|
||
}
|
||
if(count($lists)==0){
|
||
return false;
|
||
}
|
||
$worksheet->fromArray($lists, '', 'A2' );
|
||
// 获取当前时间的秒数和微秒数
|
||
list($usec, $sec) = explode(" ", microtime());
|
||
// 将秒数转换为毫秒并拼接微秒数
|
||
$millisecondTimestamp = (int)($sec * 1000) + (int)($usec * 1000);
|
||
$rootpath = dirname(__DIR__);
|
||
$filePath = "{$rootpath}/../../../public/tuihuiSacn/{$k}{$millisecondTimestamp}.xlsx";
|
||
$url = "https://ye4s.wms.gztbyc.com/tuihuiSacn/{$k}{$millisecondTimestamp}.xlsx";
|
||
$write = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||
$res = $write->save($filePath);
|
||
$msg = $this->backFile(["fromid"=>$room["room_id"]],$url);
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
$msg2 = $this->toMsg($room["room_id"],date('Y/m/d')." 昨日已退回收件扫描数据,文件名为{$k}{$millisecondTimestamp}.xlsx,只是退回收件扫描,可能未拆包");
|
||
$this->redis->lpush("Message",json_encode($msg2));
|
||
}
|
||
}
|
||
}
|
||
//每小时一次,检测货主是否换绑以及货主面单余额是否到境界线
|
||
public function create_store_balance(){
|
||
$WAREHOUSEID = 5400;
|
||
$StoreModel = new \app\common\model\wms\Store;
|
||
$AccountModel = new \app\common\model\wms\Account;
|
||
$BalanceModel = new \app\common\model\store\Balance;
|
||
$RoomsModel = new \app\common\model\Rooms;
|
||
$UserRule = new \app\common\model\UserRule;
|
||
$ExpressModel = new \app\common\model\wms\Express;
|
||
//通知客服群的数组集合
|
||
$me_msg = [];
|
||
//查询余额表账户,条件为已绑定货主的账号
|
||
$list = $BalanceModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("store_id is not null")->select();
|
||
//遍历数组
|
||
$storeids = [];
|
||
foreach($list as $r){
|
||
//检查user_id是否在表yj_store表上有绑定货主
|
||
$datas = $StoreModel->where(["STOREID"=>$r["store_id"],"USERID"=>$r["user_id"]])->find();
|
||
if(!$datas){
|
||
//没有绑定货主,执行解绑流程
|
||
//获取该货主的所有群绑定;
|
||
$rooms = $RoomsModel->where("STOREID","in",$r["store_id"])->select();
|
||
//遍历解除绑定
|
||
foreach ($rooms as $room){
|
||
$data["room_names"] .= $this->getRoomName($room["room_id"]);
|
||
$room->delete();
|
||
}
|
||
//获取该货主的所有小程序账号的绑定;
|
||
$users = $UserRule->where(["store_id"=>$r["store_id"]])->select();
|
||
$userids = [];
|
||
//遍历解除绑定
|
||
foreach ($users as $r){
|
||
array_push($userids,$r["user_id"]);
|
||
//解除账号对货主的绑定
|
||
$r->delete();
|
||
}
|
||
$usermodel = new \app\common\model\User;
|
||
$users = $usermodel->where("id","in",$userids)->select();
|
||
|
||
foreach($user as $r){
|
||
$data["users"].= $r["real_name"].";";
|
||
$r->group_id = 1;
|
||
$r->save();
|
||
}
|
||
$data['account'] = $r["account"];
|
||
$data['store_name'] = $r['name'];
|
||
$msg = $this->balance_msg(0,$data);
|
||
array_push($me_msg,$msg);
|
||
}else{
|
||
//聚合已有的绑定的货主id
|
||
array_push($storeids,$r["store_id"]);
|
||
}
|
||
}
|
||
//排除查询仓库其他货主
|
||
//聚合账号id和货主id,货主名称为数组
|
||
$stores = $StoreModel->field("store.STOREID,store.USERID,store.TITLE")
|
||
->alias("store")
|
||
->join('yj_warestore warestore','warestore.STOREID=store.STOREID')
|
||
->where("store.STOREID","not in",$storeids)
|
||
->where("warestore.WAREHOUSEID=".$WAREHOUSEID)
|
||
->select();
|
||
//遍历数组
|
||
$insetDatas = [];
|
||
foreach ($stores as $r){
|
||
//利用货主名称查询余额账户表,是否货主名称未修改
|
||
$line = $BalanceModel->where(["name"=>$r["TITLE"]])->find();
|
||
//存在货主名称,执行通知,不变更
|
||
if($line){
|
||
$data["store_name"] = $r["TITLE"];
|
||
$msg = $this->balance_msg(2,$data);
|
||
array_push($me_msg,$msg);
|
||
}else{
|
||
//不存在旧的货主名称
|
||
//在余额表根据userid和货主名称、货主id创建行
|
||
$insetData = [
|
||
"name"=>$r["TITLE"],
|
||
"user_id"=>$r["USERID"],
|
||
"store_id"=>$r["STOREID"],
|
||
"balance"=>0,
|
||
"yjbalance"=>0,
|
||
"WAREHOUSEID"=>$WAREHOUSEID
|
||
];
|
||
//提交到创建数组
|
||
array_push($insetDatas,$insetData);
|
||
$data["store_name"] = $r["TITLE"];
|
||
$msg = $this->balance_msg(1,$data);
|
||
array_push($me_msg,$msg);
|
||
}
|
||
}
|
||
//如需创建,执行创建
|
||
if(count($insetDatas)>0){
|
||
$BalanceModel->saveAll($insetDatas);
|
||
}
|
||
}
|
||
public function checkBalance(){//暂未使用
|
||
$WAREHOUSEID = 5400;
|
||
$StoreModel = new \app\common\model\wms\Store;
|
||
$AccountModel = new \app\common\model\wms\Account;
|
||
$BalanceModel = new \app\common\model\store\Balance;
|
||
$RoomsModel = new \app\common\model\Rooms;
|
||
$UserRule = new \app\common\model\UserRule;
|
||
$ExpressModel = new \app\common\model\wms\Express;
|
||
//通知客服群的数组集合
|
||
$me_msg = [];
|
||
$data = [
|
||
"store_name"=>"",
|
||
"account"=>0,
|
||
"room_names"=>"",
|
||
"users"=>"",
|
||
"room_name"=>"",
|
||
"dsaccount"=>0,
|
||
"price"=>0,
|
||
"useAccount"=>0,
|
||
"lastaccount"=>0,
|
||
"lastin"=>0,
|
||
"inaccount"=>0,
|
||
"canuseAccount"=>0
|
||
];
|
||
//重新获取余额表账户
|
||
$list = $BalanceModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("store_id is not null")->select();
|
||
//遍历余额表账户
|
||
foreach ($list as $r){
|
||
//查询货主主群
|
||
$room = $RoomsModel->where(["STOREID"=>$r["store_id"],"isMain"=>1])->find();
|
||
//获取货主待处理订单已分配订单数量
|
||
$todayEndTimestamp = $this->getTargetTimestamp();
|
||
$count = $ExpressModel->field("count(*) as COUNT")->where(["STOREID"=>$r["store_id"]])->where("CREATIONDATE",">=","00".$todayEndTimestamp."000")->select();
|
||
//判断余额减去已分配订单数量是否小于余额表预警值,小于预警值,通知提醒充单
|
||
if($r["balance"]-$count[0]["COUNT"]<=$r["yjbalance"]){
|
||
//检测主群是否存在
|
||
if($room){
|
||
$data["canuseAccount"] = $r["balance"]-$count[0]["COUNT"];
|
||
$data["dsaccount"] = $r["yjbalance"];
|
||
$data["price"] = $r["price"];
|
||
$msg = $this->balance_msg(4,$data);
|
||
//通知客服群
|
||
$data["store_name"] = $r["name"];
|
||
$data["room_name"] = $this->getRoomName($room["room_id"]);
|
||
$msg = $this->balance_msg(3,$data);
|
||
array_push($me_msg,$msg);
|
||
}else{
|
||
$data["store_name"] = $r["name"];
|
||
$data["canuseAccount"] = $r["balance"]-$count[0]["COUNT"];
|
||
$msg = $this->balance_msg(9,$data);
|
||
array_push($me_msg,$msg);
|
||
}
|
||
}
|
||
}
|
||
$chunks = array_chunk($me_msg, 40);
|
||
$msgs = [];
|
||
foreach ($chunks as $r){
|
||
$text = implode("\n", $r);
|
||
array_push($msgs,$text);
|
||
}
|
||
return json($msgs);
|
||
}
|
||
private function getRoomName($room_id){
|
||
$url = "http://{$this->wechatServer}:8203/api?json&key={$this->key}";
|
||
$body = [
|
||
"method"=>"getUserInfo",
|
||
"wxid"=>$room_id,
|
||
"pid"=>0
|
||
];
|
||
$options = [
|
||
|
||
];
|
||
$urlEncodedString = http_build_query($body);
|
||
$req = Http::sendRequest($url, $urlEncodedString, 'POST', $options);
|
||
$req = json_decode(($req["msg"] ?? null),true);
|
||
return ($req['data']['nickName'] ?? null);
|
||
}
|
||
public function getTargetTimestamp() {
|
||
$currentHour = date('G'); // 获取当前时间的小时数(24小时制)
|
||
|
||
if ($currentHour < 4) {
|
||
// 如果当前时间在4点前,返回昨天凌晨4点时间戳
|
||
$targetTimestamp = strtotime('yesterday 4:00:00');
|
||
} else {
|
||
// 如果当前时间在4点后,返回今天凌晨4点时间戳
|
||
$targetTimestamp = strtotime('today 4:00:00');
|
||
}
|
||
|
||
return $targetTimestamp;
|
||
}
|
||
//处理每日余额结算
|
||
public function finalizeDailyBalance(){
|
||
//判断结算是否为月末结算
|
||
//获取事务锁
|
||
//获取事务锁失败结束并通知客服群
|
||
//异常处理开始
|
||
//获取事务锁成功
|
||
//获取余额表账户
|
||
//月末结算
|
||
//遍历余额表账户getCamInfo
|
||
//扣减前一天时间使用量并写入日志
|
||
//清零并写入日志
|
||
//通知客服群货主结算情况
|
||
//写入缓存等待9点通知客户充单处理
|
||
//遍历结束生成表发送到客服群
|
||
//正常日结算
|
||
//遍历余额表账户
|
||
//扣减前一天时间使用量并写入日志
|
||
//遍历结束生成表发送到客服群
|
||
//异常处理触发,通知客服群
|
||
//移除事务锁
|
||
}
|
||
private function balance_msg($index,$data){
|
||
foreach ($data as $key => $value) {
|
||
${$key} = strval($value);
|
||
}
|
||
$str = [
|
||
"检测到账号已解除绑定货主{$store_name},结余余额为:{$account},已自动解除该货主的所有的群绑定{$room_names}。已自动解除小程序账号:{$users}的货主绑定。",
|
||
"检测到新账号已绑定到货主{$store_name},已初始化余额为0。",
|
||
"检测到新账号已绑定到货主{$store_name},由于货主名未变更,暂未初始化余额,变更{$store_name}的货主名后在下一个小时自动初始化余额。",
|
||
"检测到货主{$store_name}余额低于预警线,当前可用余额为{$canuseAccount}单,已在客户群{$room_name}提醒充值。",
|
||
"充单提醒:当前可用面单余额值为:{$canuseAccount},低于面单预警数量:{$dsaccount},请及时联系财务充单,以免影响后续出单发货,温馨提醒,当前的面单价格为{$price},建议充值数量为整数。",
|
||
"面单余额提醒:昨日使用面单号数量:{$useAccount},昨日结余面单数量为{$lastaccount},昨日充值面单数量为{$lastin},剩余面单数量:{$account},更多明细请移步《天豹云仓客户服务》小程序查看。",
|
||
"面单余额结算以及充单提醒:月结面单余额已清0,上月结余面单数量为{$account},未使用的面单金额等待财务出账单结算,请及时联系财务充单,以免影响后续出单发货。",
|
||
"充单成功提醒:充单数量{$inaccount}已到账,当前可用余额为{$canuseAccount}单(可用余额已扣除今日订单占用),更多明细请移步《天豹云仓客户服务》小程序查看。",
|
||
"客户充单成功提醒:{$store_name}充值{$inaccount}已到账。",
|
||
"检测到货主{$store_name}余额低于预警线,当前可用余额为{$canuseAccount}单,该客户没有绑定客户群,请另行通知。",
|
||
];
|
||
return $str[$index];
|
||
}
|
||
public function OpenDGroup(){
|
||
$model = $this->RulesModel;
|
||
$list = $model->where("title","like","%D%")->select();
|
||
foreach ($list as $r){
|
||
$r->status = 1;
|
||
$r->save();
|
||
}
|
||
return json($list);
|
||
}
|
||
public function CloseDGroup(){
|
||
$model = $this->RulesModel;
|
||
$list = $model->where("title","like","%D%")->select();
|
||
foreach ($list as $r){
|
||
$r->status = 0;
|
||
$r->save();
|
||
}
|
||
return json($list);
|
||
}
|
||
public function trackYesterdayTickets(){
|
||
$Exceptionwmsorder = new \app\common\model\wms\Exceptionwmsorder;
|
||
$TimestampRange = $this->getTimestampRange();
|
||
$list = $Exceptionwmsorder->where("CREATIONDATE","BETWEEN",["00".$TimestampRange[0]."000","00".$TimestampRange[1]."000"])->where(["TYPE"=>0])->where("DEAL=''")->where("STATUS","in","1,2,3,12,14,15,16,13,5,10")->select();
|
||
$postcodes = [];
|
||
foreach ($list as $r){
|
||
if(array_key_exists($r["POSTCODE"],$postcodes)){
|
||
|
||
if(array_key_exists($r["STATUS"],$postcodes[$r["POSTCODE"]])){
|
||
array_push($postcodes[$r["POSTCODE"]][$r["STATUS"]],$r["POSTNUM"]);
|
||
}else{
|
||
$postcodes[$r["POSTCODE"]][$r["STATUS"]] = [$r["POSTNUM"]];
|
||
}
|
||
}else{
|
||
$postcodes[$r["POSTCODE"]] = [];
|
||
$postcodes[$r["POSTCODE"]][$r["STATUS"]] = [$r["POSTNUM"]];
|
||
}
|
||
}
|
||
$msgs = [];
|
||
foreach ($postcodes as $k => $r){
|
||
$RoomsModel = new \app\common\model\Rooms;
|
||
$room = $RoomsModel->where(["POSTCODE"=>$k,"type"=>3])->find();
|
||
if($room){
|
||
foreach($r as $code => $rk){
|
||
$chunks = array_chunk($rk, 80);
|
||
foreach($chunks as $rr){
|
||
$text = implode("\n", $rr);
|
||
$text.="\n售后跟踪单复查,类型为:".$this->getExceptionName($code);
|
||
$msg2 = $this->toMsg($room["room_id"],$text);
|
||
$this->redis->lpush("Message",json_encode($msg2));
|
||
array_push($msgs,$text);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return json($msgs);
|
||
}
|
||
public function getExceptionName($code){
|
||
$arr = [
|
||
1=>"核实签收",
|
||
2=>"修改信息",
|
||
3=>"超区",
|
||
5=>"快递丢失",
|
||
10=>"无信息丢失",
|
||
12=>"客户通知拦截",
|
||
13=>"虚假签收",
|
||
14=>"快递滞留拦截",
|
||
15=>"顾客拒收退回",
|
||
16=>"快递停运退回"
|
||
];
|
||
return $arr[$code];
|
||
}
|
||
public function AutoCreatePostNumber(){
|
||
$WAREHOUSEID = $this->request->get("WAREHOUSEID");
|
||
$WarehouseModel = new \app\common\model\Warehouse;
|
||
$WAREHOUSEconfig = $WarehouseModel->where(['WAREHOUSEID'=>$WAREHOUSEID])->find();
|
||
$has = true;
|
||
$count = 0;
|
||
$ids = [];
|
||
do{
|
||
$res = $this->redis->rpop("order_ids");
|
||
if(!$res){
|
||
$has = false;
|
||
}else{
|
||
array_push($ids,$res);
|
||
$count++;
|
||
if($count>=5000){
|
||
$has = false;
|
||
}
|
||
}
|
||
}while($has);
|
||
if(count($ids)>0){
|
||
$chunks = array_chunk($ids,50);
|
||
foreach ($chunks as $r){
|
||
$ids = implode(",",$r);
|
||
$data = Wsdl::webservice([$WAREHOUSEID,intval(($WAREHOUSEconfig["operatorID"] ?? null)),$ids],'createPostNum');
|
||
}
|
||
return $ids;
|
||
}else{
|
||
return "";
|
||
}
|
||
}
|
||
public function IDLIST(){
|
||
$res = $this->redis->lrange("order_ids", 0, -1);
|
||
return json($res);
|
||
}
|
||
public function guijigenzhong(){
|
||
$DeliveryorderModel = new \app\common\model\wms\Deliveryorder;
|
||
$Paracodemodel = new \app\common\model\wms\Paracode;
|
||
$data2=$Paracodemodel->where(["TYPE"=>"301"])->select();
|
||
$POSTCODEARR = [];
|
||
foreach ($data2 as $r){
|
||
$POSTCODEARR[$r["CODE"]] = $r["NAME"];
|
||
}
|
||
$current_hour = date('H');
|
||
if($current_hour!=9 && $current_hour!=18){
|
||
return "不在执行时间";
|
||
}
|
||
$res = $this->express_redis->get('errdatas');
|
||
$res = json_decode($res,true);
|
||
$spreadsheet = new Spreadsheet();
|
||
$worksheet = $spreadsheet->getActiveSheet();
|
||
$title = '需要跟踪的单号';
|
||
$worksheet->setTitle($title);
|
||
$worksheet->fromArray(
|
||
[
|
||
['运单号','快递编码','快递名称','异常类型']
|
||
], '', 'A1' );
|
||
$lists = [];
|
||
$errStringarr = [
|
||
'超24小时无新物流信息',
|
||
'无轨迹',
|
||
'状态异常',
|
||
'未中转'
|
||
];
|
||
$IDS = [];
|
||
foreach ($res as $key => $r){
|
||
foreach ($r as $rr){
|
||
array_push($IDS,$rr["POSTNUM"]);
|
||
}
|
||
}
|
||
$orders = $DeliveryorderModel->field("POSTNUM,FLAG")->where("POSTNUM","in",$IDS)->select();
|
||
$orderss = [];
|
||
foreach ($orders as $r){
|
||
$orderss[$r["POSTNUM"]] = $r["FLAG"];
|
||
}
|
||
foreach ($res as $key => $r){
|
||
$err_string = $errStringarr[$key];
|
||
foreach ($r as $rr){
|
||
if(isset($orderss[$rr["POSTNUM"]]) && $orderss[$rr["POSTNUM"]]==0){
|
||
array_push($lists,["'".$rr["POSTNUM"],$rr["POSTCODE"],$POSTCODEARR[$rr["POSTCODE"]],$err_string]);
|
||
}
|
||
}
|
||
}
|
||
if(count($lists)==0){
|
||
return false;
|
||
}
|
||
$worksheet->fromArray($lists, '', 'A2' );
|
||
// 获取当前时间的秒数和微秒数
|
||
list($usec, $sec) = explode(" ", microtime());
|
||
// 将秒数转换为毫秒并拼接微秒数
|
||
$millisecondTimestamp = (int)($sec * 1000) + (int)($usec * 1000);
|
||
$rootpath = dirname(__DIR__);
|
||
$filePath = "{$rootpath}/../../../public/trace_err/{$millisecondTimestamp}.xlsx";
|
||
$url = "https://ye4s.wms.gztbyc.com/trace_err/{$millisecondTimestamp}.xlsx";
|
||
$write = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||
$res = $write->save($filePath);
|
||
$msg = $this->backFile(["fromid"=>"44379703923@chatroom"],$url);
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
$msg2 = $this->toMsg("44379703923@chatroom",date('Y/m/d')." 昨日前日需要跟踪的物流轨迹异常件{$millisecondTimestamp}.xlsx");
|
||
$this->redis->lpush("Message",json_encode($msg2));
|
||
return json($res);
|
||
}
|
||
public function getCamInfo(){
|
||
$params = $this->request->post();
|
||
$id = isset($params["id"])?$params["id"]:null;
|
||
if(!$id){
|
||
return json([]);
|
||
}
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$model = new \app\common\model\Gzt;
|
||
$info = $model->where(["id"=>$id,"wareHouseId"=>$WAREHOUSEID])->find();
|
||
return json($info);
|
||
}
|
||
public function AutoSaveDaBaoFilePath(){
|
||
$has = true;
|
||
$count = 0;
|
||
$insetDatas = [];
|
||
$this->express_redis->select(3);
|
||
do{
|
||
$res = $this->express_redis->rpop("videoInfos");
|
||
if(!$res){
|
||
$has = false;
|
||
}else{
|
||
$data = json_decode($res,true);
|
||
$insetData = [
|
||
"name"=>($data["recordingName"] ?? null),
|
||
"path"=>($data["recordingFilePath"] ?? null),
|
||
"time"=>intval(($data["recordingTime"] ?? null)),
|
||
"user_id"=>intval(($data["userid"] ?? null)),
|
||
"create_time"=>time()
|
||
];
|
||
array_push($insetDatas,$insetData);
|
||
$count++;
|
||
if($count>=5000){
|
||
$has = false;
|
||
}
|
||
}
|
||
}while($has);
|
||
if(count($insetDatas)>0){
|
||
$dabaoModel = new \app\common\model\file\Dabao;
|
||
$dabaoModel->saveAll($insetDatas);
|
||
return json($insetDatas);
|
||
}else{
|
||
return "";
|
||
}
|
||
}
|
||
|
||
private function jiesuan($WAREHOUSEID,$GRABNUM,$workers,$gztid){
|
||
if(!$GRABNUM){
|
||
return false;
|
||
}
|
||
$Worksmodel = new \app\common\model\workers\Works;
|
||
$work = $Worksmodel->where(["grabnum"=>$GRABNUM,"WAREHOUSEID"=>$WAREHOUSEID,"userId"=>$gztid])->find();
|
||
if($work){
|
||
$work->save(["workers"=>$workers,"updatetime"=>time()]);
|
||
}
|
||
}
|
||
public function startWork(){
|
||
$params = $this->request->post();
|
||
$model = new \app\common\model\Gzt;
|
||
$Worksmodel = new \app\common\model\workers\Works;
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$DeliveryorderModel = new \app\common\model\wms\Deliveryorder;
|
||
$POSTNUM = $params["POSTNUM"];
|
||
//开始打包
|
||
$gzt = $model->where(["userid"=>$params["userid"]])->find();
|
||
if($gzt){
|
||
$lastGRANUM = $gzt["grabnum"];
|
||
$WAREHOUSEMODEL = new \app\common\model\Warehouse;
|
||
$WAREHOUSE = $WAREHOUSEMODEL->where(["WAREHOUSEID"=>$gzt->wareHouseId])->find();
|
||
$order_tmp = $OrderModel->field("GRABNUM")->where(["POSTNUM"=>$POSTNUM])->find();
|
||
$type = 1;
|
||
if(!$order_tmp){
|
||
$order_tmp = $DeliveryorderModel->field("GRABNUM")->where(["POSTNUM"=>$POSTNUM])->find();
|
||
$type = 2;
|
||
}
|
||
if($order_tmp){
|
||
$GRABNUM = $order_tmp->GRABNUM;
|
||
$model = $type==1?new \app\common\model\wms\Order:new \app\common\model\wms\Deliveryorder;
|
||
$ORDER = $model->field("count(*) as COUNT,ITEMS")->where(["GRABNUM"=>$GRABNUM,"FLAG"=>0])->group("GRABNUM")->find();
|
||
$data = Wsdl::webservice([$gzt->wareHouseId,$gzt->grabnum,$gzt->username,preg_replace('/\|/', ',', $gzt->workers)."/结束打包"],'addOperate');
|
||
$data = Wsdl::webservice([$gzt->wareHouseId,$GRABNUM,$gzt->username,preg_replace('/\|/', ',', $gzt->workers)."/开始打包"],'addOperate');
|
||
//查询老的,补全信息
|
||
$this->jiesuan($gzt->wareHouseId,$lastGRANUM,$gzt->workers,$gzt->userid);
|
||
//新的
|
||
$insetData = [
|
||
"dabaos"=>$ORDER->COUNT,
|
||
"workDate"=>$WAREHOUSE->workDate,
|
||
"userId"=>$gzt->userid,
|
||
"grabnum"=>$GRABNUM,
|
||
"POSTNUM"=>$POSTNUM,
|
||
"WAREHOUSEID"=>$gzt->wareHouseId,
|
||
"createtime"=>time(),
|
||
"GOODSCOUNT"=>isset($ORDER->GOODSCOUNT)?$ORDER->GOODSCOUNT:0,
|
||
"items"=>$ORDER->ITEMS,
|
||
"isSandan"=>0,
|
||
"update_time"=>0,
|
||
"types"=>0,
|
||
"count"=>0,
|
||
"tuijian"=>0,
|
||
"tiedan"=>0,
|
||
"gztid"=>$gzt->id
|
||
];
|
||
$code = $gzt->save(["grabnum"=>$GRABNUM]);
|
||
$Worksmodel->save($insetData);
|
||
$url = "http://file2.gztbyc.com/startRecording";
|
||
$body = [
|
||
"code"=>$GRABNUM,
|
||
"id"=>$gzt->id
|
||
];
|
||
$options = [];
|
||
$data = [];
|
||
$urlEncodedString = http_build_query($body);
|
||
$req = Http::sendRequest($url, $urlEncodedString, 'POST', $options);
|
||
array_push($data,$req);
|
||
$url = "http://wms.gztbyc.com/tgdp/db";
|
||
$body = [
|
||
"WAREHOUSEID"=>$gzt->wareHouseId
|
||
];
|
||
$urlEncodedString = http_build_query($body);
|
||
$req = Http::sendRequest($url, $urlEncodedString, 'POST', $options);
|
||
return json(["msg"=>"开始打包","data"=>[$GRABNUM,$code]]);
|
||
}else{
|
||
$newWmsData = $this->redis->get("newWmsData:{$POSTNUM}");
|
||
if($newWmsData){
|
||
|
||
$user_ids_arr = [];
|
||
if($gzt->workers_ids){
|
||
$users = explode("|",$gzt->workers_ids);
|
||
foreach($users as $k => $v){
|
||
[$username, $userId] = explode("_",$v);
|
||
array_push($user_ids_arr,$userId);
|
||
}
|
||
}
|
||
$userModel = new \app\common\model\User;
|
||
$userList = $userModel->where("id","in",$user_ids_arr)->select();
|
||
$userListArr = [];
|
||
foreach($userList as $r){
|
||
array_push($userListArr,["wms_account_id"=>$r->wms_account_id,"real_name"=>$r->real_name]);
|
||
}
|
||
$newWmsData = json_decode($newWmsData,true);
|
||
|
||
$newWmsData['workbenchIdRaw'] = $gzt->other_id;
|
||
$newWmsData['usersParam'] = $userListArr;
|
||
$newWmsData['packTime'] = time();
|
||
$wmsResult = $this->_packNewWms($newWmsData);
|
||
\think\Log::error('_packNewWms newWms result: ' . json_encode($wmsResult, JSON_UNESCAPED_UNICODE));
|
||
$code = $gzt->save(["grabnum"=>($newWmsData['waveNo'] ?? null)]);
|
||
return json(["msg"=>"开始打包"]);
|
||
}
|
||
return json(["msg"=>"无记录"]);
|
||
}
|
||
}else{
|
||
return json(["msg"=>"工作台错误,联系主管"]);
|
||
}
|
||
}
|
||
public function startWork2(){
|
||
$params = $this->request->post();
|
||
$model = new \app\common\model\Gzt;
|
||
$Worksmodel = new \app\common\model\workers\Works;
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$DeliveryorderModel = new \app\common\model\wms\Deliveryorder;
|
||
$POSTNUM = $params["POSTNUM"];
|
||
//开始打包
|
||
$gzt = $model->where(["userid"=>$params["userid"]])->find();
|
||
if($gzt){
|
||
$lastGRANUM = $gzt["grabnum"];
|
||
$WAREHOUSEMODEL = new \app\common\model\Warehouse;
|
||
$WAREHOUSE = $WAREHOUSEMODEL->where(["WAREHOUSEID"=>$gzt->wareHouseId])->find();
|
||
$order_tmp = $OrderModel->field("GRABNUM")->where(["POSTNUM"=>$POSTNUM])->find();
|
||
$type = 1;
|
||
if(!$order_tmp){
|
||
$order_tmp = $DeliveryorderModel->field("GRABNUM")->where(["POSTNUM"=>$POSTNUM])->find();
|
||
$type = 2;
|
||
}
|
||
if($order_tmp){
|
||
$GRABNUM = $order_tmp->GRABNUM;
|
||
$model = $type==1?new \app\common\model\wms\Order:new \app\common\model\wms\Deliveryorder;
|
||
$ORDER = $model->field("count(*) as COUNT,ITEMS")->where(["GRABNUM"=>$GRABNUM,"FLAG"=>0])->group("GRABNUM")->find();
|
||
$data = Wsdl::webservice([$gzt->wareHouseId,$gzt->grabnum,$gzt->username,preg_replace('/\|/', ',', $gzt->workers)."/结束打包"],'addOperate');
|
||
$data = Wsdl::webservice([$gzt->wareHouseId,$GRABNUM,$gzt->username,preg_replace('/\|/', ',', $gzt->workers)."/开始打包"],'addOperate');
|
||
//查询老的,补全信息
|
||
$this->jiesuan($gzt->wareHouseId,$lastGRANUM,$gzt->workers,$gzt->userid);
|
||
//新的
|
||
$insetData = [
|
||
"dabaos"=>$ORDER->COUNT,
|
||
"workDate"=>$WAREHOUSE->workDate,
|
||
"userId"=>$gzt->userid,
|
||
"grabnum"=>$GRABNUM,
|
||
"POSTNUM"=>$POSTNUM,
|
||
"WAREHOUSEID"=>$gzt->wareHouseId,
|
||
"createtime"=>time(),
|
||
"GOODSCOUNT"=>isset($ORDER->GOODSCOUNT)?$ORDER->GOODSCOUNT:0,
|
||
"items"=>$ORDER->ITEMS,
|
||
"isSandan"=>0,
|
||
"update_time"=>0,
|
||
"types"=>0,
|
||
"count"=>0,
|
||
"tuijian"=>0,
|
||
"tiedan"=>0,
|
||
"gztid"=>$gzt->id
|
||
];
|
||
$code = $gzt->save(["grabnum"=>$GRABNUM]);
|
||
$Worksmodel->save($insetData);
|
||
$url = "http://file2.gztbyc.com/startRecording";
|
||
$body = [
|
||
"code"=>$GRABNUM,
|
||
"id"=>$gzt->id
|
||
];
|
||
$options = [];
|
||
$data = [];
|
||
$urlEncodedString = http_build_query($body);
|
||
$req = Http::sendRequest($url, $urlEncodedString, 'POST', $options);
|
||
array_push($data,$req);
|
||
$url = "http://wms.gztbyc.com/tgdp/db";
|
||
$body = [
|
||
"WAREHOUSEID"=>$gzt->wareHouseId
|
||
];
|
||
$urlEncodedString = http_build_query($body);
|
||
$req = Http::sendRequest($url, $urlEncodedString, 'POST', $options);
|
||
return json(["msg"=>"开始打包","data"=>[$GRABNUM,$code]]);
|
||
}else{
|
||
return json(["msg"=>"无记录"]);
|
||
}
|
||
}else{
|
||
return json(["msg"=>"工作台错误,联系主管"]);
|
||
}
|
||
}
|
||
public function userQuit(){
|
||
$params = $this->request->post();
|
||
$model = new \app\common\model\wms\Gzt;
|
||
//退出成员
|
||
$gzt = $model->where(["userid"=>$params["userid"]])->find();
|
||
if($gzt){
|
||
$userName2 = "";
|
||
$str_users1 = [];
|
||
$users = array_filter(explode("|",$gzt->workers_ids),'trim');
|
||
foreach ($users as $k=> $user){
|
||
$user = explode("_",$user);
|
||
if($user[1]==$params["user_id"]){
|
||
$userName2 = $user[0];
|
||
unset($users[$k]);
|
||
}
|
||
}
|
||
foreach($users as $r){
|
||
$username = explode("_",$r);
|
||
array_push($str_users1,$username[0]);
|
||
}
|
||
$str_users = implode("|",$users);
|
||
$gzt->workers_ids = $str_users;
|
||
$gzt->workers = implode("|",$str_users1);
|
||
$gzt->save();
|
||
$msg = $userName2."退出成功";
|
||
return json(["msg"=>$msg]);
|
||
}
|
||
}
|
||
public function pick_error(){
|
||
$params = $this->request->post();
|
||
//拣货报错
|
||
|
||
}
|
||
public function userLogin(){
|
||
$params = $this->request->post();
|
||
$usermodel = new \app\common\model\User;
|
||
$user = $usermodel->where(["tmp_code"=>$params["code"]])->find();
|
||
$userName = ($user["real_name"] ?? null)."_".($user["id"] ?? null);
|
||
$userName2 = ($user["real_name"] ?? null);
|
||
$model = new \app\common\model\wms\Gzt;
|
||
$gzt = $model->where(["userid"=>$params["userid"]])->find();
|
||
if($gzt){
|
||
$users = array_filter(explode("|",$gzt->workers_ids),'trim');
|
||
$has = false;
|
||
foreach ($users as $k => $user_item){
|
||
if($user_item==$userName){
|
||
unset($users[$k]);
|
||
$has = true;
|
||
}
|
||
}
|
||
if(!$has){
|
||
array_push($users,$userName);
|
||
}
|
||
$str_users1 = [];
|
||
foreach($users as $r){
|
||
$username = explode("_",$r);
|
||
array_push($str_users1,$username[0]);
|
||
}
|
||
$str_users = implode("|",$users);
|
||
$gzt->workers_ids = $str_users;
|
||
$gzt->workers = implode("|",$str_users1);
|
||
$gzt->save();
|
||
$msg = $has?$userName2."退出成功":$userName2."登录成功";
|
||
return json(["msg"=>$msg]);
|
||
}
|
||
}
|
||
|
||
public function sendyesterdayOrderCount($WAREHOUSEID = ""){
|
||
$RoomsModel = new \app\common\model\Rooms;
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$OrderModel2 = new \app\common\model\wms\Deliveryorder;
|
||
|
||
[$startTime,$endTime] = $this->getTimestampRange();
|
||
$list = $OrderModel->field("count(*) as Count,STOREID")->where("CREATIONDATE","BETWEEN",["00".$startTime."000","00".$endTime."999"])->where(["PLSENDFLAG"=>1])->group("STOREID")->select();
|
||
$list2 = $OrderModel2->field("count(*) as Count,STOREID")->where("CREATIONDATE","BETWEEN",["00".$startTime."000","00".$endTime."999"])->group("STOREID")->select();
|
||
$WarehouseModel = new \app\common\model\Warehouse;
|
||
$WAREHOUSE = $WarehouseModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
$storeids = explode(",",($WAREHOUSE["yesterdayOrderCount"] ?? null));
|
||
$datas = [];
|
||
foreach ($storeids as $store_id){
|
||
$count = 0;
|
||
foreach ($list as $r){
|
||
if($r["STOREID"]==$store_id){
|
||
$count+=$r["Count"];
|
||
}
|
||
}
|
||
foreach ($list2 as $r){
|
||
if($r["STOREID"]==$store_id){
|
||
$count+=$r["Count"];
|
||
}
|
||
}
|
||
$date = date('Y-m-d', $startTime);
|
||
$STR = "昨日({$date})发货单量:{$count}";
|
||
$room = $RoomsModel->where(["STOREID"=>$store_id,"isMain"=>1])->find();
|
||
if(!$room){
|
||
$room = $RoomsModel->where(["STOREID"=>$store_id])->find();
|
||
}
|
||
if($room){
|
||
$msg = $this->toMsg($room["room_id"],$STR);
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
}
|
||
array_push($datas,$STR);
|
||
}
|
||
return json([$datas,"00".$startTime."000","00".$endTime."999"]);
|
||
}
|
||
public function handleLowReturnProductQuantity($WAREHOUSEID = ""){
|
||
$BackrecordModel = new \app\common\model\wms\Backrecord;
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$OrderModel1 = new \app\common\model\wms\Order1;
|
||
$DeliveryorderModel = new \app\common\model\wms\Deliveryorder;
|
||
$StoreModel = new \app\common\model\wms\Store;
|
||
[$startTime,$endTime] = $this->getToday18();
|
||
$list = $BackrecordModel->field('POSTNUM,STOCKID,COUNT')->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("CREATIONDATE BETWEEN '00{$startTime}' and '00{$endTime}'")->where("SOURCEORDERCODE is not null and SOURCEORDERCODE <>''")->select();
|
||
$SOURCEORDERCODES = [];
|
||
$STOREIDS = [];
|
||
$list2 = [];
|
||
foreach ($list as $r){
|
||
if(array_key_exists($r["POSTNUM"],$list2)){
|
||
array_push($list2[$r["POSTNUM"]],[$r["STOCKID"],$r["COUNT"]]);
|
||
}else{
|
||
$list2[$r["POSTNUM"]] = [[$r["STOCKID"],$r["COUNT"]]];
|
||
}
|
||
}
|
||
$list3 = [];
|
||
foreach ($list2 as $k => $r){
|
||
$stocks = [];
|
||
foreach ($r as $rr){
|
||
if(array_key_exists($rr[0],$stocks)){
|
||
$stocks[$rr[0]]+=$rr[1];
|
||
}else{
|
||
$stocks[$rr[0]]=$rr[1];
|
||
}
|
||
}
|
||
$tmp_stocks = [];
|
||
foreach ($stocks as $kk => $rr){
|
||
array_push($tmp_stocks,[$kk,$rr]);
|
||
}
|
||
usort($tmp_stocks, function($a, $b) {
|
||
return $a[0] - $b[0];
|
||
});
|
||
$stocks = "";
|
||
foreach ($tmp_stocks as $rr){
|
||
$stocks.=$rr[0].$rr[1];
|
||
}
|
||
$list3[$k] = $stocks;
|
||
array_push($SOURCEORDERCODES,$k);
|
||
}
|
||
$datas = $OrderModel->field('POSTNUM,NAME,TITLE,STORENAME,ITEMS')->alias('order')->field("POSTNUM,ITEMS,paracode.NAME as NAME,TITLE,STORENAME")->join("yj_store store","store.STOREID=order.STOREID")->join("yj_paracode paracode","paracode.CODE=order.POSTCODE")->where("POSTNUM","in",$SOURCEORDERCODES)->select();
|
||
$datas1 = $OrderModel1->field('POSTNUM,NAME,TITLE,STORENAME,ITEMS')->alias('order')->field("POSTNUM,ITEMS,paracode.NAME as NAME,TITLE,STORENAME")->join("yj_store store","store.STOREID=order.STOREID")->join("yj_paracode paracode","paracode.CODE=order.POSTCODE")->where("POSTNUM","in",$SOURCEORDERCODES)->select();
|
||
$datas2 = $DeliveryorderModel->field('POSTNUM,NAME,TITLE,STORENAME,ITEMS')->alias('order')->field("POSTNUM,ITEMS,paracode.NAME as NAME,TITLE,STORENAME")->join("yj_store store","store.STOREID=order.STOREID")->join("yj_paracode paracode","paracode.CODE=order.POSTCODE")->where("POSTNUM","in",$SOURCEORDERCODES)->select();
|
||
$result = array_merge($datas, $datas1,$datas2);
|
||
$result = array_filter($result);
|
||
$list4 = [];
|
||
foreach ($result as $r){
|
||
$items = explode("|",$r["ITEMS"]);
|
||
$items = array_filter($items);
|
||
$tmp_stocks = [];
|
||
foreach ($items as $stock){
|
||
$stock = explode(",",$stock);
|
||
array_push($tmp_stocks,[$stock[0],$stock[1]]);
|
||
}
|
||
usort($tmp_stocks, function($a, $b) {
|
||
return $a[0] - $b[0];
|
||
});
|
||
$stocks = "";
|
||
foreach ($tmp_stocks as $rr){
|
||
$stocks.=$rr[0].$rr[1];
|
||
}
|
||
$list4[$r["POSTNUM"]] = [$r["POSTNUM"],$stocks,$r["NAME"],$r["TITLE"],$r["STORENAME"]];
|
||
}
|
||
$list5 = [];
|
||
foreach ($list3 as $key => $r){
|
||
if($list4[$key][1]!=$r){
|
||
array_push($list5,[$list4[$key][0],$r,$list4[$key][2],$list4[$key][3],$list4[$key][4]]);
|
||
}
|
||
}
|
||
$spreadsheet = new Spreadsheet();
|
||
$worksheet = $spreadsheet->getActiveSheet();
|
||
$title = date('Y-m-d H:i:s', $startTime/1000)." - ".date('Y-m-d H:i:s', $endTime/1000).'拆包原单与发出不符数据';
|
||
$worksheet->setTitle("拆包原单与发出不符数据");
|
||
$worksheet->fromArray(
|
||
[
|
||
['运单号','快递名称','货主','店铺名称']
|
||
], '', 'A1' );
|
||
$lists = [];
|
||
foreach ($list5 as $r){
|
||
array_push($lists,[$r[0],$r[2],$r[3],$r[4]]);
|
||
}
|
||
if(count($lists)==0){
|
||
return json([]);
|
||
}
|
||
$worksheet->fromArray($lists, '', 'A2' );
|
||
// 获取当前时间的秒数和微秒数
|
||
list($usec, $sec) = explode(" ", microtime());
|
||
// 将秒数转换为毫秒并拼接微秒数
|
||
$millisecondTimestamp = (int)($sec * 1000) + (int)($usec * 1000);
|
||
$rootpath = dirname(__DIR__);
|
||
$filePath = "{$rootpath}/../../../public/hasMoreExport/{$millisecondTimestamp}.xlsx";
|
||
$url = "https://ye4s.wms.gztbyc.com/hasMoreExport/{$millisecondTimestamp}.xlsx";
|
||
$write = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||
$res = $write->save($filePath);
|
||
$msg = $this->backFile(["fromid"=>"44379703923@chatroom"],$url);
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
$msg2 = $this->toMsg("44379703923@chatroom","{$title},文件名为{$millisecondTimestamp}.xlsx。");
|
||
$this->redis->lpush("Message",json_encode($msg2));
|
||
return json([$list2,$list3,$list4]);
|
||
}
|
||
public function copyorder(){
|
||
$rootpath = dirname(__DIR__);
|
||
$file = request()->file('file'); // 从请求中获取上传的文件
|
||
$info = $file->validate(['size'=>15678000,'ext'=>'xls,xlsx'])->move( '../uploads');
|
||
$list = [];
|
||
if($info){
|
||
$filename = $info->getSaveName();
|
||
$filePath = '../uploads/' . $filename;
|
||
|
||
// 使用 PhpSpreadsheet 解析 Excel 文件
|
||
$spreadsheet = IOFactory::load($filePath);
|
||
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
||
for($i=2;$i<count($sheetData);$i++){
|
||
$xml = $sheetData[$i]["L"];
|
||
$data = null;
|
||
$name = "";
|
||
$tel = "";
|
||
$province = "";
|
||
$city = "";
|
||
$area = "";
|
||
if($xml){
|
||
$data = simplexml_load_string($xml);
|
||
$name = (string)$data->deliveryOrder->buyerNick;
|
||
$tel = (string)$data->deliveryOrder->receiverInfo->mobile;
|
||
$province = (string)$data->deliveryOrder->receiverInfo->province;
|
||
$city = (string)$data->deliveryOrder->receiverInfo->city;
|
||
$area = (string)$data->deliveryOrder->receiverInfo->area;
|
||
}
|
||
array_push($list,[$sheetData[$i]["A"],$name,$tel,$province,$city,$area]);
|
||
}
|
||
// 删除上传的临时文件
|
||
unlink($filePath);
|
||
$spreadsheet = new Spreadsheet();
|
||
$worksheet = $spreadsheet->getActiveSheet();
|
||
$title = '导出数据';
|
||
$worksheet->setTitle($title);
|
||
$worksheet->fromArray(
|
||
[
|
||
['ID','姓名','电话','省份','城市','地址']
|
||
], '', 'A1' );
|
||
$worksheet->fromArray($list, '', 'A2' );
|
||
// 获取当前时间的秒数和微秒数
|
||
list($usec, $sec) = explode(" ", microtime());
|
||
// 将秒数转换为毫秒并拼接微秒数
|
||
$millisecondTimestamp = (int)($sec * 1000) + (int)($usec * 1000);
|
||
|
||
$filePath = "{$rootpath}/../../../public/export/{$millisecondTimestamp}.xlsx";
|
||
$url = "https://ye4s.wms.gztbyc.com/export/{$millisecondTimestamp}.xlsx";
|
||
$write = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||
$res = $write->save($filePath);
|
||
return json(['status' => 'true', 'message' => $file->getError(),'url'=>$url]);
|
||
}
|
||
}
|
||
public function test(){
|
||
$skus_tmp = [544816,544836,544852,544857,544884,544894,544940,544957,544958,544969,544973,544978,544992,544996,545006,545007,545010,545037,545043,545067,545085,545087,545094,545112,545165,545166,545185,545190,545198,545215,545221,545222,545230,545250,545252,545261,545264,545268,545273,545277,545285,545297,545303,545304,545314,545315,545317,545321,545341,545348,545351,545357,545365,545366,545375,545377,545385,545397,545407,545408,545414,545418,545423,545426,545428,545429,545439,545440,545453,545460,545464,545471,545473,545495,545499,545555,545845,546101,546102,546209,547207,548207,548219,548474,548475,548476,548477,549014,552707,553213,556082,556100,557100,557301,558744,559441];
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$orders = $OrderModel->field("SOURCEID,ITEMS")->where(["STOREID"=>17501,"ASSIGNFLAG"=>0,"PICKINGFLAG"=>0])->select();
|
||
$orders_list = [];
|
||
$skus_list = [];
|
||
$orders_list2 = [];
|
||
foreach ($orders as $r){
|
||
$items = explode("|",$r["ITEMS"]);
|
||
$items = array_filter($items);
|
||
$skus = [];
|
||
foreach ($items as $rr){
|
||
$tmp = explode(",",$rr);
|
||
array_push($skus,[$tmp[0],$tmp[1]]);
|
||
array_push($skus_list,$tmp[0]);
|
||
if(in_array($tmp[0],$skus_tmp)){
|
||
array_push($orders_list2,$tmp[0]);
|
||
}
|
||
}
|
||
array_push($orders_list,[$r["SOURCEID"],$skus]);
|
||
}
|
||
$skus_list = array_values(array_unique($skus_list));
|
||
return implode(",",$orders_list2);
|
||
}
|
||
public function getMoveLocations($CUSTOMNUM=""){
|
||
$SpaceModel = new \app\common\model\wms\Space;
|
||
$MovestorageModel = new \app\common\model\wms\Movestorage;
|
||
$oldspace = $SpaceModel->where(["CUSTOMNUM"=>$CUSTOMNUM])->find();
|
||
if(!$oldspace){
|
||
return "";
|
||
}
|
||
$newspace = $MovestorageModel->where(["OUTBARCODE"=>$oldspace["BARCODE"]])->order("CREATIONDATE","DESC")->limit(1)->select();
|
||
if($newspace){
|
||
$data = $SpaceModel->where(["BARCODE"=>$newspace[0]["INBARCODE"]])->find();
|
||
if($data){
|
||
return $data["CUSTOMNUM"];
|
||
}
|
||
}else{
|
||
return "";
|
||
}
|
||
|
||
}
|
||
public function updateStockremove(){
|
||
$params = $this->request->post();
|
||
$storages = $params["storages"];
|
||
if(!$storages){
|
||
return "";
|
||
}else{
|
||
$storages = explode(",",$storages);
|
||
$storages = array_filter($storages);
|
||
$stockids = [];
|
||
foreach ($storages as $stock){
|
||
$stock_infos = explode("|",$stock);
|
||
$this->redis->lpush('moveStocks',$stock_infos[0]);
|
||
array_push($stockids,$stock_infos[0]);
|
||
}
|
||
return json($stockids);
|
||
}
|
||
}
|
||
public function LowSalesNotice(){
|
||
$RoomsModel = new \app\common\model\Rooms;
|
||
$WarehouseModel = new \app\common\model\Warehouse;
|
||
$warehouses = $WarehouseModel->select();
|
||
$datas = [];
|
||
foreach ($warehouses as $warehouse){
|
||
if(!$warehouse["LowSalesStoreNotices"]){
|
||
continue;
|
||
}
|
||
$stores = explode(",",$warehouse["LowSalesStoreNotices"]);
|
||
$tmp_stores = [];
|
||
$tmp_stores2 = [];
|
||
foreach($stores as $store){
|
||
$tmp_store = explode("|",$store);
|
||
array_push($tmp_stores,$tmp_store[0]);
|
||
array_push($tmp_stores2,$tmp_store);
|
||
}
|
||
$data = $this->getLowSales($tmp_stores);
|
||
$store_stock_list = [];
|
||
foreach ($tmp_stores2 as $store){
|
||
$stock_tmp = [];
|
||
foreach ($data as $stock){
|
||
if(intval($store[0])==intval($stock["STOREID"]) && intval($store[1])>$stock["CKCOUNT"] && $stock["STORAGECOUNT"]>0){
|
||
array_push($stock_tmp,$stock);
|
||
}
|
||
}
|
||
if(count($stock_tmp)==0){
|
||
continue;
|
||
}
|
||
[$name,$storeTableUrl] = $this->createLowSalesTable($stock_tmp);
|
||
/*$room = $RoomsModel->where(["STOREID"=>$store[0],"isMain"=>1])->find();
|
||
if(!$room){
|
||
$room = $RoomsModel->where(["STOREID"=>$store[0]])->find();
|
||
}
|
||
if($room){
|
||
$msg = $this->backFile(["fromid"=>$room["room_id"]],$storeTableUrl);
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
$msg = $this->toMsg($room["room_id"],"上月低动销数据已经自动整理到文档{$name},请注意查收。");
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
}*/
|
||
$store_stock_list[$store[0]] = $storeTableUrl;
|
||
}
|
||
$datas[$warehouse["WAREHOUSEID"]] = $store_stock_list;
|
||
}
|
||
return json($datas);
|
||
}
|
||
private function getLowSales($stores){
|
||
if(count($stores)==0){
|
||
return [];
|
||
}
|
||
$StockModel = new \app\common\model\wms\Stock;
|
||
$Wmsitem1Model = new \app\common\model\wms\Putoutstorage;
|
||
$first_day_timestamp = strtotime('first day of last month midnight');
|
||
$last_day_timestamp = strtotime('last day of last month 23:59:59');
|
||
$STOCKS_DATA = $StockModel
|
||
->field('warestore.STOREID as STOREID,stock.STOCKID as STOCKID,IFNULL(CAST(putoutstorage.COUNT AS SIGNED), 0) as CKCOUNT,IFNULL(CAST(storage.STORAGECOUNT AS SIGNED), 0) as STORAGECOUNT,FIDX/1000 as FTIME,MIDX/1000 as MTIME,goods.NAME as NAME,stock.BARCODE as BARCODE,stock.SKU as SKU,stock.STYLE as STYLE,stock.COLOR as COLOR')
|
||
->alias('stock')
|
||
->join('yj_warestore warestore','warestore.ID=stock.WARESTOREID')
|
||
->join("(SELECT STOCKID, SUM(COUNT) as COUNT FROM `yj_putoutstorage` where `CREATIONDATE` BETWEEN '00{$first_day_timestamp}000' AND '00{$last_day_timestamp}999' GROUP BY STOCKID ) as putoutstorage",'putoutstorage.STOCKID=stock.STOCKID','left')
|
||
->join('(SELECT yj_storage.STOCKID as STOCKID, sum(copycount) as STORAGECOUNT,MIN(APPLYSTORAGENUM) as FIDX,max(APPLYSTORAGENUM) as MIDX FROM `yj_storage` GROUP BY yj_storage.STOCKID) as storage','storage.STOCKID=stock.STOCKID','left')
|
||
->join('yj_goods goods','goods.GOODSID=stock.GOODSID')
|
||
->where("warestore.STOREID","in",$stores)
|
||
->group("stock.STOCKID")
|
||
->order('CKCOUNT','desc')
|
||
->select();
|
||
return $STOCKS_DATA;
|
||
}
|
||
private function createLowSalesTable($data){
|
||
$rootpath = dirname(__DIR__);
|
||
$last_day_timestamp = time();
|
||
$spreadsheet = new Spreadsheet();
|
||
$worksheet = $spreadsheet->getActiveSheet();
|
||
$title = '低动销数据';
|
||
$worksheet->setTitle($title);
|
||
$worksheet->fromArray(
|
||
[
|
||
['WMS的SKUID','上月出库数量','WMS库存数','最早入库时间','库龄最大天数','最晚入库时间','库龄最小天数','商品名称','颜色','规格','条码','ERP的SKU编号']
|
||
], '', 'A1' );
|
||
$list = [];
|
||
foreach ($data as $r){
|
||
$dayDiff = round(($last_day_timestamp - $r["FTIME"]) / (60 * 60 * 24));
|
||
$dayDiff1 = round(($last_day_timestamp - $r["MTIME"]) / (60 * 60 * 24));
|
||
array_push($list,[$r["STOCKID"],$r["CKCOUNT"],$r["STORAGECOUNT"],date('Y-m-d H:i:s', $r["FTIME"]),$dayDiff,date('Y-m-d H:i:s', $r["MTIME"]),$dayDiff1,$r["NAME"],$r["COLOR"],$r["STYLE"],$r["BARCODE"],$r["SKU"]]);
|
||
}
|
||
$worksheet->fromArray($list, '', 'A2' );
|
||
// 获取当前时间的秒数和微秒数
|
||
list($usec, $sec) = explode(" ", microtime());
|
||
// 将秒数转换为毫秒并拼接微秒数
|
||
$millisecondTimestamp = (int)($sec * 1000) + (int)($usec * 1000);
|
||
|
||
$filePath = "{$rootpath}/../../../public/LowSales/{$millisecondTimestamp}.xlsx";
|
||
$url = "https://ye4s.wms.gztbyc.com/LowSales/{$millisecondTimestamp}.xlsx";
|
||
$write = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||
$res = $write->save($filePath);
|
||
return [$millisecondTimestamp.".xlsx",$url];
|
||
}
|
||
public function stockqh(){
|
||
$WmsitemModel = new \app\common\model\wms\Wmsitem;
|
||
$params = $this->request->post();
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$storeId = $params["storeId"];
|
||
$ltime = time()-24*60*60*3;
|
||
|
||
$data = $WmsitemModel
|
||
->alias('wmsitem')
|
||
->field('wmsitem.STOCKID, SUM(wmsitem.COUNT) AS wfpcw, IFNULL(CAST(STORAGE1.copycount AS SIGNED),0) AS fjsl, CASE WHEN SUM(wmsitem.COUNT) - IFNULL(CAST(STORAGE1.copycount AS SIGNED), 0) < 0 THEN 0 ELSE SUM(wmsitem.COUNT) - IFNULL(CAST(STORAGE1.copycount AS SIGNED), 0) END AS qhs, IFNULL(CAST(STORAGE2.copycount AS SIGNED),0) AS ccl, LEAST(IFNULL(CAST(putoutstorage.COUNT AS SIGNED),0)+(SUM(wmsitem.COUNT)- IFNULL(CAST(STORAGE1.copycount AS SIGNED),0)),IFNULL(CAST(STORAGE2.copycount AS SIGNED),0)) as tjbhl,stock.BARCODE as BARCODE,store.TITLE as storeName')
|
||
->join('(
|
||
SELECT STOCKID, sum(copycount) AS copycount
|
||
FROM yj_storage
|
||
LEFT JOIN yj_space space ON space.ID = yj_storage.SPACEID
|
||
WHERE space.FIRSTFLAG = 1
|
||
GROUP BY STOCKID
|
||
) AS STORAGE1', 'STORAGE1.STOCKID = wmsitem.STOCKID','left')
|
||
->join('(
|
||
SELECT STOCKID, sum(copycount) AS copycount
|
||
FROM yj_storage
|
||
LEFT JOIN yj_space space ON space.ID = yj_storage.SPACEID
|
||
WHERE space.FIRSTFLAG = 2
|
||
GROUP BY STOCKID
|
||
) AS STORAGE2', 'STORAGE2.STOCKID = wmsitem.STOCKID','left')
|
||
->join('(
|
||
SELECT STOCKID, sum(yj_putoutstorage.COUNT) AS COUNT
|
||
FROM yj_putoutstorage
|
||
WHERE CREATIONDATE > "00'.$ltime.'000"
|
||
GROUP BY STOCKID
|
||
) AS putoutstorage', 'putoutstorage.STOCKID = wmsitem.STOCKID','left')
|
||
->join('yj_stock stock','stock.STOCKID=wmsitem.STOCKID','left')
|
||
->join('yj_store store','store.STOREID=wmsitem.STOREID','left')
|
||
|
||
->join('yj_wmsorder wmsorder', 'wmsorder.ID = wmsitem.WMSORDERID')
|
||
->where('wmsorder.WAREHOUSEID', 5400)
|
||
->where('wmsorder.ASSIGNFLAG', 0)
|
||
->where('wmsorder.DISPLAYFLAG', 0);
|
||
if($storeId){
|
||
$data = $data->where('wmsitem.STOREID',$storeId);
|
||
}
|
||
$data = $data->group('STOCKID')
|
||
->order('qhs DESC, tjbhl DESC')
|
||
->select();
|
||
$list = [];
|
||
foreach ($data as $row){
|
||
if($row->tjbhl>0 && intval($row->qhs)>0){
|
||
array_push($list,$row);
|
||
}
|
||
}
|
||
return json($list);
|
||
}
|
||
public function fzCkd($code,$page=null){
|
||
$WmsitemModel = new \app\common\model\wms\Wmsitem;
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
$storeSettingModel = new \app\common\model\store\Setting;
|
||
$WarehouseModel = new \app\common\model\Warehouse;
|
||
$data = $WmsitemModel->field('wmsitem.STOCKID as STOCKID,stock.BARCODE as BARCODE,wmsitem.COUNT as COUNT,goods.NAME as NAME,stock.STYLE as STYLE,wmsorder.name as kfname')->alias("wmsitem")
|
||
->join("yj_wmsorder wmsorder","wmsorder.ID=wmsitem.WMSORDERID")
|
||
->join("yj_stock stock","stock.STOCKID=wmsitem.STOCKID")
|
||
->join("yj_goods goods","goods.GOODSID=stock.GOODSID")
|
||
->where(["wmsorder.SOURCEID"=>$code])->select();
|
||
$kfname = '';
|
||
if(!$data){
|
||
return "出库单不存在";
|
||
}
|
||
$order = $orderModel->field("ID,STOREID,ASSIGNFLAG,GRABNUM,PICKINGFLAG,FLAG,PLSENDFLAG,WAREHOUSEID,LEAVEMESSAGE,NAME,SYNFLAG,SOURCEID,CREATIONDATE,PROVINCE,SOURCEORDERCODE,POSTNUM,STORENAME as STORE_NAME,POSTCODE,POSTNAME,ADDRESS")->where(["SOURCEID"=>$code])->find();
|
||
if(!$order){
|
||
return "出库单不存在";
|
||
}
|
||
$WAREHOUSE = $WarehouseModel->where(["WAREHOUSEID"=>$order->WAREHOUSEID])->find();
|
||
if($order->ASSIGNFLAG==0){
|
||
//未分配储位
|
||
$res = Wsdl::webservice([$order->WAREHOUSEID,($WAREHOUSE["operatorID"] ?? null),$order->ID,1],"assignWmsOrder");
|
||
$res = Wsdl::webservice([$order->WAREHOUSEID,($WAREHOUSE["operatorID"] ?? null),$order->ID,2],"assignWmsOrder");
|
||
$res = Wsdl::webservice([$order->WAREHOUSEID,($WAREHOUSE["operatorID"] ?? null),$order->ID,3],"assignWmsOrder");
|
||
}
|
||
$order = $orderModel->field("ID,STOREID,ASSIGNFLAG,GRABNUM,PICKINGFLAG,FLAG,PLSENDFLAG,WAREHOUSEID,LEAVEMESSAGE,NAME,SYNFLAG,SOURCEID,CREATIONDATE,PROVINCE,SOURCEORDERCODE,POSTNUM,STORENAME as STORE_NAME,POSTCODE,POSTNAME,ADDRESS")->where(["SOURCEID"=>$code])->find();
|
||
if($order->ASSIGNFLAG==0){
|
||
return "分配储位失败";
|
||
}
|
||
$store_setting = $storeSettingModel->field('ckdTitle')->where(["STOREID"=>$order->STOREID])->find();
|
||
foreach ($data as $k =>$r){
|
||
$data[$k]["BARCODE"] = str_replace(';', "<br>", $r["BARCODE"]);
|
||
if($r["kfname"]){
|
||
$kfname = $r["kfname"];
|
||
}
|
||
}
|
||
$formattedDate = date("Y/n/j", time());
|
||
$newcode = mb_substr($code, -7);
|
||
$this->view->assign('title', $store_setting && $store_setting->ckdTitle?$store_setting->ckdTitle:'');
|
||
$this->view->assign('code', $order->ID);
|
||
$this->view->assign('newcode', $newcode);
|
||
$this->view->assign('formattedDate', $formattedDate);
|
||
$this->view->assign('kfname', $order->NAME);
|
||
$this->view->assign('list', $data);
|
||
$this->view->assign('remask', $order->LEAVEMESSAGE);
|
||
if($page=="A4"){
|
||
return $this->view->fetch("ckd2");
|
||
}else{
|
||
return $this->view->fetch("ckd");
|
||
}
|
||
}
|
||
public function ckd_grab($grabnum,$page=null){
|
||
$WmsitemModel = new \app\common\model\wms\Wmsitem;
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
$storeSettingModel = new \app\common\model\store\Setting;
|
||
$WarehouseModel = new \app\common\model\Warehouse;
|
||
$CkModel = new \app\common\model\wmsorder\Ck;
|
||
$CkModel2 = new \app\common\model\wmsorder\Ck;
|
||
$PickingModel = new \app\common\model\wmsorder\Picking;
|
||
$StoreModel = new \app\common\model\wms\Store;
|
||
$wmspickingModel = new \app\common\model\wms\Picking;
|
||
$orders = $orderModel->field("ID,STOREID,ASSIGNFLAG,GRABNUM,PICKINGFLAG,FLAG,PLSENDFLAG,WAREHOUSEID,LEAVEMESSAGE,NAME,SYNFLAG,SOURCEID,CREATIONDATE,PROVINCE,SOURCEORDERCODE,POSTNUM,STORENAME as STORE_NAME,POSTCODE,POSTNAME,ADDRESS")->where(["GRABNUM"=>$grabnum])->select();
|
||
$WAREHOUSE = $WarehouseModel->where(["WAREHOUSEID"=>$orders[0]->WAREHOUSEID])->find();
|
||
if(count($orders)==0){
|
||
return "波次不存在,无法处理";
|
||
}
|
||
$hasUnASSIGNs = [];
|
||
$hasUnPOSTFLAGs = [];
|
||
foreach($orders as $order){
|
||
if($order->ASSIGNFLAG==0){
|
||
array_push($hasUnASSIGNs,$order->ID);
|
||
}
|
||
if(!$order->POSTNUM){
|
||
array_push($hasUnPOSTFLAGs,$order->SOURCEID);
|
||
}
|
||
}
|
||
if($hasUnASSIGNs){
|
||
foreach ($hasUnASSIGNs as $hasUnASSIGN){
|
||
$res = Wsdl::webservice([$orders[0]->WAREHOUSEID,($WAREHOUSE["operatorID"] ?? null),$hasUnASSIGN,2],"assignWmsOrder");
|
||
$res = Wsdl::webservice([$orders[0]->WAREHOUSEID,($WAREHOUSE["operatorID"] ?? null),$hasUnASSIGN,3],"assignWmsOrder");
|
||
$res = Wsdl::webservice([$orders[0]->WAREHOUSEID,($WAREHOUSE["operatorID"] ?? null),$hasUnASSIGN,1],"assignWmsOrder");
|
||
}
|
||
$orders = $orderModel->field("ID,STOREID,ASSIGNFLAG,GRABNUM,PICKINGFLAG,FLAG,PLSENDFLAG,WAREHOUSEID,LEAVEMESSAGE,NAME,SYNFLAG,SOURCEID,CREATIONDATE,PROVINCE,SOURCEORDERCODE,POSTNUM,STORENAME as STORE_NAME,POSTCODE,POSTNAME,ADDRESS")->where(["GRABNUM"=>$grabnum])->select();
|
||
$hasUnASSIGNs = [];
|
||
foreach($orders as $order){
|
||
if($order->ASSIGNFLAG==0){
|
||
array_push($hasUnASSIGNs,$order->ID);
|
||
}
|
||
}
|
||
if($hasUnASSIGNs){
|
||
return implode("、",$hasUnASSIGNs)."等订单未分配储位,已取消打印";
|
||
}
|
||
}
|
||
if($hasUnPOSTFLAGs){
|
||
return implode("、",$hasUnPOSTFLAGs)."等订单未分配快递号,已取消打印";
|
||
}
|
||
//所有的订单拣货明细;
|
||
$data = $WmsitemModel->field('wmsitem.STOCKID as STOCKID,stock.BARCODE as BARCODE,wmsitem.COUNT as COUNT,goods.NAME as NAME,stock.STYLE as STYLE,stock.COLOR as COLOR,stock.IMG as IMG,wmsorder.name as kfname,wmsorder.ID as WMSORDERID')->alias("wmsitem")
|
||
->join("yj_wmsorder wmsorder","wmsorder.ID=wmsitem.WMSORDERID")
|
||
->join("yj_stock stock","stock.STOCKID=wmsitem.STOCKID")
|
||
->join("yj_goods goods","goods.GOODSID=stock.GOODSID")
|
||
->where(["wmsorder.GRABNUM"=>$grabnum])->select();
|
||
if(!$data){
|
||
return "数据库出错,需要排查";
|
||
}
|
||
$picking_infos = $wmspickingModel->alias("picking")->field("space.IDX as IDX,space.CUSTOMNUM as CUSTOMNUM,sum(picking.COUNT) as COUNT,picking.STOCKID,picking.WMSORDERID as WMSORDERID")->join("yj_space space","space.ID=picking.SPACEID")->join("yj_wmsorder wmsorder","wmsorder.ID=picking.WMSORDERID")->where(["wmsorder.GRABNUM"=>$grabnum])->group("picking.SPACEID,picking.STOCKID,picking.WMSORDERID")->order("space.IDX")->select();
|
||
foreach ($data as $k => $r){
|
||
$lessIDX = -1;
|
||
$tmp_SPACE_INFO = [];
|
||
foreach ($picking_infos as $picking_info){
|
||
if($picking_info["STOCKID"]==$r["STOCKID"] && $picking_info["WMSORDERID"]==$r->WMSORDERID){
|
||
if($lessIDX>$picking_info["IDX"]||$lessIDX<0){
|
||
$lessIDX = $picking_info["IDX"];
|
||
}
|
||
array_push($tmp_SPACE_INFO,$picking_info);
|
||
}
|
||
}
|
||
$data[$k]["SPACE_INFO"] = $tmp_SPACE_INFO;
|
||
$data[$k]["IDX"] = $lessIDX;
|
||
}
|
||
//return json($orders);
|
||
//创建订单到小程序
|
||
Db::startTrans();
|
||
try {
|
||
$datas = [];
|
||
$inset_datas = [];
|
||
$picking_datas = [];
|
||
foreach($orders as $order){
|
||
|
||
$datas_item = [
|
||
"code"=>"",
|
||
"title"=>"",
|
||
"newcode"=>"",
|
||
"kfname"=>"",
|
||
"list"=>[],
|
||
"remask"=>"",
|
||
"POSTNAME"=>"",
|
||
"ADDRESS"=>""
|
||
];
|
||
$datas_item['newcode'] = mb_substr($order->SOURCEID, -7);
|
||
$mp_order = $CkModel->where(["ID"=>$order->ID])->find();
|
||
$msgs = "出库单:\n";
|
||
if(!$mp_order){
|
||
//订单不存在,创建订单;
|
||
foreach ($data as $item){
|
||
if($order->ID!=$item->WMSORDERID){
|
||
continue;
|
||
}
|
||
$tmp_item = [
|
||
"STOCKID"=>$item["STOCKID"],
|
||
"NAME"=>$item["NAME"],
|
||
"BARCODE"=>$item["BARCODE"],
|
||
"COUNT"=>$item["COUNT"],
|
||
"STYLE"=>$item["STYLE"],
|
||
"COLOR"=>$item["COLOR"],
|
||
"IMG"=>$item["IMG"],
|
||
"IDX"=>$item["IDX"],
|
||
"WMSORDERID"=>$order->ID,
|
||
"SPACEID_info"=>json_encode($item["SPACE_INFO"]),
|
||
"box_info"=>"",
|
||
];
|
||
array_push($picking_datas,$tmp_item);
|
||
}
|
||
$STORE = $StoreModel->where(["STOREID"=>$order->STOREID])->find();
|
||
$STORENAME = ($STORE["TITLE"] ?? null);
|
||
$inset_data = [
|
||
"ID"=>$order->ID,
|
||
"WAREHOUSEID"=>$order->WAREHOUSEID,
|
||
"NAME"=>$order->NAME,
|
||
"CREATIONDATE"=>$order->CREATIONDATE,
|
||
"STOREID"=>$order->STOREID,
|
||
"LEAVEMESSAGE"=>$order->LEAVEMESSAGE,
|
||
"SOURCEID"=>$order->SOURCEID,
|
||
"IMGS"=>"",
|
||
"CARCODE"=>"",
|
||
"OPERATEUSERID"=>"",
|
||
"PICKING_TIME"=>"",
|
||
"SEND_TIME"=>"",
|
||
"STATUS"=>1,
|
||
"STORENAME"=>$STORENAME,
|
||
"PROVINCE"=>$order->PROVINCE,
|
||
"SOURCEORDERCODE"=>$order->SOURCEORDERCODE,
|
||
"STORE_NAME"=>$order->STORE_NAME,
|
||
"POSTNUM"=>$order->POSTNUM,
|
||
"POSTCODE"=>$order->POSTCODE,
|
||
"POSTNAME"=>$order->POSTNAME,
|
||
"ADDRESS"=>$order->ADDRESS
|
||
];
|
||
array_push($inset_datas,$inset_data);
|
||
if(($WAREHOUSE["chukuqun"] ?? null)){
|
||
foreach ($orders as $order){
|
||
$msgs.= mb_substr($order->SOURCEID, -7)."\n";
|
||
}
|
||
}
|
||
}
|
||
|
||
$store_setting = $storeSettingModel->field('ckdTitle')->where(["STOREID"=>$order->STOREID])->find();
|
||
|
||
$datas_item["title"] = $store_setting?$store_setting->ckdTitle:"";
|
||
$datas_item["code"] = $order->ID;
|
||
$datas_item["code"] = $order->ID;
|
||
$item_datas = [];
|
||
foreach ($data as $k =>$r){
|
||
|
||
if($r->WMSORDERID==$order->ID){
|
||
$tmp_r = json_decode(json_encode($r),true);
|
||
$tmp_r['BARCODE'] = str_replace(';', "<br>", $r["BARCODE"]);
|
||
if($r["kfname"]){
|
||
$kfname = $r["kfname"];
|
||
}
|
||
array_push($item_datas,$tmp_r);
|
||
}
|
||
}
|
||
$datas_item["kfname"] = $kfname;
|
||
$datas_item["list"] = $item_datas;
|
||
$datas_item['remask'] = $order->LEAVEMESSAGE." 运单号:".$order->POSTNUM;
|
||
$datas_item['POSTNAME'] = $order->POSTNAME;
|
||
$datas_item['ADDRESS'] = $order->ADDRESS;
|
||
array_push($datas,$datas_item);
|
||
}
|
||
|
||
if(count($inset_datas)>0){
|
||
$res2 = $PickingModel->saveAll($picking_datas);
|
||
foreach ($inset_datas as $inset_data){
|
||
$CkModel2->isUpdate(false)->save($inset_data);
|
||
}
|
||
}
|
||
Db::commit();
|
||
} catch (ValidateException|PDOException|Exception $e) {
|
||
Db::rollback();
|
||
return "创建订单失败,请重新打开重试".$e;
|
||
}
|
||
if(count($inset_datas)>0){
|
||
$msgs.= "已打印,请领单备货出库";
|
||
$msg = $this->toMsg(($WAREHOUSE["chukuqun"] ?? null),$msgs);
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
}
|
||
$formattedDate = date("Y/n/j", time());
|
||
$this->view->assign('formattedDate', $formattedDate);
|
||
$this->view->assign('list', $datas);
|
||
//return json($datas);
|
||
if($page=="A4"){
|
||
return $this->view->fetch("ckd_grab_a4");
|
||
}elseif($page=="3L"){
|
||
return $this->view->fetch("ckd_grab_3l");
|
||
}else{
|
||
return $this->view->fetch("ckd_grab_a5");
|
||
}
|
||
}
|
||
public function ckd($code,$page=null){
|
||
$WmsitemModel = new \app\common\model\wms\Wmsitem;
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
$storeSettingModel = new \app\common\model\store\Setting;
|
||
$WarehouseModel = new \app\common\model\Warehouse;
|
||
$CkModel = new \app\common\model\wmsorder\Ck;
|
||
$PickingModel = new \app\common\model\wmsorder\Picking;
|
||
$StoreModel = new \app\common\model\wms\Store;
|
||
$wmspickingModel = new \app\common\model\wms\Picking;
|
||
$data = $WmsitemModel->field('wmsitem.STOCKID as STOCKID,stock.BARCODE as BARCODE,wmsitem.COUNT as COUNT,goods.NAME as NAME,stock.STYLE as STYLE,stock.COLOR as COLOR,stock.IMG as IMG,wmsorder.name as kfname')->alias("wmsitem")
|
||
->join("yj_wmsorder wmsorder","wmsorder.ID=wmsitem.WMSORDERID")
|
||
->join("yj_stock stock","stock.STOCKID=wmsitem.STOCKID")
|
||
->join("yj_goods goods","goods.GOODSID=stock.GOODSID")
|
||
->where(["wmsorder.SOURCEID"=>$code])->select();
|
||
$kfname = '';
|
||
if(!$data){
|
||
return "出库单不存在";
|
||
}
|
||
$order = $orderModel->field("ID,STOREID,ASSIGNFLAG,GRABNUM,PICKINGFLAG,FLAG,PLSENDFLAG,WAREHOUSEID,LEAVEMESSAGE,NAME,SYNFLAG,SOURCEID,CREATIONDATE,PROVINCE,SOURCEORDERCODE,POSTNUM,STORENAME as STORE_NAME,POSTCODE,POSTNAME,ADDRESS")->where(["SOURCEID"=>$code])->find();
|
||
|
||
$STORE = $StoreModel->where(["STOREID"=>$order->STOREID])->find();
|
||
$STORENAME = ($STORE["TITLE"] ?? null);
|
||
if(!$order){
|
||
return "出库单不存在";
|
||
}
|
||
if(!$order["POSTNUM"]){
|
||
return "未分配快递号";
|
||
}
|
||
$WAREHOUSE = $WarehouseModel->where(["WAREHOUSEID"=>$order->WAREHOUSEID])->find();
|
||
if($order->ASSIGNFLAG==0){
|
||
//未分配储位
|
||
$res = Wsdl::webservice([$order->WAREHOUSEID,($WAREHOUSE["operatorID"] ?? null),$order->ID,2],"assignWmsOrder");
|
||
$res = Wsdl::webservice([$order->WAREHOUSEID,($WAREHOUSE["operatorID"] ?? null),$order->ID,3],"assignWmsOrder");
|
||
$res = Wsdl::webservice([$order->WAREHOUSEID,($WAREHOUSE["operatorID"] ?? null),$order->ID,1],"assignWmsOrder");
|
||
}
|
||
$order = $orderModel->field("ID,STOREID,ASSIGNFLAG,GRABNUM,PICKINGFLAG,FLAG,PLSENDFLAG,WAREHOUSEID,LEAVEMESSAGE,NAME,SYNFLAG,SOURCEID,CREATIONDATE,PROVINCE,SOURCEORDERCODE,POSTNUM,STORENAME as STORE_NAME,POSTCODE,POSTNAME,ADDRESS")->where(["SOURCEID"=>$code])->find();
|
||
if($order->ASSIGNFLAG==0){
|
||
return "分配储位失败";
|
||
}
|
||
$picking_infos = $wmspickingModel->alias("picking")->field("space.IDX as IDX,space.CUSTOMNUM as CUSTOMNUM,sum(picking.COUNT) as COUNT,STOCKID")->join("yj_space space","space.ID=picking.SPACEID")->where(["WMSORDERID"=>$order->ID])->group("picking.SPACEID,picking.STOCKID")->order("space.IDX")->select();
|
||
foreach ($data as $k => $r){
|
||
$lessIDX = -1;
|
||
$tmp_SPACE_INFO = [];
|
||
foreach ($picking_infos as $picking_info){
|
||
if($picking_info["STOCKID"]==$r["STOCKID"]){
|
||
if($lessIDX>$picking_info["IDX"]||$lessIDX<0){
|
||
$lessIDX = $picking_info["IDX"];
|
||
}
|
||
array_push($tmp_SPACE_INFO,$picking_info);
|
||
}
|
||
}
|
||
$data[$k]["SPACE_INFO"] = $tmp_SPACE_INFO;
|
||
$data[$k]["IDX"] = $lessIDX;
|
||
}
|
||
//创建订单到小程序
|
||
$newcode = mb_substr($code, -7);
|
||
$mp_order = $CkModel->where(["ID"=>$order->ID])->find();
|
||
if(!$mp_order){
|
||
//订单不存在,创建订单;
|
||
Db::startTrans();
|
||
$picking_datas = [];
|
||
foreach ($data as $item){
|
||
$tmp_item = [
|
||
"STOCKID"=>$item["STOCKID"],
|
||
"NAME"=>$item["NAME"],
|
||
"BARCODE"=>$item["BARCODE"],
|
||
"COUNT"=>$item["COUNT"],
|
||
"STYLE"=>$item["STYLE"],
|
||
"COLOR"=>$item["COLOR"],
|
||
"IMG"=>$item["IMG"],
|
||
"IDX"=>$item["IDX"],
|
||
"WMSORDERID"=>$order->ID,
|
||
"SPACEID_info"=>json_encode($item["SPACE_INFO"]),
|
||
"box_info"=>"",
|
||
];
|
||
array_push($picking_datas,$tmp_item);
|
||
}
|
||
try {
|
||
$inset_data = [
|
||
"ID"=>$order->ID,
|
||
"WAREHOUSEID"=>$order->WAREHOUSEID,
|
||
"NAME"=>$order->NAME,
|
||
"CREATIONDATE"=>$order->CREATIONDATE,
|
||
"STOREID"=>$order->STOREID,
|
||
"LEAVEMESSAGE"=>$order->LEAVEMESSAGE,
|
||
"SOURCEID"=>$order->SOURCEID,
|
||
"IMGS"=>"",
|
||
"CARCODE"=>"",
|
||
"OPERATEUSERID"=>"",
|
||
"PICKING_TIME"=>"",
|
||
"SEND_TIME"=>"",
|
||
"STATUS"=>1,
|
||
"STORENAME"=>$STORENAME,
|
||
"PROVINCE"=>$order->PROVINCE,
|
||
"SOURCEORDERCODE"=>$order->SOURCEORDERCODE,
|
||
"STORE_NAME"=>$order->STORE_NAME,
|
||
"POSTNUM"=>$order->POSTNUM,
|
||
"POSTCODE"=>$order->POSTCODE,
|
||
"POSTNAME"=>$order->POSTNAME,
|
||
"ADDRESS"=>$order->ADDRESS
|
||
];
|
||
$CkModel->save($inset_data);
|
||
$PickingModel->saveAll($picking_datas);
|
||
if(($WAREHOUSE["chukuqun"] ?? null)){
|
||
$msg = $this->toMsg(($WAREHOUSE["chukuqun"] ?? null),"{$newcode}出库单已打印,请领单备货出库");
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
}
|
||
Db::commit();
|
||
} catch (ValidateException|PDOException|Exception $e) {
|
||
Db::rollback();
|
||
return "创建订单失败,请刷新重试".$e;
|
||
}
|
||
}
|
||
|
||
$store_setting = $storeSettingModel->field('ckdTitle')->where(["STOREID"=>$order->STOREID])->find();
|
||
foreach ($data as $k =>$r){
|
||
$data[$k]["BARCODE"] = str_replace(';', "<br>", $r["BARCODE"]);
|
||
if($r["kfname"]){
|
||
$kfname = $r["kfname"];
|
||
}
|
||
}
|
||
$formattedDate = date("Y/n/j", time());
|
||
|
||
$this->view->assign('title', $store_setting && $store_setting->ckdTitle?$store_setting->ckdTitle:'');
|
||
$this->view->assign('code', $order->ID);
|
||
$this->view->assign('newcode', $newcode);
|
||
$this->view->assign('formattedDate', $formattedDate);
|
||
$this->view->assign('kfname', $order->NAME);
|
||
$this->view->assign('list', $data);
|
||
$this->view->assign('remask', $order->LEAVEMESSAGE);
|
||
$this->view->assign('POSTNAME',$order->POSTNAME);
|
||
$this->view->assign('ADDRESS',$order->ADDRESS);
|
||
if($page=="A4"){
|
||
return $this->view->fetch("ckd2");
|
||
}elseif($page=="3L"){
|
||
return $this->view->fetch("ckd3");
|
||
}else{
|
||
return $this->view->fetch();
|
||
}
|
||
}
|
||
public function ckd2($code,$page=null){
|
||
$WmsitemModel = new \app\common\model\wms\Wmsitem1;
|
||
$orderModel = new \app\common\model\wms\Deliveryorder;
|
||
$storeSettingModel = new \app\common\model\store\Setting;
|
||
$WarehouseModel = new \app\common\model\Warehouse;
|
||
$CkModel = new \app\common\model\wmsorder\Ck;
|
||
$PickingModel = new \app\common\model\wmsorder\Picking;
|
||
$StoreModel = new \app\common\model\wms\Store;
|
||
$wmspickingModel = new \app\common\model\wms\Picking;
|
||
$data = $WmsitemModel->field('wmsitem.STOCKID as STOCKID,stock.BARCODE as BARCODE,wmsitem.COUNT as COUNT,goods.NAME as NAME,stock.STYLE as STYLE,stock.COLOR as COLOR,stock.IMG as IMG,wmsorder.name as kfname')->alias("wmsitem")
|
||
->join("yj_deliveryorder wmsorder","wmsorder.ID=wmsitem.WMSORDERID")
|
||
->join("yj_stock stock","stock.STOCKID=wmsitem.STOCKID")
|
||
->join("yj_goods goods","goods.GOODSID=stock.GOODSID")
|
||
->where(["wmsorder.SOURCEID"=>$code])->select();
|
||
$kfname = '';
|
||
if(!$data){
|
||
return "出库单不存在";
|
||
}
|
||
$order = $orderModel->field("ID,STOREID,1 as ASSIGNFLAG,GRABNUM,1 as PICKINGFLAG,FLAG,1 as PLSENDFLAG,WAREHOUSEID,LEAVEMESSAGE,NAME,SYNFLAG,SOURCEID,CREATIONDATE,PROVINCE,SOURCEORDERCODE,POSTNUM,STORENAME as STORE_NAME,POSTCODE,POSTNAME,ADDRESS")->where(["SOURCEID"=>$code])->find();
|
||
|
||
$STORE = $StoreModel->where(["STOREID"=>$order->STOREID])->find();
|
||
$STORENAME = ($STORE["TITLE"] ?? null);
|
||
if(!$order){
|
||
return "出库单不存在";
|
||
}
|
||
if(!$order["POSTNUM"]){
|
||
return "未分配快递号";
|
||
}
|
||
$WAREHOUSE = $WarehouseModel->where(["WAREHOUSEID"=>$order->WAREHOUSEID])->find();
|
||
if($order->ASSIGNFLAG==0){
|
||
//未分配储位
|
||
$res = Wsdl::webservice([$order->WAREHOUSEID,($WAREHOUSE["operatorID"] ?? null),$order->ID,2],"assignWmsOrder");
|
||
$res = Wsdl::webservice([$order->WAREHOUSEID,($WAREHOUSE["operatorID"] ?? null),$order->ID,3],"assignWmsOrder");
|
||
$res = Wsdl::webservice([$order->WAREHOUSEID,($WAREHOUSE["operatorID"] ?? null),$order->ID,1],"assignWmsOrder");
|
||
}
|
||
$order = $orderModel->field("ID,STOREID,1 as ASSIGNFLAG,GRABNUM,1 as PICKINGFLAG,FLAG,1 as PLSENDFLAG,WAREHOUSEID,LEAVEMESSAGE,NAME,SYNFLAG,SOURCEID,CREATIONDATE,PROVINCE,SOURCEORDERCODE,POSTNUM,STORENAME as STORE_NAME,POSTCODE,POSTNAME,ADDRESS")->where(["SOURCEID"=>$code])->find();
|
||
if($order->ASSIGNFLAG==0){
|
||
return "分配储位失败";
|
||
}
|
||
$picking_infos = $wmspickingModel->alias("picking")->field("space.IDX as IDX,space.CUSTOMNUM as CUSTOMNUM,sum(picking.COUNT) as COUNT,STOCKID")->join("yj_space space","space.ID=picking.SPACEID")->where(["WMSORDERID"=>$order->ID])->group("picking.SPACEID,picking.STOCKID")->order("space.IDX")->select();
|
||
foreach ($data as $k => $r){
|
||
$lessIDX = -1;
|
||
$tmp_SPACE_INFO = [];
|
||
foreach ($picking_infos as $picking_info){
|
||
if($picking_info["STOCKID"]==$r["STOCKID"]){
|
||
if($lessIDX>$picking_info["IDX"]||$lessIDX<0){
|
||
$lessIDX = $picking_info["IDX"];
|
||
}
|
||
array_push($tmp_SPACE_INFO,$picking_info);
|
||
}
|
||
}
|
||
$data[$k]["SPACE_INFO"] = $tmp_SPACE_INFO;
|
||
$data[$k]["IDX"] = $lessIDX;
|
||
}
|
||
//创建订单到小程序
|
||
$newcode = mb_substr($code, -7);
|
||
$mp_order = $CkModel->where(["ID"=>$order->ID])->find();
|
||
if(!$mp_order){
|
||
//订单不存在,创建订单;
|
||
Db::startTrans();
|
||
$picking_datas = [];
|
||
foreach ($data as $item){
|
||
$tmp_item = [
|
||
"STOCKID"=>$item["STOCKID"],
|
||
"NAME"=>$item["NAME"],
|
||
"BARCODE"=>$item["BARCODE"],
|
||
"COUNT"=>$item["COUNT"],
|
||
"STYLE"=>$item["STYLE"],
|
||
"COLOR"=>$item["COLOR"],
|
||
"IMG"=>$item["IMG"],
|
||
"IDX"=>$item["IDX"],
|
||
"WMSORDERID"=>$order->ID,
|
||
"SPACEID_info"=>json_encode($item["SPACE_INFO"]),
|
||
"box_info"=>"",
|
||
];
|
||
array_push($picking_datas,$tmp_item);
|
||
}
|
||
try {
|
||
$inset_data = [
|
||
"ID"=>$order->ID,
|
||
"WAREHOUSEID"=>$order->WAREHOUSEID,
|
||
"NAME"=>$order->NAME,
|
||
"CREATIONDATE"=>$order->CREATIONDATE,
|
||
"STOREID"=>$order->STOREID,
|
||
"LEAVEMESSAGE"=>$order->LEAVEMESSAGE,
|
||
"SOURCEID"=>$order->SOURCEID,
|
||
"IMGS"=>"",
|
||
"CARCODE"=>"",
|
||
"OPERATEUSERID"=>"",
|
||
"PICKING_TIME"=>"",
|
||
"SEND_TIME"=>"",
|
||
"STATUS"=>1,
|
||
"STORENAME"=>$STORENAME,
|
||
"PROVINCE"=>$order->PROVINCE,
|
||
"SOURCEORDERCODE"=>$order->SOURCEORDERCODE,
|
||
"STORE_NAME"=>$order->STORE_NAME,
|
||
"POSTNUM"=>$order->POSTNUM,
|
||
"POSTCODE"=>$order->POSTCODE,
|
||
"POSTNAME"=>$order->POSTNAME,
|
||
"ADDRESS"=>$order->ADDRESS
|
||
];
|
||
$CkModel->save($inset_data);
|
||
$PickingModel->saveAll($picking_datas);
|
||
if(($WAREHOUSE["chukuqun"] ?? null)){
|
||
$msg = $this->toMsg(($WAREHOUSE["chukuqun"] ?? null),"{$newcode}出库单已打印,请领单备货出库");
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
}
|
||
Db::commit();
|
||
} catch (ValidateException|PDOException|Exception $e) {
|
||
Db::rollback();
|
||
return "创建订单失败,请刷新重试".$e;
|
||
}
|
||
}
|
||
|
||
$store_setting = $storeSettingModel->field('ckdTitle')->where(["STOREID"=>$order->STOREID])->find();
|
||
foreach ($data as $k =>$r){
|
||
$data[$k]["BARCODE"] = str_replace(';', "<br>", $r["BARCODE"]);
|
||
if($r["kfname"]){
|
||
$kfname = $r["kfname"];
|
||
}
|
||
}
|
||
$formattedDate = date("Y/n/j", time());
|
||
|
||
$this->view->assign('title', $store_setting && $store_setting->ckdTitle?$store_setting->ckdTitle:'');
|
||
$this->view->assign('code', $order->ID);
|
||
$this->view->assign('newcode', $newcode);
|
||
$this->view->assign('formattedDate', $formattedDate);
|
||
$this->view->assign('kfname', $order->NAME);
|
||
$this->view->assign('list', $data);
|
||
$this->view->assign('remask', $order->LEAVEMESSAGE);
|
||
$this->view->assign('POSTNAME',$order->POSTNAME);
|
||
$this->view->assign('ADDRESS',$order->ADDRESS);
|
||
if($page=="A4"){
|
||
return $this->view->fetch("ckd2");
|
||
}elseif($page=="3L"){
|
||
return $this->view->fetch("ckd3");
|
||
}else{
|
||
return $this->view->fetch();
|
||
}
|
||
}
|
||
public function msgtimeout(){
|
||
//客服处理消息超时
|
||
$redis = new \Redis();
|
||
$redis->connect('127.0.0.1', 6379);
|
||
$redis->auth('qwe2019@');
|
||
$redis->select(4);
|
||
$block_keys = $redis->keys("to:*");
|
||
$list = [];
|
||
$current_hour = intval(date('H', time()));
|
||
$msgText = $current_hour>8 && $current_hour<22?"客服可能在繁忙,已自动提醒客服处理,请耐心等待":"人工客服已下班,已自动提醒客服上班处理";
|
||
foreach ($block_keys as $block_key){
|
||
$block_info = $redis->get($block_key);
|
||
if(!$block_info){
|
||
break;
|
||
}
|
||
$msg = explode("|",$block_info);
|
||
if(time()-intval($msg[0])>300){
|
||
$text = "以下消息:\n——————————————————————\n".$msg[1]."\n——————————————————————————\n小艾暂时无法识别,{$msgText}\n@天豹单据-小陈同学 @综合客服@小雷 @售后客服--邹绮丽9:00-18:30 @售后客服--熊彩 9:00-18:30 @售后客服小青10:00--18:30 ";
|
||
$msg = $this->toMsg($block_key,$text,"wxid_j4bugg1135xv22|wxid_ldkszcxs75gj22|wxid_76e9qoyrakny12|wxid_6adeyz26uc0d22|wxid_gb0l36grxn6w22");
|
||
$redis->select(2);
|
||
array_push($list,$msg);
|
||
$redis->lpush("Message",json_encode($msg));
|
||
$redis->select(4);
|
||
$redis->del($block_key);
|
||
}
|
||
}
|
||
return json($list);
|
||
}
|
||
public function plateresult($WAREHOUSEID=""){
|
||
if(!$WAREHOUSEID){
|
||
return "0";
|
||
}
|
||
$WhitelistModel = new \app\common\model\door\Whitelist;
|
||
$data = [];
|
||
$lockKey = null;
|
||
$message = null;
|
||
$exitCarnum = null; //出口车牌号,用于推送 WMS
|
||
$entryCarnum = null; //进场车牌号,用于推送 WMS
|
||
$entryAllow = false; //进场是否已放行(临时通行/白名单)
|
||
$entryReason = ''; //进场放行缘由 / 未放行原因
|
||
try {
|
||
$requestData = $this->request->getContent();
|
||
$requestData_json = json_decode($requestData,true);
|
||
$carnum = ($requestData_json["AlarmInfoPlate"]["result"]["PlateResult"]["license"] ?? null);
|
||
$date = date('Y-m-d H:i:s');
|
||
switch(($requestData_json["AlarmInfoPlate"]["deviceName"] ?? null)){
|
||
case "出口":
|
||
$message = "车辆{$carnum}离场";
|
||
$lockKey = "plateresult_exit_lock_{$WAREHOUSEID}_{$carnum}";
|
||
$exitCarnum = $carnum; //标记出口事件,用于推送 WMS
|
||
$data = [
|
||
"Response_AlarmInfoPlate"=>
|
||
[
|
||
"info"=>"ok",
|
||
"channelNum"=>0,
|
||
"delay"=>2,
|
||
"playserver_json_request"=>
|
||
[
|
||
"type"=>"ps_voice_play",
|
||
"voice"=>$this->doorVoidText("一路平安"),
|
||
"voice_interval"=>0,
|
||
"voice_volume"=>100,
|
||
"voice_male"=>1
|
||
]
|
||
]
|
||
];
|
||
break;
|
||
case "入口":
|
||
$this->redis->select(7);
|
||
$info = $this->redis->get("{$WAREHOUSEID}_{$carnum}");
|
||
|
||
$lockKey = "plateresult_exit_lock_{$WAREHOUSEID}_{$carnum}";
|
||
$entryCarnum = $carnum; //标记进场事件,用于推送 WMS
|
||
if($info){
|
||
//判断是否临时车辆,临时车辆删除进入许可
|
||
$carinfo = json_decode($info,true);
|
||
$types = [
|
||
"daohuo"=>"到货",
|
||
"tihuo"=>"提货"
|
||
];
|
||
$message = "{$date} 临时车辆{$carnum}入场\n放行群:".($carinfo['roomName'] ?? null)."\n放行人:".($carinfo['UserName'] ?? null)."\n放行缘由:".($types[$carinfo['type'] ?? null] ?? null);
|
||
$entryAllow = true;
|
||
$entryReason = "临时车辆-".(isset($types[($carinfo['type'] ?? null)]) ? $types[($carinfo['type'] ?? null)] : ($carinfo['type'] ?? null));
|
||
$this->redis->del("{$WAREHOUSEID}_{$carnum}");
|
||
$data =
|
||
[
|
||
"Response_AlarmInfoPlate"=>
|
||
[
|
||
"info"=>"ok",
|
||
"channelNum"=>0,
|
||
"delay"=>2,
|
||
"playserver_json_request"=>
|
||
[
|
||
"type"=>"ps_voice_play",
|
||
"voice"=>$this->doorVoidText("欢迎光临"),
|
||
"voice_interval"=>0,
|
||
"voice_volume"=>100,
|
||
"voice_male"=>1
|
||
]
|
||
]
|
||
];
|
||
}else{
|
||
//缓存无放行,匹配白名单
|
||
$car = $WhitelistModel->where(["carnum"=>$carnum,"WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
//白名单有信息,加载到缓存
|
||
if($car){
|
||
$message = "{$date} {$carnum}({$car['remask']})入场";
|
||
$entryAllow = true;
|
||
$entryReason = "白名单";
|
||
$data = [
|
||
"Response_AlarmInfoPlate"=>["info"=>"ok","channelNum"=>0,"delay"=>1000,
|
||
"playserver_json_request"=>
|
||
[
|
||
"type"=>"ps_voice_play",
|
||
"voice"=>$this->doorVoidText("欢迎光临"),
|
||
"voice_interval"=>0,
|
||
"voice_volume"=>100,
|
||
]
|
||
]
|
||
];
|
||
}else{
|
||
$message = "{$date} {$carnum}无访问权限,等待人工开门";
|
||
$entryReason = "无访问权限";
|
||
$data = null;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
} catch (\Exception $e) {
|
||
return "0";
|
||
}
|
||
|
||
//发送消息
|
||
Log::error("开门信息".json_encode($message));
|
||
|
||
//事件防重锁:车牌识别设备可能在 20 秒内重复上报同一次进出
|
||
$locked = $lockKey ? $this->redis->set($lockKey, 1, ['nx', 'ex' => 20]) : true;
|
||
Log::error("防重锁: key={$lockKey} locked=".($locked ? 1 : 0));
|
||
|
||
//出口/进场事件:伪造一条 wx 系统消息推送到 WMS(群ID=system / 群名=系统 / 内容={车牌}离场|进场 / 来源=system)
|
||
if($exitCarnum && $locked){
|
||
$this->pushVehicleToWms($WAREHOUSEID, $exitCarnum, 'exit');
|
||
}
|
||
if($entryCarnum && $locked){
|
||
$this->pushVehicleToWms($WAREHOUSEID, $entryCarnum, 'entry', [
|
||
'allow' => $entryAllow ? 1 : 0, //是否已放行(临时通行/白名单)
|
||
'reason' => $entryReason, //临时车辆-到货 / 白名单 / 无访问权限
|
||
]);
|
||
}
|
||
|
||
if($message){
|
||
$roomsModel = new \app\common\model\qiwe\Rooms();
|
||
$room = $roomsModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"type"=>2,"sub_type"=>"door"])->find();
|
||
if(!$room){
|
||
$roomsModel = new \app\common\model\Rooms();
|
||
$room = $roomsModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"type"=>2,"sub_type"=>"door"])->find();
|
||
}
|
||
Log::error("开门群".json_encode($room));
|
||
|
||
if($room){
|
||
$msg = $this->toMsg($room["room_id"],$message);
|
||
if($lockKey && $locked){
|
||
$this->toMsgCache($msg);
|
||
}
|
||
}
|
||
}
|
||
if($data){
|
||
return json($data);
|
||
}else{
|
||
return "0";
|
||
}
|
||
}
|
||
/**
|
||
* 车辆进出场 → 伪造一条 wx 系统消息推送到 WMS 站内信(inbox.push)
|
||
*
|
||
* 群ID=system、群名=系统、内容={车牌}离场 / {车牌}进场、来源=system
|
||
* (inbox.push 的 sourceType 与 extData.source 都传 system)。
|
||
* 推送失败只记日志,不影响道闸放行响应。
|
||
*
|
||
* @param {int|string} $WAREHOUSEID 仓库ID
|
||
* @param {string} $carnum 车牌号
|
||
* @param {string} $event exit 离场 / entry 进场
|
||
* @param {array} $extra 追加到 extData 的额外字段(如进场的 allow / reason)
|
||
* @return {array|null} WMS 返回结果,失败返回 null
|
||
*/
|
||
private function pushVehicleToWms($WAREHOUSEID, $carnum, $event, $extra = []){
|
||
try{
|
||
if (empty(config('wms.app_key')) || empty(config('wms.app_secret'))) {
|
||
Log::error("车辆推送WMS跳过: wms 配置未就绪");
|
||
return null;
|
||
}
|
||
$textMap = ['exit'=>"离场", 'entry'=>"进场"];
|
||
$content = $carnum.(isset($textMap[$event]) ? $textMap[$event] : $event);
|
||
$inbox = new \app\index\library\new_wms\func\Inbox();
|
||
$result = $inbox->push([
|
||
'requestId' => "{$event}:{$WAREHOUSEID}:{$carnum}:" . date('YmdHis'), //幂等去重,同一次进出由上面的防重锁兜底
|
||
'content' => $content,
|
||
'groupId' => 'system',
|
||
'groupName' => '系统',
|
||
'userId' => 'system',
|
||
'userName' => '系统',
|
||
'parentId' => 0,
|
||
'sourceType' => 'system',
|
||
'targetType' => 'im',
|
||
'extData' => array_merge([
|
||
'source' => 'system', //wx / qiwe / system
|
||
'type' => 1,
|
||
'event' => $event,
|
||
'WAREHOUSEID' => $WAREHOUSEID,
|
||
'carnum' => $carnum,
|
||
'time' => date('Y-m-d H:i:s'),
|
||
], $extra),
|
||
'flags' => new \stdClass(),
|
||
]);
|
||
Log::error("车辆推送WMS: event={$event} content={$content} result=".json_encode($result, JSON_UNESCAPED_UNICODE));
|
||
return $result;
|
||
} catch (\Exception $e) {
|
||
Log::error("车辆推送WMS异常: " . $e->getMessage());
|
||
return null;
|
||
}
|
||
}
|
||
private function doorVoidText($text){
|
||
$result = '';
|
||
for ($i = 0; $i < mb_strlen($text, 'UTF-8'); $i++) {
|
||
$char = mb_substr($text, $i, 1, 'UTF-8');
|
||
if (mb_strlen($char, 'UTF-8') > 1 || strlen($char) > 1) {
|
||
$result .= '%u' . strtoupper(dechex(mb_ord($char)));
|
||
} else {
|
||
$result .= $char;
|
||
}
|
||
}
|
||
return base64_encode($result);
|
||
}
|
||
|
||
public function receivedeviceinfo($WAREHOUSEID="",$type=""){
|
||
$this->redis->select(2);
|
||
$data = $this->redis->get($WAREHOUSEID."_channelNum0");
|
||
if($data){
|
||
$data = [
|
||
"Response_AlarmInfoPlate" => [
|
||
"info" => "ok",
|
||
"channelNum" => 0,
|
||
"delay" => 20000,
|
||
"playserver_json_request" => [
|
||
"type" => "ps_voice_play",
|
||
"voice" => $this->doorVoidText("开门"),
|
||
"voice_interval" => 0,
|
||
"voice_volume" => 100,
|
||
"voice_male" => 1
|
||
],
|
||
"serialData" => [ // 修正点1:PHP 数组键必须用 =>
|
||
[
|
||
"serialChannel" => 0,
|
||
"data" => "A55A12AAD5A9413838383838006678F4E001354A9F01XX", // 记得把 XX 替换成真实校验值(如 3F)
|
||
"dataLen" => 22 // 修正点2:改为 22(因为 A5+5A+12...+01 共22字节)
|
||
]
|
||
]
|
||
]
|
||
];
|
||
$this->redis->del($WAREHOUSEID."_channelNum0");
|
||
}else{
|
||
$data = $this->redis->get($WAREHOUSEID."_openLater");
|
||
if(!$data && $type == "out"){
|
||
$data = [
|
||
"Response_AlarmInfoPlate"=>
|
||
[
|
||
"info"=>"ok",
|
||
"channelNum"=>1,
|
||
"delay"=>200000,
|
||
]
|
||
];
|
||
$this->redis->set($WAREHOUSEID."_openLater","1",['NX', 'EX' => 60]);
|
||
}
|
||
}
|
||
return json($data);
|
||
}
|
||
public function update_dgjexpress_default_flag(){
|
||
$OrderModel = new \app\common\model\wms\Order;
|
||
$orders = $OrderModel->where(["SOURCECODE"=>"z15","EXPRESSDEFAULTFLAG"=>1])->select();
|
||
foreach ($orders as $order){
|
||
$order->EXPRESSDEFAULTFLAG = 0;
|
||
$order->save();
|
||
}
|
||
return 1;
|
||
}
|
||
|
||
public function uuuuu(){//出库单填补数据
|
||
$CKModel = new \app\common\model\wmsorder\Ck;
|
||
$IDS = [];
|
||
$orders = $CKModel->where("POSTCODE is null")->select();
|
||
foreach ($orders as $r){
|
||
array_push($IDS,$r["ID"]);
|
||
}
|
||
$DeliveryorderModel = new \app\common\model\wms\Order;
|
||
$orders2 = $DeliveryorderModel->where("ID","in",$IDS)->where("POSTCODE is not null")->where("POSTCODE<>''")->select();
|
||
foreach ($orders as $r){
|
||
$POSTNUM = null;
|
||
foreach ($orders2 as $rr){
|
||
if($r["ID"]==$rr["ID"]){
|
||
$POSTNUM = $rr["POSTCODE"];
|
||
}
|
||
}
|
||
if($POSTNUM){
|
||
$r->POSTCODE = $POSTNUM;
|
||
$r->save();
|
||
}
|
||
}
|
||
return json($orders);
|
||
}
|
||
public function openD(){
|
||
$this->redis->select(2);
|
||
$data = $this->redis->set("5400_channelNum0",1);
|
||
}
|
||
public function lanshou(){
|
||
//echo 1;die();
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
$orderModel = $orderModel->field("POSTNUM,ORDERWEIGHT,ECNOTES,STOREID")->where(["WAREHOUSEID"=>5400,"POSTCODE"=>"p05","POSTFLAG"=>1,"ISLOCK"=>0,"FLAG"=>0,"ASSIGNFLAG"=>1]);
|
||
$fileContent = file_get_contents("postnums.txt");
|
||
if($fileContent){
|
||
// 使用正则分割:支持 逗号、空格、换行符、竖线、制表符等
|
||
$postnums = preg_split('/[\s,|]+/', $fileContent, -1, PREG_SPLIT_NO_EMPTY);
|
||
$orderModel ->where('POSTNUM',"in",$postnums);
|
||
}
|
||
$list = $orderModel->order("ORDERWEIGHT")->select();
|
||
$list2 = [];
|
||
foreach ($list as $r){
|
||
if($r["ORDERWEIGHT"]<999){
|
||
if($r["ORDERWEIGHT"]<500){
|
||
$WEIGHT = 130;
|
||
}else{
|
||
$WEIGHT = 290;
|
||
}
|
||
}else{
|
||
if(strpos($r["ECNOTES"],"微小")){
|
||
$WEIGHT=290;
|
||
}else{
|
||
$lv = $r["ORDERWEIGHT"]%1000;
|
||
if($lv<100){
|
||
$WEIGHT = intval($r["ORDERWEIGHT"]/1000)*1000;
|
||
}elseif($lv<500){
|
||
$WEIGHT = intval($r["ORDERWEIGHT"]/1000)*1000+200;
|
||
}elseif($lv<800){
|
||
$WEIGHT = intval($r["ORDERWEIGHT"]/1000)*1000+600;
|
||
}else{
|
||
$WEIGHT = intval($r["ORDERWEIGHT"]/1000)*1000+1000;
|
||
}
|
||
}
|
||
}
|
||
array_push($list2,[$r["POSTNUM"],$WEIGHT,$r["ORDERWEIGHT"],$r["ECNOTES"]]);
|
||
}
|
||
usort($list2, function($a, $b) {
|
||
return $a[1] - $b[1];
|
||
});
|
||
return json($list2);
|
||
}
|
||
public function getSpaceByCode(){
|
||
$params=$this->request->post();
|
||
$result = ["msg"=>"获取成功","status"=>1,"data"=>[]];
|
||
$spaceModel = new \app\common\model\wms\Space;
|
||
$space = $spaceModel->where(["BARCODE"=>$params['code'],"WAREHOUSEID"=>$params['WAREHOUSEID']])->find();
|
||
if($space){
|
||
$result["data"] = $space;
|
||
}else{
|
||
$result["status"] = 0;
|
||
$result["msg"] = "无库位";
|
||
}
|
||
return json($result);
|
||
}
|
||
public function updateStock(){
|
||
$stockModel = new \app\common\model\wms\Stock;
|
||
$result = ["msg"=>"修改成功"];
|
||
$params=$this->request->post();
|
||
if($params['stock_id']){
|
||
$stock = $stockModel->where(["STOCKID"=>$params['stock_id']])->find();
|
||
if(!$stock){
|
||
$result->msg = "找不到SKU";
|
||
return json($result);
|
||
}
|
||
$stock->IMG = $params["imgs"];
|
||
$stock->WEIGHT = $params["weight"];
|
||
$stock->STYLE = $params["style"];
|
||
$stock->COLOR = $params["color"];
|
||
$stock->save();
|
||
}
|
||
return json($result);
|
||
}
|
||
public function lanshou2(){
|
||
$orderModel = new \app\common\model\wms\Order;
|
||
$orderModel = $orderModel->field("POSTNUM,ORDERWEIGHT,ECNOTES,STOREID")->where(["WAREHOUSEID"=>5400,"POSTCODE"=>"p05"]);
|
||
$fileContent = file_get_contents("postnums.txt");
|
||
if($fileContent){
|
||
// 使用正则分割:支持 逗号、空格、换行符、竖线、制表符等
|
||
$postnums = preg_split('/[\s,|]+/', $fileContent, -1, PREG_SPLIT_NO_EMPTY);
|
||
$orderModel ->where('POSTNUM',"in",$postnums);
|
||
}else{
|
||
$orderModel ->where(["POSTFLAG"=>1,"ISLOCK"=>0]);
|
||
}
|
||
$list = $orderModel->order("ORDERWEIGHT")->select();
|
||
$list2 = [];
|
||
foreach ($list as $r){
|
||
if($r["ORDERWEIGHT"]<1100){
|
||
if($r["ORDERWEIGHT"]<500){
|
||
$WEIGHT = 130;
|
||
}else{
|
||
$WEIGHT = 1000;
|
||
}
|
||
}else{
|
||
$lv = $r["ORDERWEIGHT"]%1000;
|
||
if($lv<100){
|
||
$WEIGHT = intval($r["ORDERWEIGHT"]/1000)*1000;
|
||
}elseif($lv<500){
|
||
$WEIGHT = intval($r["ORDERWEIGHT"]/1000)*1000+200;
|
||
}elseif($lv<800){
|
||
$WEIGHT = intval($r["ORDERWEIGHT"]/1000)*1000+600;
|
||
}else{
|
||
$WEIGHT = intval($r["ORDERWEIGHT"]/1000)*1000+1000;
|
||
}
|
||
}
|
||
array_push($list2,[$r["POSTNUM"],$WEIGHT,$r["ORDERWEIGHT"],$r["ECNOTES"]]);
|
||
}
|
||
usort($list2, function($a, $b) {
|
||
return $a[1] - $b[1];
|
||
});
|
||
$this->view->assign('list', json_encode($list2));
|
||
return $this->view->fetch();
|
||
}
|
||
public function getApplyStorageInfo(){
|
||
$ApplystorageModel = new \app\common\model\wms\Applystorage;
|
||
$PutindetailModel = new \app\common\model\wms\Putindetail;
|
||
$result = ["msg"=>"","data"=>[],"status"=>0];
|
||
$params=$this->request->post();
|
||
$code = isset($params["code"])?$params["code"]:"";
|
||
$name = isset($params["name"])?$params["name"]:"";
|
||
$WAREHOUSEID = isset($params["WAREHOUSEID"])?$params["WAREHOUSEID"]:0;
|
||
|
||
if(!$code || !$name){
|
||
$result["msg"] = "无数据";
|
||
return json($result);
|
||
}
|
||
if(!$WAREHOUSEID){
|
||
$result["msg"] = "前端错误,已记录请求日志,等待技术人员排查处理";
|
||
return json($result);
|
||
}
|
||
try {
|
||
$Applystorage = $ApplystorageModel
|
||
->alias("apply")
|
||
->field("apply.ID as ID,store.TITLE as TITLE,apply.SERIALNUM as SERIALNUM,apply.status as status")
|
||
->where(["SERIALNUM"=>$code,"WAREHOUSEID"=>$WAREHOUSEID])
|
||
->join("yj_store store","store.STOREID=apply.STOREID")
|
||
->find();
|
||
|
||
if(!$Applystorage){
|
||
$result["msg"] = "没有找到入库单";
|
||
return json($result);
|
||
}
|
||
if($Applystorage['status']==5 || $Applystorage['status']==2){
|
||
$result["msg"] = "入库单已完成入库";
|
||
return json($result);
|
||
}
|
||
if($Applystorage['status']==3){
|
||
$result["msg"] = "入库单已取消";
|
||
return json($result);
|
||
}
|
||
|
||
if($Applystorage['status']!=4){
|
||
//等待入库的,
|
||
$result["msg"] = "非随机入库单,请移交客服处理";
|
||
return json($result);
|
||
}
|
||
|
||
$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 $k => $r){
|
||
$data[$k]['imgss'] = $this->getStockImgs($r['stock_id']);
|
||
}
|
||
$result["data"] = [
|
||
"stocks"=>$data,
|
||
"info"=>$Applystorage,
|
||
];
|
||
$result["status"]=1;
|
||
$result["msg"] = "获取成功";
|
||
|
||
return json($result);
|
||
|
||
} catch (\Exception $e) {
|
||
$result["msg"] = "系统异常,请稍后重试".$e->getMessage();
|
||
return json($result);
|
||
} finally {
|
||
}
|
||
}
|
||
public function inputStockConfirm(){
|
||
$result = ["msg"=>"入库成功","status"=>1,"data"=>[]];
|
||
$params=$this->request->post();
|
||
$inputCount = isset($params['inputcount'])?intval($params['inputcount']):0;
|
||
$scrq = isset($params['scrq'])?$params['scrq']:"";
|
||
$spaceId = isset($params['spaceId'])?intval($params['spaceId']):0;
|
||
$SERIALNUM = isset($params['SERIALNUM'])?$params['SERIALNUM']:"";
|
||
$userid = isset($params['userid'])?$params['userid']:0;
|
||
if($params['stock'] && $params['stock']['stock_id'] && $inputCount>0 && $SERIALNUM && $spaceId>0 && $userid>0){
|
||
$inputStr = "{$params['stock']['stock_id']}|{$inputCount}|{$params['stock']['count']}|{$params['stock']['title']} {$params['stock']['BARCODE']} {$params['stock']['color']} {$params['stock']['style']}|999|{$params['stock']['putin_count']},@@{$spaceId}@@{$scrq}";
|
||
$res = Wsdl::webservicepda([$userid,$SERIALNUM,$inputStr],"confirmPutInR1");
|
||
if(intval($res)!=1){
|
||
$result['msg'] = "入库失败,请联系技术支持";
|
||
$result['status'] = 0;
|
||
}
|
||
$result['data'] = $res;
|
||
}else{
|
||
$result['msg'] = "入库失败";
|
||
$result['status'] = 0;
|
||
}
|
||
return json($result);
|
||
}
|
||
public function confirmApplyStorage(){
|
||
$params = $this->request->post();
|
||
$WAREHOUSEID = $params["WAREHOUSEID"];
|
||
$userId = $params["userid"];
|
||
$code = $params['code'];
|
||
|
||
// Redis键名
|
||
$lockKey = "confirm_apply_lock:{$code}";
|
||
$lockValue = uniqid(); // 唯一标识
|
||
|
||
try {
|
||
// 尝试获取锁(5秒过期)
|
||
$lockAcquired = $this->redis->set(
|
||
$lockKey,
|
||
$lockValue,
|
||
['NX', 'EX' => 5]
|
||
);
|
||
|
||
if (!$lockAcquired) {
|
||
return json([
|
||
'code' => 429,
|
||
'msg' => '系统正在处理该申请,请稍后重试',
|
||
'data' => null
|
||
], 429);
|
||
}
|
||
|
||
// 业务逻辑
|
||
$this->noticeConfirmApplyStorage($code);
|
||
$res = wsdl::webservice([
|
||
intval($WAREHOUSEID),
|
||
intval($userId),
|
||
intval($code)
|
||
], "bePutInStorageR");
|
||
|
||
return json([
|
||
'code' => 200,
|
||
'msg' => '操作成功',
|
||
'data' => $res
|
||
]);
|
||
|
||
} catch (\Exception $e) {
|
||
return json([
|
||
'code' => 500,
|
||
'msg' => '系统异常',
|
||
'data' => null
|
||
], 500);
|
||
|
||
} finally {
|
||
// 释放锁(使用Lua脚本保证原子性)- 修正版本
|
||
try {
|
||
$lua = "
|
||
if redis.call('get', KEYS[1]) == ARGV[1] then
|
||
return redis.call('del', KEYS[1])
|
||
else
|
||
return 0
|
||
end
|
||
";
|
||
|
||
// 方法1:使用正确的参数顺序
|
||
$this->redis->eval($lua, [$lockKey, $lockValue], 1);
|
||
|
||
// 或者方法2:使用另一种参数格式(如果上面不行,试试这个)
|
||
// $this->redis->eval($lua, 1, $lockKey, $lockValue);
|
||
|
||
} catch (\Exception $e) {
|
||
Log::warning("释放Redis锁失败: {$e->getMessage()}", [
|
||
'lockKey' => $lockKey,
|
||
'lockValue' => $lockValue
|
||
]);
|
||
}
|
||
}
|
||
}
|
||
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 = "noting";
|
||
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']])->find();
|
||
if(!$room){
|
||
$room = $RoomsModel->where(["isMain"=>1,"STOREID"=>$Applystorage['STOREID']])->find();
|
||
}
|
||
if($room){
|
||
[$aiteUser,$atids] = $this->getAUser($room["room_id"],"资料员");
|
||
$STR = "{$Applystorage['NOTES']}\n {$info}\n 已入库完毕\n提示:如果需要@指定人员,请备注群昵称为XXXXXX资料员";
|
||
if($atids){
|
||
$STR.=$aiteUser;
|
||
$tomsg = $this->toMsg($room["room_id"],$STR,$atids);
|
||
}else{
|
||
$tomsg = $this->toMsg($room["room_id"],$STR);
|
||
}
|
||
$tomsg = $this->toMsg($room['room_id'],"{$Applystorage['NOTES']}\n {$info}\n 已入库完毕\n提示:如果需要@指定人员,请备注群昵称为XXXXXX资料员");
|
||
|
||
$this->redis->select(2);
|
||
$this->redis->lpush("Message",json_encode($tomsg));
|
||
}
|
||
}
|
||
return json($tomsg);
|
||
}
|
||
//创建群订单到wms
|
||
public function create_room_order(){
|
||
$msgs = [];
|
||
$orderModel = new \app\common\model\rooms\Order;
|
||
$OrdersLib = new \app\index\library\chat\Orders;
|
||
$lockTimeout = 180;
|
||
$time = time();
|
||
$iterator = null;
|
||
$pattern = 'dd_*'; // 匹配所有以 dd_ 开头的键
|
||
$keys = [];
|
||
$delay_time = 180; //延迟出单时间
|
||
do {
|
||
// 每次扫描返回一批匹配的键
|
||
$result = $this->redis->scan($iterator, $pattern);
|
||
|
||
if ($result !== false) {
|
||
foreach ($result as $key){
|
||
$cleanKey = substr($key, 3);
|
||
$keys[] = $cleanKey;
|
||
}
|
||
}
|
||
} while ($iterator > 0);
|
||
|
||
$orders = $orderModel->where("status","in",[1,2])->where("create_time","<",$time-$delay_time);
|
||
if(count($keys)>0){
|
||
$orders->where("ordercode","not in",$keys);
|
||
}
|
||
$orders = $orders->order('create_time')->limit(10)->select();
|
||
$datas = [];
|
||
foreach ($orders as $order){
|
||
$order_source = $order["source"]??"wx";
|
||
$this->redis->set("dd_".$order["ordercode"], 1, ['NX', 'EX' => $lockTimeout]);
|
||
print_r($order);
|
||
[$code,$msg,$data] = $OrdersLib->createOrderToWms($order);
|
||
$MessageKey = "Message";
|
||
if($order_source=="qiwe"){
|
||
$MessageKey = "QiweMessage";
|
||
}
|
||
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($MessageKey,json_encode($this->withQueueTs($tomsg,$MessageKey)));
|
||
$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($MessageKey,json_encode($this->withQueueTs($tomsg,$MessageKey)));
|
||
$order->save();
|
||
}
|
||
array_push($datas,[$code,$msg,$data]);
|
||
}
|
||
return json($datas);
|
||
}
|
||
public function ckd_unfinished($WAREHOUSEID){
|
||
|
||
$WarehouseModel = new \app\common\model\Warehouse;
|
||
$yesterday_start = strtotime('yesterday', strtotime('00:00:00'));
|
||
$yesterday_end = $yesterday_start*1000+86399999;
|
||
$CKModel = new \app\common\model\wmsorder\Ck;
|
||
$WAREHOUSE = $WarehouseModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
$orders = $CKModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("CREATIONDATE","BETWEEN",[$yesterday_start*1000,$yesterday_end])->where("status<4")->select();
|
||
$status_arr = [
|
||
1=>"等待配货",
|
||
2=>"配货中",
|
||
3=>"等待出库"
|
||
];
|
||
if(count($orders)==0){
|
||
$msg = "昨日出库单已全部完成,再接再厉";
|
||
return 1;
|
||
}else{
|
||
$msg = "昨日出库单还有以下订单未完成,请核实并处理\n";
|
||
foreach ($orders as $order){
|
||
$code = mb_substr($order->SOURCEID, -7);
|
||
$msg.="{$code}|{$order->NAME}|{$order->STORENAME}|{$status_arr[$order->STATUS]}\n";
|
||
}
|
||
}
|
||
if(($WAREHOUSE["chukuqun"] ?? null)){
|
||
$msg = $this->toMsg(($WAREHOUSE["chukuqun"] ?? null),$msg);
|
||
$this->redis->select(2);
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
}
|
||
return json($msg);
|
||
}
|
||
private function putout_putin_storage7($STOREID){
|
||
$weekEnd = $this->day7();
|
||
$arr = [];
|
||
$StockModel = new \app\common\model\wms\Stock;
|
||
foreach ($weekEnd as $day){
|
||
$STOCKS_DATA = $StockModel
|
||
->field('warestore.STOREID as STOREID,stock.STOCKID as STOCKID,IFNULL(CAST(putoutstorage.COUNT AS SIGNED), 0) as CKCOUNT,IFNULL(CAST(putinstorage.COUNT AS SIGNED), 0) as RKCOUNT,IFNULL(CAST(storage.STORAGECOUNT AS SIGNED), 0) as STORAGECOUNT,IFNULL(CAST(storage.ALL_COUNT AS SIGNED), 0) as ALL_COUNT,goods.NAME as NAME,stock.BARCODE as BARCODE,stock.SKU as SKU,stock.STYLE as STYLE,stock.COLOR as COLOR')
|
||
->alias('stock')
|
||
->join('yj_warestore warestore','warestore.ID=stock.WARESTOREID')
|
||
->join("(SELECT STOCKID, SUM(COUNT) as COUNT FROM `yj_putoutstorage` where `CREATIONDATE` BETWEEN '00{$day[0]}' AND '00{$day[1]}' GROUP BY STOCKID ) as putoutstorage",'putoutstorage.STOCKID=stock.STOCKID','left')
|
||
->join("(SELECT STOCKID, SUM(COUNT) as COUNT FROM `yj_putinstorage` where `CREATIONDATE` BETWEEN '00{$day[0]}' AND '00{$day[1]}' GROUP BY STOCKID ) as putinstorage",'putinstorage.STOCKID=stock.STOCKID','left')
|
||
->join('(SELECT yj_storage.STOCKID as STOCKID, sum(copycount) as STORAGECOUNT,sum(COUNT) as ALL_COUNT FROM `yj_storage` GROUP BY yj_storage.STOCKID) as storage','storage.STOCKID=stock.STOCKID','left')
|
||
->join('yj_goods goods','goods.GOODSID=stock.GOODSID')
|
||
->where(["warestore.STOREID"=>$STOREID])
|
||
->group("stock.STOCKID")
|
||
->order('STOCKID','desc')
|
||
->select();
|
||
array_push($arr,["date"=>$day[0],"datas"=>$STOCKS_DATA]);
|
||
}
|
||
$skus = [];
|
||
foreach ($arr[0]['datas'] as $r){
|
||
$skus[$r['STOCKID']] = ['date_data'=>[],'info_data'=>['NAME'=>"",'BARCODE'=>"",'SKU'=>"",'STORAGECOUNT'=>0,'RKCOUNT'=>0,'CKCOUNT'=>0]];
|
||
}
|
||
foreach ($skus as $k =>$r){
|
||
foreach ($arr as $rr){
|
||
foreach ($rr['datas'] as $rrr){
|
||
if($k==$rrr['STOCKID']){
|
||
array_push($skus[$k]['date_data'],[$rrr['RKCOUNT'],$rrr['CKCOUNT']]);
|
||
$skus[$k]['info_data']['NAME'] = $rrr['NAME'];
|
||
$skus[$k]['info_data']['BARCODE'] = "'".$rrr['BARCODE'];
|
||
$skus[$k]['info_data']['SKU'] = "'".$rrr['SKU'];
|
||
$skus[$k]['info_data']['STORAGECOUNT'] = $rrr['STORAGECOUNT'];
|
||
$skus[$k]['info_data']['ALL_COUNT'] = $rrr['ALL_COUNT'];
|
||
$skus[$k]['info_data']['RKCOUNT'] += $rrr['RKCOUNT'];
|
||
$skus[$k]['info_data']['CKCOUNT'] += $rrr['CKCOUNT'];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
$input_data = [];
|
||
foreach ($skus as $r){
|
||
|
||
$tmp_data = [$r['info_data']['NAME'],$r['info_data']['BARCODE'],$r['info_data']['SKU']];
|
||
foreach ($r['date_data'] as $rr){
|
||
array_push($tmp_data,$rr[1]);
|
||
array_push($tmp_data,$rr[0]);
|
||
}
|
||
$yujingCount = intval($r['info_data']['CKCOUNT']/7*4);
|
||
$caigouCount = intval($r['info_data']['CKCOUNT']/7*10);
|
||
$isyj = ($yujingCount-$r['info_data']['STORAGECOUNT'])>0;
|
||
if(!$isyj && $r['info_data']['STORAGECOUNT']<20 && $r['info_data']['RKCOUNT']<20){
|
||
$isyj = true;
|
||
$caigouCount = $caigouCount>30?$caigouCount:30;
|
||
}
|
||
if($caigouCount>0 || $isyj){
|
||
array_push($tmp_data,$r['info_data']['ALL_COUNT']-$r['info_data']['STORAGECOUNT']);
|
||
array_push($tmp_data,$r['info_data']['STORAGECOUNT']);
|
||
array_push($tmp_data,$r['info_data']['CKCOUNT']);
|
||
array_push($tmp_data,$caigouCount>0?$caigouCount:"-");
|
||
array_push($tmp_data,$isyj?'是':'否');
|
||
array_push($input_data,$tmp_data);
|
||
}
|
||
}
|
||
foreach ($input_data as $k => $r){
|
||
foreach ($r as $kk=> $rr){
|
||
if($rr<1&& $kk<20&&$kk>2){
|
||
$input_data[$k][$kk] = "-";
|
||
}
|
||
}
|
||
}
|
||
$res = $this->putinputoutFile($input_data,$weekEnd);
|
||
return $res;
|
||
}
|
||
private function putinputoutFile($data,$week){
|
||
$rootpath = dirname(__DIR__);
|
||
$spreadsheet = new Spreadsheet();
|
||
$worksheet = $spreadsheet->getActiveSheet();
|
||
$title = '7日出入库数据';
|
||
$worksheet->setTitle($title);
|
||
$worksheet->mergeCells('A1:A2');
|
||
$worksheet->mergeCells('B1:B2');
|
||
$worksheet->mergeCells('C1:C2');
|
||
$worksheet->mergeCells('R1:R2');
|
||
$worksheet->mergeCells('S1:S2');
|
||
$worksheet->mergeCells('T1:T2');
|
||
$worksheet->mergeCells('U1:U2');
|
||
$worksheet->mergeCells('V1:V2');
|
||
$worksheet->setCellValue('A1', '产品名称');
|
||
$worksheet->setCellValue('B1', '条码');
|
||
$worksheet->setCellValue('C1', '外部编码');
|
||
$worksheet->setCellValue('R1', '待处理订单占用数');
|
||
$worksheet->setCellValue('S1', '可用库存');
|
||
$worksheet->setCellValue('T1', '7日总出库数量');
|
||
$worksheet->setCellValue('U1', '推荐采购量');
|
||
$worksheet->setCellValue('V1', '是否触发预警');
|
||
$lists = ['出库数','入库数','出库数','入库数','出库数','入库数','出库数','入库数','出库数','入库数','出库数','入库数','出库数','入库数'];
|
||
$worksheet->fromArray($lists, '', 'D2' );
|
||
$worksheet->getStyle("A1:A2")->getAlignment()
|
||
->setHorizontal(Alignment::HORIZONTAL_CENTER)
|
||
->setVertical(Alignment::VERTICAL_CENTER);
|
||
$worksheet->getStyle("B1:B2")->getAlignment()
|
||
->setHorizontal(Alignment::HORIZONTAL_CENTER)
|
||
->setVertical(Alignment::VERTICAL_CENTER);
|
||
$worksheet->getStyle("C1:C2")->getAlignment()
|
||
->setHorizontal(Alignment::HORIZONTAL_CENTER)
|
||
->setVertical(Alignment::VERTICAL_CENTER);
|
||
$worksheet->getStyle("R1:R2")->getAlignment()
|
||
->setHorizontal(Alignment::HORIZONTAL_CENTER)
|
||
->setVertical(Alignment::VERTICAL_CENTER);
|
||
$worksheet->getStyle("S1:S2")->getAlignment()
|
||
->setHorizontal(Alignment::HORIZONTAL_CENTER)
|
||
->setVertical(Alignment::VERTICAL_CENTER);
|
||
$worksheet->getStyle("T1:T2")->getAlignment()
|
||
->setHorizontal(Alignment::HORIZONTAL_CENTER)
|
||
->setVertical(Alignment::VERTICAL_CENTER);
|
||
$worksheet->getStyle("U1:U2")->getAlignment()
|
||
->setHorizontal(Alignment::HORIZONTAL_CENTER)
|
||
->setVertical(Alignment::VERTICAL_CENTER);
|
||
$worksheet->getStyle("v1:v2")->getAlignment()
|
||
->setHorizontal(Alignment::HORIZONTAL_CENTER)
|
||
->setVertical(Alignment::VERTICAL_CENTER);
|
||
$charArr = ["D","E","F","G","H","I","J","K","L","M","N","O","P","Q"];
|
||
foreach ($charArr as $r){
|
||
$worksheet->getStyle("{$r}2")->getAlignment()
|
||
->setHorizontal(Alignment::HORIZONTAL_CENTER)
|
||
->setVertical(Alignment::VERTICAL_CENTER);
|
||
}
|
||
foreach ($week as $index => $r){
|
||
$start_index = $index*2;
|
||
$end_index = $index*2+1;
|
||
$worksheet->mergeCells("{$charArr[$start_index]}1:{$charArr[$end_index]}1");
|
||
$date = date('Y/n/j', $r[0]/1000);
|
||
$worksheet->setCellValue("{$charArr[$start_index]}1",$date);
|
||
$worksheet->getStyle("{$charArr[$start_index]}1:{$charArr[$end_index]}1")->getAlignment()
|
||
->setHorizontal(Alignment::HORIZONTAL_CENTER)
|
||
->setVertical(Alignment::VERTICAL_CENTER);
|
||
}
|
||
$worksheet->fromArray($data, '', 'A3' );
|
||
// 获取当前时间的秒数和微秒数
|
||
list($usec, $sec) = explode(" ", microtime());
|
||
// 将秒数转换为毫秒并拼接微秒数
|
||
$millisecondTimestamp = (int)($sec * 1000) + (int)($usec * 1000);
|
||
|
||
$filePath = "{$rootpath}/../../../public/putinputout/{$millisecondTimestamp}.xlsx";
|
||
$url = "https://ye4s.wms.gztbyc.com/putinputout/{$millisecondTimestamp}.xlsx";
|
||
$write = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||
$res = $write->save($filePath);
|
||
return $url;
|
||
}
|
||
private function day7(){
|
||
$seven_am_timestamp = strtotime('tomorrow 7:00')*1000-1;
|
||
$arr = [[$seven_am_timestamp-(24*60*60*1000)+1,$seven_am_timestamp]];
|
||
for($i = 0;$i<6;$i++){
|
||
$seven_am_timestamp -= 24*60*60*1000;
|
||
array_unshift($arr,[$seven_am_timestamp-(24*60*60*1000)+1,$seven_am_timestamp]);
|
||
}
|
||
return $arr;
|
||
}
|
||
|
||
|
||
public function autoNoErpOrder(){
|
||
$StorageModel = new \app\common\model\wms\Storage;
|
||
$WAREHOUSEMODEL = new \app\common\model\Warehouse;
|
||
$WAREHOUSES = $WAREHOUSEMODEL->field('noerporder,WAREHOUSEID')->select();
|
||
$datas = [];
|
||
$RoomsModel = new \app\common\model\Rooms;
|
||
$endtime = strtotime(date('Y-m-d'))-1;
|
||
$starttime = $endtime - 24*60*60+1;
|
||
$startTime_text = date('Y-m-d H:i:s',$starttime);
|
||
$endtime_text = date('Y-m-d H:i:s',$endtime);
|
||
$datas = [];
|
||
foreach ($WAREHOUSES as $WAREHOUSE){
|
||
$STOREIDS2 = explode(",",$WAREHOUSE["noerporder"]);
|
||
$STOREIDS2 = array_filter($STOREIDS2);
|
||
foreach ($STOREIDS2 as $STOREID){
|
||
$data = $this->getWmsDeliveryorderByStoreDate($WAREHOUSE['WAREHOUSEID'],$STOREID,["00{$starttime}000","00{$endtime}999"],[565788]);
|
||
$fileUrl = $this->WmsDeliveryorderByStoreDateFile($data);
|
||
if($fileUrl){
|
||
$STR="{$startTime_text}-{$endtime_text}非ERP订单发货数据已发送,请注意查收";
|
||
$room = $RoomsModel->where(["STOREID"=>$STOREID,"isStorge"=>1])->find();
|
||
if(!$room){
|
||
$room = $RoomsModel->where(["STOREID"=>$STOREID,"isNoErpOrder"=>1])->find();
|
||
}
|
||
if(!$room){
|
||
$room = $RoomsModel->where(["STOREID"=>$STOREID])->find();
|
||
}
|
||
array_push($datas,$room);
|
||
if($room){
|
||
[$aiteUser,$atids] = $this->getAUser($room["room_id"],"运营");
|
||
if($atids){
|
||
$STR.=$aiteUser;
|
||
$msg = $this->toMsg($room["room_id"],$STR,$atids);
|
||
}else{
|
||
$msg = $this->toMsg($room["room_id"],$STR);
|
||
}
|
||
$msg2 = $this->backFile(["fromid"=>$room["room_id"]],$fileUrl);
|
||
}
|
||
$this->redis->lpush("Message",json_encode($msg2));
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
array_push($datas,$STR);
|
||
}
|
||
array_push($datas,$fileUrl);
|
||
}
|
||
}
|
||
return json([$starttime,$endtime,$datas]);
|
||
}
|
||
private function getWmsDeliveryorderByStoreDate($WAREHOUSEID,$storeid,$date,$qimenskus){
|
||
$orderModel = new \app\common\model\wms\Deliveryorder;
|
||
$orders = $orderModel->field("ID,SOURCECODE,SOURCEID,SOURCEORDERCODE,STORENAME,WEIGHT,POSTNAME,NAME,TEL,ADDRESS,PROVINCE,CITYNAME,EXPAREANAME,POSTNUM,CREATIONDATE,SENDDATE,ITEMS")->where(["WAREHOUSEID"=>$WAREHOUSEID,"STATUS"=>1,"DISPLAYFLAG"=>0,"STOREID"=>$storeid])->where("SENDDATE","BETWEEN",$date)->where("SOURCECODE","in",["Z15","Z16","Z01"])->select();
|
||
if(count($qimenskus)>0){
|
||
$orders2 = $orderModel->field("ID,SOURCECODE,SOURCEID,SOURCEORDERCODE,STORENAME,WEIGHT,POSTNAME,NAME,TEL,ADDRESS,PROVINCE,CITYNAME,EXPAREANAME,POSTNUM,CREATIONDATE,SENDDATE,ITEMS")->where(["WAREHOUSEID"=>$WAREHOUSEID,"STATUS"=>1,"DISPLAYFLAG"=>0,"STOREID"=>$storeid])->where("SENDDATE","BETWEEN",$date)->where("SOURCECODE","in",["Z05"]);
|
||
$qimenwhere = [];
|
||
foreach ($qimenskus as $qimensku){
|
||
array_push($qimenwhere,"ITEMS like '%{$qimensku}%'");
|
||
}
|
||
$qimenwhereStr = implode(" or ",$qimenwhere);
|
||
$orders2 = $orders2->where($qimenwhereStr)->select();
|
||
}
|
||
$orders = array_merge($orders,$orders2);
|
||
$SOURCECODES = [
|
||
"Z15"=>"店管家",
|
||
"Z16"=>"群采集",
|
||
"Z01"=>"手工单",
|
||
"Z05"=>"奇门"
|
||
];
|
||
$orders_temps = [];
|
||
$data1 = [['来源','外部订单编号','平台单号',
|
||
'店铺名称','快递','收件人',
|
||
'电话','地址','省','市','县','快递号','创建时间',
|
||
'发货时间','SKUID','商品名称','条码','数量']];
|
||
$data2 = [['skuid','商品名称','条码','数量','订单数']];
|
||
foreach ($orders as $order){
|
||
$ITEMS = explode("|",$order['ITEMS']);
|
||
$ITEMS = array_filter($ITEMS);
|
||
foreach ($ITEMS as $ITEM){
|
||
$item = explode(",",$ITEM);
|
||
$tmp_order = json_decode(json_encode($order),true);
|
||
unset($tmp_order['ITEMS']);
|
||
$tmp_order['STOCKID'] = $item[0];
|
||
$tmp_order['COUNT'] = $item[1];
|
||
$tmp_order['STOCKNAME'] = $item[2];
|
||
$tmp_order['BARCODE'] = $item[3];
|
||
array_push($data1,[
|
||
$SOURCECODES[($tmp_order['SOURCECODE'] ?? null)],
|
||
"'".($tmp_order['SOURCEID'] ?? null),
|
||
"'".($tmp_order['SOURCEORDERCODE'] ?? null),
|
||
"'".($tmp_order['STORENAME'] ?? null),
|
||
($tmp_order['POSTNAME'] ?? null),
|
||
($tmp_order['NAME'] ?? null),
|
||
"'".($tmp_order['TEL'] ?? null),
|
||
($tmp_order['ADDRESS'] ?? null),
|
||
($tmp_order['PROVINCE'] ?? null),
|
||
($tmp_order['CITYNAME'] ?? null),
|
||
($tmp_order['EXPAREANAME'] ?? null),
|
||
($tmp_order['POSTNUM'] ?? null),
|
||
date('Y-m-d H:i:s',($tmp_order['CREATIONDATE'] ?? null)/1000),
|
||
date('Y-m-d H:i:s',($tmp_order['SENDDATE'] ?? null)/1000),
|
||
($tmp_order['STOCKID'] ?? null),
|
||
($tmp_order['STOCKNAME'] ?? null),
|
||
"'".($tmp_order['BARCODE'] ?? null),
|
||
($tmp_order['COUNT'] ?? null),
|
||
]);
|
||
$has = false;
|
||
$index = -1;
|
||
foreach($data2 as $k => $r){
|
||
if($k>0 && $r[0]==($tmp_order['STOCKID'] ?? null)){
|
||
$has = true;
|
||
$index = $k;
|
||
}
|
||
}
|
||
if($has){
|
||
$data2[$index][3] += intval(($tmp_order['COUNT'] ?? null));
|
||
$data2[$index][4] += 1;
|
||
}else{
|
||
array_push($data2,[($tmp_order['STOCKID'] ?? null),($tmp_order['STOCKNAME'] ?? null),"'".($tmp_order['BARCODE'] ?? null),($tmp_order['COUNT'] ?? null),1]);
|
||
}
|
||
}
|
||
}
|
||
return [$data1,$data2];
|
||
}
|
||
private function WmsDeliveryorderByStoreDateFile($data){
|
||
$rootpath = dirname(__DIR__);
|
||
$spreadsheet = new Spreadsheet();
|
||
$worksheet = $spreadsheet->getActiveSheet();
|
||
$title = '配送列表';
|
||
$worksheet->setTitle($title);
|
||
$worksheet->fromArray($data[0], '', 'A1' );
|
||
// 创建第二个工作表(汇总)
|
||
$worksheet2 = $spreadsheet->createSheet();
|
||
$worksheet2->setTitle('汇总');
|
||
$worksheet2->fromArray($data[1], '', 'A1');
|
||
// 获取当前时间的秒数和微秒数
|
||
list($usec, $sec) = explode(" ", microtime());
|
||
// 将秒数转换为毫秒并拼接微秒数
|
||
$millisecondTimestamp = (int)($sec * 1000) + (int)($usec * 1000);
|
||
|
||
$filePath = "{$rootpath}/../../../public/putinputout/{$millisecondTimestamp}.xlsx";
|
||
$url = "https://ye4s.wms.gztbyc.com/putinputout/{$millisecondTimestamp}.xlsx";
|
||
$write = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||
$res = $write->save($filePath);
|
||
return $url;
|
||
}
|
||
public function excelFileSave($data){
|
||
$rootpath = dirname(__DIR__);
|
||
$spreadsheet = new Spreadsheet();
|
||
$worksheet = $spreadsheet->getActiveSheet();
|
||
$title = $data[0]['title'];
|
||
$worksheet->setTitle($title);
|
||
$worksheet->fromArray($data[0]['data'], '', 'A1' );
|
||
for($i=0;$i<count($data);$i++){
|
||
$worksheetSub = $spreadsheet->createSheet();
|
||
$worksheet2->setTitle($data[$i]['title']);
|
||
$worksheet2->fromArray($data[$i]['data'], '', 'A1');
|
||
}
|
||
// 获取当前时间的秒数和微秒数
|
||
list($usec, $sec) = explode(" ", microtime());
|
||
// 将秒数转换为毫秒并拼接微秒数
|
||
$millisecondTimestamp = (int)($sec * 1000) + (int)($usec * 1000);
|
||
|
||
$filePath = "{$rootpath}/../../../public/putinputout/{$millisecondTimestamp}.xlsx";
|
||
$url = "https://ye4s.wms.gztbyc.com/putinputout/{$millisecondTimestamp}.xlsx";
|
||
$write = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||
$res = $write->save($filePath);
|
||
return $url;
|
||
}
|
||
public function savePickingErrAndNotic(){
|
||
$PickErrorModel = new \app\common\model\errors\Pick;
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = $params['WAREHOUSEID'];
|
||
$STOCKID = $params['STOCKID'];
|
||
$space = $params['space'];
|
||
$username = $params['username'];
|
||
$cacheKey = "ware:{$WAREHOUSEID}:stock:{$STOCKID}";
|
||
$lock = $this->redis->get($cacheKey);
|
||
if($lock){
|
||
return 1;
|
||
}
|
||
$room_id = $this->getWarePickErrorRoom($WAREHOUSEID);
|
||
$time = time();
|
||
$formattedDate = date("Y/m/d H:i:s", $time);
|
||
if($room_id){
|
||
$stock = $this->getStockCache($WAREHOUSEID,$STOCKID);
|
||
if($stock){
|
||
$STR = "时间:{$formattedDate}\nsku:{$stock['STOCKID']}\n名称:{$stock['NAME']}\n条码:{$stock['BARCODE']}\n颜色:{$stock['COLOR']}\n规格:{$stock['STYLE']}\n货主:{$stock['STORENAME']}\n库位:{$space}\n________________\n不在库位预警";
|
||
$msg = $this->toMsg($room_id,$STR);
|
||
$PickErrorModel->save([
|
||
"time"=>$time,
|
||
"username"=>$username,
|
||
"STOCKID"=>$stock['STOCKID'],
|
||
"COLOR"=>$stock['COLOR'],
|
||
"STYLE"=>$stock['STYLE'],
|
||
"BARCODE"=>$stock['BARCODE'],
|
||
"NAME"=>$stock['NAME'],
|
||
"space"=>$space,
|
||
"STORENAME"=>$stock['STORENAME'],
|
||
"WAREHOUSEID"=>$WAREHOUSEID
|
||
]);
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
$this->redis->set($cacheKey,1, 3600);//一个小时过期
|
||
return 1;
|
||
}else{
|
||
return 0;
|
||
}
|
||
}else{
|
||
return 0;
|
||
}
|
||
|
||
}
|
||
private function getWarePickErrorRoom($WAREHOUSEID){
|
||
$cacheKey = "ware:{$WAREHOUSEID}:PickErrorRoom";
|
||
|
||
// 尝试从缓存获取
|
||
$roomId = $this->redis->get($cacheKey);
|
||
|
||
// 如果缓存中有有效值,直接返回
|
||
if ($roomId && $roomId !== "none") {
|
||
return $roomId;
|
||
}
|
||
|
||
// 如果缓存中明确标记为"none",直接返回null
|
||
if ($roomId === "none") {
|
||
return null;
|
||
}
|
||
|
||
// 缓存中没有数据,从数据库查询
|
||
$warehouseModel = new \app\common\model\Warehouse;
|
||
$ware = $warehouseModel->field("room_pick_error")
|
||
->where(["WAREHOUSEID" => $WAREHOUSEID])
|
||
->find();
|
||
|
||
if ($ware && !empty($ware['room_pick_error'])) {
|
||
$roomId = $ware['room_pick_error'];
|
||
// 设置缓存,可以添加过期时间避免永久缓存
|
||
$this->redis->set($cacheKey, $roomId, 3600); // 1小时过期
|
||
} else {
|
||
// 设置特殊标记并设置较短的过期时间
|
||
$this->redis->set($cacheKey, "none", 300); // 5分钟过期
|
||
$roomId = null;
|
||
}
|
||
|
||
return $roomId;
|
||
}
|
||
public function getStockCacheTest(){
|
||
$data = $this->getStockCache(5400,359241);
|
||
return json($data);
|
||
}
|
||
private function getStockCache($WAREHOUSEID,$STOCKID){
|
||
$cacheKey = "ware:{$WAREHOUSEID}_stock:{$STOCKID}";
|
||
|
||
// 尝试从缓存获取
|
||
$stock = $this->redis->get($cacheKey);
|
||
|
||
// 如果缓存中有有效值,直接返回
|
||
if ($stock && $stock !== "none") {
|
||
return json_decode($stock,true);
|
||
}
|
||
|
||
// 如果缓存中明确标记为"none",直接返回null
|
||
if ($stock === "none") {
|
||
return null;
|
||
}
|
||
|
||
// 缓存中没有数据,从数据库查询
|
||
$StockModel = new \app\common\model\wms\Stock;
|
||
$STOCKS_DATA = $StockModel
|
||
->field('warestore.STOREID as STOREID,store.TITLE as STORENAME,stock.STOCKID as STOCKID,stock.COLOR as COLOR,stock.STYLE as STYLE,goods.NAME as NAME,stock.BARCODE as BARCODE,stock.SKU as SKU,stock.STYLE as STYLE,stock.COLOR as COLOR')
|
||
->alias('stock')
|
||
->join('yj_warestore warestore','warestore.ID=stock.WARESTOREID')
|
||
->join('yj_store store','warestore.STOREID=store.STOREID')
|
||
->join('yj_goods goods','goods.GOODSID=stock.GOODSID')
|
||
->where(["stock.STOCKID"=>$STOCKID])
|
||
->find();
|
||
|
||
if ($STOCKS_DATA) {
|
||
$stock = $STOCKS_DATA;
|
||
// 设置缓存,可以添加过期时间避免永久缓存
|
||
$this->redis->set($cacheKey, json_encode($stock), 7200); // 2小时过期
|
||
} else {
|
||
// 设置特殊标记并设置较短的过期时间
|
||
$this->redis->set($cacheKey, "none", 300); // 5分钟过期
|
||
$stock = null;
|
||
}
|
||
return $stock;
|
||
}
|
||
public function NoticPickError(){
|
||
$WAREHOUSEMODEL = new \app\common\model\Warehouse;
|
||
$WAREHOUSES = $WAREHOUSEMODEL->field('room_pick_error,WAREHOUSEID')->where("room_pick_error isnot null")->select();
|
||
$datas = [];
|
||
$endtime = strtotime(date('Y-m-d')."06:59:59");
|
||
$starttime = $endtime - 24*60*60+1;
|
||
$startTime_text = date('Y-m-d H:i:s',$starttime);
|
||
$endtime_text = date('Y-m-d H:i:s',$endtime);
|
||
foreach ($WAREHOUSES as $WAREHOUSE){
|
||
$room_id = $WAREHOUSE["room_pick_error"];
|
||
$WAREHOUSEID = $WAREHOUSE["WAREHOUSEID"];
|
||
$data = $this->getPickErrorData($WAREHOUSEID,$starttime,$endtime);
|
||
$msg = $this->toMsg($room["room_id"],$STR,$atids);
|
||
$msg2 = $this->backFile(["fromid"=>$room["room_id"]],$fileUrl);
|
||
$this->redis->lpush("Message",json_encode($msg2));
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
array_push($datas,$data);
|
||
}
|
||
return json([$starttime,$endtime,$datas]);
|
||
}
|
||
public function getPickErrorData($WAREHOUSEID,$starttime,$endtime){
|
||
$PickErrorModel = new \app\common\model\errors\Pick;
|
||
$data_query = $PickErrorModel->where("time","BETWEEN",[$starttime,$endtime])->select();
|
||
$datas = ["title"=>'明细',"data"=>[['序号','触发时间','货主','SKUID','名字','颜色','规格','条码','库位']]];
|
||
$count = count($datas);//总行数
|
||
$count2 = 0;//总SKU数
|
||
if($data_query){
|
||
$skus = [];
|
||
foreach ($data_query as $row){
|
||
array_push($skus,$row['STOCKID']);
|
||
}
|
||
$skus = array_keys(array_flip($skus));
|
||
$count2 = count($skus);
|
||
}
|
||
return $datas;
|
||
}
|
||
private function getMidnightTimestamp($timestamp = null) {
|
||
if ($timestamp === null) {
|
||
$timestamp = time();
|
||
}
|
||
|
||
$date = new \DateTime();
|
||
$date->setTimestamp($timestamp);
|
||
$date->setTime(0, 0, 0);
|
||
|
||
return $date->getTimestamp();
|
||
}
|
||
public function autoReRecord(){
|
||
$WAREHOUSEMODEL = new \app\common\model\Warehouse;
|
||
$method_name = "\\app\\common\\model\\file\\".ucfirst("dabao");
|
||
$mode = new $method_name();
|
||
$Worksmodel = new \app\common\model\workers\Works;
|
||
$WAREHOUSES = $WAREHOUSEMODEL->field('auto_re_record,WAREHOUSEID')->where("auto_re_record=1")->select();
|
||
$datas = [];
|
||
$endtime = strtotime(date('Y-m-d')."03:59:59");
|
||
$starttime = $endtime - 24*60*60+1;
|
||
$startTime_text = date('Y-m-d H:i:s',$starttime);
|
||
$endtime_text = date('Y-m-d H:i:s',$endtime);
|
||
$lastDate = $this->getMidnightTimestamp($starttime);
|
||
$works = [];
|
||
$this->express_redis->select(3);
|
||
foreach ($WAREHOUSES as $WAREHOUSE){
|
||
$WAREHOUSEID = $WAREHOUSE["WAREHOUSEID"];
|
||
$dabaos = $Worksmodel->where(["types"=>3,"workDate"=>$lastDate,"WAREHOUSEID"=>$WAREHOUSEID])->select();
|
||
$postnums = [];
|
||
foreach ($dabaos as $r){
|
||
array_push($postnums,$r['POSTNUM']);
|
||
}
|
||
$names = $mode->where("name","in",$postnums)->select();
|
||
$name_arr = [];
|
||
foreach ($names as $name){
|
||
array_push($name_arr,$name['name']);
|
||
}
|
||
foreach ($dabaos as $r){
|
||
$has = in_array($r['POSTNUM'], $name_arr) ? true : false;
|
||
if(!$has){
|
||
array_push($works,[$r['id'],0]);
|
||
$this->express_redis->lpush("ware:{$WAREHOUSEID}:reRecord",json_encode([$r['id'],0]));
|
||
}
|
||
}
|
||
//团购
|
||
$dabaos = $Worksmodel->where(["workDate"=>$lastDate,"WAREHOUSEID"=>$WAREHOUSEID])->where("dabaos>1")->select();
|
||
$postnums = [];
|
||
foreach ($dabaos as $r){
|
||
array_push($postnums,$r['grabnum']);
|
||
}
|
||
$names = $mode->where("name","in",$postnums)->select();
|
||
$name_arr = [];
|
||
foreach ($names as $name){
|
||
array_push($name_arr,$name['name']);
|
||
}
|
||
foreach ($dabaos as $r){
|
||
$has = in_array($r['grabnum'], $name_arr) ? true : false;
|
||
if(!$has){
|
||
array_push($works,[$r['id'],0]);
|
||
$this->express_redis->lpush("ware:{$WAREHOUSEID}:reRecord",json_encode([$r['id'],0]));
|
||
}
|
||
}
|
||
}
|
||
return json($works);
|
||
}
|
||
public function checkLogin(){
|
||
$url = "https://erp.yto.net.cn/erp/erpbasic/basic/express/getTrack";
|
||
$body = '{"logInId":"6f8891c4a83248a2b5be6693585b8f9e","groupId":2885,"waybillNo":"320744846079248"}';
|
||
|
||
$options = [
|
||
CURLOPT_HTTPHEADER => [
|
||
'Content-Type: application/json',
|
||
'jwt-token:BearererpeyJhbGciOiJIUzUxMiJ9.eyJjb21wYW55X2lkIjoyODg1LCJzdGFmZl9pZCI6IjZmODg5MWM0YTgzMjQ4YTJiNWJlNjY5MzU4NWI4ZjllIiwiaXNzIjoiWVRPLUtIR0oiLCJleHAiOjE3NjA0MzI4NzgsImlhdCI6MTc1OTgyODA3ODE0OX0.pC-RNAsIq3jZlo-CG1XwpG-IChlisT20I_5c05wBJIhRVOW2Pzn8DU0W7A2cSTMvOxeIekr2kL7ww8bdm_twKg',
|
||
'groupid:2885',
|
||
'host:erp.yto.net.cn',
|
||
'user-agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36',
|
||
'source:YTO-STEWARD',
|
||
'Cookie:userInfo={%22id%22:%226f8891c4a83248a2b5be6693585b8f9e%22%2C%22groupId%22:2885%2C%22username%22:%22%E5%88%98%E5%85%88%E7%94%9F%22%2C%22mobile%22:%2218022440198%22%2C%22superAccount%22:false%2C%22staffName%22:%22%E5%88%98%E5%85%88%E7%94%9F%22%2C%22companyName%22:%22%E5%90%B4%E5%93%A5%22}; stewoard-token=BearererpeyJhbGciOiJIUzUxMiJ9.eyJjb21wYW55X2lkIjoyODg1LCJzdGFmZl9pZCI6IjZmODg5MWM0YTgzMjQ4YTJiNWJlNjY5MzU4NWI4ZjllIiwiaXNzIjoiWVRPLUtIR0oiLCJleHAiOjE3NjA0MzI4NzgsImlhdCI6MTc1OTgyODA3ODE0OX0.pC-RNAsIq3jZlo-CG1XwpG-IChlisT20I_5c05wBJIhRVOW2Pzn8DU0W7A2cSTMvOxeIekr2kL7ww8bdm_twKg; username=%E5%88%98%E5%85%88%E7%94%9F; encryptMobile=undefined',
|
||
|
||
'Content-Length: ' . strlen($body)
|
||
]
|
||
];
|
||
$req = Http::sendRequest($url, $body, 'POST', $options);
|
||
$data = json_decode($req['msg'],true);
|
||
if(($data['status'] ?? null)!=200){
|
||
|
||
$this->Webhook_lib->sendText("圆通ERP,已掉线");
|
||
}
|
||
return json($data);
|
||
}
|
||
|
||
|
||
|
||
public function errorPick($WAREHOUSEID=5400){
|
||
$errorsPickModel = new \app\common\model\errors\Pick;
|
||
$today6am = strtotime('today 06:00:00');
|
||
$yesterday6am = strtotime('yesterday 06:00:00');
|
||
|
||
|
||
$WarehouseModel = new \app\common\model\Warehouse;
|
||
$WAREHOUSE = $WarehouseModel->field('room_pick_error')->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
||
$room_id = $WAREHOUSE['room_pick_error']??null;
|
||
if(!$room_id){
|
||
return false;
|
||
}
|
||
// 查询模型
|
||
$errors = $errorsPickModel
|
||
->where(["WAREHOUSEID"=>$WAREHOUSEID])
|
||
->where('time', 'BETWEEN', [$yesterday6am, $today6am])
|
||
->select();
|
||
$spreadsheet = new Spreadsheet();
|
||
$worksheet = $spreadsheet->getActiveSheet();
|
||
$title = '查询库位明细';
|
||
$worksheet->setTitle($title);
|
||
$worksheet->fromArray(
|
||
[
|
||
["SKU",
|
||
"颜色",
|
||
"规格",
|
||
"商品名称",
|
||
"货主",
|
||
"时间",
|
||
"条码",
|
||
"库位"]
|
||
], '', 'A1' );
|
||
$lists = [];
|
||
foreach ($errors as $r){
|
||
array_push($lists,[$r["STOCKID"],$r["COLOR"],$r["STYLE"],$r["NAME"],$r["STORENAME"],$r["time_text"],$r["BARCODE"],$r["space"]]);
|
||
}
|
||
$line_count = count($lists);
|
||
$worksheet->fromArray($lists, '', 'A2' );
|
||
// 获取当前时间的秒数和微秒数
|
||
list($usec, $sec) = explode(" ", microtime());
|
||
// 将秒数转换为毫秒并拼接微秒数
|
||
$millisecondTimestamp = (int)($sec * 1000) + (int)($usec * 1000);
|
||
$rootpath = dirname(__DIR__);
|
||
$filePath = "{$rootpath}/../../../public/errorPick/{$millisecondTimestamp}.xlsx";
|
||
$url = "https://ye4s.wms.gztbyc.com/errorPick/{$millisecondTimestamp}.xlsx";
|
||
$write = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||
$res = $write->save($filePath);
|
||
$msg = $this->backFile(["fromid"=>$room_id],$url);
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
$msg2 = $this->toMsg($room_id,date('Y/m/d')." 昨日拣货中查询情况,文件名为{$millisecondTimestamp}.xlsx,总计行数{$line_count}。");
|
||
$this->redis->lpush("Message",json_encode($msg2));
|
||
return json($errors);
|
||
}
|
||
private function arrayToXml($data, $parentKey = '')
|
||
{
|
||
$xml = '';
|
||
foreach ($data as $key => $value) {
|
||
if (is_numeric($key)) {
|
||
$key = $parentKey ? $parentKey . '_item' : 'item';
|
||
}
|
||
|
||
if (is_array($value)) {
|
||
$xml .= "<{$key}>\n";
|
||
$xml .= $this->arrayToXml($value, $key);
|
||
$xml .= "</{$key}>\n";
|
||
} else {
|
||
$xml .= "<{$key}>" . htmlspecialchars($value) . "</{$key}>\n";
|
||
}
|
||
}
|
||
return $xml;
|
||
}
|
||
public function test2(){
|
||
$redis = new \Redis();
|
||
try {
|
||
$redis->connect('127.0.0.1', 6379);
|
||
// 如果有密码认证
|
||
$redis->auth('qwe2019@');
|
||
$redis->select(15);
|
||
// 指定要查找的键和目标字符串
|
||
$key = 'GalaxyReceive_5400_back';
|
||
$targetString = '773385681859002';
|
||
|
||
// 获取列表所有元素
|
||
$listElements = $redis->lRange($key, 0, -1);
|
||
$outText = "";
|
||
if ($listElements === false) {
|
||
echo "错误:键 '{$key}' 不存在或不是列表类型。";
|
||
} else {
|
||
// 检查列表是否包含目标字符串
|
||
echo "揽收记录数量:".count($listElements);
|
||
foreach ($listElements as $r){
|
||
if(strpos($r,$targetString)!==false){
|
||
$outText = $r;
|
||
}
|
||
}
|
||
echo "揽收记录:773385681859002".($outText?'找到':'未找到');
|
||
}
|
||
|
||
} catch (RedisException $e) {
|
||
echo "Redis连接错误: " . $e->getMessage();
|
||
} finally {
|
||
// 关闭连接
|
||
if ($redis) {
|
||
$redis->close();
|
||
}
|
||
}
|
||
}
|
||
public function updateStock2(){
|
||
$stockModel = new \app\common\model\wms\Stock;
|
||
$StockImgsModel = new \app\common\model\wms\StockImgs;
|
||
$StockBoxsModel = new \app\common\model\wms\StockBoxs;
|
||
|
||
$defaultBox = [
|
||
"large"=>[
|
||
"count"=>0,
|
||
"length"=>0,
|
||
"width"=>0,
|
||
"height"=>0
|
||
],
|
||
"medium"=>[
|
||
"count"=>0,
|
||
"length"=>0,
|
||
"width"=>0,
|
||
"height"=>0
|
||
],
|
||
];
|
||
$result = ["msg"=>""];
|
||
|
||
$params=$this->request->post();
|
||
$WAREHOUSEID = isset($params['WAREHOUSEID'])?$params['WAREHOUSEID']:0;
|
||
$formData = isset($params['formData'])?$params['formData']:[];
|
||
$imgs = isset($params["imgs"])?$params["imgs"]:[];
|
||
$boxs = isset($params['formData']["boxs"])?$params['formData']["boxs"]:$defaultBox;
|
||
$data = $stockModel ->where(["STOCKID"=>intval($formData['STOCKID'])])->find();
|
||
if($data){
|
||
$YXQ = isset($formData['YXQ'])?$formData['YXQ']:$data['YXQ'];
|
||
$imgs = array_values(array_unique(array_filter($imgs)));
|
||
$imgs_tmp = [];
|
||
foreach ($imgs as $img){
|
||
if(strpos($img, 'http') === false){
|
||
array_push($imgs_tmp,"http://ye4s.file.gzxunren.com/".$img);
|
||
}else{
|
||
array_push($imgs_tmp,$img);
|
||
}
|
||
}
|
||
$StockImgsModel->where(["stock_id"=>$formData['STOCKID']])->where("url","not in",$imgs_tmp)->delete();
|
||
foreach ($imgs_tmp as $img){
|
||
$exitImg = $StockImgsModel->where(["stock_id"=>$formData['STOCKID'],"url"=>$img])->find();
|
||
if(!$exitImg){
|
||
$StockImgsModel->insert(["stock_id"=>$formData['STOCKID'],"url"=>$img]);
|
||
}
|
||
}
|
||
foreach($boxs as $key => $box){
|
||
$exitImg = $StockBoxsModel->where(["stock_id"=>$formData['STOCKID'],"type"=>$key])->find();
|
||
if(!$exitImg){
|
||
$StockBoxsModel->insert(["stock_id"=>$formData['STOCKID'],"type"=>$key,"count"=>$box["count"],"length"=>$box["length"],"width"=>$box["width"],"height"=>$box["height"]]);
|
||
}else{
|
||
$exitImg->save(["count"=>$box["count"],"length"=>$box["length"],"width"=>$box["width"],"height"=>$box["height"]]);
|
||
}
|
||
}
|
||
$data->save(["YXQ"=>$YXQ,"WEIGHT"=>$formData['WEIGHT']]);
|
||
$result["msg"] = "修改成功";
|
||
}else{
|
||
$result["msg"] = "无SKU信息";
|
||
}
|
||
return json($result);
|
||
}
|
||
public function upload_cos_params(){
|
||
$params = $this->request->post();
|
||
$cosController = new \addons\cos\controller\Index;
|
||
[$name,$type] = $this->getFileInfoFromPath($params['path']);
|
||
$upload = Config::get("upload");
|
||
$result = $cosController->paramsApi($params['md5'],$name,$type,$params['size'],$upload['chunking'],$upload['chunksize'],$upload['multipart']['costoken']);
|
||
return json(["data"=>["params"=>$result,"costoken"=>$upload['multipart']['costoken'],"type"=>$type,"name"=>$name]]);
|
||
}
|
||
|
||
public function upload_cos_notify(){
|
||
$params = $this->request->post();
|
||
$cosController = new \addons\cos\controller\Index;
|
||
$result = $cosController->noticeApi($params['size'],$params['name'],$params['md5'],$params['type'],"/".$params['url'],$params['width'],$params['height'],$params['category'],$params['costoken'],0);
|
||
return json($result);
|
||
}
|
||
private function getFileInfoFromPath($path) {
|
||
// 获取文件名
|
||
$pathInfo = pathinfo($path);
|
||
$name = $pathInfo['basename'];
|
||
|
||
// 根据扩展名推断文件类型
|
||
$extension = strtolower($pathInfo['extension'] ?? '');
|
||
|
||
$typeMap = [
|
||
'png' => 'image/png',
|
||
'jpg' => 'image/jpeg',
|
||
'jpeg' => 'image/jpeg',
|
||
'gif' => 'image/gif',
|
||
'bmp' => 'image/bmp',
|
||
'webp' => 'image/webp',
|
||
'pdf' => 'application/pdf',
|
||
'doc' => 'application/msword',
|
||
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||
'xls' => 'application/vnd.ms-excel',
|
||
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||
'txt' => 'text/plain',
|
||
'mp3' => 'audio/mpeg',
|
||
'mp4' => 'video/mp4',
|
||
'zip' => 'application/zip',
|
||
];
|
||
|
||
$type = $typeMap[$extension] ?? 'application/octet-stream';
|
||
|
||
return [
|
||
$name,
|
||
$type
|
||
];
|
||
}
|
||
public function getCencelPostnumSendToExpressRoom($WAREHOUSEID=5400){
|
||
$orderModel1 = new \app\common\model\wms\Order1;
|
||
$orderModel2 = new \app\common\model\wms\Order2;
|
||
$endtime = strtotime(date('Y-m-d')."10:59:59");
|
||
$starttime = $endtime - 24*60*60+1;
|
||
|
||
$RoomsModel = new \app\common\model\Rooms;
|
||
$orders = $orderModel1->field("POSTNUM,POSTCODE")->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("CREATIONDATE","BETWEEN",["00{$starttime}000","00{$endtime}000"])->where(["STATUS"=>5,"DISPLAYFLAG"=>0])->where("POSTNUM is not null and POSTNUM<>'' and SOURCECODE<>'Z16'")->order("POSTCODE")->select();
|
||
$orders2 = $orderModel2->field("POSTNUM,POSTCODE")->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("CREATIONDATE","BETWEEN",["00{$starttime}000","00{$endtime}000"])->where(["STATUS"=>5,"DISPLAYFLAG"=>0])->where("POSTNUM is not null and POSTNUM<>'' and SOURCECODE<>'Z16'")->order("POSTCODE")->select();
|
||
|
||
$posts = [];
|
||
foreach ($orders as $order){
|
||
if(array_key_exists($order["POSTCODE"],$posts)){
|
||
array_push($posts[$order["POSTCODE"]],$order["POSTNUM"]);
|
||
}else{
|
||
$posts[$order["POSTCODE"]] = [$order["POSTNUM"]];
|
||
}
|
||
}
|
||
foreach ($orders2 as $order){
|
||
if(array_key_exists($order["POSTCODE"],$posts)){
|
||
array_push($posts[$order["POSTCODE"]],$order["POSTNUM"]);
|
||
}else{
|
||
$posts[$order["POSTCODE"]] = [$order["POSTNUM"]];
|
||
}
|
||
}
|
||
$msgs = [];
|
||
foreach ($posts as $key=>$v){
|
||
$room = $RoomsModel->where(["POSTCODE"=>$key,"islanshow"=>0])->where("ECNOTES like '%default%'")->find();
|
||
if(!$room){
|
||
$room = $RoomsModel->where(["POSTCODE"=>$key])->where("ECNOTES like '%default%'")->find();
|
||
}
|
||
if(!$room){
|
||
$room = $RoomsModel->where(["POSTCODE"=>$key])->find();
|
||
}
|
||
if(!$room){
|
||
$room = ["room_id"=>"43668530427@chatroom"];
|
||
}
|
||
if($room){
|
||
$text = implode("\n",$v)."\n拦截";
|
||
$msg = $this->toMsg($room["room_id"],$text);
|
||
array_push($msgs,$msg);
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
}
|
||
}
|
||
return json([$posts,$msgs]);
|
||
}
|
||
public function receiving_notic($id){//通知收货完成
|
||
$data = $this->request->post();
|
||
$bussinessId = $data['id']?$data['id']:$id;
|
||
$receivingModel = new \app\common\model\wms_new\Receiving;
|
||
$receivingItemModel = new \app\common\model\wms_new\ReceivingItem;
|
||
$order = $receivingModel->where(["id"=>$id])->find();
|
||
$spreadsheet = new Spreadsheet();
|
||
$worksheet = $spreadsheet->getActiveSheet();
|
||
$deliverys = [
|
||
"truck"=>"货车",
|
||
"express"=>"快递",
|
||
"other"=>"其他"
|
||
];
|
||
if($order){
|
||
$list = $receivingItemModel->field("receiving_item.product_name as product_name,receiving_item.barcode as barcode,stock.item_code,receiving_item.actual_quantity as actual_quantity,receiving_item.box_quantity as box_quantity,receiving_item.boxes_per_pallet as boxes_per_pallet,receiving_item.created_at as created_at,employee.real_name as creator_name,stock.item_code as item_code")->alias('receiving_item')->where(["receiving_id"=>$id])->join('wms_stock_warehouse stock','stock.id = receiving_item.system_product_id','left')->join('wms_account_store_employee employee','employee.id = receiving_item.creator_id','left')->select();
|
||
$worksheet->setTitle('收货信息');
|
||
$creator = json_decode($order['creator_snapshot'],true);
|
||
$storeName = $order['store_name'];
|
||
$lists1 = [
|
||
["收货单号",$order['receiving_number']],
|
||
["货主",$order['store_name']],
|
||
["创建人",($creator['name'] ?? null)],
|
||
["运输方式",$deliverys[$order['delivery_method']]],
|
||
["车牌",$order['license_plate']],
|
||
["运单号",$order['tracking_number']],
|
||
["装卸方式",$order['loading_method']=="with_pallet"?'带托盘':'不带托盘'],
|
||
["备注",$order['remark']],
|
||
["创建时间",$order['created_at']],
|
||
["收货完成时间",$order['updated_at']]
|
||
];
|
||
$worksheet->fromArray(
|
||
$lists1, '', 'A1' );
|
||
|
||
$infosheet = new \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet($spreadsheet, "收货明细");
|
||
|
||
$infosheet->fromArray(
|
||
[
|
||
["商品名称",
|
||
"条码",
|
||
"外部编码",
|
||
"总数",
|
||
"箱数",
|
||
"托盘数",
|
||
"收货人",
|
||
"收货时间"]
|
||
], '', 'A1' );
|
||
$lists = [];
|
||
foreach ($list as $r){
|
||
array_push($lists,[$r["product_name"],$r["barcode"],$r["item_code"],$r["actual_quantity"],$r["box_quantity"],$r["boxes_per_pallet"],$r["creator_name"],$r["created_at"]]);
|
||
}
|
||
$infosheet->fromArray($lists, '', 'A2' );
|
||
$spreadsheet->addSheet($infosheet);
|
||
// 获取当前时间的秒数和微秒数
|
||
list($usec, $sec) = explode(" ", microtime());
|
||
// 将秒数转换为毫秒并拼接微秒数
|
||
$room_id = "43668530427@chatroom";
|
||
$millisecondTimestamp = (int)($sec * 1000) + (int)($usec * 1000);
|
||
$rootpath = dirname(__DIR__);
|
||
$filePath = "{$rootpath}/../../../public/receiving/{$millisecondTimestamp}.xlsx";
|
||
$url = "https://ye4s.wms.gztbyc.com/receiving/{$millisecondTimestamp}.xlsx";
|
||
$write = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||
$res = $write->save($filePath);
|
||
$msg = $this->backFile(["fromid"=>$room_id],$url);
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
$text = "收货完成通知:\n货主:{$storeName}\n收货明细文件名:{$millisecondTimestamp}.xlsx";
|
||
$msg = $this->toMsg($room_id,$text);
|
||
$this->redis->lpush("Message",json_encode($msg));
|
||
return 1;
|
||
}
|
||
}
|
||
/**
|
||
* @description:封装push消息到redis的方法
|
||
* @param {string} $msg 原消息
|
||
* @param {string} $source 消息来源wx:微信,qiwe:企微
|
||
*/
|
||
private function toMsgCache($msgData, $source = null){
|
||
if($source === 'wx') {
|
||
$cacheKey = "Message";
|
||
} elseif ($source === 'qiwe') {
|
||
$cacheKey = "QiweMessage";
|
||
}else{
|
||
//判断wxid是否携带chatroom字符串,携带则说明是微信的消息,推送到Message,不携带则说明是企微的消息,推送到QiweMessage
|
||
if(isset($msgData['wxid']) && strpos($msgData['wxid'], '@chatroom') !== false) {
|
||
$cacheKey = "Message";
|
||
} else {
|
||
$cacheKey = "QiweMessage";
|
||
}
|
||
}
|
||
//企微队列追加入队时间,便于排查与按时间清理积压(消费端 sendMessage 会忽略未知字段)
|
||
$msgData = $this->withQueueTs($msgData, $cacheKey);
|
||
$this->redis->select(2);
|
||
$this->redis->lpush($cacheKey, json_encode($msgData));
|
||
return $cacheKey;
|
||
}
|
||
/**
|
||
* @description:企微队列消息追加 ts 入队时间
|
||
* @param {array} $msgData 消息体
|
||
* @param {string} $cacheKey 队列键名
|
||
* @return {array} 补过 ts 的消息体
|
||
*/
|
||
private function withQueueTs($msgData, $cacheKey){
|
||
if($cacheKey === "QiweMessage" && is_array($msgData) && !isset($msgData['ts'])){
|
||
$msgData['ts'] = date('Y-m-d H:i:s');
|
||
}
|
||
return $msgData;
|
||
}
|
||
/**
|
||
* 获取货主对应的企微群聊房间,并返回房间信息及来源标识
|
||
* @param string $WAREHOUSEID 仓库ID
|
||
* @param string $STOREID 货主ID
|
||
* @param string $type 房间类型(isMain/其他字段)
|
||
* @return array|null 返回房间信息(包含room_id等字段),如果没有找到则返回null
|
||
*/
|
||
private function getOwnerRoom($WAREHOUSEID, $STOREID, $type = "isMain")
|
||
{
|
||
// 优先从qiwe命名空间下的Rooms模型查询
|
||
$RoomsModel = new \app\common\model\qiwe\Rooms();
|
||
$rooms = $RoomsModel->where([
|
||
"WAREHOUSEID" => $WAREHOUSEID,
|
||
"STOREID" => $STOREID,
|
||
"type" => 1
|
||
])->select();
|
||
// 如果在qiwe\Rooms中有数据,直接返回(标记来源为qiwe)
|
||
if ($rooms) {
|
||
$roomsArray = $rooms;
|
||
$room = $roomsArray[0];
|
||
|
||
foreach ($roomsArray as $roomItem) {
|
||
if (isset($roomItem[$type]) && $roomItem[$type] == 1) {
|
||
$room = $roomItem;
|
||
break;
|
||
}
|
||
}
|
||
|
||
// 标记来源
|
||
$room['_source'] = 'qiwe';
|
||
return $room;
|
||
}
|
||
// qiwe\Rooms中没有数据,尝试从普通Rooms模型查询
|
||
$RoomsModel = new \app\common\model\Rooms();
|
||
$rooms = $RoomsModel->where([
|
||
"WAREHOUSEID" => $WAREHOUSEID,
|
||
"STOREID" => $STOREID,
|
||
"type" => 1
|
||
])->select();
|
||
|
||
if ($rooms) {
|
||
$roomsArray = $rooms;
|
||
$room = $roomsArray[0];
|
||
|
||
foreach ($roomsArray as $roomItem) {
|
||
if (isset($roomItem[$type]) && $roomItem[$type] == 1) {
|
||
$room = $roomItem;
|
||
break;
|
||
}
|
||
}
|
||
|
||
// 标记来源
|
||
$room['_source'] = 'wx';
|
||
return $room;
|
||
}
|
||
|
||
// 仍然没有找到,尝试获取异常群
|
||
$RoomsModel = new \app\common\model\qiwe\Rooms();
|
||
$room = $RoomsModel->where([
|
||
"WAREHOUSEID" => $WAREHOUSEID,
|
||
"type" => 2,
|
||
"sub_type" => "error"
|
||
])->find();
|
||
if ($room) {
|
||
$room = $room->toArray();
|
||
$room['_source'] = 'qiwe';
|
||
return $room;
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
/**
|
||
* 推送消息到货主群
|
||
* @param string $msg 消息内容
|
||
* @param string $WAREHOUSEID 仓库ID
|
||
* @param string $STOREID 货主ID
|
||
* @param string $type 房间类型(isMain/其他字段)
|
||
* @return bool 推送是否成功
|
||
*/
|
||
private function pushMsgToOwner($msg, $WAREHOUSEID, $STOREID, $type = "isMain")
|
||
{
|
||
$room = $this->getOwnerRoom($WAREHOUSEID, $STOREID, $type);
|
||
|
||
if (!$room) {
|
||
// 没有找到任何可用的房间
|
||
return false;
|
||
}
|
||
|
||
// 根据来源判断消息前缀和缓存类型
|
||
$pushMsg = $msg;
|
||
$cacheType = 'wx'; // 默认为wx
|
||
|
||
if ($room['_source'] == 'qiwe') {
|
||
// 从qiwe\Rooms获取的房间,推送到企微
|
||
$cacheType = 'qiwe';
|
||
} elseif ($room['_source'] == 'common') {
|
||
// 从普通Rooms获取的房间,推送到微信
|
||
$cacheType = 'wx';
|
||
} elseif ($room['_source'] == 'error') {
|
||
// 异常群,需要添加前缀,推送到微信
|
||
$pushMsg = "通知货主【{$STOREID}】:" . $msg;
|
||
$cacheType = 'wx';
|
||
}
|
||
|
||
// 构建消息数据并推送
|
||
$msgData = $this->toMsg($room["room_id"], $pushMsg);
|
||
return $this->toMsgCache($msgData, $cacheType);
|
||
}
|
||
public function notic(){
|
||
$rawInput = file_get_contents('php://input');
|
||
$data = json_decode($rawInput, true);
|
||
|
||
if(empty(($data['event'] ?? null))) return 0;
|
||
|
||
$event = ($data['event'] ?? null);
|
||
$msgType = $data['message']['type'] ?? null;
|
||
|
||
// 1. 构建消息
|
||
$msgData = $this->buildMsg($msgType, $data);
|
||
if(!$msgData) return 0;
|
||
|
||
// 2. 处理事件(返回是否需要通知货主)
|
||
[$needNotify,$roomType] = $this->processEvent($event, $data, $msgData);
|
||
|
||
// 3. 通知货主
|
||
if($needNotify && !empty($data['store']['businessLicense'])){
|
||
$this->notifyOwner($data['store']['businessLicense'], $msgData,$roomType);
|
||
}
|
||
|
||
return 1;
|
||
}
|
||
|
||
// 构建消息(合并了原来的switch)
|
||
private function buildMsg($msgType, $data){
|
||
$msg = null;
|
||
$msg2 = null;
|
||
|
||
switch($msgType){
|
||
case 'image':
|
||
$msg = ["method"=>"sendImage", "wxid"=>"", "img"=>$data['message']['url'], "pid"=>0];
|
||
break;
|
||
case 'file':
|
||
Log::error("发送文件的消息原文".json_encode($data));
|
||
$msg = ["method"=>"sendFile", "wxid"=>"", "file"=>$data['message']['url'], "fileType"=>'url', "pid"=>0];
|
||
$msg2 = ["method"=>"sendText", "wxid"=>"", "msg"=>"文件下载地址为:{$data['message']['url']}", "atid"=>'', "pid"=>0];
|
||
break;
|
||
case 'text':
|
||
$msg = ["method"=>"sendText", "wxid"=>"", "msg"=>$data['message']['content'], "atid"=>"", "pid"=>0];
|
||
break;
|
||
default:
|
||
return null;
|
||
}
|
||
|
||
return ['primary' => $msg, 'secondary' => $msg2];
|
||
}
|
||
|
||
// 处理事件(返回是否需要通知货主)
|
||
private function processEvent($event, $data, &$msgData){
|
||
$RoomsModel = new \app\common\model\qiwe\Rooms();
|
||
$needNotify = false;
|
||
$roomType = "isMain";
|
||
switch($event){
|
||
case "receiving_completed":
|
||
// 发库存群
|
||
$room = $RoomsModel->where(["type"=>2,"sub_type"=>"stock"])->find();
|
||
if($room){
|
||
$this->sendMsg($msgData, $room['room_id'], 'qiwe');
|
||
}
|
||
break;
|
||
|
||
case "storage_transfer_completed":
|
||
$room = $RoomsModel->where(["type"=>2,"sub_type"=>"stock"])->find();
|
||
if($room){
|
||
$this->sendMsg($msgData, $room['room_id'], 'qiwe');
|
||
}
|
||
break;
|
||
case "receiving_rejected":
|
||
$room = $RoomsModel->where(["type"=>2,"sub_type"=>"receiving"])->find();
|
||
if($room){
|
||
$this->sendMsg($msgData, $room['room_id'], 'qiwe');
|
||
}
|
||
break;
|
||
case "receiving_reviewed":
|
||
$room = $RoomsModel->where(["type"=>2,"sub_type"=>"stock"])->find();
|
||
if($room){
|
||
$this->sendMsg($msgData, $room['room_id'], 'qiwe');
|
||
}
|
||
$needNotify = true; // 需要通知货主
|
||
$roomType = "isStorge";
|
||
break;
|
||
default:
|
||
Log::error("未知通知".json_encode($data));
|
||
}
|
||
|
||
return [$needNotify,$roomType];
|
||
}
|
||
|
||
// 统一发送消息
|
||
private function sendMsg($msgData, $wxid, $cacheType){
|
||
if($msgData['primary']){
|
||
$msgData['primary']['wxid'] = $wxid;
|
||
$this->toMsgCache($msgData['primary'], $cacheType);
|
||
}
|
||
if($msgData['secondary']){
|
||
$msgData['secondary']['wxid'] = $wxid;
|
||
$this->toMsgCache($msgData['secondary'], $cacheType);
|
||
}
|
||
}
|
||
|
||
// 通知货主
|
||
private function notifyOwner($businessLicense, $msgData,$roomType){
|
||
$StoreModel = new \app\common\model\wms\Warestore;
|
||
$store = $StoreModel->where(["id"=>$businessLicense])->find();
|
||
if(!$store) return;
|
||
|
||
$room = $this->getOwnerRoom(5400, intval($store['STOREID']),$roomType);
|
||
if(!$room) return;
|
||
|
||
// 确定缓存类型
|
||
$cacheType = ($room['_source'] == 'qiwe') ? 'qiwe' : 'wx';
|
||
|
||
// 异常群加前缀
|
||
if($room['_source'] == 'error' && $msgData['primary']){
|
||
$msgData['primary']['msg'] = "通知货主【{$store['STOREID']}】:" . $msgData['primary']['msg'];
|
||
}
|
||
|
||
$this->sendMsg($msgData, $room['room_id'], $cacheType);
|
||
Log::error("通知到货主群".json_encode($msgData['primary']));
|
||
}
|
||
|
||
// ==================== WMS 入站通知入口 ====================
|
||
|
||
/**
|
||
* new_wms_notify — 统一外部入站接口
|
||
*
|
||
* 接收 WMS 仓库 API 的回调/通知,经过签名校验后自动分发到已注册的处理器。
|
||
* 与 func/ 出方向方法独立,互不干扰。
|
||
*
|
||
* 入口: POST /index/wms/wms/new_wms_notify?method=xxx&...
|
||
*/
|
||
public function new_wms_notify()
|
||
{
|
||
$queryParams = $this->request->get();
|
||
$rawBody = file_get_contents('php://input');
|
||
|
||
\think\Log::error("[new_wms_notify] 入参\nQuery: " . json_encode($queryParams, JSON_UNESCAPED_UNICODE) . "\nBody: {$rawBody}");
|
||
|
||
$dispatcher = new \app\index\library\new_wms\notify\Dispatcher();
|
||
$result = $dispatcher->handle($queryParams, $rawBody);
|
||
|
||
\think\Log::error("[new_wms_notify] 出参: " . json_encode($result, JSON_UNESCAPED_UNICODE));
|
||
|
||
return json($result);
|
||
}
|
||
}
|