Goodup.php 170 KB

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