Goodup.php 185 KB

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