Goodup.php 150 KB

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