Goodup.php 172 KB

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