Goodup.php 145 KB

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