Goodup.php 145 KB

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