Goodup.php 157 KB

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