2026-08-28 19:55:57 +08:00

735 lines
33 KiB
PHP

<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Config;
use think\Db;
use think\db\exception\BindParamException;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\exception\DbException;
use think\exception\PDOException;
use think\exception\ValidateException;
use fast\Random;
use app\index\library\Wsdl;
use fast\Pinyin;
use fast\Http;
/**
* 首页接口
*/
class Wms extends Api
{
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('47.100.78.112', 6379);
$this->express_redis->auth('qwe2019');
$this->express_redis->select(2);
}
protected $noNeedLogin = ['resubscribe'];
protected $noNeedRight = ['create_subscribe','resubscribe'];
public function index(){
$params=$this->request->post();
$storeid=isset($params['storeid'])?$params['storeid']:0;
$where3 = 'FLAG=0';
$WAREHOUSEID = $this->auth->warehouseid;
$orderModel = new \app\common\model\wms\Order;
$userid = $this->auth->id;
$userStoreModel = new \app\common\model\UserStore;
$WarestoreModel = new \app\common\model\wms\Warestore;
$Warestoress = [];
if($this->auth->check("isstaff")){
if($storeid!=0){
$orderquery = $orderModel->where(["STOREID"=>$storeid]);
}else{
$orderquery = $orderModel->where(["WAREHOUSEID"=>$WAREHOUSEID]);
}
}else{
$stores = $userStoreModel->where(["user_id"=>$userid])->select();
$storeids = [];
foreach ($stores as $r){
array_push($storeids,$r["store_id"]);
}
if($storeid!=0){
$storeids = array_intersect([$storeid],$storeids);
}
$orderquery = $orderModel->where("STOREID",'in',$storeids);
}
try {
$datas = $orderquery->field('
SUM(CASE WHEN POSTFLAG=0 THEN 1 ELSE 0 END) AS dfp,
SUM(CASE WHEN PRINTTIMES=0 and POSTFLAG=1 THEN 1 ELSE 0 END) AS ddy,
SUM(CASE WHEN PRINTTIMES=1 and PICKINGFLAG=0 and OPERATERECORDS not like "%领料%" and OPERATERECORDS not like "%领取快递面单%" and GRABNUM != "" THEN 1 ELSE 0 END) AS dll,
SUM(CASE WHEN PICKINGFLAG=0 and (OPERATERECORDS like "%领料%" or OPERATERECORDS like "%领取快递面单%") and GRABNUM != "" THEN 1 ELSE 0 END) AS djh,
SUM(CASE WHEN (OPERATERECORDS not like "%揽收%") THEN 1 ELSE 0 END) AS dls,
SUM(CASE WHEN (OPERATERECORDS like "%揽收%") THEN 1 ELSE 0 END) AS yls,
SUM(CASE WHEN PICKINGFLAG=3 and PLSENDFLAG=0 THEN 1 ELSE 0 END) AS dfh,
SUM(CASE WHEN PLSENDFLAG=1 and WEIGHT = "" THEN 1 ELSE 0 END) AS dcz,
SUM(CASE WHEN PLSENDFLAG=1 and OPERATERECORDS not like "%打包%" THEN 1 ELSE 0 END) AS ddb,
SUM(CASE WHEN 1=1 THEN 1 ELSE 0 END) AS yjd,
SUM(CASE WHEN POSTFLAG=1 THEN 1 ELSE 0 END) AS yfp,
SUM(CASE WHEN PRINTTIMES=1 THEN 1 ELSE 0 END) AS ydy,
SUM(CASE WHEN WEIGHT <> "" THEN 1 ELSE 0 END) AS ycz,
SUM(CASE WHEN OPERATERECORDS like "%打包%" THEN 1 ELSE 0 END) AS ydb,
SUM(CASE WHEN OPERATERECORDS like "%领料%" or OPERATERECORDS like "%领取快递面单%" or PICKINGFLAG=3 THEN 1 ELSE 0 END) AS yll,
SUM(CASE WHEN PICKINGFLAG=3 THEN 1 ELSE 0 END) AS yjh,
SUM(CASE WHEN PLSENDFLAG=1 THEN 1 ELSE 0 END) AS yfh
')->where($where3)->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000)->find();
if($this->auth->check("isstaff")){
if($storeid!=0){
$orderquery2 = $orderModel->where(["STOREID"=>$storeid]);
}else{
$orderquery2 = $orderModel->where(["WAREHOUSEID"=>$WAREHOUSEID]);
}
}else{
$stores = $userStoreModel->where(["user_id"=>$userid])->select();
$storeids = [];
foreach ($stores as $r){
array_push($storeids,$r["store_id"]);
}
if($storeid!=0){
$storeids = array_intersect([$storeid],$storeids);
}
$orderquery2 = $orderModel->where("STOREID",'in',$storeids);
}
$datas2 = $orderquery2->field('
SUM(CASE WHEN FLAG=1 THEN 1 ELSE 0 END) AS ylj
')->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000)->find();
$datas['ylj'] = $datas2['ylj'];
$this->success('获取成功',$datas);
} catch (Exception $e) {
$this->error($e);
}
}
public function query(){
$params=$this->request->post();
$WAREHOUSEID = $this->auth->warehouseid;
$orderModel = new \app\common\model\wms\Order;
$query = $orderModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where($params['query']['wherest'])
->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000);
if($params['query']['group']){
$query->group('GRABNUM');
}
$count = $query->count();
$query2 = $orderModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where($params['query']['wherest'])
->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000);
if($params['query']['group']){
$query2->group('GRABNUM');
}
$query2->limit($params['query']['pagesize']*($params['query']['page']-1),$params['query']['pagesize']);
$list = $query2->select();
foreach($list as $r){
$StoreModel = new \app\common\model\wms\Store;
$store = $StoreModel->where(['STOREID'=>$r['STOREID']])->find();
$r['huozhu'] = $store['TITLE'];
}
if(!$list && $params['query']['his']){
$orderModel = new \app\common\model\wms\Order1;
$query = $orderModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where($params['query']['wherest'])
->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000);
if($params['query']['group']){
$query->group('GRABNUM');
}
$count = $query->count();
$query2 = $orderModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where($params['query']['wherest'])
->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000);
if($params['query']['group']){
$query2->group('GRABNUM');
}
$query2->limit($params['query']['pagesize']*($params['query']['page']-1),$params['query']['pagesize']);
$list = $query2->select();
foreach($list as $r){
$StoreModel = new \app\common\model\wms\Store;
$store = $StoreModel->where(['STOREID'=>$r['STOREID']])->find();
$r['huozhu'] = $store['TITLE'];
$r['OPERATERECORDS'] = $r['NOTES'];
}
}
$this->success('查询结果',["list"=>$list,"count"=>$count]);
}
public function stores(){
$WAREHOUSEID = $this->auth->warehouseid;
$userid = $this->auth->id;
$StoreModel = new \app\common\model\wms\Warestore;
$userStoreModel = new \app\common\model\UserStore;
if($this->auth->check("isstaff")){
$list = $StoreModel->with(['employees'])->where(["WAREHOUSEID"=>$WAREHOUSEID])->select();
}else{
$stores = $userStoreModel->where(["user_id"=>$userid])->select();
$storeids = [];
foreach ($stores as $r){
array_push($storeids,$r["store_id"]);
}
$list = $StoreModel->with(['employees'])->where("warestore.STOREID","in",$storeids)->select();
}
$this->success("查询结果",$list);
}
public function tggzt(){
$GztModel = new \app\common\model\wms\Gzt;
$WarehouseModel = new \app\common\model\Warehouse;
$WAREHOUSEID = $this->auth->warehouseid;
$list = $GztModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->select();
$Warehouse = $WarehouseModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
$this->success('查询结果',["list"=>$list,"workDate"=>$Warehouse->workDate]);
}
public function resetgzt(){
$params=$this->request->post();
$id = isset($params['id'])?intval($params['id']):0;
$GztModel = new \app\common\model\wms\Gzt;
$WAREHOUSEID = $this->auth->warehouseid;
$this->express_redis->select(3);
if($id==0){
$gzts = $GztModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"type"=>1])->select();
foreach ($gzts as $r){
$data = $this->express_redis->get("camera_{$r->id}");
if($data){
$isrunning = $this->express_redis->get("running_{$data}");
if($isrunning=="1"){
$this->express_redis->set($data,1);
}
}
$this->jiesuan($r->grabnum,$r->workers);
$r->grabnum = "";
$r->workers = "";
$r->ordercount = 0;
$r->grabcount = 0;
$r->hordercount = 0;
$r->save();
}
$this->success();
}
$gzt = $GztModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"id"=>"$id","type"=>1])->find();
if($gzt){
$data = $this->express_redis->get("camera_{$gzt->id}");
if($data){
$isrunning = $this->express_redis->get("running_{$data}");
if($isrunning=="1"){
$this->express_redis->set($data,1);
}
}
$this->jiesuan($gzt->grabnum,$gzt->workers);
$gzt->grabnum = "";
$gzt->workers = "";
$gzt->ordercount = 0;
$gzt->grabcount = 0;
$gzt->hordercount = 0;
$gzt->save();
}else{
$this->error('工作台不存在');
}
$this->success();
}
public function set_date(){
$WarehouseModel = new \app\common\model\Warehouse;
$WAREHOUSEID = $this->auth->warehouseid;
$Warehouse = $WarehouseModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
if(!$Warehouse){
$this->error('仓库不存在');
}
$params=$this->request->post();
$date = isset($params['date'])?intval($params['date']):0;
switch ($date) {
case 1:
$time = date("Y-m-d",strtotime("+1 day"));
break;
default:
$time = date("Y-m-d");
break;
}
$time = strtotime($time);
$Warehouse->workDate = $time;
$Warehouse->save();
$this->success('设置成功',$time);
}
public function deletegzt(){
$params=$this->request->post();
$id = isset($params['id'])?intval($params['id']):0;
$GztModel = new \app\common\model\wms\Gzt;
$WAREHOUSEID = $this->auth->warehouseid;
if($id==0){
$this->error('工作台不存在');
}
$gzt = $GztModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"id"=>"$id"])->find();
if($gzt){
$gzt->delete();
$UserModel = new \app\common\model\wms\User;
$user = $UserModel->where(["userid"=>$gzt->userid])->find();
if($user){
$user->delete();
}
$OperatorModel = new \app\common\model\wms\Operator;
$rules = $OperatorModel->where(["USERID"=>$gzt->userid])->select();
foreach ($rules as $r){
$r->delete();
}
}else{
$this->error('工作台不存在');
}
$this->success('删除成功');
}
public function addgzt(){
$params=$this->request->post();
$gztName = isset($params['gztName'])?$params['gztName']:0;
$maxRecordingDuration = isset($params["maxRecordingDuration"])?$params["maxRecordingDuration"]:9000;
$rtspUrl = isset($params["rtspUrl"])?$params["rtspUrl"]:"";
$recordHost = isset($params["recordHost"])?$params["recordHost"]:"";
$gztid = isset($params["id"])?$params["id"]:0;
$GztModel = new \app\common\model\wms\Gzt;
$UserModel = new \app\common\model\wms\User;
$WAREHOUSEID = $this->auth->warehouseid;
if($gztid>0){
//编辑
$gzt = $GztModel->where(['id'=>$gztid,"wareHouseId"=>$WAREHOUSEID])->find();
if($gzt){
$gzt->save(['name'=>$gztName,'type'=>$params['type'],"rtspUrl"=>$rtspUrl,"maxRecordingDuration"=>$maxRecordingDuration]);
$this->success('修改成功');
}else{
$this->error('编辑失败,工作台不存在');
}
}else{
$wmsuser = $GztModel->where(['name'=>$gztName,"wareHouseId"=>$WAREHOUSEID])->find();
if($wmsuser){
$this->error('工作台名称已存在');
}else{
$uuid = Random::uuid();
$tmp_code = base64_encode(json_encode(["uuid"=>$uuid]));
$uuid = Pinyin::get($gztName);
$password = Random::alnum(16);
$res = Wsdl::webservice([$WAREHOUSEID,$uuid,$gztName,$password,'入库,盘点,打包,拣货,移库,出库,分播,收货,快捷出入库,快递操作,不复核发货,线下出库'],"createUser");
if($res>0){
$GztModel->save(['username'=>$uuid,'name'=>$gztName,'type'=>$params['type'],'userid'=>$res,'wareHouseId'=>$WAREHOUSEID,"workers"=>"","grabnum"=>"","rtspUrl"=>$rtspUrl,"maxRecordingDuration"=>$maxRecordingDuration,"tmp_code"=>$tmp_code]);
$this->success('添加成功');
}else{
$this->success('添加失败');
}
}
}
}
public function gzt_bind(){
$params=$this->request->post();
\think\Log::error("[gzt_bind] 入参: " . json_encode($params, JSON_UNESCAPED_UNICODE));
$GztModel = new \app\common\model\wms\Gzt;
$WAREHOUSEID = $this->auth->warehouseid;
$gzt = $GztModel->where(['id'=>$params["id"],"wareHouseId"=>$WAREHOUSEID,"type"=>2])->find();
if(!$gzt){
\think\Log::error("[gzt_bind] 工作台不存在或类型错误: id={$params['id']} wareHouseId={$WAREHOUSEID}");
$this->error("工作台不存在,或工作台是团购类型");
}
$sid = $this->redis->get("bindcode_".$params["code"]);
$sid2 = $this->redis->get("gzt_".$gzt["id"]);
if(!$sid){
\think\Log::error("[gzt_bind] 无记录或二维码已失效: code={$params['code']} gzt_id={$gzt['id']}");
$this->error('无记录或二维码已失效');
}else{
$uuid = Random::uuid();
$tmp_code = base64_encode(json_encode(["uuid"=>$uuid]));
$gzt->tmp_code = $tmp_code;
$gzt->save();
$url="http://127.0.0.1:7001/tool/backMsg";
$requsetData = [
'sid'=>$sid,
'method'=>"binded",
'data'=>$tmp_code
];
$options = [];
$urlEncodedString = http_build_query($requsetData);
$req = Http::sendRequest($url, $urlEncodedString, 'POST', $options);
\think\Log::error("[gzt_bind] binded 请求结果: " . json_encode($req, JSON_UNESCAPED_UNICODE));
if(!$req['ret']){
\think\Log::error("[gzt_bind] binded 发送失败: " . json_encode($req, JSON_UNESCAPED_UNICODE));
}
if($sid2){
$requsetData = [
'sid'=>$sid2,
'method'=>"cheakBind",
'data'=>""
];
$urlEncodedString = http_build_query($requsetData);
$req = Http::sendRequest($url, $urlEncodedString, 'POST', $options);
\think\Log::error("[gzt_bind] cheakBind 请求结果: " . json_encode($req, JSON_UNESCAPED_UNICODE));
if(!$req['ret']){
\think\Log::error("[gzt_bind] cheakBind 发送失败: " . json_encode($req, JSON_UNESCAPED_UNICODE));
}
}
$this->success('绑定成功');
}
}
public function mine(){
$params=$this->request->post();
$start = $params['start'];
$end = $params['end'];
$wms_userid = $this->auth->wms_userid;
$name = $this->auth->real_name;
$WAREHOUSEID = $this->auth->warehouseid;
$res_data = ["t"=>["j"=>[0,0,0,0],"f"=>[0,0,0,0],"d"=>[0,0,0,0]],"s"=>["j"=>[0,0,0,0],"f"=>[0,0,0,0],"d"=>[0,0,0,0]]];
$WokesModel = new \app\common\model\wms\Wokes;
$dabaos = [];
if($name){
$dabaos = $WokesModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where('grabnum is not null')->where('workDate','BETWEEN',[strtotime($start),strtotime($end)])->where('workers like "%'.$name.'%"')->where('dabaos>0')->select();
}
foreach ($dabaos as $r){
$workers = explode('|',$r['workers']);
$stocks = explode('|',$r['items']);
$workers_count = count($workers);
$stocks_count = count($stocks)-1;
$res_data["t"]["d"][0] += floor($r['dabaos']/$workers_count);
$res_data["t"]["d"][1] +=1;
$res_data["t"]["d"][2] += $stocks_count;
$res_data["t"]["d"][3] += floor($r['GOODSCOUNT']/$workers_count);
}
$infos = $WokesModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where('workDate','BETWEEN',[strtotime($start),strtotime($end)])->where(['userID'=>$wms_userid])->select();
$list2 = $WokesModel->field('count(*) as count,userId')->where(["WAREHOUSEID"=>$WAREHOUSEID])->where('workDate','BETWEEN',[strtotime($start),strtotime($end)])->where('grabnum not like "%B%" and fuhe>0')->group('userId,grabnum')->select();
foreach ($infos as $r){
if(strpos($r['grabnum'],"B")>-1){
//团购
if($r['fuhe']>0){
$stocks = explode('|',$r['items']);
$stocks_count = count($stocks)-1;
$res_data["t"]["f"][0] += intval($r['fuhe']);
$res_data["t"]["f"][1] +=1;
$res_data["t"]["f"][2] += $stocks_count;
$res_data["t"]["f"][3] += $r['GOODSCOUNT'];
}
if($r['picks']>0){
$stocks = explode('|',$r['items']);
$stocks_count = count($stocks)-1;
$res_data["t"]["j"][0] += intval($r['picks']);
$res_data["t"]["j"][1] +=1;
$res_data["t"]["j"][2] += $stocks_count;
$res_data["t"]["j"][3] += $r['GOODSCOUNT'];
}
}else{
//散单
if($r['fuhe']>0){
$stocks = explode('|',$r['items']);
$stocks_count = count($stocks)-1;
$res_data["s"]["f"][0] += 1;
$res_data["s"]["f"][1] += 1;
$res_data["s"]["f"][2] += $stocks_count;
$res_data["s"]["f"][3] += $r['GOODSCOUNT'];
}
if($r['picks']>0){
$stocks = explode(';',$r['items']);
$stocks_count = count($stocks)-1;
$res_data["s"]["j"][0] += intval($r['picks']);
$res_data["s"]["j"][1] += 1;
$res_data["s"]["j"][2] += $stocks_count;
$res_data["s"]["j"][3] += $r['GOODSCOUNT'];
}
if($r['dabaos']>0){
$stocks = explode('|',$r['items']);
$stocks_count = count($stocks)-1;
$res_data["s"]["d"][0] += 1;
$res_data["s"]["d"][1] += 1;
$res_data["s"]["d"][2] += $stocks_count;
$res_data["s"]["d"][3] += $r['GOODSCOUNT'];
}
}
$res_data["s"]["f"][1] =0;
foreach ($list2 as $rr){
if($rr['userId']==$wms_userid){
$res_data["s"]["f"][1] += 1;
}
}
}
$this->success('获取成功',["infos"=>$res_data]);
}
public function infos(){
$WAREHOUSEID = $this->auth->warehouseid;
$params=$this->request->post();
$start = $params['start'];
$end = $params['end'];
$WokesModel = new \app\common\model\wms\Wokes;
$list = $WokesModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->where('workDate','BETWEEN',[strtotime($start),strtotime($end)])->where('grabnum is not null')->select();
$list2 = $WokesModel->field('count(*) as count,userId')->where(["WAREHOUSEID"=>$WAREHOUSEID])->where('workDate','BETWEEN',[strtotime($start),strtotime($end)])->where('grabnum not like "%B%" and fuhe>0')->where('grabnum is not null')->group('userId,grabnum')->select();
$users = [];
$users2 = [];
$users3 = [];
$users4 = [];
$users5 = [];
foreach ($list as $r){
if(strpos($r['grabnum'],'B')>-1 && $r['dabaos']>0){
$workers_tmp = explode("|",$r['workers']);
foreach ($workers_tmp as $rr){
array_push($users3,$rr);
}
}else{
array_push($users,$r['userId']);
}
if($r['types']==3){
array_push($users5,$r['userId']);
}
}
$users = array_unique($users);
$wmsuserModel = new \app\common\model\wms\User;
$userModel = new \app\common\model\User;
$wmsuser = $wmsuserModel->where('userID','in',$users)->select();
foreach ($wmsuser as $r){
array_push($users2,$r['name'].','.$r['userID']);
}
$users2 = array_unique($users2);
$users2 = array_filter($users2,'strlen');
$users3 = array_unique($users3);
$users3 = array_filter($users3,'strlen');
$users5 = array_unique($users5);
$users5 = array_filter($users5,'strlen');
$users6 = $userModel->where('id','in',$users5)->select();
$workers = [];
foreach ($users2 as $r){
$d = explode(',',$r);
array_push($workers,[$d[0],$d[1],0,[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]);
array_push($users4,$d[1]);
}
foreach ($users3 as $r){
$hasU = false;
foreach ($workers as $rr){
if($rr[0]==$r){
$hasU = true;
}
}
if(!$hasU){
array_push($workers,[$r,0,0,[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]);
}
}
foreach ($users6 as $r){
$hasU = 0;
foreach ($workers as $key => $rr){
if($rr[0]==$r['real_name']){
$hasU = 1;
$workers[$key][2] = $r['id'];
}
}
if(!$hasU){
array_push($workers,[$r['real_name'],0,$r['id'],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]);
}
}
foreach ($list as $r){
if(strpos($r['grabnum'],"B")>-1){
//团购
if($r['fuhe']>0){
foreach ($workers as $k => $rr){
if($rr[1]==$r['userId']){
$stocks = explode('|',$r['items']);
$stocks_count = count($stocks)-1;
$workers[$k][4][0] += intval($r['fuhe']);
$workers[$k][4][1] += 1;
$workers[$k][4][2] += $stocks_count;
$workers[$k][4][3] += $r['GOODSCOUNT'];
}
}
}
if($r['picks']>0){
foreach ($workers as $k => $rr){
if($rr[1]==$r['userId']){
$stocks = explode('|',$r['items']);
$stocks_count = count($stocks)-1;
$workers[$k][3][0] += intval($r['picks']);
$workers[$k][3][1] += 1;
$workers[$k][3][2] += $stocks_count;
$workers[$k][3][3] += $r['GOODSCOUNT'];
}
}
}
if($r['tiedan']>0){
foreach ($workers as $k => $rr){
if($rr[1]==$r['userId']){
$workers[$k][9][0] += intval($r['tiedan']);
$workers[$k][9][1] += 1;
$workers[$k][9][2] += 0;
$workers[$k][9][3] += 0;
}
}
}
if($r['dabaos']>0){
$cworkers = explode('|',$r['workers']);
$workers_count = count($cworkers);
$stocks = explode('|',$r['items']);
$stocks_count = count($stocks)-1;
foreach ($workers as $k => $rr){
if(in_array($rr[0],$cworkers)){
$workers[$k][5][0] += number_format($r['dabaos']/$workers_count,8);
$workers[$k][5][1] += 1;
$workers[$k][5][2] += $stocks_count;
$workers[$k][5][3] += floor($r['GOODSCOUNT']/$workers_count);
}
}
}
}else{
//散单
if($r['picks']>0){
foreach ($workers as $k => $rr){
if($rr[1]==$r['userId']){
$stocks = explode(';',$r['items']);
$stocks_count = count($stocks)-1;
$workers[$k][6][0] += intval($r['picks']);
$workers[$k][6][1] += 0;
$workers[$k][6][2] += $stocks_count;
$workers[$k][6][3] += $r['GOODSCOUNT'];
}
}
}
if($r['fuhe']>0){
foreach ($workers as $k => $rr){
if($rr[1]==$r['userId']){
$stocks = explode('|',$r['items']);
$stocks_count = count($stocks)-1;
$workers[$k][7][0] += 1;
$workers[$k][7][2] += $stocks_count;
$workers[$k][7][3] += $r['GOODSCOUNT'];
}
}
}
if($r['dabaos']>0){
foreach ($workers as $k => $rr){
if($rr[1]==$r['userId']){
$stocks = explode('|',$r['items']);
$stocks_count = count($stocks)-1;
$workers[$k][8][0] += 1;
$workers[$k][8][1] += 1;
$workers[$k][8][2] += $stocks_count;
$workers[$k][8][3] += $r['GOODSCOUNT'];
}
}
}
if($r['tuijian']>0){
foreach ($workers as $k => $rr){
if($rr[1]==$r['userId']){
$stocks = explode('|',$r['items']);
$stocks_count = count($stocks)-1;
$workers[$k][10][0] += 1;
$workers[$k][10][1] += 0;
$workers[$k][10][2] += $stocks_count;
$workers[$k][10][3] += $r['GOODSCOUNT'];
}
}
}
}
if($r['types']==3){
foreach ($workers as $k => $rr){
if($rr[2]==$r['userId']){
$stocks = explode('|',$r['items']);
$stocks_count = count($stocks)-1;
$workers[$k][8][0] += 1;
$workers[$k][8][1] += 0;
$workers[$k][8][2] += $stocks_count;
$workers[$k][8][3] += $r['GOODSCOUNT'];
}
}
}
}
foreach ($workers as $k => $r){
$workers[$k][7][1] = 0;
foreach ($list2 as $rr){
if(intval($r[1])==$rr['userId']){
$workers[$k][7][1] += 1;
}
}
}
foreach ($workers as $k => $r){
foreach ($r[5] as $kk => $rr){
$workers[$k][5][$kk] = floor($rr);
}
}
$this->success('获取成功',["infos"=>$workers]);
}
private function jiesuan($GRABNUM,$workers){
if(!$GRABNUM){
return false;
}
$WokesModel = new \app\common\model\wms\Wokes;
$WAREHOUSEID = $this->auth->warehouseid;
$work = $WokesModel->where(["grabnum"=>$GRABNUM,"WAREHOUSEID"=>$WAREHOUSEID])->where('dabaos>0')->find();
$work->updatetime = time();
$work->workers = $workers;
$work->save();
}
public function create_subscribe(){
$WAREHOUSEID = $this->auth->warehouseid;
$OrderModel = new \app\common\model\wms\Order;
$items = $OrderModel->field('ID,POSTCODE,POSTNUM')->where(["WAREHOUSEID"=>$WAREHOUSEID,"FLAG"=>0,"PLSENDFLAG"=>1])->select();
$IDS = [];
foreach ($items as $r){
array_push($IDS,$r['ID']);
}
$ExpressModel = new \app\common\model\Express;
$has = $ExpressModel->field('POSTNUM')->where("order_id","in",$IDS)->select();
$exclude_postnum = [];
foreach ($has as $r){
array_push($exclude_postnum,$r["POSTNUM"]);
}
$insert = [];
foreach ($items as $r){
if(!in_array($r["POSTNUM"],$exclude_postnum)){
array_push($insert,["WAREHOUSEID"=>$WAREHOUSEID,"order_id"=>$r["ID"],"POSTNUM"=>$r["POSTNUM"],"create_time"=>time(),"POSTCODE"=>$r["POSTCODE"]]);
}
}
try {
$ExpressModel->saveAll($insert);
} catch (PDOException $exception) {
$msg = $exception->getMessage();
if (preg_match("/.+Integrity constraint violation: 1062 Duplicate entry '(.+)' for key '(.+)'/is", $msg, $matches)) {
$msg = "导入失败,包含【{$matches[1]}】的记录已存在";
};
$this->error($msg);
} catch (Exception $e) {
$this->error($e->getMessage());
}
$postcodes = [];
foreach($insert as $r){
if(array_key_exists($r['POSTCODE'],$postcodes)){
array_push($postcodes[$r['POSTCODE']],$r['POSTNUM']);
}else{
$postcodes[$r['POSTCODE']] = [$r['POSTNUM']];
}
}
$msgs = [];
foreach ($postcodes as $key=>$r){
array_push($msgs,$ExpressModel->subscribe_trace($r,$key));
}
$this->success('成功',$msgs);
}
public function resubscribe(){
$WAREHOUSEID = $this->auth->warehouseid;
$ExpressModel = new \app\common\model\Express;
$datas = $ExpressModel->field('POSTNUM,POSTCODE')->where(["status"=>0])->select();
$postcodes = [];
foreach($datas as $r){
if(array_key_exists($r['POSTCODE'],$postcodes)){
array_push($postcodes[$r['POSTCODE']],$r['POSTNUM']);
}else{
$postcodes[$r['POSTCODE']] = [$r['POSTNUM']];
}
}
$msgs = [];
foreach ($postcodes as $key=>$r){
array_push($msgs,$ExpressModel->subscribe_trace($r,$key));
}
$this->success('成功',$msgs);
/*
$taskID = $this->request->get('taskID');
$POSTCODE = $this->request->get('POSTCODE');
$redis = new \Redis();
$redis->connect('127.0.0.1', 6379);
$redis->auth('qwe2019');
$redis->select(2);
$redis->lpush('subscribe_tasks',json_encode(['taskID'=>$taskID,'POSTCODE'=>$POSTCODE]));
*/
}
public function postcode(){
$ParacodeModel = new \app\common\model\wms\Paracode;
$list = $ParacodeModel->where('TYPE=301')->select();
$this->success('成功',$list);
}
}