liufumingren e8605149c0 初始化
2026-08-06 17:04:35 +08:00

234 lines
9.1 KiB
PHP

<?php
namespace app\index\controller\wms;
use addons\wechat\model\WechatCaptcha;
use app\common\controller\Frontend;
use app\common\library\Ems;
use app\common\library\Sms;
use app\common\model\Attachment;
use think\Config;
use think\Cookie;
use think\Hook;
use think\Session;
use think\Validate;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\IOFactory;
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;
class Pda extends Frontend
{
protected $noNeedLogin = '*';
protected $noNeedRight = '*';
protected $layout = '';
public function scan_task()
{
$parmes = $this->request->post();
$this->layout = '';
$this->model = new \app\common\model\scan\Task;
$userid = $parmes["userid"];
$WAREHOUSEID = $parmes["WAREHOUSEID"];
$isAll = $parmes["isAll"];
$list = $this->model->where(["WAREHOUSEID"=>$WAREHOUSEID]);
if($isAll){
}else{
$list->where(["packed"=>0,"userid"=>$userid]);
}
$list = $list->order('id desc')
->select();
$result = ['rows' => $list];
return json($result);
}
public function scan_task_detail($ids = null){
$WAREHOUSEID = $parmes["WAREHOUSEID"];
$this->model = new \app\common\model\scan\Task;
$Smodel = new \app\common\model\scan\S;
$count = $Smodel->where(["userid"=>$this->auth->id,"taskid"=>$ids]);
$list = $Smodel->where(["userid"=>$this->auth->id,"taskid"=>$ids]);
$count = $count->count();
$list = $list->order('id','desc')->select();
$row = $this->model->where(["WAREHOUSEID"=>$WAREHOUSEID])->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
if (false === $this->request->isPost()) {
$this->view->assign('row', $row);
$this->view->assign('count', $count);
$this->view->assign('listss', $list);
$this->view->assign("auth", $this->auth);
return $this->view->fetch();
}
}
public function up_scan(){
$WAREHOUSEID = $parmes["WAREHOUSEID"];
$parmes = $this->request->post();
$StockModel = new \app\common\model\wms\Stock;
$stack_id = $parmes["stack_id"];
$Taskmodel = new \app\common\model\scan\Task;
$task = $Taskmodel->where(["id"=>$stack_id])->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
if(!$task){
return false;
}
$storeids = explode(",",$task["stores"]);
$stocks = $StockModel->with(['goods','store'])->where(["stock.WAREHOUSEID"=>$parmes['WAREHOUSEID']])->where('stock.BARCODE like "%'.$parmes['code'].'%"')->where(["WAREHOUSEID"=>$WAREHOUSEID]);
if(count($storeids)>0){
$stocks->where("stock.WARESTOREID","in",$storeids);
}
$stocks = $stocks->select();
foreach ($stocks as $r){
$r["goods"]["NAME"] .= '|'.$r["store"]["TITLE"];
}
//$val = $Smodel->save(['code'=>$parmes['code'],'userid'=>$parmes['userid'],'taskid'=>$parmes['taskid'],'scanTime'=>$parmes['scanTime']]);
return json($stocks);
}
public function packed(){
$WAREHOUSEID = $parmes["WAREHOUSEID"];
$parmes = $this->request->post();
$Taskmodel = new \app\common\model\scan\Task;
$stack_id = $parmes["stack_id"];
$task = $Taskmodel->where(["id"=>$stack_id])->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
$task->save(["packed"=>1]);
return 1;
}
public function up_scan2(){
$WAREHOUSEID = $parmes["WAREHOUSEID"];
$parmes = $this->request->post();
$StockModel = new \app\common\model\wms\Stock;
$Smodel = new \app\common\model\scan\S;
if($parmes["STOCKID"]){
$val = $Smodel->save(['code'=>$parmes['code'],'userid'=>$parmes['userid'],'taskid'=>$parmes['taskid'],'scanTime'=>$parmes['scanTime'],'STOCKID'=>$parmes['STOCKID'],"WAREHOUSEID"=>$WAREHOUSEID]);
}
$list = $Smodel->where(["taskid"=>$parmes['taskid']])->where(["WAREHOUSEID"=>$WAREHOUSEID])->select();
$skus = [];
foreach ($list as $r){
array_push($skus,$r['STOCKID']);
}
$stocks = $StockModel->where(["stock.WAREHOUSEID"=>$parmes['WAREHOUSEID']])->where("stock.STOCKID","in",$skus)->with(['goods','store'])->where(["WAREHOUSEID"=>$WAREHOUSEID])->select();
foreach ($stocks as $r){
$r["goods"]["NAME"] .= '|'.$r["store"]["TITLE"];
}
foreach ($list as $r){
foreach ($stocks as $stock){
if($r['STOCKID']==$stock['STOCKID']){
$r['STOCK'] = $stock;
}
}
}
return json($list);
}
public function del_scan(){
$WAREHOUSEID = $parmes["WAREHOUSEID"];
$parmes = $this->request->post();
$Smodel = new \app\common\model\scan\S;
$StockModel = new \app\common\model\wms\Stock;
$row = $Smodel->find($parmes['id']);
$row->delete();
$list = $Smodel->where(["taskid"=>$parmes['taskid']])->where(["WAREHOUSEID"=>$WAREHOUSEID])->select();
$skus = [];
foreach ($list as $r){
array_push($skus,$r['STOCKID']);
}
$stocks = $StockModel->where(["stock.WAREHOUSEID"=>$parmes['WAREHOUSEID']])->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("stock.STOCKID","in",$skus)->with(['goods','store'])->select();
foreach ($stocks as $r){
$r["goods"]["NAME"] .= '|'.$r["store"]["TITLE"];
}
foreach ($list as $r){
foreach ($stocks as $stock){
if($r['STOCKID']==$stock['STOCKID']){
$r['STOCK'] = $stock;
}
}
}
return json($list);
}
public function prints(){
$WAREHOUSEID = $parmes["WAREHOUSEID"];
$parmes = $this->request->post();
$Smodel = new \app\common\model\scan\S;
$StockModel = new \app\common\model\wms\Stock;
$list = $Smodel->field('count(*) as Count,ye4s_scan_s.*')->where(["WAREHOUSEID"=>$WAREHOUSEID])->where(["taskid"=>$parmes['taskid']])->group("STOCKID")->select();
$skus = [];
foreach ($list as $r){
array_push($skus,$r['STOCKID']);
}
$stocks = $StockModel->where(["stock.WAREHOUSEID"=>$parmes['WAREHOUSEID']])->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("stock.STOCKID","in",$skus)->with(['goods'])->select();
foreach ($list as $r){
foreach ($stocks as $stock){
if($r['STOCKID']==$stock['STOCKID']){
$r['STOCK'] = $stock;
}
}
}
return json($list);
}
public function scan_task_add(){
$WAREHOUSEID = $parmes["WAREHOUSEID"];
$params=$this->request->post();
$this->model = new \app\common\model\scan\Task;
$task_count = isset($params['count'])?$params['count']:1;
$insertData = [];
$time = time();
$stores = implode($params["stores"],",");
$n = "";
for($i=0;$i<$task_count;$i++){
if($task_count>1){
$n = ($i+1)."号";
}
array_push($insertData,["name"=>$params['name'].$n,"userid"=>$params["userid"],"create_time"=>$time,"stores"=>$stores,"WAREHOUSEID"=>$WAREHOUSEID]);
}
print_r($insertData);
$res = $this->model->saveAll($insertData);
return json($res);
}
public function scan_task_export($ids = null){
$WAREHOUSEID = $parmes["WAREHOUSEID"];
$this->model = new \app\common\model\scan\Task;
$Smodel = new \app\common\model\scan\S;
$count = $Smodel->where(["userid"=>$this->auth->id,"taskid"=>$ids])->count();
$list = $Smodel
->field("s.*,user.nickname as username")
->alias("s")
->where(["taskid"=>$ids])
->order('id','desc')
->join('jicang_user user', 's.userid = user.id')
->where(["WAREHOUSEID"=>$WAREHOUSEID])
->select();
$row = $this->model->where(["WAREHOUSEID"=>$WAREHOUSEID])->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$worksheet->setTitle($row['name']);
$worksheet->fromArray(
[
['条码','扫描时间','扫描工号']], '', 'A1' );
$workers = [];
foreach ($list as $r){
array_push($workers,[$r['code'],date('Y-m-d H:i:s', $r['scanTime']),$r['username']]);
}
$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');
exit();
}
}