Goodup.php 182 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\ChangeLog;
  5. use app\admin\model\DataGroup as DataGroupModel;
  6. use app\admin\model\GoodBasic;use app\admin\model\GoodCombind;use app\admin\model\GoodStock;use app\admin\model\ProcessOrder;
  7. use app\youzan\model\PlatformYouzan;
  8. use think\App;
  9. use think\Exception;
  10. use think\facade\Cache;
  11. use think\facade\Config;
  12. use think\facade\Db;
  13. use think\facade\Validate;
  14. //商品基础库
  15. class Goodup extends Base
  16. {
  17. public $noble=[];
  18. public function __construct(App $app)
  19. {
  20. parent::__construct($app);
  21. $this->noble=\think\facade\Config::get("noble");
  22. }
  23. public function list(){
  24. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  25. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  26. $where =[["gb.is_del","=",0]];
  27. $condit =[["a.is_del","=",0]];
  28. $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !=="" ? intval($this->post['cat_id']):"";
  29. if($cat_id!==""){
  30. $cat_ids=catChild($cat_id);
  31. $where[]=['gb.cat_id',"in",$cat_ids];
  32. $condit[]=['a.cat_id',"in",$cat_ids];
  33. }
  34. $is_combind = isset($this->post['is_combind']) && $this->post['is_combind'] !=='' ? intval($this->post['is_combind']):'';
  35. if($is_combind!==''){
  36. $where[]=['gb.is_combind','=',$is_combind];
  37. }
  38. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']):"";
  39. if($good_name!==""){
  40. $where[]=['gb.good_name',"like","%$good_name%"];
  41. $condit[]=['a.good_name',"like","%$good_name%"];
  42. }
  43. $spucode = isset($this->post['spucode']) && $this->post['spucode'] !=="" ? trim($this->post['spucode']) :"";
  44. if($spucode!==""){
  45. $where[]=['gb.spuCode',"like","%$spucode%"];
  46. $condit[]=['a.spuCode',"like","%$spucode%"];
  47. }
  48. $good_type = isset($this->post['good_type']) && $this->post['good_type'] !=="" ? trim($this->post['good_type']) :"";
  49. if($good_type!==""){
  50. $where[]=['gb.good_type',"=",$good_type];
  51. $condit[]=['a.good_type',"=",$good_type];
  52. }
  53. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) :"";
  54. if($companyNo!==""){
  55. $where[]=['gb.companyNo',"like","%$companyNo%"];
  56. $condit[]=['a.companyNo',"like","%$companyNo%"];
  57. }
  58. $userCommon = \app\admin\common\User::getIns();
  59. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :"";
  60. if($supplierNo!==""){
  61. $where[]=['gb.supplierNo',"like","%$supplierNo%"];
  62. $condit[]=['a.supplierNo',"like","%$supplierNo%"];
  63. }
  64. $supplier = isset($this->post['supplier']) && $this->post['supplier'] !=="" ? trim($this->post['supplier']) :"";
  65. if($supplier!==""){
  66. // $suppliernos = Db::name("supplier")->where([["name","like","%$supplier%"]])->column("code");
  67. $tmp = $userCommon->handle('sGetList',['name'=>$supplier]);
  68. if(isset($tmp['data']['list']) && !empty($tmp['data']['list'])){
  69. $suppliernos = array_column($tmp['data']['list'],'companyNo');
  70. $where[]=['gb.supplierNo',"in",$suppliernos];
  71. $condit[]=['a.supplierNo',"in",$suppliernos];
  72. }
  73. }
  74. $company = isset($this->post['company']) && $this->post['company'] !=="" ? trim($this->post['company']) :"";
  75. if($company!==""){
  76. // $companyNos = Db::name("business")->where([["company","like","%$company%"]])->column("companyNo");
  77. $tmp = $userCommon->handle('bGetList',['company'=>$company]);
  78. if(isset($tmp['data']['list']) && !empty($tmp['data']['list'])){
  79. $companyNos = array_column($tmp['data']['list'],'companyNo');
  80. $where[]=['gb.companyNo',"in",$companyNos];
  81. $condit[]=['a.companyNo',"in",$companyNos];
  82. }
  83. }
  84. $brandid = isset($this->post['brandid']) && $this->post['brandid'] !=="" ? intval($this->post['brandid']) :"";
  85. if($brandid!==""){
  86. $where[]=['gb.brand_id',"=",$brandid];
  87. $condit[]=['a.brand_id',"=",$brandid];
  88. }
  89. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
  90. if($status!==""){
  91. $where[]=['gb.status',"=",$status];
  92. $condit[]=['a.status',"=",$status];
  93. }
  94. $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] !== "" ? intval($this->post['is_stock']) : '';
  95. if ($is_stock!=='') {
  96. $where[] = ['gb.is_stock', "=", $is_stock];
  97. }
  98. $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  99. if($start!==""){
  100. $where[]=['gb.addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
  101. $condit[]=['a.addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
  102. }
  103. $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  104. if($end!==""){
  105. $where[]=['gb.addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  106. $condit[]=['a.addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  107. }
  108. $isonline = isset($this->post['isonline']) && $this->post['isonline']!=="" ? $this->post['isonline']:"";
  109. if($isonline!==""){
  110. $condit[] =['b.exam_status',"=",3];
  111. $sta =Db::name("good_basic")
  112. ->alias("a")
  113. ->leftJoin("good_platform b","a.spuCode=b.spuCode")
  114. ->where($condit)
  115. ->group("a.spuCode")
  116. ->column('a.spuCode');
  117. if($isonline==1) $where[]=["gb.spuCode","in",$sta];
  118. else $where[]=["gb.spuCode","not in",$sta];
  119. }
  120. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  121. if ($company_name !== "") $where[] = ["gb.createrid", 'in', get_company_item_user_by_name($company_name)];
  122. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):"";
  123. if($relaComNo!="") $where[]=['gb.companyNo','=', $relaComNo];
  124. $count = Db::name('good_basic')
  125. ->alias('gb')
  126. ->where($where)
  127. ->count('gb.id');
  128. $total = ceil($count / $size);
  129. $page = $page >= $total ? $total : $page;
  130. $list = Db::name('good_basic')
  131. ->alias('gb')
  132. ->where($where)
  133. ->page($page, $size)
  134. ->order("addtime desc")
  135. ->select()
  136. ->toArray();
  137. $data=[];
  138. $all_createrid = array_column($list,'chargerid');
  139. $item = get_company_name_by_uid($all_createrid);
  140. //查询一下这些spucode是否在平台上成功上线
  141. $exam_statuss = Db::name('good_platform')
  142. ->whereIn('spuCode',array_column($list,'spuCode'))
  143. ->where(['is_del'=>0,'exam_status'=>3])//exam_status==6表示上线审核成功
  144. ->column('id','spuCode');
  145. $exam_status_yz = Db::name('platform_youzan')
  146. ->whereIn('spuCode', array_column($list, 'spuCode'))
  147. ->where(['is_del' => 0, 'exam_status' => 6])//exam_status==6表示上线审核成功
  148. ->column('id', 'spuCode');
  149. $account = checkHasAccountBySupplierNos(array_column($list, 'supplierNo'));
  150. $brand = Db::name('brand')
  151. ->where(['id'=>array_column($list,'brand_id')])
  152. ->column('brand_name','id');
  153. $unit = Db::name('unit')
  154. ->where(['id'=>array_column($list,'good_unit')])
  155. ->column('unit','id');
  156. // $supplierInfo = $userCommon->handle('getCodeAndName',['code'=>array_merge(array_column($list,'companyNo'),array_column($list,'supplierNo'))]);
  157. foreach ($list as $value){
  158. $value["cat_info"]= made($value['cat_id'],[]);
  159. // $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  160. $value["brand_name"]=$brand[$value['brand_id']]??'';//isset($brand['brand_name'])?$brand['brand_name']:"";
  161. // $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
  162. $value['unit'] =$unit[$value['good_unit']]??'';//isset($unit['unit'])?$unit['unit']:"";
  163. // $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  164. $value['company'] = $value['companyName'];//$supplierInfo['data'][$value['companyNo']]??'';//isset($company['company'])?$company['company']:"";
  165. // $supplier = Db::name("supplier")->where(['code'=>$value['supplierNo']])->find();
  166. $value['supplier_name']=$value['supplierName'];//$supplierInfo['data'][$value['supplierNo']]??'';//isset($supplier['name'])?$supplier['name']:"";
  167. $value['exclusive']=makeExcluse($value['is_exclusive']);
  168. $value['noble_name']=isset($value['noble_metal'])&&$value['noble_metal']!=0?$this->noble[$value['noble_metal']] :"";
  169. //如果一个spucode在任意平台上线,那么就视为它上线,即手动把它的is_online值改为1
  170. $value['is_online'] = 0;
  171. if (isset($exam_statuss[$value['spuCode']]) || isset($exam_status_yz[$value['spuCode']])) $value['is_online'] = 1;
  172. else $value['is_online'] = 0;
  173. $value['charger_company_name'] = $item[$value['chargerid']]??'';
  174. $value['has_account'] = (int)isset($account[$value['supplierNo']]);
  175. //是否具有编辑权限
  176. $value['is_allow_update'] = 1;
  177. // if ($this->level == 2) {
  178. // if (in_array($this->roleid, [1, 33]) || in_array($value['chargerid'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  179. // } elseif ($this->level == 3) $value['is_allow_update'] = 1;
  180. $data[] = $value;
  181. }
  182. return app_show(0, "获取成功", ['count' => $count, 'list' => $data]);
  183. }
  184. //商品成本列表,不受数据权限控制
  185. public function list_copy()
  186. {
  187. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  188. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  189. $where = [["gb.is_del", "=", 0]];
  190. $condit = [["a.is_del", "=", 0]];
  191. $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !== "" ? intval($this->post['cat_id']) : "";
  192. if ($cat_id !== "") {
  193. $cat_ids = catChild($cat_id);
  194. $where[] = ['gb.cat_id', "in", $cat_ids];
  195. $condit[] = ['a.cat_id', "in", $cat_ids];
  196. }
  197. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
  198. if ($good_name !== "") {
  199. $where[] = ['gb.good_name', "like", "%$good_name%"];
  200. $condit[] = ['a.good_name', "like", "%$good_name%"];
  201. }
  202. $spucode = isset($this->post['spucode']) && $this->post['spucode'] !== "" ? trim($this->post['spucode']) : "";
  203. if ($spucode !== "") {
  204. $where[] = ['gb.spuCode', "like", "%$spucode%"];
  205. $condit[] = ['a.spuCode', "like", "%$spucode%"];
  206. }
  207. $good_type = isset($this->post['good_type']) && $this->post['good_type'] !== "" ? trim($this->post['good_type']) : "";
  208. if ($good_type !== "") {
  209. $where[] = ['gb.good_type', "=", $good_type];
  210. $condit[] = ['a.good_type', "=", $good_type];
  211. }
  212. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  213. if ($companyNo !== "") {
  214. $where[] = ['gb.companyNo', "like", "%$companyNo%"];
  215. $condit[] = ['a.companyNo', "like", "%$companyNo%"];
  216. }
  217. $userCommon = \app\admin\common\User::getIns();
  218. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  219. if ($supplierNo !== "") {
  220. $where[] = ['gb.supplierNo', "like", "%$supplierNo%"];
  221. $condit[] = ['a.supplierNo', "like", "%$supplierNo%"];
  222. }
  223. $supplier = isset($this->post['supplier']) && $this->post['supplier'] !== "" ? trim($this->post['supplier']) : "";
  224. if ($supplier !== "") {
  225. // $suppliernos = Db::name("supplier")->where([["name","like","%$supplier%"]])->column("code");
  226. $tmp = $userCommon->handle('sGetList', ['name' => $supplier]);
  227. if (isset($tmp['data']['list']) && !empty($tmp['data']['list'])) {
  228. $suppliernos = array_column($tmp['data']['list'], 'companyNo');
  229. $where[] = ['gb.supplierNo', "in", $suppliernos];
  230. $condit[] = ['a.supplierNo', "in", $suppliernos];
  231. }
  232. }
  233. $company = isset($this->post['company']) && $this->post['company'] !== "" ? trim($this->post['company']) : "";
  234. if ($company !== "") {
  235. // $companyNos = Db::name("business")->where([["company","like","%$company%"]])->column("companyNo");
  236. $tmp = $userCommon->handle('bGetList', ['company' => $company]);
  237. if (isset($tmp['data']['list']) && !empty($tmp['data']['list'])) {
  238. $companyNos = array_column($tmp['data']['list'], 'companyNo');
  239. $where[] = ['gb.companyNo', "in", $companyNos];
  240. $condit[] = ['a.companyNo', "in", $companyNos];
  241. }
  242. }
  243. $is_combind = isset($this->post['is_combind']) && $this->post['is_combind'] !=='' ? intval($this->post['is_combind']):'';
  244. if($is_combind!==''){
  245. $where[]=['gb.is_combind','=',$is_combind];
  246. }
  247. $brandid = isset($this->post['brandid']) && $this->post['brandid'] !== "" ? intval($this->post['brandid']) : "";
  248. if ($brandid !== "") {
  249. $where[] = ['gb.brand_id', "=", $brandid];
  250. $condit[] = ['a.brand_id', "=", $brandid];
  251. }
  252. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  253. if ($status !== "") {
  254. $where[] = ['gb.status', "=", $status];
  255. $condit[] = ['a.status', "=", $status];
  256. }
  257. $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] !== "" ? intval($this->post['is_stock']) : '';
  258. if ($is_stock !== '') {
  259. $where[] = ['gb.is_stock', "=", $is_stock];
  260. }
  261. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  262. if ($start !== "") {
  263. $where[] = ['gb.addtime', ">=", date('Y-m-d H:i:s', strtotime($start))];
  264. $condit[] = ['a.addtime', ">=", date('Y-m-d H:i:s', strtotime($start))];
  265. }
  266. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  267. if ($end !== "") {
  268. $where[] = ['gb.addtime', "<", date('Y-m-d H:i:s', strtotime($end) + 24 * 3600)];
  269. $condit[] = ['a.addtime', "<", date('Y-m-d H:i:s', strtotime($end) + 24 * 3600)];
  270. }
  271. $isonline = isset($this->post['isonline']) && $this->post['isonline'] !== "" ? $this->post['isonline'] : "";
  272. if ($isonline !== "") {
  273. $condit[] = ['b.exam_status', "=", 3];
  274. // if($isonline==1){
  275. // $condit[] =['b.exam_status',"=",6];
  276. // }else{
  277. // $condit[] =['b.exam_status',"<>",6];
  278. // }
  279. $sta = Db::name("good_basic")
  280. ->alias("a")
  281. ->leftJoin("good_platform b", "a.spuCode=b.spuCode")
  282. ->where($condit)
  283. ->group("a.spuCode")
  284. ->column('a.spuCode');
  285. if ($isonline == 1) $where[] = ["gb.spuCode", "in", $sta];
  286. else $where[] = ["gb.spuCode", "not in", $sta];
  287. }
  288. // $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  289. // if($token==""){
  290. // return error_show(101,'token不能为空');
  291. // }
  292. // $apply_id =GetUserInfo($token);
  293. // if(empty($apply_id)||$apply_id['code']!=0){
  294. // return error_show(102,"申请人数据不存在");
  295. // }
  296. // $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  297. // if($rm!=''){
  298. // $useinfo = Db::name("user_role")->where(['uid'=>$rm,"status"=>1,"is_del"=>0])->find();
  299. // if($useinfo==false){
  300. // return error_show(1002,"未找到用户角色权限");
  301. // }
  302. // $check = checkRole($useinfo['roleid'],115);
  303. // if($check){
  304. // $where[]=['gb.createrid', "=" ,$rm];
  305. // }
  306. // }
  307. // $role=$this->checkRole();
  308. // $wheror=[];
  309. // $role = $this->checkDataShare();//取负责人字段
  310. // if(!empty($role[DataGroupModel::$type_全部])) $wheror[]=["gb.chargerid","in",$role[DataGroupModel::$type_全部]];
  311. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  312. if ($company_name !== "") $where[] = ["gb.createrid", 'in', get_company_item_user_by_name($company_name)];
  313. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):"";
  314. if($relaComNo!="") $where[]=['gb.companyNo','=', $relaComNo];
  315. $count = Db::name('good_basic')
  316. ->alias('gb')
  317. ->where($where)
  318. // ->where(function ($Query) use ($wheror) {
  319. // return $Query->whereOr($wheror);
  320. // })
  321. ->count('gb.id');
  322. $total = ceil($count / $size);
  323. $page = $page >= $total ? $total : $page;
  324. $list = Db::name('good_basic')
  325. ->alias('gb')
  326. ->where($where)
  327. ->page($page, $size)
  328. ->order("addtime desc")
  329. ->select()
  330. ->toArray();
  331. $data = [];
  332. $all_createrid = array_column($list, 'chargerid');
  333. $item = get_company_name_by_uid($all_createrid);
  334. //查询一下这些spucode是否在平台上成功上线
  335. $exam_statuss = Db::name('good_platform')
  336. ->whereIn('spuCode', array_column($list, 'spuCode'))
  337. ->where(['is_del' => 0, 'exam_status' => 3])//exam_status==3表示上线审核成功
  338. ->column('id', 'spuCode');
  339. $exam_status_yz = Db::name('platform_youzan')
  340. ->whereIn('spuCode', array_column($list, 'spuCode'))
  341. ->where(['is_del' => 0, 'exam_status' => 6])//exam_status==3表示上线审核成功
  342. ->column('id', 'spuCode');
  343. $account = checkHasAccountBySupplierNos(array_column($list, 'supplierNo'));
  344. $brand = Db::name('brand')
  345. ->where(['id' => array_column($list, 'brand_id')])
  346. ->column('brand_name', 'id');
  347. $unit = Db::name('unit')
  348. ->where(['id' => array_column($list, 'good_unit')])
  349. ->column('unit', 'id');
  350. $supplierInfo = $userCommon->handle('getCodeAndName', ['code' => array_merge(array_column($list, 'companyNo'), array_column($list, 'supplierNo'))]);
  351. foreach ($list as $value) {
  352. $value["cat_info"] = made($value['cat_id'], []);
  353. // $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  354. $value["brand_name"] = $brand[$value['brand_id']] ?? '';//isset($brand['brand_name'])?$brand['brand_name']:"";
  355. // $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
  356. $value['unit'] = $unit[$value['good_unit']] ?? '';//isset($unit['unit'])?$unit['unit']:"";
  357. // $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  358. $value['company'] = $supplierInfo['data'][$value['companyNo']] ?? '';//isset($company['company'])?$company['company']:"";
  359. // $supplier = Db::name("supplier")->where(['code'=>$value['supplierNo']])->find();
  360. $value['supplier_name'] = $supplierInfo['data'][$value['supplierNo']] ?? '';//isset($supplier['name'])?$supplier['name']:"";
  361. $value['exclusive'] = makeExcluse($value['is_exclusive']);
  362. $value['noble_name'] = isset($value['noble_metal']) && $value['noble_metal'] != 0 ? $this->noble[$value['noble_metal']] : "";
  363. //如果一个spucode在任意平台上线,那么就视为它上线,即手动把它的is_online值改为1
  364. if (isset($exam_statuss[$value['spuCode']]) || isset($exam_status_yz[$value['spuCode']])) $value['is_online'] = 1;
  365. $value['charger_company_name'] = $item[$value['chargerid']] ?? '';
  366. $value['has_account'] = (int)isset($account[$value['supplierNo']]);
  367. // //是否具有编辑权限
  368. // $value['is_allow_update'] = 0;
  369. // if ($this->level == 2) {
  370. // if (in_array($this->roleid, [1, 33]) || in_array($value['chargerid'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  371. // } elseif ($this->level == 3) $value['is_allow_update'] = 1;
  372. $data[] = $value;
  373. }
  374. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  375. }
  376. public function create(){
  377. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):"";
  378. if($good_name==""){
  379. return error_show(1004,"商品名称不能为空");
  380. }
  381. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):"";
  382. if($cat_id==''){
  383. return error_show(1004,"商品分类不能为空");
  384. }
  385. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  386. if($brandid==''){
  387. return error_show(1004,"商品品牌不能为空");
  388. }
  389. $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):"";
  390. if($unit==''){
  391. return error_show(1004,"商品单位不能为空");
  392. }
  393. $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type']) :"";
  394. if($good_type===''){
  395. return error_show(1004,"参数good_type不能为空");
  396. }
  397. $moq=0;
  398. $customized=0;
  399. if($good_type==1){
  400. $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):"";
  401. if($moq===''){
  402. return error_show(1004,"定制商品起订量不能为空");
  403. }
  404. $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  405. if($customized===''){
  406. return error_show(1004,"参数customized不能为空");
  407. }
  408. }
  409. $isCombind= $this->post['is_combind']??0;
  410. $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):"";
  411. if($is_exclusive===''){
  412. return error_show(1004,"参数is_exclusive不能为空");
  413. }
  414. $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):"";
  415. if($tax===''){
  416. return error_show(1004,"参数tax不能为空");
  417. }
  418. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=''? trim($this->post['supplierNo']):'';
  419. $supplierArr=[];
  420. $supplier=[];
  421. $userCommon= \app\admin\common\User::getIns();
  422. if($supplierNo==''){
  423. return error_show(1004,'参数supplierNo不能为空');
  424. }
  425. $supplier_temp =$userCommon->handle('hqInfo',['code'=>$supplierNo]);
  426. if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1004,'供应商信息未找到');
  427. $supplierArr=$supplier_temp['data']??[];
  428. $supplier=$supplierArr['child']??[];
  429. $supplier_account = checkHasAccountBySupplierNos([$supplierNo]);
  430. if ($this->level == 2 &&isset($supplier_account[$supplierNo]) ) {
  431. return json_show(1004, '该供应商已开通账号,不允许操作');
  432. }
  433. $cgd_supplier_code = isset($this->post['cgd_supplier_code'])&&$this->post['cgd_supplier_code']!=''? trim($this->post['cgd_supplier_code']):'';
  434. $cgd_apply_id = isset($this->post['cgd_apply_id'])&&$this->post['cgd_apply_id']!=''? trim($this->post['cgd_apply_id']):'';
  435. $cgd_apply_name = isset($this->post['cgd_apply_name'])&&$this->post['cgd_apply_name']!=''? trim($this->post['cgd_apply_name']):'';
  436. // $supplier_origin_price = isset($this->post['supplier_origin_price'])&&$this->post['supplier_origin_price']!=''? floatval($this->post['supplier_origin_price']):'';
  437. $cgd_supplier_name='';
  438. if(isset($supplierArr['relation_code']) && $supplierArr['relation_code']!=''){
  439. if($cgd_supplier_code=="")return error_show(1004,'采购供应商信息不能为空');
  440. if($cgd_apply_id=="")return error_show(1004,'采购竞单人信息不能为空');
  441. // if($supplier_origin_price==="")return error_show(1004,'采购供应商信息采购成本不能为空');
  442. $cgd_supplier =$userCommon->handle('getCodeAndName',['code'=>$cgd_supplier_code]);
  443. $cgd_supplier_name= $cgd_supplier['data'][$cgd_supplier_code]??'';
  444. }
  445. $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size']):"";
  446. if($good_size==''){
  447. return error_show(1004,"参数good_size不能为空");
  448. }
  449. $proof_type = isset($this->post['proof_type'])&&$this->post['proof_type']!=""? trim($this->post['proof_type']):"";
  450. $proof_url = isset($this->post['proof_url'])&&$this->post['proof_url']!=""? trim($this->post['proof_url']):"";
  451. $company_id = isset($this->post['company_id'])&&$this->post['company_id']!=""? trim($this->post['company_id']) :"";
  452. if($company_id==''){
  453. return error_show(1004,"参数company_id不能为空");
  454. }
  455. $companyinfo =$userCommon->handle("getCodeAndName",["code"=>$company_id]);
  456. if(isset($supplierArr['relation_code'])&&$supplierArr['relation_code']==$company_id){
  457. return error_show(1004,"业务公司与供应商属于同一家公司");
  458. }
  459. $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):"";
  460. if($is_auth===''){
  461. return error_show(1004,"参数is_auth不能为空");
  462. }
  463. $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):"";
  464. $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):"";
  465. if($after_sales==""){
  466. return error_show(1004,"参数after_sales不能为空");
  467. }
  468. $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):"";
  469. $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):"";
  470. if($good_remark===""){
  471. return error_show(1004,"参数good_remark不能为空");
  472. }
  473. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  474. if($weight===""){
  475. return error_show(1004,"参数weight不能为空");
  476. }
  477. $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):"";
  478. if($packing_way===""){
  479. return error_show(1004,"参数packing_way不能为空");
  480. }
  481. $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):"";
  482. if($packing_size===""){
  483. return error_show(1004,"参数packing_size不能为空");
  484. }
  485. $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):"";
  486. if($packing_spec===""){
  487. return error_show(1004,"参数packing_spec不能为空");
  488. }
  489. $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):"";
  490. if($packing_weight===""){
  491. return error_show(1004,"参数packing_weight不能为空");
  492. }
  493. $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):"";
  494. if($packing_list===""){
  495. return error_show(1004,"参数packing_list不能为空");
  496. }
  497. $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):"";
  498. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  499. if($supply_area===""){
  500. return error_show(1004,"参数supply_area不能为空");
  501. }
  502. $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? trim($this->post['delivery_place']):"";
  503. if($delivery_place===""){
  504. return error_show(1004,"参数delivery_place不能为空");
  505. }
  506. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? trim($this->post['origin_place']):"";
  507. if($origin_place===""){
  508. return error_show(1004,"参数origin_place不能为空");
  509. }
  510. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):"";
  511. if($delivery_day===""){
  512. return error_show(1004,"参数delivery_day不能为空");
  513. }
  514. $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time']) :"0";
  515. $cgd_gold_price =isset($this->post['cgd_gold_price'])&&$this->post['cgd_gold_price']!==""?floatval($this->post['cgd_gold_price']):"0";
  516. $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0";
  517. $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0";
  518. $is_stock = isset($this->post['is_stock'])&&$this->post['is_stock']!==""? intval($this->post['is_stock']):"";
  519. if($is_stock===""){
  520. return error_show(1004,"参数is_stock不能为空");
  521. }
  522. // $stock_moq=0 ;//库存品备库起订量; 如果是0 表示无限制;
  523. $stock_moq = isset($this->post['stock_moq'])&&$this->post['stock_moq']!==""? intval($this->post['stock_moq']):"0";
  524. if($is_stock==1 && $stock_moq ==0){
  525. return error_show(1004,"库存品备库起订量不能为零");
  526. }
  527. if($is_stock==0 && $isCombind==1) return error_show(1004,'非库存品不支持组合商品类型');
  528. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"0";
  529. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  530. $config = isset($this->post['config'])&&$this->post['config']!==""? trim($this->post['config']):"";
  531. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!==""? trim($this->post['other_config']):"";
  532. if($good_img===""){
  533. return error_show(1004,"参数good_img不能为空");
  534. }
  535. $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):"";
  536. if($good_thumb_img===""){
  537. return error_show(1004,"参数good_thumb_img不能为空");
  538. }
  539. $good_info_img = isset($this->post['good_info_img'])&&$this->post['good_info_img']!=""? trim($this->post['good_info_img']):"";
  540. if($good_info_img===""){
  541. return error_show(1004,"参数good_info_img不能为空");
  542. }
  543. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  544. $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0";
  545. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  546. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  547. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  548. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  549. $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0";
  550. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  551. $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0";
  552. $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):"";
  553. if($market_price===""){
  554. return error_show(1004,"参数market_price不能为空");
  555. }
  556. $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"0";
  557. $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:"";
  558. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
  559. $is_support_barter = isset($this->post['is_support_barter']) && $this->post['is_support_barter'] !== "" ? intval($this->post['is_support_barter']) : 1;
  560. $combindList = $this->post["combind_list"]??[];
  561. $createrid= $this->uid;
  562. $creater= $this->uname;
  563. $spucode=makeNo("SKU");
  564. if($isCombind==1){
  565. if(empty($combindList)) return error_show(1004,'组合商品子商品信息不能为空');
  566. $spucode=makeNo("SSU");
  567. $dchild=[];
  568. $valid = Validate::rule(['childCode|子商品成本编号'=>'require','child_name|子商品名称'=>'require','child_num|组合比例'=>'require|number|gt:0']);
  569. foreach ($combindList as $value){
  570. if($valid->check($value)==false)return error_show(1004,$valid->getError());
  571. $value['spuCode'] = $spucode;
  572. $value['good_name'] =$good_name;
  573. $dchild[]=$value;
  574. }
  575. }
  576. Db::startTrans();
  577. try {
  578. $data=[
  579. "spuCode"=>$spucode,
  580. "good_code"=>'',
  581. "good_name"=>$good_name,
  582. "cat_id"=>$cat_id,
  583. 'brand_id'=>$brandid,
  584. "good_unit"=>$unit,
  585. "good_type"=>$good_type,
  586. "moq"=>$moq,
  587. "is_exclusive"=>$is_exclusive,
  588. "customized"=>$customized,
  589. "companyNo"=>$company_id,
  590. "companyName"=>$companyinfo['data'][$company_id]??"",
  591. "tax"=>$tax,
  592. "supplierNo"=>$supplierNo,
  593. "supplierName"=>$supplierArr['name']??"",
  594. "good_size"=>$good_size,
  595. "is_auth"=>$is_auth,
  596. "is_stock"=>$is_stock,
  597. "auth_img"=>$auth_img,
  598. "after_sales"=>$after_sales,
  599. "craft_desc"=>$craft_desc,
  600. "good_remark"=>$good_remark,
  601. "weight"=>$weight,
  602. "packing_way"=>$packing_way,
  603. "packing_size"=>$packing_size,
  604. "packing_spec"=>$packing_spec,
  605. "packing_list"=>$packing_list,
  606. "packing_weight"=>$packing_weight,
  607. "good_bar"=>$good_bar,
  608. "supply_area"=>$supply_area,
  609. "delivery_place"=>$delivery_place,
  610. "origin_place"=>$origin_place,
  611. "delivery_day"=>$delivery_day,
  612. "lead_time"=>$lead_time,
  613. "sample_day"=>$sample_day,
  614. "sample_fee"=>$sample_fee,
  615. "good_img"=>$good_img,
  616. "good_thumb_img"=>$good_thumb_img,
  617. "good_info_img"=>$good_info_img,
  618. "cert_fee"=>$cert_fee,
  619. "packing_fee"=>$packing_fee,
  620. "cost_fee"=>$cost_fee,
  621. "mark_fee"=>$mark_fee,
  622. "demo_fee"=>$demo_fee,
  623. "open_fee"=>$open_fee,
  624. "noble_metal"=>$noble_metal,
  625. "cgd_gold_price"=>$cgd_gold_price,
  626. "noble_weight"=>$noble_weight,
  627. "is_gold_price"=>$is_gold_price,
  628. "market_price"=>$market_price,
  629. "nake_price"=>$nake_price,
  630. "is_diff"=>$is_diff,
  631. "config"=>$config,
  632. "other_config"=>$other_config,
  633. "field_change"=>'',
  634. "is_step" => count($good_ladder) > 1 ? 1 : 0,//如果阶梯价个数大于1,说明启用阶梯价
  635. "is_online"=>0,
  636. "stock_moq"=>$stock_moq,
  637. "status"=>0,
  638. "createrid"=>$createrid,
  639. "creater"=>$creater,
  640. "addtime"=>date("Y-m-d H:i:s"),
  641. "updatetime"=>date("Y-m-d H:i:s"),
  642. 'is_support_barter'=>$is_support_barter,
  643. 'is_combind'=>$isCombind,
  644. 'chargerid'=>$supplier['personid']??$createrid,
  645. 'charger'=>$supplier['person']??$creater,//负责人跟创建人一致
  646. // 'supplier_origin_price'=>$supplier_origin_price,//供应商采购成本
  647. 'cgd_supplier_code'=>$cgd_supplier_code,//采购供应商编号
  648. 'cgd_supplier_name'=>$cgd_supplier_name,//采购供应商编号
  649. 'cgd_apply_id'=>$cgd_apply_id,//竞单人
  650. 'cgd_apply_name'=>$cgd_apply_name,//竞单人
  651. ];
  652. $in = Db::name("good_basic")->insertGetId($data);
  653. if($in){
  654. if($speclist!=="" && !empty($speclist)){
  655. $temp=[];
  656. foreach ($speclist as $value){
  657. $lemp=[];
  658. $lemp['spuCode']=$spucode;
  659. $lemp['spec_id'] = $value['spec_id'];
  660. $lemp['spec_value_id'] = $value['spec_value_id'];
  661. $lemp['addtime'] = date("Y-m-d H:i:s");
  662. $lemp['updatetime'] =date("Y-m-d H:i:s");
  663. $temp[]=$lemp;
  664. }
  665. $count = Db::name("good_spec")->insertAll($temp);
  666. if($count==0){
  667. throw new \Exception("商品规格值创建失败");
  668. }
  669. }
  670. if($proof_url!==''){
  671. $proof=[
  672. 'spuCode'=>$spucode,
  673. 'proof_type'=>$proof_type,
  674. 'proof_url'=>$proof_url,
  675. 'is_del'=>0,
  676. "creater"=>$creater,
  677. "createrid"=>$createrid,
  678. "addtime"=>date("Y-m-d H:i:s"),
  679. "updatetime"=>date("Y-m-d H:i:s")
  680. ];
  681. $inproof = Db::name("good_proof")->insert($proof);
  682. if($inproof==false)throw new \Exception("商品凭证新建失败");
  683. }
  684. $top_cat_id = made($cat_id);//获取所有分类
  685. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  686. if($good_ladder!=="" && !empty($good_ladder)){
  687. $temp=[];
  688. foreach ($good_ladder as $value){
  689. $lemp=[];
  690. $lemp['spuCode']=$spucode;
  691. $lemp['min_num'] = $value['min_num'];
  692. $lemp['nake_fee'] = $value['nake_fee'];
  693. $lemp['cost_fee'] = $value['cost_fee'];
  694. $lemp['delivery_fee'] = $value['delivery_fee'];
  695. $lemp['cert_fee'] = $value['cert_fee'];
  696. $lemp['mark_fee'] = $value['mark_fee'];
  697. $lemp['package_fee'] = $value['package_fee'];
  698. $lemp['other_fee'] = $value['other_fee'];
  699. $lemp['supplier_origin_price'] = $value['supplier_origin_price'];
  700. if($is_gold_price==1 && $top_cat_id==6){
  701. //$is_gold_price==1 表示启用实时金价,cat_id==6表示贵金属
  702. $gold = Db::name("gold_price1")->where(["type" => $noble_metal, "status" => 1, "is_del" => 0])->order("addtime desc")->find();
  703. //$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'];
  704. //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用
  705. //成本总计启用实时金价时,采用供应商实时金价
  706. $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'];
  707. }else{
  708. $lemp['nake_total'] =$value['nake_fee']+$value['delivery_fee']+$value['cert_fee']+$value['mark_fee']+$value['package_fee']+$value['other_fee'];
  709. }
  710. $lemp['creater_id'] = $createrid;
  711. $lemp['creater'] = $creater;
  712. $lemp['is_del'] = 0;
  713. $lemp['addtime'] = date("Y-m-d H:i:s");
  714. $lemp['updatetime'] =date("Y-m-d H:i:s");
  715. $temp[]=$lemp;
  716. }
  717. $count = Db::name("good_nake")->insertAll($temp);
  718. if($count==0){
  719. throw new \Exception("商品成本创建失败");
  720. }
  721. }
  722. if($isCombind==1 && !empty($dchild)){
  723. (new GoodCombind())->saveAll($dchild);
  724. }
  725. //修改状态,添加待办
  726. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  727. "order_code" =>$spucode,//咨询单详情编号
  728. "status" => 0,//这里的status是之前的值
  729. "action_remark" => '',//备注
  730. "action_type" => "create"//新建create,编辑edit,更改状态status
  731. ], "SPCB", 0,$data);
  732. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  733. "order_type" => 'SPCB',
  734. "order_code" => $spucode,//咨询单详情编号
  735. "order_id" => $in,
  736. "order_status" => 0,
  737. "before_status" => 0,
  738. 'holder_id'=>$data['createrid'],
  739. ]);
  740. Db::commit();
  741. return app_show(0,"创建成功",["spuCode"=>$spucode]);
  742. }else{
  743. throw new \Exception("商品创建失败");
  744. }
  745. }catch (\Exception $e){
  746. Db::rollback();
  747. return app_show(1004,$e->getMessage());
  748. }
  749. }
  750. public function editinfo(){
  751. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  752. if($supcode==""){
  753. return error_show(1004,"参数spuCode不能为空");
  754. }
  755. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  756. if($data==false){
  757. return error_show(1004,"未找到商品数据");
  758. }
  759. $is_down = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->where("exam_status","<>",5)
  760. ->find();
  761. if($is_down!=false){
  762. return error_show(1004,"存在未下线商品数据");
  763. }
  764. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):"";
  765. if($good_name==""){
  766. return error_show(1004,"商品名称不能为空");
  767. }
  768. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):"";
  769. if($cat_id==''){
  770. return error_show(1004,"商品分类不能为空");
  771. }
  772. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"0";
  773. $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):"";
  774. if($unit==''){
  775. return error_show(1004,"商品单位不能为空");
  776. }
  777. $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type']) :"";
  778. if($good_type===''){
  779. return error_show(1004,"参数good_type不能为空");
  780. }
  781. $moq=0;
  782. $customized=0;
  783. if($good_type==1){
  784. $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):"";
  785. if($moq===''){
  786. return error_show(1004,"定制商品起订量不能为空");
  787. }
  788. $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  789. if($customized===''){
  790. return error_show(1004,"参数customized不能为空");
  791. }
  792. }
  793. $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):"";
  794. if($is_exclusive===''){
  795. return error_show(1004,"参数is_exclusive不能为空");
  796. }
  797. $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):"";
  798. if($tax===''){
  799. return error_show(1004,"参数tax不能为空");
  800. }
  801. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  802. $isCombind= $this->post['is_combind']??0;
  803. $supplierArr=[];
  804. $supplier=[];
  805. $userCommon= \app\admin\common\User::getIns();
  806. if($supplierNo=='')return error_show(1004,'参数supplierNo不能为空');
  807. $supplier_temp =$userCommon->handle('hqInfo',['code'=>$supplierNo]);
  808. if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1004,'供应商信息未找到');
  809. $supplierArr=$supplier_temp['data']??[];
  810. $supplier=$supplierArr['child']??[];
  811. $supplier_account = checkHasAccountBySupplierNos([$supplierNo]);
  812. $cgd_supplier_code = isset($this->post['cgd_supplier_code'])&&$this->post['cgd_supplier_code']!=''? trim($this->post['cgd_supplier_code']):'';
  813. $cgd_apply_id = isset($this->post['cgd_apply_id'])&&$this->post['cgd_apply_id']!=''? trim($this->post['cgd_apply_id']):'';
  814. $cgd_apply_name = isset($this->post['cgd_apply_name'])&&$this->post['cgd_apply_name']!=''? trim($this->post['cgd_apply_name']):'';
  815. // $supplier_origin_price = isset($this->post['supplier_origin_price'])&&$this->post['supplier_origin_price']!=''? floatval($this->post['supplier_origin_price']):'';
  816. $cgd_supplier_name='';
  817. if(isset($supplierArr['relation_code']) && $supplierArr['relation_code']!=''){
  818. if($cgd_supplier_code=='')return error_show(1004,'采购供应商信息不能为空');
  819. if($cgd_apply_id=='')return error_show(1004,'采购竞单人信息不能为空');
  820. // if($supplier_origin_price==='')return error_show(1004,'采购供应商信息采购成本不能为空');
  821. $cgd_supplier =$userCommon->handle('getCodeAndName',['code'=>$cgd_supplier_code]);
  822. $cgd_supplier_name= $cgd_supplier['data'][$cgd_supplier_code]??'';
  823. }
  824. $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size']) :"";
  825. if($good_size==''){
  826. return error_show(1004,"参数good_size不能为空");
  827. }
  828. $company_id = isset($this->post['company_id'])&&$this->post['company_id']!=""? trim($this->post['company_id']) :"";
  829. if($company_id==''){
  830. return error_show(1004,"参数company_id不能为空");
  831. }
  832. $companyinfo =$userCommon->handle("getCodeAndName",["code"=>$company_id]);
  833. if(isset($supplierArr['relation_code'])&&$supplierArr['relation_code']==$company_id){
  834. return error_show(1004,"业务公司与供应商属于同一家公司");
  835. }
  836. $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):"";
  837. if($is_auth===''){
  838. return error_show(1004,"参数is_auth不能为空");
  839. }
  840. $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):"";
  841. // if($auth_img==''){
  842. // return error_show(1004,"商品不能为空");
  843. // }
  844. $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):"";
  845. if($after_sales==""){
  846. return error_show(1004,"参数after_sales不能为空");
  847. }
  848. $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):"";
  849. $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):"";
  850. if($good_remark===""){
  851. return error_show(1004,"参数good_remark不能为空");
  852. }
  853. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  854. if($weight===""){
  855. return error_show(1004,"参数weight不能为空");
  856. }
  857. $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):"";
  858. if($packing_way===""){
  859. return error_show(1004,"参数packing_way不能为空");
  860. }
  861. $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):"";
  862. if($packing_size===""){
  863. return error_show(1004,"参数packing_size不能为空");
  864. }
  865. $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):"";
  866. if($packing_spec===""){
  867. return error_show(1004,"参数packing_spec不能为空");
  868. }
  869. $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):"";
  870. if($packing_weight===""){
  871. return error_show(1004,"参数packing_weight不能为空");
  872. }
  873. $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):"";
  874. if($packing_list===""){
  875. return error_show(1004,"参数packing_list不能为空");
  876. }
  877. $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):"";
  878. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  879. if($supply_area===""){
  880. return error_show(1004,"参数supply_area不能为空");
  881. }
  882. $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? $this->post['delivery_place']:"";
  883. if($delivery_place===""){
  884. return error_show(1004,"参数delivery_place不能为空");
  885. }
  886. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? $this->post['origin_place']:"";
  887. if($origin_place===""){
  888. return error_show(1004,"参数origin_place不能为空");
  889. }
  890. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):"";
  891. if($delivery_day===""){
  892. return error_show(1004,"参数delivery_day不能为空");
  893. }
  894. $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time']) :"0";
  895. // if($lead_time===""){
  896. // return error_show(1004,"参数lead_time不能为空");
  897. // }
  898. $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0";
  899. // if($sample_day===""){
  900. // return error_show(1004,"参数sample_day不能为空");
  901. // }
  902. // $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval
  903. //($this->post['sample_fee']):"0";
  904. $config = isset($this->post['config'])&&$this->post['config']!==""? trim($this->post['config']):"";
  905. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!==""? trim($this->post['other_config']):"";
  906. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"0";
  907. $is_stock = isset($this->post['is_stock'])&&$this->post['is_stock']!==""? intval($this->post['is_stock']):"0";
  908. $stock_moq = isset($this->post['stock_moq'])&&$this->post['stock_moq']!==""? intval($this->post['stock_moq']):"0";
  909. if($is_stock==1 && $stock_moq ==0){
  910. return error_show(1004,"库存品备库起订量不能为零");
  911. }
  912. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  913. if($good_img===""){
  914. return error_show(1004,"参数good_img不能为空");
  915. }
  916. $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):"";
  917. if($good_thumb_img===""){
  918. return error_show(1004,"参数good_thumb_img不能为空");
  919. }
  920. $good_info_img = isset($this->post['good_info_img'])&&!empty($this->post['good_info_img'])? trim($this->post['good_info_img']):"";
  921. if($good_info_img===""){
  922. return error_show(1004,"参数good_info_img不能为空");
  923. }
  924. $count = Db::name("good_nake")->where(["spuCode"=>$supcode,"is_del"=>0])->count();
  925. $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:"";
  926. $proof_type = isset($this->post['proof_type'])&&$this->post['proof_type']!=""? trim($this->post['proof_type']):"";
  927. $proof_url = isset($this->post['proof_url'])&&$this->post['proof_url']!=""? trim($this->post['proof_url']):"";
  928. $combindList = $this->post['combind_list']??[];
  929. if($isCombind==1){
  930. if(empty($combindList)) return error_show(1004,'组合商品子商品信息不能为空');
  931. $dchild=[];
  932. $valid = Validate::rule(['childCode|子商品成本编号'=>'require','child_name|子商品名称'=>'require','child_num|组合比例'=>'require|number|gt:0']);
  933. foreach ($combindList as $value){
  934. if($valid->check($value)==false)return error_show(1004,$valid->getError());
  935. $value['spuCode'] = $data['spuCode'];
  936. $value['good_name'] =$good_name;
  937. $value['updatetime'] =date("Y-m-d H:i:s");
  938. if($value['is_del']==1){
  939. $usable_stock = Db::name("good")->where(["spuCode"=>$data['spuCode']])->value("usable_stock",0);
  940. if($usable_stock>0) return error_show(1004,'组合商品库存未处理完不可删除子商品');
  941. }
  942. $dchild[]=$value;
  943. }
  944. }
  945. Db::startTrans();
  946. try {
  947. $temp=[
  948. "good_name"=>$good_name,
  949. "cat_id"=>$cat_id,
  950. 'brand_id'=>$brandid,
  951. "good_unit"=>$unit,
  952. "good_type"=>$good_type,
  953. "companyNo"=>$company_id,
  954. "companyName"=>$companyinfo['data'][$company_id]??'',
  955. "supplierName"=>$supplierArr['name']??"",
  956. "moq"=>$moq,
  957. "is_exclusive"=>$is_exclusive,
  958. "customized"=>$customized,
  959. "tax"=>$tax,
  960. "supplierNo"=>$supplierNo,
  961. "is_auth"=>$is_auth,
  962. "good_size"=>$good_size,
  963. "auth_img"=>$auth_img,
  964. "after_sales"=>$after_sales,
  965. "craft_desc"=>$craft_desc,
  966. "good_remark"=>$good_remark,
  967. "weight"=>$weight,
  968. "packing_way"=>$packing_way,
  969. "packing_size"=>$packing_size,
  970. "packing_spec"=>$packing_spec,
  971. "packing_list"=>$packing_list,
  972. "packing_weight"=>$packing_weight,
  973. "good_bar"=>$good_bar,
  974. "supply_area"=>$supply_area,
  975. "delivery_place"=>$delivery_place,
  976. "origin_place"=>$origin_place,
  977. "delivery_day"=>$delivery_day,
  978. "lead_time"=>$lead_time,
  979. "sample_day"=>$sample_day,
  980. "is_diff"=>$is_diff,
  981. 'is_stock'=>$is_stock,
  982. "config"=>$config,
  983. "other_config"=>$other_config,
  984. "good_img" => $good_img,
  985. "stock_moq" => $stock_moq,
  986. "good_thumb_img"=>$good_thumb_img,
  987. "good_info_img"=>$good_info_img,
  988. "status"=>$count>0?2:1,
  989. "updatetime" => date("Y-m-d H:i:s"),
  990. 'is_combind'=>$isCombind,
  991. 'chargerid' => $supplier['personid'] ?? $this->uid,
  992. 'charger' => $supplier['person'] ?? $this->uname,//负责人跟创建人一致
  993. // 'supplier_origin_price'=>$supplier_origin_price,//供应商采购成本
  994. 'cgd_supplier_code'=>$cgd_supplier_code,//采购供应商编号
  995. 'cgd_supplier_name'=>$cgd_supplier_name,//采购供应商编号
  996. 'cgd_apply_id'=>$cgd_apply_id,//竞单人
  997. 'cgd_apply_name'=>$cgd_apply_name,//竞单人
  998. ];
  999. $field = array_diff_assoc($temp,$data);
  1000. $temp['field_change'] =empty($field)?"":json_encode(array_keys($field));
  1001. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($temp);
  1002. $timp = array_diff($temp,$data);
  1003. $json = json_encode($timp,JSON_UNESCAPED_UNICODE);
  1004. $jsp = json_encode($data,JSON_UNESCAPED_UNICODE);
  1005. if($up){
  1006. $this->BasicToGood($supcode,$temp);
  1007. ChangeLog::logAdd(3,$data['spuCode'],$jsp,$json,['id' => $this->uid, 'nickname' => $this->uname]);
  1008. if($speclist!=="" && !empty($speclist)){
  1009. foreach ($speclist as $value){
  1010. $lemp=[];
  1011. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  1012. $lemp['spuCode']=$supcode;
  1013. $lemp['spec_id'] = $value['spec_id'];
  1014. $lemp['spec_value_id'] = $value['spec_value_id'];
  1015. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1016. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  1017. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1018. $count = Db::name("good_spec")->save($lemp);
  1019. if($count==false){
  1020. Db::rollback();
  1021. return app_show(1004,"商品规格值修改失败");
  1022. }
  1023. }
  1024. }
  1025. if($proof_url!=''){
  1026. $proof=[
  1027. 'spuCode'=>$supcode,
  1028. 'proof_type'=>$proof_type,
  1029. 'proof_url'=>$proof_url,
  1030. 'is_del'=>0,
  1031. "creater"=>$this->uname,
  1032. "createrid"=>$this->uid,
  1033. "addtime"=>date("Y-m-d H:i:s"),
  1034. "updatetime"=>date("Y-m-d H:i:s")
  1035. ];
  1036. $inproof = Db::name("good_proof")->insert($proof);
  1037. if($inproof==false)throw new \Exception("商品凭证新建失败");
  1038. }
  1039. if($isCombind==1 && !empty($dchild)){
  1040. (new GoodCombind())->saveAll($dchild);
  1041. }
  1042. //修改状态,添加待办
  1043. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
  1044. "order_code" =>$supcode,//咨询单详情编号
  1045. "status" => $data['status'],//这里的status是之前的值
  1046. "action_remark" => '',//备注
  1047. "action_type" => "edit"//新建create,编辑edit,更改状态status
  1048. ], "SPCB",$temp['status'] ,$data);
  1049. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
  1050. "order_type" => 'SPCB',
  1051. "order_code" => $supcode,//咨询单详情编号
  1052. "order_id" => $data['id'],
  1053. "order_status" =>$temp['status'],
  1054. "before_status"=>$data['status'],
  1055. 'holder_id'=>$data['createrid'],
  1056. ]);
  1057. Db::commit();
  1058. return app_show(0,"更新成功");
  1059. }else{
  1060. Db::rollback();
  1061. return error_show(1005,"更新失败");
  1062. }
  1063. }catch (\Exception $e){
  1064. Db::rollback();
  1065. return error_show(1004,$e->getMessage());
  1066. }
  1067. }
  1068. public function editfee(){
  1069. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1070. if($supcode==""){
  1071. return error_show(1004,"参数spuCode不能为空");
  1072. }
  1073. $datas = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1074. if($datas==false){
  1075. return error_show(1004,"未找到商品数据");
  1076. }
  1077. $is_down = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->where("exam_status","<>",5)
  1078. ->find();
  1079. if($is_down!=false){
  1080. return error_show(1004,"存在未下线商品数据");
  1081. }
  1082. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  1083. $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0";
  1084. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  1085. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  1086. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  1087. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  1088. $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0";
  1089. $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0";
  1090. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  1091. $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0";
  1092. $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):"";
  1093. $cgd_gold_price = isset($this->post['cgd_gold_price'])&&$this->post['cgd_gold_price']!==""? floatval($this->post['cgd_gold_price']):"0";
  1094. if($market_price===""){
  1095. return error_show(1004,"参数market_price不能为空");
  1096. }
  1097. $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"";
  1098. // $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  1099. // if($is_step===""){
  1100. // return error_show(1004,"参数is_step不能为空");
  1101. // }
  1102. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
  1103. // if($is_step==1 && $good_ladder==""){
  1104. // return error_show(1004,"启用阶梯,阶梯价不能为空");
  1105. // }
  1106. $data=[
  1107. "cert_fee"=>$cert_fee,
  1108. "packing_fee"=>$packing_fee,
  1109. "cost_fee"=>$cost_fee,
  1110. "mark_fee"=>$mark_fee,
  1111. "demo_fee"=>$demo_fee,
  1112. "open_fee"=>$open_fee,
  1113. "sample_fee"=>$sample_fee,
  1114. "noble_metal"=>$noble_metal,
  1115. "noble_weight"=>$noble_weight,
  1116. "is_gold_price"=>$is_gold_price,
  1117. "market_price"=>$market_price,
  1118. "nake_price"=>$nake_price,
  1119. "cgd_gold_price"=>$cgd_gold_price,
  1120. "is_step" => count($good_ladder) > 1 ? 1 : 0,
  1121. "status"=>"3",
  1122. "updatetime"=>date("Y-m-d H:i:s")
  1123. ];
  1124. $field = array_diff_assoc($data,$datas);
  1125. $data['field_change'] =empty($field)?"":json_encode(array_keys($field));
  1126. Db::startTrans();
  1127. try{
  1128. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($data);
  1129. $temp = array_diff($data,$datas);
  1130. $json = json_encode($temp,JSON_UNESCAPED_UNICODE);
  1131. $jsp = json_encode($datas,JSON_UNESCAPED_UNICODE);
  1132. if($up){
  1133. $this->BasicToGood($supcode,$data);
  1134. ChangeLog::logAdd(3,$datas['spuCode'],$jsp,$json,['id' => $this->uid, 'nickname' => $this->uname]);
  1135. //修改状态,添加待办
  1136. ActionLog::logAdd($this->post['token'], [
  1137. "order_code" =>$supcode,//咨询单详情编号
  1138. "status" => $datas['status'],//这里的status是之前的值
  1139. "action_remark" => '',//备注
  1140. "action_type" => "edit"//新建create,编辑edit,更改状态status
  1141. ], "SPCB",$data['status'] ,$data);
  1142. ProcessOrder::AddProcess($this->post['token'], [
  1143. "order_type" => 'SPCB',
  1144. "order_code" => $supcode,//咨询单详情编号
  1145. "order_id" => $datas['id'],
  1146. "order_status" =>$data['status'],
  1147. "before_status"=>$datas['status'],
  1148. 'holder_id'=>$datas['createrid'],
  1149. ]);
  1150. if($good_ladder!=="" && !empty($good_ladder)){
  1151. $user =GetUserInfo($this->post['token']);
  1152. foreach ($good_ladder as $value){
  1153. $lemp=[];
  1154. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  1155. $lemp['spuCode']=$supcode;
  1156. $lemp['min_num'] = $value['min_num'];
  1157. $lemp['nake_fee'] = $value['nake_fee'];
  1158. $lemp['cost_fee'] = $value['cost_fee'];
  1159. $lemp['delivery_fee'] = $value['delivery_fee'];
  1160. $lemp['cert_fee'] = $value['cert_fee'];
  1161. $lemp['mark_fee'] = $value['mark_fee'];
  1162. $lemp['package_fee'] = $value['package_fee'];
  1163. $lemp['other_fee'] = $value['other_fee'];
  1164. $lemp['supplier_origin_price'] = $value['supplier_origin_price'];
  1165. $top_cat_id = made($datas['cat_id']);//获取所有分类
  1166. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  1167. if($is_gold_price==1 && $top_cat_id==6){
  1168. $gold =Db::name("gold_price1")->where(["type"=>$noble_metal,"status"=>1,"is_del"=>0])->order("addtime desc")->find();
  1169. //$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'];
  1170. //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用
  1171. //成本总计启用实时金价时,采用供应商实时金价
  1172. $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'];
  1173. }else{
  1174. $lemp['nake_total'] =$value['nake_fee']+$value['delivery_fee']+$value['cert_fee']+$value['mark_fee']+$value['package_fee']+$value['other_fee'];
  1175. }
  1176. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1177. $lemp['creater_id'] = isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1178. $lemp['creater'] =isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1179. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  1180. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1181. $count = Db::name("good_nake")->save($lemp);
  1182. if($count==false){
  1183. Db::rollback();
  1184. return app_show(1004,"商品规成本修改失败");
  1185. }
  1186. }
  1187. }
  1188. Db::commit();
  1189. return app_show(0,"更新成功");
  1190. }else{
  1191. Db::rollback();
  1192. return error_show(1005,"更新失败");
  1193. }
  1194. }catch (\Exception $e){
  1195. Db::rollback();
  1196. return error_show(1005,$e->getMessage());
  1197. }
  1198. }
  1199. public function exam(){
  1200. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1201. if($supcode==""){
  1202. return error_show(1004,"参数spuCode不能为空");
  1203. }
  1204. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1205. if($data==false){
  1206. return error_show(1004,"未找到商品数据");
  1207. }
  1208. $isupdate = $this->isUpdate($supcode);
  1209. if($isupdate==0){
  1210. return error_show(1004,"存在上线进行中的商品");
  1211. }
  1212. if($data['status']==1){
  1213. return error_show(1004,"商品已审核通过");
  1214. }
  1215. $status = isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):"";
  1216. // if($status===""){
  1217. // return error_show(1004,"参数status不能为空");
  1218. // }
  1219. $remark = isset($this->post['remark'])&&$this->post['remark']!=="" ? trim($this->post['remark']):"";
  1220. // if($remark===""){
  1221. // return error_show(1004,"参数remark不能为空");
  1222. // }
  1223. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1224. if($token==''){
  1225. return error_show(105,"参数token不能为空");
  1226. }
  1227. $createrid=$this->uid;
  1228. $creater= $this->uname;
  1229. Db::startTrans();
  1230. try {
  1231. if($status==1){
  1232. //区分是否是对接平台
  1233. $platform_info=Db::name('platform')
  1234. ->field('id,platform_type')
  1235. ->where(['is_del'=>0,'platform_type'=>1])
  1236. ->column("id");
  1237. $online = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->whereNotIn("platform_code",$platform_info)->find();
  1238. if($online) {
  1239. $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")]);
  1240. if ($onl == false) {
  1241. Db::rollback();
  1242. return error_show(1004, "审核失败");
  1243. }
  1244. ActionLog::logAdd($this->post['token'], [
  1245. "order_code" =>$online['skuCode'],//咨询单详情编号
  1246. "status" => $online['exam_status'],//这里的status是之前的值
  1247. "action_remark" => '',//备注
  1248. "action_type" => "edit"//新建create,编辑edit,更改状态status
  1249. ], "SPSX", 2, ["exam_status" => 2, "updatetime" => date("Y-m-d H:i:s")]);
  1250. ProcessOrder::AddProcess($this->post['token'], [
  1251. "order_type" => 'SPSX',
  1252. "order_code" =>$online['skuCode'],//咨询单详情编号
  1253. "order_id" => $online['id'],
  1254. "order_status" => 2,
  1255. "before_status"=>$online['exam_status'],
  1256. 'holder_id' => $online['createrid'],
  1257. ]);
  1258. }
  1259. }
  1260. // if ($status == 1) {
  1261. // //把同一个spuCode,且状态为1待完善成本,的记录更改状态为2待产品审核
  1262. // Db::name('good')
  1263. // ->where(['is_del' => 0, 'status' => 1])
  1264. // ->whereIn('spuCode', $supcode)
  1265. // ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]);
  1266. // }
  1267. $old_status = $data['status'];
  1268. $data['status']=$status;
  1269. $data['updatetime']=date("Y-m-d H:i:s");
  1270. $up= Db::name("good_basic")->save($data);
  1271. if($up){
  1272. //修改状态,添加待办
  1273. ActionLog::logAdd($this->post['token'], [
  1274. "order_code" =>$supcode,//咨询单详情编号
  1275. "status" => $status,//这里的status是之前的值
  1276. "action_remark" => '',//备注
  1277. "action_type" => "edit"//新建create,编辑edit,更改状态status
  1278. ], "SPCB",$data['status'] ,$data);
  1279. ProcessOrder::AddProcess($this->post['token'], [
  1280. "order_type" => 'SPCB',
  1281. "order_code" => $supcode,//咨询单详情编号
  1282. "order_id" => $data['id'],
  1283. "order_status" =>$data['status'],
  1284. "before_status"=>$old_status,
  1285. 'holder_id'=>$data['createrid'],
  1286. ]);
  1287. $data=[
  1288. "code"=>$supcode,
  1289. "exam_status"=>$status,
  1290. "type"=>1,
  1291. "exam_id"=>$createrid,
  1292. "exam_name"=>$creater,
  1293. "exam_remark"=>$remark,
  1294. "addtime"=>date("Y-m-d H:i:s")
  1295. ];
  1296. $inr=Db::name("good_exam")->insert($data);
  1297. if($inr){
  1298. Db::commit();
  1299. return app_show(0,"审核成功");
  1300. }else{
  1301. Db::rollback();
  1302. return error_show(1004,"审核失败");
  1303. }
  1304. }else{
  1305. Db::rollback();
  1306. return error_show(1004,"审核失败");
  1307. }
  1308. }catch (\Exception $e){
  1309. Db::rollback();
  1310. return error_show(1004,$e->getMessage());
  1311. }
  1312. }
  1313. public function info(){
  1314. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1315. if($supcode==""){
  1316. return error_show(1004,"参数spuCode不能为空");
  1317. }
  1318. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1319. if($data==false){
  1320. return error_show(1004,"未找到商品数据");
  1321. }
  1322. $unit =Db::name("unit")->where(["id"=>$data['good_unit']])->find();
  1323. $data['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1324. $data['cat_info'] = made($data['cat_id'],[]);
  1325. $spec = Db::name("good_spec")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  1326. $userCommon = \app\admin\common\User::getIns();
  1327. $sinfo = $userCommon->handle('sInfo',['code'=>$data['supplierNo']]);
  1328. $data['cgderid'] = $sinfo['data']['personid'] ?? '';
  1329. $data['cgder'] = $sinfo['data']['person'] ?? '';
  1330. $data['combind_list'] =[];
  1331. $data['wsm_list']=[];
  1332. $data['usable_stock']=(new GoodStock())->withJoin(['wsminfo'],'left')
  1333. ->where(['spuCode' => $supcode, 'wsm_type'=>[2,5]])
  1334. ->sum('usable_stock');
  1335. if($data['is_combind']==1){
  1336. $data['combind_list'] = (new GoodCombind())->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  1337. foreach ($data['combind_list'] as &$item){
  1338. $item['stock'] =bcmul($item['child_num'],$data['usable_stock']);
  1339. }
  1340. $data['wsm_list']=(new GoodStock())->withJoin(['wsminfo'] , 'left')
  1341. ->where(['spuCode'=>$supcode , 'wsm_type'=>[2 , 5]])
  1342. ->column('good_stock.id stock_id,name,good_stock.wsm_code,usable_stock');
  1343. }
  1344. $data['field_change'] = $data['field_change']!=''?json_decode($data['field_change']):"";
  1345. if($data['brand_id']!=0){
  1346. $brand=Db::name("brand")->where(["id"=>$data['brand_id']])->find();
  1347. $data["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1348. }else{
  1349. $data["brand_name"]="";
  1350. $data["brand_id"]="";
  1351. }
  1352. $excluse = makeExcluse($data['is_exclusive']);
  1353. $data['exclusive']=$excluse;
  1354. $data['noble_name']=isset($data['noble_metal'])&&$data['noble_metal']!=0?$this->noble[$data['noble_metal']] :"";
  1355. $data["good_info_img"]=$data['good_info_img']!=""? $data['good_info_img']:'';
  1356. $data["good_img"]=$data['good_img']!=""? $data['good_img']:[];
  1357. $gold=[];
  1358. if ($data['is_gold_price'] == 1) {
  1359. $gold = Db::name("gold_price1")->where(["type" => $data['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->find();
  1360. }
  1361. $data['cgd_price'] = 0;
  1362. if($data['create_source']==1){
  1363. $data['cgd_price'] = Db::name("purchease_order")->where(["spuCode"=>$supcode,"order_type"=>3])->value
  1364. ("good_price",0);
  1365. }
  1366. $data['gold_price'] =isset($gold["price"])?$gold["price"]:0;
  1367. $speclist=[];
  1368. if(!empty($spec)){
  1369. foreach ($spec as $value){
  1370. $temp=[];
  1371. $temp['id']=$value['id'];
  1372. $temp['spuCode']=$value['spuCode'];
  1373. $temp['spec_id']=$value['spec_id'];
  1374. $temp['spec_value_id']=$value['spec_value_id'];
  1375. $temp['is_del']=$value['is_del'];
  1376. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  1377. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  1378. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  1379. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  1380. $speclist[]=$temp;
  1381. }
  1382. }
  1383. $data["speclist"]=empty($speclist)?[]:$speclist;
  1384. $nakelist = Db::name("good_nake")->where(['spuCode'=>$supcode,"is_del"=>0])->select()->toArray();
  1385. $nakearry=[];
  1386. if(!empty($nakelist)){
  1387. foreach ($nakelist as $value) {
  1388. $nakearry[] = $value;
  1389. }
  1390. }
  1391. $data["nakelist"]=$nakearry;
  1392. return app_show(0,"获取成功",$data);
  1393. }
  1394. //删除商品成本
  1395. public function delall()
  1396. {
  1397. $supcode = $this->request->post('codes', '', 'trim');
  1398. if ($supcode == "") {
  1399. return error_show(1004, "参数codes不能为空");
  1400. }
  1401. Db::startTrans();
  1402. try {
  1403. $good_basic = Db::name("good_basic")
  1404. ->field('id,spuCode,status')
  1405. ->where(["spuCode" => $supcode, "is_del" => 0])
  1406. ->select()->toArray();
  1407. if (empty($good_basic)) throw new Exception('该记录不存在或已删除');
  1408. $good = Db::name('good')
  1409. ->alias('g')
  1410. ->field('gp.id,gp.exam_status,gp.skuCode')
  1411. ->leftJoin('good_platform gp', 'gp.spuCode=g.spuCode AND gp.is_del=0')
  1412. ->where(['g.spuCode' => $supcode, 'g.is_del' => 0])
  1413. ->where('gp.exam_status',"<>",5)
  1414. ->select()->toArray();
  1415. if (!empty($good)) throw new Exception('该商品需要下线之后才能删除');
  1416. Db::name("good_basic")
  1417. ->where(["spuCode" => $supcode, 'is_del' => 0])
  1418. ->update(['is_del' => 1, 'updatetime' => date('Y-m-d H:i:s')]);
  1419. Db::name("good")
  1420. ->where(['spuCode' => $supcode, 'is_del' => 0])
  1421. ->update(['is_del' => 1, 'updatetime' => date('Y-m-d H:i:s')]);
  1422. Db::name("good_platform")
  1423. ->where(['spuCode' => $supcode, 'is_del' => 0])
  1424. ->where('exam_status', "<>",5)
  1425. ->update(['is_del' => 1, 'updatetime' => date('Y-m-d H:i:s')]);
  1426. Db::name("good_ladder")->where(["skuCode"=>array_column($good,"skuCode"),"is_del"=>0])->update(['is_del'
  1427. => 1, 'updatetime' => date('Y-m-d H:i:s')]);
  1428. Db::name("good_nake")->where(["spuCode"=>$supcode,"is_del"=>0])->update(['is_del'
  1429. => 1, 'updatetime' => date('Y-m-d H:i:s')]);
  1430. ProcessOrder::workdel(["order_type" => "SPCB", "order_code" => $supcode]);
  1431. ProcessOrder::workdel(["order_type" => "SPSX", "order_code" => array_column($good,"skuCode")]);
  1432. Db::commit();
  1433. app_show(0, "删除成功");
  1434. } catch (Exception $exception) {
  1435. Db::rollback();
  1436. return error_show(1005, "删除失败," . $exception->getMessage());
  1437. }
  1438. }
  1439. //添加上线商品
  1440. public function online(){
  1441. $platform =isset($this->post['platform'])&&!empty($this->post['platform'])? $this->post['platform']:"";
  1442. if($platform==""){
  1443. return error_show(1004,"参数platform不能为空");
  1444. }
  1445. // $spuCode =isset($this->post['codes'])&&!empty($this->post['codes'])? $this->post['codes']:"";
  1446. // if($spuCode===''){
  1447. // return error_show(1004,"参数codes不能为空");
  1448. // }
  1449. $goodinfo =isset($this->post['goodinfo'])&&!empty($this->post['goodinfo'])? $this->post['goodinfo']:[];
  1450. if(empty($goodinfo)){
  1451. return error_show(1004,'参数goodinfo不能为空');
  1452. }
  1453. $datas = Db::name("good_basic")->where(["spuCode"=>array_column($goodinfo,"spuCode"),"is_del"=>0])->select()
  1454. ->toArray();
  1455. if(empty($datas)){
  1456. return error_show(1004,"未找到商品数据");
  1457. }
  1458. $online_reason = isset($this->post['online_reason'])&&$this->post['online_reason']!==""? trim($this->post['online_reason']):"";
  1459. if($online_reason===""){
  1460. return error_show(1004,"参数online_reason不能为空");
  1461. }
  1462. $online_remark= isset($this->post['online_remark'])&&$this->post['online_remark']!==""? trim($this->post['online_remark']):"";
  1463. if($online_remark===""){
  1464. return error_show(1004,"参数online_remark不能为空");
  1465. }
  1466. $fixed = isset($this->post['is_fixed'])&&$this->post['is_fixed']!==''? intval($this->post['is_fixed']):1;
  1467. if($fixed==1){
  1468. //使用实时金价
  1469. $nake=Db::name('good_nake')->where(['spuCode'=> array_column($goodinfo,'spuCode'),'is_del'=>0,"nake_fee"=>0])->findOrEmpty();
  1470. if(!empty($nake)) return error_show(1004,'一口价商品请先完善商品成本单价');
  1471. }
  1472. $createrid= $this->uid;//isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1473. $creater= $this->uname;//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1474. //区分是否是对接平台
  1475. $platform_info=Db::name('platform')
  1476. ->field('id,platform_type,is_select_pay_rate,status')
  1477. ->where(['is_del'=>0,'id'=>$platform])
  1478. ->findOrEmpty();
  1479. if(empty($platform_info)) return error_show(1005,'所选的平台不存在');
  1480. if($platform_info['status']!=1) return error_show(1005,'所选的平台已禁用');
  1481. if($platform_info['is_select_pay_rate']==1){
  1482. foreach ($datas as $ite){
  1483. if(channel_is_company($platform,$ite['companyNo'])) return error_show(1004, "商品{$ite['spuCode']}平台渠道含有业务公司{$ite['companyName']}");
  1484. }
  1485. }
  1486. if($platform_info['platform_type']==1){
  1487. if($fixed==0) return error_show(1005,'有赞平台商品不可使用实时金价');
  1488. return \app\youzan\logic\Goodup::create([
  1489. 'platform_id'=>$platform,
  1490. 'online_reason'=>$online_reason,
  1491. 'online_remark'=>$online_remark,
  1492. 'good_data'=>$datas,
  1493. 'good_info'=>$goodinfo,
  1494. 'createrid'=>$createrid,
  1495. 'creater'=>$creater,
  1496. ]);
  1497. }
  1498. $market = array_column( $goodinfo,"market_url",'spuCode');
  1499. $data=[];
  1500. $isonline=[];
  1501. $i=0;
  1502. Db::startTrans();
  1503. try{
  1504. foreach ($datas as $value){
  1505. $count = Db::name("good_nake")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->count();
  1506. $ist =Db::name("good_platform")->where(["spuCode"=>$value['spuCode'],"platform_code"=>$platform,"is_del"=>0])->find();
  1507. if($ist){
  1508. $god=Db::name("good_basic")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  1509. if($god){
  1510. $tp=[];
  1511. $tp['spuCode']=$value['spuCode'];
  1512. $tp['good_name']=$god['good_name'];
  1513. $tp['good_img']=$god['good_thumb_img'];
  1514. $tp['exam_status']=$ist['exam_status'];
  1515. $spec = Db::name("good_spec")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->select()->toArray();
  1516. $speclist=[];
  1517. if(!empty($spec)){
  1518. foreach ($spec as $val){
  1519. $temp=[];
  1520. $temp['id']=$val['id'];
  1521. $temp['spuCode']=$val['spuCode'];
  1522. $temp['spec_id']=$val['spec_id'];
  1523. $temp['spec_value_id']=$val['spec_value_id'];
  1524. $temp['is_del']=$val['is_del'];
  1525. $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
  1526. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  1527. $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
  1528. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  1529. $speclist[]=$temp;
  1530. }
  1531. }
  1532. $tp["speclist"]=empty($speclist)?[]:$speclist;
  1533. $isonline[]=$tp;
  1534. }
  1535. }
  1536. if(!empty($isonline)){
  1537. return app_show(1009,"存在已上线产品",$isonline);
  1538. }
  1539. //改变编码规则,将原来的skuCode后两位换成序列号
  1540. //str_pad字符串填充
  1541. $skuCode = makeNo("SN");
  1542. $skuCode = substr($skuCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
  1543. $tmp=[
  1544. "spuCode"=>$value['spuCode'],
  1545. "skuCode"=>$skuCode,
  1546. "platform_code"=>$platform,
  1547. "online_reason"=>$online_reason,
  1548. "online_remark"=>$online_remark,
  1549. "exam_status"=>$count>0 ?2:1,
  1550. "is_online"=>0,
  1551. "is_fixed"=>$fixed,
  1552. 'market_url'=>$market[$value['spuCode']]??"",
  1553. "status"=>1,
  1554. "is_del"=>0,
  1555. "creater"=>$creater,
  1556. "createrid"=>$createrid,
  1557. "addtime"=>date("Y-m-d H:i:s"),
  1558. "updatetime"=>date("Y-m-d H:i:s")
  1559. ];
  1560. $i++;
  1561. $create =Db::name("good_platform")->insert($tmp,true);
  1562. if($create>0){
  1563. $iso = Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->findOrEmpty();
  1564. if(empty($iso)){
  1565. unset($value['id']);
  1566. $stock_num = Db::name('good_stock')->alias("a")
  1567. ->leftJoin("warehouse_info b","a.wsm_code=b.wsm_code")
  1568. ->where(['a.is_del' => 0, 'a.spuCode' =>$value['spuCode'],"b.wsm_type"=>[2,5]])->sum('usable_stock');
  1569. $value['usable_stock'] =$stock_num;
  1570. $value['addtime']=date("Y-m-d H:i:s");
  1571. $value['updatetime']=date("Y-m-d H:i:s");
  1572. }else{
  1573. $value['id']=$iso['id'];
  1574. $value['updatetime']=date("Y-m-d H:i:s");
  1575. }
  1576. $up = Db::name("good")->strict(false)->save($value);
  1577. if(!$up){
  1578. Db::rollback();
  1579. return error_show(1004,"提交失败");
  1580. }
  1581. //修改状态,添加待办
  1582. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  1583. "order_code" => $skuCode,//编号
  1584. "status" => 0,
  1585. "action_remark" => '',//备注
  1586. "action_type" => 'create'//新建create,编辑edit,更改状态status
  1587. ], "SPSX", $tmp['exam_status'], $platform);
  1588. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  1589. "order_type" => 'SPSX',
  1590. "order_code" => $skuCode,//咨询单详情编号
  1591. "order_id" => $create,
  1592. "order_status" => $tmp['exam_status'],
  1593. "before_status" => 0,
  1594. 'holder_id' => $createrid,
  1595. ]);
  1596. }else{
  1597. Db::rollback();
  1598. return error_show(1004,"提交失败");
  1599. }
  1600. }
  1601. Db::commit();
  1602. return app_show(0,"提交成功");
  1603. }catch (\Exception $e){
  1604. Db::rollback();
  1605. return error_show(1004, $e->getMessage());
  1606. }
  1607. }
  1608. //审核
  1609. public function online_exam(){
  1610. $post =$this->request->only([
  1611. "skuCode"=>"", //商品成本编号
  1612. "exam_status"=>"", //审核状态 1 提交待完善成本 2待审核 3上线完成 4 审核驳回 5 下线完成
  1613. "offline_reason"=>"", //下线原因
  1614. "offline_remark"=>"", //下线备注
  1615. "plat_code"=>"", //平台订单号
  1616. 'exam_remark'=>"", //审核备注
  1617. 'good_ladder'=>[], //售价阶梯
  1618. 'proof_type'=>"", // 售价凭证类型
  1619. 'proof_url'=>"", // 售价凭证
  1620. ],"post","trim");
  1621. $valide = Validate::rule([
  1622. "skuCode|商品编号"=>"require|max:255",
  1623. "exam_status|审核状态"=>"require|number|in:0,1,2,3,4,5",
  1624. "offline_reason|线下原因"=>"requireIf:exam_status,5|max:255",
  1625. "offline_remark|下线备注"=>"requireIf:exam_status,5|max:255",
  1626. "plat_code|平台商品编码"=>"requireIf:exam_status,3|max:255",
  1627. 'exam_remark|审核备注'=>"max:255",
  1628. 'good_ladder|售价阶梯'=>"requireIf:exam_status,3|array",
  1629. 'proof_type|售价凭证类型'=>"requireIf:exam_status,3|number|gt:0",
  1630. 'proof_url|售价凭证'=>"requireIf:exam_status,3|max:255",
  1631. ]);
  1632. if($valide->check($post)==false) return error_show(1004,$valide->getError());
  1633. $platform = Db::name("good_platform")->where(["skuCode"=>$post['skuCode'],"is_del"=>0])->find();
  1634. if($platform==false){
  1635. return error_show(1004,"未找到数据");
  1636. }
  1637. if($platform['is_fixed']==1){
  1638. //使用实时金价
  1639. $nake=Db::name('good_nake')->where(['spuCode'=> $platform['spuCode'],'is_del'=>0,'nake_fee'=>0])
  1640. ->findOrEmpty();
  1641. if(!empty($nake)) return error_show(1004,'一口价商品请先完善商品成本单价');
  1642. }
  1643. if($post['exam_status']==3){
  1644. $is_exit = Db::name("good_platform")
  1645. ->where(["plat_code" =>$post['plat_code'], "platform_code" => $platform['platform_code'], "is_del" =>0, 'exam_status' =>3])//exam_status==3已上线
  1646. ->where("id", "<>", $platform['id'])
  1647. ->find();
  1648. if($is_exit==false){
  1649. $platform['plat_code']=$post['plat_code'];
  1650. }else{
  1651. return error_show(1004,"平台商品编码 {$post['plat_code']} 已存在");
  1652. }
  1653. }
  1654. if($post['exam_status']==5){
  1655. $platform['is_compliance']=0;
  1656. $platform['compliance_remark']='';
  1657. }
  1658. $before = $platform['exam_status'];
  1659. $platform['exam_status']=$post['exam_status'];
  1660. $platform['updatetime']=date("Y-m-d H:i:s");
  1661. $createrid= $this->uid;
  1662. $creater= $this->uname;
  1663. Db::startTrans();
  1664. try {
  1665. $up = Db::name("good_platform")->save($platform);
  1666. if($up){
  1667. $data=[
  1668. "code"=>$platform['skuCode'],
  1669. "exam_status"=>$post['exam_status'],//$exam_status,
  1670. "type"=>2,
  1671. "exam_id"=>$createrid,
  1672. "exam_name"=>$creater,
  1673. "exam_remark"=>$post['exam_remark'],
  1674. "addtime"=>date("Y-m-d H:i:s")
  1675. ];
  1676. $inr=Db::name("good_exam")->insert($data);
  1677. if($inr){
  1678. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  1679. "order_code" => $platform['skuCode'],//编号
  1680. "status" => $before,
  1681. "action_remark" => '',//备注
  1682. "action_type" => "status"//新建create,编辑edit,更改状态status
  1683. ], "SPSX", $post['exam_status'], $platform);
  1684. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  1685. "order_type" => 'SPSX',
  1686. "order_code" =>$platform['skuCode'],//咨询单详情编号
  1687. "order_id" => $platform['id'],
  1688. "order_status" => $post['exam_status'],
  1689. "before_status" => $before,
  1690. 'holder_id' => $platform['createrid'],
  1691. ]);
  1692. //如果是商品下线的话,记入商品下线记录表
  1693. if ($post['exam_status'] == 5) {
  1694. $offline_id = Db::name("good_offline_log")->insertGetId([
  1695. 'spuCode' => $platform['spuCode'],
  1696. 'skuCodes' => $platform['skuCode'],
  1697. 'good_name' => Db::name("good_basic")->where('spuCode', $platform['spuCode'])->value('good_name', ''),
  1698. 'offline_reason' => $post['offline_reason'],
  1699. 'offline_remark' => $post['offline_remark'],
  1700. 'createrid' => $createrid,
  1701. 'creater' => $creater,
  1702. 'addtime' => date('Y-m-d H:i:s'),
  1703. ]);
  1704. //根据权限查询应该接收商品下线通知的人员
  1705. $all_uid_name = Db::name('role_action')
  1706. ->whereFindInSet('action_conllect','877')//数据写死的,要注意各个环境数据是否一致
  1707. ->field('role_id')
  1708. ->buildSql();
  1709. $all_user = Db::name('user_role')
  1710. ->alias('ur')
  1711. ->where('ur.roleid IN '.$all_uid_name)
  1712. ->leftJoin('depart_user du','du.uid = ur.uid AND du.is_del=0')
  1713. ->column('ur.uid,du.nickName');
  1714. $insert_order_msg_data=[];
  1715. foreach ($all_user as $itemitem) {
  1716. $insert_order_msg_data[] = [
  1717. 'content' => '商品下线:' . $platform['spuCode'] . '由' . $creater . '操作下线',
  1718. 'orderCode' => $platform['skuCode'],
  1719. 'order_type' => 'GOL',
  1720. 'order_status' => 5,
  1721. 'order_id' => $offline_id,
  1722. 'apply_id' => $createrid,
  1723. 'apply_name' => $creater,
  1724. 'uid' => $itemitem['uid'],
  1725. 'uname' => empty($itemitem['nickName']) ? '' : $itemitem['nickName'],
  1726. 'is_read' => 0,
  1727. 'addtime' => date('Y-m-d H:i:s'),
  1728. 'updatetime' => date('Y-m-d H:i:s'),
  1729. ];
  1730. }
  1731. //消息表
  1732. Db::name('order_msg')->insertAll($insert_order_msg_data);
  1733. }
  1734. if ($post['exam_status'] == 3) {
  1735. //todo::需要去掉;
  1736. $proof=[
  1737. 'spuCode'=>$platform['spuCode'],
  1738. 'proof_type'=>$post['proof_type'],
  1739. 'proof_url'=>$post['proof_url'],
  1740. 'is_del'=>0,
  1741. "creater"=>$this->uname,
  1742. "createrid"=>$this->uid,
  1743. "addtime"=>date("Y-m-d H:i:s"),
  1744. "updatetime"=>date("Y-m-d H:i:s")
  1745. ];
  1746. $inproof = Db::name("good_proof")->insert($proof);
  1747. if($inproof==false)throw new \Exception("商品凭证新建失败");
  1748. if(empty($post['good_ladder']))throw new \Exception("商品阶梯价不能为空");
  1749. foreach ($post['good_ladder'] as $value){
  1750. $lemp=[];
  1751. isset($value["id"])?$lemp['id']=$value['id']:$lemp['addtime'] = date("Y-m-d H:i:s");
  1752. $lemp['skuCode']=$platform['skuCode'];
  1753. $lemp['min_num'] = $value['min_num'];
  1754. $lemp['max_num'] = 0;
  1755. $lemp['sale_price'] = $value['sale_price'];
  1756. $lemp['market_price'] = $value['market_price'];
  1757. $lemp['market_platform'] = $value['market_platform'];
  1758. $lemp['cost_fee'] = $value['cost_fee'];
  1759. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1760. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1761. //$value["id"]?'':$lemp['addtime'] = date("Y-m-d H:i:s");$lemp['updatetime'] =date("Y-m-d H:i:s");
  1762. $ladderUp = Db::name("good_ladder")->save($lemp);
  1763. if($ladderUp==false) throw new \Exception("商品起订价修改失败");
  1764. }
  1765. }
  1766. Db::commit();
  1767. return app_show(0,"审核成功");
  1768. }else{
  1769. Db::rollback();
  1770. return error_show(1004,"审核失败");
  1771. }
  1772. }else{
  1773. Db::rollback();
  1774. return error_show(1004,"审核失败");
  1775. }
  1776. }catch (\Exception $e){
  1777. Db::rollback();
  1778. return error_show(1004,$e->getMessage());
  1779. }
  1780. }
  1781. //财务定价 废弃
  1782. public function editladder(){
  1783. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  1784. if($skuCode===""){
  1785. return error_show(1004,"参数skuCode不能为空");
  1786. }
  1787. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  1788. if($platform==false){
  1789. return error_show(1004,"未找到数据");
  1790. }
  1791. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])?$this->post['good_ladder']:"";
  1792. if($good_ladder==""){
  1793. return error_show(1004,"参数good_ladder不能为空");
  1794. }
  1795. $proof_type = isset($this->post['proof_type'])&&$this->post['proof_type']!==""?intval($this->post['proof_type']):"";
  1796. if($proof_type===""){
  1797. return error_show(1004,"参数proof_type不能为空");
  1798. }
  1799. $proof_url = isset($this->post['proof_url'])&&$this->post['proof_url']!==""?trim($this->post['proof_url']):"";
  1800. if($proof_url===""){
  1801. return error_show(1004,"参数proof_url不能为空");
  1802. }
  1803. $exam_remark = isset($this->post['exam_remark'])&& $this->post['exam_remark']!='' ? trim($this->post['exam_remark']):"";
  1804. $createrid= $this->uid;//isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1805. $creater= $this->uname;//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1806. $bifore=$platform['exam_status'];
  1807. $platform['exam_status']=4;
  1808. $platform['updatetime']=date("Y-m-d H:i:s");
  1809. Db::startTrans();
  1810. try {
  1811. foreach ($good_ladder as $value){
  1812. $lemp=[];
  1813. isset($value["id"])&&$value["id"]!=""?$lemp['id']=$value['id']:"";
  1814. $lemp['skuCode']=$skuCode;
  1815. $lemp['min_num'] = $value['min_num'];
  1816. $lemp['max_num'] = 0;
  1817. $lemp['sale_price'] = $value['sale_price'];
  1818. $lemp['market_price'] = $value['market_price'];
  1819. $lemp['market_platform'] = $value['market_platform'];
  1820. $lemp['cost_fee'] = $value['cost_fee'];
  1821. $lemp['status'] = $value['status'];
  1822. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1823. isset($value["id"])&&$value["id"]!=""?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  1824. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1825. $count = Db::name("good_ladder")->save($lemp);
  1826. if($count==false){
  1827. Db::rollback();
  1828. return app_show(1004,"商品起订价修改失败");
  1829. }
  1830. }
  1831. $up = Db::name("good_platform")->save($platform);
  1832. if($up){
  1833. // ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  1834. // "order_code" =>$platform['skuCode'],//咨询单详情编号
  1835. // "status" =>$bifore,//这里的status是之前的值
  1836. // "action_remark" => '',//备注
  1837. // "action_type" => "edit"//新建create,编辑edit,更改状态status
  1838. // ], "SPSX", $platform['exam_status'],$platform);
  1839. //
  1840. // ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
  1841. // "order_type" => 'SPSX',
  1842. // "order_code" =>$platform['skuCode'],//咨询单详情编号
  1843. // "order_id" => $platform['id'],
  1844. // "order_status" => $platform['exam_status'],
  1845. // "before_status"=>$bifore,
  1846. // 'holder_id' => $platform['createrid'],
  1847. // ]);
  1848. $proof=[
  1849. 'spuCode'=>$platform['spuCode'],
  1850. 'proof_type'=>$proof_type,
  1851. 'proof_url'=>$proof_url,
  1852. 'is_del'=>0,
  1853. "creater"=>$creater,
  1854. "createrid"=>$createrid,
  1855. "addtime"=>date("Y-m-d H:i:s"),
  1856. "updatetime"=>date("Y-m-d H:i:s")
  1857. ];
  1858. $inproof = Db::name("good_proof")->insert($proof);
  1859. if($inproof==false){
  1860. Db::rollback();
  1861. return app_show(1004,"商品凭证新建失败");
  1862. }
  1863. $data=[
  1864. "code"=>$platform['skuCode'],
  1865. "type"=>2,
  1866. "exam_status"=>$bifore,//4,
  1867. "exam_id"=>$createrid,
  1868. "exam_name"=>$creater,
  1869. "exam_remark"=>$exam_remark,
  1870. "addtime"=>date("Y-m-d H:i:s")
  1871. ];
  1872. $inr=Db::name("good_exam")->insert($data);
  1873. if($inr){
  1874. Db::commit();
  1875. return app_show(0,"审核成功");
  1876. }else{
  1877. Db::rollback();
  1878. return error_show(1004,"审核失败");
  1879. }
  1880. }else{
  1881. Db::rollback();
  1882. return error_show(1004,"审核失败");
  1883. }
  1884. }catch (\Exception $e){
  1885. Db::rollback();
  1886. return error_show(1004,$e->getMessage());
  1887. }
  1888. }
  1889. public function prooflist(){
  1890. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  1891. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  1892. $where =[["is_del","=",0]];
  1893. $spuCode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1894. if($spuCode!==""){
  1895. $where[]=["spuCode","like","%$spuCode%"];
  1896. }
  1897. $count = Db::name("good_proof")->where($where)->count();
  1898. $total = ceil($count / $size);
  1899. $page = $page >= $total ? $total : $page;
  1900. $data = Db::name("good_proof")->where($where)->page($page,$size)->order("addtime desc")->select();
  1901. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  1902. }
  1903. /**
  1904. * 已下线商品重新发起上线流程
  1905. */
  1906. public function againOnline(){
  1907. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  1908. if($skuCode===""){
  1909. return error_show(1004,"参数skuCode不能为空");
  1910. }
  1911. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  1912. if($platform==false){
  1913. return error_show(1004,"未找到数据");
  1914. }
  1915. if(!in_array($platform["exam_status"],[4,5])){
  1916. return error_show(1004,"商品状态有误");
  1917. }
  1918. //判断平台商品编码是否重复
  1919. // $rs = Db::name("good_platform")
  1920. // ->field('id')
  1921. // ->where(["plat_code" => $platform['plat_code'],"platform_code" => $platform['platform_code'], 'exam_status' => 6, "is_del" => 0])//exam_status==6已上线
  1922. // ->where('id', '<>', $platform['id'])
  1923. // ->find();
  1924. // if (!empty($rs)) return error_show(1005, '该商品的平台商品编码已被使用');
  1925. $nake =Db::name("good_nake")->where(["spuCode"=>$platform['spuCode'],"is_del"=>0])->select()->toArray();
  1926. $bifore=$platform['exam_status'];
  1927. $platform['exam_status'] = empty($nake)?1:2;
  1928. $platform['updatetime'] = date("Y-m-d H:i:s");
  1929. $createrid= $this->uid;
  1930. $creater= $this->uname;
  1931. Db::startTrans();
  1932. try {
  1933. $save =Db::name("good_platform")->save($platform);
  1934. if($save){
  1935. ActionLog::logAdd(['id'=>$createrid,'nickname'=>$creater], [
  1936. "order_code" =>$platform['skuCode'],//咨询单详情编号
  1937. "status" =>$bifore,//这里的status是之前的值
  1938. "action_remark" => '',//备注
  1939. "action_type" => "edit"//新建create,编辑edit,更改状态status
  1940. ], "SPSX", $platform['exam_status'],$platform);
  1941. ProcessOrder::AddProcess(['id'=>$createrid,'nickname'=>$creater], [
  1942. "order_type" => 'SPSX',
  1943. "order_code" =>$platform['skuCode'],//咨询单详情编号
  1944. "order_id" => $platform['id'],
  1945. "order_status" => $platform['exam_status'],
  1946. "before_status"=>$bifore,
  1947. 'holder_id' => $platform['createrid'],
  1948. ]);
  1949. $data=[
  1950. "code"=>$platform['skuCode'],
  1951. "type"=>2,
  1952. "exam_status"=>$platform['exam_status'],//$platform['exam_status'] ,
  1953. "exam_id"=>$createrid,
  1954. "exam_name"=>$creater,
  1955. "exam_remark"=>'',
  1956. "addtime"=>date("Y-m-d H:i:s")
  1957. ];
  1958. $inr=Db::name("good_exam")->insert($data);
  1959. //修改状态,添加待办
  1960. if($inr){
  1961. //将good_basic数据同步到good表
  1962. $good_basic = Db::name('good_basic')
  1963. ->where(['spuCode' => $platform['spuCode'], 'is_del' => 0])
  1964. ->find();
  1965. if (!empty($good_basic)) {
  1966. unset($good_basic['id']);
  1967. unset($good_basic['addtime']);
  1968. $good_basic['updatetime'] = date('Y-m-d H:i:s');
  1969. Db::name('good')
  1970. ->strict(false)
  1971. ->where(['spuCode' => $platform['spuCode'], 'is_del' => 0])
  1972. ->update($good_basic);
  1973. }
  1974. Db::commit();
  1975. return app_show(0,"审核成功");
  1976. }
  1977. }
  1978. Db::rollback();
  1979. return error_show(1004,"审核失败");
  1980. }catch (\Exception $e){
  1981. Db::rollback();
  1982. return error_show(1004,$e->getMessage());
  1983. }
  1984. }
  1985. public function copy(){
  1986. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1987. if($supcode==""){
  1988. return error_show(1004,"参数spuCode不能为空");
  1989. }
  1990. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1991. if($data==false){
  1992. return error_show(1004,"未找到商品数据");
  1993. }
  1994. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1995. if($token==''){
  1996. return error_show(105,"参数token不能为空");
  1997. }
  1998. $createrid= $this->uid;
  1999. $creater= $this->uname;
  2000. $nake = Db::name("good_nake")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  2001. $ladd=[];
  2002. $newCode =makeNo("SKU");
  2003. if($data['is_combind']==1){
  2004. $newCode =makeNo('SSU');
  2005. $combindList = (new GoodCombind())->where(["spuCode"=>$supcode,"is_del"=>0])->hidden(["id"])
  2006. ->select()->toArray();
  2007. if(!empty($combindList)){
  2008. foreach ($combindList as &$item){
  2009. $item['spuCode']=$newCode;
  2010. $item['good_name']=$data['good_name'];
  2011. }
  2012. }
  2013. }
  2014. if(!empty($nake)){
  2015. foreach ($nake as $value){
  2016. $tmp=[];
  2017. $tmp['spuCode']=$newCode;
  2018. $tmp['min_num']=$value['min_num'];
  2019. $tmp['nake_fee'] = $value['nake_fee'];
  2020. $tmp['cost_fee'] = $value['cost_fee'];
  2021. $tmp['delivery_fee'] = $value['delivery_fee'];
  2022. $tmp['cert_fee'] = $value['cert_fee'];
  2023. $tmp['mark_fee'] = $value['mark_fee'];
  2024. $tmp['package_fee'] = $value['package_fee'];
  2025. $tmp['other_fee'] = $value['other_fee'];
  2026. $tmp['nake_total'] =$value['nake_total'];
  2027. $tmp['creater_id']=$createrid;
  2028. $tmp['creater']=$creater;
  2029. $tmp['is_del']=$value['is_del'];
  2030. $tmp['addtime']=date("Y-m-d H:i:s");
  2031. $tmp['updatetime']=date("Y-m-d H:i:s");
  2032. $ladd[]=$tmp;
  2033. }
  2034. }
  2035. $spec = Db::name("good_spec")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  2036. $specArr=[];
  2037. if(!empty($spec)){
  2038. foreach ($spec as $value){
  2039. $tmp=[];
  2040. $tmp['spuCode']=$newCode;
  2041. $tmp['spec_id']=$value['spec_id'];
  2042. $tmp['spec_value_id']=$value['spec_value_id'];
  2043. $tmp['is_del']=$value['is_del'];
  2044. $tmp['addtime']=date("Y-m-d H:i:s");
  2045. $tmp['updatetime']=date("Y-m-d H:i:s");
  2046. $specArr[]=$tmp;
  2047. }
  2048. }
  2049. Db::startTrans();
  2050. try {
  2051. unset($data['id']);
  2052. $data['spuCode']=$newCode;
  2053. $data['createrid']=$createrid;
  2054. $data['creater']=$creater;
  2055. $data['status']=7;
  2056. $data['addtime']=date("Y-m-d H:i:s");
  2057. $data['updatetime']=date("Y-m-d H:i:s");
  2058. $cre = Db::name("good_basic")->insertGetId($data);
  2059. if($cre){
  2060. //修改状态,添加待办
  2061. ActionLog::logAdd($this->post['token'], [
  2062. "order_code" =>$newCode,//咨询单详情编号
  2063. "status" => 0,//这里的status是之前的值
  2064. "action_remark" => '',//备注
  2065. "action_type" => "create"//新建create,编辑edit,更改状态status
  2066. ], "SPCB", 7,$data);
  2067. ProcessOrder::AddProcess($this->post['token'], [
  2068. "order_type" => 'SPCB',
  2069. "order_code" =>$newCode,//咨询单详情编号
  2070. "order_id" => $cre,
  2071. "order_status" =>7,
  2072. "before_status"=>0,
  2073. 'holder_id'=>$data['createrid'],
  2074. ]);
  2075. if(!empty($ladd)){
  2076. $na = Db::name("good_nake")->insertAll($ladd);
  2077. if($na==0){
  2078. throw new \Exception('成本数据复制失败');
  2079. }
  2080. }
  2081. if(!empty($specArr)){
  2082. $sp = Db::name("good_spec")->insertAll($specArr);
  2083. if($sp==0){
  2084. throw new \Exception('规格数据复制失败');
  2085. }
  2086. }
  2087. if(!empty($combindList)){
  2088. $in =(new GoodCombind())->saveAll($combindList);
  2089. if($in->isEmpty()){
  2090. throw new \Exception("组合商子商品品信息复制失败");
  2091. }
  2092. }
  2093. Db::commit();
  2094. return app_show(0,"复制数据成功",["spuCode"=>$newCode]);
  2095. }else{
  2096. throw new \Exception('数据复制失败');
  2097. }
  2098. }catch (\Exception $e){
  2099. Db::rollback();
  2100. return error_show(1004,$e->getMessage());
  2101. }
  2102. }
  2103. public function edit(){
  2104. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  2105. if($supcode==""){
  2106. return error_show(1004,"参数spuCode不能为空");
  2107. }
  2108. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  2109. if($data==false){
  2110. return error_show(1004,"未找到商品数据");
  2111. }
  2112. $is_down = Db::name("good_platform")
  2113. ->where(["spuCode"=>$supcode,"is_del"=>0])
  2114. ->where("exam_status", "not in", [1, 5])//exam_status=1待完善成本,8已下线,除了这两个状态外其他状态都不允许编辑
  2115. ->find();
  2116. if($is_down!=false){
  2117. return error_show(1004,"存在未下线商品数据");
  2118. }
  2119. if ($data['status'] != 6 && $data['status'] != 7 && $data['status'] != 8) {
  2120. return error_show(1004,"商品状态有误");
  2121. }
  2122. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):"";
  2123. if($good_name==""){
  2124. return error_show(1004,"商品名称不能为空");
  2125. }
  2126. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):"";
  2127. if($cat_id==''){
  2128. return error_show(1004,"商品分类不能为空");
  2129. }
  2130. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"0";
  2131. // if($brandid==''){
  2132. // return error_show(1004,"商品品牌不能为空");
  2133. // }
  2134. $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):"";
  2135. if($unit==''){
  2136. return error_show(1004,"商品单位不能为空");
  2137. }
  2138. $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type']) :"";
  2139. if($good_type===''){
  2140. return error_show(1004,"参数good_type不能为空");
  2141. }
  2142. $moq=0;
  2143. $customized=0;
  2144. if($good_type==1){
  2145. $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):"";
  2146. if($moq===''){
  2147. return error_show(1004,"定制商品起订量不能为空");
  2148. }
  2149. $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  2150. if($customized===''){
  2151. return error_show(1004,"参数customized不能为空");
  2152. }
  2153. }
  2154. $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):"";
  2155. if($is_exclusive===''){
  2156. return error_show(1004,"参数is_exclusive不能为空");
  2157. }
  2158. // $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  2159. // if($customized===''){
  2160. // return error_show(1004,"参数customized不能为空");
  2161. // }
  2162. $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):"";
  2163. if($tax===''){
  2164. return error_show(1004,"参数tax不能为空");
  2165. }
  2166. $company_id = isset($this->post['companyNo'])&&$this->post['companyNo']!=''? trim($this->post['companyNo']) :'';
  2167. if($company_id==''){
  2168. return error_show(1004,'参数companyNo不能为空');
  2169. }
  2170. $userCommon= \app\admin\common\User::getIns();
  2171. $companyinfo =$userCommon->handle('getCodeAndName',['code'=>$company_id]);
  2172. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  2173. $isCombind= $data['is_combind'];
  2174. $supplierArr=[];
  2175. $supplier=[];
  2176. if($supplierNo==''){
  2177. return error_show(1004,"参数supplierNo不能为空");
  2178. }
  2179. if (($this->level == 2) && ($supplierNo != $data['supplierNo'])) {
  2180. $supplier_account = checkHasAccountBySupplierNos([$supplierNo]);
  2181. if (isset($supplier_account[$supplierNo])) return json_show(1004, '该供应商已开通账号,不允许操作');
  2182. if (isset($supplier_account[$data['supplierNo']])) return json_show(1004, '原供应商已开通账号,不允许操作');
  2183. }
  2184. $supplier_temp =$userCommon->handle('hqInfo',['code'=>$supplierNo]);
  2185. if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1004,'供应商信息未找到');
  2186. $supplierArr=$supplier_temp['data']??[];
  2187. $supplier=$supplierArr['child']??[];
  2188. if($supplierArr['relation_code']==$company_id){
  2189. return error_show(1004,'业务公司与供应商属于同一家公司');
  2190. }
  2191. $cgd_supplier_code = isset($this->post['cgd_supplier_code'])&&$this->post['cgd_supplier_code']!=''? trim($this->post['cgd_supplier_code']):'';
  2192. $cgd_apply_id = isset($this->post['cgd_apply_id'])&&$this->post['cgd_apply_id']!=''? trim($this->post['cgd_apply_id']):'';
  2193. $cgd_apply_name = isset($this->post['cgd_apply_name'])&&$this->post['cgd_apply_name']!=''? trim($this->post['cgd_apply_name']):'';
  2194. $cgd_supplier_name='';
  2195. if(isset($supplierArr['relation_code']) && $supplierArr['relation_code']!=''){
  2196. if($cgd_supplier_code=='')return error_show(1004,'采购供应商信息不能为空');
  2197. if($cgd_apply_id=='')return error_show(1004,'采购竞单人信息不能为空');
  2198. $cgd_supplier =$userCommon->handle('getCodeAndName',['code'=>$cgd_supplier_code]);
  2199. $cgd_supplier_name= $cgd_supplier['data'][$cgd_supplier_code]??'';
  2200. }
  2201. $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size']) :"";
  2202. if($good_size==''){
  2203. return error_show(1004,"参数good_size不能为空");
  2204. }
  2205. $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):"";
  2206. if($is_auth===''){
  2207. return error_show(1004,"参数is_auth不能为空");
  2208. }
  2209. $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):"";
  2210. // if($auth_img==''){
  2211. // return error_show(1004,"商品不能为空");
  2212. // }
  2213. $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):"";
  2214. if($after_sales==""){
  2215. return error_show(1004,"参数after_sales不能为空");
  2216. }
  2217. $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):"";
  2218. $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):"";
  2219. if($good_remark===""){
  2220. return error_show(1004,"参数good_remark不能为空");
  2221. }
  2222. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  2223. if($weight===""){
  2224. return error_show(1004,"参数weight不能为空");
  2225. }
  2226. $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):"";
  2227. if($packing_way===""){
  2228. return error_show(1004,"参数packing_way不能为空");
  2229. }
  2230. $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):"";
  2231. if($packing_size===""){
  2232. return error_show(1004,"参数packing_size不能为空");
  2233. }
  2234. $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):"";
  2235. if($packing_spec===""){
  2236. return error_show(1004,"参数packing_spec不能为空");
  2237. }
  2238. $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):"";
  2239. if($packing_weight===""){
  2240. return error_show(1004,"参数packing_weight不能为空");
  2241. }
  2242. $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):"";
  2243. if($packing_list===""){
  2244. return error_show(1004,"参数packing_list不能为空");
  2245. }
  2246. $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):"";
  2247. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  2248. if($supply_area===""){
  2249. return error_show(1004,"参数supply_area不能为空");
  2250. }
  2251. $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? $this->post['delivery_place']:"";
  2252. if($delivery_place===""){
  2253. return error_show(1004,"参数delivery_place不能为空");
  2254. }
  2255. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? $this->post['origin_place']:"";
  2256. if($origin_place===""){
  2257. return error_show(1004,"参数origin_place不能为空");
  2258. }
  2259. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):"";
  2260. if($delivery_day===""){
  2261. return error_show(1004,"参数delivery_day不能为空");
  2262. }
  2263. $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time']) :"0";
  2264. $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0";
  2265. $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0";
  2266. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  2267. if($good_img===""){
  2268. return error_show(1004,"参数good_img不能为空");
  2269. }
  2270. $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):"";
  2271. if($good_thumb_img===""){
  2272. return error_show(1004,"参数good_thumb_img不能为空");
  2273. }
  2274. $good_info_img = isset($this->post['good_info_img'])&&!empty($this->post['good_info_img'])? trim($this->post['good_info_img']):"";
  2275. if($good_info_img===""){
  2276. return error_show(1004,"参数good_info_img不能为空");
  2277. }
  2278. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  2279. $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0";
  2280. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  2281. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  2282. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  2283. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  2284. $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0";
  2285. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  2286. $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0";
  2287. $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):"";
  2288. $cgd_gold_price = isset($this->post['cgd_gold_price'])&&$this->post['cgd_gold_price']!==""? floatval($this->post['cgd_gold_price']):"0";
  2289. if($market_price===""){
  2290. return error_show(1004,"参数market_price不能为空");
  2291. }
  2292. $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"0";
  2293. $config = isset($this->post['config'])&&$this->post['config']!==""? trim($this->post['config']):"";
  2294. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!==""? trim($this->post['other_config']):"";
  2295. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"0";
  2296. $is_stock = isset($this->post['is_stock'])&&$this->post['is_stock']!==""? intval($this->post['is_stock']):"0";
  2297. $stock_moq = isset($this->post['stock_moq'])&&$this->post['stock_moq']!==""? intval($this->post['stock_moq']):"0";
  2298. if($is_stock==1 && $stock_moq ==0){
  2299. return error_show(1004,"库存品备库起订量不能为零");
  2300. }
  2301. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
  2302. $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:"";
  2303. $is_support_barter = isset($this->post['is_support_barter']) && $this->post['is_support_barter'] !== "" ? intval($this->post['is_support_barter']) : 1;
  2304. $proof_type = isset($this->post['proof_type'])&&$this->post['proof_type']!=""? trim($this->post['proof_type']):"";
  2305. $proof_url = isset($this->post['proof_url'])&&$this->post['proof_url']!=""? trim($this->post['proof_url']):"";
  2306. $combindList = $this->post['combind_list']??[];
  2307. if($isCombind==1){
  2308. if(empty($combindList)) return error_show(1004,'组合商品子商品信息不能为空');
  2309. $dchild=[];
  2310. $valid = Validate::rule(['childCode|子商品成本编号'=>'require','child_name|子商品名称'=>'require','child_num|组合比例'=>'require|number|gt:0']);
  2311. foreach ($combindList as $value){
  2312. if($valid->check($value)==false)return error_show(1004,$valid->getError());
  2313. $value['spuCode'] = $data['spuCode'];
  2314. $value['good_name'] =$good_name;
  2315. $value['updatetime'] =date('Y-m-d H:i:s');
  2316. if($value['is_del']==1){
  2317. $usable_stock = Db::name('good')->where(['spuCode'=>$data['spuCode']])->value('usable_stock',0);
  2318. if($usable_stock>0) return error_show(1004,'组合商品库存未处理完不可删除子商品');
  2319. }
  2320. $dchild[]=$value;
  2321. }
  2322. }
  2323. Db::startTrans();
  2324. try {
  2325. $temp=[
  2326. "good_name"=>$good_name,
  2327. "cat_id"=>$cat_id,
  2328. 'brand_id'=>$brandid,
  2329. "good_unit"=>$unit,
  2330. "good_type"=>$good_type,
  2331. "companyNo"=>$company_id,
  2332. "companyName"=>$companyinfo['data'][$company_id]??"",
  2333. "moq"=>$moq,
  2334. "is_exclusive"=>$is_exclusive,
  2335. "customized"=>$customized,
  2336. "tax"=>$tax,
  2337. "supplierNo"=>$supplierNo,
  2338. "supplierName"=>$supplierArr['name']??"",
  2339. "is_auth"=>$is_auth,
  2340. "good_size"=>$good_size,
  2341. "auth_img"=>$auth_img,
  2342. "after_sales"=>$after_sales,
  2343. "craft_desc"=>$craft_desc,
  2344. "good_remark"=>$good_remark,
  2345. "weight"=>$weight,
  2346. "packing_way"=>$packing_way,
  2347. "packing_size"=>$packing_size,
  2348. "packing_spec"=>$packing_spec,
  2349. "packing_list"=>$packing_list,
  2350. "packing_weight"=>$packing_weight,
  2351. "good_bar"=>$good_bar,
  2352. "supply_area"=>$supply_area,
  2353. "delivery_place"=>$delivery_place,
  2354. "origin_place"=>$origin_place,
  2355. "delivery_day"=>$delivery_day,
  2356. "lead_time"=>$lead_time,
  2357. "sample_day"=>$sample_day,
  2358. "sample_fee"=>$sample_fee,
  2359. "good_img"=>$good_img,
  2360. "good_thumb_img"=>$good_thumb_img,
  2361. "good_info_img"=>$good_info_img,
  2362. "cert_fee"=>$cert_fee,
  2363. "packing_fee"=>$packing_fee,
  2364. "is_diff"=>$is_diff,
  2365. "config"=>$config,
  2366. "other_config"=>$other_config,
  2367. "is_stock"=>$is_stock,
  2368. "cost_fee"=>$cost_fee,
  2369. "mark_fee"=>$mark_fee,
  2370. "demo_fee"=>$demo_fee,
  2371. "open_fee"=>$open_fee,
  2372. "noble_metal"=>$noble_metal,
  2373. "noble_weight"=>$noble_weight,
  2374. "is_gold_price"=>$is_gold_price,
  2375. "market_price"=>$market_price,
  2376. "nake_price"=>$nake_price,
  2377. "cgd_gold_price"=>$cgd_gold_price,
  2378. "is_step" => count($good_ladder) > 1 ? 1 : 0,
  2379. "stock_moq"=>$stock_moq,
  2380. "status"=>"0",
  2381. 'is_combind'=>$isCombind,
  2382. "updatetime"=>date("Y-m-d H:i:s"),
  2383. 'is_support_barter'=>$is_support_barter,
  2384. 'chargerid' => $supplier['personid'] ?? $this->uid,
  2385. 'charger' => $supplier['person'] ?? $this->uname,
  2386. 'cgd_supplier_code'=>$cgd_supplier_code,//采购供应商编号
  2387. 'cgd_supplier_name'=>$cgd_supplier_name,//采购供应商编号
  2388. 'cgd_apply_id'=>$cgd_apply_id,//竞单人
  2389. 'cgd_apply_name'=>$cgd_apply_name,//竞单人
  2390. ];
  2391. $field = array_diff_assoc($temp,$data);
  2392. $temp['field_change'] =empty($field)?"":json_encode(array_keys($field));
  2393. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($temp);
  2394. $var = array_diff($temp,$data);
  2395. $json = json_encode($var,JSON_UNESCAPED_UNICODE);
  2396. $dat = json_encode($data,JSON_UNESCAPED_UNICODE);
  2397. if($up){
  2398. $this->BasicToGood($supcode,$temp);
  2399. ChangeLog::logAdd(3,$data['spuCode'],$dat,$json,['id' => $this->uid, 'nickname' => $this->uname]);
  2400. if($speclist!=="" && !empty($speclist)){
  2401. foreach ($speclist as $value){
  2402. $lemp=[];
  2403. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  2404. $lemp['spuCode']=$supcode;
  2405. $lemp['spec_id'] = $value['spec_id'];
  2406. $lemp['spec_value_id'] = $value['spec_value_id'];
  2407. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  2408. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  2409. $lemp['updatetime'] =date("Y-m-d H:i:s");
  2410. $count = Db::name("good_spec")->save($lemp);
  2411. if($count==false){
  2412. Db::rollback();
  2413. return app_show(1004,"商品规格值修改失败");
  2414. }
  2415. }
  2416. }
  2417. if($proof_url!=''){
  2418. $proof=[
  2419. 'spuCode'=>$supcode,
  2420. 'proof_type'=>$proof_type,
  2421. 'proof_url'=>$proof_url,
  2422. 'is_del'=>0,
  2423. "creater"=>$this->uname,
  2424. "createrid"=>$this->uid,
  2425. "addtime"=>date("Y-m-d H:i:s"),
  2426. "updatetime"=>date("Y-m-d H:i:s")
  2427. ];
  2428. $inproof = Db::name("good_proof")->insert($proof);
  2429. if($inproof==false)throw new \Exception("商品凭证新建失败");
  2430. }
  2431. if($good_ladder!=="" && !empty($good_ladder)){
  2432. // $user =GetUserInfo($this->post['token']);//获取用户信息,下面更新成本表的创建人
  2433. $top_cat_id = made($cat_id);//获取所有分类
  2434. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  2435. foreach ($good_ladder as $value){
  2436. $lemp=[];
  2437. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  2438. $lemp['spuCode']=$supcode;
  2439. $lemp['min_num'] = $value['min_num'];
  2440. $lemp['nake_fee'] = $value['nake_fee'];
  2441. $lemp['cost_fee'] = $value['cost_fee'];
  2442. $lemp['delivery_fee'] = $value['delivery_fee'];
  2443. $lemp['cert_fee'] = $value['cert_fee'];
  2444. $lemp['mark_fee'] = $value['mark_fee'];
  2445. $lemp['package_fee'] = $value['package_fee'];
  2446. $lemp['other_fee'] = $value['other_fee'];
  2447. $lemp['supplier_origin_price'] = $value['supplier_origin_price'];
  2448. if ($is_gold_price == 1 && $top_cat_id == 6) {
  2449. $gold =Db::name("gold_price1")->where(["type"=>$noble_metal,"status"=>1,"is_del"=>0])->order("addtime desc")->find();
  2450. //$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'];
  2451. //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用
  2452. //成本总计启用实时金价时,采用供应商实时金价
  2453. $lemp['nake_total'] =$noble_weight *$gold['price']+ $value['cost_fee'] * $noble_weight +
  2454. $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
  2455. }else{
  2456. $lemp['nake_total'] =$value['nake_fee']+$value['delivery_fee']+$value['cert_fee']+$value['mark_fee']+$value['package_fee']+$value['other_fee'];
  2457. }
  2458. $lemp['creater_id'] = $this->uid;
  2459. $lemp['creater'] = $this->uname;
  2460. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  2461. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  2462. $lemp['updatetime'] =date("Y-m-d H:i:s");
  2463. $count = Db::name("good_nake")->save($lemp);
  2464. if($count==false){
  2465. Db::rollback();
  2466. return app_show(1004,"商品规成本修改失败");
  2467. }
  2468. }
  2469. }
  2470. if($isCombind==1 && !empty($dchild)){
  2471. (new GoodCombind())->saveAll($dchild);
  2472. }
  2473. Db::commit();
  2474. return app_show(0,"更新成功");
  2475. }else{
  2476. Db::rollback();
  2477. return error_show(1005,"更新失败");
  2478. }
  2479. }catch (\Exception $e){
  2480. Db::rollback();
  2481. return error_show(1004,$e->getMessage());
  2482. }
  2483. }
  2484. public function checkPrice(){
  2485. $param = $this->request->only(['spuCode', 'min_num', 'platform_id', 'relaComNo',"is_fixed"], 'post', 'trim');
  2486. $val = Validate::rule([
  2487. 'spuCode|商品成本编码' => 'require',
  2488. 'min_num|起订量' => 'require|number|gt:0',
  2489. 'platform_id|上线平台ID' => 'require|number|gt:0',
  2490. 'is_fixed|定价模式' => 'require|number|in:0,1',
  2491. 'relaComNo'=>'require'
  2492. ]);
  2493. if($val->check($param) == false) return json_show(1005,$val->getError());
  2494. $good =Db::name("good_basic")
  2495. ->field('id,is_stock,cat_id,is_gold_price,noble_weight,cgd_gold_price')
  2496. ->where(["spuCode"=>$param['spuCode'],"is_del"=>0])
  2497. ->findOrEmpty();
  2498. if(empty($good)) return json_show(1005,"商品数据未找到");
  2499. $nakelist = Db::name("good_nake")
  2500. ->where(['spuCode'=>$param['spuCode'],"is_del"=>0])
  2501. ->where([["min_num","<=",$param['min_num']]])
  2502. ->order("min_num desc")
  2503. ->find();
  2504. if($nakelist==false){
  2505. $nakelist = Db::name("good_nake")
  2506. ->where(['spuCode'=>$param['spuCode'],"is_del"=>0])
  2507. ->order("min_num asc")
  2508. ->find();
  2509. //非库存品的话,继续校验最小起订量
  2510. //库存品的话,不足采购起订量的时候,取采购最小起订量
  2511. if ($good['is_stock'] == 0) return error_show(1010, "起订量不足{$nakelist['min_num']}");
  2512. }
  2513. //计算毛利率
  2514. $budget = get_budget($good['cat_id'],$param['relaComNo'],$param['platform_id']);
  2515. $top_cat_id = made($good['cat_id']);//获取所有分类
  2516. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  2517. $sale_cost_fee = 0;
  2518. if ($good['is_gold_price'] == 1 && $top_cat_id == 6) {
  2519. // $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'];
  2520. if($param['is_fixed']==0) $nakelist['nake_fee']=0;
  2521. //系统售价=(贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用)/(1-成本售价/100)
  2522. $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);
  2523. //计算工艺费
  2524. //销售工艺费=(( 商品重量* 供应商采购金价 + 采购成本工艺费* 商品重量+包装费+加标费+证书费+产品裸价+其他费用)/(1-成本售价/100)-(包装费+加标费+证书费+产品裸价0+运费+其他费用) )/商品重量-供应商采购金价
  2525. $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"];
  2526. }else{
  2527. // $saleprice = ($nakelist['mark_fee'] + $nakelist['package_fee'] + $nakelist['cert_fee'] + $nakelist['delivery_fee'] + $nakelist['nake_fee']) / (1 - $budget);
  2528. // (加标费+包装费+证书费+成本裸价+运费)/(1-成本售价/100)=系统售价
  2529. // $saleprice = (加标费 + 包装费 + 证书费 + 运费 + 成本裸价+其他费用) / (1 - $budget);
  2530. $saleprice = $nakelist['nake_total'] / (1 - $budget);
  2531. }
  2532. return app_show(0, "获取成功", ["sale_price" => round($saleprice, 2), 'new_cost_fee' => round($sale_cost_fee, 2)]);
  2533. }
  2534. //咨询成交商品池 添加上线商品
  2535. public function onlineZixunGoods()
  2536. {
  2537. $param = $this->request->only([
  2538. 'platform',
  2539. "is_fixed",
  2540. 'goodinfo',
  2541. 'online_reason',
  2542. 'online_remark',
  2543. 'token'], 'post', 'trim');
  2544. $val = Validate::rule([
  2545. 'platform|所选上线平台' => 'require|number|gt:0',
  2546. 'goodinfo|所选上线商品编号' => 'require|array',
  2547. 'is_fixed|是否一口价' => 'require|number|in:0,1',
  2548. 'online_reason|上线原因' => 'require',
  2549. 'online_remark|上线备注' => 'require',
  2550. 'token' => 'require',
  2551. ]);
  2552. if (!$val->check($param)) return error_show(1004, $val->getError());
  2553. $codes= array_column($param['goodinfo'],"spuCode");
  2554. $good_zixun_list = Db::name("good_zixun")
  2555. ->where(["is_del" => 0])
  2556. ->whereIn('spuCode',$codes)
  2557. ->column('*', 'spuCode');
  2558. if (empty($good_zixun_list)) return error_show(1004, "未找到相关咨询商品数据");
  2559. $a = array_diff($codes, array_keys($good_zixun_list));
  2560. if (!empty($a)) return error_show(1005, '该咨询商品不存在' . implode(',', $a));
  2561. $isonline = Db::name("good_platform")
  2562. ->alias('gp')
  2563. ->field('gp.id,gp.spuCode,gb.good_name,gb.good_img,gp.exam_status')
  2564. ->where(["gp.platform_code" => $param['platform'], "gp.is_del" => 0])
  2565. ->whereIn('gp.spuCode', $codes)
  2566. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  2567. ->select()
  2568. ->toArray();
  2569. if (!empty($isonline)) {
  2570. foreach ($isonline as &$v) {
  2571. $spec = Db::name("good_spec")
  2572. ->where(["spuCode" => $v['spuCode'], "is_del" => 0])
  2573. ->select()
  2574. ->toArray();
  2575. $speclist = [];
  2576. if (!empty($spec)) {
  2577. foreach ($spec as $val) {
  2578. $temp = [];
  2579. $temp['id'] = $val['id'];
  2580. $temp['spuCode'] = $val['spuCode'];
  2581. $temp['spec_id'] = $val['spec_id'];
  2582. $temp['spec_value_id'] = $val['spec_value_id'];
  2583. $temp['is_del'] = $val['is_del'];
  2584. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  2585. $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  2586. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  2587. $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  2588. $speclist[] = $temp;
  2589. }
  2590. }
  2591. $v["speclist"] = empty($speclist) ? [] : $speclist;
  2592. }
  2593. return app_show(1009, "存在已上线产品", $isonline);
  2594. }
  2595. if (!empty($isonline)) return error_show(1005, $isonline['spuCode'] . '该商品已在商品成本管理中,请在商品成本管理菜单提交上线!');
  2596. $user = GetUserInfo($param['token']);
  2597. if (empty($user) || $user['code'] != 0) return error_show(1002, "用户数据不存在");
  2598. $createrid = isset($user["data"]['id']) ? $user["data"]['id'] : "";
  2599. $creater = isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  2600. $data = $good_insert_data = $good_basic_insert_data = $good_spec_insert_data = [];
  2601. $i = 0;
  2602. $all_nakes = Db::name("good_nake")
  2603. ->where(["is_del" => 0])->fetchSql()
  2604. ->whereIn('spuCode',$codes)
  2605. ->group('spuCode')
  2606. ->column('count(`id`) total', 'spuCode');
  2607. $all_good = Db::name('good')
  2608. ->where('is_del', 0)
  2609. ->whereIn('spuCode', $codes)
  2610. ->column('id', 'spuCode');
  2611. if (!empty($all_good)) return error_show(1004, '请从商品成本提交该商品上线');
  2612. $all_good_basic = Db::name('good_basic')
  2613. ->where('is_del', 0)
  2614. ->whereIn('spuCode', $codes)
  2615. ->column('id', 'spuCode');
  2616. if (!empty($all_good_basic)) return error_show(1004, '请从商品成本提交该商品上线');
  2617. foreach ($param['goodinfo'] as $value) {
  2618. // if($good_zixun_list[$value['spuCode']]['is_gold_price']==1&&$param['is_fixed']==1){
  2619. // return error_show(1004," {$good_zixun_list[$value['spuCode']]['good_name']}商品使用实时金价,不可使用一口价!");
  2620. // }
  2621. $bd=[];
  2622. if($good_zixun_list[$value['spuCode']]['order_source']==2 ||$good_zixun_list[$value['spuCode']]['order_source']==3){
  2623. $bd = Db::name('consult_bids')->where(['spuCode'=> $value['spuCode']])->findOrEmpty();
  2624. }
  2625. //改变编码规则,将原来的skuCode后两位换成序列号
  2626. //str_pad字符串填充
  2627. $skuCode = makeNo("SN");
  2628. $skuCode = substr($skuCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
  2629. $data[] = [
  2630. "spuCode" => $value['spuCode'],
  2631. "skuCode" => $skuCode,
  2632. "platform_code" => $param['platform'],
  2633. "online_reason" => $param['online_reason'],
  2634. "online_remark" => $param['online_remark'],
  2635. "exam_status" => isset($all_nakes[$value]) ? ($all_nakes[$value] > 0 ? 2 : 1) : 1,
  2636. "is_online" => 0,
  2637. "market_url" =>$value['market_url'],
  2638. "is_fixed" =>$param['is_fixed'],
  2639. "status" => 0,
  2640. "is_del" => 0,
  2641. "creater" => $creater,
  2642. "createrid" => $createrid,
  2643. "addtime" => date("Y-m-d H:i:s"),
  2644. "updatetime" => date("Y-m-d H:i:s")
  2645. ];
  2646. //good表
  2647. if (!isset($all_good[$value['spuCode']])) {
  2648. $good_insert_data[] = [
  2649. 'spuCode' => $good_zixun_list[$value['spuCode']]['spuCode'],
  2650. 'good_code' => $good_zixun_list[$value['spuCode']]['good_code'],
  2651. 'good_name' => $good_zixun_list[$value['spuCode']]['good_name'],
  2652. 'cat_id' => $good_zixun_list[$value['spuCode']]['cat_id'],
  2653. 'brand_id' => $good_zixun_list[$value['spuCode']]['brand_id'],
  2654. 'good_unit' => $good_zixun_list[$value['spuCode']]['good_unit'],
  2655. 'good_type' => $good_zixun_list[$value['spuCode']]['good_type'],
  2656. 'companyNo' => $good_zixun_list[$value['spuCode']]['companyNo'],
  2657. 'companyName' => $good_zixun_list[$value['spuCode']]['companyName'],
  2658. 'moq' => $good_zixun_list[$value['spuCode']]['moq'],
  2659. 'customized' => $good_zixun_list[$value['spuCode']]['customized'],
  2660. 'tax' => $good_zixun_list[$value['spuCode']]['tax'],
  2661. 'supplierNo' => $good_zixun_list[$value['spuCode']]['supplierNo'],
  2662. 'supplierName' => $good_zixun_list[$value['spuCode']]['supplierName'],
  2663. 'is_auth' => $good_zixun_list[$value['spuCode']]['is_auth'],
  2664. 'is_stock' => '',
  2665. 'auth_img' => $good_zixun_list[$value['spuCode']]['auth_img'],
  2666. 'after_sales' => '',
  2667. 'craft_desc' => $good_zixun_list[$value['spuCode']]['craft_desc'],
  2668. 'good_remark' => $good_zixun_list[$value['spuCode']]['good_remark'],
  2669. 'good_size' => '',
  2670. 'weight' => $good_zixun_list[$value['spuCode']]['weight'],
  2671. 'packing_way' => '',
  2672. 'packing_size' => '',
  2673. 'packing_spec' => '',
  2674. 'packing_list' => '',
  2675. 'packing_weight' => '',
  2676. 'good_bar' => '',
  2677. 'supply_area' => $good_zixun_list[$value['spuCode']]['supply_area'],
  2678. 'delivery_place' =>$bd['delivery_place']??"",
  2679. 'origin_place' =>$bd['origin_place']??'',
  2680. 'delivery_day' => $bd['delivery_day']??'',
  2681. 'lead_time' => '',
  2682. 'sample_day' => '',
  2683. 'sample_fee' => '',
  2684. 'good_img' => $good_zixun_list[$value['spuCode']]['good_img'],
  2685. 'good_thumb_img' => $good_zixun_list[$value['spuCode']]['good_thumb_img'],
  2686. 'good_info_img' => $good_zixun_list[$value['spuCode']]['good_info_img'],
  2687. 'cert_fee' => '',
  2688. 'packing_fee' => '',
  2689. 'cost_fee' => '',
  2690. 'mark_fee' => '',
  2691. 'demo_fee' => '',
  2692. 'open_fee' => '',
  2693. 'noble_metal' => $good_zixun_list[$value['spuCode']]['noble_metal'],
  2694. 'noble_weight' => $good_zixun_list[$value['spuCode']]['good_weight'],
  2695. 'is_gold_price' => $good_zixun_list[$value['spuCode']]['is_gold_price'],
  2696. 'cgd_gold_price' => '',
  2697. 'market_price' => '',
  2698. 'nake_price' => '',
  2699. 'is_step' => '',
  2700. 'is_online' => '',
  2701. 'status' => 1,//待完善成本
  2702. 'createrid' => $createrid,
  2703. 'creater' => $creater,
  2704. 'create_source' => 1,
  2705. 'is_del' => 0,
  2706. 'field_change' => '',
  2707. 'addtime' => date('Y-m-d H:i:s'),
  2708. 'updatetime' => date('Y-m-d H:i:s'),
  2709. 'is_exclusive' => '',
  2710. 'is_diff' => $good_zixun_list[$value['spuCode']]['is_diff'],
  2711. 'config' => $good_zixun_list[$value['spuCode']]['config'],
  2712. 'other_config' => $good_zixun_list[$value['spuCode']]['other_config'],
  2713. ];
  2714. }
  2715. //good_basic表
  2716. if (!isset($all_good_basic[$value['spuCode']])) {
  2717. $good_basic_insert_data[] = [
  2718. 'spuCode' => $value['spuCode'],
  2719. 'good_code' => $good_zixun_list[$value['spuCode']]['good_code'],
  2720. 'good_name' => $good_zixun_list[$value['spuCode']]['good_name'],
  2721. 'cat_id' => $good_zixun_list[$value['spuCode']]['cat_id'],
  2722. 'brand_id' => $good_zixun_list[$value['spuCode']]['brand_id'],
  2723. 'companyNo' => $good_zixun_list[$value['spuCode']]['companyNo'],
  2724. 'companyName' => $good_zixun_list[$value['spuCode']]['companyName'],
  2725. 'good_unit' => $good_zixun_list[$value['spuCode']]['good_unit'],
  2726. 'good_type' => $good_zixun_list[$value['spuCode']]['good_type'],
  2727. 'moq' => $good_zixun_list[$value['spuCode']]['moq'],
  2728. 'customized' => $good_zixun_list[$value['spuCode']]['customized'],
  2729. 'tax' => $good_zixun_list[$value['spuCode']]['tax'],
  2730. 'supplierNo' => $good_zixun_list[$value['spuCode']]['supplierNo'],
  2731. 'supplierName' => $good_zixun_list[$value['spuCode']]['supplierName'],
  2732. 'is_auth' => $good_zixun_list[$value['spuCode']]['is_auth'],
  2733. 'auth_img' => $good_zixun_list[$value['spuCode']]['auth_img'],
  2734. 'after_sales' => '',
  2735. 'craft_desc' => $good_zixun_list[$value['spuCode']]['craft_desc'],
  2736. 'good_remark' => $good_zixun_list[$value['spuCode']]['good_remark'],
  2737. 'weight' => $good_zixun_list[$value['spuCode']]['weight'],
  2738. 'packing_way' => '',
  2739. 'packing_size' => '',
  2740. 'packing_spec' => '',
  2741. 'packing_list' => '',
  2742. 'packing_weight' => '',
  2743. 'good_bar' => '',
  2744. 'supply_area' => $good_zixun_list[$value['spuCode']]['supply_area'],
  2745. 'delivery_place' =>$bd['delivery_place']??'',
  2746. 'origin_place' =>$bd['origin_place']??'',
  2747. 'delivery_day' => $bd['delivery_day']??'',
  2748. 'lead_time' => '',
  2749. 'sample_day' => '',
  2750. 'sample_fee' => '',
  2751. 'good_img' => '',//$good_zixun_list[$value['spuCode']]['good_img'],
  2752. 'good_thumb_img' => $good_zixun_list[$value['spuCode']]['good_thumb_img'],
  2753. 'good_info_img' => $good_zixun_list[$value['spuCode']]['good_img'],//商品主图对应到商品详情
  2754. 'cert_fee' => '',
  2755. 'packing_fee' => '',
  2756. 'cost_fee' => '',
  2757. 'mark_fee' => '',
  2758. 'demo_fee' => '',
  2759. 'open_fee' => '',
  2760. 'noble_metal' => $good_zixun_list[$value['spuCode']]['noble_metal'],
  2761. 'noble_weight' => $good_zixun_list[$value['spuCode']]['good_weight'],
  2762. 'is_gold_price' => $good_zixun_list[$value['spuCode']]['is_gold_price'],
  2763. 'cgd_gold_price' => '',
  2764. 'market_price' => '',
  2765. 'nake_price' => '',
  2766. 'is_step' => '',
  2767. 'is_online' => '',
  2768. 'status' => 8,//咨询商品待编辑
  2769. 'createrid' => $createrid,
  2770. 'creater' => $creater,
  2771. 'create_source' => 1,
  2772. 'field_change' => '',
  2773. 'is_del' => 0,
  2774. 'addtime' => date('Y-m-d H:i:s'),
  2775. 'updatetime' => date('Y-m-d H:i:s'),
  2776. 'is_diff' => $good_zixun_list[$value['spuCode']]['is_diff'],
  2777. 'config' => $good_zixun_list[$value['spuCode']]['config'],
  2778. 'other_config' => $good_zixun_list[$value['spuCode']]['other_config'],
  2779. ];
  2780. }
  2781. //good_spec
  2782. if ($good_zixun_list[$value['spuCode']]['specinfo']!=='') {
  2783. $spec_list = json_decode($good_zixun_list[$value['spuCode']]['specinfo'], true);
  2784. foreach ($spec_list as $spec) {
  2785. $specid = $spec['specid']??($spec['spec_id']??"");
  2786. $temp = Db::name('good_spec')
  2787. ->field('id')
  2788. ->where(['spuCode' => $value['spuCode'], 'spec_id' => $specid, 'spec_value_id' => $spec['spec_value_id'], 'is_del' => 0])
  2789. ->findOrEmpty();
  2790. if (empty($temp)) {
  2791. $good_spec_insert_data[] = [
  2792. 'spuCode' => $value['spuCode'],
  2793. 'spec_id' => $specid,
  2794. 'spec_value_id' => $spec['spec_value_id'],
  2795. 'is_del' => 0,
  2796. 'addtime' => date('Y-m-d H:i:s'),
  2797. 'updatetime' => date('Y-m-d H:i:s'),
  2798. ];
  2799. }
  2800. }
  2801. }
  2802. $i++;
  2803. }
  2804. if (!empty($isonline)) {
  2805. return app_show(1009, "存在已上线产品", $isonline);
  2806. }
  2807. Db::startTrans();
  2808. try {
  2809. $create = Db::name("good_platform")->insertAll($data);
  2810. Db::name("good_zixun")
  2811. ->where(["is_del" => 0, 'status' => 1])
  2812. ->whereIn('spuCode', $codes)
  2813. ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]);
  2814. if (!empty($good_insert_data)) Db::name('good')->insertAll($good_insert_data);
  2815. if (!empty($good_basic_insert_data)) Db::name('good_basic')->insertAll($good_basic_insert_data);
  2816. if (!empty($good_spec_insert_data)) Db::name('good_spec')->insertAll($good_spec_insert_data);
  2817. if ($create) {
  2818. foreach ($good_basic_insert_data as $value) {
  2819. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  2820. "order_code" =>$value['spuCode'],//
  2821. "status" => 8,//待产品审核
  2822. "action_remark" => '',//备注
  2823. "action_type" => "create"//新建create,编辑edit,更改状态status
  2824. ], "SPCB", $value['status'], $value);
  2825. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  2826. "order_type" => 'SPCB',
  2827. "order_code" =>$value['spuCode'],//
  2828. "order_id" => isset($value['id']) ? $value['id'] : 0,
  2829. "order_status" => 8,//待产品审核
  2830. "before_status" => 0,//待产品审核
  2831. 'holder_id'=>$value['createrid'],
  2832. ]);
  2833. }
  2834. foreach ($data as $value) {
  2835. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  2836. "order_code" =>$value['skuCode'],//
  2837. "status" => 0,//待产品审核
  2838. "action_remark" => '',//备注
  2839. "action_type" => "create"//新建create,编辑edit,更改状态status
  2840. ], "SPSX", $value['exam_status'], $value);
  2841. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  2842. "order_type" => 'SPSX',
  2843. "order_code" =>$value['skuCode'],//
  2844. "order_id" => isset($value['id']) ? $value['id'] : 0,
  2845. "order_status" =>$value['exam_status'],//待产品审核
  2846. "before_status" => 0,
  2847. 'holder_id' => $value['createrid'],
  2848. ]);
  2849. }
  2850. Db::commit();
  2851. return app_show(0, "提交成功");
  2852. } else {
  2853. Db::rollback();
  2854. return error_show(1004, "提交失败");
  2855. }
  2856. } catch (Exception $exception) {
  2857. Db::rollback();
  2858. return error_show(1005, $exception->getMessage());
  2859. }
  2860. }
  2861. //商品上线审核流程时,驳回重新审核
  2862. public function rejectGoodToAgainExamine()
  2863. {
  2864. $param = $this->request->only(['token', 'skuCode', 'exam_remark' => ''], 'post', 'trim');
  2865. $val = Validate::rule(['token' => 'require', 'skuCode' => 'require']);
  2866. if (!$val->check($param)) return error_show(1005, $val->getError());
  2867. $user = GetUserInfo($param['token']);
  2868. $createrid = isset($user['data']['id']) ? $user['data']['id'] : 0;
  2869. $creater = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
  2870. Db::startTrans();
  2871. try {
  2872. $rs = Db::name("good_platform")
  2873. ->field('id,spuCode,skuCode,exam_status,createrid')
  2874. ->where(['skuCode' => $param['skuCode'], 'is_del' => 0])
  2875. ->where('exam_status', '<>', 3)//exam_status==6上线成功
  2876. ->find();
  2877. if (empty($rs)) throw new \Exception('该记录不存在');
  2878. $old_exam_staus = $rs['exam_status'];
  2879. $good_nake = Db::name("good_nake")
  2880. ->field('id')
  2881. ->where(["spuCode" => $rs['spuCode'], "is_del" => 0])
  2882. ->find();
  2883. $exam_status = empty($good_nake) ? 1 : 2;
  2884. if ($exam_status == $rs['exam_status']) $exam_status =4;//第一级审核失败时,状态改为'审核失败'
  2885. Db::name("good_platform")
  2886. ->where('id', $rs['id'])
  2887. ->save([
  2888. 'exam_status' => $exam_status,
  2889. 'updatetime' => date('Y-m-d H:i:s'),
  2890. ]);
  2891. Db::name("good_exam")->insert([
  2892. 'code' => $rs['skuCode'],
  2893. 'exam_status' => $old_exam_staus,
  2894. 'type' => 2,
  2895. 'exam_id' => $createrid,
  2896. 'exam_name' => $creater,
  2897. 'exam_remark' => $param['exam_remark'],
  2898. 'addtime' => date('Y-m-d H:i:s')
  2899. ]);
  2900. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  2901. "order_code" => $param['skuCode'],//编号
  2902. "status" => $rs['exam_status'],
  2903. "action_remark" => '',//备注
  2904. "action_type" => "status"//新建create,编辑edit,更改状态status
  2905. ], "SPSX", $exam_status, $param);
  2906. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  2907. "order_type" => 'SPSX',
  2908. "order_code" => $param['skuCode'],//咨询单详情编号
  2909. "order_id" => $rs['id'],
  2910. "order_status" => $exam_status,
  2911. "before_status" => $rs['exam_status'],
  2912. 'holder_id' => $rs['createrid'],
  2913. ]);
  2914. Db::commit();
  2915. return app_show(0, "驳回重新审核成功");
  2916. } catch (\Exception $e) {
  2917. Db::rollback();
  2918. return error_show(1004, '驳回重新审核失败,' . $e->getMessage());
  2919. }
  2920. }
  2921. //同一个spuCode下所有的商品都下线
  2922. public function offlineGoodBySpuCode()
  2923. {
  2924. $param = $this->request->only(['token', 'spuCode', 'offline_reason', 'offline_remark' => ''], 'post', 'trim');
  2925. $val = Validate::rule(['token' => 'require', 'spuCode' => 'require', 'offline_reason|下线原因' => 'require']);
  2926. if (!$val->check($param)) return error_show(1005, $val->getError());
  2927. $user = GetUserInfo($param['token']);
  2928. $createrid = isset($user['data']['id']) ? $user['data']['id'] : 0;
  2929. $creater = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
  2930. Db::startTrans();
  2931. try {
  2932. $good_name = Db::name("good_basic")
  2933. ->where(['is_del' => 0, 'spuCode' => $param['spuCode']])
  2934. ->value('good_name', '');
  2935. $skuCodeS = Db::name("good_platform")
  2936. ->where(['spuCode' => $param['spuCode'], 'is_del' => 0])//exam_status 7审核失败,8已下线
  2937. ->whereNotIn('exam_status', [4,5])
  2938. ->column('exam_status,skuCode', 'skuCode');
  2939. if ($skuCodeS) {
  2940. // if (empty($skuCodeS)) throw new \Exception('该商品未在任何平台申请上线');
  2941. //商品平台
  2942. Db::name("good_platform")
  2943. ->where(['spuCode' => $param['spuCode'], 'is_del' => 0])//exam_status 7审核失败,8已下线
  2944. ->whereNotIn('exam_status', [4,5])
  2945. ->save([
  2946. 'exam_status' => 5,
  2947. "is_compliance"=>0,
  2948. "compliance_remark"=>'',
  2949. 'updatetime' => date('Y-m-d H:i:s'),
  2950. ]);
  2951. //商品下线记录
  2952. $good_offline_log_id = Db::name("good_offline_log")->insertGetId([
  2953. 'spuCode' => $param['spuCode'],
  2954. 'skuCodes' => implode(',', array_keys($skuCodeS)),
  2955. 'good_name' => $good_name,
  2956. 'offline_reason' => $param['offline_reason'],
  2957. 'offline_remark' => $param['offline_remark'],
  2958. 'createrid' => $createrid,
  2959. 'creater' => $creater,
  2960. 'addtime' => date('Y-m-d H:i:s'),
  2961. ]);
  2962. //根据权限查询应该接收商品下线通知的人员
  2963. $all_uid_name = Db::name('role_action')
  2964. ->whereFindInSet('action_conllect', '877')//数据写死的,要注意各个环境数据是否一致
  2965. ->field('role_id')
  2966. ->buildSql();
  2967. $all_user = Db::name('user_role')
  2968. ->alias('ur')
  2969. ->where('ur.roleid IN ' . $all_uid_name)
  2970. ->leftJoin('depart_user du', 'du.uid = ur.uid AND du.is_del=0')
  2971. ->column('ur.uid,du.nickName');
  2972. $insert_good_exam_data = $insert_order_msg_data = [];
  2973. foreach ($skuCodeS as $skuCode => $value) {
  2974. $insert_good_exam_data[] = [
  2975. 'code' => $skuCode,
  2976. 'exam_status' =>5,
  2977. 'type' => 2,
  2978. 'exam_id' => $createrid,
  2979. 'exam_name' => $creater,
  2980. 'exam_remark' => '',
  2981. 'addtime' => date('Y-m-d H:i:s')
  2982. ];
  2983. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  2984. "order_code" => $skuCode,//编号
  2985. "status" =>$value['exam_status'] ,
  2986. "action_remark" => '',//备注
  2987. "action_type" => "status"//新建create,编辑edit,更改状态status
  2988. ], "GOL",5, $param);
  2989. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  2990. "order_type" => 'GOL',
  2991. "order_code" => $skuCode,
  2992. "order_id" => $good_offline_log_id,
  2993. "order_status" =>5,
  2994. "before_status" => $value['exam_status']
  2995. ]);
  2996. foreach ($all_user as $itemitem) {
  2997. $insert_order_msg_data[] = [
  2998. 'content' => '商品下线:' . $skuCode . '由' . $creater . '操作下线',
  2999. 'orderCode' => $skuCode,
  3000. 'order_type' => 'GOL',
  3001. 'order_status' =>5,
  3002. 'order_id' => $good_offline_log_id,
  3003. 'uid' => $itemitem['uid'],
  3004. 'uname' => empty($itemitem['nickName']) ? '' : $itemitem['nickName'],
  3005. 'apply_id' => $createrid,
  3006. 'apply_name' => $creater,
  3007. 'is_read' => 0,
  3008. 'addtime' => date('Y-m-d H:i:s'),
  3009. 'updatetime' => date('Y-m-d H:i:s'),
  3010. ];
  3011. }
  3012. }
  3013. //变动记录
  3014. Db::name("good_exam")->insertAll($insert_good_exam_data);
  3015. //消息表
  3016. Db::name('order_msg')->insertAll($insert_order_msg_data);
  3017. }
  3018. //处理有赞平台
  3019. $rs = Db::name('platform_youzan')
  3020. ->field('id,spuCode,skuCode,exam_status,platform_id')
  3021. ->where(['spuCode' => $param['spuCode'], 'is_del' => PlatformYouzan::$del_normal])
  3022. ->whereNotIn('exam_status', [PlatformYouzan::$exam_status_7, PlatformYouzan::$exam_status_8])
  3023. ->select()
  3024. ->toArray();
  3025. if ($rs) {
  3026. $insert_good_offline_log_youzan_data = [];
  3027. foreach ($rs as $value) {
  3028. $curl_data = [
  3029. 'item_no' => $value['skuCode'],//商品自定义编码 skuCode
  3030. 'uid' => $createrid,
  3031. 'nickname' => $creater,
  3032. ];
  3033. //已上线的要调用有赞接口下线
  3034. //调有赞项目的接口,从有赞平台下线该商品
  3035. if($value['exam_status'] == PlatformYouzan::$exam_status_6){
  3036. $host = config('app.yz_domain');
  3037. $response = curl_request($host . 'api/yz_goodup_offline', $curl_data);
  3038. $response = json_decode($response, true);
  3039. if ($response['code'] != 0) throw new Exception($response['message']);
  3040. }
  3041. $insert_good_offline_log_youzan_data[] = [
  3042. 'spuCode' => $value['spuCode'],
  3043. 'skuCodes' => $value['skuCode'],
  3044. 'good_name' => $good_name,
  3045. 'offline_reason' => $param['offline_reason'],
  3046. 'offline_remark' => $param['offline_remark'],
  3047. 'createrid' => $createrid,
  3048. 'creater' => $creater,
  3049. 'addtime' => date('Y-m-d H:i:s')
  3050. ];
  3051. }
  3052. Db::name('platform_youzan')
  3053. ->where(['spuCode' => $param['spuCode'], 'is_del' => PlatformYouzan::$del_normal])
  3054. ->whereNotIn('exam_status', [PlatformYouzan::$exam_status_7, PlatformYouzan::$exam_status_8])
  3055. ->update([
  3056. 'exam_status' => PlatformYouzan::$exam_status_8,
  3057. 'offline_reason_id' => $param['offline_reason'],
  3058. 'offline_remark' => $param['offline_remark'],
  3059. 'updaterid' => $createrid,
  3060. 'updater' => $creater,
  3061. 'updatetime' => date('Y-m-d H:i:s')
  3062. ]);
  3063. //下线记录表增加记录
  3064. if ($insert_good_offline_log_youzan_data) Db::name('good_offline_log_youzan')->insertAll($insert_good_offline_log_youzan_data);
  3065. }
  3066. Db::commit();
  3067. return app_show(0, "下线成功");
  3068. } catch (\Exception $e) {
  3069. Db::rollback();
  3070. return error_show(1004, '操作失败,' . $e->getMessage());
  3071. }
  3072. }
  3073. //判断是否允许修改成本信息和基础信息
  3074. public function checkIsUpdate()
  3075. {
  3076. $spuCode = $this->request->post('spuCode', '', 'trim');
  3077. if ($spuCode == '') return error_show(1004, '成本商品编号不能为空');
  3078. $is_allow_update = 1;
  3079. //检查是否有上线记录
  3080. $rs = Db::name('good_platform')
  3081. ->field('id')
  3082. ->where(['spuCode' => $spuCode, 'is_del' => 0])
  3083. ->whereNotIn('exam_status', [0,1,5])//0待提交,8已下线
  3084. ->find();
  3085. if (!empty($rs)) $is_allow_update = 0;
  3086. else {
  3087. $rs = PlatformYouzan::field('id')
  3088. ->where(['spuCode' => $spuCode, 'is_del' => PlatformYouzan::$del_normal])
  3089. ->whereNotIn('exam_status', [PlatformYouzan::$exam_status_8,PlatformYouzan::$exam_status_2])//8已下线,2审核驳回
  3090. ->findOrEmpty()
  3091. ->isEmpty();
  3092. if (!$rs) $is_allow_update = 0;
  3093. }
  3094. return app_show(0, '请求成功', ['is_allow_update' => $is_allow_update]);
  3095. }
  3096. private function isUpdate($spuCode){
  3097. $is_allow_update = 1;
  3098. //检查是否有上线记录
  3099. $rs = Db::name('good_platform')
  3100. ->field('id')
  3101. ->where(['spuCode' => $spuCode, 'is_del' => 0])
  3102. ->whereNotIn('exam_status', [0,1,5])
  3103. ->find();
  3104. if (!empty($rs)) $is_allow_update = 0;
  3105. else {
  3106. $rs = PlatformYouzan::field('id')
  3107. ->where(['spuCode' => $spuCode, 'is_del' => PlatformYouzan::$del_normal])
  3108. ->whereNotIn('exam_status', [PlatformYouzan::$exam_status_8,PlatformYouzan::$exam_status_2])
  3109. ->findOrEmpty()
  3110. ->isEmpty();
  3111. if (!$rs) $is_allow_update = 0;
  3112. }
  3113. return $is_allow_update;
  3114. }
  3115. //获取某个商品编号下的所有审核备注列表
  3116. public function getGoodExamList()
  3117. {
  3118. $param = $this->request->filter('trim')->only(['token', 'skuCode', 'page' => 1, 'size' => 15], 'post');
  3119. $val = Validate::rule(['token' => 'require', 'skuCode' => 'require']);
  3120. if (!$val->check($param)) return error_show(1005, $val->getError());
  3121. $count = Db::name('good_exam')
  3122. ->where('code', $param['skuCode'])
  3123. ->count('id');
  3124. $list = Db::name('good_exam')
  3125. ->where('code', $param['skuCode'])
  3126. ->order('id')
  3127. ->page($param['page'], $param['size'])
  3128. ->select()
  3129. ->toArray();
  3130. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  3131. }
  3132. //获取某个商品编号下的所有审核备注列表
  3133. public function changeLog()
  3134. {
  3135. $param = $this->request->filter('trim')->only(["code"=>"","type"=>""], 'post');
  3136. $val = Validate::rule(['code' => 'require|max:255', 'type' => 'require|number|in:1,2,3,4,5,6,7,8']);
  3137. if (!$val->check($param)) return error_show(1005, $val->getError());
  3138. $count = Db::name('change_log')
  3139. ->where([['code',"=", $param['code']],["type","=",$param['type']]])
  3140. ->json(["after_info","before_info"])
  3141. ->order("id desc")
  3142. ->findOrEmpty();
  3143. return app_show(0, '请求成功', $count);
  3144. }
  3145. //财务审核是否合规接口 只有上线成功才可以操作
  3146. public function AddCompliance(){
  3147. $param = $this->request->filter('trim')->only(["skuCode"=>"","is_compliance"=>"","compliance_remark"=>""],
  3148. 'post',"trim");
  3149. $val = Validate::rule([
  3150. 'compliance_remark|备注' => 'max:255',
  3151. 'skuCode|上线商品编号' => 'require|max:255',
  3152. 'is_compliance|是否合规' => 'require|number|in:0,1,2']);
  3153. if ($val->check($param)==false) return error_show(1005, $val->getError());
  3154. $goodinfo =Db::name("good_platform")
  3155. ->where(["skuCode"=>$param["skuCode"],"is_del"=>0])
  3156. ->findOrEmpty();
  3157. if(empty($goodinfo)) return error_show(1004,"未找到上线商品数据");
  3158. if($goodinfo['exam_status']!=3)return error_show(1004,"商品完成未上线不可操作");
  3159. $upinfo = [
  3160. "is_compliance"=>$param['is_compliance'],
  3161. "compliance_remark"=>$param['compliance_remark'],
  3162. "updatetime"=>date("Y-m-d H:i:s")
  3163. ];
  3164. $up = Db::name("good_platform")
  3165. ->where(["skuCode"=>$param["skuCode"],"is_del"=>0])->update($upinfo);
  3166. if($up==false)return error_show(1004,"数据更新失败");
  3167. else return app_show(0,"数据更新成功");
  3168. }
  3169. /**
  3170. *咨询商品入成本库
  3171. */
  3172. public function basicZixunGoods(){
  3173. $param = $this->request->only(['codes'=>[]], 'post', 'trim');
  3174. $val = Validate::rule([
  3175. 'codes|所选上线商品编号' => 'require|array',
  3176. ]);
  3177. if (!$val->check($param)) return error_show(1004, $val->getError());
  3178. $good_zixun_list = Db::name('good_zixun')
  3179. ->where(['is_del' => 0])
  3180. ->whereIn('spuCode', $param['codes'])
  3181. ->select();
  3182. if (empty($good_zixun_list)) return error_show(1004, '未找到相关咨询商品数据');
  3183. $temp=[];
  3184. $good_spec_insert_data=[];
  3185. $GoodBasic = new GoodBasic();
  3186. foreach ($good_zixun_list as $item){
  3187. $isT =$GoodBasic->where(["spuCode"=>$item['spuCode'],"is_del"=>0])->findOrEmpty();
  3188. if($isT->isEmpty()==false)return error_show(1004, "{$item['good_name']}商品已存在成本库中!");
  3189. $bd=[];
  3190. if($item['order_source']==2 || $item['order_source']==3){
  3191. $bd = Db::name("consult_bids")->where(["spuCode"=> $item['spuCode']])->findOrEmpty();
  3192. }
  3193. $temp[] = [
  3194. 'spuCode' => $item['spuCode'],
  3195. 'good_code' => $item['good_code'],
  3196. 'good_name' => $item['good_name'],
  3197. 'cat_id' => $item['cat_id'],
  3198. 'brand_id' => $item['brand_id'],
  3199. 'companyNo' => $item['companyNo'],
  3200. 'companyName' => $item['companyName'],
  3201. 'good_unit' => $item['good_unit'],
  3202. 'good_type' => $item['good_type'],
  3203. 'moq' => $item['moq'],
  3204. 'customized' => $item['customized'],
  3205. 'tax' => $item['tax'],
  3206. 'supplierNo' => $item['supplierNo'],
  3207. 'supplierName' => $item['supplierName'],
  3208. 'is_auth' => $item['is_auth'],
  3209. 'auth_img' => $item['auth_img'],
  3210. 'after_sales' => '',
  3211. 'craft_desc' => $item['craft_desc'],
  3212. 'good_remark' => $item['good_remark'],
  3213. 'weight' => $item['weight'],
  3214. 'packing_way' => '',
  3215. 'packing_size' => '',
  3216. 'packing_spec' => '',
  3217. 'packing_list' => '',
  3218. 'packing_weight' => '',
  3219. 'good_bar' => '',
  3220. 'supply_area' => $item['supply_area'],
  3221. 'delivery_place' =>$bd['delivery_place']??"",
  3222. 'origin_place' =>$bd['origin_place']??'',
  3223. 'delivery_day' => $bd['delivery_day']??'',
  3224. 'lead_time' => '',
  3225. 'sample_day' => '',
  3226. 'sample_fee' => '',
  3227. 'good_img' => '',//$item['good_img'],
  3228. 'good_thumb_img' => $item['good_thumb_img'],
  3229. 'good_info_img' => $item['good_img'],//商品主图对应到商品详情
  3230. 'cert_fee' => '',
  3231. 'packing_fee' => '',
  3232. 'cost_fee' => '',
  3233. 'mark_fee' => '',
  3234. 'demo_fee' => '',
  3235. 'open_fee' => '',
  3236. 'noble_metal' => $item['noble_metal'],
  3237. 'noble_weight' => $item['good_weight'],
  3238. 'is_gold_price' => $item['is_gold_price'],
  3239. 'cgd_gold_price' => '',
  3240. 'market_price' => '',
  3241. 'nake_price' => '',
  3242. 'is_step' => '',
  3243. 'is_online' => '',
  3244. 'status' => 8,//咨询商品待编辑
  3245. 'createrid' => $this->uid,
  3246. 'creater' => $this->uname,
  3247. 'create_source' => 1,
  3248. 'field_change' => '',
  3249. 'is_del' => 0,
  3250. 'addtime' => date('Y-m-d H:i:s'),
  3251. 'updatetime' => date('Y-m-d H:i:s'),
  3252. 'is_diff' => $item['is_diff'],
  3253. 'config' => $item['config'],
  3254. 'other_config' => $item['other_config'],
  3255. ];
  3256. if ($item['specinfo']!='') {
  3257. $spec_list = json_decode($item['specinfo'], true);
  3258. foreach ($spec_list as $spec) {
  3259. $specid = $spec['specid']??($spec['spec_id']??'');
  3260. $specinfo = Db::name('good_spec')
  3261. ->field('id')
  3262. ->where(['spuCode' => $item['spuCode'], 'spec_id' => $specid, 'spec_value_id' => $spec['spec_value_id'],
  3263. 'is_del' => 0])
  3264. ->findOrEmpty();
  3265. if (empty($specinfo)) {
  3266. $good_spec_insert_data[] = [
  3267. 'spuCode' => $item['spuCode'],
  3268. 'spec_id' => $specid,
  3269. 'spec_value_id' => $spec['spec_value_id'],
  3270. 'is_del' => 0,
  3271. 'addtime' => date('Y-m-d H:i:s'),
  3272. 'updatetime' => date('Y-m-d H:i:s'),
  3273. ];
  3274. }
  3275. }
  3276. }
  3277. }
  3278. $GoodBasic->startTrans();
  3279. try {
  3280. $create = $GoodBasic->saveAll($temp);
  3281. Db::name('good_zixun')
  3282. ->where(['is_del' => 0, 'status' => 1])
  3283. ->whereIn('spuCode', $param['codes'])
  3284. ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]);
  3285. if (!empty($good_spec_insert_data)) Db::name('good_spec')->insertAll($good_spec_insert_data);
  3286. if ($create) {
  3287. foreach ($temp as $value) {
  3288. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
  3289. 'order_code' =>$value['spuCode'],//
  3290. 'status' => 8,//待产品审核
  3291. 'action_remark' => '',//备注
  3292. 'action_type' => 'create'//新建create,编辑edit,更改状态status
  3293. ], 'SPCB', $value['status'], $value);
  3294. ProcessOrder::AddProcess(['id' =>$this->uid, 'nickname' =>$this->uname], [
  3295. 'order_type' => 'SPCB',
  3296. 'order_code' =>$value['spuCode'],//
  3297. 'order_id' => isset($value['id']) ? $value['id'] : 0,
  3298. 'order_status' => 8,//待产品审核
  3299. 'before_status' => 0,//待产品审核
  3300. 'holder_id'=>$value['createrid'],
  3301. ]);
  3302. }
  3303. $GoodBasic->commit();
  3304. return app_show(0, '提交成功');
  3305. } else {
  3306. $GoodBasic->rollback();
  3307. return error_show(1004, '提交失败');
  3308. }
  3309. } catch (Exception $exception) {
  3310. $GoodBasic->rollback();
  3311. return error_show(1005, $exception->getMessage());
  3312. }
  3313. }
  3314. protected function BasicToGood($spuCode,$data=[]){
  3315. $good =new \app\admin\model\Good();
  3316. $info = $good->where(["spuCode"=>$spuCode,"is_del"=>0])->findOrEmpty();
  3317. if($info->isEmpty()==false){
  3318. if(isset($data['usable_stock']))unset($data['usable_stock']);
  3319. if(isset($data['status']))unset($data['status']);
  3320. if(isset($data['charger']))unset($data['charger']);
  3321. if(isset($data['chargerid']))unset($data['chargerid']);
  3322. $good->where($info->toArray())->save($data);
  3323. }
  3324. }
  3325. }