Goodup.php 169 KB

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