Goodup.php 151 KB

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