Goodup.php 188 KB

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