Goodup.php 149 KB

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