'圆通', 'p02'=> '申通', 'p03'=> '韵达', 'p24'=> '韵达国际', 'p04'=> '中通', 'p25'=> '中通快运', 'p05'=> '顺丰', 'p06'=> '百世快运', 'p07'=> 'EMS', 'p08'=> '京广速运', 'p09'=> '百世极兔/百世快递', 'p10'=> '京东', 'p16'=> '安能', 'p17'=> '优速', 'p21'=> '运通速运', 'p18'=> '自提', 'p26'=> '德邦快递/德邦物流', 'p19'=> '零担', 'p20'=> '整车', 'p22'=> '邮政', 'p23'=> '跨越', 'p27'=> '壹米滴答', 'p32'=> '极兔速递', 'p34'=> '丰网速运', 'p30'=> '其他', 'p35'=> '邮政标快' ]; 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); } public function store(){ $WAREHOUSEID = $this->auth->warehouseid; $this->success(); } public function warehouse(){ $WAREHOUSEID = $this->auth->warehouseid; $WAREHOUSEModel = new \app\common\model\Warehouse; $WAREHOUSE = $WAREHOUSEModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->find(); if(!$WAREHOUSE){ $this->error("仓库未配置"); } $TasksModel = new \app\common\model\Tasks; $plist = $TasksModel->select(); $this->success("获取成功",["WAREHOUSE"=>$WAREHOUSE,"plist"=>$plist,"pcodes"=>$this->pcodes]); } public function warehouse_save(){ $WAREHOUSEID = $this->auth->warehouseid; $params=$this->request->post(); $WAREHOUSEModel = new \app\common\model\Warehouse; $WAREHOUSE = $WAREHOUSEModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->find(); if(!$WAREHOUSE){ $this->error("仓库未配置"); } Db::startTrans(); try { $result = $WAREHOUSE->save(["autoCreatePostnumStoreId"=>$params["configs"]["autoCreatePostnumStoreId"],"autoCreateOnePostnumStoreId"=>$params["configs"]["autoCreateOnePostnumStoreId"],"autoCreatePostnumStoreId2"=>$params["configs"]["autoCreatePostnumStoreId2"],"autocheckStoragStoreId"=>$params["configs"]["autocheckStoragStoreId"],"exclude_express"=>$params["configs"]["exclude_express"],"operatorID"=>intval($params["configs"]["operatorID"]),"include_stocks"=>$params["configs"]["include_stocks"],"is_all_express"=>$params["configs"]["is_all_express"],"yesterdayOrderCount"=>$params["configs"]["yesterdayOrderCount"],"dgjAutoAudit"=>html_entity_decode($params["configs"]["dgjAutoAudit"])]); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if (false === $result) { $this->error(__('No rows were updated')); } $this->success("保存成功"); } public function open_door(){ $WAREHOUSEID = $this->auth->warehouseid; $this->redis->select(2); $data = $this->redis->set($WAREHOUSEID."_channelNum0",1); $doorLogModel = new \app\common\model\door\Log; $log = [ "WAREHOUSEID"=>$WAREHOUSEID, "carnum"=>"", "username"=>$this->auth->real_name, "open_time"=>time() ]; $doorLogModel->save($log); } public function sandan(){ $WAREHOUSEID = $this->auth->warehouseid; $RulesModel = new \app\common\model\wms\PickingRules; $list = $RulesModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->select(); $this->success("获取成功",$list); } public function printer(){ $WAREHOUSEID = $this->auth->warehouseid; $printerModel = new \app\common\model\Printer; $list = $printerModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->select(); $this->success("获取成功",$list); } public function saveSandan(){ $WAREHOUSEID = $this->auth->warehouseid; $RulesModel = new \app\common\model\wms\PickingRules; $params = $this->request->post(); $id = isset($params['id'])?$params['id']:false; if($id){ $info = $RulesModel->where(["id"=>$params['id'],"WAREHOUSEID"=>$WAREHOUSEID])->find(); if($info){ $data = $info->save($params); } }else{ $params['WAREHOUSEID'] = $WAREHOUSEID; $data = $RulesModel->save($params); } $this->success('保存成功',$data); } public function printer_save(){ $WAREHOUSEID = $this->auth->warehouseid; $printerModel = new \app\common\model\Printer; $params = $this->request->post(); $id = isset($params['id'])?$params['id']:false; $params['config'] = isset($params['config'])?htmlspecialchars_decode($params['config']):''; if($id){ $info = $printerModel->where(["id"=>$params['id'],"WAREHOUSEID"=>$WAREHOUSEID])->find(); if($info){ $data = $info->save($params); } }else{ $params['WAREHOUSEID'] = $WAREHOUSEID; $data = $printerModel->save($params); } $this->success('保存成功',[$data,$params]); } public function delSandan(){ $WAREHOUSEID = $this->auth->warehouseid; $RulesModel = new \app\common\model\sandan\Rules; $params = $this->request->post(); $id = isset($params['id'])?$params['id']:false; if($id){ $info = $RulesModel->where(["id"=>$params['id'],"WAREHOUSEID"=>$WAREHOUSEID])->find(); if($info){ $data = $info->delete(); } } $this->success('删除成功',$data); } public function del_printer(){ $WAREHOUSEID = $this->auth->warehouseid; $printerModel = new \app\common\model\Printer; $params = $this->request->post(); $id = isset($params['id'])?$params['id']:false; if($id){ $info = $printerModel->where(["id"=>$params['id'],"WAREHOUSEID"=>$WAREHOUSEID])->find(); if($info){ $data = $info->delete(); } } $this->success('删除成功',$data); } public function packs(){ $WAREHOUSEID = $this->auth->warehouseid; $PackModel = new \app\common\model\wms\Pack; $data = $PackModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->select(); $this->success('获取成功',$data); } public function weightandpack(){ $ItemsinfoModel = new \app\common\model\stocks\Weightandpack; $ItemsinfoModel1 = new \app\common\model\stocks\Weightandpack; $OrderModel = new \app\common\model\wms\Order; $params = $this->request->post(); $keyword = $params['keyword']; $WAREHOUSEID = $this->auth->warehouseid; $Itemsinfos = $ItemsinfoModel->limit(($params['page']-1)*20,20); $order = null; if($keyword){ $order = $OrderModel->where(["POSTNUM"=>$keyword,"WAREHOUSEID"=>$WAREHOUSEID])->find(); if($order){ $Itemsinfos->where('STOCKS="'.$order["STOCKS"].'"')->where(["WAREHOUSEID"=>$WAREHOUSEID]); }else{ $Itemsinfos->where('ITEMS like "%'.$keyword.'%"')->where(["WAREHOUSEID"=>$WAREHOUSEID]); } }else{ $Itemsinfos->where("Misses>0 and ISLOCK=0")->where(["WAREHOUSEID"=>$WAREHOUSEID]); } $list = $Itemsinfos->select(); $Itemsinfos2 = $ItemsinfoModel1; if($keyword){ $order = $OrderModel->where(["POSTNUM"=>$keyword,"WAREHOUSEID"=>$WAREHOUSEID])->find(); if($order){ $Itemsinfos->where('STOCKS="'.$order["STOCKS"].'"')->where(["WAREHOUSEID"=>$WAREHOUSEID]); }else{ $Itemsinfos->where('ITEMS like "%'.$keyword.'%"')->where(["WAREHOUSEID"=>$WAREHOUSEID]); } }else{ $Itemsinfos2->where("Misses>0 and ISLOCK=0")->where(["WAREHOUSEID"=>$WAREHOUSEID]); } $count = $Itemsinfos2->count(); $this->success('',["list"=>$list,"count"=>$count,"order"=>$order]); } public function find_stock(){ $params = $this->request->post(); $WAREHOUSEID = $this->auth->warehouseid; $keyword = isset($params["keyword"])?$params["keyword"]:""; $ItemsinfoModel = new \app\common\model\wms\Stock; if($keyword){ $list = $ItemsinfoModel->with(['goods','box'])->where('(stock.BARCODE="'.$keyword.'" or stock.STOCKID="'.$keyword.'" or goods.NAME like "%'.$keyword.'%") and stock.WAREHOUSEID='.$WAREHOUSEID)->limit(($params['page']-1)*20,20)->select(); $count = $ItemsinfoModel->with(['goods','box'])->where('(stock.BARCODE="'.$keyword.'" or stock.STOCKID="'.$keyword.'" or goods.NAME like "%'.$keyword.'%") and stock.WAREHOUSEID='.$WAREHOUSEID)->count(); }else{ $list = $ItemsinfoModel->with(['goods','box'])->where('stock.WAREHOUSEID='.$WAREHOUSEID)->limit(($params['page']-1)*20,20)->select(); $count = $ItemsinfoModel->with(['goods','box'])->where('stock.WAREHOUSEID='.$WAREHOUSEID)->count(); } $this->success('查询成功',["list"=>$list,"count"=>$count]); } public function save_items(){ $ItemsinfoModel = new \app\common\model\stocks\Weightandpack; $params = $this->request->post(); $WAREHOUSEID = $this->auth->warehouseid; if(isset($params['id'])){ $res = $ItemsinfoModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"id"=>$params['id']])->find(); $res->save(["WEIGHT"=>$params['WEIGHT'],"Misses"=>0,"STOCKS"=>$params['STOCKS'],"PACKID"=>$params['PACKID'],"ITEMS"=>$params['ITEMS']]); }else{ $res = $ItemsinfoModel->save(["WEIGHT"=>$params['WEIGHT'],"Misses"=>0,"STOCKS"=>$params['STOCKS'],"PACKID"=>$params['PACKID'],"ITEMS"=>$params['ITEMS'],"WAREHOUSEID"=>$WAREHOUSEID]); } $this->success('保存成功',$res); } public function updateStock(){ $ItemsinfoModel = new \app\common\model\stocks\Weightandpack; $Order1Model = new \app\common\model\wms\Order; $Order1Model1 = new \app\common\model\wms\Order1; $items = $ItemsinfoModel->where("ITEMS ='' or ITEMS is null")->limit(1)->select(); if($items){ $info = $Order1Model->where('STOCKS='.$items[0]['STOCKS'])->select(); if($info){ //$item = $ItemsinfoModel->find($items[0][id]); $res = $items[0]->save(["ITEMS"=>$info[0]['ITEMS']]); $this->success('成功',$res); }else{ $info = $Order1Model->where('STOCKS='.$items[0]['STOCKS'])->select(); if($info){ $res = $items[0]->save(["ITEMS"=>$info[0]['ITEMS']]); $this->success('成功',$res); }else{ $res = $items[0]->delete(); $this->error('无记录2'); } } } $this->error('无记录'); } public function cost_rule(){ $RuleModel = new \app\common\model\cost\Rules; $WAREHOUSEID = $this->auth->warehouseid; $params = $this->request->post(); $PackModel = new \app\common\model\wms\Pack; $PackcostModel = new \app\common\model\cost\Pack; $BackModel = new \app\common\model\cost\Back; $PackingModel = new \app\common\model\cost\Packing; $Paracodemodel = new \app\common\model\wms\Paracode; $STOREID = $params["storeid"]; $POSTCODE = $params["POSTCODE"]; $selectTime = [strtotime($params["selectTime"][0]),strtotime($params["selectTime"][1])]; $expressRule = $RuleModel->where(["STOREID"=>$STOREID])->where("endTime>=".$selectTime[0]." or endTime=0")->where("startTime<=".$selectTime[1]." or startTime=0")->where(["WAREHOUSEID"=>$WAREHOUSEID]); if($POSTCODE!="0"){ $expressRule ->where('POSTCODE like "%'.$POSTCODE.'%" or POSTCODE="*"'); } $expressRule = $expressRule->order("weight","desc")->select(); $data = $PackModel->field("ID,NAME")->where(["WAREHOUSEID"=>$WAREHOUSEID])->select(); array_unshift($data,["ID"=>0,"NAME"=>"无包装"]); $packsrule = $PackcostModel->where(["STOREID"=>$STOREID,"WAREHOUSEID"=>$WAREHOUSEID])->select(); foreach ($data as $key => $r){ foreach ($packsrule as $rr){ if($r["ID"]==$rr["packid"]){ $data[$key]["ruleid"] = $rr["id"]; $data[$key]["price"] = $rr["price"]; } } } $data2=$Paracodemodel->where(["TYPE"=>"301"])->select(); $packingrule = $PackingModel->where(["STOREID"=>$STOREID,"WAREHOUSEID"=>$WAREHOUSEID])->order("weight","desc")->select(); $data3 = $BackModel->where(["STOREID"=>$STOREID,"WAREHOUSEID"=>$WAREHOUSEID])->order("weight","desc")->select(); $this->success("获取成功",[$expressRule,$data,$packingrule,$data2,$data3]); } public function express_rule_del(){ $WAREHOUSEID = $this->auth->warehouseid; $params = $this->request->post(); $RuleModel = new \app\common\model\cost\Rules; $id = $params["id"]; $rule = $RuleModel->where(["id"=>$id,"WAREHOUSEID"=>$WAREHOUSEID])->find(); if($rule){ $res = $rule->delete(); }else{ $this->error("规则不存在"); } $this->success("删除成功",$res); } public function express_rule_save(){ $WAREHOUSEID = $this->auth->warehouseid; $params = $this->request->post(); $RuleModel = new \app\common\model\cost\Rules; $isAdd = $params["isAdd"]; $express_data = $params["express_data"]; $express_data["startTime"] = $express_data["startTime"]/1000; $express_data["endTime"] = $express_data["endTime"]/1000; $express_data["kilogramsegment"] = json_encode($express_data["kilogramsegment"]); $express_data["WAREHOUSEID"] = $WAREHOUSEID; if($isAdd){ $RuleModel->save($express_data); }else{ $data = $RuleModel->where(["id"=>$express_data["id"]])->find(); if($data){ $data->save($express_data); }else{ $this->error("保存失败,规则已经不存在"); } } $this->success("保存成功",$express_data); } public function copy_express_rule_save(){ $WAREHOUSEID = $this->auth->warehouseid; $params = $this->request->post(); $RuleModel = new \app\common\model\cost\Rules; $rule = $RuleModel->where(["id"=>$params["copy_rule"]])->find(); if($rule){ $insertdata = [ "type"=>$rule["type"], "NAME"=>$rule["NAME"], "POSTCODE"=>$rule["POSTCODE"], "maxweight"=>$rule["maxweight"], "fristweight"=>$rule["fristweight"], "continuedweight"=>$rule["continuedweight"], "firstprice"=>$rule["firstprice"], "continuedweightprice"=>$rule["continuedweightprice"], "region"=>$rule["region"], "kilogramsegment"=>$rule["kilogramsegment"], "minweight"=>$rule["minweight"], "startTime"=>$rule["startTime"], "endTime"=>$rule["endTime"], "STOREID"=>$rule["STOREID"], "weight"=>$rule["weight"], "WAREHOUSEID"=>$rule["WAREHOUSEID"], "surcharge"=>$rule["surcharge"] ]; $all_line = []; foreach ($params["copy_stores_array"] as $r){ $insertdata["STOREID"] = $r; array_push($all_line,$insertdata); } $saveresult = $RuleModel->saveAll($all_line); }else{ $this->error("规则已经不存在"); } $this->success("保存成功",$saveresult); } public function pack_rule_save(){ $WAREHOUSEID = $this->auth->warehouseid; $params = $this->request->post(); $PackModel = new \app\common\model\cost\Pack; $pack_data = $params["pack_data"]; $line = $PackModel->where(["packid"=>$pack_data["packid"],"WAREHOUSEID"=>$WAREHOUSEID,"STOREID"=>$pack_data["STOREID"]])->find(); $save_data = ["packid"=>$pack_data["packid"],"price"=>$pack_data["price"],"WAREHOUSEID"=>$WAREHOUSEID,"STOREID"=>$pack_data["STOREID"]]; if($line){ $res = $line->save($save_data); }else{ $res = $PackModel->save($save_data); } $this->success("保存成功",$res); } public function packing_rule_save(){ $WAREHOUSEID = $this->auth->warehouseid; $params = $this->request->post(); $PackModel = new \app\common\model\cost\Packing; $isAdd = $params["isAdd"]; $packing_data = $params["packing_data"]; $packing_data["starttime"] = $packing_data["starttime"]/1000; $packing_data["endtime"] = $packing_data["endtime"]/1000; $packing_data["WAREHOUSEID"] = $WAREHOUSEID; if($isAdd){ $PackModel->save($packing_data); }else{ $data = $PackModel->where(["id"=>$packing_data["id"]])->find(); if($data){ $data->save($packing_data); }else{ $this->error("保存失败,规则已经不存在"); } } $this->success("保存成功",$packing_data); } public function back_rule_save(){ $WAREHOUSEID = $this->auth->warehouseid; $params = $this->request->post(); $BackModel = new \app\common\model\cost\Back; $isAdd = $params["isAdd"]; $back_data = $params["back_data"]; $back_data["starttime"] = $back_data["starttime"]/1000; $back_data["endtime"] = $back_data["endtime"]/1000; $back_data["WAREHOUSEID"] = $WAREHOUSEID; if($isAdd){ $BackModel->save($back_data); }else{ $data = $BackModel->where(["id"=>$back_data["id"]])->find(); if($data){ $data->save($back_data); }else{ $this->error("保存失败,规则已经不存在"); } } $this->success("保存成功",$back_data); } public function config_pack_model_dowmload(){ $PackcostModel = new \app\common\model\cost\Pack; $PackModel = new \app\common\model\wms\Pack; $params = $this->request->post(); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $WAREHOUSEID = $this->auth->warehouseid; $STOREID = $params["STOREID"]; $title = '导入模板'; $worksheet->setTitle($title); $worksheet->fromArray( [ ['包装ID','包装名称','货主ID','价格'] ], '', 'A1' ); $data = $PackModel->field("ID,NAME")->where(["WAREHOUSEID"=>$WAREHOUSEID])->select(); $packsrule = $PackcostModel->where(["STOREID"=>$STOREID,"WAREHOUSEID"=>$WAREHOUSEID])->select(); array_unshift($data,["ID"=>0,"NAME"=>"无包装"]); foreach ($data as $key => $r){ foreach ($packsrule as $rr){ if($r["ID"]==$rr["packid"]){ $data[$key]["ruleid"] = $rr["id"]; $data[$key]["price"] = $rr["price"]; } } } $workers = []; foreach ($data as $r){ $price = isset($r["price"])?$r["price"]:0; array_push($workers,[$r["ID"],$r["NAME"],$STOREID,$price]); } $worksheet->fromArray( $workers, '', 'A2' ); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename=Excel导出.xlsx'); header('Cache-Control: max-age=0'); $write = IOFactory::createWriter($spreadsheet, 'Xlsx'); $write->save('php://output'); } public function import_pack_rule() { $WAREHOUSEID = $this->auth->warehouseid; $PackModel = new \app\common\model\cost\Pack; $file = request()->file('file'); // 获取上传的文件 if ($file) { $filePath = $file->getRealPath(); // 获取文件路径 $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filePath); // 加载 XLSX 文件 $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); // 读取数据 $save_data_arr = []; foreach($sheetData as $r){ $line = $PackModel->where(["packid"=>$r["A"],"WAREHOUSEID"=>$WAREHOUSEID,"STOREID"=>$r["C"]])->find(); $save_data = ["packid"=>$r["A"],"price"=>$r["D"],"WAREHOUSEID"=>$WAREHOUSEID,"STOREID"=>$r["C"]]; if(!$line){ array_push($save_data_arr,$save_data); }else{ $line->save($save_data); } } $res = $PackModel->saveAll($save_data_arr); $this->success("保存成功"); } $this->error("上传失败"); } }