Goodup.php 152 KB

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