post=$this->request->post(); } 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]]; $wsm_in_code=isset($this->post['wsm_in_code']) && $this->post['wsm_in_code']!==""? trim($this->post['wsm_in_code']) :""; if($wsm_in_code!==""){ $where[]=["a.wsm_in_code",'like',"%$wsm_in_code%"]; } $cgdNo= isset($this->post['cgdNo']) && $this->post['cgdNo'] !==""? trim($this->post['cgdNo']) :""; if($cgdNo!==""){ $where[]=['a.cgdNo','like',"%$cgdNo%"]; } $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !==""? trim($this->post['apply_name']):""; if($apply_name!==""){ $where[]=['a.apply_name','like',"%$apply_name%"]; } $apply_id= isset($this->post['apply_id']) && $this->post['apply_id'] !==""? trim($this->post['apply_id']):""; if($apply_id!==""){ $where[]=['a.apply_id','=',$apply_id]; } $status= isset($this->post['status']) && $this->post['status'] !==""? trim($this->post['status']):""; if($status!==""){ $where[]=['a.status','=',$status]; } $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:""; if ($start !=="") { $where[]= ["a.sendtime",'>=',$start]; } $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :""; if($end !==""){ $where[]= ["a.sendtime",'<=',$end]; } $order_type=isset($this->post['order_type']) && $this->post['order_type']!==""? intval($this->post['order_type']):""; if($order_type !==""){ $where[]= ["b.order_type",'=',$order_type]; } $order_source=isset($this->post['order_source']) && $this->post['order_source']!==""? intval($this->post['order_source']):""; if($order_source !=="") $where[]= ["b.order_source",'=',$order_source]; $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[]= ["b.spuCode",'like',"%$good_type_code%"]; } $good_name=isset($this->post['good_name']) && $this->post['good_name']!==""? trim($this->post['good_name']):""; if($good_name !==""){ $where[]= ["b.good_name",'like',"%$good_name%"]; } $supplie=isset($this->post['supplier']) && $this->post['supplier']!==""? trim($this->post['supplier']):""; if($supplie !==""){ $where[]= ["b.supplier_name",'like',"%$supplie%"]; } $wsm_code=isset($this->post['wsm_code']) && $this->post['wsm_code']!==""? trim($this->post['wsm_code']):""; if($wsm_code !==""){ $where[]= ["a.wsm_code",'=',$wsm_code]; } $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"); // $where[]=['a.wsm_code',"in",$wsmcode]; $where[]= ["b.supplierNo",'=',$supplierNo]; } $condition=[]; //只有level2的账号过滤数据权限 // if ($this->level == 2) { // $role = $this->checkDataShare(); // $hand = resign_hand_user($this->uid, 0); // if (!empty($role[DataGroupModel::$type_全部])) { // $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部])); // // if($arr){ // $sys_supplier = Db::connect('mysql_sys') // ->name('supplier') // ->where(['is_del'=>0,'personid'=>$arr]) // ->column('code'); // $condition[] = ["b.supplierNo", "in", $sys_supplier]; // } // // $condition[] = ["a.apply_id", "in", $hand]; // $condition[] = ["c.contactor", "in", $hand]; //// $condition.="sip.personid in (".implode(",", //// $role[DataGroupModel::$type_全部]).") or a.apply_id in {$hand} or c.contactor in {$hand}"; // } // } $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : ""; if ($company_name !== "") $where[] = ["a.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[]=['b.companyNo','=', $relaComNo]; //$count = Db::name('purchease_in')->alias('a')->join("purchease_order b","b.cgdNo=a.cgdNo","left") $count = Db::name('purchease_in') ->alias('a') ->join("purchease_order b","b.cgdNo=a.cgdNo","left") ->leftJoin("warehouse_info c","a.wsm_code=c.wsm_code") // ->leftJoin('supplier sip', 'sip.code=b.supplierNo') ->where($where) // ->whereOr($condition) ->where(function ($query)use ($condition){$query->whereOr($condition);}) ->count(); $total = ceil($count/$size); $page = $page >= $total ? $total : $page; $list = Db::name('purchease_in') ->alias('a') ->join("purchease_order b","b.cgdNo=a.cgdNo","left") // ->leftJoin('supplier sip', 'sip.code=b.supplierNo') ->leftJoin("warehouse_info c","a.wsm_code=c.wsm_code") ->where($where) ->where(function ($query)use ($condition){$query->whereOr($condition);}) ->page($page,$size) ->field("a.apply_name,a.sendtime,b.order_type,b.order_source,a.status,a.cgdNo,a.wsm_in_code,a.send_num,a.wsm_code,b.good_name,b.spuCode,a.post_company,a.post_code,a.post_fee,a.apply_id,a.wsm_num,a.error_num,a.wait_num,a.status,a.check_name,a.checkid,b.bkcode,'' cgder_id,'' cgder,b.good_createrid,b.good_creater,c.name wsm_name,b.supplierNo,b.supplier_name,c.supplierNo wsm_supplierNo,c.supplierName wsm_supplier,b.companyNo,b.companyName") ->order("a.addtime desc") ->select() ->toArray(); $all_createrid = array_column($list,'apply_id'); $item = get_company_name_by_uid($all_createrid); //获取采购单供应商和仓库供应商的名称 $userCommon = \app\admin\common\User::getIns(); // $names = $userCommon->handle('getCodeAndName',['code'=>array_unique(array_column($list,'wsm_supplierNo'))]); $all_supplierNos = array_unique(array_column($list,'supplierNo')); $all_supplier = $userCommon->handle('sGetList',['more_code'=>$all_supplierNos,'page'=>1,'size'=>$size]); $all_supplier_list = array_column($all_supplier['data']['list'],null,'code'); //校验是否开通了供应商账号 $supp_account = checkHasAccountBySupplierNos($all_supplierNos); $data=[]; foreach ($list as $value){ $value['cgder_id'] = $all_supplier_list[$value['supplierNo']]['personid']??''; $value['cgder'] = $all_supplier_list[$value['supplierNo']]['person']??''; //获取规格、品牌信息 if ($value['order_type'] == 3 || $value['order_type'] == 4 ) { $temp = Db::name('good_zixun') ->alias('gz') ->field('gz.specinfo,b.brand_name') ->join('brand b', 'b.id=gz.brand_id') ->where(['gz.spuCode' => $value['spuCode'], 'gz.is_del' => 0]) ->find(); $value["brand_name"] = $temp['brand_name']; $value["speclist"] = json_decode($temp['specinfo'], true); } else { $value['brand_name'] = Db::name('good_basic') ->alias('gb') ->join('brand b', 'b.id=gb.brand_id') ->where(['gb.spuCode' => $value['spuCode']]) ->value('b.brand_name'); $spec = Db::name("good_spec") ->where(["spuCode" => $value['spuCode'], "is_del" => 0]) ->select() ->toArray(); $speclist = []; if (!empty($spec)) { foreach ($spec as $val) { $temp = []; $temp['id'] = $val['id']; $temp['spuCode'] = $val['spuCode']; $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'] = isset($spv["spec_value"]) ? $spv["spec_value"] : ""; $speclist[] = $temp; } } $value["speclist"] = empty($speclist) ? [] : $speclist; } // $wsmcode = Db::name("warehouse_info") // ->alias("k") // ->leftJoin("supplier c","k.supplierNo=c.code") // ->where(["k.wsm_code"=>$value['wsm_code']]) // ->field("k.name as wsm_name,c.name,c.code") // ->find(); // $value['wsm_name'] = $wsmcode['wsm_name']; // $value['wsm_supplier'] = $names['data'][$value['wsm_supplierNo']]??''; // $value['companyName'] = $names['data'][$value['companyNo']]??''; // $value['wsm_supplierNo'] = $wsmcode['code']; $value['company_name'] = $item[$value['apply_id']]??''; //是否具有编辑权限 // $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['has_account'] = (int)isset($supp_account[$value['supplierNo']]); $data[]=$value; } return app_show(0,"获取成功",['list'=>$data,'count'=>$count]); } public function add(){ $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!=""? trim($this->post['cgdNo']):""; if($cgdNo==""){ return error_show(1005,"参数cgdNo 不能为空"); } $cgdinfo = Db::name("purchease_order")->where(['cgdNo'=>$cgdNo,'is_del'=>0])->find(); if(empty($cgdinfo)){ return error_show(1005,"未找到采购单数据"); } if($cgdinfo['status']==0){ return error_show(1005,"采购单未确认"); } $isreturn = cgd_sale_return($cgdNo); if($isreturn){ return error_show(1005, "关联销售单存在退货单正在进行"); } $wsm_in_code = makeNo("CF"); $bn_code = makeNo("BN"); $wsminfo = Db::name("warehouse_info")->where(["wsm_code"=>$cgdinfo['wsm_code'],"is_del"=>0])->find(); if(empty($wsminfo)){ return error_show(1004,"未找到仓库信息"); } $recep = Db::name('warehouse_addr')->where(["wsm_code"=>$cgdinfo['wsm_code'],"is_del"=>0])->find(); $sendtype = isset($this->post['sendtype'])&&$this->post['sendtype']!="" ? intval($this->post['sendtype']):""; if($sendtype==""){ return error_show(1004,"参数 sendtype 不能为空"); } $post_company = isset($this->post['post_company'])&&$this->post['post_company']!="" ? trim($this->post['post_company']):""; $post_code = isset($this->post['post_code'])&&$this->post['post_code']!="" ? trim($this->post['post_code']):""; $post_fee = isset($this->post['post_fee'])&&$this->post['post_fee']!="" ? $this->post['post_fee']:"0"; $post_time = isset($this->post['post_time'])&&$this->post['post_time']!="" ? $this->post['post_time']:date("Y-m-d H:i:s"); $send_num = isset($this->post['send_num'])&&$this->post['send_num']!="" ? intval($this->post['send_num']):""; $status = isset($this->post['status'])&&$this->post['status']!="" ? intval($this->post['status']):"1 "; if($send_num==''){ return error_show(1004,"参数 send_num 不能为空或零"); } $wsmin_num=Db::name("purchease_in")->where([["cgdNo","=",$cgdNo],["is_del","=",0],["status","=",1]]) ->sum("send_num"); if($send_num>$cgdinfo['wsend_num']-$wsmin_num){ return error_show(1009,"采购单剩余未发货数量不足"); } if($cgdinfo['order_type']!=1){ $status=2; } $orin = [ "wsm_in_code"=>$wsm_in_code, "cgdNo"=>$cgdNo, "bnCode"=>$bn_code, "wsm_code"=>$cgdinfo['wsm_code'], "wsm_reaper"=>isset($recep)&& $recep['wsm_name']!=''? $recep['wsm_name']:"", "send_num"=>$send_num, "post_company"=>$post_company, "post_code"=>$post_code, "post_fee"=>$post_fee, "sendtime"=>$post_time, "apply_id"=>$this->uid, "apply_name"=>$this->uname, "wait_num"=>0, "wsm_num"=>0, "sendtype"=>$sendtype, "status"=>$status, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; Db::startTrans(); try{ // if ($this->level == 2) { //如果开通了供应商账号,则只允许level3账号操作,level2账号不允许操作 $all_has_supplier_account = checkHasAccountBySupplierNos([$cgdinfo['supplierNo']]); if (isset($all_has_supplier_account[$cgdinfo['supplierNo']])) throw new Exception('已开通供应商账号,当前账号不能操作'); } $win = Db::name("purchease_in")->insert($orin,true); if($win){ $sto = ["order_code"=>$wsm_in_code,"status"=>$status,"action_remark"=>'',"action_type"=>"edit"]; ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$sto,"RKD",$status,$this->post); if($status==1){ // $uid = Db::name('user_role') // ->where([ // ['is_del', '=', 0], // ['roleid', 'in', [31, 41]], // ['status', '=', 1] // ])->column('uid'); // $handle_user_list = implode(',', $uid); } $process=["order_code"=>$wsm_in_code,"order_id"=>$win,"order_status"=>$status,"order_type"=>'RKD',"before_status"=>$status,'holder_id' => $orin['apply_id'],"handle_user_list"=>$handle_user_list??""]; ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process); $order = ["order_code"=>$cgdNo,"status"=>$cgdinfo['status'],"action_remark"=>'',"action_type"=>"edit"]; //维护台账信息 Db::execute("UPDATE `wsm_standing_book` SET `wsm_in_code`=CONCAT(IFNULL(`wsm_in_code`,''),',{$wsm_in_code}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE `cgdNo`='{$cgdNo}'"); $is_stock = Db::name('good_basic') ->where(['is_del'=>0,'spuCode'=>$cgdinfo['spuCode']]) ->value('is_stock'); $userCommon = \app\admin\common\User::getIns(); $supplier_temp = $userCommon->handle('sInfo',['code'=>$cgdinfo['supplierNo']]); $person = $supplier_temp['data']; // if ($this->level == 2 && $this->uid != $person['personid']) throw new Exception('只能由供应商负责人操作'); if($status==1){ Db::commit(); return app_show(0,'新建成功',["wsm_in_code"=>$wsm_in_code]); } if($status==2){ $cgdinfo['wsend_num']-=$send_num; $cgdinfo['send_num']+=$send_num; $cgdinfo['send_status']=$cgdinfo['wsend_num']==0 ? 3:($cgdinfo['send_num']==0 ?1:2); $cgdinfo['status']=$cgdinfo['wsend_num']==0 ? 3:($cgdinfo['send_num']==0 ?1:2); $cgdinfo['updatetime']=date("Y-m-d H:i:s"); $up=Db::name("purchease_order")->save($cgdinfo); if($up==false){ Db::rollback(); return error_show(1004,"新建失败"); } $good = Db::name("good_stock")->where(["wsm_code"=>$cgdinfo['wsm_code'],"spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->lock(true)->find(); if(empty($good)) { $good=[ "spuCode"=>$cgdinfo['spuCode'], "wsm_code"=>$cgdinfo['wsm_code'], "usable_stock"=>0, "wait_out_stock"=>0, "wait_in_stock"=>$send_num, "total_stock"=>0, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s"), ]; } $good['wait_in_stock']-=$send_num; $good['usable_stock']+=$send_num; $good['total_stock']=$good['usable_stock']+$good['wait_out_stock']; $good['updatetime'] = date("Y-m-d H:i:s"); $upd= Db::name("good_stock")->save($good); $stockid=$good['id']?? Db::name("good_stock")->getLastInsID(); //商品变动日志表,good_log_code字段存储采购单单号 $good_data=[]; $good_data[]=['good_log_code'=>$wsm_in_code,"stock_id"=>$stockid,"type"=>1,'stock'=>$send_num,"stock_name"=>"usable_stock"]; $good_data[]=['good_log_code'=>$wsm_in_code,"stock_id"=>$stockid,"type"=>2,'stock'=>$send_num,"stock_name"=>"wait_in_stock"]; if($upd){ GoodLog::LogAdd(['id'=>$this->uid,'nickname'=>$this->uname],$good_data,'RKD'); $bnin=GoodStockInfo::AddBn($stockid,$bn_code,$send_num,$cgdinfo['good_price']); if($bnin==false){ Db::rollback(); return error_show(1004,"库存bn数据新增失败"); } //todo:: 新增bn编号库存数据修改 if($cgdinfo['order_type']==1){ //商品表里的'可用总库存数'增加 Db::name('good') ->data(['updatetime' => date('Y-m-d H:i:s')]) ->where(['is_del' => 0, 'spuCode' => $cgdinfo['spuCode']]) ->inc('usable_stock', $send_num) ->update(); } if($cgdinfo['send_status']==3 && $cgdinfo['order_type']!=1){ $send=Db::name("order_send")->where(["cgdNo"=>$cgdNo,"status"=>1])->column("outCode"); if(!empty($send)){ $out =Db::name("order_out")->where(["outCode"=>$send,"status"=>0,"is_del"=>0])->select() ->toArray(); if(!empty($out)){ $up =Db::name("order_out")->where(["outCode"=>$send,"status"=>0,"is_del"=>0])->update(["status"=>1,'send_status'=>1,'wsm_code'=>$cgdinfo['wsm_code'],"updatetime"=>date('Y-m-d H:i:s')]); //2023-03-14 17:34修改,增加'send_status'=>1 by 武 if($up==false){ Db::rollback(); return error_show(1004,"出库单出库失败"); }else{ foreach ($out as $k => $v_outCode) { \app\admin\model\OrderOutChild::makeChild($v_outCode['outCode']); ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [ "order_code" => $v_outCode['outCode'],//出库单号 "status" => 0,//这里的status是之前的值 "action_remark" => '',//备注 "action_type" => "status"//新建create,编辑edit,更改状态status ], "CKD", 1, $this->post); if ($is_stock == 1) { //库存品,推给库管和库管-张凯旋 $roleid = config('app.wsm_cgder_role'); $uids = Db::name('user_role') ->where('is_del', 0) ->whereIn('roleid', $roleid) ->column('uid'); ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [ "order_type" => 'CKD', "order_code" => $v_outCode['outCode'],//出库单号 "order_id" => $v_outCode['id'], "order_status" => 1, "before_status" => 0, // 'wait_id' => $supplier['personid'], // 'wait_name' => $supplier['person'], // 'holder_id' => $supplier['personid'], 'handle_user_list' => implode(',', $uids) ]); } else { //非库存品和采返商品,推给供应商负责人 ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [ "order_type" => 'CKD', "order_code" => $v_outCode['outCode'],//出库单号 "order_id" => $v_outCode['id'], "order_status" => 1, "before_status" => 0, 'wait_id' => $person['personid']??0, 'wait_name' => $person['person']??'', 'holder_id' =>$person['personid']??0, ]); } } } // $good1 = Db::name("good_stock")->where(["wsm_code"=>$cgdinfo['wsm_code'], "spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->find(); // if($good1==false){ // Db::rollback(); // return error_show(1004,"未找到对应商品库存"); // } // $out_num = intval(array_sum(array_column($out,"send_num"))); // if($out_num>$good1['usable_stock']){ // Db::rollback(); // return error_show(1004,"库存数量不足发货"); // } // $good1['usable_stock']-=$out_num; // $good1['wait_out_stock']+=$out_num; // $good1['total_stock']=$good1['usable_stock']+$good1['wait_out_stock']; // $good1['updatetime'] = date("Y-m-d H:i:s"); // $upd= Db::name("good_stock")->save($good1); // if($upd==false){ // Db::rollback(); // return error_show(1004,"库存数量更新失败"); // } // $stockid= isset($good['id'])?$good['id']:Db::name("good_stock")->getLastInsID(); // // $good_data[]=['good_log_code'=>$wsm_in_code,"stock_id"=>$stockid,"type"=>1,'stock'=>$send_num,"stock_name"=>"wait_out_stock"]; // $good_data[]=['good_log_code'=>$wsm_in_code,"stock_id"=>$stockid,"type"=>1,'stock'=>$send_num,"stock_name"=>"usable_stock"]; // GoodLog::LogAdd(['id'=>$this->uid,'nickname'=>$this->uname],$good_data,'RKD'); $sendp=Db::name("order_send")->where(["cgdNo"=>$cgdNo,"outCode"=>$send,"status"=>1])->save (["status"=>2]); if($sendp==false){ Db::rollback(); return error_show(1004,"库存发货失败"); } } } if ($cgdinfo['order_type'] == 2) Db::name('good') ->data(['updatetime' => date('Y-m-d H:i:s')]) ->where(['is_del' => 0, 'spuCode' => $cgdinfo['spuCode']]) ->inc('usable_stock', $send_num) ->update(); else Db::name('good_zixun') ->data(['updatetime' => date('Y-m-d H:i:s')]) ->where(['is_del' => 0, 'spuCode' => $cgdinfo['spuCode']]) ->inc('usable_stock', $send_num) ->update(); } ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$order,"CGD", $cgdinfo['status'],$cgdinfo); // $personid = Db::name('supplier') // ->where('is_del',0) // ->where('code',$cgdinfo['supplierNo']) // ->value('personid'); // if($cgdinfo['status']==1 || $cgdinfo['status']==2){ // $is_stock = Db::name('good_basic') // ->where(['is_del'=>0,'spuCode'=>$cgdinfo['spuCode']]) // ->value('is_stock'); // if($is_stock==1){ // //库存品,推给31库管人员、41库管-张凯旋 // $uid = Db::name('user_role') // ->where([ // ['is_del', '=', 0], // ['roleid', 'in', [31, 41]], // ['status', '=', 1] // ])->column('uid'); // if(!in_array($this->uid,$uid)) throw new Exception('库存品订单只能由库管人员操作'); //// $process = ["order_code" => $cgdNo, "order_id" => $cgdinfo['id'], "order_status" => $cgdinfo['status'], "order_type" => 'CGD', "before_status" => $order['status'], 'holder_id' => $personid,'handle_user_list'=>implode(',', $uid)]; // // }else{ // if (($this->level == 2) && ($this->uid != $person['personid'])) throw new Exception('只能由供应商负责人操作'); // } // }//else $process = ["order_code" => $cgdNo, "order_id" => $cgdinfo['id'], "order_status" => $cgdinfo['status'], "order_type" => 'CGD', "before_status" => $order['status'], 'holder_id' => $personid]; ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],["order_code" => $cgdNo, "order_id" => $cgdinfo['id'], "order_status" => $cgdinfo['status'], "order_type" => 'CGD', "before_status" => $order['status'], 'holder_id' => $person['personid']??0]); Db::commit(); return app_show(0,'商品入库成功',["wsm_in_code"=>$wsm_in_code]); }else{ Db::rollback(); return error_show(1002,"商品入库失败"); } } Db::commit(); return app_show(0,'新建成功',["wsm_in_code"=>$wsm_in_code]); } Db::rollback(); return error_show(1004,"新建失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1004, $e->getMessage()); } } //批量添加入库单 public function addBatch() { $param = $this->request->filter('trim')->only(['cgdNo'], 'post'); $val = Validate::rule(['cgdNo|订单编号' => 'require|array|max:100']); //入库方式 供应商包邮, //运费 0 if (!$val->check($param)) return json_show(1004, $val->getError()); $cgdinfo = Db::name("purchease_order") ->whereIn('cgdNo', $param['cgdNo']) ->where(['is_del' => 0]) ->where('status', 'in', [1, 2])//1待入库,2部分入库 ->column('id,wsm_code,good_num,good_price,spuCode,order_type,send_status,status,supplierNo', 'cgdNo'); if (empty($cgdinfo)) return json_show(1005, "未找到采购单数据或采购单未发货"); $all_wsm_code = array_column($cgdinfo, 'wsm_code'); $recep = Db::name('warehouse_addr') ->where('is_del', 0) ->whereIn('wsm_code', $all_wsm_code) ->column('wsm_name', 'wsm_code'); $uid = $this->uid; $nickname = $this->uname; Db::startTrans(); try { $date = date('Y-m-d H:i:s'); // $supplier_cgderid = Db::name('supplier') // ->where('is_del',0) // ->whereIn('code',array_column($cgdinfo,'supplierNo')) // ->column('personid,person','code'); $codes = array_unique(array_column($cgdinfo, 'supplierNo')); $temp = \app\admin\common\User::getIns()->handle('sGetList', ['more_code' => $codes, 'size' => count($codes)]); $supplier_cgderid = []; foreach ($temp['data']['list'] as $da) { if (!isset($supplier_cgderid[$da['code']])) $supplier_cgderid[$da['code']] = [ 'personid' => $da['personid'], 'person' => $da['person'], ]; } $i = 0; $status = 2;//4入库完成 foreach ($param['cgdNo'] as $cgdNo) { $isreturn = cgd_sale_return($cgdNo); if ($isreturn) { throw new Exception("{$cgdNo}关联销售单存在退货单正在进行"); } if (empty($cgdinfo[$cgdNo])) throw new Exception('未找到采购单数据或采购单未发货'); $wsm_in_code = makeNo("CF"); $bn_code = makeNo("BN"); $send_num = $cgdinfo[$cgdNo]['good_num']; //改变编码规则,将原编码后两位换成序列号 //str_pad字符串填充 $wsm_in_code = substr($wsm_in_code, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT); $i++; //入库单 $win = Db::name("purchease_in")->insertGetId([ "wsm_in_code" => $wsm_in_code, "cgdNo" => $cgdNo, "bnCode" => $bn_code, "wsm_code" => $cgdinfo[$cgdNo]['wsm_code'], "wsm_reaper" => isset($recep[$cgdinfo[$cgdNo]['wsm_code']]) ? $recep[$cgdinfo[$cgdNo]['wsm_code']] : '', "send_num" => $cgdinfo[$cgdNo]['good_num'], "post_company" => '', "post_code" => '', "post_fee" => 0,//运费固定值:0 "sendtime" => $date, "apply_id" => $uid, "apply_name" => $nickname, "wait_num" => 0, "wsm_num" => 0, "sendtype" => 2,//发货方式,固定值,供应商包邮2 "status" => $status, "addtime" => $date, "updatetime" => $date ]); if ($win) { $sto = ["order_code" => $wsm_in_code, "status" => $status, "action_remark" => '', "action_type" => "edit"]; ActionLog::logAdd(['id' => $uid, 'nickname' => $nickname], $sto, "RKD", $status, $this->request->filter('trim')->post()); $process = ["order_code" => $wsm_in_code, "order_id" => $win, "order_status" => $status, "order_type" => 'RKD', "before_status" => $status, 'holder_id' => $uid]; ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $nickname], $process); $order = ["order_code" => $cgdNo, "status" => $cgdinfo[$cgdNo]['status'], "action_remark" => '', "action_type" => "edit"]; //维护台账信息 Db::execute("UPDATE `wsm_standing_book` SET `wsm_in_code`=CONCAT(IFNULL(`wsm_in_code`,''),',{$wsm_in_code}'),`updatetime`='" . $date . "' WHERE `cgdNo`='{$cgdNo}'"); ////////////////// $good = Db::name("good_stock") ->where(["wsm_code" => $cgdinfo[$cgdNo]['wsm_code'], "spuCode" => $cgdinfo[$cgdNo]['spuCode'], "is_del" => 0]) ->lock(true) ->find(); if (empty($good)) { $good = [ "spuCode" => $cgdinfo[$cgdNo]['spuCode'], "wsm_code" => $cgdinfo[$cgdNo]['wsm_code'], "usable_stock" => 0, "wait_out_stock" => 0, "wait_in_stock" => $send_num, "total_stock" => 0, "addtime" => date("Y-m-d H:i:s"), "updatetime" => date("Y-m-d H:i:s"), ]; // $order = ["order_code" => $good['spuCode'], "status" => 1, "action_remark" => '', "action_type" => "create"]; } else { // $order = ["order_code" => $good['spuCode'], "status" => 1, "action_remark" => '', "action_type" => "edit"]; } $good['wait_in_stock'] -= $send_num; // if ($good['presale_stock'] > 0) { // if ($good['presale_stock'] >= $send_num) { // $good['presale_stock'] -= $send_num; // $good['wait_out_stock'] += $send_num; // } else { // $good['presale_stock'] = 0; // $good['usable_stock'] += $send_num - $good['presale_stock']; // $good['wait_out_stock'] += $good['presale_stock']; // } // } else { $good['usable_stock'] += $send_num; // } $good['total_stock'] = $good['usable_stock'] + $good['wait_out_stock']; $good['updatetime'] = date("Y-m-d H:i:s"); $upd = Db::name("good_stock")->save($good); $stockid = $good['id'] ?? Db::name("good_stock")->getLastInsID(); //商品变动日志表,good_log_code字段存储采购单单号 $good_data[] = ['good_log_code' => $wsm_in_code, "stock_id" => $stockid, "type" => 1, 'stock' => $send_num, "stock_name" => "usable_stock"]; $good_data[] = ['good_log_code' => $wsm_in_code, "stock_id" => $stockid, "type" => 2, 'stock' => $send_num, "stock_name" => "wait_in_stock"]; if ($upd) { GoodLog::LogAdd(['id' => $uid, 'nickname' => $nickname], $good_data, 'RKD'); $bnin = GoodStockInfo::AddBn($stockid, $bn_code, $send_num, $cgdinfo[$cgdNo]['good_price']); if ($bnin == false) { Db::rollback(); return error_show(1004, "库存bn数据新增失败"); } if ($cgdinfo[$cgdNo]['order_type'] == 1) { $bk = Db::name("order_bk")->where(['cgdNo' => $cgdNo])->find(); if ($bk == false) { $bk = [ "cgdNo" => $cgdNo, "spuCode" => $cgdinfo[$cgdNo]['spuCode'], "companyNo" => $cgdinfo[$cgdNo]['companyNo'], "total_num" => $send_num, "merge_num" => 0, "balance_num" => $send_num, "status" => 1, "is_del" => 0, 'addtime' => date("Y-m-d H:i:s"), "updatetime" => date("Y-m-d H:i:s") ]; $upcgd = Db::name("order_bk")->save($bk); } else { $where = ['id' => $bk['id'], 'total_num' => $bk['total_num'], 'balance_num' => $bk['balance_num']]; $bk['balance_num'] += $send_num; $bk['total_num'] += $send_num; $bk['updatetime'] = date("Y-m-d H:i:s"); $upcgd = Db::name("order_bk")->where($where)->update($bk); } if ($upcgd == false) throw new Exception('采购单数量更新失败'); } if (in_array($cgdinfo[$cgdNo]['send_status'], [1, 2]) && $cgdinfo[$cgdNo]['order_type'] != 1) { $send = Db::name("order_send")->where(["cgdNo" => $cgdNo, "status" => 1])->column("outCode"); if (!empty($send)) { $out = Db::name("order_out")->where(["outCode" => $send, "status" => 0,'is_del'=>0])->select()->toArray(); if (!empty($out)) { $up = Db::name("order_out")->where(["outCode" => $send, "status" => 0,'is_del'=>0])->update(["status" => 1,'send_status'=>1, 'wsm_code' => $cgdinfo[$cgdNo]['wsm_code'], "updatetime" => date('Y-m-d H:i:s')]); //2023-03-14 17:34修改,增加'send_status'=>1 by 武 if ($up == false) throw new Exception('出库单出库失败'); else { //查询是否有非库存品订单 $is_stock = Db::name('sale') ->where([ ['is_del', '=', 0], ['orderCode', 'in', array_column($out, 'orderCode')] ])->column('is_stock', 'orderCode'); foreach ($out as $k => $v_outCode) { \app\admin\model\OrderOutChild::makeChild($v_outCode['outCode']); //修改状态,添加待办 ActionLog::logAdd(['id' => $uid, 'nickname' => $nickname], [ "order_code" => $v_outCode['outCode'],//出库单号 "status" => 0,//这里的status是之前的值 "action_remark" => '',//备注 "action_type" => "status"//新建create,编辑edit,更改状态status ], "CKD", 1, $param); //库存品,推给库管和库管-张凯旋 if ($is_stock[$v_outCode['orderCode']] == 1) { $roleid = config('app.wsm_cgder_role'); $uids = Db::name('user_role') ->where('is_del', 0) ->whereIn('roleid', $roleid) ->column('uid'); ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $nickname], [ "order_type" => 'CKD', "order_code" => $v_outCode['outCode'],//出库单号 "order_id" => $v_outCode['id'], "order_status" => 1, "before_status" => 0, // 'wait_id' => $wait['personid'], // 'wait_name' => $wait['person'], // 'holder_id' => $wait['personid'], 'handle_user_list' => implode(',', $uids) ]); } else { //推给供应商负责人 $wait = $supplier_cgderid[$cgdinfo[$cgdNo]['supplierNo']]; ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $nickname], [ "order_type" => 'CKD', "order_code" => $v_outCode['outCode'],//出库单号 "order_id" => $v_outCode['id'], "order_status" => 1, "before_status" => 0, 'wait_id' => $wait['personid'], 'wait_name' => $wait['person'], 'holder_id' => $wait['personid'], ]); } } } // $good1 = Db::name("good_stock")->where(["wsm_code" => $cgdinfo[$cgdNo]['wsm_code'], "spuCode" => $cgdinfo[$cgdNo]['spuCode'], "is_del" => 0])->find(); // if ($good1 == false) throw new Exception('未找到对应商品库存'); // $out_num = intval(array_sum(array_column($out, "send_num"))); // if ($out_num > $good1['usable_stock']) throw new Exception('库存数量不足发货'); // // $good1['usable_stock'] -= $out_num; // $good1['wait_out_stock'] += $out_num; // $good1['total_stock'] = $good1['usable_stock'] + $good1['wait_out_stock']; // $good1['updatetime'] = date("Y-m-d H:i:s"); // $upd = Db::name("good_stock")->save($good1); // if ($upd == false) throw new Exception('库存数量更新失败'); // // $good_data[] = ['good_log_code' => $wsm_in_code, "stock_id" => isset($good['id']) ? $good['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1, 'stock' => $send_num, "stock_name" => "wait_out_stock"]; // $good_data[] = ['good_log_code' => $wsm_in_code, "stock_id" => isset($good['id']) ? $good['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1, 'stock' => $send_num, "stock_name" => "usable_stock"]; // GoodLog::LogAdd(['id' => $uid, 'nickname' => $nickname], $good_data, 'RKD'); $sendp = Db::name("order_send")->where(["cgdNo" => $cgdNo, "outCode" => $send, "status" => 1])->save(["status" => 2]); if ($sendp == false) throw new Exception('库存发货失败'); } } } ActionLog::logAdd(['id' => $uid, 'nickname' => $nickname], $order, "CGD", $cgdinfo[$cgdNo]['status'], $cgdinfo[$cgdNo]); $process = ["order_code" => $cgdNo, "order_id" => $cgdinfo[$cgdNo]['id'], "order_status" => $cgdinfo[$cgdNo]['status'], "order_type" => 'CGD', "before_status" => $order['status'], 'holder_id' => isset($supplier_cgderid[$cgdinfo[$cgdNo]['supplierNo']]['personid']) ? $supplier_cgderid[$cgdinfo[$cgdNo]['supplierNo']]['personid'] : 0]; ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $nickname], $process); // Db::commit(); // return json_show(0, '商品入库成功', ["wsm_in_code" => $wsm_in_code]); } else throw new Exception('商品入库失败'); ////////////////// } else throw new Exception('新建入库单失败'); } //维护原有采购单信息 Db::name("purchease_order") ->whereIn('id', array_column($cgdinfo, 'id')) ->update([ 'wsend_num' => 0, 'send_num' => Db::raw('good_num'), 'send_status' => 3, 'status' => 3, 'updatetime' => date("Y-m-d H:i:s"), ]); Db::commit(); return json_show(0, '新建入库单成功'); // $win = Db::name("purchease_in")->insert($orin, true); // if ($win) { // $sto = ["order_code" => $wsm_in_code, "status" => $status, "action_remark" => '', "action_type" => "edit"]; // ActionLog::logAdd($this->post['token'], $sto, "RKD", $status, $this->post); // $process = ["order_code" => $wsm_in_code, "order_id" => $win, "order_status" => $status, "order_type" => 'RKD', "before_status" => $status]; // ProcessOrder::AddProcess($this->post['token'], $process); // $order = ["order_code" => $cgdNo, "status" => $cgdinfo['status'], "action_remark" => '', "action_type" => "edit"]; //维护台账信息 // Db::execute("UPDATE `wsm_standing_book` SET `wsm_in_code`=CONCAT(IFNULL(`wsm_in_code`,''),',{$wsm_in_code}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE `cgdNo`='{$cgdNo}'"); // if ($status == 1) { // Db::commit(); // return json_show(0, '新建成功', ["wsm_in_code" => $wsm_in_code]); // } // if ($status == 4) { // $cgdinfo['wsend_num'] -= $send_num; // $cgdinfo['send_num'] += $send_num; // $cgdinfo['send_status'] = $cgdinfo['wsend_num'] == 0 ? 3 : ($cgdinfo['send_num'] == 0 ? 1 : 2); // $cgdinfo['status'] = $cgdinfo['wsend_num'] == 0 ? 3 : ($cgdinfo['send_num'] == 0 ? 1 : 2); // $cgdinfo['updatetime'] = date("Y-m-d H:i:s"); // $up = Db::name("purchease_order")->save($cgdinfo); // if ($up == false) { // Db::rollback(); // return json_show(1004, "新建失败"); // } // $good = Db::name("good_stock") // ->where(["wsm_code" => $cgdinfo['wsm_code'], "spuCode" => $cgdinfo['spuCode'], "is_del" => 0]) // ->lock(true) // ->find(); // if (empty($good)) { // $good = [ // "spuCode" => $cgdinfo['spuCode'], // "wsm_code" => $cgdinfo['wsm_code'], // "usable_stock" => 0, // "wait_out_stock" => 0, // "wait_in_stock" => $send_num, // "total_stock" => 0, // "addtime" => date("Y-m-d H:i:s"), // "updatetime" => date("Y-m-d H:i:s"), // ]; // // $order = ["order_code"=>$good['spuCode'],"status"=>1,"action_remark"=>'', // // "action_type"=>"create"]; // } else { // // $order = ["order_code"=>$good['spuCode'],"status"=>1,"action_remark"=>'', // // "action_type"=>"edit"]; // } // $good['wait_in_stock'] -= $send_num; // if ($good['presale_stock'] > 0) { // if ($good['presale_stock'] >= $send_num) { // $good['presale_stock'] -= $send_num; // $good['wait_out_stock'] += $send_num; // } else { // $good['presale_stock'] = 0; // $good['usable_stock'] += $send_num - $good['presale_stock']; // $good['wait_out_stock'] += $good['presale_stock']; // } // } else { // $good['usable_stock'] += $send_num; // } // // $good['total_stock'] = $good['usable_stock'] + $good['wait_out_stock']; // $good['updatetime'] = date("Y-m-d H:i:s"); // $upd = Db::name("good_stock")->save($good); // //商品变动日志表,good_log_code字段存储采购单单号 // $good_data[] = ['good_log_code' => $wsm_in_code, "stock_id" => isset($good['id']) ? $good['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1, 'stock' => $send_num, "stock_name" => "usable_stock"]; // $good_data[] = ['good_log_code' => $wsm_in_code, "stock_id" => isset($good['id']) ? $good['id'] : Db::name("good_stock")->getLastInsID(), "type" => 2, 'stock' => $send_num, "stock_name" => "wait_in_stock"]; // if ($upd) { // GoodLog::LogAdd($this->post['token'], $good_data, 'RKD'); // if ($cgdinfo['order_type'] == 1) { // $bk = Db::name("order_bk")->where(['cgdNo' => $cgdinfo['cgdNo']])->find(); // if ($bk == false) { // $bk = [ // "cgdNo" => $cgdinfo['cgdNo'], // "spuCode" => $cgdinfo['spuCode'], // "companyNo" => $cgdinfo['companyNo'], // "total_num" => $send_num, // "merge_num" => 0, // "balance_num" => $send_num, // "status" => 1, // "is_del" => 0, // 'addtime' => date("Y-m-d H:i:s"), // "updatetime" => date("Y-m-d H:i:s") // ]; // $upcgd = Db::name("order_bk")->save($bk); // } else { // $where = ['id' => $bk['id'], 'total_num' => $bk['total_num'], 'balance_num' => $bk['balance_num']]; // $bk['balance_num'] += $send_num; // $bk['total_num'] += $send_num; // $bk['updatetime'] = date("Y-m-d H:i:s"); // $upcgd = Db::name("order_bk")->where($where)->update($bk); // } // // if ($upcgd == false) { // Db::rollback(); // return json_show(1004, "采购单数量更新失败"); // } // } // if ($cgdinfo['send_status'] == 3 && $cgdinfo['order_type'] != 1) { // $send = Db::name("order_send")->where(["cgdNo" => $cgdNo, "status" => 1])->column("outCode"); // if (!empty($send)) { // $out = Db::name("order_out")->where(["outCode" => $send, "status" => 0])->select() // ->toArray(); // if (!empty($out)) { // $up = Db::name("order_out")->where(["outCode" => $send, "status" => 0])->update // (["status" => 1, 'wsm_code' => $cgdinfo['wsm_code'], "updatetime" => date('Y-m-d H:i:s')]); // if ($up == false) { // Db::rollback(); // return json_show(1004, "出库单出库失败"); // } else { // foreach ($out as $k => $v_outCode) { // //修改状态,添加待办 // ActionLog::logAdd($this->post['token'], [ // "order_code" => $v_outCode['outCode'],//出库单号 // "status" => 0,//这里的status是之前的值 // "action_remark" => '',//备注 // "action_type" => "status"//新建create,编辑edit,更改状态status // ], "CKD", 1, $this->post); // // ProcessOrder::AddProcess($this->post['token'], [ // "order_type" => 'CKD', // "order_code" => $v_outCode['outCode'],//出库单号 // "order_id" => $v_outCode['id'], // "order_status" => 1, "before_status" => 0 // ]); // } // } // $good1 = Db::name("good_stock")->where(["wsm_code" => $cgdinfo['wsm_code'], "spuCode" => $cgdinfo['spuCode'], "is_del" => 0])->find(); // if ($good1 == false) { // Db::rollback(); // return json_show(1004, "未找到对应商品库存"); // } // $out_num = intval(array_sum(array_column($out, "send_num"))); // if ($out_num > $good1['usable_stock']) { // Db::rollback(); // return json_show(1004, "库存数量不足发货"); // } // $good1['usable_stock'] -= $out_num; // $good1['wait_out_stock'] += $out_num; // $good1['total_stock'] = $good1['usable_stock'] + $good1['wait_out_stock']; // $good1['updatetime'] = date("Y-m-d H:i:s"); // $upd = Db::name("good_stock")->save($good1); // if ($upd == false) { // Db::rollback(); // return json_show(1004, "库存数量更新失败"); // } // $good_data[] = ['good_log_code' => $wsm_in_code, "stock_id" => isset($good['id']) ? $good['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1, 'stock' => $send_num, "stock_name" => "wait_out_stock"]; // $good_data[] = ['good_log_code' => $wsm_in_code, "stock_id" => isset($good['id']) ? $good['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1, 'stock' => $send_num, "stock_name" => "usable_stock"]; // GoodLog::LogAdd($this->post['token'], $good_data, 'RKD'); // $sendp = Db::name("order_send")->where(["cgdNo" => $cgdNo, "outCode" => $send, "status" => 1])->save(["status" => 2]); // if ($sendp == false) { // Db::rollback(); // return json_show(1004, "库存发货失败"); // } // } // } // } // ActionLog::logAdd($this->post['token'], $order, "CGD", $cgdinfo['status'], $cgdinfo); // $process = ["order_code" => $cgdNo, "order_id" => $cgdinfo['id'], "order_status" => $cgdinfo['status'], "order_type" => 'CGD', "before_status" => $order['status']]; // ProcessOrder::AddProcess($this->post['token'], $process); // Db::commit(); // return json_show(0, '商品入库成功', ["wsm_in_code" => $wsm_in_code]); // } else { // Db::rollback(); // return json_show(1002, "商品入库失败"); // } // } // Db::commit(); // return json_show(0, '新建成功', ["wsm_in_code" => $wsm_in_code]); // } // Db::rollback(); // return json_show(1004, "新建失败"); } catch (Exception $e) { Db::rollback(); return json_show(1004, $e->getMessage().'|'.$e->getFile().'|'.$e->getLine()); } } public function info(){ $incode = isset($this->post['wsm_in_code'])&&$this->post['wsm_in_code']!="" ? trim($this->post['wsm_in_code']) :""; if($incode==""){ return error_show(1004,"参数wsm_in_code 不为空"); } $info = Db::name("purchease_in")->where(['wsm_in_code'=>$incode,"is_del"=>0])->find(); if(empty($info)){ return error_show(1004,"未找到数据"); } $dom = Db::name("purchease_order")->where(['cgdNo'=>$info['cgdNo'],'is_del'=>0])->find(); if($dom['order_type']==3|| $dom['order_type']==4){ $goon = Db::name("good_zixun")->where(["spuCode"=>$dom['spuCode'],"is_del"=>0])->find(); }else { $goon =Db::name('good_basic')->where(['spuCode'=>$dom['spuCode']])->find(); } if(empty($goon)){ return error_show(1002,"未找到商品数据"); } $cat= isset($goon['cat_id']) && $goon['cat_id'] !=0 ? made($goon['cat_id']):[]; $info['cgder']=$dom['cgder']; $info['spuCode']=$dom['spuCode']; $info['good_name']=$dom['good_name']; $info['skuCode']=$dom['skuCode']; $info['good_num']=$dom['good_num']; $info['good_price']=$dom['good_price']; $info['total_fee']=$dom['total_fee']; $info['diff_fee']=$dom['diff_fee']; $info['diff_weight']=$dom['diff_weight']; $info['gold_price']=$dom['gold_price']; $wsmcode = Db::name("warehouse_info") ->alias("a") // ->leftJoin("supplier b","a.supplierNo=b.code") ->leftJoin("warehouse_addr c","a.wsm_code=c.wsm_code and c.is_del=0") ->where(["a.wsm_code"=>$info['wsm_code']]) ->field("a.name as wsm_name,a.contactor,a.contactor_name,a.supplierNo,c.wsm_name as wsm_contactor,c.wsm_mobile,c.wsm_addr,c.addr_code") ->find(); $names = \app\admin\common\User::getIns()->handle('getCodeAndName',['code'=>$wsmcode['supplierNo']]); $info['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:""; $info['wsm_supplier'] =$names['data'][$wsmcode['supplierNo']]??''; $info['wsm_supplierNo'] =$wsmcode['supplierNo']??""; $info['wsm_contactor'] =isset($wsmcode['wsm_contactor']) ? $wsmcode['wsm_contactor']:""; $info['wsm_mobile'] =isset($wsmcode['wsm_mobile']) ? $wsmcode['wsm_mobile']:""; $info['addr_code'] =isset($wsmcode['addr_code']) ? $wsmcode['addr_code']:""; $info['wsm_addr'] =isset($wsmcode['addr_code']) ? GetAddr($wsmcode['addr_code']):""; $info['wsm_addr'].=isset($wsmcode['wsm_addr']) ? $wsmcode['wsm_addr']:""; $info['contactor'] =$wsmcode['contactor']??""; $info['contactor_name'] =$wsmcode['contactor_name']??""; $check = Db::name("purchease_info")->alias("a")->leftJoin("result_info b","a.error_code=b.result_code")->where (['wsm_in_code'=>$incode,"a.is_del"=>0])->field("a.id,a.wsm_in_code,a.num,a.error_code,b.result as error_msg,a.error_img,remark,a.is_del")->select(); $info['checkinfo']= $check; $return = Db::name("purchease_return")->where(['wsm_in_code'=>$incode,"is_del"=>0])->find(); $return['return_contactor']=isset($return['return_contactor'])&&$return['return_contactor']!="" ?$return['return_contactor']:''; $return['return_addr']=isset($return['return_addr'])&&$return['return_addr']!="" ?$return['return_addr']:''; $return['return_mobile']=isset($return['return_mobile'])&&$return['return_mobile']!="" ?$return['return_mobile']:''; //以下字段临时补充到return中 $return['wsm_in_code'] = $incode; $return['wsm_num'] = isset($return['wsm_num']) ? $return['wsm_num'] : 0; $return['reissue_num'] = isset($return['reissue_num']) ? $return['reissue_num'] : 0; $return['return_num'] = isset($return['return_num']) ? $return['return_num'] : 0; $return['contactor'] = $return['return_contactor']; $return['addr'] = $return['return_addr']; $return['mobile'] = $return['return_mobile']; $return['error_remark'] = isset($return['error_remark']) ? $return['error_remark'] : ''; $return['remark'] = isset($return['remark']) ? $return['remark'] : ''; $info['return']= $return; $info['can']=$cat; $info['company'] = ''; if(isset($dom['companyNo'])&&$dom['companyNo']!=""){ // $company = Db::name("business")->where(["companyNo"=>$dom['companyNo']])->find(); $userCommon = \app\admin\common\User::getIns(); $tmp = $userCommon->handle('getCodeAndName', ['code' => [$dom['companyNo']]]); $info['company'] = $tmp['data'][$dom['companyNo']]??''; } // $info['company'] = isset($company['company'])?$company['company']:""; $info['companyNo'] = isset($dom['companyNo'])?$dom['companyNo']:""; $info['order_type'] = isset($dom['order_type'])?$dom['order_type']:""; return app_show(0,'获取成功',$info); } public function check(){ $incode = isset($this->post['wsm_in_code'])&&$this->post['wsm_in_code']!="" ? trim($this->post['wsm_in_code']) :""; if($incode==""){ return error_show(1004,"参数wsm_in_code 不为空"); } $info = Db::name("purchease_in")->where(['wsm_in_code'=>$incode,"is_del"=>0])->find(); if(empty($info)){ return error_show(1004,"未找到数据"); } if($info['status']!=1){ return error_show(1004,"发货单状态有误"); } $order_num = isset($this->post['order_num']) && $this->post['order_num']!==''?intval($this->post['order_num']) :""; if($order_num===""){ return error_show(1004,"参数 order_num 不为空"); } $error_list = isset($this->post['error_list']) && $this->post['error_list']!==''?$this->post['error_list']:""; Db::startTrans(); try{ $order = ["order_code"=>$incode,"status"=>$info['status'],"action_remark"=>'',"action_type"=>"edit"]; $info['wsm_num'] = $order_num; $info['wait_num'] = $info['send_num']; $info['checkid'] = $this->uid; $info['check_name'] = $this->uname; $info['status'] =2; $info['error_num'] = $info['send_num']-$order_num; $info['updatetime'] = date("Y-m-d H:i:s"); $up =Db::name("purchease_in")->save($info); if($up){ ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$order,"RKD",2,$this->post); $uid = Db::name('user_role') ->where([ ['is_del', '=', 0], ['roleid', 'in', [31, 41]], ['status', '=', 1] ])->column('uid'); $handle_user_list = implode(',', $uid); $process=["order_code"=>$info['wsm_in_code'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'RKD',"before_status"=>$order['status'],'holder_id' => $info['apply_id'],"handle_user_list"=>$handle_user_list]; ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process); if(!empty($error_list)){ $data=[]; foreach ($error_list as $value ){ $temp=[]; $temp['wsm_in_code']=$info['wsm_in_code']; $temp['num']=$value['num']; $temp['error_code']=$value['error_code']; $temp['error_img']=$value['error_img']; $temp['remark']=$value['remark']; $temp['is_del']=0; $temp['addtime']=date("Y-m-d H:i:s"); $temp['updatetime']=date("Y-m-d H:i:s"); $data[]=$temp; } $derr= Db::name("purchease_info")->insertAll($data); if($derr){ Db::commit(); return app_show(0,"验货完成"); }else{ Db::rollback(); return error_show(1002,"验货数据保存失败"); } } Db::commit(); return app_show(0,"验货完成"); } Db::rollback(); return error_show(1002,"验货数据保存失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1002,$e->getMessage()); } } public function status(){ $incode = isset($this->post['wsm_in_code'])&&$this->post['wsm_in_code']!="" ? trim($this->post['wsm_in_code']) :""; if($incode==""){ return error_show(1004,"参数wsm_in_code 不为空"); } $info = Db::name("purchease_in")->where(['wsm_in_code'=>$incode,"is_del"=>0])->find(); if(empty($info)){ return error_show(1004,"未找到数据"); } $status = isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):""; if($status===""){ return error_show(1004,"参数status 不为空"); } if($info['status']==4){ return error_show(1004,"入库单已完成"); } $cgdinfo=Db::name("purchease_order")->where(['cgdNo'=>$info['cgdNo'],"is_del"=>0])->find(); if(empty($cgdinfo)){ return error_show(1002,"未找到采购单数据"); } $remark = isset($this->post['remark'])&&$this->post['remark']!="" ? trim($this->post['remark']) :""; $userCommon= \app\admin\common\User::getIns(); $supplier_temp =$userCommon->handle("sInfo",["code"=>$cgdinfo['supplierNo']]); if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1002,"采购单供应商不存在"); $holder_id=$supplier_temp['data']['personid']??0; Db::startTrans(); try{ $order = ["order_code"=>$incode,"status"=>$info['status'],"action_remark"=>'',"action_type"=>"status"]; $info['status'] = $status; $info['remark'] = $remark; $info['updatetime'] = date("Y-m-d H:i:s"); $update = Db::name("purchease_in")->save($info); if($update){ ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$order,"RKD",$status,$this->post); $uid = Db::name('user_role') ->where([ ['is_del', '=', 0], ['roleid', 'in', [31, 41]], ['status', '=', 1] ])->column('uid'); $handle_user_list = implode(',', $uid); $process=["order_code"=>$info['wsm_in_code'],"order_id"=>$info['id'],"order_status"=>$status,"order_type"=>'RKD',"before_status"=>$order['status'],'holder_id' => $info['apply_id'],"handle_user_list"=>$handle_user_list]; ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process); if($status==0){ $order = ["order_code"=>$info['cgdNo'],"status"=>$cgdinfo['status'],"action_remark"=>'',"action_type"=>"edit"]; $cgdinfo['wsend_num']+=$info['send_num']; $cgdinfo['send_num']-=$info['send_num']; $cgdinfo['send_status']=$cgdinfo['wsend_num']==0 ? 3:($cgdinfo['send_num']==0 ?1:2); $cgdinfo['status']=$cgdinfo['wsend_num']==0 ? 3:($cgdinfo['send_num']==0 ?1:2); $cgdinfo['updatetime']=date("Y-m-d H:i:s"); $up=Db::name("purchease_order")->save($cgdinfo); if($up){ ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$order,"CGD", $cgdinfo['status'],$cgdinfo); if($cgdinfo['status']==1 || $cgdinfo['status']==2){ $is_stock = Db::name('good_basic') ->where(['is_del'=>0,'spuCode'=>$cgdinfo['spuCode']]) ->value('is_stock'); if($is_stock==1){ //库存品,推给31库管人员、41库管-张凯旋 $uid = Db::name('user_role') ->where([ ['is_del', '=', 0], ['roleid', 'in', [31, 41]], ['status', '=', 1] ])->column('uid'); if(!in_array($this->uid,$uid)) throw new Exception('库存品订单只能由库管人员操作'); $handle_user_list=implode(",",$uid); // $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0),'handle_user_list'=>implode(',', $uid)]; }else{ //$holder_id = Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0); if($this->uid != $holder_id)throw new Exception('非库存品和采返商品只能由供应商负责人操作'); //$process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>$holder_id,'handle_user_list'=>$holder_id]; }//非库存品和采返商品,推给供应商负责人 }//else $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0)]; $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>$holder_id]; ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process); Db::commit(); return app_show(0,'取消成功'); }else{ Db::rollback(); return error_show(1002,"取消失败"); } } if($status==1){ $order = ["order_code"=>$info['cgdNo'],"status"=>$cgdinfo['status'],"action_remark"=>'',"action_type"=>"edit"]; $cgdinfo['wsend_num']-=$info['send_num']; $cgdinfo['send_num']+=$info['send_num']; $cgdinfo['send_status']=$cgdinfo['wsend_num']==0 ? 3:($cgdinfo['send_num']==0 ?1:2); $cgdinfo['status']=$cgdinfo['wsend_num']==0 ? 3:($cgdinfo['send_num']==0 ?1:2); $cgdinfo['updatetime']=date("Y-m-d H:i:s"); $up=Db::name("purchease_order")->save($cgdinfo); if($up){ ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$order,"CGD", $cgdinfo['status'],$cgdinfo); if($cgdinfo['status'] == 1 || $cgdinfo['status']==2){ $is_stock = Db::name('good_basic') ->where(['is_del'=>0,'spuCode'=>$cgdinfo['spuCode']]) ->value('is_stock'); if($is_stock==1){ //库存品,推给31库管人员、41库管-张凯旋 $uid = Db::name('user_role') ->where([ ['is_del', '=', 0], ['roleid', 'in', [31, 41]], ['status', '=', 1] ])->column('uid'); if(!in_array($this->uid,$uid)) throw new Exception('库存品订单只能由库管人员操作'); $handle_user_list = implode(",",$uid); // $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0),'handle_user_list'=>implode(',', $uid)]; }elseif ($is_stock==0 || $cgdinfo['order_type']==3) { if($this->uid != $holder_id)throw new Exception('非库存品和采返商品只能由供应商负责人操作'); // $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>$holder_id,'handle_user_list'=>$holder_id]; }//非库存品和采返商品,推给供应商负责人 }//else $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0)]; $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>$holder_id];ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process); Db::commit(); return app_show(0,'发货成功'); }else{ Db::rollback(); return error_show(1002,"发货失败"); } } if($status==4){ $order = ["order_code"=>$info['cgdNo'],"status"=>$cgdinfo['status'],"action_remark"=>'',"action_type"=>"edit"]; $cgdinfo['wsend_num']-=$info['send_num']; $cgdinfo['send_num']+=$info['send_num']; $cgdinfo['send_status']=$cgdinfo['wsend_num']==0 ? 3:($cgdinfo['send_num']==0 ?1:2); $cgdinfo['status']=$cgdinfo['wsend_num']==0 ? 3:($cgdinfo['send_num']==0 ?1:2); $cgdinfo['updatetime']=date("Y-m-d H:i:s"); $up=Db::name("purchease_order")->save($cgdinfo); if($up==false){ Db::rollback(); return error_show(1002,"发货失败"); } ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$order,"CGD", $cgdinfo['status'],$cgdinfo); if($cgdinfo['status']==1 || $cgdinfo['status']==2){ $is_stock = Db::name('good_basic') ->where(['is_del'=>0,'spuCode'=>$cgdinfo['spuCode']]) ->value('is_stock'); if($is_stock==1){ //库存品,推给31库管人员、41库管-张凯旋 $uid = Db::name('user_role') ->where([ ['is_del', '=', 0], ['roleid', 'in', [31, 41]], ['status', '=', 1] ])->column('uid'); if(!in_array($this->uid,$uid)) throw new Exception('库存品订单只能由库管人员操作'); }else{ if($this->uid != $holder_id)throw new Exception('非库存品和采返商品只能由供应商负责人操作'); // $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>$holder_id,'handle_user_list'=>$holder_id]; }//非库存品和采返商品,推给供应商负责人 }//else $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0)]; $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>$holder_id]; ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process); $good = Db::name("good_stock")->where(["wsm_code"=>$info['wsm_code'], "spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->find(); if(empty($good)) { $good=[ "spuCode"=>$cgdinfo['spuCode'], "wsm_code"=>$info['wsm_code'], "usable_stock"=>0, "wait_out_stock"=>0, "wait_in_stock"=>$info['wsm_num'], "total_stock"=>0, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s"), ]; $order = ["order_code"=>$good['spuCode'],"status"=>1,"action_remark"=>'', "action_type"=>"create"]; }else{ $order = ["order_code"=>$good['spuCode'],"status"=>1,"action_remark"=>'', "action_type"=>"edit"]; } $good['wait_in_stock']-=$info['wsm_num']; $good['usable_stock']+=$info['wsm_num']; $good['total_stock']=$good['usable_stock']+$good['wait_out_stock']; $good['updatetime'] = date("Y-m-d H:i:s"); $upd= Db::name("good_stock")->save($good); $stockid=$good['id']?? Db::name("good_stock")->getLastInsID(); //商品变动日志表,good_log_code字段存储入库单编号 $good_data[] = ['good_log_code' => $incode, "stock_id" => isset($good['id']) ? $good['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1, 'stock' => $info['wsm_num'], "stock_name" => "usable_stock"]; $good_data[] = ['good_log_code' => $incode, "stock_id" => isset($good['id']) ? $good['id'] :Db::name("good_stock")->getLastInsID(), "type" => 2, 'stock' => $info['wsm_num'], "stock_name" => "wait_in_stock"]; if($upd){ $bnin=GoodStockInfo::AddBn($stockid,$info['bnCode'],$info['wsm_num'],$cgdinfo['good_price']); if($bnin==false){ Db::rollback(); return error_show(1004,"库存bn数据新增失败"); } if($cgdinfo['order_type']==1){ //商品表里的'可用总库存数'增加 Db::name('good') ->data(['updatetime' => date('Y-m-d H:i:s')]) ->where(['is_del' => 0, 'spuCode' => $cgdinfo['spuCode']]) ->inc('usable_stock', $info['wsm_num']) ->update(); } //商品表里的'可用总库存数'增加 GoodLog::LogAdd(['id'=>$this->uid,'nickname'=>$this->uname],$good_data,'RKD'); Db::commit(); return app_show(0,'商品入库成功'); }else{ Db::rollback(); return error_show(1002,"商品入库失败"); } } Db::commit(); return app_show(0,"状态修改完成"); } Db::rollback(); return error_show(1002,"状态修改失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1002,$e->getMessage()); } } /** 0代发货 1库管验货 2仓库主管审核 3 采购审核 4 入库完成 5填写物流 6 退货完成 /** 0代发货 1待库管验货 2入库完成 * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function ReturnAdd(){ $incode = isset($this->post['wsm_in_code'])&&$this->post['wsm_in_code']!="" ? trim($this->post['wsm_in_code']) :""; if($incode==""){ return error_show(1004,"参数wsm_in_code 不为空"); } $info = Db::name("purchease_in")->where(['wsm_in_code'=>$incode,"is_del"=>0])->find(); if(empty($info)){ return error_show(1004,"未找到数据"); } //正常入库数量 $wsm_num = isset($this->post['wsm_num']) &&$this->post['wsm_num']!=="" ? intval($this->post['wsm_num']):"" ; if($wsm_num===""){ return error_show(1004,"参数wsm_num 不为空"); } //补货数量 $reissue_num = isset($this->post['reissue_num']) &&$this->post['reissue_num']!=="" ? intval($this->post['reissue_num']):"0" ; //退货数量 $return_num = isset($this->post['return_num']) &&$this->post['return_num']!=="" ? intval($this->post['return_num']):"0" ; $contactor = isset($this->post['contactor']) &&$this->post['contactor']!=="" ? trim($this->post['contactor']):"" ; if($contactor==""){ return error_show(1004,"参数contactor 不为空"); } $addr = isset($this->post['addr']) &&$this->post['addr']!=="" ? trim($this->post['addr']):"" ; if($addr==""){ return error_show(1004,"参数addr 不为空"); } $mobile = isset($this->post['mobile']) &&$this->post['mobile']!=="" ? trim($this->post['mobile']):"" ; if($mobile==""){ return error_show(1004,"参数mobile 不为空"); } $error_remark = isset($this->post['error_remark']) &&$this->post['error_remark']!=="" ? trim($this->post['error_remark']):"" ; $remark = isset($this->post['remark']) &&$this->post['remark']!=="" ? trim($this->post['remark']):"" ; $cgdinfo=Db::name("purchease_order")->where(['cgdNo'=>$info['cgdNo'],"is_del"=>0])->find(); if(empty($cgdinfo)){ return error_show(1002,"未找到采购单数据"); } $userCommon= \app\admin\common\User::getIns(); $supplier_temp =$userCommon->handle("sInfo",["code"=>$cgdinfo['supplierNo']]); if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1002,"采购单供应商不存在"); $holder_id=$supplier_temp['data']['personid']??0; Db::startTrans(); try{ $sto = ["order_code"=>$incode,"status"=>$info['status'],"action_remark"=>'',"action_type"=>"edit"]; $info['status'] = $info['send_num'] == $wsm_num ? 4 : 5;//艳蓉说,这里不能用入库数量比较,应该是用入库数量,即总数来比较 $info['is_th'] =$return_num>0 ?1:0; $info['wsm_num']= $wsm_num; $info['updatetime'] = date("Y-m-d H:i:s"); $up= Db::name("purchease_in")->save($info); if($up){ //库存品,推给仓库对应的管理员 $uid = Db::name('warehouse_info') ->where(['wsm_code' => $info['wsm_code'], 'is_del' => 0]) ->column('contactor'); $handle_user_list=implode(",",$uid); if($info['status']==4){ $order = ["order_code"=>$info['cgdNo'],"status"=>$cgdinfo['status'],"action_remark"=>'',"action_type"=>"edit"]; $cgdinfo['wsend_num']-=$info['send_num']; $cgdinfo['send_num']+=$info['send_num']; $cgdinfo['send_status']=$cgdinfo['wsend_num']==0 ? 3:($cgdinfo['send_num']==0 ?1:2); $cgdinfo['status']=$cgdinfo['wsend_num']==0 ? 3:($cgdinfo['send_num']==0 ?1:2); $cgdinfo['updatetime']=date("Y-m-d H:i:s"); $up=Db::name("purchease_order")->save($cgdinfo); if($up==false){ Db::rollback(); return error_show(1002,"发货失败"); } ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $order, "CGD", $cgdinfo['status'], $cgdinfo); if($cgdinfo['status']==1 || $cgdinfo['status']==2){ $is_stock = Db::name('good_basic') ->where(['is_del'=>0,'spuCode'=>$cgdinfo['spuCode']]) ->value('is_stock'); if($is_stock==1){ //库存品,推给仓库对应的负责人 if(!in_array($this->uid,$uid)) throw new Exception('库存品订单只能由库管人员操作'); }else{ // $holder_id = Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0); if($this->uid != $holder_id)throw new Exception('非库存品和采返商品只能由供应商负责人操作'); // $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>$holder_id,'handle_user_list'=>$holder_id]; }//非库存品和采返商品,推给供应商负责人 }//else $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0)]; $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>$holder_id]; ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname],$process); $good = Db::name("good_stock")->where(["wsm_code"=>$info['wsm_code'], "spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->find(); if(empty($good)) { $good=[ "spuCode"=>$cgdinfo['spuCode'], "wsm_code"=>$info['wsm_code'], "usable_stock"=>0, "wait_out_stock"=>0, "wait_in_stock"=>$wsm_num, "total_stock"=>0, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s"), ]; $order = ["order_code"=>$good['spuCode'],"status"=>1,"action_remark"=>'', "action_type"=>"create"]; }else{ $order = ["order_code"=>$good['spuCode'],"status"=>1,"action_remark"=>'', "action_type"=>"edit"]; } $good['wait_in_stock']-=$wsm_num; $good['usable_stock']+=$wsm_num; $good['total_stock']=$good['usable_stock']+$good['wait_out_stock']; $good['updatetime'] = date("Y-m-d H:i:s"); $upd= Db::name("good_stock")->save($good); $stockid=$good['id']?? Db::name("good_stock")->getLastInsID(); if($upd){ $bnin=GoodStockInfo::AddBn($stockid,$info['bnCode'],$info['wsm_num'],$cgdinfo['good_price']); if($bnin==false){ Db::rollback(); return error_show(1004,"库存bn数据新增失败"); } }else{ Db::rollback(); return error_show(1002,"商品入库失败"); } $good_data[]=['good_log_code' => $incode,"stock_id"=>isset($good['id'])? $good['id']:Db::name("good_stock")->getLastInsID(),"type"=>1, 'stock'=>$info['wsm_num'],"stock_name"=>"usable_stock"]; $good_data[]=['good_log_code' => $incode,"stock_id"=>isset($good['id'])? $good['id']:Db::name("good_stock")->getLastInsID(),"type"=>2, 'stock'=>$info['wsm_num'],"stock_name"=>"wait_in_stock"]; GoodLog::LogAdd(['id' => $this->uid, 'nickname' => $this->uname],$good_data,'RKD'); $bk =Db::name("order_bk")->where(['cgdNo'=>$cgdinfo['cgdNo']])->lock(true)->find(); if($bk==false){ $bk=[ "cgdNo"=>$cgdinfo['cgdNo'], "spuCode"=>$cgdinfo['spuCode'], "companyNo"=>$cgdinfo['companyNo'], "total_num"=>0, "merge_num"=>0, "balance_num"=>0, "status"=>1, "is_del"=>0, 'addtime'=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; } $bk['balance_num']+=$wsm_num; $bk['total_num']+=$wsm_num; $bk['updatetime']=date("Y-m-d H:i:s"); $upcgd =Db::name("order_bk")->save($bk); if($upcgd==false){ Db::rollback(); return error_show(1004,"采购单数量更新失败"); } } ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname],$sto,"RKD", $info['status'],$this->post); $process=["order_code"=>$info['wsm_in_code'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'RKD',"before_status"=>$sto['status'],'holder_id' => $info['apply_id'],"handle_user_list"=>$handle_user_list??""]; ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname],$process); //需要在详情页把相关退货记录原样取出来,所以这里把if去掉,所有记录都入purchease_return表 if($info['status']==5){ $returnCode=makeNo("CR"); $data=[ "returnCode"=>$returnCode, "wsm_in_code"=>$incode, "cgdNo"=>$cgdinfo['cgdNo'], "wsm_num"=>$wsm_num, "reissue_num"=>$reissue_num, "return_num"=>$return_num, "return_contactor"=>$contactor, "return_addr"=>$addr, "return_mobile"=>$mobile, "error_remark"=>$error_remark, "post_code"=>"", "post_company"=>"", "remark"=>$remark , "apply_id"=>$this->uid, "apply_name"=>$this->uname, "status"=>0, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $res = Db::name("purchease_return")->insert($data,true); if($res==false){ Db::rollback(); return error_show(1002,"验货审核失败"); } $sto = ["order_code"=>$incode,"status"=>0,"action_remark"=>'',"action_type"=>"create"]; ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname],$sto,"RKTHD",0,$data); //维护台账记录 // Db::name('standing_book') // ->where('wsm_in_code', $incode) // ->update([ // 'cgdReturnCode' => $returnCode, // 'updatetime' => date('Y-m-d H:i:s'), // ]); Db::execute("UPDATE `wsm_standing_book` SET `cgdReturnCode`=CONCAT(IFNULL(`cgdReturnCode`,''),',{$returnCode}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE FIND_IN_SET('{$incode}',`wsm_in_code`)");//这里的wsm_in_code可能有多个 } Db::commit(); return app_show(0,"验货审核完成"); } }catch (\Exception $e){ Db::rollback(); return error_show(1002,$e->getMessage()); } } public function ReturnSend(){ $incode = isset($this->post['wsm_in_code'])&&$this->post['wsm_in_code']!="" ? trim($this->post['wsm_in_code']) :""; if($incode==""){ return error_show(1004,"参数wsm_in_code 不为空"); } $info = Db::name("purchease_in")->where(['wsm_in_code'=>$incode,"is_del"=>0])->find(); if(empty($info)){ return error_show(1004,"未找到发货单数据"); } $return = Db::name("purchease_return")->where(['wsm_in_code'=>$incode,"is_del"=>0])->find(); if(empty($return)){ return error_show(1004,"未找到退货单数据"); } $cgdinfo=Db::name("purchease_order")->where(['cgdNo'=>$info['cgdNo'],"is_del"=>0])->find(); if(empty($cgdinfo)){ return error_show(1002,"未找到采购单数据"); } $post_code = isset($this->post['post_code']) &&$this->post['post_code']!=="" ? trim($this->post['post_code']):"" ; if($post_code==""){ return error_show(1004,"参数 post_code 不能为空"); } $post_company = isset($this->post['post_company']) &&$this->post['post_company']!=="" ? trim($this->post['post_company']):"" ; if($post_company==""){ return error_show(1004,"参数 post_company 不能为空"); } $remark = isset($this->post['remark']) &&$this->post['remark']!=="" ? trim($this->post['remark']):"" ; $data=[ "post_code"=>$post_code, "post_company"=>$post_company, "remark"=>$remark, "status"=>1, "updatetime"=>date("Y-m-d H:i:s") ]; $userCommon= \app\admin\common\User::getIns(); $supplier_temp =$userCommon->handle("sInfo",["code"=>$cgdinfo['supplierNo']]); if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1002,"采购单供应商不存在"); $holder_id=$supplier_temp['data']['personid']??0; Db::startTrans(); try{ $up =Db::name("purchease_return")->where($return)->save($data); if($up){ $sto = ["order_code"=>$info['wsm_in_code'],"status"=>$return['status'],"action_remark"=>'', "action_type"=>"edit"]; ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$sto,"RKTHD",1,$this->post); $ark=$info['status']; $info['status']=6; $info['updatetime']=date("Y-m-d H:i:s"); $sa=Db::name("purchease_in")->save($info); if($sa){ $stn = ["order_code"=>$info['wsm_in_code'],"status"=>$ark,"action_remark"=>'',"action_type"=>"edit"]; ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$stn,"RKD",6,$info); // $uid = Db::name('user_role') // ->where([ // ['is_del', '=', 0], // ['roleid', 'in', [31, 41]], // ['status', '=', 1] // ])->column('uid'); //库管人员取仓库管理员 $uid = Db::name('warehouse_info')->where(['is_del'=>0,'wsm_code'=>$info['wsm_code']])->column('contactor'); $handle_user_list = implode(',', $uid); $process=["order_code"=>$info['wsm_in_code'],"order_id"=>$info['id'],"order_status"=>6,"order_type"=>'RKD',"before_status"=>$stn['status'],'holder_id' => $info['apply_id'],"handle_user_list"=>$handle_user_list]; ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process); $good = Db::name("good_stock")->where(["wsm_code"=>$info['wsm_code'], "spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->find(); if(empty($good)) { $good=[ "spuCode"=>$cgdinfo['spuCode'], "wsm_code"=>$info['wsm_code'], "usable_stock"=>0, "wait_out_stock"=>0, "wait_in_stock"=>$return['wsm_num'], "total_stock"=>0, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s"), ]; $order = ["order_code"=>$good['spuCode'],"status"=>1,"action_remark"=>'',"action_type"=>"create"]; }else{ $order = ["order_code"=>$good['spuCode'],"status"=>1,"action_remark"=>'', "action_type"=>"edit"]; } $good['wait_in_stock']-=$return['wsm_num']+$return['return_num']-$return['reissue_num']; $good['usable_stock']+=$return['wsm_num']; $good['total_stock']=$good['usable_stock']+$good['wait_out_stock']; $good['updatetime'] = date("Y-m-d H:i:s"); $upd= Db::name("good_stock")->save($good); if($upd==false){ Db::rollback(); return error_show(1002,"库存更新失败"); } $stockid=$good['id']?? Db::name("good_stock")->getLastInsID(); $bnin=GoodStockInfo::AddBn($stockid,$info['bnCode'],$return['wsm_num'],$cgdinfo['good_price']); if($bnin==false){ Db::rollback(); return error_show(1004,"库存bn数据新增失败"); } $good_data[]=['good_log_code' => $incode,"stock_id"=>$stockid,"type"=>1, 'stock'=>$info['wsm_num'],"stock_name"=>"usable_stock"]; $good_data[]=['good_log_code' => $incode,"stock_id"=>$stockid,"type"=>2, 'stock'=>$good['wait_in_stock'],"stock_name"=>"wait_in_stock"]; GoodLog::LogAdd(['id'=>$this->uid,'nickname'=>$this->uname],$good_data,'RKD'); $order = ["order_code"=>$cgdinfo['cgdNo'],"status"=>$cgdinfo['status'],"action_remark"=>'',"action_type"=>"edit"]; $cgdinfo['wsend_num']-=$return['wsm_num']+$return['return_num']-$return['reissue_num']; $cgdinfo['send_num']+=$return['wsm_num']+$return['return_num']-$return['reissue_num']; $cgdinfo['th_num']+=$return['return_num']-$return['reissue_num']; $cgdinfo['th_fee']=round(($return['return_num']-$return['reissue_num'])*$cgdinfo['good_price'],2); $cgdinfo['send_status']=$cgdinfo['wsend_num']==0 ? 3:($cgdinfo['send_num']==0 ?1:2); $cgdinfo['status']=$cgdinfo['wsend_num']==0 ? 3:($cgdinfo['send_num']==0 ?1:2); if($cgdinfo['th_num']==$cgdinfo['send_num']&& $cgdinfo['wsend_num']==0){ $cgdinfo['status']=4; } $cgdinfo['updatetime']=date("Y-m-d H:i:s"); $up=Db::name("purchease_order")->save($cgdinfo); if($up==false){ Db::rollback(); return error_show(1004,"采购单数量更新失败"); } $bk =Db::name("order_bk")->where(['cgdNo'=>$cgdinfo['cgdNo']])->lock(true)->find(); if($bk==false){ $bk=[ "cgdNo"=>$cgdinfo['cgdNo'], "spuCode"=>$cgdinfo['spuCode'], "companyNo"=>$cgdinfo['companyNo'], "total_num"=>0, "merge_num"=>0, "balance_num"=>0, "status"=>1, "is_del"=>0, 'addtime'=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; } $bk['balance_num']+=$return['wsm_num']; $bk['total_num']+=$return['wsm_num']; $bk['updatetime']=date("Y-m-d H:i:s"); $upcgd =Db::name("order_bk")->save($bk); if($upcgd==false){ Db::rollback(); return error_show(1004,"采购单数量更新失败"); } ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$order,"CGD", $cgdinfo['status'],$cgdinfo); // $holder_id = Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0); if($cgdinfo['status']==1 || $cgdinfo['status']==2){ // $orderinfo = Db::name('sale') // ->alias('a') // ->field('a.id,a.orderCode,a.is_stock,a.order_type,a.cgderid') // ->leftJoin('order_num b','b.orderCode=a.orderCode') // ->where([ // 'a.is_del'=>0, // 'b.cgdNo'=>$cgdinfo['cgdNo'], // ])->findOrEmpty(); $is_stock = Db::name('good_basic') ->where(['is_del'=>0,'spuCode'=>$cgdinfo['spuCode']]) ->value('is_stock'); if($is_stock==1){ //库存品,推给31库管人员、41库管-张凯旋 // $uid = Db::name('user_role') // ->where([ // ['is_del', '=', 0], // ['roleid', 'in', [31, 41]], // ['status', '=', 1] // ])->column('uid'); if(!in_array($this->uid,$uid)) throw new Exception('库存品订单只能由库管人员操作'); // $process=["order_code"=>$cgdinfo['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0),'handle_user_list'=>implode(',', $uid)]; // $handle_user_list = implode(",",$uid); }else{ // $holder_id = Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0); if($this->uid != $holder_id)throw new Exception('非库存品和采返商品只能由供应商负责人操作'); // $process=["order_code"=>$cgdinfo['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>$holder_id,'handle_user_list'=>$holder_id];//非库存品和采返商品,推给供应商负责人 } }//else $process=["order_code"=>$cgdinfo['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0)]; $process=["order_code"=>$cgdinfo['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>$holder_id];//非库存品和采返商品,推给供应商负责人 ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process); Db::commit(); return app_show(0,"退货发货成功"); }else{ Db::rollback(); return error_show(1004,"退货发货失败"); } }else{ return error_show(1004,"退货发货失败"); } }catch (\Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } public function returnList(){ $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]]; $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ? trim($this->post['cgdNo']):""; if($cgdNo!=""){ $where[]=['a.cgdNo',"like", "%$cgdNo%"]; } $returnCode= isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):""; if($returnCode!=""){ $where[]=['a.returnCode',"like", "%$returnCode%"]; } $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[]= ["b.spuCode",'like',"%$good_type_code%"]; } $good_name=isset($this->post['good_name']) && $this->post['good_name']!==""? trim($this->post['good_name']):""; if($good_name !=""){ $where[]= ["b.good_name",'like',"%$good_name%"]; } $status=isset($this->post['status']) && $this->post['status']!==""? trim($this->post['status']):""; if($status!=""){ $where[]= ["a.status",'=',$status]; } $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):""; if($relaComNo!='') $where[]=['b.companyNo','=', $relaComNo]; $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] != "" ? trim($this->post['supplierNo']) : ""; if ($supplierNo != '') $where[] = ['b.supplierNo', '=', $supplierNo]; $order_source = isset($this->post['order_source']) && $this->post['order_source'] != "" ? intval($this->post['order_source']) : ""; if ($order_source != '') $where[] = ['b.order_source', '=', $order_source]; $order_type = isset($this->post['order_type']) && $this->post['order_type'] != "" ? intval($this->post['order_type']) : ""; if ($order_type !== '') $where[] = ['b.order_type', '=', $order_type]; // $role = $this->checkDataShare(); // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ["a.apply_id", "in", $role[DataGroupModel::$type_全部]]; //只有level2的账号过滤数据权限 if ($this->level == 2) { $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]; } } $count = Db::name('purchease_return') ->alias('a') ->leftJoin("purchease_order b","b.cgdNo=a.cgdNo") ->leftJoin("good_basic c","c.spuCode=b.spuCode") ->where($where) ->count(); $total = ceil($count / $size); $page = $page >= $total ? $total : $page; $list = Db::name('purchease_return') ->alias('a') ->leftJoin("purchease_order b","b.cgdNo=a.cgdNo") ->leftJoin("good_basic c","c.spuCode=b.spuCode") ->where($where) ->page($page,$size) ->field("a.*,b.spuCode,b.good_price,b.order_type,b.good_price,b.total_fee,b.good_name,b.order_source,c.is_stock,b.supplierNo,b.supplier_name,b.companyNo,b.companyName") ->order("a.addtime desc") ->select() ->toArray(); $data=[]; // $userCommon = \app\admin\common\User::getIns(); // $names = $userCommon->handle('getCodeAndName',['code'=>array_unique(array_column($list,'companyNo'))]); //校验是否开通了供应商账号 $supp_account = checkHasAccountBySupplierNos(array_unique(array_column($list,'supplierNo'))); foreach ($list as $value){ if (in_array($value['order_type'], [3, 4])) { $goon = Db::name("good_zixun")->field('cat_id')->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find(); }else { $goon =Db::name('good_basic')->field('cat_id')->where(['spuCode'=>$value['spuCode']])->find(); } $value['can']= isset($goon['cat_id']) && $goon['cat_id'] !=0 ? made($goon['cat_id']):[]; $value['return_fee']= round($value['good_price']*$value['return_num'],2); $value['has_account'] = (int)isset($supp_account[$value['supplierNo']]); $data[]=$value; } return app_show(0,"获取成功",['list'=>$data,'count'=>$count]); } //库管验货 0待发货 1 待验货 2验货完成 public function checkOrder(){ $post =$this->request->only(["wsm_in_code"=>"","wsm_num"=>0],"post","trim"); $valide= Validate::rule([ "wsm_in_code|入库单号"=>"require|max:255", "wsm_num|入库数量"=>"require|number" ]); if($valide->check($post)==false)return error_show(1004,$valide->getError()); $info = Db::name("purchease_in")->where(['wsm_in_code'=>$post['wsm_in_code'],"is_del"=>0])->findOrEmpty(); if(empty($info)) return error_show(1004,"未找到入库单数据"); if($info['status']!=1) return error_show(1004,"入库单状态有误"); if($info['send_num'] <$post['wsm_num'])return error_show(1004,"入库数量不可大于发货单总数量"); $cgdinfo = Db::name("purchease_order")->where(["cgdNo"=>$info['cgdNo'],"is_del"=>0])->findOrEmpty(); if(empty($cgdinfo)) return error_show(1004,"未找到采购单信息"); if ($cgdinfo['order_type'] == 1) { //库存品,只能由仓库管理员操作 $contactor = Db::name('warehouse_info')->where(['is_del' => 0, 'wsm_code' => $info['wsm_code']])->value('contactor', 0); if ($this->uid != $contactor) return json_show(1004, '库存品只能由仓库管理员操作'); } $good = Db::name("good_stock")->where(["wsm_code"=>$info['wsm_code'], "spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->findOrEmpty(); if(empty($good)) { $good=[ "spuCode"=>$cgdinfo['spuCode'], "wsm_code"=>$info['wsm_code'], "usable_stock"=>0, "wait_out_stock"=>0, "wait_in_stock"=>$cgdinfo['wsend_num'], "total_stock"=>0, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s"), ]; } Db::startTrans(); try{ $upsend=[ "wsm_num"=>$post['wsm_num'], "error_num"=>$info['send_num'] - $post['wsm_num'], "checkid"=>$this->uid, "check_name"=>$this->uname, "status"=>2, "updatetime"=>date("Y-m-d H:i:s") ]; $up=Db::name("purchease_in")->where($info)->update($upsend); if($up==false) throw new \Exception("入库失败"); $order = ["order_code"=>$post['wsm_in_code'],"status"=>2,"action_remark"=>'',"action_type"=>"status"]; ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$order,"RKD", $info['status'], $info); $cgdstatus=$cgdinfo['status']; $cgdinfo['wsend_num']-=$info['send_num']; $cgdinfo['send_num']+=$info['send_num']; $cgdinfo['th_num']+=$info['send_num'] - $post['wsm_num']; $cgdinfo['th_fee']= round($cgdinfo['th_num']*$cgdinfo['good_price'],2); $cgdinfo['send_status']=$cgdinfo['wsend_num']==0 ? 3:($cgdinfo['send_num']==0 ?1:2); $cgdinfo['status']=$cgdinfo['wsend_num']==0 ? 3:($cgdinfo['send_num']==0 ?1:2); $cgdinfo['updatetime']=date("Y-m-d H:i:s"); $upOrder=Db::name("purchease_order")->save($cgdinfo); if($upOrder==false)throw new \Exception("入库失败"); $order = ["order_code"=>$info['cgdNo'],"status"=>$cgdinfo['status'],"action_remark"=>'',"action_type"=>"status"]; ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$order,"RKD",$cgdstatus, $cgdinfo); $good['wait_in_stock']-=$info['send_num']; $good['usable_stock']+=$post['wsm_num']; $good['total_stock']=$good['usable_stock']+$good['wait_out_stock']; $good['updatetime'] = date("Y-m-d H:i:s"); $upstock = Db::name("good_stock")->save($good); if($upstock==false) throw new \Exception("库存更新失败"); $stockid=$good['id']?? Db::name("good_stock")->getLastInsID(); $buadd= GoodStockInfo::AddBn($stockid,$info['bnCode'],$post['wsm_num'],$cgdinfo['good_price']); if($buadd==false) throw new \Exception("库存bn更新失败"); //商品表里的'可用总库存数'增加 $isGood= Db::name('good')->where(['is_del' => 0, 'spuCode' => $cgdinfo['spuCode']])->findOrEmpty(); if(!empty($isGood)){ $upgood = Db::name('good') ->data(['updatetime' => date('Y-m-d H:i:s')]) ->where(['is_del' => 0, 'spuCode' => $cgdinfo['spuCode']]) ->inc('usable_stock', $post['wsm_num']) ->update(); if($upgood ==false) throw new \Exception("商品库存更新失败"); } if($upsend['error_num']>0){ $returnCode=makeNo("CR"); $data=[ "returnCode"=>$returnCode, "wsm_in_code"=>$post['wsm_in_code'], "cgdNo"=>$cgdinfo['cgdNo'], "wsm_num"=>$post['wsm_num'], "reissue_num"=>0, "return_num"=>$upsend['error_num'], "return_contactor"=>'', "return_addr"=>'', "return_mobile"=>'', "error_remark"=>'', "post_code"=>"", "post_company"=>"", "remark"=>'' , "apply_id"=>$this->uid, "apply_name"=>$this->uname, "status"=>0, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $res = Db::name("purchease_return")->insert($data); if($res==false) throw new \Exception("退货单生成失败"); } Db::commit(); return app_show(0,"验货入库完成"); }catch (\Exception $exception){ Db::rollback(); return error_show(1004,$exception->getMessage()); } } }