Goodup.php 140 KB

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