Goodup.php 167 KB

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