Goodup.php 187 KB

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