Goodup.php 145 KB

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