Goodup.php 164 KB

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