Goodup.php 81 KB

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