Goodup.php 154 KB

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