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