Goodup.php 187 KB

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