noble=\think\facade\Config::get("noble"); } 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 =[["gb.is_del","=",0]]; $condit =[["a.is_del","=",0]]; $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !=="" ? intval($this->post['cat_id']):""; if($cat_id!==""){ $cat_ids=catChild($cat_id); $where[]=['gb.cat_id',"in",$cat_ids]; $condit[]=['a.cat_id',"in",$cat_ids]; } $good_name = isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']):""; if($good_name!==""){ $where[]=['gb.good_name',"like","%$good_name%"]; $condit[]=['a.good_name',"like","%$good_name%"]; } $spucode = isset($this->post['spucode']) && $this->post['spucode'] !=="" ? trim($this->post['spucode']) :""; if($spucode!==""){ $where[]=['gb.spuCode',"like","%$spucode%"]; $condit[]=['a.spuCode',"like","%$spucode%"]; } $good_type = isset($this->post['good_type']) && $this->post['good_type'] !=="" ? trim($this->post['good_type']) :""; if($good_type!==""){ $where[]=['gb.good_type',"=",$good_type]; $condit[]=['a.good_type',"=",$good_type]; } $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) :""; if($companyNo!==""){ $where[]=['gb.companyNo',"like","%$companyNo%"]; $condit[]=['a.companyNo',"like","%$companyNo%"]; } $userCommon = \app\admin\common\User::getIns(); $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :""; if($supplierNo!==""){ $where[]=['gb.supplierNo',"like","%$supplierNo%"]; $condit[]=['a.supplierNo',"like","%$supplierNo%"]; } $supplier = isset($this->post['supplier']) && $this->post['supplier'] !=="" ? trim($this->post['supplier']) :""; if($supplier!==""){ // $suppliernos = Db::name("supplier")->where([["name","like","%$supplier%"]])->column("code"); $tmp = $userCommon->handle('sGetList',['name'=>$supplier]); if(isset($tmp['data']['list']) && !empty($tmp['data']['list'])){ $suppliernos = array_column($tmp['data']['list'],'companyNo'); $where[]=['gb.supplierNo',"in",$suppliernos]; $condit[]=['a.supplierNo',"in",$suppliernos]; } } $company = isset($this->post['company']) && $this->post['company'] !=="" ? trim($this->post['company']) :""; if($company!==""){ // $companyNos = Db::name("business")->where([["company","like","%$company%"]])->column("companyNo"); $tmp = $userCommon->handle('bGetList',['company'=>$company]); if(isset($tmp['data']['list']) && !empty($tmp['data']['list'])){ $companyNos = array_column($tmp['data']['list'],'companyNo'); $where[]=['gb.companyNo',"in",$companyNos]; $condit[]=['a.companyNo',"in",$companyNos]; } } $brandid = isset($this->post['brandid']) && $this->post['brandid'] !=="" ? intval($this->post['brandid']) :""; if($brandid!==""){ $where[]=['gb.brand_id',"=",$brandid]; $condit[]=['a.brand_id',"=",$brandid]; } $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :""; if($status!==""){ $where[]=['gb.status',"=",$status]; $condit[]=['a.status',"=",$status]; } $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] !== "" ? intval($this->post['is_stock']) : ''; if ($is_stock!=='') { $where[] = ['gb.is_stock', "=", $is_stock]; } $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:""; if($start!==""){ $where[]=['gb.addtime',">=",date('Y-m-d H:i:s',strtotime($start))]; $condit[]=['a.addtime',">=",date('Y-m-d H:i:s',strtotime($start))]; } $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:""; if($end!==""){ $where[]=['gb.addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)]; $condit[]=['a.addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)]; } $isonline = isset($this->post['isonline']) && $this->post['isonline']!=="" ? $this->post['isonline']:""; if($isonline!==""){ $condit[] =['b.exam_status',"=",3]; // if($isonline==1){ // $condit[] =['b.exam_status',"=",6]; // }else{ // $condit[] =['b.exam_status',"<>",6]; // } $sta =Db::name("good_basic") ->alias("a") ->leftJoin("good_platform b","a.spuCode=b.spuCode") ->where($condit) ->group("a.spuCode") ->column('a.spuCode'); if($isonline==1) $where[]=["gb.spuCode","in",$sta]; else $where[]=["gb.spuCode","not in",$sta]; } // $token = isset($this->post['token']) ? trim($this->post['token']) : ""; // if($token==""){ // return error_show(101,'token不能为空'); // } // $apply_id =GetUserInfo($token); // if(empty($apply_id)||$apply_id['code']!=0){ // return error_show(102,"申请人数据不存在"); // } // $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : ""; // if($rm!=''){ // $useinfo = Db::name("user_role")->where(['uid'=>$rm,"status"=>1,"is_del"=>0])->find(); // if($useinfo==false){ // return error_show(1002,"未找到用户角色权限"); // } // $check = checkRole($useinfo['roleid'],115); // if($check){ // $where[]=['gb.createrid', "=" ,$rm]; // } // } // $role=$this->checkRole(); // $wheror=[]; // $role = $this->checkDataShare();//取负责人字段 // if(!empty($role[DataGroupModel::$type_全部])) $wheror[]=["gb.chargerid","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[] = ['gb.chargerid|gb.createrid', 'in', $arr]; $supplierNos = Db::connect('mysql_sys') ->name('supplier') ->where(['is_del' => 0, 'personid' => $arr]) ->column('code'); $where[] = ['gb.supplierNo', 'in', $supplierNos]; } } $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : ""; if ($company_name !== "") $where[] = ["gb.createrid", 'in', get_company_item_user_by_name($company_name)]; $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):""; if($relaComNo!="") $where[]=['gb.companyNo','=', $relaComNo]; $count = Db::name('good_basic') ->alias('gb') ->where($where) // ->where(function ($Query) use ($wheror) { // return $Query->whereOr($wheror); // }) ->count('gb.id'); $total = ceil($count / $size); $page = $page >= $total ? $total : $page; $list = Db::name('good_basic') ->alias('gb') ->where($where) ->page($page, $size) ->order("addtime desc") ->select() ->toArray(); $data=[]; $all_createrid = array_column($list,'chargerid'); $item = get_company_name_by_uid($all_createrid); //查询一下这些spucode是否在平台上成功上线 $exam_statuss = Db::name('good_platform') ->whereIn('spuCode',array_column($list,'spuCode')) ->where(['is_del'=>0,'exam_status'=>3])//exam_status==6表示上线审核成功 ->column('id','spuCode'); $exam_status_yz = Db::name('platform_youzan') ->whereIn('spuCode', array_column($list, 'spuCode')) ->where(['is_del' => 0, 'exam_status' => 6])//exam_status==6表示上线审核成功 ->column('id', 'spuCode'); $account = checkHasAccountBySupplierNos(array_column($list, 'supplierNo')); $brand = Db::name('brand') ->where(['id'=>array_column($list,'brand_id')]) ->column('brand_name','id'); $unit = Db::name('unit') ->where(['id'=>array_column($list,'good_unit')]) ->column('unit','id'); // $supplierInfo = $userCommon->handle('getCodeAndName',['code'=>array_merge(array_column($list,'companyNo'),array_column($list,'supplierNo'))]); foreach ($list as $value){ $value["cat_info"]= made($value['cat_id'],[]); // $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find(); $value["brand_name"]=$brand[$value['brand_id']]??'';//isset($brand['brand_name'])?$brand['brand_name']:""; // $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find(); $value['unit'] =$unit[$value['good_unit']]??'';//isset($unit['unit'])?$unit['unit']:""; // $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find(); $value['company'] = $value['companyName'];//$supplierInfo['data'][$value['companyNo']]??'';//isset($company['company'])?$company['company']:""; // $supplier = Db::name("supplier")->where(['code'=>$value['supplierNo']])->find(); $value['supplier_name']=$value['supplierName'];//$supplierInfo['data'][$value['supplierNo']]??'';//isset($supplier['name'])?$supplier['name']:""; $value['exclusive']=makeExcluse($value['is_exclusive']); $value['noble_name']=isset($value['noble_metal'])&&$value['noble_metal']!=0?$this->noble[$value['noble_metal']] :""; //如果一个spucode在任意平台上线,那么就视为它上线,即手动把它的is_online值改为1 if (isset($exam_statuss[$value['spuCode']]) || isset($exam_status_yz[$value['spuCode']])) $value['is_online'] = 1; $value['charger_company_name'] = $item[$value['chargerid']]??''; $value['has_account'] = (int)isset($account[$value['supplierNo']]); //是否具有编辑权限 $value['is_allow_update'] = 0; if ($this->level == 2) { if (in_array($this->roleid, [1, 33]) || in_array($value['chargerid'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1; } elseif ($this->level == 3) $value['is_allow_update'] = 1; $data[] = $value; } return app_show(0, "获取成功", ['count' => $count, 'list' => $data]); } //商品成本列表,不受数据权限控制 public function list_copy() { $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 = [["gb.is_del", "=", 0]]; $condit = [["a.is_del", "=", 0]]; $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !== "" ? intval($this->post['cat_id']) : ""; if ($cat_id !== "") { $cat_ids = catChild($cat_id); $where[] = ['gb.cat_id', "in", $cat_ids]; $condit[] = ['a.cat_id', "in", $cat_ids]; } $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : ""; if ($good_name !== "") { $where[] = ['gb.good_name', "like", "%$good_name%"]; $condit[] = ['a.good_name', "like", "%$good_name%"]; } $spucode = isset($this->post['spucode']) && $this->post['spucode'] !== "" ? trim($this->post['spucode']) : ""; if ($spucode !== "") { $where[] = ['gb.spuCode', "like", "%$spucode%"]; $condit[] = ['a.spuCode', "like", "%$spucode%"]; } $good_type = isset($this->post['good_type']) && $this->post['good_type'] !== "" ? trim($this->post['good_type']) : ""; if ($good_type !== "") { $where[] = ['gb.good_type', "=", $good_type]; $condit[] = ['a.good_type', "=", $good_type]; } $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : ""; if ($companyNo !== "") { $where[] = ['gb.companyNo', "like", "%$companyNo%"]; $condit[] = ['a.companyNo', "like", "%$companyNo%"]; } $userCommon = \app\admin\common\User::getIns(); $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : ""; if ($supplierNo !== "") { $where[] = ['gb.supplierNo', "like", "%$supplierNo%"]; $condit[] = ['a.supplierNo', "like", "%$supplierNo%"]; } $supplier = isset($this->post['supplier']) && $this->post['supplier'] !== "" ? trim($this->post['supplier']) : ""; if ($supplier !== "") { // $suppliernos = Db::name("supplier")->where([["name","like","%$supplier%"]])->column("code"); $tmp = $userCommon->handle('sGetList', ['name' => $supplier]); if (isset($tmp['data']['list']) && !empty($tmp['data']['list'])) { $suppliernos = array_column($tmp['data']['list'], 'companyNo'); $where[] = ['gb.supplierNo', "in", $suppliernos]; $condit[] = ['a.supplierNo', "in", $suppliernos]; } } $company = isset($this->post['company']) && $this->post['company'] !== "" ? trim($this->post['company']) : ""; if ($company !== "") { // $companyNos = Db::name("business")->where([["company","like","%$company%"]])->column("companyNo"); $tmp = $userCommon->handle('bGetList', ['company' => $company]); if (isset($tmp['data']['list']) && !empty($tmp['data']['list'])) { $companyNos = array_column($tmp['data']['list'], 'companyNo'); $where[] = ['gb.companyNo', "in", $companyNos]; $condit[] = ['a.companyNo', "in", $companyNos]; } } $brandid = isset($this->post['brandid']) && $this->post['brandid'] !== "" ? intval($this->post['brandid']) : ""; if ($brandid !== "") { $where[] = ['gb.brand_id', "=", $brandid]; $condit[] = ['a.brand_id', "=", $brandid]; } $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : ""; if ($status !== "") { $where[] = ['gb.status', "=", $status]; $condit[] = ['a.status', "=", $status]; } $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] !== "" ? intval($this->post['is_stock']) : ''; if ($is_stock !== '') { $where[] = ['gb.is_stock', "=", $is_stock]; } $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : ""; if ($start !== "") { $where[] = ['gb.addtime', ">=", date('Y-m-d H:i:s', strtotime($start))]; $condit[] = ['a.addtime', ">=", date('Y-m-d H:i:s', strtotime($start))]; } $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : ""; if ($end !== "") { $where[] = ['gb.addtime', "<", date('Y-m-d H:i:s', strtotime($end) + 24 * 3600)]; $condit[] = ['a.addtime', "<", date('Y-m-d H:i:s', strtotime($end) + 24 * 3600)]; } $isonline = isset($this->post['isonline']) && $this->post['isonline'] !== "" ? $this->post['isonline'] : ""; if ($isonline !== "") { $condit[] = ['b.exam_status', "=", 3]; // if($isonline==1){ // $condit[] =['b.exam_status',"=",6]; // }else{ // $condit[] =['b.exam_status',"<>",6]; // } $sta = Db::name("good_basic") ->alias("a") ->leftJoin("good_platform b", "a.spuCode=b.spuCode") ->where($condit) ->group("a.spuCode") ->column('a.spuCode'); if ($isonline == 1) $where[] = ["gb.spuCode", "in", $sta]; else $where[] = ["gb.spuCode", "not in", $sta]; } // $token = isset($this->post['token']) ? trim($this->post['token']) : ""; // if($token==""){ // return error_show(101,'token不能为空'); // } // $apply_id =GetUserInfo($token); // if(empty($apply_id)||$apply_id['code']!=0){ // return error_show(102,"申请人数据不存在"); // } // $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : ""; // if($rm!=''){ // $useinfo = Db::name("user_role")->where(['uid'=>$rm,"status"=>1,"is_del"=>0])->find(); // if($useinfo==false){ // return error_show(1002,"未找到用户角色权限"); // } // $check = checkRole($useinfo['roleid'],115); // if($check){ // $where[]=['gb.createrid', "=" ,$rm]; // } // } // $role=$this->checkRole(); // $wheror=[]; // $role = $this->checkDataShare();//取负责人字段 // if(!empty($role[DataGroupModel::$type_全部])) $wheror[]=["gb.chargerid","in",$role[DataGroupModel::$type_全部]]; $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : ""; if ($company_name !== "") $where[] = ["gb.createrid", 'in', get_company_item_user_by_name($company_name)]; $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):""; if($relaComNo!="") $where[]=['gb.companyNo','=', $relaComNo]; $count = Db::name('good_basic') ->alias('gb') ->where($where) // ->where(function ($Query) use ($wheror) { // return $Query->whereOr($wheror); // }) ->count('gb.id'); $total = ceil($count / $size); $page = $page >= $total ? $total : $page; $list = Db::name('good_basic') ->alias('gb') ->where($where) ->page($page, $size) ->order("addtime desc") ->select() ->toArray(); $data = []; $all_createrid = array_column($list, 'chargerid'); $item = get_company_name_by_uid($all_createrid); //查询一下这些spucode是否在平台上成功上线 $exam_statuss = Db::name('good_platform') ->whereIn('spuCode', array_column($list, 'spuCode')) ->where(['is_del' => 0, 'exam_status' => 3])//exam_status==3表示上线审核成功 ->column('id', 'spuCode'); $exam_status_yz = Db::name('platform_youzan') ->whereIn('spuCode', array_column($list, 'spuCode')) ->where(['is_del' => 0, 'exam_status' => 6])//exam_status==3表示上线审核成功 ->column('id', 'spuCode'); $account = checkHasAccountBySupplierNos(array_column($list, 'supplierNo')); $brand = Db::name('brand') ->where(['id' => array_column($list, 'brand_id')]) ->column('brand_name', 'id'); $unit = Db::name('unit') ->where(['id' => array_column($list, 'good_unit')]) ->column('unit', 'id'); $supplierInfo = $userCommon->handle('getCodeAndName', ['code' => array_merge(array_column($list, 'companyNo'), array_column($list, 'supplierNo'))]); foreach ($list as $value) { $value["cat_info"] = made($value['cat_id'], []); // $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find(); $value["brand_name"] = $brand[$value['brand_id']] ?? '';//isset($brand['brand_name'])?$brand['brand_name']:""; // $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find(); $value['unit'] = $unit[$value['good_unit']] ?? '';//isset($unit['unit'])?$unit['unit']:""; // $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find(); $value['company'] = $supplierInfo['data'][$value['companyNo']] ?? '';//isset($company['company'])?$company['company']:""; // $supplier = Db::name("supplier")->where(['code'=>$value['supplierNo']])->find(); $value['supplier_name'] = $supplierInfo['data'][$value['supplierNo']] ?? '';//isset($supplier['name'])?$supplier['name']:""; $value['exclusive'] = makeExcluse($value['is_exclusive']); $value['noble_name'] = isset($value['noble_metal']) && $value['noble_metal'] != 0 ? $this->noble[$value['noble_metal']] : ""; //如果一个spucode在任意平台上线,那么就视为它上线,即手动把它的is_online值改为1 if (isset($exam_statuss[$value['spuCode']]) || isset($exam_status_yz[$value['spuCode']])) $value['is_online'] = 1; $value['charger_company_name'] = $item[$value['chargerid']] ?? ''; $value['has_account'] = (int)isset($account[$value['supplierNo']]); // //是否具有编辑权限 // $value['is_allow_update'] = 0; // if ($this->level == 2) { // if (in_array($this->roleid, [1, 33]) || in_array($value['chargerid'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1; // } elseif ($this->level == 3) $value['is_allow_update'] = 1; $data[] = $value; } return app_show(0, "获取成功", ['list' => $data, 'count' => $count]); } public function create(){ $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):""; if($good_name==""){ return error_show(1004,"商品名称不能为空"); } $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):""; if($cat_id==''){ return error_show(1004,"商品分类不能为空"); } $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):""; if($brandid==''){ return error_show(1004,"商品品牌不能为空"); } $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):""; if($unit==''){ return error_show(1004,"商品单位不能为空"); } $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type']) :""; if($good_type===''){ return error_show(1004,"参数good_type不能为空"); } $moq=0; $customized=0; if($good_type==1){ $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):""; if($moq===''){ return error_show(1004,"定制商品起订量不能为空"); } $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):""; if($customized===''){ return error_show(1004,"参数customized不能为空"); } } $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):""; if($is_exclusive===''){ return error_show(1004,"参数is_exclusive不能为空"); } $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):""; if($tax===''){ return error_show(1004,"参数tax不能为空"); } $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):""; if($supplierNo==''){ return error_show(1004,"参数supplierNo不能为空"); } $userCommon= \app\admin\common\User::getIns(); $supplier_temp =$userCommon->handle("hqInfo",["code"=>$supplierNo]); if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1004,"供应商信息未找到"); $supplierArr=$supplier_temp['data']??[]; $supplier=$supplierArr['child']??[]; if ($this->level == 2) { $supplier_account = checkHasAccountBySupplierNos([$supplierNo]); if (isset($supplier_account[$supplierNo])) return json_show(1004, '该供应商已开通账号,不允许操作'); } $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size']):""; if($good_size==''){ return error_show(1004,"参数good_size不能为空"); } $company_id = isset($this->post['company_id'])&&$this->post['company_id']!=""? trim($this->post['company_id']) :""; if($company_id==''){ return error_show(1004,"参数company_id不能为空"); } $companyinfo =$userCommon->handle("getCodeAndName",["code"=>$company_id]); if($supplierArr['relation_code']==$company_id){ return error_show(1004,"业务公司与供应商属于同一家公司"); } $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):""; if($is_auth===''){ return error_show(1004,"参数is_auth不能为空"); } $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):""; // if($auth_img==''){ // return error_show(1004,"商品不能为空"); // } $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):""; if($after_sales==""){ return error_show(1004,"参数after_sales不能为空"); } $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):""; $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):""; if($good_remark===""){ return error_show(1004,"参数good_remark不能为空"); } $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):""; if($weight===""){ return error_show(1004,"参数weight不能为空"); } $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):""; if($packing_way===""){ return error_show(1004,"参数packing_way不能为空"); } $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):""; if($packing_size===""){ return error_show(1004,"参数packing_size不能为空"); } $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):""; if($packing_spec===""){ return error_show(1004,"参数packing_spec不能为空"); } $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):""; if($packing_weight===""){ return error_show(1004,"参数packing_weight不能为空"); } $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):""; if($packing_list===""){ return error_show(1004,"参数packing_list不能为空"); } $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):""; $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):""; if($supply_area===""){ return error_show(1004,"参数supply_area不能为空"); } $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? trim($this->post['delivery_place']):""; if($delivery_place===""){ return error_show(1004,"参数delivery_place不能为空"); } $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? trim($this->post['origin_place']):""; if($origin_place===""){ return error_show(1004,"参数origin_place不能为空"); } $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):""; if($delivery_day===""){ return error_show(1004,"参数delivery_day不能为空"); } $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time']) :"0"; $cgd_gold_price =isset($this->post['cgd_gold_price'])&&$this->post['cgd_gold_price']!==""?floatval($this->post['cgd_gold_price']):"0"; // if($lead_time===""){ // return error_show(1004,"参数lead_time不能为空"); // } $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0"; // if($sample_day===""){ // return error_show(1004,"参数sample_day不能为空"); // } $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0"; $is_stock = isset($this->post['is_stock'])&&$this->post['is_stock']!==""? intval($this->post['is_stock']):""; if($is_stock===""){ return error_show(1004,"参数is_stock不能为空"); } // $stock_moq=0 ;//库存品备库起订量; 如果是0 表示无限制; $stock_moq = isset($this->post['stock_moq'])&&$this->post['stock_moq']!==""? intval($this->post['stock_moq']):"0"; if($is_stock==1 && $stock_moq ==0){ return error_show(1004,"库存品备库起订量不能为零"); } $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"0"; $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):""; $config = isset($this->post['config'])&&$this->post['config']!==""? trim($this->post['config']):""; $other_config = isset($this->post['other_config'])&&$this->post['other_config']!==""? trim($this->post['other_config']):""; if($good_img===""){ return error_show(1004,"参数good_img不能为空"); } $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):""; if($good_thumb_img===""){ return error_show(1004,"参数good_thumb_img不能为空"); } $good_info_img = isset($this->post['good_info_img'])&&$this->post['good_info_img']!=""? trim($this->post['good_info_img']):""; if($good_info_img===""){ return error_show(1004,"参数good_info_img不能为空"); } $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0"; $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0"; $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0"; $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0"; $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0"; $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0"; $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0"; $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0"; $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0"; $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):""; if($market_price===""){ return error_show(1004,"参数market_price不能为空"); } $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"0"; // $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):""; // if($is_step===""){ // return error_show(1004,"参数is_step不能为空"); // } $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:""; $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:""; // if($is_step==1 && $good_ladder==""){ // return error_show(1004,"启用阶梯,阶梯价不能为空"); // } $is_support_barter = isset($this->post['is_support_barter']) && $this->post['is_support_barter'] !== "" ? intval($this->post['is_support_barter']) : 1; $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):""; if($token==''){ return error_show(105,"参数token不能为空"); } // $user =GetUserInfo($token); // if(empty($user)||$user['code']!=0){ // return error_show(1002,"创建人数据不存在"); // } $createrid= $this->uid; $creater= $this->uname; $spucode=makeNo("SKU"); Db::startTrans(); try { $data=[ "spuCode"=>$spucode, "good_code"=>'', "good_name"=>$good_name, "cat_id"=>$cat_id, 'brand_id'=>$brandid, "good_unit"=>$unit, "good_type"=>$good_type, "moq"=>$moq, "is_exclusive"=>$is_exclusive, "customized"=>$customized, "companyNo"=>$company_id, "companyName"=>$companyinfo['data'][$company_id]??"", "tax"=>$tax, "supplierNo"=>$supplierNo, "supplierName"=>$supplierArr['name']??"", "good_size"=>$good_size, "is_auth"=>$is_auth, "is_stock"=>$is_stock, "auth_img"=>$auth_img, "after_sales"=>$after_sales, "craft_desc"=>$craft_desc, "good_remark"=>$good_remark, "weight"=>$weight, "packing_way"=>$packing_way, "packing_size"=>$packing_size, "packing_spec"=>$packing_spec, "packing_list"=>$packing_list, "packing_weight"=>$packing_weight, "good_bar"=>$good_bar, "supply_area"=>$supply_area, "delivery_place"=>$delivery_place, "origin_place"=>$origin_place, "delivery_day"=>$delivery_day, "lead_time"=>$lead_time, "sample_day"=>$sample_day, "sample_fee"=>$sample_fee, "good_img"=>$good_img, "good_thumb_img"=>$good_thumb_img, "good_info_img"=>$good_info_img, "cert_fee"=>$cert_fee, "packing_fee"=>$packing_fee, "cost_fee"=>$cost_fee, "mark_fee"=>$mark_fee, "demo_fee"=>$demo_fee, "open_fee"=>$open_fee, "noble_metal"=>$noble_metal, "cgd_gold_price"=>$cgd_gold_price, "noble_weight"=>$noble_weight, "is_gold_price"=>$is_gold_price, "market_price"=>$market_price, "nake_price"=>$nake_price, "is_diff"=>$is_diff, "config"=>$config, "other_config"=>$other_config, "field_change"=>'', "is_step" => count($good_ladder) > 1 ? 1 : 0,//如果阶梯价个数大于1,说明启用阶梯价 "is_online"=>0, "stock_moq"=>$stock_moq, "status"=>0, "createrid"=>$createrid, "creater"=>$creater, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s"), 'is_support_barter'=>$is_support_barter, 'chargerid'=>$supplier['personid']??$createrid, 'charger'=>$supplier['person']??$creater,//负责人跟创建人一致 ]; $in = Db::name("good_basic")->insertGetId($data); if($in){ if($speclist!=="" && !empty($speclist)){ $temp=[]; foreach ($speclist as $value){ $lemp=[]; $lemp['spuCode']=$spucode; $lemp['spec_id'] = $value['spec_id']; $lemp['spec_value_id'] = $value['spec_value_id']; $lemp['addtime'] = date("Y-m-d H:i:s"); $lemp['updatetime'] =date("Y-m-d H:i:s"); $temp[]=$lemp; } $count = Db::name("good_spec")->insertAll($temp); if($count==0){ Db::rollback(); return app_show(1004,"商品规格值创建失败"); } } // $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find(); // $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0; $top_cat_id = made($cat_id);//获取所有分类 $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id if($good_ladder!=="" && !empty($good_ladder)){ $temp=[]; foreach ($good_ladder as $value){ $lemp=[]; $lemp['spuCode']=$spucode; $lemp['min_num'] = $value['min_num']; $lemp['nake_fee'] = $value['nake_fee']; $lemp['cost_fee'] = $value['cost_fee']; $lemp['delivery_fee'] = $value['delivery_fee']; $lemp['cert_fee'] = $value['cert_fee']; $lemp['mark_fee'] = $value['mark_fee']; $lemp['package_fee'] = $value['package_fee']; $lemp['other_fee'] = $value['other_fee']; if($is_gold_price==1 && $top_cat_id==6){ //$is_gold_price==1 表示启用实时金价,cat_id==6表示贵金属 $gold = Db::name("gold_price1")->where(["type" => $noble_metal, "status" => 1, "is_del" => 0])->order("addtime desc")->find(); //$lemp['nake_total'] = $noble_weight * $gold['price'] + $value['cost_fee'] * $noble_weight + $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee']; //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用 //成本总计启用实时金价时,采用供应商实时金价 $lemp['nake_total'] = $noble_weight *$gold['price'] + $value['cost_fee'] * $noble_weight + $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee']; }else{ $lemp['nake_total'] =$value['nake_fee']+$value['delivery_fee']+$value['cert_fee']+$value['mark_fee']+$value['package_fee']+$value['other_fee']; } $lemp['creater_id'] = $createrid; $lemp['creater'] = $creater; $lemp['is_del'] = 0; $lemp['addtime'] = date("Y-m-d H:i:s"); $lemp['updatetime'] =date("Y-m-d H:i:s"); $temp[]=$lemp; } $count = Db::name("good_nake")->insertAll($temp); if($count==0){ Db::rollback(); return app_show(1004,"商品规格值创建失败"); } } //修改状态,添加待办 ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [ "order_code" =>$spucode,//咨询单详情编号 "status" => 0,//这里的status是之前的值 "action_remark" => '',//备注 "action_type" => "create"//新建create,编辑edit,更改状态status ], "SPCB", 0,$data); ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [ "order_type" => 'SPCB', "order_code" => $spucode,//咨询单详情编号 "order_id" => $in, "order_status" => 0, "before_status" => 0, 'holder_id'=>$data['createrid'], ]); Db::commit(); return app_show(0,"创建成功",["spuCode"=>$spucode]); }else{ Db::rollback(); return app_show(1004,"商品创建失败"); } }catch (\Exception $e){ Db::rollback(); return app_show(1004,$e->getMessage()); } } public function editinfo(){ $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):""; if($supcode==""){ return error_show(1004,"参数spuCode不能为空"); } $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find(); if($data==false){ return error_show(1004,"未找到商品数据"); } $is_down = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->where("exam_status","<>",5) ->find(); if($is_down!=false){ return error_show(1004,"存在未下线商品数据"); } $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):""; if($good_name==""){ return error_show(1004,"商品名称不能为空"); } $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):""; if($cat_id==''){ return error_show(1004,"商品分类不能为空"); } $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"0"; // if($brandid==''){ // return error_show(1004,"商品品牌不能为空"); // } $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):""; if($unit==''){ return error_show(1004,"商品单位不能为空"); } $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type']) :""; if($good_type===''){ return error_show(1004,"参数good_type不能为空"); } $moq=0; $customized=0; if($good_type==1){ $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):""; if($moq===''){ return error_show(1004,"定制商品起订量不能为空"); } $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):""; if($customized===''){ return error_show(1004,"参数customized不能为空"); } } $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):""; if($is_exclusive===''){ return error_show(1004,"参数is_exclusive不能为空"); } // $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):""; // if($customized===''){ // return error_show(1004,"参数customized不能为空"); // } $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):""; if($tax===''){ return error_show(1004,"参数tax不能为空"); } $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):""; if($supplierNo==''){ return error_show(1004,"参数supplierNo不能为空"); } $userCommon= \app\admin\common\User::getIns(); $supplier_temp =$userCommon->handle("hqInfo",["code"=>$supplierNo]); if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1004,"供应商信息未找到"); $supplierArr=$supplier_temp['data']??[]; $supplier=$supplierArr['child']??[]; $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size']) :""; if($good_size==''){ return error_show(1004,"参数good_size不能为空"); } $company_id = isset($this->post['company_id'])&&$this->post['company_id']!=""? trim($this->post['company_id']) :""; if($company_id==''){ return error_show(1004,"参数company_id不能为空"); } $companyinfo =$userCommon->handle("getCodeAndName",["code"=>$company_id]); if($supplierArr['relation_code']==$company_id){ return error_show(1004,"业务公司与供应商属于同一家公司"); } $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):""; if($is_auth===''){ return error_show(1004,"参数is_auth不能为空"); } $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):""; // if($auth_img==''){ // return error_show(1004,"商品不能为空"); // } $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):""; if($after_sales==""){ return error_show(1004,"参数after_sales不能为空"); } $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):""; $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):""; if($good_remark===""){ return error_show(1004,"参数good_remark不能为空"); } $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):""; if($weight===""){ return error_show(1004,"参数weight不能为空"); } $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):""; if($packing_way===""){ return error_show(1004,"参数packing_way不能为空"); } $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):""; if($packing_size===""){ return error_show(1004,"参数packing_size不能为空"); } $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):""; if($packing_spec===""){ return error_show(1004,"参数packing_spec不能为空"); } $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):""; if($packing_weight===""){ return error_show(1004,"参数packing_weight不能为空"); } $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):""; if($packing_list===""){ return error_show(1004,"参数packing_list不能为空"); } $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):""; $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):""; if($supply_area===""){ return error_show(1004,"参数supply_area不能为空"); } $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? $this->post['delivery_place']:""; if($delivery_place===""){ return error_show(1004,"参数delivery_place不能为空"); } $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? $this->post['origin_place']:""; if($origin_place===""){ return error_show(1004,"参数origin_place不能为空"); } $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):""; if($delivery_day===""){ return error_show(1004,"参数delivery_day不能为空"); } $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time']) :"0"; // if($lead_time===""){ // return error_show(1004,"参数lead_time不能为空"); // } $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0"; // if($sample_day===""){ // return error_show(1004,"参数sample_day不能为空"); // } // $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval //($this->post['sample_fee']):"0"; $config = isset($this->post['config'])&&$this->post['config']!==""? trim($this->post['config']):""; $other_config = isset($this->post['other_config'])&&$this->post['other_config']!==""? trim($this->post['other_config']):""; $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"0"; $is_stock = isset($this->post['is_stock'])&&$this->post['is_stock']!==""? intval($this->post['is_stock']):"0"; $stock_moq = isset($this->post['stock_moq'])&&$this->post['stock_moq']!==""? intval($this->post['stock_moq']):"0"; if($is_stock==1 && $stock_moq ==0){ return error_show(1004,"库存品备库起订量不能为零"); } $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):""; if($good_img===""){ return error_show(1004,"参数good_img不能为空"); } $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):""; if($good_thumb_img===""){ return error_show(1004,"参数good_thumb_img不能为空"); } $good_info_img = isset($this->post['good_info_img'])&&!empty($this->post['good_info_img'])? trim($this->post['good_info_img']):""; if($good_info_img===""){ return error_show(1004,"参数good_info_img不能为空"); } $count = Db::name("good_nake")->where(["spuCode"=>$supcode,"is_del"=>0])->count(); $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:""; Db::startTrans(); try { $temp=[ "good_name"=>$good_name, "cat_id"=>$cat_id, 'brand_id'=>$brandid, "good_unit"=>$unit, "good_type"=>$good_type, "companyNo"=>$company_id, "companyName"=>$companyinfo['data'][$company_id]??'', "supplierName"=>$supplierArr['name']??"", "moq"=>$moq, "is_exclusive"=>$is_exclusive, "customized"=>$customized, "tax"=>$tax, "supplierNo"=>$supplierNo, "is_auth"=>$is_auth, "good_size"=>$good_size, "auth_img"=>$auth_img, "after_sales"=>$after_sales, "craft_desc"=>$craft_desc, "good_remark"=>$good_remark, "weight"=>$weight, "packing_way"=>$packing_way, "packing_size"=>$packing_size, "packing_spec"=>$packing_spec, "packing_list"=>$packing_list, "packing_weight"=>$packing_weight, "good_bar"=>$good_bar, "supply_area"=>$supply_area, "delivery_place"=>$delivery_place, "origin_place"=>$origin_place, "delivery_day"=>$delivery_day, "lead_time"=>$lead_time, "sample_day"=>$sample_day, "is_diff"=>$is_diff, 'is_stock'=>$is_stock, "config"=>$config, "other_config"=>$other_config, "good_img" => $good_img, "stock_moq" => $stock_moq, "good_thumb_img"=>$good_thumb_img, "good_info_img"=>$good_info_img, "status"=>$count>0?2:1, "updatetime" => date("Y-m-d H:i:s"), 'chargerid' => $supplier['personid'] ?? $this->uid, 'charger' => $supplier['person'] ?? $this->uname,//负责人跟创建人一致 ]; $field = array_diff_assoc($temp,$data); $temp['field_change'] =empty($field)?"":json_encode(array_keys($field)); $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($temp); $timp = array_diff($temp,$data); $json = json_encode($timp,JSON_UNESCAPED_UNICODE); $jsp = json_encode($data,JSON_UNESCAPED_UNICODE); if($up){ ChangeLog::logAdd(3,$data['spuCode'],$jsp,$json,['id' => $this->uid, 'nickname' => $this->uname]); if($speclist!=="" && !empty($speclist)){ foreach ($speclist as $value){ $lemp=[]; isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:""; $lemp['spuCode']=$supcode; $lemp['spec_id'] = $value['spec_id']; $lemp['spec_value_id'] = $value['spec_value_id']; $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0; isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s"); $lemp['updatetime'] =date("Y-m-d H:i:s"); $count = Db::name("good_spec")->save($lemp); if($count==false){ Db::rollback(); return app_show(1004,"商品规格值修改失败"); } } } //修改状态,添加待办 ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [ "order_code" =>$supcode,//咨询单详情编号 "status" => $data['status'],//这里的status是之前的值 "action_remark" => '',//备注 "action_type" => "edit"//新建create,编辑edit,更改状态status ], "SPCB",$temp['status'] ,$data); ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [ "order_type" => 'SPCB', "order_code" => $supcode,//咨询单详情编号 "order_id" => $data['id'], "order_status" =>$temp['status'], "before_status"=>$data['status'], 'holder_id'=>$data['createrid'], ]); Db::commit(); return app_show(0,"更新成功"); }else{ Db::rollback(); return error_show(1005,"更新失败"); } }catch (\Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } public function editfee(){ $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):""; if($supcode==""){ return error_show(1004,"参数spuCode不能为空"); } $datas = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find(); if($datas==false){ return error_show(1004,"未找到商品数据"); } $is_down = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->where("exam_status","<>",5) ->find(); if($is_down!=false){ return error_show(1004,"存在未下线商品数据"); } $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0"; $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0"; $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0"; $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0"; $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0"; $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0"; $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0"; $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0"; $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0"; $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0"; $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):""; $cgd_gold_price = isset($this->post['cgd_gold_price'])&&$this->post['cgd_gold_price']!==""? floatval($this->post['cgd_gold_price']):"0"; if($market_price===""){ return error_show(1004,"参数market_price不能为空"); } $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):""; // $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):""; // if($is_step===""){ // return error_show(1004,"参数is_step不能为空"); // } $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:""; // if($is_step==1 && $good_ladder==""){ // return error_show(1004,"启用阶梯,阶梯价不能为空"); // } $data=[ "cert_fee"=>$cert_fee, "packing_fee"=>$packing_fee, "cost_fee"=>$cost_fee, "mark_fee"=>$mark_fee, "demo_fee"=>$demo_fee, "open_fee"=>$open_fee, "sample_fee"=>$sample_fee, "noble_metal"=>$noble_metal, "noble_weight"=>$noble_weight, "is_gold_price"=>$is_gold_price, "market_price"=>$market_price, "nake_price"=>$nake_price, "cgd_gold_price"=>$cgd_gold_price, "is_step" => count($good_ladder) > 1 ? 1 : 0, "status"=>"3", "updatetime"=>date("Y-m-d H:i:s") ]; $field = array_diff_assoc($data,$datas); $data['field_change'] =empty($field)?"":json_encode(array_keys($field)); Db::startTrans(); try{ $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($data); $temp = array_diff($data,$datas); $json = json_encode($temp,JSON_UNESCAPED_UNICODE); $jsp = json_encode($datas,JSON_UNESCAPED_UNICODE); if($up){ ChangeLog::logAdd(3,$datas['spuCode'],$jsp,$json,['id' => $this->uid, 'nickname' => $this->uname]); //修改状态,添加待办 ActionLog::logAdd($this->post['token'], [ "order_code" =>$supcode,//咨询单详情编号 "status" => $datas['status'],//这里的status是之前的值 "action_remark" => '',//备注 "action_type" => "edit"//新建create,编辑edit,更改状态status ], "SPCB",$data['status'] ,$data); ProcessOrder::AddProcess($this->post['token'], [ "order_type" => 'SPCB', "order_code" => $supcode,//咨询单详情编号 "order_id" => $datas['id'], "order_status" =>$data['status'], "before_status"=>$datas['status'], 'holder_id'=>$datas['createrid'], ]); // $online = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->find(); // if($online){ // $onup = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->save // (["exam_status"=>2,"updatetime"=>date("Y-m-d H:i:s")]); // if($onup==false){ // Db::rollback(); // return app_show(1004,"商品规成本修改失败"); // } // //修改状态,添加待办 // ActionLog::logAdd($this->post['token'], [ // "order_code" =>$online['skuCode'],//咨询单详情编号 // "status" => $online['exam_status'],//这里的status是之前的值 // "action_remark" => '',//备注 // "action_type" => "edit"//新建create,编辑edit,更改状态status // ], "SPSX",2,["exam_status"=>2,"updatetime"=>date("Y-m-d H:i:s")]); // // ProcessOrder::AddProcess($this->post['token'], [ // "order_type" => 'SPSX', // "order_code" => $online['skuCode'],//咨询单详情编号 // "order_id" => $online['id'], // "order_status" =>2,"before_status"=>$online['exam_status'] // ]); // } if($good_ladder!=="" && !empty($good_ladder)){ $user =GetUserInfo($this->post['token']); foreach ($good_ladder as $value){ $lemp=[]; isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:""; $lemp['spuCode']=$supcode; $lemp['min_num'] = $value['min_num']; $lemp['nake_fee'] = $value['nake_fee']; $lemp['cost_fee'] = $value['cost_fee']; $lemp['delivery_fee'] = $value['delivery_fee']; $lemp['cert_fee'] = $value['cert_fee']; $lemp['mark_fee'] = $value['mark_fee']; $lemp['package_fee'] = $value['package_fee']; $lemp['other_fee'] = $value['other_fee']; $top_cat_id = made($datas['cat_id']);//获取所有分类 $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id if($is_gold_price==1 && $top_cat_id==6){ $gold =Db::name("gold_price1")->where(["type"=>$noble_metal,"status"=>1,"is_del"=>0])->order("addtime desc")->find(); //$lemp['nake_total'] =$noble_weight*$gold['price'] + $value['cost_fee']*$noble_weight+$value['mark_fee']+$value['package_fee']+$value['cert_fee']+$value['nake_fee']+$value['delivery_fee']+$value['other_fee']; //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用 //成本总计启用实时金价时,采用供应商实时金价 $lemp['nake_total'] = $noble_weight * $gold['price']+ $value['cost_fee'] * $noble_weight + $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee']; }else{ $lemp['nake_total'] =$value['nake_fee']+$value['delivery_fee']+$value['cert_fee']+$value['mark_fee']+$value['package_fee']+$value['other_fee']; } $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0; $lemp['creater_id'] = isset($user["data"]['id']) ? $user["data"]['id'] : ""; $lemp['creater'] =isset($user["data"]['nickname']) ? $user["data"]['nickname'] : ""; isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s"); $lemp['updatetime'] =date("Y-m-d H:i:s"); $count = Db::name("good_nake")->save($lemp); if($count==false){ Db::rollback(); return app_show(1004,"商品规成本修改失败"); } } } Db::commit(); return app_show(0,"更新成功"); }else{ Db::rollback(); return error_show(1005,"更新失败"); } }catch (\Exception $e){ Db::rollback(); return error_show(1005,$e->getMessage()); } } public function exam(){ $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):""; if($supcode==""){ return error_show(1004,"参数spuCode不能为空"); } $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find(); if($data==false){ return error_show(1004,"未找到商品数据"); } $isupdate = $this->isUpdate($supcode); if($isupdate==0){ return error_show(1004,"存在上线进行中的商品"); } if($data['status']==1){ return error_show(1004,"商品已审核通过"); } $status = isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):""; // if($status===""){ // return error_show(1004,"参数status不能为空"); // } $remark = isset($this->post['remark'])&&$this->post['remark']!=="" ? trim($this->post['remark']):""; // if($remark===""){ // return error_show(1004,"参数remark不能为空"); // } $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):""; if($token==''){ return error_show(105,"参数token不能为空"); } $createrid=$this->uid; $creater= $this->uname; Db::startTrans(); try { if($data['status']==3 && $status==1){ //区分是否是对接平台 $platform_info=Db::name('platform') ->field('id,platform_type') ->where(['is_del'=>0,'platform_type'=>1]) ->column("id"); $online = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->whereNotIn("platform_code",$platform_info)->find(); if($online) { $onl= Db::name("good_platform")->where(["spuCode" => $supcode, "is_del" => 0])->whereNotIn("platform_code",$platform_info)->save(["exam_status" => 2, "updatetime" => date("Y-m-d H:i:s")]); if ($onl == false) { Db::rollback(); return error_show(1004, "审核失败"); } ActionLog::logAdd($this->post['token'], [ "order_code" =>$online['skuCode'],//咨询单详情编号 "status" => $online['exam_status'],//这里的status是之前的值 "action_remark" => '',//备注 "action_type" => "edit"//新建create,编辑edit,更改状态status ], "SPSX", 2, ["exam_status" => 2, "updatetime" => date("Y-m-d H:i:s")]); ProcessOrder::AddProcess($this->post['token'], [ "order_type" => 'SPSX', "order_code" =>$online['skuCode'],//咨询单详情编号 "order_id" => $online['id'], "order_status" => 2, "before_status"=>$online['exam_status'], 'holder_id' => $online['createrid'], ]); } } // if ($status == 1) { // //把同一个spuCode,且状态为1待完善成本,的记录更改状态为2待产品审核 // Db::name('good') // ->where(['is_del' => 0, 'status' => 1]) // ->whereIn('spuCode', $supcode) // ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]); // } $old_status = $data['status']; $data['status']=$status; $data['updatetime']=date("Y-m-d H:i:s"); $up= Db::name("good_basic")->save($data); if($up){ //修改状态,添加待办 ActionLog::logAdd($this->post['token'], [ "order_code" =>$supcode,//咨询单详情编号 "status" => $status,//这里的status是之前的值 "action_remark" => '',//备注 "action_type" => "edit"//新建create,编辑edit,更改状态status ], "SPCB",$data['status'] ,$data); ProcessOrder::AddProcess($this->post['token'], [ "order_type" => 'SPCB', "order_code" => $supcode,//咨询单详情编号 "order_id" => $data['id'], "order_status" =>$data['status'], "before_status"=>$old_status, 'holder_id'=>$data['createrid'], ]); $data=[ "code"=>$supcode, "exam_status"=>$status, "type"=>1, "exam_id"=>$createrid, "exam_name"=>$creater, "exam_remark"=>$remark, "addtime"=>date("Y-m-d H:i:s") ]; $inr=Db::name("good_exam")->insert($data); if($inr){ Db::commit(); return app_show(0,"审核成功"); }else{ Db::rollback(); return error_show(1004,"审核失败"); } }else{ Db::rollback(); return error_show(1004,"审核失败"); } }catch (\Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } public function info(){ $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):""; if($supcode==""){ return error_show(1004,"参数spuCode不能为空"); } $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find(); if($data==false){ return error_show(1004,"未找到商品数据"); } $unit =Db::name("unit")->where(["id"=>$data['good_unit']])->find(); $data['unit'] = isset($unit['unit'])?$unit['unit']:''; $data['cat_info'] = made($data['cat_id'],[]); $spec = Db::name("good_spec")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray(); $userCommon = \app\admin\common\User::getIns(); $sinfo = $userCommon->handle('sInfo',['code'=>$data['supplierNo']]); // $names = $userCommon->handle('getCodeAndName', ['code' => [$data['supplierNo'], $data['companyNo']]]); // $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find(); // $data['supplierName'] = $names['data'][$data['supplierNo']] ?? '';//isset($supplier['name']) //?$supplier['name']:""; // $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find(); // $data['company'] = $names['data'][$data['companyNo']] ?? ''; //isset($company['company'])?$company['company']:""; $data['field_change'] = $data['field_change']!=''?json_decode($data['field_change']):""; if($data['brand_id']!=0){ $brand=Db::name("brand")->where(["id"=>$data['brand_id']])->find(); $data["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:""; }else{ $data["brand_name"]=""; $data["brand_id"]=""; } $excluse = makeExcluse($data['is_exclusive']); $data['exclusive']=$excluse; $data['noble_name']=isset($data['noble_metal'])&&$data['noble_metal']!=0?$this->noble[$data['noble_metal']] :""; $data["good_info_img"]=$data['good_info_img']!=""? $data['good_info_img']:''; $data["good_img"]=$data['good_img']!=""? $data['good_img']:[]; $gold=[]; if ($data['is_gold_price'] == 1) { $gold = Db::name("gold_price1")->where(["type" => $data['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->find(); } $data['gold_price'] =isset($gold["price"])?$gold["price"]:0; $speclist=[]; if(!empty($spec)){ foreach ($spec as $value){ $temp=[]; $temp['id']=$value['id']; $temp['spuCode']=$value['spuCode']; $temp['spec_id']=$value['spec_id']; $temp['spec_value_id']=$value['spec_value_id']; $temp['is_del']=$value['is_del']; $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find(); $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:""; $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find(); $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:""; $speclist[]=$temp; } } $data["speclist"]=empty($speclist)?[]:$speclist; // $nake=[]; $nakelist = Db::name("good_nake")->where(['spuCode'=>$supcode,"is_del"=>0])->select()->toArray(); // $catinfo = Db::name("cat")->where(["id"=>$data['cat_id']])->find(); // $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0; $nakearry=[]; if(!empty($nakelist)){ foreach ($nakelist as $value) { $nakearry[] = $value; } } $data["nakelist"]=$nakearry; $data['cgderid'] = $sinfo['data']['personid'] ?? ''; $data['cgder'] = $sinfo['data']['person'] ?? ''; return app_show(0,"获取成功",$data); } //删除商品成本 public function delall() { $supcode = $this->request->post('codes', '', 'trim'); if ($supcode == "") { return error_show(1004, "参数codes不能为空"); } Db::startTrans(); try { $good_basic = Db::name("good_basic") ->field('id,spuCode,status') ->where(["spuCode" => $supcode, "is_del" => 0]) ->select()->toArray(); if (empty($good_basic)) throw new Exception('该记录不存在或已删除'); $good = Db::name('good') ->alias('g') ->field('gp.id,gp.exam_status,gp.skuCode') ->leftJoin('good_platform gp', 'gp.spuCode=g.spuCode AND gp.is_del=0') ->where(['g.spuCode' => $supcode, 'g.is_del' => 0]) ->where('gp.exam_status',"<>",5) ->select()->toArray(); if (!empty($good)) throw new Exception('该商品需要下线之后才能删除'); Db::name("good_basic") ->where(["spuCode" => $supcode, 'is_del' => 0]) ->update(['is_del' => 1, 'updatetime' => date('Y-m-d H:i:s')]); Db::name("good") ->where(['spuCode' => $supcode, 'is_del' => 0]) ->update(['is_del' => 1, 'updatetime' => date('Y-m-d H:i:s')]); Db::name("good_platform") ->where(['spuCode' => $supcode, 'is_del' => 0]) ->where('exam_status', "<>",5) ->update(['is_del' => 1, 'updatetime' => date('Y-m-d H:i:s')]); Db::name("good_ladder")->where(["skuCode"=>array_column($good,"skuCode"),"is_del"=>0])->update(['is_del' => 1, 'updatetime' => date('Y-m-d H:i:s')]); Db::name("good_nake")->where(["spuCode"=>$supcode,"is_del"=>0])->update(['is_del' => 1, 'updatetime' => date('Y-m-d H:i:s')]); ProcessOrder::workdel(["order_type" => "SPCB", "order_code" => $supcode]); ProcessOrder::workdel(["order_type" => "SPSX", "order_code" => array_column($good,"skuCode")]); Db::commit(); app_show(0, "删除成功"); } catch (Exception $exception) { Db::rollback(); return error_show(1005, "删除失败," . $exception->getMessage()); } } //添加上线商品 public function online(){ $platform =isset($this->post['platform'])&&!empty($this->post['platform'])? $this->post['platform']:""; if($platform==""){ return error_show(1004,"参数platform不能为空"); } $spuCode =isset($this->post['codes'])&&!empty($this->post['codes'])? $this->post['codes']:""; if($spuCode===''){ return error_show(1004,"参数codes不能为空"); } $datas = Db::name("good_basic")->where(["spuCode"=>$spuCode,"is_del"=>0])->select()->toArray(); if(empty($datas)){ return error_show(1004,"未找到商品数据"); } $online_reason = isset($this->post['online_reason'])&&$this->post['online_reason']!==""? trim($this->post['online_reason']):""; if($online_reason===""){ return error_show(1004,"参数online_reason不能为空"); } $online_remark= isset($this->post['online_remark'])&&$this->post['online_remark']!==""? trim($this->post['online_remark']):""; if($online_remark===""){ return error_show(1004,"参数online_remark不能为空"); } $createrid= $this->uid;//isset($user["data"]['id']) ? $user["data"]['id'] : ""; $creater= $this->uname;//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : ""; //区分是否是对接平台 $platform_info=Db::name('platform') ->field('id,platform_type,is_select_pay_rate') ->where(['is_del'=>0,'id'=>$platform]) ->findOrEmpty(); if(empty($platform_info)) return error_show(1005,'所选的平台不存在'); if($platform_info['is_select_pay_rate']==1){ //所选的商品成本中的业务公司,不能和支付渠道中的业务公司重复 $companyNo = Db::name('platform_pay_rate') ->where(['platform_id'=>$platform,'is_del'=>0]) ->column('companyNo'); $tmp = Db::name("good_basic") ->field('id,spuCode,good_name,companyNo,good_thumb_img') ->where(["spuCode"=>$spuCode,"is_del"=>0]) ->whereIn('companyNo',$companyNo) ->select() ->toArray(); if(!empty($tmp)) return json_show(1009,'以下商品的业务公司和平台支付渠道中的业务公司重复,不允许上线',$tmp); } if($platform_info['platform_type']==1) return \app\youzan\logic\Goodup::create([ 'platform_id'=>$platform, 'online_reason'=>$online_reason, 'online_remark'=>$online_remark, 'good_data'=>$datas, 'createrid'=>$createrid, 'creater'=>$creater, ]); $data=[]; $isonline=[]; $i=0; Db::startTrans(); try{ foreach ($datas as $value){ $count = Db::name("good_nake")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->count(); $ist =Db::name("good_platform")->where(["spuCode"=>$value['spuCode'],"platform_code"=>$platform,"is_del"=>0])->find(); if($ist){ $god=Db::name("good_basic")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find(); if($god){ $tp=[]; $tp['spuCode']=$value['spuCode']; $tp['good_name']=$god['good_name']; $tp['good_img']=$god['good_thumb_img']; $tp['exam_status']=$ist['exam_status']; $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']; $temp['is_del']=$val['is_del']; $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; } } $tp["speclist"]=empty($speclist)?[]:$speclist; $isonline[]=$tp; } } if(!empty($isonline)){ return app_show(1009,"存在已上线产品",$isonline); } //改变编码规则,将原来的skuCode后两位换成序列号 //str_pad字符串填充 $skuCode = makeNo("SN"); $skuCode = substr($skuCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT); $tmp=[ "spuCode"=>$value['spuCode'], "skuCode"=>$skuCode, "platform_code"=>$platform, "online_reason"=>$online_reason, "online_remark"=>$online_remark, "exam_status"=>$count>0 ?2:1, "is_online"=>0, "status"=>1, "is_del"=>0, "creater"=>$creater, "createrid"=>$createrid, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $i++; $create =Db::name("good_platform")->insert($tmp,true); if($create>0){ $iso = Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->findOrEmpty(); if(empty($iso)){ unset($value['id']); $stock_num = Db::name('good_stock')->alias("a") ->leftJoin("warehouse_info b","a.wsm_code=b.wsm_code") ->where(['a.is_del' => 0, 'a.spuCode' =>$value['spuCode'],"b.wsm_type"=>[2,5]])->sum('usable_stock'); $value['usable_stock'] =$stock_num; $value['addtime']=date("Y-m-d H:i:s"); $value['updatetime']=date("Y-m-d H:i:s"); }else{ $value['id']=$iso['id']; $value['updatetime']=date("Y-m-d H:i:s"); } $up = Db::name("good")->strict(false)->save($value); if(!$up){ Db::rollback(); return error_show(1004,"提交失败"); } //修改状态,添加待办 ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [ "order_code" => $skuCode,//编号 "status" => 0, "action_remark" => '',//备注 "action_type" => 'create'//新建create,编辑edit,更改状态status ], "SPSX", $tmp['exam_status'], $platform); ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [ "order_type" => 'SPSX', "order_code" => $skuCode,//咨询单详情编号 "order_id" => $create, "order_status" => $tmp['exam_status'], "before_status" => 0, 'holder_id' => $createrid, ]); }else{ Db::rollback(); return error_show(1004,"提交失败"); } } Db::commit(); return app_show(0,"提交成功"); }catch (\Exception $e){ Db::rollback(); return error_show(1004, $e->getMessage()); } } //审核 public function online_exam(){ $post =$this->request->only([ "skuCode"=>"", //商品成本编号 "exam_status"=>"", //审核状态 1 提交待完善成本 2待审核 3上线完成 4 审核驳回 5 下线完成 "offline_reason"=>"", //下线原因 "offline_remark"=>"", //下线备注 "plat_code"=>"", //平台订单号 'exam_remark'=>"", //审核备注 'good_ladder'=>[], //售价阶梯 'proof_type'=>"", // 售价凭证类型 'proof_url'=>"", // 售价凭证 ],"post","trim"); $valide = Validate::rule([ "skuCode|商品编号"=>"require|max:255", "exam_status|审核状态"=>"require|number|in:0,1,2,3,4,5", "offline_reason|线下原因"=>"requireIf:exam_status,5|max:255", "offline_remark|下线备注"=>"requireIf:exam_status,5|max:255", "plat_code|平台商品编码"=>"requireIf:exam_status,3|max:255", 'exam_remark|审核备注'=>"max:255", 'good_ladder|售价阶梯'=>"requireIf:exam_status,3|array", 'proof_type|售价凭证类型'=>"requireIf:exam_status,3|number|gt:0", 'proof_url|售价凭证'=>"requireIf:exam_status,3|max:255", ]); if($valide->check($post)==false) return error_show(1004,$valide->getError()); $platform = Db::name("good_platform")->where(["skuCode"=>$post['skuCode'],"is_del"=>0])->find(); if($platform==false){ return error_show(1004,"未找到数据"); } if($post['exam_status']==3){ $is_exit = Db::name("good_platform") ->where(["plat_code" =>$post['plat_code'], "platform_code" => $platform['platform_code'], "is_del" =>0, 'exam_status' =>3])//exam_status==3已上线 ->where("id", "<>", $platform['id']) ->find(); if($is_exit==false){ $platform['plat_code']=$post['plat_code']; }else{ return error_show(1004,"平台商品编码 {$post['plat_code']} 已存在"); } } if($post['exam_status']==5){ $platform['is_compliance']=0; $platform['compliance_remark']=''; } $before = $platform['exam_status']; $platform['exam_status']=$post['exam_status']; $platform['updatetime']=date("Y-m-d H:i:s"); $createrid= $this->uid; $creater= $this->uname; Db::startTrans(); try { $up = Db::name("good_platform")->save($platform); if($up){ $data=[ "code"=>$platform['skuCode'], "exam_status"=>$post['exam_status'],//$exam_status, "type"=>2, "exam_id"=>$createrid, "exam_name"=>$creater, "exam_remark"=>$post['exam_remark'], "addtime"=>date("Y-m-d H:i:s") ]; $inr=Db::name("good_exam")->insert($data); if($inr){ ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [ "order_code" => $platform['skuCode'],//编号 "status" => $before, "action_remark" => '',//备注 "action_type" => "status"//新建create,编辑edit,更改状态status ], "SPSX", $post['exam_status'], $platform); ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [ "order_type" => 'SPSX', "order_code" =>$platform['skuCode'],//咨询单详情编号 "order_id" => $platform['id'], "order_status" => $post['exam_status'], "before_status" => $before, 'holder_id' => $platform['createrid'], ]); //如果是商品下线的话,记入商品下线记录表 if ($post['exam_status'] == 5) { $offline_id = Db::name("good_offline_log")->insertGetId([ 'spuCode' => $platform['spuCode'], 'skuCodes' => $platform['skuCode'], 'good_name' => Db::name("good_basic")->where('spuCode', $platform['spuCode'])->value('good_name', ''), 'offline_reason' => $post['offline_reason'], 'offline_remark' => $post['offline_remark'], 'createrid' => $createrid, 'creater' => $creater, 'addtime' => date('Y-m-d H:i:s'), ]); //根据权限查询应该接收商品下线通知的人员 $all_uid_name = Db::name('role_action') ->whereFindInSet('action_conllect','877')//数据写死的,要注意各个环境数据是否一致 ->field('role_id') ->buildSql(); $all_user = Db::name('user_role') ->alias('ur') ->where('ur.roleid IN '.$all_uid_name) ->leftJoin('depart_user du','du.uid = ur.uid AND du.is_del=0') ->column('ur.uid,du.nickName'); $insert_order_msg_data=[]; foreach ($all_user as $itemitem) { $insert_order_msg_data[] = [ 'content' => '商品下线:' . $platform['spuCode'] . '由' . $creater . '操作下线', 'orderCode' => $platform['skuCode'], 'order_type' => 'GOL', 'order_status' => 5, 'order_id' => $offline_id, 'apply_id' => $createrid, 'apply_name' => $creater, 'uid' => $itemitem['uid'], 'uname' => empty($itemitem['nickName']) ? '' : $itemitem['nickName'], 'is_read' => 0, 'addtime' => date('Y-m-d H:i:s'), 'updatetime' => date('Y-m-d H:i:s'), ]; } //消息表 Db::name('order_msg')->insertAll($insert_order_msg_data); } if ($post['exam_status'] == 3) { $proof=[ 'spuCode'=>$platform['spuCode'], 'proof_type'=>$post['proof_type'], 'proof_url'=>$post['proof_url'], 'is_del'=>0, "creater"=>$creater, "createrid"=>$createrid, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $inproof = Db::name("good_proof")->insert($proof); if($inproof==false)throw new \Exception("商品凭证新建失败"); if(empty($post['good_ladder']))throw new \Exception("商品阶梯价不能为空"); foreach ($post['good_ladder'] as $value){ $lemp=[]; $value["id"]?$lemp['id']=$value['id']:$lemp['addtime'] = date("Y-m-d H:i:s"); $lemp['skuCode']=$platform['skuCode']; $lemp['min_num'] = $value['min_num']; $lemp['max_num'] = 0; $lemp['sale_price'] = $value['sale_price']; $lemp['market_price'] = $value['market_price']; $lemp['market_platform'] = $value['market_platform']; $lemp['cost_fee'] = $value['cost_fee']; $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0; $lemp['updatetime'] =date("Y-m-d H:i:s"); //$value["id"]?'':$lemp['addtime'] = date("Y-m-d H:i:s");$lemp['updatetime'] =date("Y-m-d H:i:s"); $ladderUp = Db::name("good_ladder")->save($lemp); if($ladderUp==false) throw new \Exception("商品起订价修改失败"); } } Db::commit(); return app_show(0,"审核成功"); }else{ Db::rollback(); return error_show(1004,"审核失败"); } }else{ Db::rollback(); return error_show(1004,"审核失败"); } }catch (\Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } //财务定价 废弃 public function editladder(){ $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):""; if($skuCode===""){ return error_show(1004,"参数skuCode不能为空"); } $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find(); if($platform==false){ return error_show(1004,"未找到数据"); } $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])?$this->post['good_ladder']:""; if($good_ladder==""){ return error_show(1004,"参数good_ladder不能为空"); } $proof_type = isset($this->post['proof_type'])&&$this->post['proof_type']!==""?intval($this->post['proof_type']):""; if($proof_type===""){ return error_show(1004,"参数proof_type不能为空"); } $proof_url = isset($this->post['proof_url'])&&$this->post['proof_url']!==""?trim($this->post['proof_url']):""; if($proof_url===""){ return error_show(1004,"参数proof_url不能为空"); } $exam_remark = isset($this->post['exam_remark'])&& $this->post['exam_remark']!='' ? trim($this->post['exam_remark']):""; $createrid= $this->uid;//isset($user["data"]['id']) ? $user["data"]['id'] : ""; $creater= $this->uname;//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : ""; $bifore=$platform['exam_status']; $platform['exam_status']=4; $platform['updatetime']=date("Y-m-d H:i:s"); Db::startTrans(); try { foreach ($good_ladder as $value){ $lemp=[]; isset($value["id"])&&$value["id"]!=""?$lemp['id']=$value['id']:""; $lemp['skuCode']=$skuCode; $lemp['min_num'] = $value['min_num']; $lemp['max_num'] = 0; $lemp['sale_price'] = $value['sale_price']; $lemp['market_price'] = $value['market_price']; $lemp['market_platform'] = $value['market_platform']; $lemp['cost_fee'] = $value['cost_fee']; $lemp['status'] = $value['status']; $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0; isset($value["id"])&&$value["id"]!=""?"": $lemp['addtime'] = date("Y-m-d H:i:s"); $lemp['updatetime'] =date("Y-m-d H:i:s"); $count = Db::name("good_ladder")->save($lemp); if($count==false){ Db::rollback(); return app_show(1004,"商品起订价修改失败"); } } $up = Db::name("good_platform")->save($platform); if($up){ // ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [ // "order_code" =>$platform['skuCode'],//咨询单详情编号 // "status" =>$bifore,//这里的status是之前的值 // "action_remark" => '',//备注 // "action_type" => "edit"//新建create,编辑edit,更改状态status // ], "SPSX", $platform['exam_status'],$platform); // // ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [ // "order_type" => 'SPSX', // "order_code" =>$platform['skuCode'],//咨询单详情编号 // "order_id" => $platform['id'], // "order_status" => $platform['exam_status'], // "before_status"=>$bifore, // 'holder_id' => $platform['createrid'], // ]); $proof=[ 'spuCode'=>$platform['spuCode'], 'proof_type'=>$proof_type, 'proof_url'=>$proof_url, 'is_del'=>0, "creater"=>$creater, "createrid"=>$createrid, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $inproof = Db::name("good_proof")->insert($proof); if($inproof==false){ Db::rollback(); return app_show(1004,"商品凭证新建失败"); } $data=[ "code"=>$platform['skuCode'], "type"=>2, "exam_status"=>$bifore,//4, "exam_id"=>$createrid, "exam_name"=>$creater, "exam_remark"=>$exam_remark, "addtime"=>date("Y-m-d H:i:s") ]; $inr=Db::name("good_exam")->insert($data); if($inr){ Db::commit(); return app_show(0,"审核成功"); }else{ Db::rollback(); return error_show(1004,"审核失败"); } }else{ Db::rollback(); return error_show(1004,"审核失败"); } }catch (\Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } public function prooflist(){ $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1"; $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10"; $where =[["is_del","=",0]]; $spuCode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):""; if($spuCode!==""){ $where[]=["spuCode","like","%$spuCode%"]; } $count = Db::name("good_proof")->where($where)->count(); $total = ceil($count / $size); $page = $page >= $total ? $total : $page; $data = Db::name("good_proof")->where($where)->page($page,$size)->order("addtime desc")->select(); return app_show(0,"获取成功",['list'=>$data,"count"=>$count]); } /** * 已下线商品重新发起上线流程 */ public function againOnline(){ $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):""; if($skuCode===""){ return error_show(1004,"参数skuCode不能为空"); } $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find(); if($platform==false){ return error_show(1004,"未找到数据"); } if(in_array($platform["exam_status"],[4,5])){ return error_show(1004,"商品状态有误"); } //判断平台商品编码是否重复 // $rs = Db::name("good_platform") // ->field('id') // ->where(["plat_code" => $platform['plat_code'],"platform_code" => $platform['platform_code'], 'exam_status' => 6, "is_del" => 0])//exam_status==6已上线 // ->where('id', '<>', $platform['id']) // ->find(); // if (!empty($rs)) return error_show(1005, '该商品的平台商品编码已被使用'); $nake =Db::name("good_nake")->where(["spuCode"=>$platform['spuCode'],"is_del"=>0])->select()->toArray(); $bifore=$platform['exam_status']; $platform['exam_status'] = empty($nake)?1:2; $platform['updatetime'] = date("Y-m-d H:i:s"); $createrid= $this->uid; $creater= $this->uame; Db::startTrans(); try { $save =Db::name("good_platform")->save($platform); if($save){ ActionLog::logAdd(['id'=>$createrid,'nickname'=>$creater], [ "order_code" =>$platform['skuCode'],//咨询单详情编号 "status" =>$bifore,//这里的status是之前的值 "action_remark" => '',//备注 "action_type" => "edit"//新建create,编辑edit,更改状态status ], "SPSX", $platform['exam_status'],$platform); ProcessOrder::AddProcess(['id'=>$createrid,'nickname'=>$creater], [ "order_type" => 'SPSX', "order_code" =>$platform['skuCode'],//咨询单详情编号 "order_id" => $platform['id'], "order_status" => $platform['exam_status'], "before_status"=>$bifore, 'holder_id' => $platform['createrid'], ]); $data=[ "code"=>$platform['skuCode'], "type"=>2, "exam_status"=>$platform['exam_status'],//$platform['exam_status'] , "exam_id"=>$createrid, "exam_name"=>$creater, "exam_remark"=>'', "addtime"=>date("Y-m-d H:i:s") ]; $inr=Db::name("good_exam")->insert($data); //修改状态,添加待办 if($inr){ //将good_basic数据同步到good表 $good_basic = Db::name('good_basic') ->where(['spuCode' => $platform['spuCode'], 'is_del' => 0]) ->find(); if (!empty($good_basic)) { unset($good_basic['id']); unset($good_basic['addtime']); $good_basic['updatetime'] = date('Y-m-d H:i:s'); Db::name('good') ->strict(false) ->where(['spuCode' => $platform['spuCode'], 'is_del' => 0]) ->update($good_basic); } Db::commit(); return app_show(0,"审核成功"); } } Db::rollback(); return error_show(1004,"审核失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } public function copy(){ $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):""; if($supcode==""){ return error_show(1004,"参数spuCode不能为空"); } $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find(); if($data==false){ return error_show(1004,"未找到商品数据"); } $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):""; if($token==''){ return error_show(105,"参数token不能为空"); } $createrid= $this->uid; $creater= $this->uname; $nake = Db::name("good_nake")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray(); $ladd=[]; $newCode =makeNo("SKU"); if(!empty($nake)){ foreach ($nake as $value){ $tmp=[]; $tmp['spuCode']=$newCode; $tmp['min_num']=$value['min_num']; $tmp['nake_fee'] = $value['nake_fee']; $tmp['cost_fee'] = $value['cost_fee']; $tmp['delivery_fee'] = $value['delivery_fee']; $tmp['cert_fee'] = $value['cert_fee']; $tmp['mark_fee'] = $value['mark_fee']; $tmp['package_fee'] = $value['package_fee']; $tmp['other_fee'] = $value['other_fee']; $tmp['nake_total'] =$value['nake_total']; $tmp['creater_id']=$createrid; $tmp['creater']=$creater; $tmp['is_del']=$value['is_del']; $tmp['addtime']=date("Y-m-d H:i:s"); $tmp['updatetime']=date("Y-m-d H:i:s"); $ladd[]=$tmp; } } $spec = Db::name("good_spec")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray(); $specArr=[]; if(!empty($spec)){ foreach ($spec as $value){ $tmp=[]; $tmp['spuCode']=$newCode; $tmp['spec_id']=$value['spec_id']; $tmp['spec_value_id']=$value['spec_value_id']; $tmp['is_del']=$value['is_del']; $tmp['addtime']=date("Y-m-d H:i:s"); $tmp['updatetime']=date("Y-m-d H:i:s"); $specArr[]=$tmp; } } Db::startTrans(); try { unset($data['id']); $data['spuCode']=$newCode; $data['createrid']=$createrid; $data['creater']=$creater; $data['status']=7; $data['addtime']=date("Y-m-d H:i:s"); $data['updatetime']=date("Y-m-d H:i:s"); $cre = Db::name("good_basic")->insertGetId($data); if($cre){ //修改状态,添加待办 ActionLog::logAdd($this->post['token'], [ "order_code" =>$newCode,//咨询单详情编号 "status" => 0,//这里的status是之前的值 "action_remark" => '',//备注 "action_type" => "create"//新建create,编辑edit,更改状态status ], "SPCB", 7,$data); ProcessOrder::AddProcess($this->post['token'], [ "order_type" => 'SPCB', "order_code" =>$newCode,//咨询单详情编号 "order_id" => $cre, "order_status" =>7, "before_status"=>0, 'holder_id'=>$data['createrid'], ]); if(!empty($ladd)){ $na = Db::name("good_nake")->insertAll($ladd); if($na==0){ Db::rollback(); return error_show(1005,"成本数据复制失败"); } } if(!empty($specArr)){ $sp = Db::name("good_spec")->insertAll($specArr); if($sp==0){ Db::rollback(); return error_show(1005,"规格数据复制失败"); } } Db::commit(); return app_show(0,"复制数据成功",["spuCode"=>$newCode]); }else{ Db::rollback(); return error_show(1005,"数据复制失败"); } }catch (\Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } public function edit(){ $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):""; if($supcode==""){ return error_show(1004,"参数spuCode不能为空"); } $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find(); if($data==false){ return error_show(1004,"未找到商品数据"); } $is_down = Db::name("good_platform") ->where(["spuCode"=>$supcode,"is_del"=>0]) ->where("exam_status", "not in", [1, 5])//exam_status=1待完善成本,8已下线,除了这两个状态外其他状态都不允许编辑 ->find(); if($is_down!=false){ return error_show(1004,"存在未下线商品数据"); } if ($data['status'] != 6 && $data['status'] != 7 && $data['status'] != 8) { return error_show(1004,"商品状态有误"); } $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):""; if($good_name==""){ return error_show(1004,"商品名称不能为空"); } $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):""; if($cat_id==''){ return error_show(1004,"商品分类不能为空"); } $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"0"; // if($brandid==''){ // return error_show(1004,"商品品牌不能为空"); // } $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):""; if($unit==''){ return error_show(1004,"商品单位不能为空"); } $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type']) :""; if($good_type===''){ return error_show(1004,"参数good_type不能为空"); } $moq=0; $customized=0; if($good_type==1){ $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):""; if($moq===''){ return error_show(1004,"定制商品起订量不能为空"); } $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):""; if($customized===''){ return error_show(1004,"参数customized不能为空"); } } $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):""; if($is_exclusive===''){ return error_show(1004,"参数is_exclusive不能为空"); } // $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):""; // if($customized===''){ // return error_show(1004,"参数customized不能为空"); // } $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):""; if($tax===''){ return error_show(1004,"参数tax不能为空"); } $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):""; if($supplierNo==''){ return error_show(1004,"参数supplierNo不能为空"); } if (($this->level == 2) && ($supplierNo != $data['supplierNo'])) { $supplier_account = checkHasAccountBySupplierNos([$supplierNo]); if (isset($supplier_account[$supplierNo])) return json_show(1004, '该供应商已开通账号,不允许操作'); } $userCommon= \app\admin\common\User::getIns(); $supplier_temp =$userCommon->handle("hqInfo",["code"=>$supplierNo]); if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1004,"供应商信息未找到"); $supplierArr=$supplier_temp['data']??[]; $supplier=$supplierArr['child']??[]; $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size']) :""; if($good_size==''){ return error_show(1004,"参数good_size不能为空"); } $company_id = isset($this->post['companyNo'])&&$this->post['companyNo']!=""? trim($this->post['companyNo']) :""; if($company_id==''){ return error_show(1004,"参数companyNo不能为空"); } $companyinfo =$userCommon->handle("getCodeAndName",["code"=>$company_id]); if($supplierArr['relation_code']==$company_id){ return error_show(1004,"业务公司与供应商属于同一家公司"); } $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):""; if($is_auth===''){ return error_show(1004,"参数is_auth不能为空"); } $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):""; // if($auth_img==''){ // return error_show(1004,"商品不能为空"); // } $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):""; if($after_sales==""){ return error_show(1004,"参数after_sales不能为空"); } $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):""; $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):""; if($good_remark===""){ return error_show(1004,"参数good_remark不能为空"); } $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):""; if($weight===""){ return error_show(1004,"参数weight不能为空"); } $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):""; if($packing_way===""){ return error_show(1004,"参数packing_way不能为空"); } $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):""; if($packing_size===""){ return error_show(1004,"参数packing_size不能为空"); } $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):""; if($packing_spec===""){ return error_show(1004,"参数packing_spec不能为空"); } $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):""; if($packing_weight===""){ return error_show(1004,"参数packing_weight不能为空"); } $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):""; if($packing_list===""){ return error_show(1004,"参数packing_list不能为空"); } $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):""; $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):""; if($supply_area===""){ return error_show(1004,"参数supply_area不能为空"); } $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? $this->post['delivery_place']:""; if($delivery_place===""){ return error_show(1004,"参数delivery_place不能为空"); } $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? $this->post['origin_place']:""; if($origin_place===""){ return error_show(1004,"参数origin_place不能为空"); } $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):""; if($delivery_day===""){ return error_show(1004,"参数delivery_day不能为空"); } $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time']) :"0"; $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0"; $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0"; $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):""; if($good_img===""){ return error_show(1004,"参数good_img不能为空"); } $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):""; if($good_thumb_img===""){ return error_show(1004,"参数good_thumb_img不能为空"); } $good_info_img = isset($this->post['good_info_img'])&&!empty($this->post['good_info_img'])? trim($this->post['good_info_img']):""; if($good_info_img===""){ return error_show(1004,"参数good_info_img不能为空"); } $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0"; $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0"; $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0"; $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0"; $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0"; $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0"; $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0"; $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0"; $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0"; $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):""; $cgd_gold_price = isset($this->post['cgd_gold_price'])&&$this->post['cgd_gold_price']!==""? floatval($this->post['cgd_gold_price']):"0"; if($market_price===""){ return error_show(1004,"参数market_price不能为空"); } $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"0"; $config = isset($this->post['config'])&&$this->post['config']!==""? trim($this->post['config']):""; $other_config = isset($this->post['other_config'])&&$this->post['other_config']!==""? trim($this->post['other_config']):""; $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"0"; $is_stock = isset($this->post['is_stock'])&&$this->post['is_stock']!==""? intval($this->post['is_stock']):"0"; $stock_moq = isset($this->post['stock_moq'])&&$this->post['stock_moq']!==""? intval($this->post['stock_moq']):"0"; if($is_stock==1 && $stock_moq ==0){ return error_show(1004,"库存品备库起订量不能为零"); } $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:""; $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:""; $is_support_barter = isset($this->post['is_support_barter']) && $this->post['is_support_barter'] !== "" ? intval($this->post['is_support_barter']) : 1; Db::startTrans(); try { $temp=[ "good_name"=>$good_name, "cat_id"=>$cat_id, 'brand_id'=>$brandid, "good_unit"=>$unit, "good_type"=>$good_type, "companyNo"=>$company_id, "companyName"=>$companyinfo['data'][$company_id]??"", "moq"=>$moq, "is_exclusive"=>$is_exclusive, "customized"=>$customized, "tax"=>$tax, "supplierNo"=>$supplierNo, "supplierName"=>$supplierArr['name'], "is_auth"=>$is_auth, "good_size"=>$good_size, "auth_img"=>$auth_img, "after_sales"=>$after_sales, "craft_desc"=>$craft_desc, "good_remark"=>$good_remark, "weight"=>$weight, "packing_way"=>$packing_way, "packing_size"=>$packing_size, "packing_spec"=>$packing_spec, "packing_list"=>$packing_list, "packing_weight"=>$packing_weight, "good_bar"=>$good_bar, "supply_area"=>$supply_area, "delivery_place"=>$delivery_place, "origin_place"=>$origin_place, "delivery_day"=>$delivery_day, "lead_time"=>$lead_time, "sample_day"=>$sample_day, "sample_fee"=>$sample_fee, "good_img"=>$good_img, "good_thumb_img"=>$good_thumb_img, "good_info_img"=>$good_info_img, "cert_fee"=>$cert_fee, "packing_fee"=>$packing_fee, "is_diff"=>$is_diff, "config"=>$config, "other_config"=>$other_config, "is_stock"=>$is_stock, "cost_fee"=>$cost_fee, "mark_fee"=>$mark_fee, "demo_fee"=>$demo_fee, "open_fee"=>$open_fee, "noble_metal"=>$noble_metal, "noble_weight"=>$noble_weight, "is_gold_price"=>$is_gold_price, "market_price"=>$market_price, "nake_price"=>$nake_price, "cgd_gold_price"=>$cgd_gold_price, "is_step" => count($good_ladder) > 1 ? 1 : 0, "stock_moq"=>$stock_moq, "status"=>"0", "updatetime"=>date("Y-m-d H:i:s"), 'is_support_barter'=>$is_support_barter, 'chargerid' => $supplier['personid'] ?? $this->uid, 'charger' => $supplier['person'] ?? $this->uname, ]; $field = array_diff_assoc($temp,$data); $temp['field_change'] =empty($field)?"":json_encode(array_keys($field)); $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($temp); $var = array_diff($temp,$data); $json = json_encode($var,JSON_UNESCAPED_UNICODE); $dat = json_encode($data,JSON_UNESCAPED_UNICODE); if($up){ ChangeLog::logAdd(3,$data['spuCode'],$dat,$json,['id' => $this->uid, 'nickname' => $this->uname]); // //修改状态,添加待办 // ActionLog::logAdd($this->post['token'], [ // "order_code" =>$supcode,//咨询单详情编号 // "status" => $data['status'],//这里的status是之前的值 // "action_remark" => '',//备注 // "action_type" => "create"//新建create,编辑edit,更改状态status // ], "SPCB", 0,$temp); // // ProcessOrder::AddProcess($this->post['token'], [ // "order_type" => 'SPCB', // "order_code" =>$supcode,//咨询单详情编号 // "order_id" => $data['id'], // "order_status" =>0, // "before_status"=>0, // 'holder_id'=>$data['createrid'], // ]); if($speclist!=="" && !empty($speclist)){ foreach ($speclist as $value){ $lemp=[]; isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:""; $lemp['spuCode']=$supcode; $lemp['spec_id'] = $value['spec_id']; $lemp['spec_value_id'] = $value['spec_value_id']; $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0; isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s"); $lemp['updatetime'] =date("Y-m-d H:i:s"); $count = Db::name("good_spec")->save($lemp); if($count==false){ Db::rollback(); return app_show(1004,"商品规格值修改失败"); } } } if($good_ladder!=="" && !empty($good_ladder)){ // $user =GetUserInfo($this->post['token']);//获取用户信息,下面更新成本表的创建人 $top_cat_id = made($cat_id);//获取所有分类 $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id foreach ($good_ladder as $value){ $lemp=[]; isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:""; $lemp['spuCode']=$supcode; $lemp['min_num'] = $value['min_num']; $lemp['nake_fee'] = $value['nake_fee']; $lemp['cost_fee'] = $value['cost_fee']; $lemp['delivery_fee'] = $value['delivery_fee']; $lemp['cert_fee'] = $value['cert_fee']; $lemp['mark_fee'] = $value['mark_fee']; $lemp['package_fee'] = $value['package_fee']; $lemp['other_fee'] = $value['other_fee']; if ($is_gold_price == 1 && $top_cat_id == 6) { $gold =Db::name("gold_price1")->where(["type"=>$noble_metal,"status"=>1,"is_del"=>0])->order("addtime desc")->find(); //$lemp['nake_total'] =$noble_weight*$gold['price'] + $value['cost_fee']*$noble_weight+$value['mark_fee']+$value['package_fee']+$value['cert_fee']+$value['nake_fee']+$value['delivery_fee']+$value['other_fee']; //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用 //成本总计启用实时金价时,采用供应商实时金价 $lemp['nake_total'] =$noble_weight *$gold['price']+ $value['cost_fee'] * $noble_weight + $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee']; }else{ $lemp['nake_total'] =$value['nake_fee']+$value['delivery_fee']+$value['cert_fee']+$value['mark_fee']+$value['package_fee']+$value['other_fee']; } $lemp['creater_id'] = $this->uid; $lemp['creater'] = $this->uname; $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0; isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s"); $lemp['updatetime'] =date("Y-m-d H:i:s"); $count = Db::name("good_nake")->save($lemp); if($count==false){ Db::rollback(); return app_show(1004,"商品规成本修改失败"); } } } Db::commit(); return app_show(0,"更新成功"); }else{ Db::rollback(); return error_show(1005,"更新失败"); } }catch (\Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } public function checkPrice(){ $param = $this->request->only(['spuCode', 'min_num', 'platform_id', 'relaComNo'], 'post', 'trim'); $val = Validate::rule([ 'spuCode|商品成本编码' => 'require', 'min_num|起订量' => 'require|number|gt:0', 'platform_id|上线平台ID' => 'require|number|gt:0', 'relaComNo'=>'require' ]); if($val->check($param) == false) return json_show(1005,$val->getError()); $good =Db::name("good_basic") ->field('id,is_stock,cat_id,is_gold_price,noble_weight,cgd_gold_price') ->where(["spuCode"=>$param['spuCode'],"is_del"=>0]) ->findOrEmpty(); if(empty($good)) return json_show(1005,"商品数据未找到"); // $num=isset($this->post['min_num'])&&$this->post['min_num']!=="" ? intval($this->post['min_num']):""; // if($num==""){ // return error_show(1005,"参数min_num不能为空"); // } $nakelist = Db::name("good_nake") ->where(['spuCode'=>$param['spuCode'],"is_del"=>0]) ->where([["min_num","<=",$param['min_num']]]) ->order("min_num desc") ->find(); if($nakelist==false){ $nakelist = Db::name("good_nake") ->where(['spuCode'=>$param['spuCode'],"is_del"=>0]) ->order("min_num asc") ->find(); //非库存品的话,继续校验最小起订量 //库存品的话,不足采购起订量的时候,取采购最小起订量 if ($good['is_stock'] == 0) return error_show(1010, "起订量不足{$nakelist['min_num']}"); } //计算毛利率 $budget = get_budget($good['cat_id'],$param['relaComNo'],$param['platform_id']); $top_cat_id = made($good['cat_id']);//获取所有分类 $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id $sale_cost_fee = 0; if ($good['is_gold_price'] == 1 && $top_cat_id == 6) { // $saleprice = $good['noble_weight']*$good["cgd_gold_price"] + $nakelist['cost_fee']/(1-$budget)*$good['noble_weight']+$nakelist['mark_fee']+$nakelist['package_fee']+$nakelist['cert_fee']+$nakelist['nake_fee']+$nakelist['delivery_fee']; //系统售价=(贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用)/(1-成本售价/100) $saleprice = ($good['noble_weight'] * $good["cgd_gold_price"] + $nakelist['cost_fee'] * $good['noble_weight'] + $nakelist['mark_fee'] + $nakelist['package_fee'] + $nakelist['cert_fee'] + $nakelist['nake_fee'] + $nakelist['delivery_fee'] + $nakelist['other_fee']) / (1 - $budget); //计算工艺费 //销售工艺费=(( 商品重量* 供应商采购金价 + 采购成本工艺费* 商品重量+包装费+加标费+证书费+产品裸价+其他费用)/(1-成本售价/100)-(包装费+加标费+证书费+产品裸价0+运费+其他费用) )/商品重量-供应商采购金价 $sale_cost_fee = (($good['noble_weight'] * $good["cgd_gold_price"] + $nakelist['cost_fee'] * $good['noble_weight'] + $nakelist['package_fee'] + $nakelist['mark_fee'] + $nakelist['cert_fee'] + $nakelist['nake_fee'] + $nakelist['other_fee'] + $nakelist['delivery_fee']) / (1 - $budget) - ($nakelist['package_fee'] + $nakelist['mark_fee'] + $nakelist['cert_fee'] + $nakelist['nake_fee'] + $nakelist['delivery_fee'] + $nakelist['other_fee'])) / $good['noble_weight'] - $good["cgd_gold_price"]; }else{ // $saleprice = ($nakelist['mark_fee'] + $nakelist['package_fee'] + $nakelist['cert_fee'] + $nakelist['delivery_fee'] + $nakelist['nake_fee']) / (1 - $budget); // (加标费+包装费+证书费+成本裸价+运费)/(1-成本售价/100)=系统售价 // $saleprice = (加标费 + 包装费 + 证书费 + 运费 + 成本裸价+其他费用) / (1 - $budget); $saleprice = $nakelist['nake_total'] / (1 - $budget); } return app_show(0, "获取成功", ["sale_price" => round($saleprice, 2), 'new_cost_fee' => round($sale_cost_fee, 2)]); } //咨询成交商品池 添加上线商品 public function onlineZixunGoods() { $param = $this->request->only(['platform', 'codes', 'online_reason', 'online_remark', 'token'], 'post', 'trim'); $val = Validate::rule([ 'platform|所选上线平台' => 'require|number|gt:0', 'codes|所选上线商品编号' => 'require', 'online_reason|上线原因' => 'require', 'online_remark|上线备注' => 'require', 'token' => 'require', ]); if (!$val->check($param)) return error_show(1004, $val->getError()); $good_zixun_list = Db::name("good_zixun") ->where(["is_del" => 0]) ->whereIn('spuCode', $param['codes']) ->column('*', 'spuCode'); if (empty($good_zixun_list)) return error_show(1004, "未找到相关咨询商品数据"); $a = array_diff($param['codes'], array_keys($good_zixun_list)); if (!empty($a)) return error_show(1005, '该咨询商品不存在' . implode(',', $a)); $isonline = Db::name("good_platform") ->alias('gp') ->field('gp.id,gp.spuCode,gb.good_name,gb.good_img,gp.exam_status') ->where(["gp.platform_code" => $param['platform'], "gp.is_del" => 0]) ->whereIn('gp.spuCode', $param['codes']) ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0') ->select() ->toArray(); if (!empty($isonline)) { foreach ($isonline as &$v) { $spec = Db::name("good_spec") ->where(["spuCode" => $v['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']; $temp['is_del'] = $val['is_del']; $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; } } $v["speclist"] = empty($speclist) ? [] : $speclist; } return app_show(1009, "存在已上线产品", $isonline); } if (!empty($isonline)) return error_show(1005, $isonline['spuCode'] . '该商品已在商品成本管理中,请在商品成本管理菜单提交上线!'); $user = GetUserInfo($param['token']); if (empty($user) || $user['code'] != 0) return error_show(1002, "用户数据不存在"); $createrid = isset($user["data"]['id']) ? $user["data"]['id'] : ""; $creater = isset($user["data"]['nickname']) ? $user["data"]['nickname'] : ""; $data = $good_insert_data = $good_basic_insert_data = $good_spec_insert_data = []; $i = 0; $all_nakes = Db::name("good_nake") ->where(["is_del" => 0])->fetchSql() ->whereIn('spuCode', $param['codes']) ->group('spuCode') ->column('count(`id`) total', 'spuCode'); $all_good = Db::name('good') ->where('is_del', 0) ->whereIn('spuCode', $param['codes']) ->column('id', 'spuCode'); if (!empty($all_good)) return error_show(1004, '请从商品成本提交该商品上线'); $all_good_basic = Db::name('good_basic') ->where('is_del', 0) ->whereIn('spuCode', $param['codes']) ->column('id', 'spuCode'); if (!empty($all_good_basic)) return error_show(1004, '请从商品成本提交该商品上线'); foreach ($param['codes'] as $value) { //改变编码规则,将原来的skuCode后两位换成序列号 //str_pad字符串填充 $skuCode = makeNo("SN"); $skuCode = substr($skuCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT); $data[] = [ "spuCode" => $value, "skuCode" => $skuCode, "platform_code" => $param['platform'], "online_reason" => $param['online_reason'], "online_remark" => $param['online_remark'], "exam_status" => isset($all_nakes[$value]) ? ($all_nakes[$value] > 0 ? 2 : 1) : 1, "is_online" => 0, "status" => 0, "is_del" => 0, "creater" => $creater, "createrid" => $createrid, "addtime" => date("Y-m-d H:i:s"), "updatetime" => date("Y-m-d H:i:s") ]; //good表 if (!isset($all_good[$value])) { $good_insert_data[] = [ 'spuCode' => $good_zixun_list[$value]['spuCode'], 'good_code' => $good_zixun_list[$value]['good_code'], 'good_name' => $good_zixun_list[$value]['good_name'], 'cat_id' => $good_zixun_list[$value]['cat_id'], 'brand_id' => $good_zixun_list[$value]['brand_id'], 'good_unit' => $good_zixun_list[$value]['good_unit'], 'good_type' => $good_zixun_list[$value]['good_type'], 'companyNo' => $good_zixun_list[$value]['companyNo'], 'moq' => $good_zixun_list[$value]['moq'], 'customized' => $good_zixun_list[$value]['customized'], 'tax' => $good_zixun_list[$value]['tax'], 'supplierNo' => $good_zixun_list[$value]['supplierNo'], 'is_auth' => $good_zixun_list[$value]['is_auth'], 'is_stock' => '', 'auth_img' => $good_zixun_list[$value]['auth_img'], 'after_sales' => '', 'craft_desc' => $good_zixun_list[$value]['craft_desc'], 'good_remark' => $good_zixun_list[$value]['good_remark'], 'good_size' => '', 'weight' => $good_zixun_list[$value]['weight'], 'packing_way' => '', 'packing_size' => '', 'packing_spec' => '', 'packing_list' => '', 'packing_weight' => '', 'good_bar' => '', 'supply_area' => $good_zixun_list[$value]['supply_area'], 'delivery_place' => '', 'origin_place' => '', 'delivery_day' => 0, 'lead_time' => '', 'sample_day' => '', 'sample_fee' => '', 'good_img' => $good_zixun_list[$value]['good_img'], 'good_thumb_img' => $good_zixun_list[$value]['good_thumb_img'], 'good_info_img' => $good_zixun_list[$value]['good_info_img'], 'cert_fee' => '', 'packing_fee' => '', 'cost_fee' => '', 'mark_fee' => '', 'demo_fee' => '', 'open_fee' => '', 'noble_metal' => $good_zixun_list[$value]['noble_metal'], 'noble_weight' => $good_zixun_list[$value]['good_weight'], 'is_gold_price' => $good_zixun_list[$value]['is_gold_price'], 'cgd_gold_price' => '', 'market_price' => '', 'nake_price' => '', 'is_step' => '', 'is_online' => '', 'status' => 1,//待完善成本 'createrid' => $createrid, 'creater' => $creater, 'is_del' => 0, 'field_change' => '', 'addtime' => date('Y-m-d H:i:s'), 'updatetime' => date('Y-m-d H:i:s'), 'is_exclusive' => '', 'is_diff' => $good_zixun_list[$value]['is_diff'], 'config' => $good_zixun_list[$value]['config'], 'other_config' => $good_zixun_list[$value]['other_config'], ]; } //good_basic表 if (!isset($all_good_basic[$value])) { $good_basic_insert_data[] = [ 'spuCode' => $good_zixun_list[$value]['spuCode'], 'good_code' => $good_zixun_list[$value]['good_code'], 'good_name' => $good_zixun_list[$value]['good_name'], 'cat_id' => $good_zixun_list[$value]['cat_id'], 'brand_id' => $good_zixun_list[$value]['brand_id'], 'companyNo' => $good_zixun_list[$value]['companyNo'], 'good_unit' => $good_zixun_list[$value]['good_unit'], 'good_type' => $good_zixun_list[$value]['good_type'], 'moq' => $good_zixun_list[$value]['moq'], 'customized' => $good_zixun_list[$value]['customized'], 'tax' => $good_zixun_list[$value]['tax'], 'supplierNo' => $good_zixun_list[$value]['supplierNo'], 'is_auth' => $good_zixun_list[$value]['is_auth'], 'auth_img' => $good_zixun_list[$value]['auth_img'], 'after_sales' => '', 'craft_desc' => $good_zixun_list[$value]['craft_desc'], 'good_remark' => $good_zixun_list[$value]['good_remark'], 'weight' => $good_zixun_list[$value]['weight'], 'packing_way' => '', 'packing_size' => '', 'packing_spec' => '', 'packing_list' => '', 'packing_weight' => '', 'good_bar' => '', 'supply_area' => $good_zixun_list[$value]['supply_area'], 'delivery_place' => '', 'origin_place' => '', 'delivery_day' => '', 'lead_time' => '', 'sample_day' => '', 'sample_fee' => '', 'good_img' => '',//$good_zixun_list[$value]['good_img'], 'good_thumb_img' => $good_zixun_list[$value]['good_thumb_img'], 'good_info_img' => $good_zixun_list[$value]['good_img'],//商品主图对应到商品详情 'cert_fee' => '', 'packing_fee' => '', 'cost_fee' => '', 'mark_fee' => '', 'demo_fee' => '', 'open_fee' => '', 'noble_metal' => $good_zixun_list[$value]['noble_metal'], 'noble_weight' => $good_zixun_list[$value]['good_weight'], 'is_gold_price' => $good_zixun_list[$value]['is_gold_price'], 'cgd_gold_price' => '', 'market_price' => '', 'nake_price' => '', 'is_step' => '', 'is_online' => '', 'status' => 8,//咨询商品待编辑 'createrid' => $createrid, 'creater' => $creater, 'field_change' => '', 'is_del' => 0, 'addtime' => date('Y-m-d H:i:s'), 'updatetime' => date('Y-m-d H:i:s'), 'is_diff' => $good_zixun_list[$value]['is_diff'], 'config' => $good_zixun_list[$value]['config'], 'other_config' => $good_zixun_list[$value]['other_config'], ]; } //good_spec if (!empty($good_zixun_list[$value]['specinfo'])) { $spec_list = json_decode($good_zixun_list[$value]['specinfo'], true); foreach ($spec_list as $spec) { $temp = Db::name('good_spec') ->field('id') ->where(['spuCode' => $value, 'spec_id' => $spec['specid'], 'spec_value_id' => $spec['spec_value_id'], 'is_del' => 0]) ->find(); if (!empty($temp)) { $good_spec_insert_data[] = [ 'spuCode' => $value, 'spec_id' => $spec['specid'], 'spec_value_id' => $spec['spec_value_id'], 'is_del' => 0, 'addtime' => date('Y-m-d H:i:s'), 'updatetime' => date('Y-m-d H:i:s'), ]; } } } $i++; } if (!empty($isonline)) { return app_show(1009, "存在已上线产品", $isonline); } Db::startTrans(); try { $create = Db::name("good_platform")->insertAll($data); Db::name("good_zixun") ->where(["is_del" => 0, 'status' => 1]) ->whereIn('spuCode', $param['codes']) ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]); if (!empty($good_insert_data)) Db::name('good')->insertAll($good_insert_data); if (!empty($good_basic_insert_data)) Db::name('good_basic')->insertAll($good_basic_insert_data); if (!empty($good_spec_insert_data)) Db::name('good_spec')->insertAll($good_spec_insert_data); if ($create) { foreach ($good_basic_insert_data as $value) { ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [ "order_code" =>$value['spuCode'],// "status" => 8,//待产品审核 "action_remark" => '',//备注 "action_type" => "create"//新建create,编辑edit,更改状态status ], "SPCB", $value['status'], $value); ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [ "order_type" => 'SPCB', "order_code" =>$value['spuCode'],// "order_id" => isset($value['id']) ? $value['id'] : 0, "order_status" => 8,//待产品审核 "before_status" => 0,//待产品审核 'holder_id'=>$value['createrid'], ]); } foreach ($data as $value) { ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [ "order_code" =>$value['skuCode'],// "status" => 0,//待产品审核 "action_remark" => '',//备注 "action_type" => "create"//新建create,编辑edit,更改状态status ], "SPSX", $value['exam_status'], $value); ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [ "order_type" => 'SPSX', "order_code" =>$value['skuCode'],// "order_id" => isset($value['id']) ? $value['id'] : 0, "order_status" =>$value['exam_status'],//待产品审核 "before_status" => 0, 'holder_id' => $value['createrid'], ]); } Db::commit(); return app_show(0, "提交成功"); } else { Db::rollback(); return error_show(1004, "提交失败"); } } catch (Exception $exception) { Db::rollback(); return error_show(1005, $exception->getMessage()); } } //商品上线审核流程时,驳回重新审核 public function rejectGoodToAgainExamine() { $param = $this->request->only(['token', 'skuCode', 'exam_remark' => ''], 'post', 'trim'); $val = Validate::rule(['token' => 'require', 'skuCode' => 'require']); if (!$val->check($param)) return error_show(1005, $val->getError()); $user = GetUserInfo($param['token']); $createrid = isset($user['data']['id']) ? $user['data']['id'] : 0; $creater = isset($user['data']['nickname']) ? $user['data']['nickname'] : ''; Db::startTrans(); try { $rs = Db::name("good_platform") ->field('id,spuCode,skuCode,exam_status,createrid') ->where(['skuCode' => $param['skuCode'], 'is_del' => 0]) ->where('exam_status', '<>', 3)//exam_status==6上线成功 ->find(); if (empty($rs)) throw new \Exception('该记录不存在'); $old_exam_staus = $rs['exam_status']; $good_nake = Db::name("good_nake") ->field('id') ->where(["spuCode" => $rs['spuCode'], "is_del" => 0]) ->find(); $exam_status = empty($good_nake) ? 1 : 2; if ($exam_status == $rs['exam_status']) $exam_status =4;//第一级审核失败时,状态改为'审核失败' Db::name("good_platform") ->where('id', $rs['id']) ->save([ 'exam_status' => $exam_status, 'updatetime' => date('Y-m-d H:i:s'), ]); Db::name("good_exam")->insert([ 'code' => $rs['skuCode'], 'exam_status' => $old_exam_staus, 'type' => 2, 'exam_id' => $createrid, 'exam_name' => $creater, 'exam_remark' => $param['exam_remark'], 'addtime' => date('Y-m-d H:i:s') ]); ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [ "order_code" => $param['skuCode'],//编号 "status" => $rs['exam_status'], "action_remark" => '',//备注 "action_type" => "status"//新建create,编辑edit,更改状态status ], "SPSX", $exam_status, $param); ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [ "order_type" => 'SPSX', "order_code" => $param['skuCode'],//咨询单详情编号 "order_id" => $rs['id'], "order_status" => $exam_status, "before_status" => $rs['exam_status'], 'holder_id' => $rs['createrid'], ]); Db::commit(); return app_show(0, "驳回重新审核成功"); } catch (\Exception $e) { Db::rollback(); return error_show(1004, '驳回重新审核失败,' . $e->getMessage()); } } //同一个spuCode下所有的商品都下线 public function offlineGoodBySpuCode() { $param = $this->request->only(['token', 'spuCode', 'offline_reason', 'offline_remark' => ''], 'post', 'trim'); $val = Validate::rule(['token' => 'require', 'spuCode' => 'require', 'offline_reason|下线原因' => 'require']); if (!$val->check($param)) return error_show(1005, $val->getError()); $user = GetUserInfo($param['token']); $createrid = isset($user['data']['id']) ? $user['data']['id'] : 0; $creater = isset($user['data']['nickname']) ? $user['data']['nickname'] : ''; Db::startTrans(); try { $good_name = Db::name("good_basic") ->where(['is_del' => 0, 'spuCode' => $param['spuCode']]) ->value('good_name', ''); $skuCodeS = Db::name("good_platform") ->where(['spuCode' => $param['spuCode'], 'is_del' => 0])//exam_status 7审核失败,8已下线 ->whereNotIn('exam_status', [4,5]) ->column('exam_status,skuCode', 'skuCode'); if ($skuCodeS) { // if (empty($skuCodeS)) throw new \Exception('该商品未在任何平台申请上线'); //商品平台 Db::name("good_platform") ->where(['spuCode' => $param['spuCode'], 'is_del' => 0])//exam_status 7审核失败,8已下线 ->whereNotIn('exam_status', [4,5]) ->save([ 'exam_status' => 5, "is_compliance"=>0, "compliance_remark"=>'', 'updatetime' => date('Y-m-d H:i:s'), ]); //商品下线记录 $good_offline_log_id = Db::name("good_offline_log")->insertGetId([ 'spuCode' => $param['spuCode'], 'skuCodes' => implode(',', array_keys($skuCodeS)), 'good_name' => $good_name, 'offline_reason' => $param['offline_reason'], 'offline_remark' => $param['offline_remark'], 'createrid' => $createrid, 'creater' => $creater, 'addtime' => date('Y-m-d H:i:s'), ]); //根据权限查询应该接收商品下线通知的人员 $all_uid_name = Db::name('role_action') ->whereFindInSet('action_conllect', '877')//数据写死的,要注意各个环境数据是否一致 ->field('role_id') ->buildSql(); $all_user = Db::name('user_role') ->alias('ur') ->where('ur.roleid IN ' . $all_uid_name) ->leftJoin('depart_user du', 'du.uid = ur.uid AND du.is_del=0') ->column('ur.uid,du.nickName'); $insert_good_exam_data = $insert_order_msg_data = []; foreach ($skuCodeS as $skuCode => $value) { $insert_good_exam_data[] = [ 'code' => $skuCode, 'exam_status' =>5, 'type' => 2, 'exam_id' => $createrid, 'exam_name' => $creater, 'exam_remark' => '', 'addtime' => date('Y-m-d H:i:s') ]; ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [ "order_code" => $skuCode,//编号 "status" =>$value['exam_status'] , "action_remark" => '',//备注 "action_type" => "status"//新建create,编辑edit,更改状态status ], "GOL",5, $param); ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [ "order_type" => 'GOL', "order_code" => $skuCode, "order_id" => $good_offline_log_id, "order_status" =>5, "before_status" => $value['exam_status'] ]); foreach ($all_user as $itemitem) { $insert_order_msg_data[] = [ 'content' => '商品下线:' . $skuCode . '由' . $creater . '操作下线', 'orderCode' => $skuCode, 'order_type' => 'GOL', 'order_status' =>5, 'order_id' => $good_offline_log_id, 'uid' => $itemitem['uid'], 'uname' => empty($itemitem['nickName']) ? '' : $itemitem['nickName'], 'apply_id' => $createrid, 'apply_name' => $creater, 'is_read' => 0, 'addtime' => date('Y-m-d H:i:s'), 'updatetime' => date('Y-m-d H:i:s'), ]; } } //变动记录 Db::name("good_exam")->insertAll($insert_good_exam_data); //消息表 Db::name('order_msg')->insertAll($insert_order_msg_data); } //处理有赞平台 $rs = Db::name('platform_youzan') ->field('id,spuCode,skuCode,exam_status,platform_id') ->where(['spuCode' => $param['spuCode'], 'is_del' => PlatformYouzan::$del_normal]) ->whereNotIn('exam_status', [PlatformYouzan::$exam_status_7, PlatformYouzan::$exam_status_8]) ->select() ->toArray(); if ($rs) { $insert_good_offline_log_youzan_data = []; foreach ($rs as $value) { $curl_data = [ 'item_no' => $value['skuCode'],//商品自定义编码 skuCode 'uid' => $createrid, 'nickname' => $creater, ]; //已上线的要调用有赞接口下线 //调有赞项目的接口,从有赞平台下线该商品 if($value['exam_status'] == PlatformYouzan::$exam_status_6){ $host = config('app.yz_domain'); $response = curl_request($host . 'api/yz_goodup_offline', $curl_data); $response = json_decode($response, true); if ($response['code'] != 0) throw new Exception($response['message']); } $insert_good_offline_log_youzan_data[] = [ 'spuCode' => $value['spuCode'], 'skuCodes' => $value['skuCode'], 'good_name' => $good_name, 'offline_reason' => $param['offline_reason'], 'offline_remark' => $param['offline_remark'], 'createrid' => $createrid, 'creater' => $creater, 'addtime' => date('Y-m-d H:i:s') ]; } Db::name('platform_youzan') ->where(['spuCode' => $param['spuCode'], 'is_del' => PlatformYouzan::$del_normal]) ->whereNotIn('exam_status', [PlatformYouzan::$exam_status_7, PlatformYouzan::$exam_status_8]) ->update([ 'exam_status' => PlatformYouzan::$exam_status_8, 'offline_reason_id' => $param['offline_reason'], 'offline_remark' => $param['offline_remark'], 'updaterid' => $createrid, 'updater' => $creater, 'updatetime' => date('Y-m-d H:i:s') ]); //下线记录表增加记录 if ($insert_good_offline_log_youzan_data) Db::name('good_offline_log_youzan')->insertAll($insert_good_offline_log_youzan_data); } Db::commit(); return app_show(0, "下线成功"); } catch (\Exception $e) { Db::rollback(); return error_show(1004, '操作失败,' . $e->getMessage()); } } //判断是否允许修改成本信息和基础信息 public function checkIsUpdate() { $spuCode = $this->request->post('spuCode', '', 'trim'); if ($spuCode == '') return error_show(1004, '成本商品编号不能为空'); $is_allow_update = 1; //检查是否有上线记录 $rs = Db::name('good_platform') ->field('id') ->where(['spuCode' => $spuCode, 'is_del' => 0]) ->whereNotIn('exam_status', [0, 5])//0待提交,8已下线 ->find(); if (!empty($rs)) $is_allow_update = 0; else { $rs = PlatformYouzan::field('id') ->where(['spuCode' => $spuCode, 'is_del' => PlatformYouzan::$del_normal]) ->whereNotIn('exam_status', [PlatformYouzan::$exam_status_8,PlatformYouzan::$exam_status_2])//8已下线,2审核驳回 ->findOrEmpty() ->isEmpty(); if (!$rs) $is_allow_update = 0; } return app_show(0, '请求成功', ['is_allow_update' => $is_allow_update]); } private function isUpdate($spuCode){ $is_allow_update = 1; //检查是否有上线记录 $rs = Db::name('good_platform') ->field('id') ->where(['spuCode' => $spuCode, 'is_del' => 0]) ->whereNotIn('exam_status', [0, 5]) ->find(); if (!empty($rs)) $is_allow_update = 0; else { $rs = PlatformYouzan::field('id') ->where(['spuCode' => $spuCode, 'is_del' => PlatformYouzan::$del_normal]) ->whereNotIn('exam_status', [PlatformYouzan::$exam_status_8,PlatformYouzan::$exam_status_2]) ->findOrEmpty() ->isEmpty(); if (!$rs) $is_allow_update = 0; } return $is_allow_update; } //获取某个商品编号下的所有审核备注列表 public function getGoodExamList() { $param = $this->request->filter('trim')->only(['token', 'skuCode', 'page' => 1, 'size' => 15], 'post'); $val = Validate::rule(['token' => 'require', 'skuCode' => 'require']); if (!$val->check($param)) return error_show(1005, $val->getError()); $count = Db::name('good_exam') ->where('code', $param['skuCode']) ->count('id'); $list = Db::name('good_exam') ->where('code', $param['skuCode']) ->order('id') ->page($param['page'], $param['size']) ->select() ->toArray(); return app_show(0, '请求成功', ['list' => $list, 'count' => $count]); } //获取某个商品编号下的所有审核备注列表 public function changeLog() { $param = $this->request->filter('trim')->only(["code"=>"","type"=>""], 'post'); $val = Validate::rule(['code' => 'require|max:255', 'type' => 'require|number|in:1,2,3,4,5,6,7,8']); if (!$val->check($param)) return error_show(1005, $val->getError()); $count = Db::name('change_log') ->where([['code',"=", $param['code']],["type","=",$param['type']]]) ->json(["after_info","before_info"]) ->order("id desc") ->findOrEmpty(); return app_show(0, '请求成功', $count); } //财务审核是否合规接口 只有上线成功才可以操作 public function AddCompliance(){ $param = $this->request->filter('trim')->only(["skuCode"=>"","is_compliance"=>"","compliance_remark"=>""], 'post',"trim"); $val = Validate::rule([ 'compliance_remark|备注' => 'max:255', 'skuCode|上线商品编号' => 'require|max:255', 'is_compliance|是否合规' => 'require|number|in:0,1,2']); if ($val->check($param)==false) return error_show(1005, $val->getError()); $goodinfo =Db::name("good_platform") ->where(["skuCode"=>$param["skuCode"],"is_del"=>0]) ->findOrEmpty(); if(empty($goodinfo)) return error_show(1004,"未找到上线商品数据"); if($goodinfo['exam_status']!=3)return error_show(1004,"商品完成未上线不可操作"); $upinfo = [ "is_compliance"=>$param['is_compliance'], "compliance_remark"=>$param['compliance_remark'], "updatetime"=>date("Y-m-d H:i:s") ]; $up = Db::name("good_platform") ->where(["skuCode"=>$param["skuCode"],"is_del"=>0])->update($upinfo); if($up==false)return error_show(1004,"数据更新失败"); else return app_show(0,"数据更新成功"); } }