post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : 1; $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : 10; $condtion = [['b.is_del', "=", 0], ['c.is_del', "=", 0]]; $wsmcode = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : ""; if ($wsmcode !== "") { $condtion[] = ['c.wsm_code', "=", $wsmcode]; } $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}%'"); $condtion[] = ['b.spuCode', "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}%'"); $condtion[] = ['b.good_name', "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, "未找到供应商信息"); // } // $wsmcode = Db::name("warehouse_info")->where(["is_del" => 0, "supplierNo" => $supplierNo])->column("wsm_code"); $condtion[] = ['b.supplierNo', "=", $wsmcode]; } $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : ""; if ($companyNo !== "") { $wsmcode = Db::name("warehouse_info")->where(['companyNo' => $companyNo, "is_del" => 0])->column("wsm_code"); $condtion[] = ["c.wsm_code", "in", $wsmcode]; } $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):""; if($relaComNo!="") { $wsmcode = Db::name("warehouse_info")->where(['companyNo' => $relaComNo, "is_del" => 0])->column("wsm_code"); $condtion[] = ["c.wsm_code", "in", $wsmcode]; } $stock_low = isset($this->post['stock_low']) && $this->post['stock_low'] !== "" ? intval($this->post['stock_low']) : ""; if ($stock_low != "") { $condtion[] = ['c.usable_stock', ">=", $stock_low]; } $stock_max = isset($this->post['stock_max']) && $this->post['stock_max'] !== "" ? intval($this->post['stock_max']) : ""; if ($stock_max != "") { $condtion[] = ['c.usable_stock', ">=", $stock_max]; } $stock_up = isset($this->post['stock_up']) && $this->post['stock_up'] !== "" ? trim($this->post['stock_up']) : ""; if ($stock_up != "") { $condtion[] = ['c.usable_stock', "<=", $stock_up]; } $warn_low = isset($this->post['warn_low']) && $this->post['warn_low'] !== "" ? intval($this->post['warn_low']) : ""; if ($warn_low !== "") { $condtion[] = ['c.warn_stock', ">=", $warn_low]; } $warn_up = isset($this->post['warn_up']) && $this->post['warn_up'] !== "" ? intval($this->post['warn_up']) : ""; if ($warn_up != "") { $condtion[] = ['c.warn_stock', "<=", $warn_up]; } $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !== "" ? intval($this->post['cat_id']) : ""; if ($cat_id != "") { $at = Db::name('cat')->where(['id' => $cat_id])->find(); if (empty($at)) { return error_show(1004, "未找到分类信息"); } $cat = manger([$at['id']], $at['level']); $condtion[] = ['b.cat_id', "in", $cat]; } $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : ""; if ($company_name !== "") $condtion[] = ["b.createrid", 'in', get_company_item_user_by_name($company_name)]; $count = Db::name("good") ->alias("b") ->join("good_stock c", "c.spuCode=b.spuCode", "left") ->where($condtion) ->count(); $page >= ceil($count / $size) ? $page = ceil($count / $size) : ""; $list = Db::name("good") ->alias("b") ->leftJoin("good_stock c", "c.spuCode=b.spuCode") ->where($condtion) ->field("b.*,c.id as stock_id,c.usable_stock,c.wait_in_stock,c.wait_out_stock,c.wsm_code") ->page($page, $size) ->select() ->toArray(); // $all_createrid = array_column($list,'createrid'); // $item = get_company_name_by_uid($all_createrid); $data = []; if ($list) { //品牌信息 $brands = Db::name('brand')->whereIn('id', array_column($list, 'brand_id'))->where('is_del', 0)->column('brand_name', 'id'); $units = Db::name('unit')->whereIn('id', array_column($list, 'good_unit'))->where('is_del', 0)->column('unit', 'id'); // $business = Db::name('business')->whereIn('companyNo', array_column($list, 'companyNo'))->where('is_del', 0)->column('company', 'companyNo'); $wsminfo =Db::name("warehouse_info")->whereIn("wsm_code",array_column($list, 'wsm_code'))->column("name,supplierNo","wsm_code"); $goodBasic =Db::name("good_basic")->whereIn("spuCode",array_column($list, 'spuCode'))->column("charger","spuCode"); $userCommon= \app\admin\common\User::getIns(); $supplier_temp =$userCommon->handle("getCodeAndName",["code"=>array_merge(array_column($list, 'companyNo'),array_column($list, 'supplierNo'),array_column($wsminfo,"supplierNo"))]); $supplier=$supplier_temp['data']??[]; foreach ($list as $key => $value) { // $supplier = Db::name("supplier")->where(["code" => $value['supplierNo']])->find(); $value['supplier_name'] = $supplier[$value['supplierNo']]??""; // $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b", "a.supplierNo=b.code")->where(["a.wsm_code" => $value['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find(); $value['wsm_name'] =$wsminfo[$value['wsm_code']]['name']?? ""; $value['wsm_supplier'] = $supplier[$wsminfo[$value['wsm_code']]['supplierNo']]??""; $value['wsm_supplierNo'] = $wsminfo[$value['wsm_code']]['supplierNo']?? ""; $value['can'] = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : []; $value['brand_name'] = isset($brands[$value['brand_id']]) ? $brands[$value['brand_id']] : ''; $value['unit'] = isset($units[$value['good_unit']]) ? $units[$value['good_unit']] : ''; $value['companyName'] = $supplier[$value['companyNo']]??""; $value['bninfo'] =Db::name("good_stock_info")->where([["stockid","=",$value['stock_id']],["balance_num",">",0]])->select()->toArray(); //规格信息 $spec = Db::name("good_spec")->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray(); $speclist = []; if (!empty($spec)) { foreach ($spec as $val) { $temp = []; $temp['spec_id'] = $val['spec_id']; $temp['spec_value_id'] = $val['spec_value_id']; $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find(); $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : ""; $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find(); $temp['spec_value_name'] = isset($spv["spec_value"]) ? $spv["spec_value"] : ""; $speclist[] = $temp; } } $value['specinfo'] = $speclist; $value['cgder'] =$goodBasic[$value['spuCode']]??""; // $value['company_name'] = $item[$value['createrid']]??''; $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}'"); $where[] = ['a.addtime', ">=", $start]; } $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : ""; if ($end != "") { // $where["a.addtime"] = Db::raw("<= '{$end}'"); $where[] = ['a.addtime', "<=", $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%'"); $where[] = ['a.check_code', "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%'"); $where[] = ['a.wsm_code', "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; $where[] = ['a.apply_name', "like", "%$apply_name%"]; } $type = isset($this->post['type']) && $this->post['type'] !== "" ? trim($this->post['type']) : ""; if ($type !== "") { // $where['a.type'] = $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; $where[] = ['a.apply_id', "=", $apply_id]; } $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : ""; if ($status !== "") { // $where['a.status '] = $status; $where[] = ['a.status', "=", $status]; } $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : ""; if ($companyNo !== "") { $condition[] = ["a.companyNo ", "=", $companyNo]; } // $role = $this->checkDataShare(); // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ['a.apply_id', 'in', $role[DataGroupModel::$type_全部]]; $role = $this->checkDataShare(); $hand = resign_hand_user($this->uid, 0); if (!empty($role[DataGroupModel::$type_全部])) { $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部])); $where[] = ['a.apply_id', 'in', $arr]; } $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):""; if($relaComNo!="") $where[]=['a.companyNo','=', $relaComNo]; $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,b.supplierNo as code,b.supplierName,a.companyNo") ->where($where) ->page($page, $size) ->order("a.id desc") ->select() ->toArray(); $userCommon= \app\admin\common\User::getIns(); $supplier_temp =$userCommon->handle("getCodeAndName",["code"=>array_unique(array_merge(array_column($list,"code"),array_column($list,"companyNo")))]); $supplier=$supplier_temp['data']??[]; $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); } //是否具有编辑权限 $value['is_allow_update'] = 0; if (in_array($this->roleid, [1, 33]) || in_array($value['apply_id'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1; $value['companyName'] = $supplier[$value['companyNo']]??''; $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]; $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :""; if($id==""){ return error_show(1002,"参数id不能为空"); } $fo = Db::name('good_check')->alias('a')->join('warehouse_info b',"b.wsm_code=a.wsm_code","left") ->field("a.*")->where(['a.id'=>$id,'a.is_del'=>0])->find(); if(empty($fo)){ return error_show(1003,"未找到盘点信息"); } if ($fo['check_code'] !== "") { $where['check_code'] = $fo['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,"盘点类型不能为空"); } $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) :""; if($companyNo==""){ return error_show(1002,"参数companyNo不能为空"); } $userCommon = \app\admin\common\User::getIns(); $tmp = $userCommon->handle('bInfo', ['companyNo' => $companyNo]); if (!isset($tmp['data']) || empty($tmp['data'])) return json_show(1002, '未找到业务公司'); // $company =Db::name("business")->where(['companyNo'=>$companyNo,"is_del"=>0])->find(); // if($company==false){ // 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= $this->uid;//isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : ""; $ri= $this->uname;//isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : ""; $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"0"; $remark = isset($this->post['remark']) && $this->post['remark'] !=="" ? intval($this->post['remark']) :""; Db::startTrans(); try{ $data=[ "check_code"=>$check_code, "wsm_code"=>$wsm_code, "type"=>$type, "status"=>$status, "companyNo"=>$companyNo, "remark"=>$remark, "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); if($da){ $orde = ["order_code" => $check_code, "status" => $data['status'], "action_remark" => '', "action_type" => "create"]; ActionLog::logAdd(['id' => $rm, 'nickname' => $ri], $orde, 'PDD', $data['status'], $orde); $process = ["order_code" => $check_code, "order_id" => $da, "order_status" => $data['status'], "order_type" => 'PDD', "before_status" => $data['status'], 'holder_id' => $rm]; ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], $process); 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,"参数id不能为空"); } $fo = Db::name('good_check')->alias('a')->join('warehouse_info b',"b.wsm_code=a.wsm_code","left") ->field("b.supplierNo as code,a.*") ->where(['a.id'=>$id,'a.is_del'=>0])->find(); if(empty($fo)){ return error_show(1003,"未找到盘点信息"); } $userCommon = \app\admin\common\User::getIns(); $tmp = $userCommon->handle('sInfo', ['code' => $fo['code']]); $fo['name'] = $tmp['data']['name']??""; $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']) : ""; $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : ""; 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_id["data"]['nickname']) ? $apply_id["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, "remark" => $remark, "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) { $orde = ["order_code"=>$eid['check_code'],"status"=>$eid['status'],"action_remark"=>'',"action_type"=>"edit"]; ActionLog::logAdd($this->post['token'],$orde,'qrd',$eid['status'],$orde); Db::commit(); return error_show(0, "盘点更新成功"); } Db::rollback(); return error_show(1003,"盘点更新失败"); } catch (\Exception $e) { Db::rollback(); return error_show(1005, $e->getMessage()); } } /** * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ 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){ $orde = ["order_code"=>$deln['check_code'],"status"=>$deln['status'],"action_remark"=>'',"action_type"=>"delete"]; ActionLog::logAdd($this->post['token'],$orde,'PDD',$deln['status'],['id'=>$id,'is_del'=>1, 'updatetime'=>date("Y-m-d H:i:s")]); $process=["order_code"=>$deln['check_code'],"order_status"=>$deln['status'],"order_type"=>'PDD']; ProcessOrder::workdel($process); //将对应的盘点单流程的数据都删掉(没有相关的中断节点,所以这里直接操作process_wait表) Db::name('process_wait') ->where([ 'order_type' => 'PDD', 'order_code' => $deln['check_code'], 'order_id' => $id, 'status' => ProcessWait::$status_wait, ])->update(['status' => ProcessWait::$status_interrupt]); return error_show(0,"删除成功"); }else{ return error_show(1002,"删除失败"); } } /** * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ 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']) :""; $remark = isset($this->post['remark']) && $this->post['remark'] !=="" ? trim($this->post['remark']) :""; 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,"盘点信息未找到"); } Db::startTrans(); try{ $temp = $st['status']; $st['status']=$stauts; $st['remark']=$remark; $st['updatetime']= date('Y-m-d H:i:s'); $sv = Db::name('good_check')->save($st); if($sv){ $orde = ["order_code"=>$st['check_code'],$temp,"action_remark"=>'',"action_type"=>"status"]; ActionLog::logAdd($this->post['token'],$orde,'PDD',$st['status'],$orde); if($stauts==1&&$temp==2){ $up = Db::name('check_item')->where(['check_code'=>$st['check_code'],"is_del"=>0])->save(['is_del'=>1, "updatetime"=>date("Y-m-d H:i:s")]); if($up==false){ Db::rollback(); return error_show(1003,"盘点结果删除失败"); } } if($stauts==2){ $nu = Db::name('check_item')->where(['check_code'=>$st['check_code'],"is_del"=>0])->select()->toArray(); if(empty($nu)){ Db::rollback(); return error_show(1003,"未上传盘点结果"); } } $process=["order_code"=>$st['check_code'],"order_id"=>$st['id'],"order_status"=>$stauts, "order_type"=>'PDD',"before_status"=>$temp, 'holder_id' => $st['apply_id']]; ProcessOrder::AddProcess($this->post['token'],$process); Db::commit(); return error_show(0,"状态更新成功"); } Db::rollback(); return error_show(1002,"状态更新失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1002,$e->getMessage()); } } //导出(盘点的明细) public function exportGood() { $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : ""; if ($id == "") { return error_show(1002, "参数id不能为空"); } $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,b.name,a.*") ->field("b.name,a.*") ->where(['a.id' => $id, 'a.is_del' => 0]) ->find(); if (empty($fo)) { return error_show(1003, "未找到盘点信息"); } $list = Db::name("good_stock_info")->alias("d") ->join("good_stock c", "c.id=d.stockid and d.balance_num>0", "left") ->join("good_basic b", "c.spuCode=b.spuCode", "left") ->where(['c.wsm_code' => $fo['wsm_code'], "b.is_del" => 0, "c.is_del" => 0]) ->field("d.bnCode '商品批次号',b.spuCode'商品编码',b.good_name '商品名称',b.craft_desc '商品描述',b.brand_id '品牌',b.good_unit '单位',b.supplierNo '供应商编码','' as '供应商名称','' as '一级分类','' as '二级分类','' as '三级分类',b.addtime '新建时间',c.wsm_code '仓库编码','' as '仓库名称',c.usable_stock '可用总库存',d.balance_num '批次库存数','' as '盘点库存'") ->select() ->toArray(); $data = []; $userCommon = \app\admin\common\User::getIns(); $tmp = $userCommon->handle('getCodeAndName', ['code' => array_column($list, "供应商编码")]); $supplier = $tmp['data'] ?? []; $unit = Db::name('unit') ->where(['id' => array_column($list, '单位')]) ->column('unit', 'id'); $brand = Db::name('brand') ->where(['id' => array_column($list, '品牌')]) ->column('brand_name', 'id'); $wsm = Db::name('warehouse_info') ->where(['wsm_code' => array_column($list, '仓库编码')]) ->column('name', 'wsm_code'); foreach ($list as $key => $value) { // $wsm = Db::name("warehouse_info")->where(['wsm_code'=>$value['仓库编码']])->find(); // $supplier = Db::name("supplier")->where(["code"=>$value['供应商编码']])->find(); $value['供应商名称'] = $supplier[$value['供应商编码']] ?? ""; $value['仓库名称'] = $wsm[$value['仓库编码']] ?? '';//isset($wsm['name']) ?$wsm['name'] :""; // $unit =Db::name("unit")->where(["id"=>$value['单位']])->find(); // $brand =Db::name("brand")->where(["id"=>$value['品牌']])->find(); $value['单位'] = $unit[$value['单位']] ?? '';//isset($unit['unit']) ?$unit['unit'] :""; $value['品牌'] = $brand[$value['品牌']] ?? '';//isset($brand['brand_name']) ?$brand['brand_name'] :""; $data[] = $value; } if (empty($data)) { $data[] = ["暂无商品信息" => '']; } $headerArr = array_keys($data[0]); excelSave('盘点商品', $headerArr, $data); // return app_show(0,"获取成功",$data); } //导入 public function importGood(){ $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :""; if($id==""){ return error_show(1002,"参数id不能为空"); } $fo = Db::name('good_check')->alias('a')->join('warehouse_info b',"b.wsm_code=a.wsm_code","left") ->field("b.supplierNo as code,b.name,a.*") ->where(['a.id'=>$id,'a.is_del'=>0])->find(); if(empty($fo)){ return error_show(1003,"未找到盘点信息"); } if($fo['status']>=2){ return error_show(1003,"盘点已提交审核,不可提交盘点数据"); } $data = isset($this->post['data']) && $this->post['data'] !=="" ?$this->post['data'] :""; if($data=="" || empty($data)){ return error_show(1003,"盘点数据不能为空"); } $insert=[]; foreach ($data as $value){ if($value["value0"]==""){ return error_show(1003,"商品批次编号不能为空"); } if($value["value16"]===""){ continue; } $stock = Db::name("good_stock")->alias("a") ->join("good_stock_info b","a.id=b.stockid","left") ->where(["a.spuCode"=>$value["value1"],"wsm_code"=>$fo['wsm_code'],"bnCode"=>$value['value0'],"is_del"=>0])->find(); $stock_num = isset($stock) ? $stock['balance_num']:0; $insert[]=[ "spuCode"=>$value["value1"], "bnCode"=>$value["value0"], "good_name"=>$value["value2"], "origin_price"=>0, "origin_num"=>isset($stock) ? $stock['balance_num']:0, "check_num"=>$value["value16"], "is_profit"=>intval($value["value16"])>=$stock_num ?0:1, "diff_num"=>intval($value["value16"])>=$stock_num ?intval($value["value16"])-$stock_num:$stock_num-intval($value["value16"]), 'addtime'=>date("Y-m-d H:i:s"), 'updatetime'=>date("Y-m-d H:i:s"), "check_code"=>$fo['check_code'] ]; } if(empty($insert)){ return error_show(1003,"盘点数据不可用"); } Db::startTrans(); try{ $inst = Db::name("check_item")->insertAll($insert); if($inst){ $check_up = Db::name("good_check")->where(["check_code"=>$fo['check_code'],"is_del"=>0])->save(["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]); if($check_up){ $orde = ["order_code"=>$fo['check_code'],$fo['status'],"action_remark"=>'',"action_type"=>"edit"]; ActionLog::logAdd($this->post['token'],$orde,'PDD',2,["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]); $process = ["order_code" => $fo['check_code'], "order_id" => $fo['id'], "order_status" => 2, "order_type" => 'PDD', "before_status" => $fo['status'], 'holder_id' => $fo['apply_id']]; ProcessOrder::AddProcess($this->post['token'],$process); Db::commit(); return app_show(0,"盘点数据导入成功"); } } Db::rollback(); return error_show(1002,"盘点数据导入失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1002,"盘点数据导入失败"); } } }