post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1"; $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10"; $where =[['p.is_del',"=",0]]; $bkcode = isset($this->post['bk_code']) && $this->post['bk_code']!="" ? trim($this->post['bk_code']):""; if($bkcode!=""){ //$where['p.bk_code'] = $bk_code; $where[]=['p.bk_code',"like","%{$bkcode}%"]; } $good_code = isset($this->post['good_code']) && $this->post['good_code']!="" ? trim($this->post['good_code']):""; if($good_code!=""){ // $where['p.good_code'] = $good_code; $where[]=['p.spuCode',"like","%{$good_code}%"]; } $good_type_code = isset($this->post['good_type_code']) && $this->post['good_type_code']!="" ? trim($this->post['good_type_code']):""; if($good_type_code!=""){ // $where['p.good_type_code'] = $good_type_code; $where[]=['p.good_type_code',"like","%{$good_type_code}%"]; } $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):""; if($wsm_code!=""){ //$where['p.wsm_code'] = $wsm_code; $where[]=['p.wsm_code',"=",$wsm_code]; } $good_name = isset($this->post['good_name']) && $this->post['good_name']!="" ? trim($this->post['good_name']):""; if($good_name!=""){ // $where['p.good_name'] = Db::raw(" like '%{$good_name}%'"); $where[]=['p.good_name',"like","%{$good_name}%"]; } $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name']):""; if($apply_name!=""){ // $where['p.apply_name'] =Db::Raw("like '%{$apply_name}%'"); $where[]=['p.apply_name',"like","%{$apply_name}%"]; } $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):""; if($status!==""){ // $where['p.status'] = $status; $where[]=['p.status',"=",$status]; } $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:""; if($start!==""){ //$where['p.addtime'] = Db::Raw(">= '{$start}'"); $where[]=['p.addtime',">=",$start]; } $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:""; if($end!==""){ // $where['p.addtime'] = Db::Raw("<= '{$end}'"); $where[]=['p.addtime',"<=",$end]; } // $role=$this->checkRole(); $condition=[]; // if(!empty($role['write']) && $this->uid!=""){ // // $where[]=["a.apply_id","in",$role['write']]; // $condition .="p.cgderid = {$this->uid} or p.apply_id in (".implode(',',$role['write']).")"; // } //超管、库管、库管-张凯旋、boss能看到所有,其他人只能看到自己创建的和身为采购员的单子 $super_roleid = array_merge([1, 33], config('app.wsm_cgder_role')); if (!in_array($this->roleid, $super_roleid)) { $role = $this->checkDataShare(); $hand =resign_hand_user($this->uid,0); if (!empty($role[DataGroupModel::$type_全部])){ $arr= array_unique(array_merge($hand,$role[DataGroupModel::$type_全部])); $condition[]= ["p.apply_id","in",$arr]; $condition[]= ["p.cgderid","in",$hand]; } // $condition .="p.cgderid in {$hand} or p.apply_id in {$hand} or p.apply_id in (" // .implode(',',$role[DataGroupModel::$type_全部]).")"; } $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : ""; if ($company_name !== "") $where[] = ["p.apply_id", 'in', get_company_item_user_by_name($company_name)]; $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] !== "" ? trim($this->post['relaComNo']) : ""; if ($relaComNo !== "") $where[] = ["p.companyNo", '=', $relaComNo]; $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : ""; if ($supplierNo !== "") $where[] = ["p.supplierNo", '=', $supplierNo]; // if(!empty($role['platform']) ){ // $where[]=["p.platform_id","in",$role['platform']]; // } $count=Db::name("purchease") ->alias('p') ->where($where) ->where(function ($query)use ($condition){$query->whereOr($condition);}) ->count(); $total = ceil($count/$size); $page = $page >= $total ? $total : $page; $list = Db::name("purchease") ->alias('p') ->where($where) ->where(function ($query)use ($condition){$query->whereOr($condition);}) ->page($page,$size) ->order("p.addtime desc") ->select() ->toArray(); $data=[]; $all_createrid = array_column($list,'apply_id'); $item = get_company_name_by_uid($all_createrid); $userCommon = \app\admin\common\User::getIns(); $wsmCodes = array_column($list,'wsm_code'); $wsmcode = Db::name("warehouse_info")->alias("a") ->where(["a.wsm_code"=>$wsmCodes])->column("a.name as wsm_name,a.supplierNo as code","wsm_code"); $names = $userCommon->handle('getCodeAndName', ['code' =>array_merge(array_column($wsmcode,"code"),array_column($list,"companyNo"),array_column($list,"supplierNo"))]); $wsmsupplier = $names['data']??[]; foreach ($list as $value){ $value['wsm_name'] =isset($wsmcode[$value['wsm_code']]['wsm_name']) ? $wsmcode[$value['wsm_code']]['wsm_name']:""; $value['wsm_supplier'] = isset($wsmcode[$value['wsm_code']]['code'])? $wsmsupplier[$wsmcode[$value['wsm_code']]['code']]??"" :""; $value['wsm_supplierNo'] =$wsmcode[$value['wsm_code']]['code']??""; $value['companyName'] = $wsmsupplier[$value['companyNo']]??""; $value['supplierName'] = $wsmsupplier[$value['supplierNo']]??""; $value['file_name'] =''; if($value['file_url']){ $file= basename($value['file_url']); $value['file_name'] =substr($file,0,strripos($file,"_")); } $value['company_name'] = $item[$value['apply_id']]??''; $data[]=$value; } return app_show(0,"获取成功",["count"=>$count,"list"=>$data]); } public function add(){ $token = isset($this->post['token']) ? trim($this->post['token']) : ""; if($token==""){ return error_show(101,'token不能为空'); } $good_code = isset($this->post['good_code']) && $this->post['good_code']!=""?trim($this->post['good_code']):""; if($good_code==""){ return error_show(1004,"参数good_code不能为空"); } $good_num = isset($this->post['good_num'])&& $this->post['good_num']!==""? intval($this->post['good_num']):""; if($good_num===""){ return error_show(1004,"参数good_code不能为空"); } $file_url = isset($this->post['file_url'])&& $this->post['file_url']!==""? trim($this->post['file_url']):""; if($file_url===""){ return error_show(1004,"参数file_url不能为空"); } $mark =isset($this->post['remark'])&&$this->post['remark']!=""?trim($this->post['remark']):""; if($mark==""){ return error_show(1004,"参数remark不能为空"); } $good =Db::name("good_basic")->where([["spuCode","=",$good_code],["is_del","=",0]])->find(); if($good==false){ return error_show(1004,"未找到商品数据"); } $userCommon= \app\admin\common\User::getIns(); $supplier_temp =$userCommon->handle("sInfo",["code"=>$good['supplierNo']]); if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1002,"商品供应商不存在"); $holder_id=$supplier_temp['data']['personid']??0; $holder_name=$supplier_temp['data']['person']??0; $coma =$userCommon->handle("getCodeAndName",["code"=>[$good['companyNo'],$good['supplierNo']]]); // if($coma['code']!=0 || empty($coma['data']) ) return error_show(1002,"商品业务公司不存在"); //校验数量 $goodnake = Db::name("good_nake") ->field('id,min_num') ->where([["spuCode", "=", $good_code], ["is_del", "=", 0]]) ->order("min_num asc") ->find(); if (empty($goodnake)) return error_show(1004, '未找到商品成本数据'); $minnum = $goodnake['min_num']; if($good['is_stock']==1 && $good['stock_moq']>0){ $minnum =$good['stock_moq']; } if ($minnum > $good_num) return error_show(1004, '该商品最低采购数量为' . $minnum); $lastime = isset($this->post['lastime'])&&$this->post['lastime']!="" ? $this->post['lastime']:""; if($lastime===""){ return error_show(1004,"参数lastime不能为空"); } $bk_code=makeNo("BK"); $info = [ "spuCode"=>$good['spuCode'], "good_name"=>$good['good_name'], "good_num"=>$good_num, "wsm_code"=>'', "companyName"=>$coma['data'][$good['companyNo']]??'', "companyNo"=>$good['companyNo'], "supplierName"=>$coma['data'][$good['supplierNo']]??'', "supplierNo"=>$good['supplierNo'], "file_url"=>$file_url, "lasttime"=>$lastime, "status"=>1, "remark"=>$mark, "cgder" => $good['charger'],//$good['creater'], "cgderid" => $good['chargerid'],//$good['createrid'], "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s"), "apply_id"=>$this->uid, "apply_name"=>$this->uname, "bk_code"=>$bk_code ]; $in = Db::name("purchease")->insert($info,true); if($in>0){ //备库单,推给供应商负责人 $order = ["order_type" => 'BHD', "order_code" => $bk_code, "order_id" => $in, "order_status" => 1, "before_status" => 1, 'wait_id' => $holder_id, 'wait_name' => $holder_name]; ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $order); $ste = ["order_code" => $bk_code, "status" => 0, "action_remark" => '', "action_type" => "create"]; ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $ste, "BHD", 1, $info); //台账记录 Db::name('standing_book') ->insert([ 'standBookNo' => makeNo("IO"), 'bk_code' => $bk_code, 'purchease_id' => $in, 'addtime' => date('Y-m-d H:i:s'), 'updatetime' => date('Y-m-d H:i:s') ]); return app_show(0,"新建成功",['bk_code'=>$bk_code]); }else{ return error_show(1005,"新建失败"); } } /** * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function copy(){ $id = isset($this->post['id']) ? intval($this->post['id']) : ""; if($id==""){ return error_show(1001,'id不能为空'); } $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find(); if(empty($info)){ return error_show(1002,'未找到数据'); } $userCommon= \app\admin\common\User::getIns(); $supplier_temp =$userCommon->handle("sInfo",["code"=>$info['supplierNo']]); if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1002,"供应商不存在"); $holder_id=$supplier_temp['data']['personid']??0; $holder_name=$supplier_temp['data']['person']??0; $bk_code=makeNo("BK"); $info['bk_code']=$bk_code; $info['status']=1; $info['addtime']=date("Y-m-d H:i:s"); $info['updatetime']=date("Y-m-d H:i:s"); $info['apply_id']=$this->uid; $info['apply_name']=$this->uname; unset($info['id']); $in = Db::name("purchease")->insert($info,true); if($in>0){ $order = ["order_type" => 'BHD', "order_code" => $bk_code, "order_id" => $in, "order_status" => 1, "before_status" => 1, 'wait_id' =>$holder_id, 'wait_name' =>$holder_name]; ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $order); $ste = ["order_code"=>$bk_code,"status"=>0,"action_remark"=>'',"action_type"=>"create"]; ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname],$ste,"BHD",1,$info); return app_show(0,"新建成功",['bk_code'=>$bk_code]); }else{ return error_show(1005,"新建失败"); } } /** * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function info(){ $id = isset($this->post['id']) ? intval($this->post['id']) : ""; if($id==""){ return error_show(1001,'id不能为空'); } $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find(); if(empty($info)){ return error_show(1002,'未找到数据'); } $good =Db::name("good_basic")->where([["spuCode","=", $info['spuCode']],["is_del","=",0]])->find(); if($good==false){ return error_show(1004,"未找到商品数据"); } $int= isset($good['cat_id']) && $good['cat_id'] !=0 ? made($good['cat_id']):[]; $metal = \think\facade\Config::get("noble"); $info['noble_metal']= isset($metal[$good['noble_metal']]) && $good['noble_metal'] !=''?$metal[$good['noble_metal']]:''; $info['noble_id']= isset($good['noble_metal']) && $good['noble_metal'] !='' ? $good['noble_metal']:""; $info['wsm_name']=""; $info['file_name'] =''; if($info['file_url']){ $file= basename($info['file_url']); $info['file_name'] =substr($file,0,strripos($file,"_")); } // $userCommon = \app\admin\common\User::getIns(); if($info['wsm_code']!=""){ $wsmcode = Db::name("warehouse_info")->where(["wsm_code"=>$info['wsm_code']])->field("name as wsm_name,supplierNo,supplierName,contactor,contactor_name")->find(); // $tmpd = $userCommon->handle('getCodeAndName', ['code' =>$wsmcode['supplierNo']]); $info['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:""; $info['wsm_supplier'] =$wsmcode['supplierName']??""; $info['wsm_supplierNo'] =$wsmcode['supplierNo']??""; $info['wsm_contactor'] =$wsmcode['contactor']??""; $info['wsm_contactor_name'] =$wsmcode['contactor_name']??""; } // $supplier =Db::name("supplier")->where(["code"=>$info['supplierNo']])->find(); // $tmp = $userCommon->handle('getCodeAndName', ['code' =>[$info['companyNo'],$info['supplierNo']]]); // if (!isset($tmp['code']) || $tmp['code'] != 0) return json_show($tmp['code'], $tmp['message'], $tmp['data']); // $sinfo = $userCommon->handle('sInfo', ['code' => $info['supplierNo']]); // $info['person'] = $sinfo['data']['person'] ?? ''; // $company =Db::name("business")->where(["companyNo"=>$info['companyNo']])->find(); // $info['company_name'] = $info['companyName'] ?? ''; // $info['supplier_name'] = $info['supplierName'] ?? ''; $info['can']=$int; return app_show(0,"获取成功",$info); } public function edit(){ $token = isset($this->post['token']) ? trim($this->post['token']) : ""; if($token==""){ return error_show(101,'token不能为空'); } $id = isset($this->post['id']) ? intval($this->post['id']) : ""; if($id==""){ return error_show(1001,'id不能为空'); } $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find(); if(empty($info)){ return error_show(1002,'未找到数据'); } $customer = isset($this->post['customer_code'])&&$this->post['customer_code']!="" ?trim($this->post['customer_code']):""; if($customer==""){ return error_show(1004,"参数customer_code不能为空"); } $supplier = isset($this->post['supplier_code'])&&$this->post['supplier_code']!="" ?trim($this->post['supplier_code']):""; if($supplier==""){ return error_show(1004,"参数supplier_code不能为空"); } $good_code = isset($this->post['good_code']) && $this->post['good_code']!=""?trim($this->post['good_code']):""; if($good_code==""){ return error_show(1004,"参数good_code不能为空"); } $good_num = isset($this->post['good_num'])&& $this->post['good_num']!==""? intval($this->post['good_num']):""; if($good_num===""){ return error_show(1004,"参数good_code不能为空"); } $file_url = isset($this->post['file_url'])&& $this->post['file_url']!==""? trim($this->post['file_url']):""; if($file_url===""){ return error_show(1004,"参数file_url不能为空"); } $mark =isset($this->post['remark'])&&$this->post['remark']!=""?trim($this->post['remark']):""; if($mark==""){ return error_show(1004,"参数remark不能为空"); } $good =Db::name("good_basic")->where([["spuCode","=", $good_code],["is_del","=",0]])->find(); if($good==false){ return error_show(1004,"未找到商品数据"); } // $data = GetUserInfo($token); // if((!empty($data) && $data['code']!=0) ||empty($data) ){ // return error_show($data['code'],$data['message']); // } // $userinfo = $data['data']; $up = [ "spuCode"=>$good_code, "good_name"=>$good['good_name'], "good_num"=>$good_num, // "skuCode"=>$good['skuCode'], "companyNo"=>$customer, "supplierNo"=>$supplier, "file_url"=>$file_url, "remark"=>$mark, "updatetime"=>date("Y-m-d H:i:s"), ]; $in = Db::name("purchease")->where($info)->save($up); if($in){ $order=["order_type"=>'BHD',"order_code"=>$info['bk_code'],"order_id"=>$info['id'],"order_status"=>$info['status'],"before_status"=>1, 'holder_id' => $info['apply_id']]; ProcessOrder::AddProcess($this->post['token'],$order); $ste = ["order_code"=>$info['bk_code'],"status"=>$info['status'],"action_remark"=>'',"action_type"=>"edit"]; ActionLog::logAdd($this->post['token'],$ste,"BHD",$info['status'],$up); return app_show(0,"更新成功",['bk_code'=>$info['bk_code']]); }else{ return error_show(1005,"更新失败"); } } public function delete(){ $id = isset($this->post['id']) ? intval($this->post['id']) : ""; if($id==""){ return error_show(1001,'id不能为空'); } $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find(); if(empty($info)){ return error_show(1002,'未找到数据'); } $info['is_del']=1; $info['updatetime']=date("Y-m-d H:i:s"); $up = Db::name("purchease")->update($info); if($up){ $order=["order_type"=>'BHD',"order_code"=>$info['bk_code'],"order_id"=>$info['id'],"order_status"=>$info['status']]; ProcessOrder::workdel($order); $ste = ["order_code"=>$info['bk_code'],"status"=>$info['status'],"action_remark"=>'',"action_type"=>"delete"]; ActionLog::logAdd($this->post['token'],$ste,"BHD",$info['status'],$info); } return $up ? app_show(0,"删除成功"):error_show(1005,"删除失败"); } public function status(){ $id = isset($this->post['id']) ? intval($this->post['id']) : ""; if($id==""){ return error_show(1001,'id不能为空'); } $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find(); if(empty($info)){ return error_show(1002,'未找到数据'); } $userCommon= \app\admin\common\User::getIns(); $supplier_temp =$userCommon->handle("sInfo",["code"=>$info['supplierNo']]); if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1002,"采购单供应商不存在"); $holder_id=$supplier_temp['data']['personid']??0; $holder_name=$supplier_temp['data']['person']??0; $status = isset($this->post['status'])&&$this->post['status']!=='' ? intval($this->post['status']) : ""; if($status===""){ return error_show(1001,'status不能为空'); } if($status==3 && $info['status']==2)return error_show(1001,'备库单已完成无法取消'); $temp = $info['status']; $info['status']= $status; $info['updatetime']=date("Y-m-d H:i:s"); $up = Db::name("purchease")->update($info); if($up){ $order = ["order_type" => 'BHD', "order_code" => $info['bk_code'], "order_id" => $info['id'], "order_status" => $status, "before_status" => $temp, 'holder_id' => $info['apply_id']]; ProcessOrder::AddProcess($this->post['token'],$order); $ste = ["order_code"=>$info['bk_code'],"status"=> $temp,"action_remark"=>'',"action_type"=>"status"]; ActionLog::logAdd($this->post['token'],$ste,"BHD",$status,$info); return app_show(0,"更新成功",['bk_code'=>$info['bk_code']]); }else{ return error_show(1005,"更新失败"); } } //废弃 public function addFeed(){ $token = isset($this->post['token']) ? trim($this->post['token']) : ""; if($token==""){ return error_show(101,'token不能为空'); } $id = isset($this->post['id']) ? intval($this->post['id']) : ""; if($id==""){ return error_show(1001,'id不能为空'); } $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find(); if(empty($info)){ return error_show(1002,'未找到备库数据'); } if($info['status']!=1){ return error_show(1002,'备库数据状态有误'); } $num = isset($this->post['num']) && $this->post['num']!=="" ? intval($this->post['num']):""; if($num==''){ return error_show(1002,'参数num 不能为空或零'); } $expecttime = isset($this->post['expecttime'])&&$this->post['expecttime']!=''?$this->post['expecttime'] :""; if($expecttime==''){ return error_show(1002,'参数expecttime 不能为空'); } $wsm_type = isset($this->post['wsm_type'])&&$this->post['wsm_type']!="" ? intval($this->post['wsm_type']):""; if($wsm_type==""){ return error_show(1002,'参数wsm_type 不能为空'); } $wsm_code = isset($this->post['wsm_code'])&&$this->post['wsm_code']!="" ? trim($this->post['wsm_code']):""; if($wsm_code==""){ return error_show(1002,'参数wsm_code 不能为空'); } $wsminfo = Db::name("warehouse_info")->where(['wsm_code'=>$wsm_code,"wsm_type"=>$wsm_type,"is_del"=>0])->find(); if(empty($wsminfo)){ return error_show(1002,'未找到仓库数据'); } $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!="" ? trim($this->post['supplierNo']):""; if($supplierNo==""){ return error_show(1002,'参数supplierNo 不能为空'); } $supplie = Db::name("supplier")->where(['code'=>$supplierNo,"is_del"=>0])->find();//废弃 if(empty($supplie)){ return error_show(1002,'未找到供应商'); } $good_price = isset($this->post['good_price'])&&$this->post['good_price']!=="" ? $this->post['good_price']:""; if($good_price===""){ return error_show(1002,'参数good_price 不能为空'); } $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=="" ? $this->post['pakge_fee']:0; $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=="" ? $this->post['cert_fee']:0; $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=="" ? $this->post['open_fee']:0; $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=="" ? $this->post['delivery_fee']:0; $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=="" ? $this->post['mark_fee']:0; $teach_fee = isset($this->post['teach_fee'])&&$this->post['teach_fee']!=="" ? $this->post['teach_fee']:0; $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!=="" ? $this->post['nake_fee']:0; $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=="" ? $this->post['demo_fee']:0; $weight = isset($this->post['weight'])&&$this->post['weight']!=="" ? $this->post['weight']:0; $diff_weight =isset($this->post['diff_weight'])&&$this->post['diff_weight']!=="" ? $this->post['diff_weight']:0; $diff_price =isset($this->post['diff_price'])&&$this->post['diff_price']!=="" ? $this->post['diff_price']:0; $remark =isset($this->post['remark'])&&$this->post['remark']!=="" ? $this->post['remark']:''; $data = GetUserInfo($token); if((!empty($data) && $data['code']!=0) ||empty($data) ){ return error_show($data['code'],$data['message']); } $userinfo = $data['data']; $data=[ "bkcode"=>$info['bk_code'], "warehouse"=>$wsm_code, "wsm_type"=>$wsm_type, "num"=>$num, 'expecttime'=>$expecttime, 'supplier'=>isset($supplie) && $supplie['code']!=''? $supplie['code']:'', 'good_price'=>$good_price, 'pakge_fee'=>$pakge_fee, 'cert_fee'=>$cert_fee, 'open_fee'=>$open_fee, 'mark_fee'=>$mark_fee, 'teach_fee'=>$teach_fee, 'nake_fee'=>$nake_fee, 'demo_fee'=>$demo_fee, 'delivery_fee'=>$delivery_fee, 'weight'=>$weight, 'remark'=>$remark, 'diff_weight'=>$diff_weight, 'diff_price'=>$diff_price, 'purchaser'=>$userinfo['nickname'], 'purchaser_id'=>$userinfo['id'], "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; Db::startTrans(); try{ $in = Db::name('purchease_feedback')->insert($data,true); if($in>0){ $order=["order_type"=>'FKD',"order_code"=>$info['bk_code'],"order_id"=>$in, "order_status"=>0,"before_status"=>1]; ProcessOrder::AddProcess($this->post['token'],$order); $ste = ["order_code"=>$info['bk_code'],"status"=>0,"action_remark"=>'',"action_type"=>"create"]; ActionLog::logAdd($this->post['token'],$ste,"FKD",0,$data); $temp=$info['status']; $info['status']=2; $info['wsm_code']=$wsm_code; $info['addtime']=date("Y-m-d H:i:s"); $ood=Db::name('purchease')->save($info); if($ood){ $order=["order_type"=>'BHD',"order_code"=>$info['bk_code'],"order_id"=>$info['id'], "order_status"=>$info['status'],"before_status"=>$temp, 'holder_id' => $info['apply_id']]; ProcessOrder::AddProcess($this->post['token'],$order); $ste = ["order_code"=>$info['bk_code'],"status"=>$temp,"action_remark"=>'',"action_type"=>"status"]; ActionLog::logAdd($this->post['token'],$ste,"BHD",$info['status'],$info); Db::commit(); return app_show(0,"新建成功"); } } Db::rollback(); return error_show(1005,"新建失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1005,"新建失败"); } // return $in ? app_show(0,"新建成功"):error_show(1005,"新建失败"); } public function delFeed(){ $id = isset($this->post['id']) ? intval($this->post['id']) : ""; if($id==""){ return error_show(1001,'id不能为空'); } $feed = Db::name("purchease_feedback")->where(['id'=>$id,'is_del'=>0])->find(); if(empty($feed)){ return error_show(1004,'未找到数据'); } if($feed['status']==1){ return error_show(1004,'反馈数据已采用无法删除'); } $feed['is_del']= 1; $feed['updatetime']=date("Y-m-d H:i:s"); $up = Db::name("purchease_feedback")->update($feed); if($up){ $order=["order_type"=>'FKD',"order_code"=>$feed['bk_code'],"order_id"=>$feed['id'], "order_status"=>0]; ProcessOrder::workdel($order); $ste = ["order_code"=>$feed['bk_code'],"status"=>$feed['status'],"action_remark"=>'',"action_type"=>"delete"]; ActionLog::logAdd($this->post['token'],$ste,"FKD",$feed['status'],$feed); } return $up ? app_show(0,"删除成功"):error_show(1005,"删除失败"); } public function infoFeed(){ $id = isset($this->post['id']) ? intval($this->post['id']) : ""; if($id==""){ return error_show(1001,'id不能为空'); } $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find(); if(empty($info)){ return error_show(1002,'未找到备库数据'); } $feed = Db::name("purchease_feedback")->where(['bkcode'=>$info['bk_code'],'is_del'=>0])->find(); if(empty($feed)){ return error_show(1004,'未找到反馈数据'); } $feed['wsm_name']=""; if($feed['warehouse']!=""){ $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code") ->where(["a.wsm_code"=>$feed['warehouse']])->field("a.name as wsm_name,b.name,b.code")->find(); $feed['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:""; $feed['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:""; $feed['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:""; } if($feed['supplier']!=""){ $supplie = Db::name("supplier")->where(['code'=>$feed['supplier'],"is_del"=>0])->find();//废弃 $feed['supplier_name'] =isset($supplie['name']) ? $supplie['name']:""; } return app_show(0,"获取成功",$feed); } public function changeFeed(){ $id = isset($this->post['id']) ? intval($this->post['id']) : ""; if($id==""){ return error_show(1001,'id不能为空'); } $feed = Db::name("purchease")->where(['id'=>$id,'is_del'=>0])->find(); if(empty($feed)){ return error_show(1004,'未找到数据'); } $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']) : ""; if($status==""){ return error_show(1001,'参数status 不能为空'); } $remark = isset($this->post['remark'])&& $this->post['remark']!=='' ? trim($this->post['remark']) : ""; $userCommon= \app\admin\common\User::getIns(); $supplier_temp =$userCommon->handle("sInfo",["code"=>$feed['supplierNo']]); if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1002,"供应商不存在"); $holder_id=$supplier_temp['data']['personid']??0; $holder_name=$supplier_temp['data']['person']??0; Db::startTrans(); try{ $tem =$feed['status']; $feed['remark']= $remark; $feed['status']= $status; $feed['updatetime']=date("Y-m-d H:i:s"); $up = Db::name("purchease")->update($feed); if($up){ if ($feed['status'] == 1) { // $supplier = Db::name('supplier') // ->field('id,person,personid') // ->where('code', $feed['supplierNo']) // ->findOrEmpty(); $order = ["order_type" => 'BHD', "order_code" => $feed['bk_code'], "order_id" => $feed['id'], "order_status" => $feed['status'], "before_status" => $tem, 'holder_id' => $feed['apply_id'], 'wait_id' => $holder_id, 'wait_name' => $holder_name]; } else $order = ["order_type" => 'BHD', "order_code" => $feed['bk_code'], "order_id" => $feed['id'], "order_status" => $feed['status'], "before_status" => $tem, 'holder_id' => $feed['apply_id']]; ProcessOrder::AddProcess($this->post['token'], $order); $ste = ["order_code"=>$feed['bk_code'],"status"=>$tem,"action_remark"=>'',"action_type"=>"edit"]; ActionLog::logAdd($this->post['token'],$ste,"BHD",$feed['status'],$feed); if($status==3){ // $ware = Db::name("warehouse_addr")->where(["wsm_code"=>$feed['warehouse'],"is_del"=>0])->find(); $purse = Db::name("purchease_feedback")->where(['bkcode'=>$feed['bk_code'],"is_del"=>0])->find(); if(empty($purse)){ Db::rollback(); return error_show(1001,'未找到备库反馈数据'); } $pe = $purse['status']; $purse['status']=1; $purse['addtime']=date("Y-m-d H:i:s"); $up = Db::name("purchease_feedback")->save($purse); if($up==false){ Db::rollback(); return error_show(1001,'备库反馈数据状态修改失败'); } $order=["order_type"=>'FKD',"order_code"=>$feed['bk_code'],"order_id"=>$purse['id'],"order_status"=>$purse['status'],"before_status"=>$pe]; ProcessOrder::AddProcess($this->post['token'],$order); $ste = ["order_code"=>$feed['bk_code'],"status"=>$pe,"action_remark"=>'',"action_type"=>"status"]; ActionLog::logAdd($this->post['token'],$ste,"FKD",$feed['status'],$purse); $supplier = Db::name("supplier")->where(["code"=>$purse['supplier']])->find(); //废弃 $inw = makeNo("CG"); $goodinfo=Db::name('good_basic') ->field('id,createrid,creater') ->where(['is_del'=>0,'spuCode'=>$feed['spuCode']]) ->findOrEmpty(); $data=[ "bkcode"=>$purse['bkcode'], 'cgdNo'=>$inw, "wsm_code"=>$purse['warehouse'], "good_code"=>$feed['good_code'], "good_name"=>$feed['good_name'], "good_type_code"=>$feed['good_type_code'], "good_num"=>$feed['good_num'], "send_num"=>0, "wsend_num"=>$feed['good_num'], 'good_price'=>$purse['good_price'], "total_fee"=>$purse['good_price'], 'pakge_fee'=>$purse['pakge_fee'], 'cert_fee'=>$purse['cert_fee'], 'open_fee'=>$purse['open_fee'], 'mark_fee'=>$purse['mark_fee'], 'teach_fee'=>$purse['teach_fee'], 'nake_fee'=>$purse['nake_fee'], 'demo_fee'=>$purse['demo_fee'], 'delivery_fee'=>$purse['delivery_fee'], 'weight'=>$purse['weight'], 'diff_weight'=>$purse['diff_weight'], 'diff_fee'=>$purse['diff_price'], 'cgder_id'=>$purse['purchaser_id'], 'cgder'=>$purse['purchaser'], "remark"=>$purse['remark'], "status"=>0, 'supplierNo'=>$purse['supplier'], 'supplier_name'=>isset($supplier['name']) ? $supplier['name']:"", 'lasttime'=>$purse['expecttime'], "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s"), 'good_createrid' => $goodinfo['createrid'], 'good_creater' => $goodinfo['creater'],//商品的创建人 ]; $in= Db::name("purchease_order")->insert($data,true); if($in>0){ //当采购单是节点0待与供应商确认,推给供应商负责人 if(!isset($supplier)) $supplier = Db::name("supplier")->where(["code"=>$purse['supplier']]) //废弃 ->find(); //废弃 $order=["order_type"=>'CGD',"order_code"=>$data['cgdNo'],"order_id"=>$in, "order_status"=>$data['status'],"before_status"=>0,'wait_id'=>$supplier['personid'],'wait_name'=>$supplier['person']]; ProcessOrder::AddProcess($this->post['token'],$order); $ste = ["order_code"=>$inw,"status"=>$data['status'],"action_remark"=>'',"action_type"=>"create"]; ActionLog::logAdd($this->post['token'],$ste,"CGD",$data['status'],$data); //将采购单数据塞入到队列中 $push_data = json_encode([ 'supplierNo' => $data['supplierNo'], 'type' => 1,//1销售订单(采销的采购单),2上线结果 'data' => [ 'cgdNo' => $data['cgdNo'], 'spuCode' => $feed['spuCode'], 'good_name' => $data['good_name'], 'good_num' => $data['good_num'], 'good_price' => $data['good_price'], 'total_fee' => $data['total_fee'], 'weight' => $data['weight'], 'addtime' => $data['addtime'], ], ], JSON_UNESCAPED_UNICODE); // Cache::store("redis")->handler()->lPush(Config::get('app.abutment_queue'), $push_data); Db::commit(); return app_show(0,"更新成功",['cgdNo'=>$inw]); } }else{ if($status==4){ $purse = Db::name("purchease_feedback")->where(['bkcode'=>$feed['bk_code'],"is_del"=>0])->find(); if(empty($purse)){ Db::rollback(); return error_show(1001,'未找到备库反馈数据'); } $pe=$purse['status']; $purse['status']=2; $purse['addtime']=date("Y-m-d H:i:s"); $up = Db::name("purchease_feedback")->save($purse); if($up==false){ Db::rollback(); return error_show(1001,'备库反馈数据状态修改失败'); } $order=["order_type"=>'FKD',"order_code"=>$feed['bk_code'],"order_id"=>$purse['id'],"order_status"=>$purse['status'],"before_status"=>1]; ProcessOrder::AddProcess($this->post['token'],$order); $ste = ["order_code"=>$feed['bk_code'],"status"=>$pe,"action_remark"=>'',"action_type"=>"status"]; ActionLog::logAdd($this->post['token'],$ste,"FKD",$feed['status'],$purse); } Db::commit(); return app_show(0,"更新成功"); } } Db::rollback(); return error_show(1004,"更新失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1005,$e->getMessage()); } } public function addwsm(){ $id = isset($this->post['id']) ? intval($this->post['id']) : ""; if($id==""){ return error_show(1001,'id不能为空'); } $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find(); if($info==false){ return error_show(1002,'未找到备库数据'); } $wsm= isset($this->post['wsm_code'])&&$this->post['wsm_code']!="" ? trim($this->post['wsm_code']) : ""; if($wsm==""){ return error_show(1004,"参数wsm_code不能为空"); } $wsminfo = Db::name("warehouse_info")->where(["wsm_code"=>$wsm,"is_del"=>0])->find(); if($wsminfo==false){ return error_show(1004,"未找到仓库数据"); } $userCommon= \app\admin\common\User::getIns(); $supplier_temp =$userCommon->handle("sInfo",["code"=>$info['supplierNo']]); if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1002,"供应商不存在"); $holder_id=$supplier_temp['data']['personid']??0; $holder_name=$supplier_temp['data']['person']??0; $info['wsm_code']=$wsm; $old_info_status = $info['status']; $info['status']=1; $info['updatetime']=date("y-m-d H;i:s"); $up =Db::name("purchease")->save($info); if($up){ //修改状态,添加待办 ActionLog::logAdd($this->post['token'], [ "order_code" => $info['bk_code'],//销售单code "status" => $old_info_status,//这里的status是之前的值 "action_remark" => '',//备注 "action_type" => "edit"//新建create,编辑edit,更改状态status ], "BHD", $info['status'], $info); // $supplier = Db::name('supplier') // ->field('id,person,personid') // ->where('code', $info['supplierNo']) // ->findOrEmpty(); ProcessOrder::AddProcess($this->post['token'], [ "order_type" => 'BHD', "order_code" => $info['bk_code'],//销售单code "order_id" => $info['id'], "order_status" => $info['status'], "before_status"=>$old_info_status, 'wait_id' => $holder_id, 'wait_name' => $holder_name, ]); return app_show(0,"备库单仓库选择成功"); }else{ return error_show(1004,"备库单仓库选择失败"); } } //备库单生成采购单 public function createCgd(){ $bk_code=isset($this->post['bk_code'])&&$this->post['bk_code']!=="" ? trim($this->post['bk_code']):""; if($bk_code===""){ return error_show(1004,"参数bk_code不能为空"); } $info = Db::name("purchease")->where(["bk_code"=>$bk_code,"is_del"=>0])->find(); if($info==false){ return error_show(1002,'未找到备库数据'); } if($info['status']!=1){ 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,'备库仓库不能为空'); } $wsminfo = Db::name("warehouse_info")->where(["wsm_code"=>$wsm_code,"is_del"=>0])->find(); if($wsminfo==false){ return error_show(1002,'备库仓库未找到'); } $good =Db::name("good_basic")->where([["spuCode","=",$info['spuCode']],["is_del","=",0]])->find(); if($good==false){ return error_show(1004,"未找到商品数据"); } $userCommon= \app\admin\common\User::getIns(); $supplier_temp =$userCommon->handle("sInfo",["code"=>$info['supplierNo']]); if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1002,"未找到供应商数据"); $supplierName=$supplier_temp['data']['name']??''; $personid=$supplier_temp['data']['personid']??''; $person=$supplier_temp['data']['person']??''; $goodnake =Db::name("good_nake")->where([["spuCode","=",$info['spuCode']],["is_del","=",0],["min_num","<=", $info['good_num']]])->order("min_num desc")->find(); if($goodnake==false){ return error_show(1004,"未找到成本数据"); } $top_cat = made($good['cat_id']); $top_cat_id = isset($top_cat[0]['id'])?$top_cat[0]['id']:""; if($good['is_gold_price']==1 && $top_cat_id==6){ $gold = Db::name("gold_price1")->where(["type"=>$good['noble_metal'],"is_del"=>0,"status"=>1])->order("addtime desc") ->find(); $sale_price = round($good['demo_fee'] / $info['good_num'] + $good['open_fee'] / $info['good_num'] + $good['noble_weight'] * $gold["price"] + $goodnake['cost_fee'] * $good['noble_weight'] + $goodnake['package_fee'] + $goodnake['mark_fee'] + $goodnake['cert_fee'] +$goodnake['nake_fee'] + $goodnake['delivery_fee'],2); $total_price = round($info['good_num']*$sale_price,2); }else{ $sale_price = $goodnake['nake_total']; $total_price = round($info['good_num']*$sale_price,2); } $cgdCode = makeNo("CG"); $cg =["cgdNo"=>$cgdCode, "bkcode"=>$bk_code, "wsm_code"=>$wsm_code, "cgder"=>$good['creater'], "cgder_id"=>$good['createrid'], "spuCode"=>$info['spuCode'], "good_name"=>$info['good_name'], "good_num"=>$info['good_num'], "good_price"=>$sale_price, "total_fee"=>$total_price, "pakge_fee"=>isset($goodnake['package_fee'])? $goodnake['package_fee']:0, "cert_fee"=>isset($goodnake['cert_fee'])? $goodnake['cert_fee']:0, "open_fee"=>$good['open_fee'], "delivery_fee"=>isset($goodnake['delivery_fee'])? $goodnake['delivery_fee']:0, "mark_fee"=>isset($goodnake['mark_fee'])? $goodnake['mark_fee']:0, "nake_fee"=>isset($goodnake['nake_fee'])? $goodnake['nake_fee']:0, "teach_fee"=>isset($goodnake['cost_fee'])? $goodnake['cost_fee']:0, "demo_fee"=>$good['demo_fee'], "diff_weight"=>"0", "diff_fee"=>"0", "gold_price"=>"0", "supplierNo"=>$info['supplierNo'], "supplier_name"=>$info['supplierName'], "companyNo"=>$info['companyNo'], "companyName"=>$info['companyName'], "send_status"=>1, "send_num"=>"0", "wsend_num"=>$info['good_num'], "weight"=>$good['noble_weight'], "remark"=>"", "status"=>0,//0表示初始化 "lasttime"=>$info['lasttime'], "is_del"=>0, "order_type" => 1,//1备库 "order_source" => 0,//0备库下单 "good_type"=>1, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s"), 'good_createrid' => $good['createrid'], 'good_creater' => $good['creater'],//商品创建人 ]; Db::startTrans(); try{ $up =Db::name("purchease_order")->insert($cg,true); if($up>0){ $good = Db::name("good_stock")->where(["wsm_code" =>$wsm_code, "spuCode" => $info['spuCode'], "is_del" => 0])->find(); if ($good == false) { $good = [ "spuCode" => $info['spuCode'], "wsm_code" => $wsm_code, "usable_stock" => 0, "wait_out_stock" => 0, "wait_in_stock" => 0, "total_stock" => 0, "addtime" => date("Y-m-d H:i:s"), "updatetime" => date("Y-m-d H:i:s"), ]; $order = ["order_code" => $info['spuCode'], "status" => 1, "action_remark" => '', "action_type" => "create"]; } else { $order = ["order_code" => $info['spuCode'], "status" => 1, "action_remark" => '', "action_type" => "edit"]; } $good['wait_in_stock'] += $info['good_num']; $good['updatetime'] = date("Y-m-d H:i:s"); $upd = Db::name("good_stock")->save($good); $good_data[] = ['good_log_code' => $cgdCode,"stock_id" => isset($good['id']) ? $good['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1, 'stock' => $info['good_num'], "stock_name" => "wait_in_stock"]; if ($upd) { // 商品变动日志表,good_log_code字段存储采购单号 $order = ["order_code" => $cgdCode, "status" => 0, "action_remark" => '', "action_type" => "create"]; GoodLog::LogAdd($this->post['token'], $good_data, 'CGD'); ActionLog::logAdd($this->post['token'], $order, "CGD", 0, $good); $process = ["order_code" => $cgdCode, "order_id" => $up, "order_status" => $cg['status'], "order_type" => 'CGD',"before_status"=>0,'holder_id'=>$personid,'wait_id'=>$personid,'wait_name'=>$person]; ProcessOrder::AddProcess($this->post['token'], $process); $info['wsm_code'] = $wsm_code; $old_info_status = $info['status']; $info['status'] = 2; $info['updatetime'] = date("Y-m-d H:i:s"); $bas = Db::name("purchease")->save($info); if ($bas) { //修改状态,添加待办 ActionLog::logAdd($this->post['token'], [ "order_code" => $info['bk_code'],//销售单code "status" => $old_info_status,//这里的status是之前的值 "action_remark" => '',//备注 "action_type" => "edit"//新建create,编辑edit,更改状态status ], "BHD", $info['status'], $info); ProcessOrder::AddProcess($this->post['token'], [ "order_type" => 'BHD', "order_code" => $info['bk_code'],//销售单code "order_id" => $info['id'], "order_status" => $info['status'], "before_status"=> $old_info_status, 'holder_id' => $info['apply_id'] ]); //维护台账记录 Db::name('standing_book')->where('bk_code', $bk_code)->update([ 'spuCode' => $cg['spuCode'], 'order_type' => $cg['order_type'], 'order_source' => $cg['order_source'], 'supplierNo' => $cg['supplierNo'], 'companyNo' => $cg['companyNo'], 'cgdNo' => $cg['cgdNo'], 'updatetime' => date('Y-m-d H:i:s'), ]); //将采购单数据塞入到队列中 $push_data = json_encode([ 'supplierNo' => $cg['supplierNo'], 'type' => 1,//1销售订单(采销的采购单),2上线结果 'data' => [ 'cgdNo' => $cg['cgdNo'], 'spuCode' => $cg['spuCode'], 'good_name' => $cg['good_name'], 'good_num' => $cg['good_num'], 'good_price' => $cg['good_price'], 'total_fee' => $cg['total_fee'], 'weight' => $cg['weight'], 'addtime' => $cg['addtime'], ], ], JSON_UNESCAPED_UNICODE); // Cache::store("redis")->handler()->lPush(Config::get('app.abutment_queue'), $push_data); Db::commit(); return app_show(0, "采购单新建成功", ["cgdNo" => $cgdCode]); } } // } } Db::rollback(); return error_show(1004,"采购单新建失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } }