Goodup.php 188 KB

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