Goodup.php 127 KB

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