Goodup.php 169 KB

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