Goodup.php 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\facade\Db;
  5. class Goodup extends Base
  6. {
  7. public function __construct(App $app)
  8. {
  9. parent::__construct($app);
  10. }
  11. public function list(){
  12. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  13. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  14. $where =[["is_del","=",0]];
  15. $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !=="" ? intval($this->post['cat_id']):"";
  16. if($cat_id!==""){
  17. $cat_ids=catChild($cat_id);
  18. $where[]=['cat_id',"in",$cat_ids];
  19. }
  20. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']):"";
  21. if($good_name!==""){
  22. $where[]=['good_name',"like","%$good_name%"];
  23. }
  24. $spucode = isset($this->post['spucode']) && $this->post['spucode'] !=="" ? trim($this->post['spucode'])
  25. :"";
  26. if($spucode!==""){
  27. $where[]=['spuCode',"like","%$spucode%"];
  28. }
  29. $good_type = isset($this->post['good_type']) && $this->post['good_type'] !=="" ? trim($this->post['good_type'])
  30. :"";
  31. if($good_type!==""){
  32. $where[]=['good_type',"=",$good_type];
  33. }
  34. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo'])
  35. :"";
  36. if($companyNo!==""){
  37. $where[]=['companyNo',"like","%$companyNo%"];
  38. }
  39. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
  40. :"";
  41. if($supplierNo!==""){
  42. $where[]=['supplierNo',"like","%$supplierNo%"];
  43. }
  44. $supplier = isset($this->post['supplier']) && $this->post['supplier'] !=="" ? trim($this->post['supplier'])
  45. :"";
  46. if($supplier!==""){
  47. $suppliernos = Db::name("supplier")->where([["name","like","%$supplier%"]])->column("code");
  48. $where[]=['supplierNo',"in",$suppliernos];
  49. }
  50. $company = isset($this->post['company']) && $this->post['company'] !=="" ? trim($this->post['company'])
  51. :"";
  52. if($company!==""){
  53. $companyNos = Db::name("business")->where([["company","like","%$company%"]])->column("companyNo");
  54. $where[]=['companyNo',"in",$companyNos];
  55. }
  56. $brandid = isset($this->post['brandid']) && $this->post['brandid'] !=="" ? intval($this->post['brandid'])
  57. :"";
  58. if($brandid!==""){
  59. $where[]=['brand_id',"=",$brandid];
  60. }
  61. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status'])
  62. :"";
  63. if($status!==""){
  64. $where[]=['status',"=",$status];
  65. }
  66. $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  67. if($start!==""){
  68. $where[]=['addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
  69. }
  70. $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  71. if($end!==""){
  72. $where[]=['addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  73. }
  74. $count = Db::name('good_basic')->where($where)->count();
  75. $total = ceil($count / $size);
  76. $page = $page >= $total ? $total : $page;
  77. $list = Db::name('good_basic')->where($where)->page($page,$size)->order("addtime desc")->select();
  78. $data=[];
  79. foreach ($list as $value){
  80. $value["cat_info"]= made($value['cat_id'],[]);
  81. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  82. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  83. $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
  84. $value['unit'] =isset($unit['unit'])?$unit['unit']:"";
  85. $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  86. $value['company'] = isset($company['company'])?$company['company']:"";
  87. $supplier = Db::name("supplier")->where(['code'=>$value['supplierNo']])->find();
  88. $value['supplier_name']=isset($supplier['name'])?$supplier['name']:"";
  89. $value['good_info_img']=json_decode($value['good_info_img'],true);
  90. $value['exclusive']=makeExcluse($value['is_exclusive']);
  91. // $value['status']=$value['exam_status'];
  92. $data[]=$value;
  93. }
  94. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  95. }
  96. public function create(){
  97. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):"";
  98. if($good_name==""){
  99. return error_show(1004,"商品名称不能为空");
  100. }
  101. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):"";
  102. if($cat_id==''){
  103. return error_show(1004,"商品分类不能为空");
  104. }
  105. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  106. if($brandid==''){
  107. return error_show(1004,"商品品牌不能为空");
  108. }
  109. $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):"";
  110. if($unit==''){
  111. return error_show(1004,"商品单位不能为空");
  112. }
  113. $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type'])
  114. :"";
  115. if($good_type===''){
  116. return error_show(1004,"参数good_type不能为空");
  117. }
  118. $moq=0;
  119. $customized=0;
  120. if($good_type==1){
  121. $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):"";
  122. if($moq===''){
  123. return error_show(1004,"定制商品起订量不能为空");
  124. }
  125. $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  126. if($customized===''){
  127. return error_show(1004,"参数customized不能为空");
  128. }
  129. }
  130. $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):"";
  131. if($is_exclusive===''){
  132. return error_show(1004,"参数is_exclusive不能为空");
  133. }
  134. // $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  135. // if($customized===''){
  136. // return error_show(1004,"参数customized不能为空");
  137. // }
  138. $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):"";
  139. if($tax===''){
  140. return error_show(1004,"参数tax不能为空");
  141. }
  142. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  143. if($supplierNo==''){
  144. return error_show(1004,"参数supplierNo不能为空");
  145. }
  146. $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size']):"";
  147. if($good_size==''){
  148. return error_show(1004,"参数good_size不能为空");
  149. }
  150. $company_id = isset($this->post['company_id'])&&$this->post['company_id']!=""? trim($this->post['company_id'])
  151. :"";
  152. if($company_id==''){
  153. return error_show(1004,"参数company_id不能为空");
  154. }
  155. $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):"";
  156. if($is_auth===''){
  157. return error_show(1004,"参数is_auth不能为空");
  158. }
  159. $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):"";
  160. // if($auth_img==''){
  161. // return error_show(1004,"商品不能为空");
  162. // }
  163. $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):"";
  164. if($after_sales==""){
  165. return error_show(1004,"参数after_sales不能为空");
  166. }
  167. $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):"";
  168. $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):"";
  169. if($good_remark===""){
  170. return error_show(1004,"参数good_remark不能为空");
  171. }
  172. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  173. if($weight===""){
  174. return error_show(1004,"参数weight不能为空");
  175. }
  176. $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):"";
  177. if($packing_way===""){
  178. return error_show(1004,"参数packing_way不能为空");
  179. }
  180. $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):"";
  181. if($packing_size===""){
  182. return error_show(1004,"参数packing_size不能为空");
  183. }
  184. $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):"";
  185. if($packing_spec===""){
  186. return error_show(1004,"参数packing_spec不能为空");
  187. }
  188. $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):"";
  189. if($packing_weight===""){
  190. return error_show(1004,"参数packing_weight不能为空");
  191. }
  192. $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):"";
  193. if($packing_list===""){
  194. return error_show(1004,"参数packing_list不能为空");
  195. }
  196. $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):"";
  197. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  198. if($supply_area===""){
  199. return error_show(1004,"参数supply_area不能为空");
  200. }
  201. $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? trim($this->post['delivery_place']):"";
  202. if($delivery_place===""){
  203. return error_show(1004,"参数delivery_place不能为空");
  204. }
  205. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? trim($this->post['origin_place']):"";
  206. if($origin_place===""){
  207. return error_show(1004,"参数origin_place不能为空");
  208. }
  209. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):"";
  210. if($delivery_day===""){
  211. return error_show(1004,"参数delivery_day不能为空");
  212. }
  213. $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time'])
  214. :"0";
  215. // if($lead_time===""){
  216. // return error_show(1004,"参数lead_time不能为空");
  217. // }
  218. $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0";
  219. // if($sample_day===""){
  220. // return error_show(1004,"参数sample_day不能为空");
  221. // }
  222. $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0";
  223. $is_stock = isset($this->post['is_stock'])&&$this->post['is_stock']!==""? intval($this->post['is_stock']):"";
  224. if($is_stock===""){
  225. return error_show(1004,"参数is_stock不能为空");
  226. }
  227. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"0";
  228. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!==""? trim($this->post['good_img']):"";
  229. $config = isset($this->post['config'])&&$this->post['config']!==""? trim($this->post['config']):"";
  230. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!==""? trim($this->post['other_config']):"";
  231. // if($good_img===""){
  232. // return error_show(1004,"参数good_img不能为空");
  233. // }
  234. $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):"";
  235. if($good_thumb_img===""){
  236. return error_show(1004,"参数good_thumb_img不能为空");
  237. }
  238. $good_info_img = isset($this->post['good_info_img'])&&!empty($this->post['good_info_img'])? $this->post['good_info_img']:"";
  239. if($good_info_img===""){
  240. return error_show(1004,"参数good_info_img不能为空");
  241. }
  242. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  243. $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0";
  244. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  245. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  246. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  247. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  248. $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0";
  249. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  250. $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0";
  251. $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):"";
  252. if($market_price===""){
  253. return error_show(1004,"参数market_price不能为空");
  254. }
  255. $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"";
  256. if($nake_price===""){
  257. return error_show(1004,"参数nake_price不能为空");
  258. }
  259. $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  260. if($is_step===""){
  261. return error_show(1004,"参数is_step不能为空");
  262. }
  263. $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:"";
  264. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
  265. if($is_step==1 && $good_ladder==""){
  266. return error_show(1004,"启用阶梯,阶梯价不能为空");
  267. }
  268. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  269. if($token==''){
  270. return error_show(105,"参数token不能为空");
  271. }
  272. $user =GetUserInfo($token);
  273. if(empty($user)||$user['code']!=0){
  274. return error_show(1002,"创建人数据不存在");
  275. }
  276. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  277. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  278. $spucode=makeNo("SPU");
  279. Db::startTrans();
  280. try {
  281. $data=[
  282. "spuCode"=>$spucode,
  283. "good_code"=>'',
  284. "good_name"=>$good_name,
  285. "cat_id"=>$cat_id,
  286. 'brand_id'=>$brandid,
  287. "good_unit"=>$unit,
  288. "good_type"=>$good_type,
  289. "moq"=>$moq,
  290. "is_exclusive"=>$is_exclusive,
  291. "customized"=>$customized,
  292. "companyNo"=>$company_id,
  293. "tax"=>$tax,
  294. "supplierNo"=>$supplierNo,
  295. "good_size"=>$good_size,
  296. "is_auth"=>$is_auth,
  297. "is_stock"=>$is_stock,
  298. "auth_img"=>$auth_img,
  299. "after_sales"=>$after_sales,
  300. "craft_desc"=>$craft_desc,
  301. "good_remark"=>$good_remark,
  302. "weight"=>$weight,
  303. "packing_way"=>$packing_way,
  304. "packing_size"=>$packing_size,
  305. "packing_spec"=>$packing_spec,
  306. "packing_list"=>$packing_list,
  307. "packing_weight"=>$packing_weight,
  308. "good_bar"=>$good_bar,
  309. "supply_area"=>$supply_area,
  310. "delivery_place"=>$delivery_place,
  311. "origin_place"=>$origin_place,
  312. "delivery_day"=>$delivery_day,
  313. "lead_time"=>$lead_time,
  314. "sample_day"=>$sample_day,
  315. "sample_fee"=>$sample_fee,
  316. "good_img"=>$good_img,
  317. "good_thumb_img"=>$good_thumb_img,
  318. "good_info_img"=>json_encode($good_info_img),
  319. "cert_fee"=>$cert_fee,
  320. "packing_fee"=>$packing_fee,
  321. "cost_fee"=>$cost_fee,
  322. "mark_fee"=>$mark_fee,
  323. "demo_fee"=>$demo_fee,
  324. "open_fee"=>$open_fee,
  325. "noble_metal"=>$noble_metal,
  326. "noble_weight"=>$noble_weight,
  327. "is_gold_price"=>$is_gold_price,
  328. "market_price"=>$market_price,
  329. "nake_price"=>$nake_price,
  330. "is_diff"=>$is_diff,
  331. "config"=>$config,
  332. "other_config"=>$other_config,
  333. "is_step"=>$is_step,
  334. "is_online"=>0,
  335. "status"=>0,
  336. "createrid"=>$createrid,
  337. "creater"=>$creater,
  338. "addtime"=>date("Y-m-d H:i:s"),
  339. "updatetime"=>date("Y-m-d H:i:s")
  340. ];
  341. $in = Db::name("good_basic")->insert($data);
  342. if($in){
  343. if($speclist!=="" && !empty($speclist)){
  344. $temp=[];
  345. foreach ($speclist as $value){
  346. $lemp=[];
  347. $lemp['spuCode']=$spucode;
  348. $lemp['spec_id'] = $value['spec_id'];
  349. $lemp['spec_value_id'] = $value['spec_value_id'];
  350. $lemp['addtime'] = date("Y-m-d H:i:s");
  351. $lemp['updatetime'] =date("Y-m-d H:i:s");
  352. $temp[]=$lemp;
  353. }
  354. $count = Db::name("good_spec")->insertAll($temp);
  355. if($count==0){
  356. Db::rollback();
  357. return app_show(1004,"商品规格值创建失败");
  358. }
  359. }
  360. if($good_ladder!=="" && !empty($good_ladder)){
  361. $temp=[];
  362. foreach ($good_ladder as $value){
  363. $lemp=[];
  364. $lemp['spuCode']=$spucode;
  365. $lemp['min_num'] = $value['min_num'];
  366. $lemp['nake_fee'] = $value['nake_fee'];
  367. $lemp['cost_fee'] = $value['cost_fee'];
  368. $lemp['delivery_fee'] = $value['delivery_fee'];
  369. $lemp['is_del'] = 0;
  370. $lemp['addtime'] = date("Y-m-d H:i:s");
  371. $lemp['updatetime'] =date("Y-m-d H:i:s");
  372. $temp[]=$lemp;
  373. }
  374. $count = Db::name("good_nake")->insertAll($temp);
  375. if($count==0){
  376. Db::rollback();
  377. return app_show(1004,"商品规格值创建失败");
  378. }
  379. }
  380. Db::commit();
  381. return app_show(0,"创建成功",["spuCode"=>$spucode]);
  382. }else{
  383. Db::rollback();
  384. return app_show(1004,"商品创建失败");
  385. }
  386. }catch (\Exception $e){
  387. Db::rollback();
  388. return app_show(1004,$e->getMessage());
  389. }
  390. }
  391. public function editinfo(){
  392. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  393. if($supcode==""){
  394. return error_show(1004,"参数spuCode不能为空");
  395. }
  396. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  397. if($data==false){
  398. return error_show(1004,"未找到商品数据");
  399. }
  400. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):"";
  401. if($good_name==""){
  402. return error_show(1004,"商品名称不能为空");
  403. }
  404. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):"";
  405. if($cat_id==''){
  406. return error_show(1004,"商品分类不能为空");
  407. }
  408. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"0";
  409. // if($brandid==''){
  410. // return error_show(1004,"商品品牌不能为空");
  411. // }
  412. $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):"";
  413. if($unit==''){
  414. return error_show(1004,"商品单位不能为空");
  415. }
  416. $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type'])
  417. :"";
  418. if($good_type===''){
  419. return error_show(1004,"参数good_type不能为空");
  420. }
  421. $moq=0;
  422. $customized=0;
  423. if($good_type==1){
  424. $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):"";
  425. if($moq===''){
  426. return error_show(1004,"定制商品起订量不能为空");
  427. }
  428. $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  429. if($customized===''){
  430. return error_show(1004,"参数customized不能为空");
  431. }
  432. }
  433. $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):"";
  434. if($is_exclusive===''){
  435. return error_show(1004,"参数is_exclusive不能为空");
  436. }
  437. // $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  438. // if($customized===''){
  439. // return error_show(1004,"参数customized不能为空");
  440. // }
  441. $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):"";
  442. if($tax===''){
  443. return error_show(1004,"参数tax不能为空");
  444. }
  445. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  446. if($supplierNo==''){
  447. return error_show(1004,"参数supplierNo不能为空");
  448. }
  449. $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size'])
  450. :"";
  451. if($good_size==''){
  452. return error_show(1004,"参数good_size不能为空");
  453. }
  454. $company_id = isset($this->post['company_id'])&&$this->post['company_id']!=""? trim($this->post['company_id'])
  455. :"";
  456. if($company_id==''){
  457. return error_show(1004,"参数company_id不能为空");
  458. }
  459. $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):"";
  460. if($is_auth===''){
  461. return error_show(1004,"参数is_auth不能为空");
  462. }
  463. $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):"";
  464. // if($auth_img==''){
  465. // return error_show(1004,"商品不能为空");
  466. // }
  467. $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):"";
  468. if($after_sales==""){
  469. return error_show(1004,"参数after_sales不能为空");
  470. }
  471. $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):"";
  472. $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):"";
  473. if($good_remark===""){
  474. return error_show(1004,"参数good_remark不能为空");
  475. }
  476. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  477. if($weight===""){
  478. return error_show(1004,"参数weight不能为空");
  479. }
  480. $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):"";
  481. if($packing_way===""){
  482. return error_show(1004,"参数packing_way不能为空");
  483. }
  484. $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):"";
  485. if($packing_size===""){
  486. return error_show(1004,"参数packing_size不能为空");
  487. }
  488. $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):"";
  489. if($packing_spec===""){
  490. return error_show(1004,"参数packing_spec不能为空");
  491. }
  492. $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):"";
  493. if($packing_weight===""){
  494. return error_show(1004,"参数packing_weight不能为空");
  495. }
  496. $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):"";
  497. if($packing_list===""){
  498. return error_show(1004,"参数packing_list不能为空");
  499. }
  500. $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):"";
  501. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  502. if($supply_area===""){
  503. return error_show(1004,"参数supply_area不能为空");
  504. }
  505. $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? $this->post['delivery_place']:"";
  506. if($delivery_place===""){
  507. return error_show(1004,"参数delivery_place不能为空");
  508. }
  509. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? $this->post['origin_place']:"";
  510. if($origin_place===""){
  511. return error_show(1004,"参数origin_place不能为空");
  512. }
  513. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):"";
  514. if($delivery_day===""){
  515. return error_show(1004,"参数delivery_day不能为空");
  516. }
  517. $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time'])
  518. :"0";
  519. // if($lead_time===""){
  520. // return error_show(1004,"参数lead_time不能为空");
  521. // }
  522. $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0";
  523. // if($sample_day===""){
  524. // return error_show(1004,"参数sample_day不能为空");
  525. // }
  526. $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0";
  527. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!==""? trim($this->post['good_img']):"";
  528. // if($good_img===""){
  529. // return error_show(1004,"参数good_img不能为空");
  530. // }
  531. $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):"";
  532. if($good_thumb_img===""){
  533. return error_show(1004,"参数good_thumb_img不能为空");
  534. }
  535. $good_info_img = isset($this->post['good_info_img'])&&!empty($this->post['good_info_img'])? $this->post['good_info_img']:"";
  536. if($good_info_img===""){
  537. return error_show(1004,"参数good_info_img不能为空");
  538. }
  539. $count = Db::name("good_nake")->where(["spuCode"=>$supcode,"is_del"=>0])->count();
  540. $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:"";
  541. Db::startTrans();
  542. try {
  543. $temp=[
  544. "good_name"=>$good_name,
  545. "cat_id"=>$cat_id,
  546. 'brand_id'=>$brandid,
  547. "good_unit"=>$unit,
  548. "good_type"=>$good_type,
  549. "companyNo"=>$company_id,
  550. "moq"=>$moq,
  551. "is_exclusive"=>$is_exclusive,
  552. "customized"=>$customized,
  553. "tax"=>$tax,
  554. "supplierNo"=>$supplierNo,
  555. "is_auth"=>$is_auth,
  556. "good_size"=>$good_size,
  557. "auth_img"=>$auth_img,
  558. "after_sales"=>$after_sales,
  559. "craft_desc"=>$craft_desc,
  560. "good_remark"=>$good_remark,
  561. "weight"=>$weight,
  562. "packing_way"=>$packing_way,
  563. "packing_size"=>$packing_size,
  564. "packing_spec"=>$packing_spec,
  565. "packing_list"=>$packing_list,
  566. "packing_weight"=>$packing_weight,
  567. "good_bar"=>$good_bar,
  568. "supply_area"=>$supply_area,
  569. "delivery_place"=>$delivery_place,
  570. "origin_place"=>$origin_place,
  571. "delivery_day"=>$delivery_day,
  572. "lead_time"=>$lead_time,
  573. "sample_day"=>$sample_day,
  574. "sample_fee"=>$sample_fee,
  575. "good_img"=>$good_img,
  576. "good_thumb_img"=>$good_thumb_img,
  577. "good_info_img"=>json_encode($good_info_img),
  578. "status"=>$count>0?2:1,
  579. "updatetime"=>date("Y-m-d H:i:s")
  580. ];
  581. $field = array_diff_assoc($temp,$data);
  582. $temp['field_change'] =empty($field)?"":json_encode(array_keys($field));
  583. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($temp);
  584. if($up){
  585. if($speclist!=="" && !empty($speclist)){
  586. foreach ($speclist as $value){
  587. $lemp=[];
  588. isset($value["id"])?$lemp['id']=$value['id']:"";
  589. $lemp['spuCode']=$supcode;
  590. $lemp['spec_id'] = $value['spec_id'];
  591. $lemp['spec_value_id'] = $value['spec_value_id'];
  592. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  593. isset($value["id"])? $lemp['addtime'] = date("Y-m-d H:i:s"):"";
  594. $lemp['updatetime'] =date("Y-m-d H:i:s");
  595. $count = Db::name("good_spec")->save($lemp);
  596. if($count==false){
  597. Db::rollback();
  598. return app_show(1004,"商品规格值修改失败");
  599. }
  600. }
  601. }
  602. Db::commit();
  603. return app_show(0,"更新成功");
  604. }else{
  605. Db::rollback();
  606. return error_show(1005,"更新失败");
  607. }
  608. }catch (\Exception $e){
  609. Db::rollback();
  610. return error_show(1004,$e->getMessage());
  611. }
  612. }
  613. public function editfee(){
  614. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  615. if($supcode==""){
  616. return error_show(1004,"参数spuCode不能为空");
  617. }
  618. $datas = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  619. if($datas==false){
  620. return error_show(1004,"未找到商品数据");
  621. }
  622. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  623. $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0";
  624. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  625. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  626. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  627. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  628. $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0";
  629. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  630. $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0";
  631. $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):"";
  632. if($market_price===""){
  633. return error_show(1004,"参数market_price不能为空");
  634. }
  635. $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"";
  636. if($nake_price===""){
  637. return error_show(1004,"参数nake_price不能为空");
  638. }
  639. $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  640. if($is_step===""){
  641. return error_show(1004,"参数is_step不能为空");
  642. }
  643. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
  644. if($is_step==1 && $good_ladder==""){
  645. return error_show(1004,"启用阶梯,阶梯价不能为空");
  646. }
  647. $data=[
  648. "cert_fee"=>$cert_fee,
  649. "packing_fee"=>$packing_fee,
  650. "cost_fee"=>$cost_fee,
  651. "mark_fee"=>$mark_fee,
  652. "demo_fee"=>$demo_fee,
  653. "open_fee"=>$open_fee,
  654. "noble_metal"=>$noble_metal,
  655. "noble_weight"=>$noble_weight,
  656. "is_gold_price"=>$is_gold_price,
  657. "market_price"=>$market_price,
  658. "nake_price"=>$nake_price,
  659. "is_step"=>$is_step,
  660. "status"=>"2",
  661. "updatetime"=>date("Y-m-d H:i:s")
  662. ];
  663. $field = array_diff_assoc($data,$datas);
  664. $data['field_change'] =empty($field)?"":json_encode(array_keys($field));
  665. Db::startTrans();
  666. try{
  667. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($data);
  668. if($up){
  669. $online = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->save(["is_online"=>0,"status"=>0,"updatetime"=>date("Y-m-d H:i:s")]);
  670. if($good_ladder!=="" && !empty($good_ladder)){
  671. foreach ($good_ladder as $value){
  672. $lemp=[];
  673. isset($value["id"])?$lemp['id']=$value['id']:"";
  674. $lemp['spuCode']=$supcode;
  675. $lemp['min_num'] = $value['min_num'];
  676. $lemp['nake_fee'] = $value['nake_fee'];
  677. $lemp['cost_fee'] = $value['cost_fee'];
  678. $lemp['delivery_fee'] = $value['delivery_fee'];
  679. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  680. isset($value["id"])? $lemp['addtime'] = date("Y-m-d H:i:s"):"";
  681. $lemp['updatetime'] =date("Y-m-d H:i:s");
  682. $count = Db::name("good_nake")->save($lemp);
  683. if($count==false){
  684. Db::rollback();
  685. return app_show(1004,"商品规成本修改失败");
  686. }
  687. }
  688. }
  689. Db::commit();
  690. return app_show(0,"更新成功");
  691. }else{
  692. Db::rollback();
  693. return error_show(1005,"更新失败");
  694. }
  695. }catch (\Exception $e){
  696. Db::rollback();
  697. return error_show(1005,$e->getMessage());
  698. }
  699. }
  700. public function exam(){
  701. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  702. if($supcode==""){
  703. return error_show(1004,"参数spuCode不能为空");
  704. }
  705. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  706. if($data==false){
  707. return error_show(1004,"未找到商品数据");
  708. }
  709. if($data['status']==1){
  710. return error_show(1004,"商品已审核通过");
  711. }
  712. $status = isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):"";
  713. // if($status===""){
  714. // return error_show(1004,"参数status不能为空");
  715. // }
  716. $remark = isset($this->post['remark'])&&$this->post['remark']!=="" ? trim($this->post['remark']):"";
  717. // if($remark===""){
  718. // return error_show(1004,"参数remark不能为空");
  719. // }
  720. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  721. if($token==''){
  722. return error_show(105,"参数token不能为空");
  723. }
  724. $user =GetUserInfo($token);
  725. if(empty($user)||$user['code']!=0){
  726. return error_show(1002,"用户数据不存在");
  727. }
  728. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  729. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  730. Db::startTrans();
  731. try {
  732. if($data['status']==3 && $status==1){
  733. $online = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_online"=>0,"status"=>0, "is_del"=>0])->save(["is_online"=>0,"exam_status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  734. }
  735. $data['status']=$status;
  736. $data['updatetime']=date("Y-m-d H:i:s");
  737. $up= Db::name("good_basic")->save($data);
  738. if($up){
  739. $data=[
  740. "code"=>$supcode,
  741. "exam_status"=>$status,
  742. "type"=>1,
  743. "exam_id"=>$createrid,
  744. "exam_name"=>$creater,
  745. "exam_remark"=>$remark,
  746. "addtime"=>date("Y-m-d H:i:s")
  747. ];
  748. $inr=Db::name("good_exam")->insert($data);
  749. if($inr){
  750. Db::commit();
  751. return app_show(0,"审核成功");
  752. }else{
  753. Db::rollback();
  754. return error_show(1004,"审核失败");
  755. }
  756. }else{
  757. Db::rollback();
  758. return error_show(1004,"审核失败");
  759. }
  760. }catch (\Exception $e){
  761. Db::rollback();
  762. return error_show(1004,$e->getMessage());
  763. }
  764. }
  765. public function info(){
  766. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  767. if($supcode==""){
  768. return error_show(1004,"参数spuCode不能为空");
  769. }
  770. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  771. if($data==false){
  772. return error_show(1004,"未找到商品数据");
  773. }
  774. $unit =Db::name("unit")->where(["id"=>$data['good_unit']])->find();
  775. $data['unit'] = isset($unit['unit'])?$unit['unit']:'';
  776. $data['cat_info'] = made($data['cat_id'],[]);
  777. $spec = Db::name("good_spec")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  778. $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  779. $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  780. $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  781. $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  782. $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find();
  783. $data['company'] = isset($company['company'])?$company['company']:"";
  784. $data['field_change'] = $data['field_change']!=''?json_decode($data['field_change']):"";
  785. if($data['brand_id']!=0){
  786. $brand=Db::name("brand")->where(["id"=>$data['brand_id']])->find();
  787. $data["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  788. }else{
  789. $data["brand_name"]="";
  790. $data["brand_id"]="";
  791. }
  792. $excluse = makeExcluse($data['is_exclusive']);
  793. $data['exclusive']=$excluse;
  794. $data["good_info_img"]=$data['good_info_img']!=""? json_decode($data['good_info_img'],true):[];
  795. $speclist=[];
  796. if(!empty($spec)){
  797. foreach ($spec as $value){
  798. $temp=[];
  799. $temp['id']=$value['id'];
  800. $temp['spuCode']=$value['spuCode'];
  801. $temp['spec_id']=$value['spec_id'];
  802. $temp['spec_value_id']=$value['spec_value_id'];
  803. $temp['is_del']=$value['is_del'];
  804. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  805. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  806. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  807. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  808. $speclist[]=$temp;
  809. }
  810. }
  811. $data["speclist"]=empty($speclist)?[]:$speclist;
  812. // $nake=[];
  813. $nakelist = Db::name("good_nake")->where(['spuCode'=>$supcode,"is_del"=>0])->select()->toArray();
  814. $catinfo = Db::name("cat")->where(["id"=>$data['cat_id']])->find();
  815. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  816. $nakearry=[];
  817. if(!empty($nakelist)){
  818. foreach ($nakelist as $value){
  819. if($data['is_gold_price']==1){
  820. $gold = Db::name("gold_price1")->where(["type"=>$data['noble_metal'],"is_del"=>0,"status"=>1])->order("addtime desc")
  821. ->find();
  822. // $total_fee = $data['open_fee']/$value['min_num'] + $data['weight']*$gold["price"] + $data['cost_fee']/(1-$budget)*
  823. // $data['noble_weight']+$data['mark_fee']+$data['packing_fee']+$data['cert_fee']+$value['nake_fee'];
  824. $saleprice = $data['open_fee']/$value['min_num'] + $data['weight']*$gold["price"] + $data['cost_fee']*
  825. $data['noble_weight']+$data['mark_fee']+$data['packing_fee']+$data['cert_fee']+$value['nake_fee'];
  826. }else{
  827. // $total_fee = $data['open_fee']/$value['min_num']+
  828. // $data['cost_fee']*$data['weight']+$data['mark_fee']+$data['packing_fee']+$data['cert_fee']+$value['nake_fee'];
  829. $saleprice = $data['open_fee']/$value['min_num'] + $data['cost_fee']*
  830. $data['noble_weight']+$data['mark_fee']+$data['packing_fee']+$data['cert_fee']+$value['nake_fee']/(1-$budget);
  831. }
  832. $value['sale_price'] =round($saleprice,2) ;
  833. $nakearry[]=$value;
  834. }
  835. }
  836. $data["nakelist"]=$nakearry;
  837. return app_show(0,"获取成功",$data);
  838. }
  839. public function delall(){
  840. $supcode = isset($this->post['codes'])&&!empty($this->post['codes'])? $this->post['codes']:"";
  841. if($supcode==""){
  842. return error_show(1004,"参数codes不能为空");
  843. }
  844. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  845. if(empty($data)){
  846. return error_show(1004,"未找到商品数据");
  847. }
  848. $up= Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save(["is_del"=>1]);
  849. if($up){
  850. return app_show(0,"更新成功");
  851. }else{
  852. return error_show(1005,"更新失败");
  853. }
  854. }
  855. public function online(){
  856. $platform =isset($this->post['platform'])&&!empty($this->post['platform'])? $this->post['platform']:"";
  857. if($platform==""){
  858. return error_show(1004,"参数codes不能为空");
  859. }
  860. $spuCode =isset($this->post['codes'])&&!empty($this->post['codes'])? $this->post['codes']:"";
  861. if($spuCode===''){
  862. return error_show(1004,"参数codes不能为空");
  863. }
  864. $datas = Db::name("good_basic")->where(["spuCode"=>$spuCode,"is_del"=>0])->select()->toArray();
  865. if(empty($datas)){
  866. return error_show(1004,"未找到商品数据");
  867. }
  868. $online_reason = isset($this->post['online_reason'])&&$this->post['online_reason']!==""? trim($this->post['online_reason']):"";
  869. if($online_reason===""){
  870. return error_show(1004,"参数online_reason不能为空");
  871. }
  872. $online_remark= isset($this->post['online_remark'])&&$this->post['online_remark']!==""? trim($this->post['online_remark']):"";
  873. if($online_remark===""){
  874. return error_show(1004,"参数online_remark不能为空");
  875. }
  876. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  877. if($token==''){
  878. return error_show(105,"参数token不能为空");
  879. }
  880. $user =GetUserInfo($token);
  881. if(empty($user)||$user['code']!=0){
  882. return error_show(1002,"用户数据不存在");
  883. }
  884. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  885. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  886. $data=[];
  887. $isonline=[];
  888. foreach ($spuCode as $value){
  889. $count = Db::name("good_nake")->where(["spuCode"=>$value,"is_del"=>0])->count();
  890. $ist =Db::name("good_platform")->where(["spuCode"=>$value,"platform_code"=>$platform,"is_del"=>0])->find();
  891. if($ist){
  892. $god=Db::name("good_basic")->where(["spuCode"=>$value,"is_del"=>0])->find();
  893. if($god){
  894. $tp=[];
  895. $tp['spuCode']=$value;
  896. $tp['good_name']=$god['good_name'];
  897. $tp['good_img']=$god['good_thumb_img'];
  898. $tp['exam_status']=$ist['exam_status'];
  899. $spec = Db::name("good_spec")->where(["spuCode"=>$value,"is_del"=>0])->select()->toArray();
  900. $speclist=[];
  901. if(!empty($spec)){
  902. foreach ($spec as $val){
  903. $temp=[];
  904. $temp['id']=$val['id'];
  905. $temp['spuCode']=$val['spuCode'];
  906. $temp['spec_id']=$val['spec_id'];
  907. $temp['spec_value_id']=$val['spec_value_id'];
  908. $temp['is_del']=$val['is_del'];
  909. $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
  910. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  911. $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
  912. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  913. $speclist[]=$temp;
  914. }
  915. }
  916. $tp["speclist"]=empty($speclist)?[]:$speclist;
  917. $isonline[]=$tp;
  918. }
  919. }
  920. $data[]=[
  921. "spuCode"=>$value,
  922. "skuCode"=>makeNo("SKU"),
  923. "platform_code"=>$platform,
  924. "online_reason"=>$online_reason,
  925. "online_remark"=>$online_remark,
  926. "exam_status"=>$count>0 ?2:1,
  927. "is_online"=>0,
  928. "status"=>1,
  929. "is_del"=>0,
  930. "creater"=>$creater,
  931. "createrid"=>$createrid,
  932. "addtime"=>date("Y-m-d H:i:s"),
  933. "updatetime"=>date("Y-m-d H:i:s")
  934. ];
  935. }
  936. if(!empty($isonline)){
  937. return app_show(1009,"存在已上线产品",$isonline);
  938. }
  939. Db::startTrans();
  940. $create =Db::name("good_platform")->insertAll($data);
  941. if($create){
  942. foreach ($datas as $value){
  943. $iso = Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  944. if($iso==false){
  945. unset($value['id']);
  946. $value['creater']=$creater;
  947. $value['createrid']=$createrid;
  948. $value['addtime']=date("Y-m-d H:i:s");
  949. $value['updatetime']=date("Y-m-d H:i:s");
  950. }else{
  951. $value['id']=$iso['id'];
  952. $value['creater']=$creater;
  953. $value['createrid']=$createrid;
  954. $value['updatetime']=date("Y-m-d H:i:s");
  955. }
  956. $up =Db::name("good")->save($value);
  957. if(!$up){
  958. Db::rollback();
  959. return error_show(1004,"提交失败");
  960. }
  961. }
  962. Db::commit();
  963. return app_show(0,"提交成功");
  964. }else{
  965. Db::rollback();
  966. return error_show(1004,"提交失败");
  967. }
  968. }
  969. public function online_exam(){
  970. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  971. if($skuCode===""){
  972. return error_show(1004,"参数skuCode不能为空");
  973. }
  974. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  975. if($platform==false){
  976. return error_show(1004,"未找到数据");
  977. }
  978. $exam_status=isset($this->post['exam_status'])&&$this->post['exam_status']!==""?intval($this->post['exam_status']):"";
  979. // if($exam_status===""){
  980. // return error_show(1004,"参数exam_status不能为空");
  981. // }
  982. if($exam_status==3){
  983. $online_time= isset($this->post['online_time'])&&$this->post['online_time']!==""?$this->post['online_time']:"";
  984. if($online_time===""){
  985. return error_show(1004,"参数online_time不能为空");
  986. }
  987. $platform['online_time']=$online_time;
  988. }
  989. if($exam_status==6){
  990. $good_code= isset($this->post['plat_code'])&&$this->post['plat_code']!==""?trim($this->post['plat_code']):"";
  991. if($good_code===""){
  992. return error_show(1004,"参数plat_code不能为空");
  993. }
  994. $platform['plat_code']=$good_code;
  995. }
  996. $exam_remark = isset($this->post['exam_remark'])&&$this->post['exam_remark']!==""?trim($this->post['exam_remark']):"";
  997. $platform['exam_status']=$exam_status;
  998. $platform['updatetime']=date("Y-m-d H:i:s");
  999. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1000. if($token==''){
  1001. return error_show(105,"参数token不能为空");
  1002. }
  1003. $user =GetUserInfo($token);
  1004. if(empty($user)||$user['code']!=0){
  1005. return error_show(1002,"用户数据不存在");
  1006. }
  1007. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1008. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1009. Db::startTrans();
  1010. try {
  1011. $up = Db::name("good_platform")->save($platform);
  1012. if($up){
  1013. $data=[
  1014. "code"=>$platform['skuCode'],
  1015. "exam_status"=>$exam_status,
  1016. "type"=>2,
  1017. "exam_id"=>$createrid,
  1018. "exam_name"=>$creater,
  1019. "exam_remark"=>$exam_remark,
  1020. "addtime"=>date("Y-m-d H:i:s")
  1021. ];
  1022. $inr=Db::name("good_exam")->insert($data);
  1023. if($inr){
  1024. Db::commit();
  1025. return app_show(0,"审核成功");
  1026. }else{
  1027. Db::rollback();
  1028. return error_show(1004,"审核失败");
  1029. }
  1030. }else{
  1031. Db::rollback();
  1032. return error_show(1004,"审核失败");
  1033. }
  1034. }catch (\Exception $e){
  1035. Db::rollback();
  1036. return error_show(1004,$e->getMessage());
  1037. }
  1038. }
  1039. public function editladder(){
  1040. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  1041. if($skuCode===""){
  1042. return error_show(1004,"参数skuCode不能为空");
  1043. }
  1044. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  1045. if($platform==false){
  1046. return error_show(1004,"未找到数据");
  1047. }
  1048. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])?$this->post['good_ladder']:"";
  1049. if($good_ladder==""){
  1050. return error_show(1004,"参数good_ladder不能为空");
  1051. }
  1052. $proof_type = isset($this->post['proof_type'])&&$this->post['proof_type']!==""?intval($this->post['proof_type']):"";
  1053. if($proof_type===""){
  1054. return error_show(1004,"参数proof_type不能为空");
  1055. }
  1056. $proof_url = isset($this->post['proof_url'])&&$this->post['proof_url']!==""?trim($this->post['proof_url']):"";
  1057. if($proof_url===""){
  1058. return error_show(1004,"参数proof_url不能为空");
  1059. }
  1060. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1061. if($token==''){
  1062. return error_show(105,"参数token不能为空");
  1063. }
  1064. $user =GetUserInfo($token);
  1065. if(empty($user)||$user['code']!=0){
  1066. return error_show(1002,"用户数据不存在");
  1067. }
  1068. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1069. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1070. $platform['exam_status']=4;
  1071. $platform['updatetime']=date("Y-m-d H:i:s");
  1072. Db::startTrans();
  1073. try {
  1074. foreach ($good_ladder as $value){
  1075. $lemp=[];
  1076. isset($value["id"])&&$value["id"]!=""?$lemp['id']=$value['id']:"";
  1077. $lemp['skuCode']=$skuCode;
  1078. $lemp['min_num'] = $value['min_num'];
  1079. $lemp['max_num'] = 0;
  1080. $lemp['sale_price'] = $value['sale_price'];
  1081. $lemp['market_price'] = $value['market_price'];
  1082. $lemp['market_platform'] = $value['market_platform'];
  1083. $lemp['status'] = $value['status'];
  1084. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1085. isset($value["id"])&&$value["id"]!=""?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  1086. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1087. $count = Db::name("good_ladder")->save($lemp);
  1088. if($count==false){
  1089. Db::rollback();
  1090. return app_show(1004,"商品起订价修改失败");
  1091. }
  1092. }
  1093. $up = Db::name("good_platform")->save($platform);
  1094. if($up){
  1095. $proof=[
  1096. 'spuCode'=>$platform['spuCode'],
  1097. 'proof_type'=>$proof_type,
  1098. 'proof_url'=>$proof_url,
  1099. 'is_del'=>0,
  1100. "creater"=>$creater,
  1101. "createrid"=>$createrid,
  1102. "addtime"=>date("Y-m-d H:i:s"),
  1103. "updatetime"=>date("Y-m-d H:i:s")
  1104. ];
  1105. $inproof = Db::name("good_proof")->insert($proof);
  1106. if($inproof==false){
  1107. Db::rollback();
  1108. return app_show(1004,"商品凭证新建失败");
  1109. }
  1110. $data=[
  1111. "code"=>$platform['skuCode'],
  1112. "type"=>2,
  1113. "exam_status"=>4,
  1114. "exam_id"=>$createrid,
  1115. "exam_name"=>$creater,
  1116. "exam_remark"=>'',
  1117. "addtime"=>date("Y-m-d H:i:s")
  1118. ];
  1119. $inr=Db::name("good_exam")->insert($data);
  1120. if($inr){
  1121. Db::commit();
  1122. return app_show(0,"审核成功");
  1123. }else{
  1124. Db::rollback();
  1125. return error_show(1004,"审核失败");
  1126. }
  1127. }else{
  1128. Db::rollback();
  1129. return error_show(1004,"审核失败");
  1130. }
  1131. }catch (\Exception $e){
  1132. Db::rollback();
  1133. return error_show(1004,$e->getMessage());
  1134. }
  1135. }
  1136. public function prooflist(){
  1137. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  1138. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  1139. $where =[["is_del","=",0]];
  1140. $spuCode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1141. if($spuCode!==""){
  1142. $where[]=["spuCode","like","%$spuCode%"];
  1143. }
  1144. $count = Db::name("good_proof")->where($where)->count();
  1145. $total = ceil($count / $size);
  1146. $page = $page >= $total ? $total : $page;
  1147. $data = Db::name("good_proof")->where($where)->page($page,$size)->order("addtime desc")->select();
  1148. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  1149. }
  1150. /**
  1151. *
  1152. */
  1153. public function againOnline(){
  1154. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  1155. if($skuCode===""){
  1156. return error_show(1004,"参数skuCode不能为空");
  1157. }
  1158. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  1159. if($platform==false){
  1160. return error_show(1004,"未找到数据");
  1161. }
  1162. if($platform["exam_status"]!=7&&$platform["exam_status"]!=8){
  1163. return error_show(1004,"商品状态有误");
  1164. }
  1165. $nake =Db::name("good_nake")->where(["spuCode"=>$platform['spuCode'],"is_del"=>0])->select()->toArray();
  1166. $platform['exam_status'] = empty($nake)?1:2;
  1167. $platform['updatetime'] = date("Y-m-d H:i:s");
  1168. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1169. if($token==''){
  1170. return error_show(105,"参数token不能为空");
  1171. }
  1172. $user =GetUserInfo($token);
  1173. if(empty($user)||$user['code']!=0){
  1174. return error_show(1002,"用户数据不存在");
  1175. }
  1176. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1177. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1178. Db::startTrans();
  1179. try {
  1180. $save =Db::name("good_platform")->save($platform);
  1181. if($save){
  1182. $data=[
  1183. "code"=>$platform['skuCode'],
  1184. "type"=>2,
  1185. "exam_status"=>$platform['exam_status'] ,
  1186. "exam_id"=>$createrid,
  1187. "exam_name"=>$creater,
  1188. "exam_remark"=>'',
  1189. "addtime"=>date("Y-m-d H:i:s")
  1190. ];
  1191. $inr=Db::name("good_exam")->insert($data);
  1192. if($inr){
  1193. Db::commit();
  1194. return app_show(0,"审核成功");
  1195. }
  1196. }
  1197. Db::rollback();
  1198. return error_show(1004,"审核失败");
  1199. }catch (\Exception $e){
  1200. Db::rollback();
  1201. return error_show(1004,$e->getMessage());
  1202. }
  1203. }
  1204. public function copy(){
  1205. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1206. if($supcode==""){
  1207. return error_show(1004,"参数spuCode不能为空");
  1208. }
  1209. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1210. if($data==false){
  1211. return error_show(1004,"未找到商品数据");
  1212. }
  1213. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1214. if($token==''){
  1215. return error_show(105,"参数token不能为空");
  1216. }
  1217. $user =GetUserInfo($token);
  1218. if(empty($user)||$user['code']!=0){
  1219. return error_show(102,"用户数据不存在");
  1220. }
  1221. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1222. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1223. $nake = Db::name("good_nake")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  1224. $ladd=[];
  1225. $newCode =makeNo("SPU");
  1226. if(!empty($nake)){
  1227. foreach ($nake as $value){
  1228. $tmp=[];
  1229. $tmp['spuCode']=$newCode;
  1230. $tmp['min_num']=$value['min_num'];
  1231. $tmp['nake_fee']=$value['nake_fee'];
  1232. $tmp['cost_fee']=$value['cost_fee'];
  1233. $tmp['delivery_fee']=$value['delivery_fee'];
  1234. $tmp['is_del']=$value['is_del'];
  1235. $tmp['addtime']=date("Y-m-d H:i:s");
  1236. $tmp['updatetime']=date("Y-m-d H:i:s");
  1237. $ladd[]=$tmp;
  1238. }
  1239. }
  1240. $spec = Db::name("good_spec")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  1241. $specArr=[];
  1242. if(!empty($spec)){
  1243. foreach ($spec as $value){
  1244. $tmp=[];
  1245. $tmp['spuCode']=$newCode;
  1246. $tmp['spec_id']=$value['spec_id'];
  1247. $tmp['spec_value_id']=$value['spec_value_id'];
  1248. $tmp['is_del']=$value['is_del'];
  1249. $tmp['addtime']=date("Y-m-d H:i:s");
  1250. $tmp['updatetime']=date("Y-m-d H:i:s");
  1251. $specArr[]=$tmp;
  1252. }
  1253. }
  1254. Db::startTrans();
  1255. try {
  1256. unset($data['id']);
  1257. $data['spuCode']=$newCode;
  1258. $data['createrid']=$createrid;
  1259. $data['creater']=$creater;
  1260. $data['status']=7;
  1261. $data['addtime']=date("Y-m-d H:i:s");
  1262. $data['updatetime']=date("Y-m-d H:i:s");
  1263. $cre = Db::name("good_basic")->insert($data);
  1264. if($cre){
  1265. if(!empty($ladd)){
  1266. $na = Db::name("good_nake")->insertAll($ladd);
  1267. if($na==0){
  1268. Db::rollback();
  1269. return error_show(1005,"成本数据复制失败");
  1270. }
  1271. }
  1272. if(!empty($specArr)){
  1273. $sp = Db::name("good_spec")->insertAll($specArr);
  1274. if($sp==0){
  1275. Db::rollback();
  1276. return error_show(1005,"规格数据复制失败");
  1277. }
  1278. }
  1279. Db::commit();
  1280. return app_show(0,"复制数据成功",["spuCode"=>$newCode]);
  1281. }else{
  1282. Db::rollback();
  1283. return error_show(1005,"数据复制失败");
  1284. }
  1285. }catch (\Exception $e){
  1286. Db::rollback();
  1287. return error_show(1004,$e->getMessage());
  1288. }
  1289. }
  1290. public function edit(){
  1291. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1292. if($supcode==""){
  1293. return error_show(1004,"参数spuCode不能为空");
  1294. }
  1295. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1296. if($data==false){
  1297. return error_show(1004,"未找到商品数据");
  1298. }
  1299. if($data['status']!=6 &&$data['status']!=7 ){
  1300. return error_show(1004,"商品状态有误");
  1301. }
  1302. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):"";
  1303. if($good_name==""){
  1304. return error_show(1004,"商品名称不能为空");
  1305. }
  1306. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):"";
  1307. if($cat_id==''){
  1308. return error_show(1004,"商品分类不能为空");
  1309. }
  1310. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"0";
  1311. // if($brandid==''){
  1312. // return error_show(1004,"商品品牌不能为空");
  1313. // }
  1314. $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):"";
  1315. if($unit==''){
  1316. return error_show(1004,"商品单位不能为空");
  1317. }
  1318. $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type'])
  1319. :"";
  1320. if($good_type===''){
  1321. return error_show(1004,"参数good_type不能为空");
  1322. }
  1323. $moq=0;
  1324. $customized=0;
  1325. if($good_type==1){
  1326. $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):"";
  1327. if($moq===''){
  1328. return error_show(1004,"定制商品起订量不能为空");
  1329. }
  1330. $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  1331. if($customized===''){
  1332. return error_show(1004,"参数customized不能为空");
  1333. }
  1334. }
  1335. $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):"";
  1336. if($is_exclusive===''){
  1337. return error_show(1004,"参数is_exclusive不能为空");
  1338. }
  1339. // $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  1340. // if($customized===''){
  1341. // return error_show(1004,"参数customized不能为空");
  1342. // }
  1343. $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):"";
  1344. if($tax===''){
  1345. return error_show(1004,"参数tax不能为空");
  1346. }
  1347. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  1348. if($supplierNo==''){
  1349. return error_show(1004,"参数supplierNo不能为空");
  1350. }
  1351. $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size'])
  1352. :"";
  1353. if($good_size==''){
  1354. return error_show(1004,"参数good_size不能为空");
  1355. }
  1356. $company_id = isset($this->post['companyNo'])&&$this->post['companyNo']!=""? trim($this->post['companyNo'])
  1357. :"";
  1358. if($company_id==''){
  1359. return error_show(1004,"参数companyNo不能为空");
  1360. }
  1361. $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):"";
  1362. if($is_auth===''){
  1363. return error_show(1004,"参数is_auth不能为空");
  1364. }
  1365. $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):"";
  1366. // if($auth_img==''){
  1367. // return error_show(1004,"商品不能为空");
  1368. // }
  1369. $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):"";
  1370. if($after_sales==""){
  1371. return error_show(1004,"参数after_sales不能为空");
  1372. }
  1373. $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):"";
  1374. $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):"";
  1375. if($good_remark===""){
  1376. return error_show(1004,"参数good_remark不能为空");
  1377. }
  1378. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  1379. if($weight===""){
  1380. return error_show(1004,"参数weight不能为空");
  1381. }
  1382. $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):"";
  1383. if($packing_way===""){
  1384. return error_show(1004,"参数packing_way不能为空");
  1385. }
  1386. $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):"";
  1387. if($packing_size===""){
  1388. return error_show(1004,"参数packing_size不能为空");
  1389. }
  1390. $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):"";
  1391. if($packing_spec===""){
  1392. return error_show(1004,"参数packing_spec不能为空");
  1393. }
  1394. $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):"";
  1395. if($packing_weight===""){
  1396. return error_show(1004,"参数packing_weight不能为空");
  1397. }
  1398. $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):"";
  1399. if($packing_list===""){
  1400. return error_show(1004,"参数packing_list不能为空");
  1401. }
  1402. $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):"";
  1403. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  1404. if($supply_area===""){
  1405. return error_show(1004,"参数supply_area不能为空");
  1406. }
  1407. $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? $this->post['delivery_place']:"";
  1408. if($delivery_place===""){
  1409. return error_show(1004,"参数delivery_place不能为空");
  1410. }
  1411. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? $this->post['origin_place']:"";
  1412. if($origin_place===""){
  1413. return error_show(1004,"参数origin_place不能为空");
  1414. }
  1415. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):"";
  1416. if($delivery_day===""){
  1417. return error_show(1004,"参数delivery_day不能为空");
  1418. }
  1419. $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time'])
  1420. :"0";
  1421. // if($lead_time===""){
  1422. // return error_show(1004,"参数lead_time不能为空");
  1423. // }
  1424. $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0";
  1425. // if($sample_day===""){
  1426. // return error_show(1004,"参数sample_day不能为空");
  1427. // }
  1428. $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0";
  1429. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!==""? trim($this->post['good_img']):"";
  1430. // if($good_img===""){
  1431. // return error_show(1004,"参数good_img不能为空");
  1432. // }
  1433. $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):"";
  1434. if($good_thumb_img===""){
  1435. return error_show(1004,"参数good_thumb_img不能为空");
  1436. }
  1437. $good_info_img = isset($this->post['good_info_img'])&&!empty($this->post['good_info_img'])? $this->post['good_info_img']:"";
  1438. if($good_info_img===""){
  1439. return error_show(1004,"参数good_info_img不能为空");
  1440. }
  1441. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  1442. $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0";
  1443. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  1444. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  1445. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  1446. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  1447. $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0";
  1448. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  1449. $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0";
  1450. $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):"";
  1451. if($market_price===""){
  1452. return error_show(1004,"参数market_price不能为空");
  1453. }
  1454. $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"";
  1455. if($nake_price===""){
  1456. return error_show(1004,"参数nake_price不能为空");
  1457. }
  1458. $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  1459. if($is_step===""){
  1460. return error_show(1004,"参数is_step不能为空");
  1461. }
  1462. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
  1463. if($is_step==1 && $good_ladder==""){
  1464. return error_show(1004,"启用阶梯,阶梯价不能为空");
  1465. }
  1466. $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:"";
  1467. Db::startTrans();
  1468. try {
  1469. $temp=[
  1470. "good_name"=>$good_name,
  1471. "cat_id"=>$cat_id,
  1472. 'brand_id'=>$brandid,
  1473. "good_unit"=>$unit,
  1474. "good_type"=>$good_type,
  1475. "companyNo"=>$company_id,
  1476. "moq"=>$moq,
  1477. "is_exclusive"=>$is_exclusive,
  1478. "customized"=>$customized,
  1479. "tax"=>$tax,
  1480. "supplierNo"=>$supplierNo,
  1481. "is_auth"=>$is_auth,
  1482. "good_size"=>$good_size,
  1483. "auth_img"=>$auth_img,
  1484. "after_sales"=>$after_sales,
  1485. "craft_desc"=>$craft_desc,
  1486. "good_remark"=>$good_remark,
  1487. "weight"=>$weight,
  1488. "packing_way"=>$packing_way,
  1489. "packing_size"=>$packing_size,
  1490. "packing_spec"=>$packing_spec,
  1491. "packing_list"=>$packing_list,
  1492. "packing_weight"=>$packing_weight,
  1493. "good_bar"=>$good_bar,
  1494. "supply_area"=>$supply_area,
  1495. "delivery_place"=>$delivery_place,
  1496. "origin_place"=>$origin_place,
  1497. "delivery_day"=>$delivery_day,
  1498. "lead_time"=>$lead_time,
  1499. "sample_day"=>$sample_day,
  1500. "sample_fee"=>$sample_fee,
  1501. "good_img"=>$good_img,
  1502. "good_thumb_img"=>$good_thumb_img,
  1503. "good_info_img"=>json_encode($good_info_img),
  1504. "cert_fee"=>$cert_fee,
  1505. "packing_fee"=>$packing_fee,
  1506. "cost_fee"=>$cost_fee,
  1507. "mark_fee"=>$mark_fee,
  1508. "demo_fee"=>$demo_fee,
  1509. "open_fee"=>$open_fee,
  1510. "noble_metal"=>$noble_metal,
  1511. "noble_weight"=>$noble_weight,
  1512. "is_gold_price"=>$is_gold_price,
  1513. "market_price"=>$market_price,
  1514. "nake_price"=>$nake_price,
  1515. "is_step"=>$is_step,
  1516. "status"=>"0",
  1517. "updatetime"=>date("Y-m-d H:i:s")
  1518. ];
  1519. $field = array_diff_assoc($temp,$data);
  1520. $temp['field_change'] =empty($field)?"":json_encode(array_keys($field));
  1521. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($temp);
  1522. if($up){
  1523. if($speclist!=="" && !empty($speclist)){
  1524. foreach ($speclist as $value){
  1525. $lemp=[];
  1526. isset($value["id"])?$lemp['id']=$value['id']:"";
  1527. $lemp['spuCode']=$supcode;
  1528. $lemp['spec_id'] = $value['spec_id'];
  1529. $lemp['spec_value_id'] = $value['spec_value_id'];
  1530. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1531. isset($value["id"])? $lemp['addtime'] = date("Y-m-d H:i:s"):"";
  1532. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1533. $count = Db::name("good_spec")->save($lemp);
  1534. if($count==false){
  1535. Db::rollback();
  1536. return app_show(1004,"商品规格值修改失败");
  1537. }
  1538. }
  1539. }
  1540. if($good_ladder!=="" && !empty($good_ladder)){
  1541. foreach ($good_ladder as $value){
  1542. $lemp=[];
  1543. isset($value["id"])?$lemp['id']=$value['id']:"";
  1544. $lemp['spuCode']=$supcode;
  1545. $lemp['min_num'] = $value['min_num'];
  1546. $lemp['nake_fee'] = $value['nake_fee'];
  1547. $lemp['cost_fee'] = $value['cost_fee'];
  1548. $lemp['delivery_fee'] = $value['delivery_fee'];
  1549. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1550. isset($value["id"])? $lemp['addtime'] = date("Y-m-d H:i:s"):"";
  1551. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1552. $count = Db::name("good_nake")->save($lemp);
  1553. if($count==false){
  1554. Db::rollback();
  1555. return app_show(1004,"商品规成本修改失败");
  1556. }
  1557. }
  1558. }
  1559. Db::commit();
  1560. return app_show(0,"更新成功");
  1561. }else{
  1562. Db::rollback();
  1563. return error_show(1005,"更新失败");
  1564. }
  1565. }catch (\Exception $e){
  1566. Db::rollback();
  1567. return error_show(1004,$e->getMessage());
  1568. }
  1569. }
  1570. public function checkPrice(){
  1571. $spuCode=isset($this->post['spuCode'])&&$this->post['spuCode']!=""? trim($this->post['spuCode']):"";
  1572. if($spuCode==""){
  1573. return error_show(1005,"参数spuCode不能为空");
  1574. }
  1575. $good =Db::name("good_basic")->where(["spuCode"=>$spuCode,"is_del"=>0])->find();
  1576. if($good==false){
  1577. return error_show(1005,"商品数据未找到");
  1578. }
  1579. // $nake_fee=isset($this->post['nake_fee'])&&$this->post['nake_fee']!="" ? floatval($this->post['nake_fee']):"";
  1580. // if($nake_fee==""){
  1581. // return error_show(1005,"参数nake_fee不能为空");
  1582. // }
  1583. $num=isset($this->post['min_num'])&&$this->post['min_num']!=="" ? intval($this->post['min_num']):"";
  1584. if($num==""){
  1585. return error_show(1005,"参数min_num不能为空");
  1586. }
  1587. $nakelist = Db::name("good_nake")->where(['spuCode'=>$spuCode,"is_del"=>0])->where([["min_num","<=",$num]])
  1588. ->order("min_num desc")->find();
  1589. if($nakelist==false){
  1590. return error_show(1010,"起订量不足");
  1591. }
  1592. $catinfo = Db::name("cat")->where(["id"=>$good['cat_id']])->find();
  1593. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1594. if($good['is_gold_price']==1){
  1595. $gold = Db::name("gold_price1")->where(["type"=>$good['noble_metal'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1596. ->find();
  1597. $saleprice = $good['open_fee']/$num + $good['weight']*$gold["price"] + $nakelist['cost_fee']/(1-$budget)*
  1598. $good['noble_weight']+$good['mark_fee']+$good['packing_fee']+$good['cert_fee']+$nakelist['nake_fee'];
  1599. }else{
  1600. $saleprice = $good['open_fee']/$num + $good['cost_fee']*
  1601. $good['noble_weight']+$good['mark_fee']+$good['packing_fee']+$good['cert_fee']+$nakelist['nake_fee']/(1-$budget);
  1602. }
  1603. return app_show(0,"获取成功",["sale_price"=>round($saleprice,2)]);
  1604. }
  1605. }