Goodup.php 171 KB

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