Goodup.php 161 KB

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