Goodup.php 81 KB

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