Goodup.php 184 KB

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