Goodup.php 168 KB

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