Goodup.php 140 KB

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