Goodup.php 154 KB

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