Goodup.php 188 KB

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