Goodup.php 187 KB

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