Goodup.php 186 KB

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