1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\ChangeLog;
- use think\App;
- use think\facade\Db;
- //商品基础库
- class Goodup extends Base
- {
- public $noble=[];
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->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 =[["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[]=['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[]=['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[]=['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[]=['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[]=['companyNo',"like","%$companyNo%"];
- $condit[]=['a.companyNo',"like","%$companyNo%"];
- }
- $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
- :"";
- if($supplierNo!==""){
- $where[]=['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");
- $where[]=['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");
- $where[]=['companyNo',"in",$companyNos];
- $condit[]=['a.companyNo',"in",$companyNos];
- }
- $brandid = isset($this->post['brandid']) && $this->post['brandid'] !=="" ? intval($this->post['brandid'])
- :"";
- if($brandid!==""){
- $where[]=['brand_id',"=",$brandid];
- $condit[]=['a.brand_id',"=",$brandid];
- }
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status'])
- :"";
- if($status!==""){
- $where[]=['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[] = ['is_stock', "=", $is_stock];
- }
- $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
- if($start!==""){
- $where[]=['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[]=['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!==""){
- 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');
- $where[]=["spuCode","in",$sta];
- }
- $count = Db::name('good_basic')->where($where)->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('good_basic')->where($where)->page($page,$size)->order("addtime desc")->select();
- $data=[];
- foreach ($list as $value){
- $value["cat_info"]= made($value['cat_id'],[]);
- $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
- $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
- $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
- $value['unit'] =isset($unit['unit'])?$unit['unit']:"";
- $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
- $value['company'] = isset($company['company'])?$company['company']:"";
- $supplier = Db::name("supplier")->where(['code'=>$value['supplierNo']])->find();
- $value['supplier_name']=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']] :"";
- $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不能为空");
- }
- // $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不能为空");
- }
- $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不能为空");
- }
- $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($ths->post['cgd_gold_price'])&&$ths->post['cgd_gold_price']!==""?floatval($ths->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不能为空");
- }
- $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,"启用阶梯,阶梯价不能为空");
- }
- $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= isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- $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,
- "tax"=>$tax,
- "supplierNo"=>$supplierNo,
- "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,
- "is_step"=>$is_step,
- "is_online"=>0,
- "status"=>0,
- "createrid"=>$createrid,
- "creater"=>$creater,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $in = Db::name("good_basic")->insert($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;
- 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){
- $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'];
- }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'] = 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,"商品规格值创建失败");
- }
- }
- 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,"未找到商品数据");
- }
- $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不能为空");
- }
- $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不能为空");
- }
- $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";
- $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,
- "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,
- "sample_fee"=>$sample_fee,
- "good_img"=>$good_img,
- "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")
- ];
- $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,$this->post['token'],$this->post);
- 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,"商品规格值修改失败");
- }
- }
- }
- 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,"未找到商品数据");
- }
- $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']):"";
- $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,
- "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"=>$is_step,
- "status"=>"2",
- "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,$this->post['token'],$this->post);
- $online = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->save(["is_online"=>0,"status"=>0,"updatetime"=>date("Y-m-d H:i:s")]);
- if($good_ladder!=="" && !empty($good_ladder)){
- 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){
- $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'];
- }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;
- 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,"未找到商品数据");
- }
- 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不能为空");
- }
- $user =GetUserInfo($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'] : "";
- Db::startTrans();
- try {
- if($data['status']==3 && $status==1){
- $online = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_online"=>0,"status"=>0, "is_del"=>0])->save(["is_online"=>0,"exam_status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
- }
- $data['status']=$status;
- $data['updatetime']=date("Y-m-d H:i:s");
- $up= Db::name("good_basic")->save($data);
- if($up){
- $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();
- $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
- $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
- $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
- $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
- $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find();
- $data['company'] = 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']:[];
- $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;
- return app_show(0,"获取成功",$data);
- }
- public function delall(){
- $supcode = isset($this->post['codes'])&&!empty($this->post['codes'])? $this->post['codes']:"";
- if($supcode==""){
- return error_show(1004,"参数codes不能为空");
- }
- $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
- if(empty($data)){
- return error_show(1004,"未找到商品数据");
- }
- $up= Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save(["is_del"=>1]);
- if($up){
- return app_show(0,"更新成功");
- }else{
- return error_show(1005,"更新失败");
- }
- }
- public function online(){
- $platform =isset($this->post['platform'])&&!empty($this->post['platform'])? $this->post['platform']:"";
- if($platform==""){
- return error_show(1004,"参数codes不能为空");
- }
- $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不能为空");
- }
- $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= isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- $data=[];
- $isonline=[];
- foreach ($spuCode as $value){
- $count = Db::name("good_nake")->where(["spuCode"=>$value,"is_del"=>0])->count();
- $ist =Db::name("good_platform")->where(["spuCode"=>$value,"platform_code"=>$platform,"is_del"=>0])->find();
- if($ist){
- $god=Db::name("good_basic")->where(["spuCode"=>$value,"is_del"=>0])->find();
- if($god){
- $tp=[];
- $tp['spuCode']=$value;
- $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,"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;
- }
- }
- $data[]=[
- "spuCode"=>$value,
- "skuCode"=>makeNo("SN"),
- "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")
- ];
- }
- if(!empty($isonline)){
- return app_show(1009,"存在已上线产品",$isonline);
- }
- Db::startTrans();
- $create =Db::name("good_platform")->insertAll($data);
- if($create){
- foreach ($datas as $value){
- $iso = Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
- if($iso==false){
- unset($value['id']);
- $value['creater']=$creater;
- $value['createrid']=$createrid;
- $value['addtime']=date("Y-m-d H:i:s");
- $value['updatetime']=date("Y-m-d H:i:s");
- }else{
- $value['id']=$iso['id'];
- $value['creater']=$creater;
- $value['createrid']=$createrid;
- $value['updatetime']=date("Y-m-d H:i:s");
- }
- $up =Db::name("good")->save($value);
- if(!$up){
- Db::rollback();
- return error_show(1004,"提交失败");
- }
- }
- Db::commit();
- return app_show(0,"提交成功");
- }else{
- Db::rollback();
- return error_show(1004,"提交失败");
- }
- }
- public function online_exam(){
- $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,"未找到数据");
- }
- $exam_status=isset($this->post['exam_status'])&&$this->post['exam_status']!==""?intval($this->post['exam_status']):"";
- // if($exam_status===""){
- // return error_show(1004,"参数exam_status不能为空");
- // }
- if($exam_status==3){
- $online_time= isset($this->post['online_time'])&&$this->post['online_time']!==""?$this->post['online_time']:"";
- if($online_time===""){
- return error_show(1004,"参数online_time不能为空");
- }
- $platform['online_time']=$online_time;
- }
- if($exam_status==6){
- $good_code= isset($this->post['plat_code'])&&$this->post['plat_code']!==""?trim($this->post['plat_code']):"";
- if($good_code===""){
- return error_show(1004,"参数plat_code不能为空");
- }
- $platform['plat_code']=$good_code;
- }
- $exam_remark = isset($this->post['exam_remark'])&&$this->post['exam_remark']!==""?trim($this->post['exam_remark']):"";
- $platform['exam_status']=$exam_status;
- $platform['updatetime']=date("Y-m-d H:i:s");
- $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= isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- Db::startTrans();
- try {
- $up = Db::name("good_platform")->save($platform);
- if($up){
- $data=[
- "code"=>$platform['skuCode'],
- "exam_status"=>$exam_status,
- "type"=>2,
- "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 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不能为空");
- }
- $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= isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- $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['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){
- $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"=>4,
- "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){
- 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($platform["exam_status"]!=7&&$platform["exam_status"]!=8){
- return error_show(1004,"商品状态有误");
- }
- $nake =Db::name("good_nake")->where(["spuCode"=>$platform['spuCode'],"is_del"=>0])->select()->toArray();
- $platform['exam_status'] = empty($nake)?1:2;
- $platform['updatetime'] = date("Y-m-d H:i:s");
- $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= isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- Db::startTrans();
- try {
- $save =Db::name("good_platform")->save($platform);
- if($save){
- $data=[
- "code"=>$platform['skuCode'],
- "type"=>2,
- "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){
- 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不能为空");
- }
- $user =GetUserInfo($token);
- if(empty($user)||$user['code']!=0){
- return error_show(102,"用户数据不存在");
- }
- $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- $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['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")->insert($data);
- if($cre){
- 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,"未找到商品数据");
- }
- if($data['status']!=6 &&$data['status']!=7 ){
- 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不能为空");
- }
- $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不能为空");
- }
- $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";
- $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";
- $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,"启用阶梯,阶梯价不能为空");
- }
- $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,
- "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,
- "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,
- "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"=>$is_step,
- "status"=>"0",
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $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,$this->post['token'],$this->post);
- 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)){
- 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){
- $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'];
- }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;
- 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(){
- $spuCode=isset($this->post['spuCode'])&&$this->post['spuCode']!=""? trim($this->post['spuCode']):"";
- if($spuCode==""){
- return error_show(1005,"参数spuCode不能为空");
- }
- $good =Db::name("good_basic")->where(["spuCode"=>$spuCode,"is_del"=>0])->find();
- if($good==false){
- return error_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'=>$spuCode,"is_del"=>0])->where([["min_num","<=",$num]])
- ->order("min_num desc")->find();
- if($nakelist==false){
- $nakelist = Db::name("good_nake")->where(['spuCode'=>$spuCode,"is_del"=>0])->order("min_num asc")->find();
- return error_show(1010,"起订量不足{$nakelist['min_num']}");
- }
- $catinfo = Db::name("cat")->where(["id"=>$good['cat_id']])->find();
- $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
- if($good['is_gold_price']==1){
- $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'];
- }else{
- $saleprice =$nakelist['mark_fee']+$nakelist['package_fee']+$nakelist['cert_fee']+$nakelist['delivery_fee']+$nakelist['nake_fee']/(1-$budget);
- }
- return app_show(0,"获取成功",["sale_price"=>round($saleprice,2)]);
- }
- }
|