Goodup.php 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  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(1005,"参数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. $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:"";
  541. Db::startTrans();
  542. try {
  543. $temp=[
  544. "good_name"=>$good_name,
  545. "cat_id"=>$cat_id,
  546. 'brand_id'=>$brandid,
  547. "good_unit"=>$unit,
  548. "good_type"=>$good_type,
  549. "companyNo"=>$company_id,
  550. "moq"=>$moq,
  551. "is_exclusive"=>$is_exclusive,
  552. "customized"=>$customized,
  553. "tax"=>$tax,
  554. "supplierNo"=>$supplierNo,
  555. "is_auth"=>$is_auth,
  556. "good_size"=>$good_size,
  557. "auth_img"=>$auth_img,
  558. "after_sales"=>$after_sales,
  559. "craft_desc"=>$craft_desc,
  560. "good_remark"=>$good_remark,
  561. "weight"=>$weight,
  562. "packing_way"=>$packing_way,
  563. "packing_size"=>$packing_size,
  564. "packing_spec"=>$packing_spec,
  565. "packing_list"=>$packing_list,
  566. "packing_weight"=>$packing_weight,
  567. "good_bar"=>$good_bar,
  568. "supply_area"=>$supply_area,
  569. "delivery_place"=>$delivery_place,
  570. "origin_place"=>$origin_place,
  571. "delivery_day"=>$delivery_day,
  572. "lead_time"=>$lead_time,
  573. "sample_day"=>$sample_day,
  574. "sample_fee"=>$sample_fee,
  575. "good_img"=>$good_img,
  576. "good_thumb_img"=>$good_thumb_img,
  577. "good_info_img"=>json_encode($good_info_img),
  578. "status"=>"3",
  579. "updatetime"=>date("Y-m-d H:i:s")
  580. ];
  581. $field = array_diff_assoc($temp,$data);
  582. $temp['field_change'] =empty($field)?"":json_encode(array_keys($field));
  583. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($temp);
  584. if($up){
  585. if($speclist!=="" && !empty($speclist)){
  586. foreach ($speclist as $value){
  587. $lemp=[];
  588. isset($value["id"])?$lemp['id']=$value['id']:"";
  589. $lemp['spuCode']=$supcode;
  590. $lemp['spec_id'] = $value['spec_id'];
  591. $lemp['spec_value_id'] = $value['spec_value_id'];
  592. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  593. isset($value["id"])? $lemp['addtime'] = date("Y-m-d H:i:s"):"";
  594. $lemp['updatetime'] =date("Y-m-d H:i:s");
  595. $count = Db::name("good_spec")->save($lemp);
  596. if($count==false){
  597. Db::rollback();
  598. return app_show(1004,"商品规格值修改失败");
  599. }
  600. }
  601. }
  602. Db::commit();
  603. return app_show(0,"更新成功");
  604. }else{
  605. Db::rollback();
  606. return error_show(1005,"更新失败");
  607. }
  608. }catch (\Exception $e){
  609. Db::rollback();
  610. return error_show(1004,$e->getMessage());
  611. }
  612. }
  613. public function editfee(){
  614. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  615. if($supcode==""){
  616. return error_show(1004,"参数spuCode不能为空");
  617. }
  618. $datas = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  619. if($datas==false){
  620. return error_show(1004,"未找到商品数据");
  621. }
  622. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  623. $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0";
  624. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  625. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  626. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  627. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  628. $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0";
  629. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  630. $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0";
  631. $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):"";
  632. if($market_price===""){
  633. return error_show(1004,"参数market_price不能为空");
  634. }
  635. $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"";
  636. if($nake_price===""){
  637. return error_show(1004,"参数nake_price不能为空");
  638. }
  639. $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  640. if($is_step===""){
  641. return error_show(1004,"参数is_step不能为空");
  642. }
  643. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
  644. if($is_step==1 && $good_ladder==""){
  645. return error_show(1004,"启用阶梯,阶梯价不能为空");
  646. }
  647. $data=[
  648. "cert_fee"=>$cert_fee,
  649. "packing_fee"=>$packing_fee,
  650. "cost_fee"=>$cost_fee,
  651. "mark_fee"=>$mark_fee,
  652. "demo_fee"=>$demo_fee,
  653. "open_fee"=>$open_fee,
  654. "noble_metal"=>$noble_metal,
  655. "noble_weight"=>$noble_weight,
  656. "is_gold_price"=>$is_gold_price,
  657. "market_price"=>$market_price,
  658. "nake_price"=>$nake_price,
  659. "is_step"=>$is_step,
  660. "status"=>"2",
  661. "updatetime"=>date("Y-m-d H:i:s")
  662. ];
  663. $field = array_diff_assoc($data,$datas);
  664. $data['field_change'] =empty($field)?"":json_encode(array_keys($field));
  665. Db::startTrans();
  666. try{
  667. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($data);
  668. if($up){
  669. $online = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->save(["is_online"=>0,"status"=>0,"updatetime"=>date("Y-m-d H:i:s")]);
  670. if($good_ladder!=="" && !empty($good_ladder)){
  671. foreach ($good_ladder as $value){
  672. $lemp=[];
  673. isset($value["id"])?$lemp['id']=$value['id']:"";
  674. $lemp['spuCode']=$supcode;
  675. $lemp['min_num'] = $value['min_num'];
  676. $lemp['nake_fee'] = $value['nake_fee'];
  677. $lemp['cost_fee'] = $value['cost_fee'];
  678. $lemp['delivery_fee'] = $value['delivery_fee'];
  679. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  680. isset($value["id"])? $lemp['addtime'] = date("Y-m-d H:i:s"):"";
  681. $lemp['updatetime'] =date("Y-m-d H:i:s");
  682. $count = Db::name("good_nake")->save($lemp);
  683. if($count==false){
  684. Db::rollback();
  685. return app_show(1004,"商品规成本修改失败");
  686. }
  687. }
  688. }
  689. Db::commit();
  690. return app_show(0,"更新成功");
  691. }else{
  692. Db::rollback();
  693. return error_show(1005,"更新失败");
  694. }
  695. }catch (\Exception $e){
  696. Db::rollback();
  697. return error_show(1005,$e->getMessage());
  698. }
  699. }
  700. public function exam(){
  701. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  702. if($supcode==""){
  703. return error_show(1004,"参数spuCode不能为空");
  704. }
  705. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  706. if($data==false){
  707. return error_show(1004,"未找到商品数据");
  708. }
  709. if($data['status']==1){
  710. return error_show(1004,"商品已审核通过");
  711. }
  712. $status = isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):"";
  713. // if($status===""){
  714. // return error_show(1004,"参数status不能为空");
  715. // }
  716. $remark = isset($this->post['remark'])&&$this->post['remark']!=="" ? trim($this->post['remark']):"";
  717. // if($remark===""){
  718. // return error_show(1004,"参数remark不能为空");
  719. // }
  720. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  721. if($token==''){
  722. return error_show(1005,"参数token不能为空");
  723. }
  724. $user =GetUserInfo($token);
  725. if(empty($user)||$user['code']!=0){
  726. return error_show(1002,"用户数据不存在");
  727. }
  728. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  729. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  730. Db::startTrans();
  731. try {
  732. if($data['status']==3){
  733. $online = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_online"=>0,"status"=>0, "is_del"=>0])->save(["is_online"=>0,"status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  734. }
  735. $data['status']=$status;
  736. $data['updatetime']=date("Y-m-d H:i:s");
  737. $up= Db::name("good_basic")->save($data);
  738. if($up){
  739. $data=[
  740. "code"=>$supcode,
  741. "exam_status"=>$status,
  742. "type"=>1,
  743. "exam_id"=>$createrid,
  744. "exam_name"=>$creater,
  745. "exam_remark"=>$remark,
  746. "addtime"=>date("Y-m-d H:i:s")
  747. ];
  748. $inr=Db::name("good_exam")->insert($data);
  749. if($inr){
  750. Db::commit();
  751. return app_show(0,"审核成功");
  752. }else{
  753. Db::rollback();
  754. return error_show(1004,"审核失败");
  755. }
  756. }else{
  757. Db::rollback();
  758. return error_show(1004,"审核失败");
  759. }
  760. }catch (\Exception $e){
  761. Db::rollback();
  762. return error_show(1004,$e->getMessage());
  763. }
  764. }
  765. public function info(){
  766. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  767. if($supcode==""){
  768. return error_show(1004,"参数spuCode不能为空");
  769. }
  770. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  771. if($data==false){
  772. return error_show(1004,"未找到商品数据");
  773. }
  774. $unit =Db::name("unit")->where(["id"=>$data['good_unit']])->find();
  775. $data['unit'] = isset($unit['unit'])?$unit['unit']:'';
  776. $data['cat_info'] = made($data['cat_id'],[]);
  777. $spec = Db::name("good_spec")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  778. $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  779. $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  780. $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  781. $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  782. $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find();
  783. $data['company'] = isset($company['company'])?$company['company']:"";
  784. $data['field_change'] = $data['field_change']!=''?json_decode($data['field_change']):"";
  785. if($data['brand_id']!=0){
  786. $brand=Db::name("brand")->where(["id"=>$data['brand_id']])->find();
  787. $data["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  788. }else{
  789. $data["brand_name"]="";
  790. $data["brand_id"]="";
  791. }
  792. $excluse = makeExcluse($data['is_exclusive']);
  793. $data['exclusive']=$excluse;
  794. $data["good_info_img"]=$data['good_info_img']!=""? json_decode($data['good_info_img'],true):[];
  795. $speclist=[];
  796. if(!empty($spec)){
  797. foreach ($spec as $value){
  798. $temp=[];
  799. $temp['id']=$value['id'];
  800. $temp['spuCode']=$value['spuCode'];
  801. $temp['spec_id']=$value['spec_id'];
  802. $temp['spec_value_id']=$value['spec_value_id'];
  803. $temp['is_del']=$value['is_del'];
  804. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  805. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  806. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  807. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  808. $speclist[]=$temp;
  809. }
  810. }
  811. $data["speclist"]=empty($speclist)?[]:$speclist;
  812. // $nake=[];
  813. $nakelist = Db::name("good_nake")->where(['spuCode'=>$supcode,"is_del"=>0])->select()->toArray();
  814. $data["nakelist"]=!empty($nakelist)?$nakelist:[];
  815. return app_show(0,"获取成功",$data);
  816. }
  817. public function delall(){
  818. $supcode = isset($this->post['codes'])&&!empty($this->post['codes'])? $this->post['codes']:"";
  819. if($supcode==""){
  820. return error_show(1004,"参数codes不能为空");
  821. }
  822. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  823. if(empty($data)){
  824. return error_show(1004,"未找到商品数据");
  825. }
  826. $up= Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save(["is_del"=>1]);
  827. if($up){
  828. return app_show(0,"更新成功");
  829. }else{
  830. return error_show(1005,"更新失败");
  831. }
  832. }
  833. public function online(){
  834. $platform =isset($this->post['platform'])&&!empty($this->post['platform'])? $this->post['platform']:"";
  835. if($platform==""){
  836. return error_show(1004,"参数codes不能为空");
  837. }
  838. $spuCode =isset($this->post['codes'])&&!empty($this->post['codes'])? $this->post['codes']:"";
  839. if($spuCode===''){
  840. return error_show(1004,"参数codes不能为空");
  841. }
  842. $datas = Db::name("good_basic")->where(["spuCode"=>$spuCode,"is_del"=>0])->select()->toArray();
  843. if(empty($datas)){
  844. return error_show(1004,"未找到商品数据");
  845. }
  846. $online_reason = isset($this->post['online_reason'])&&$this->post['online_reason']!==""? trim($this->post['online_reason']):"";
  847. if($online_reason===""){
  848. return error_show(1004,"参数online_reason不能为空");
  849. }
  850. $online_remark= isset($this->post['online_remark'])&&$this->post['online_remark']!==""? trim($this->post['online_remark']):"";
  851. if($online_remark===""){
  852. return error_show(1004,"参数online_remark不能为空");
  853. }
  854. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  855. if($token==''){
  856. return error_show(1005,"参数token不能为空");
  857. }
  858. $user =GetUserInfo($token);
  859. if(empty($user)||$user['code']!=0){
  860. return error_show(1002,"用户数据不存在");
  861. }
  862. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  863. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  864. $data=[];
  865. foreach ($spuCode as $value){
  866. $count = Db::name("good_nake")->where(["spuCode"=>$value,"is_del"=>0])->count();
  867. $data[]=[
  868. "spuCode"=>$value,
  869. "skuCode"=>makeNo("SKU"),
  870. "platform_code"=>$platform,
  871. "online_reason"=>$online_reason,
  872. "online_remark"=>$online_remark,
  873. "exam_status"=>$count>0 ?3:2,
  874. "is_online"=>0,
  875. "status"=>1,
  876. "is_del"=>0,
  877. "creater"=>$creater,
  878. "createrid"=>$createrid,
  879. "addtime"=>date("Y-m-d H:i:s"),
  880. "updatetime"=>date("Y-m-d H:i:s")
  881. ];
  882. }
  883. Db::startTrans();
  884. $create =Db::name("good_platform")->insertAll($data);
  885. if($create){
  886. foreach ($datas as $value){
  887. $iso = Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  888. if($iso==false){
  889. unset($value['id']);
  890. $value['creater']=$creater;
  891. $value['createrid']=$createrid;
  892. $value['addtime']=date("Y-m-d H:i:s");
  893. $value['updatetime']=date("Y-m-d H:i:s");
  894. }else{
  895. $value['id']=$iso['id'];
  896. $value['creater']=$creater;
  897. $value['createrid']=$createrid;
  898. $value['updatetime']=date("Y-m-d H:i:s");
  899. }
  900. $up =Db::name("good")->save($value);
  901. if(!$up){
  902. Db::rollback();
  903. return error_show(1004,"提交失败");
  904. }
  905. }
  906. Db::commit();
  907. return app_show(0,"提交成功");
  908. }else{
  909. Db::rollback();
  910. return error_show(1004,"提交失败");
  911. }
  912. }
  913. public function online_exam(){
  914. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  915. if($skuCode===""){
  916. return error_show(1004,"参数skuCode不能为空");
  917. }
  918. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  919. if($platform==false){
  920. return error_show(1004,"未找到数据");
  921. }
  922. $exam_status=isset($this->post['exam_status'])&&$this->post['exam_status']!==""?intval($this->post['exam_status']):"";
  923. // if($exam_status===""){
  924. // return error_show(1004,"参数exam_status不能为空");
  925. // }
  926. if($exam_status==3){
  927. $online_time= isset($this->post['online_time'])&&$this->post['online_time']!==""?$this->post['online_time']:"";
  928. if($online_time===""){
  929. return error_show(1004,"参数online_time不能为空");
  930. }
  931. $platform['online_time']=$online_time;
  932. }
  933. if($exam_status==6){
  934. $good_code= isset($this->post['plat_code'])&&$this->post['plat_code']!==""?trim($this->post['plat_code']):"";
  935. if($good_code===""){
  936. return error_show(1004,"参数plat_code不能为空");
  937. }
  938. $platform['plat_code']=$good_code;
  939. }
  940. $exam_remark = isset($this->post['exam_remark'])&&$this->post['exam_remark']!==""?trim($this->post['exam_remark']):"";
  941. $platform['exam_status']=$exam_status;
  942. $platform['updatetime']=date("Y-m-d H:i:s");
  943. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  944. if($token==''){
  945. return error_show(1005,"参数token不能为空");
  946. }
  947. $user =GetUserInfo($token);
  948. if(empty($user)||$user['code']!=0){
  949. return error_show(1002,"用户数据不存在");
  950. }
  951. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  952. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  953. Db::startTrans();
  954. try {
  955. $up = Db::name("good_platform")->save($platform);
  956. if($up){
  957. $data=[
  958. "code"=>$platform['skuCode'],
  959. "exam_status"=>$exam_status,
  960. "type"=>2,
  961. "exam_id"=>$createrid,
  962. "exam_name"=>$creater,
  963. "exam_remark"=>$exam_remark,
  964. "addtime"=>date("Y-m-d H:i:s")
  965. ];
  966. $inr=Db::name("good_exam")->insert($data);
  967. if($inr){
  968. Db::commit();
  969. return app_show(0,"审核成功");
  970. }else{
  971. Db::rollback();
  972. return error_show(1004,"审核失败");
  973. }
  974. }else{
  975. Db::rollback();
  976. return error_show(1004,"审核失败");
  977. }
  978. }catch (\Exception $e){
  979. Db::rollback();
  980. return error_show(1004,$e->getMessage());
  981. }
  982. }
  983. public function editladder(){
  984. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  985. if($skuCode===""){
  986. return error_show(1004,"参数skuCode不能为空");
  987. }
  988. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  989. if($platform==false){
  990. return error_show(1004,"未找到数据");
  991. }
  992. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])?$this->post['good_ladder']:"";
  993. if($good_ladder==""){
  994. return error_show(1004,"参数good_ladder不能为空");
  995. }
  996. $proof_type = isset($this->post['proof_type'])&&$this->post['proof_type']!==""?intval($this->post['proof_type']):"";
  997. if($proof_type===""){
  998. return error_show(1004,"参数proof_type不能为空");
  999. }
  1000. $proof_url = isset($this->post['proof_url'])&&$this->post['proof_url']!==""?trim($this->post['proof_url']):"";
  1001. if($proof_url===""){
  1002. return error_show(1004,"参数proof_url不能为空");
  1003. }
  1004. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1005. if($token==''){
  1006. return error_show(1005,"参数token不能为空");
  1007. }
  1008. $user =GetUserInfo($token);
  1009. if(empty($user)||$user['code']!=0){
  1010. return error_show(1002,"用户数据不存在");
  1011. }
  1012. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1013. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1014. $platform['exam_status']=4;
  1015. $platform['updatetime']=date("Y-m-d H:i:s");
  1016. Db::startTrans();
  1017. try {
  1018. foreach ($good_ladder as $value){
  1019. $lemp=[];
  1020. isset($value["id"])&&$value["id"]!=""?$lemp['id']=$value['id']:"";
  1021. $lemp['skuCode']=$skuCode;
  1022. $lemp['min_num'] = $value['min_num'];
  1023. $lemp['max_num'] = 0;
  1024. $lemp['sale_price'] = $value['sale_price'];
  1025. // $lemp['origin_price'] = $value['origin_price'];
  1026. $lemp['market_price'] = $value['market_price'];
  1027. $lemp['market_platform'] = $value['market_platform'];
  1028. // $lemp['origin_rate'] = $value['origin_rate'];
  1029. $lemp['status'] = $value['status'];
  1030. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1031. isset($value["id"])&&$value["id"]!=""?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  1032. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1033. // var_dump(isset($value["id"]));
  1034. $count = Db::name("good_ladder")->save($lemp);
  1035. if($count==false){
  1036. Db::rollback();
  1037. return app_show(1004,"商品起订价修改失败");
  1038. }
  1039. }
  1040. $up = Db::name("good_platform")->save($platform);
  1041. if($up){
  1042. $proof=[
  1043. 'spuCode'=>$platform['spuCode'],
  1044. 'proof_type'=>$proof_type,
  1045. 'proof_url'=>$proof_url,
  1046. 'is_del'=>0,
  1047. "creater"=>$creater,
  1048. "createrid"=>$createrid,
  1049. "addtime"=>date("Y-m-d H:i:s"),
  1050. "updatetime"=>date("Y-m-d H:i:s")
  1051. ];
  1052. $inproof = Db::name("good_proof")->insert($proof);
  1053. if($inproof==false){
  1054. Db::rollback();
  1055. return app_show(1004,"商品凭证新建失败");
  1056. }
  1057. $data=[
  1058. "code"=>$platform['skuCode'],
  1059. "type"=>2,
  1060. "exam_status"=>4,
  1061. "exam_id"=>$createrid,
  1062. "exam_name"=>$creater,
  1063. "exam_remark"=>'',
  1064. "addtime"=>date("Y-m-d H:i:s")
  1065. ];
  1066. $inr=Db::name("good_exam")->insert($data);
  1067. if($inr){
  1068. Db::commit();
  1069. return app_show(0,"审核成功");
  1070. }else{
  1071. Db::rollback();
  1072. return error_show(1004,"审核失败");
  1073. }
  1074. }else{
  1075. Db::rollback();
  1076. return error_show(1004,"审核失败");
  1077. }
  1078. }catch (\Exception $e){
  1079. Db::rollback();
  1080. return error_show(1004,$e->getMessage());
  1081. }
  1082. }
  1083. public function prooflist(){
  1084. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  1085. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  1086. $where =[["is_del","=",0]];
  1087. $spuCode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1088. if($spuCode!==""){
  1089. $where[]=["spuCode","like","%$spuCode%"];
  1090. }
  1091. $count = Db::name("good_proof")->where($where)->count();
  1092. $total = ceil($count / $size);
  1093. $page = $page >= $total ? $total : $page;
  1094. $data = Db::name("good_proof")->where($where)->page($page,$size)->order("addtime desc")->select();
  1095. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  1096. }
  1097. }