123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413 |
- <?php
- namespace app\admin\controller;
- use app\BaseController;
- use think\App;
- use think\facade\Db;
- class Check extends BaseController
- {
- public $post = "";
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->post=$this->request->post();
- $token = isset($this->post['token']) ? trim($this->post['token']) : "";
- if($token==""){
- return error_show(101,'token不能为空');
- }
- $effetc = VerifyTokens($token);
- if(!empty($effetc) && $effetc['code']!=0){
- return error_show($effetc['code'],$effetc['message']);
- }
- }
- public function flist(){
- $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
- $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
- $condtion=['a.is_del'=>0,'b.is_del'=>0];
- $wsmcode =isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
- if($wsmcode==""){
- return error_show(1002,"仓库code不能为空");
- // $typecode= Db::name("good_stock")->where(["wsm_code"=>$wsmcode,'is_del'=>0])->column("good_type_code");
- }
- $condtion['c.wsm_code']=$wsmcode;
- $good_code =isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
- if($good_code!=""){
- $condtion['b.type_code'] = $good_code;
- }
- $goodcode =isset($this->post['good_code']) &&$this->post['good_code'] !=="" ? trim($this->post['good_code'])
- :"";
- if($goodcode!=""){
- $condtion['a.good_code'] = Db::raw("like '%{$goodcode}%'");
- }
- $good_name =isset($this->post['good_name']) &&$this->post['good_name'] !=="" ? trim($this->post['good_name'])
- :"";
- if($good_name!=""){
- $condtion['a.good_name'] = Db::raw("like '%{$good_name}%'");
- }
- $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
- if($supplierNo!=""){
- $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
- if(empty($supplier)){
- return error_show(1004,"未找到供应商信息");
- }
- // $typecode = Db::name("good_stock")->alias("a")->join("warehouse_info b","a.wsm_code=b.wsm_code","left")->where(["a.is_del"=>0,
- // "b.is_del"=>0,"b.supplierNo"=>$supplierNo])->column("a.good_type_code");
- // if(empty($typecode)){
- // return error_show(1004,"未找到供应商有关的商品信息");
- // }
- $condtion["a.gys_code"] = $supplierNo;
- }
- $count = Db::name("good_type")->alias("b")
- ->join("good a","a.good_code = b.good_code","left")
- ->join("good_stock c","c.good_type_code=b.type_code","left")
- ->where($condtion)->count();
- $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
- $list = Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
- ->join("good_stock c","c.good_type_code=b.type_code","left")
- ->where($condtion)->field("b.id,a.good_code,a.good_name,a.good_desc,a.brand,a.original_price,a.cg_saler,a.good_type,a.market_fee,a.gys_code,a.unit,
- a.sort_f,a.sort_s,a.sort_t,b.color,b.material,b.specs,b.is_main,b.type_code,b.attribute,b.status as bstatus,a.addtime,c.usable_stock,a.updatetime")
- ->page($page,$size)->select();
- $data=[];
- foreach ($list as $key=>$value){
- //$stock = Db::name("good_stock")->where(["good_type_code"=>$value['type_code'],"is_del"=>0])->sum("usable_stock");
- //$value['usable_stock']=$stock;
- $supplier = Db::name("supplier")->where(["code"=>$value['gys_code']])->find();
- $value['supplier_name'] =isset($supplier['name']) ?$supplier['name'] :"";
- $data[]=$value;
- }
- return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
- }
- public function list()
- {
- $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
- $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
- $where = ['a.is_del' => 0,'b.is_del'=>0];
- $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
- if ($start !="") {
- $where["a.addtime"]=Db::raw(">= '{$start}'");
- }
- $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
- if($end !=""){
- $where["a.addtime"] = Db::raw("<= '{$end}'");
- }
- $check_code = isset($this->post['check_code']) && $this->post['check_code'] !== "" ? trim($this->post['check_code']) : "";
- if ($check_code !== "") {
- $where['a.check_code'] = Db::raw("like '%$check_code%'");
- }
- $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : "";
- if ($wsm_code !== "") {
- $where['a.wsm_code'] = Db::raw("like '%$wsm_code%'");
- }
- $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !== "" ? trim($this->post['apply_name']) : "";
- if ($apply_name !== "") {
- $where['a.apply_name'] = $apply_name;
- }
- $type = isset($this->post['type']) && $this->post['type'] !== "" ? trim($this->post['type']) : "";
- if ($type !== "") {
- $where['a.type'] = $type;
- }
- $apply_id = isset($this->post['apply_id']) && $this->post['apply_id'] !== "" ? intval($this->post['apply_id']) : "";
- if ($apply_id!== "") {
- $where['a.apply_id'] = $apply_id;
- }
- $status= isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
- if ($status !== "") {
- $where['a.status '] = $status;
- }
- $count = Db::name('good_check')->alias('a')->join("warehouse_info b","a.wsm_code = b.wsm_code","left")
- ->join("supplier v","v.code=b.supplierNo","left")
- ->where($where)->count();
- $total = ceil($count / $size);
- $page = $page <= $total ? $page : $total;
- $list = Db::name('good_check')->alias('a')->join("warehouse_info b","a.wsm_code = b.wsm_code","left")
- ->join("supplier v","v.code=b.supplierNo","left")
- ->field("a.status,a.apply_id,a.apply_name,a.type,a.addtime,a.wsm_code,a.check_code,b.name,a.id,v.name as 'caname',v.code")->where($where)->page($page,$size)->order("a.id desc")->select();
- $data=[];
- foreach ($list as $key=>$value){
- $value['rename'] ='';
- if($value['apply_id']!=0){
- $depart = Db::name("depart_user")->alias("a")->leftJoin("company_item b","a.itemid = b.id")->where(['a.uid'=>$value['apply_id'],'a.is_del'=>0])
- ->column('b.name');
- // var_dump(Db::name("depart_user")->getLastSql());
- $value['rename'] =implode(",",$depart);
- }
- $data[] = $value;
- }
- return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
- }
- public function goodlist(){
- $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']) :"1";
- $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
- $where = ['is_del'=>0];
- $check_code = isset($this->post['check_code']) && $this->post['check_code'] !== "" ? trim($this->post['check_code']) : "";
- if ($check_code !== "") {
- $where['check_code'] = $check_code;
- }
- $count = Db::name('check_item')->where($where)->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total: $page;
- $list = Db::name('check_item')->where($where)->page($page,$size)->select();
- return app_show(0,"获取成功",['count'=>$count,'list'=>$list]);
- }
- public function create(){
- $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
- $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
- if($wsm_code==""){
- return error_show(1002,"盘点仓库编号不能为空");
- }
- $type = isset($this->post['type']) && $this->post['type'] !=="" ? intval($this->post['type']) :"";
- if($type==""){
- return error_show(1002,"盘点类型不能为空");
- }
- $check_code = makeNo("CK");
- $apply_id=GetUserInfo($token);
- if(empty($apply_id)||$apply_id['code']!=0){
- return error_show(1002,"申请人数据不存在");
- }
- $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $ri= isset($apply_name["data"]['nickname']) ? $apply_name["data"]['nickname'] : "";
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"0";
- // $dain=isset($this->post['good']) && $this->post['good'] !=="" ? trim($this->post['good']):"";
- // if($type==2){
- // if($dain==""||empty($dain)){
- // return error_show(1002,"商品不能为空");
- // }
- // }else{
- // if($type==1) {
- //
- // $dain= Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
- // ->join("good_stock c","c.good_type_code = b.type_code","left")->where(['c.wsm_code'=>$wsm_code,'b.is_del'=>0,'a.is_del'=>0])->where("c.is_del=0 or c.is_del is null")
- // ->field("b.type_code,a.good_name")->select();
- // //var_dump($dain);
- // }
- // if($dain==""){
- // return error_show(1003,"商品不能为空");
- // }
- // }
- Db::startTrans();
- try{
- $data=[
- "check_code"=>$check_code,
- "wsm_code"=>$wsm_code,
- "type"=>$type,
- "status"=>$status,
- "apply_id"=>$rm,
- "apply_name"=>$ri,
- "is_del"=>0,
- "addtime"=>date('Y-m-d H:i:s'),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $da= Db::name('good_check')->insert($data,true);
- // $dio=[];
- // if($da>0){
- // foreach ($dain as $value){
- // $st=Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
- // ->join("good_stock c","c.good_type_code = b.type_code","left")->where(['c.wsm_code'=>$wsm_code,'good_type_code'=>$value['type_code'],'b.is_del'=>0,'a.is_del'=>0])->where("c.is_del=0 or c.is_del is null")
- // ->field("b.type_code,a.good_name,c.wsm_code,c.wait_in_stock,c.wait_out_stock,c.usable_stock,c.good_type_code,a.original_price")->find();
- //
- // $temp=[];
- // $temp['good_name']=$st['good_name'];
- // $temp['origin_price']=$st['original_price'];
- // $temp['good_type_code']=$st['good_type_code'];
- // $temp['origin_num']=$st['usable_stock'];
- // $temp['check_num']=0;
- // $temp['diff_num']=0;
- // $temp['status']=0;
- // $temp['remark']="";
- // $temp['is_del']=0;
- // $temp['check_time']=date('Y-m-d H:i:s');
- // $temp['check_code']=$check_code;
- // $temp['addtime']=date("Y-m-d H:i:s");
- // $temp['updatetime']=date("Y-m-d H:i:s");
- // $dio[] =$temp;
- // }
- // $in= Db::name('check_item')->insertAll($dio);
- // }
- if($da){
- Db::commit();
- return error_show(0,"盘点创建成功");
- }else{
- Db::rollback();
- return error_show(1002,"创建失败");
- }
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1005,$e->getMessage());
- }
- }
- public function info(){
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
- if($id==""){
- return error_show(1002,"盘点单号不能为空");
- }
- $fo = Db::name('good_check')->alias('a')->join('warehouse_info b',"b.wsm_code=a.wsm_code","left")
- ->join('supplier c',"c.code=b.supplierNo","left")->field("c.name,c.code,a.*")
- ->where(['a.id'=>$id,'a.is_del'=>0])->find();
- if(empty($fo)){
- return error_show(1003,"未找到盘点信息");
- }
- $fi = Db::name('check_item')->where(['check_code'=>$fo['check_code'],'is_del'=>0])->select();
- $fo['item']=$fi;
- if(empty($fo)){
- return error_show(1002,"未找到盘点编号");
- }else{
- return app_show(0,"获取成功",$fo);
- }
- }
- public function edit()
- {
- $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
- $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
- $eid = Db::name('good_check')->where(['id' => $id, 'is_del' => 0])->find();
- if ($eid ==="") {
- return error_show(1002, "未找到盘点编号信息");
- }
- $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : "";
- if ($wsm_code == "") {
- return error_show(1002, "盘点仓库不能为空");
- }
- $type = isset($this->post['type']) && $this->post['type'] !== "" ? trim($this->post['type']) : "";
- if ($type == "") {
- return error_show(1002, "盘点类型不能为空");
- }
- $apply_id=GetUserInfo($token);
- if(empty($apply_id)||$apply_id['code']!=0){
- return error_show(1002,"申请人数据不存在");
- }
- $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $ri= isset($apply_name["data"]['nickname']) ? $apply_name["data"]['nickname'] : "";
- // $dain=isset($this->post['good']) && $this->post['good'] !=="" ? $this->post['good']:"";
- // if($type==2){
- // // var_dump($dain);
- // if($dain==""||empty($dain)){
- // return error_show(1002,"商品不能为空");
- // }
- // }else{
- // if($type==1) {
- //
- // $dain= Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
- // ->join("good_stock c","c.good_type_code = b.type_code","left")->where(['c.wsm_code'=>$wsm_code,'b.is_del'=>0,'a.is_del'=>0])->where("c.is_del=0 or c.is_del is null")
- // ->field("b.type_code,a.good_name")->select();
- // //var_dump($dain);
- // }
- // if($dain==""){
- // return error_show(1003,"商品不能为空");
- // }
- // }
- Db::startTrans();
- try {
- $var = [
- "wsm_code" => $wsm_code,
- "type" => $type,
- "apply_id" => $rm,
- "apply_name" => $ri,
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $up = Db::name('good_check')->where(['id'=>$id,'is_del' => 0])->save($var);
- // $dn =[];
- // if($up>0){
- // foreach ($dain as $value){
- // $st=Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
- // ->join("good_stock c","c.good_type_code = b.type_code","left")->where(['c.wsm_code'=>$wsm_code,'good_type_code'=>$value['type_code'],'b.is_del'=>0,'a.is_del'=>0])->where("c.is_del=0 or c.is_del is null")
- // ->field("b.type_code,a.good_name,c.wsm_code,c.wait_in_stock,c.wait_out_stock,c.usable_stock,c.good_type_code,a.original_price")->find();
- // $temp=[];
- // $temp['good_name']=$st['good_name'];
- // $temp['origin_price']=$st['original_price'];
- // $temp['good_type_code']=$st['good_type_code'];
- // $temp['origin_num']=$st['usable_stock'];
- // $temp['check_num']=0;
- // $temp['diff_num']=0;
- // $temp['status']=0;
- // $temp['remark']="";
- // $temp['is_del']=0;
- // $temp['check_time']=date('Y-m-d H:i:s');
- // $temp['check_code']=$eid['check_code'];
- // $temp['addtime']=date("Y-m-d H:i:s");
- // $temp['updatetime']=date("Y-m-d H:i:s");
- // $dn[] =$temp;
- // }
- // $np = Db::name('check_item')->where(['check_code'=>$eid['check_code'],'is_del'=>0])->update(['is_del'=>1,'updatetime'=>date('Y-m-d H:i:s')]);
- // $io = db::name('check_item')->insertAll($up);
- // var_dump(Db::name('check_item')->getLastSql());
- if ($up) {
- Db::commit();
- return error_show(0, "盘点更新成功");
- }
- Db::rollback();
- return error_show(1003,"盘点更新失败");
- } catch (\Exception $e) {
- Db::rollback();
- return error_show(1005, $e->getMessage());
- }
- }
- public function dell(){
- $id = $this->post['id'] && $this->post['id'] !=="" ? intval($this->post['id']) :"";
- if($id===""){
- return error_show(1004,"参数id不能为空");
- }
- $deln= Db::name('good_check')->where(['id'=>$id,'is_del'=>0])->find();
- if(empty($deln)){
- return error_show(1002,"未找到数据");
- }
- $sv = Db::name('good_check')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
- if($sv){
- return error_show(0,"删除成功");
- }else{
- return error_show(1002,"删除失败");
- }
- }
- public function statu()
- {
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
- if($id==""){
- return error_show(1002,"盘点id不能为空");
- }
- $stauts = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
- if($stauts===""){
- return error_show(1002,"状态不能为空");
- }
- $st = Db::name('good_check')->where(['id'=>$id,"is_del"=>0])->find();
- if(empty($st)){
- return error_show(1002,"盘点信息未找到");
- }
- $st['status']=$stauts;
- $st['updatetime']= date('Y-m-d H:i:s');
- $sv = Db::name('good_check')->save($st);
- if($sv){
- return error_show(0,"状态更新成功");
- }else{
- return error_show(1002,"状态更新失败");
- }
- }
- public function exportGood(){
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
- if($id==""){
- return error_show(1002,"盘点单号不能为空");
- }
- $fo = Db::name('good_check')->alias('a')->join('warehouse_info b',"b.wsm_code=a.wsm_code","left")
- ->join('supplier c',"c.code=b.supplierNo","left")->field("c.name,c.code,a.*")
- ->where(['a.id'=>$id,'a.is_del'=>0])->find();
- if(empty($fo)){
- return error_show(1003,"未找到盘点信息");
- }
- $fi = Db::name('check_item')->where(['check_code'=>$fo['check_code'],'is_del'=>0])->select();
- $fo['item']=$fi;
- if(empty($fo)){
- return error_show(1002,"未找到盘点编号");
- }else{
- return app_show(0,"获取成功",$fo);
- }
- }
- }
|