Goodup.php 188 KB

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