Goodup.php 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  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. $where[]=['cat_id',"=",$cat_id];
  21. }
  22. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']):"";
  23. if($good_name!==""){
  24. $where[]=['good_name',"like","%$good_name%"];
  25. }
  26. $spucode = isset($this->post['spucode']) && $this->post['spucode'] !=="" ? trim($this->post['spucode'])
  27. :"";
  28. if($spucode!==""){
  29. $where[]=['spuCode',"like","%$spucode%"];
  30. }
  31. $good_type = isset($this->post['good_type']) && $this->post['good_type'] !=="" ? trim($this->post['good_type'])
  32. :"";
  33. if($good_type!==""){
  34. $where[]=['good_type',"=",$good_type];
  35. }
  36. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo'])
  37. :"";
  38. if($companyNo!==""){
  39. $where[]=['companyNo',"like","%$companyNo%"];
  40. }
  41. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
  42. :"";
  43. if($supplierNo!==""){
  44. $where[]=['supplierNo',"like","%$supplierNo%"];
  45. }
  46. $brandid = isset($this->post['brandid']) && $this->post['brandid'] !=="" ? intval($this->post['brandid'])
  47. :"";
  48. if($brandid!==""){
  49. $where[]=['brand_id',"=",$brandid];
  50. }
  51. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status'])
  52. :"";
  53. if($status!==""){
  54. $where[]=['status',"=",$status];
  55. }
  56. $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  57. if($start!==""){
  58. $where[]=['addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
  59. }
  60. $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  61. if($end!==""){
  62. $where[]=['addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  63. }
  64. $count = Db::name('good_basic')->where($where)->count();
  65. $total = ceil($count / $size);
  66. $page = $page >= $total ? $total : $page;
  67. $list = Db::name('good_basic')->where($where)->page($page,$size)->order("addtime desc")->select();
  68. $data=[];
  69. foreach ($list as $value){
  70. $value["cat_info"]= made($value['cat_id'],[]);
  71. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  72. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  73. $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
  74. $value['unit'] =isset($unit['unit'])?$unit['unit']:"";
  75. $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  76. $value['company'] = isset($company['company'])?$company['company']:"";
  77. $supplier = Db::name("supplier")->where(['code'=>$value['supplierNo']])->find();
  78. $value['supplier_name']=isset($supplier['name'])?$supplier['name']:"";
  79. // $value['status']=$value['exam_status'];
  80. $data[]=$value;
  81. }
  82. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  83. }
  84. public function create(){
  85. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):"";
  86. if($good_name==""){
  87. return error_show(1004,"商品名称不能为空");
  88. }
  89. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):"";
  90. if($cat_id==''){
  91. return error_show(1004,"商品分类不能为空");
  92. }
  93. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  94. if($brandid==''){
  95. return error_show(1004,"商品品牌不能为空");
  96. }
  97. $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):"";
  98. if($unit==''){
  99. return error_show(1004,"商品单位不能为空");
  100. }
  101. $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type'])
  102. :"";
  103. if($good_type===''){
  104. return error_show(1004,"参数good_type不能为空");
  105. }
  106. $moq=0;
  107. $customized=0;
  108. if($good_type==1){
  109. $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):"";
  110. if($moq===''){
  111. return error_show(1004,"定制商品起订量不能为空");
  112. }
  113. $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  114. if($customized===''){
  115. return error_show(1004,"参数customized不能为空");
  116. }
  117. }
  118. $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):"";
  119. if($is_exclusive===''){
  120. return error_show(1004,"参数is_exclusive不能为空");
  121. }
  122. // $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  123. // if($customized===''){
  124. // return error_show(1004,"参数customized不能为空");
  125. // }
  126. $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):"";
  127. if($tax===''){
  128. return error_show(1004,"参数tax不能为空");
  129. }
  130. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  131. if($supplierNo==''){
  132. return error_show(1004,"参数supplierNo不能为空");
  133. }
  134. $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size']):"";
  135. if($good_size==''){
  136. return error_show(1004,"参数good_size不能为空");
  137. }
  138. $company_id = isset($this->post['company_id'])&&$this->post['company_id']!=""? trim($this->post['company_id'])
  139. :"";
  140. if($company_id==''){
  141. return error_show(1004,"参数company_id不能为空");
  142. }
  143. $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):"";
  144. if($is_auth===''){
  145. return error_show(1004,"参数is_auth不能为空");
  146. }
  147. $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):"";
  148. // if($auth_img==''){
  149. // return error_show(1004,"商品不能为空");
  150. // }
  151. $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):"";
  152. if($after_sales==""){
  153. return error_show(1004,"参数after_sales不能为空");
  154. }
  155. $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):"";
  156. $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):"";
  157. if($good_remark===""){
  158. return error_show(1004,"参数good_remark不能为空");
  159. }
  160. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  161. if($weight===""){
  162. return error_show(1004,"参数weight不能为空");
  163. }
  164. $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):"";
  165. if($packing_way===""){
  166. return error_show(1004,"参数packing_way不能为空");
  167. }
  168. $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):"";
  169. if($packing_size===""){
  170. return error_show(1004,"参数packing_size不能为空");
  171. }
  172. $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):"";
  173. if($packing_spec===""){
  174. return error_show(1004,"参数packing_spec不能为空");
  175. }
  176. $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):"";
  177. if($packing_weight===""){
  178. return error_show(1004,"参数packing_weight不能为空");
  179. }
  180. $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):"";
  181. if($packing_list===""){
  182. return error_show(1004,"参数packing_list不能为空");
  183. }
  184. $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):"";
  185. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  186. if($supply_area===""){
  187. return error_show(1004,"参数supply_area不能为空");
  188. }
  189. $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? trim($this->post['delivery_place']):"";
  190. if($delivery_place===""){
  191. return error_show(1004,"参数delivery_place不能为空");
  192. }
  193. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? trim($this->post['origin_place']):"";
  194. if($origin_place===""){
  195. return error_show(1004,"参数origin_place不能为空");
  196. }
  197. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):"";
  198. if($delivery_day===""){
  199. return error_show(1004,"参数delivery_day不能为空");
  200. }
  201. $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time'])
  202. :"0";
  203. // if($lead_time===""){
  204. // return error_show(1004,"参数lead_time不能为空");
  205. // }
  206. $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0";
  207. // if($sample_day===""){
  208. // return error_show(1004,"参数sample_day不能为空");
  209. // }
  210. $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0";
  211. $is_stock = isset($this->post['is_stock'])&&$this->post['is_stock']!==""? intval($this->post['is_stock']):"";
  212. if($is_stock===""){
  213. return error_show(1004,"参数is_stock不能为空");
  214. }
  215. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!==""? trim($this->post['good_img']):"";
  216. // if($good_img===""){
  217. // return error_show(1004,"参数good_img不能为空");
  218. // }
  219. $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):"";
  220. if($good_thumb_img===""){
  221. return error_show(1004,"参数good_thumb_img不能为空");
  222. }
  223. $good_info_img = isset($this->post['good_info_img'])&&!empty($this->post['good_info_img'])? $this->post['good_info_img']:"";
  224. if($good_info_img===""){
  225. return error_show(1004,"参数good_info_img不能为空");
  226. }
  227. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  228. $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0";
  229. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  230. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  231. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  232. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  233. $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0";
  234. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  235. $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0";
  236. $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):"";
  237. if($market_price===""){
  238. return error_show(1004,"参数market_price不能为空");
  239. }
  240. $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"";
  241. if($nake_price===""){
  242. return error_show(1004,"参数nake_price不能为空");
  243. }
  244. $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  245. if($is_step===""){
  246. return error_show(1004,"参数is_step不能为空");
  247. }
  248. $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:"";
  249. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
  250. if($is_step==1 && $good_ladder==""){
  251. return error_show(1004,"启用阶梯,阶梯价不能为空");
  252. }
  253. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  254. if($token==''){
  255. return error_show(1005,"参数token不能为空");
  256. }
  257. $user =GetUserInfo($token);
  258. if(empty($user)||$user['code']!=0){
  259. return error_show(1002,"创建人数据不存在");
  260. }
  261. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  262. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  263. $spucode=makeNo("SPU");
  264. Db::startTrans();
  265. try {
  266. $data=[
  267. "spuCode"=>$spucode,
  268. "good_code"=>'',
  269. "good_name"=>$good_name,
  270. "cat_id"=>$cat_id,
  271. 'brand_id'=>$brandid,
  272. "good_unit"=>$unit,
  273. "good_type"=>$good_type,
  274. "moq"=>$moq,
  275. "is_exclusive"=>$is_exclusive,
  276. "customized"=>$customized,
  277. "companyNo"=>$company_id,
  278. "tax"=>$tax,
  279. "supplierNo"=>$supplierNo,
  280. "good_size"=>$good_size,
  281. "is_auth"=>$is_auth,
  282. "is_stock"=>$is_stock,
  283. "auth_img"=>$auth_img,
  284. "after_sales"=>$after_sales,
  285. "craft_desc"=>$craft_desc,
  286. "good_remark"=>$good_remark,
  287. "weight"=>$weight,
  288. "packing_way"=>$packing_way,
  289. "packing_size"=>$packing_size,
  290. "packing_spec"=>$packing_spec,
  291. "packing_list"=>$packing_list,
  292. "packing_weight"=>$packing_weight,
  293. "good_bar"=>$good_bar,
  294. "supply_area"=>$supply_area,
  295. "delivery_place"=>$delivery_place,
  296. "origin_place"=>$origin_place,
  297. "delivery_day"=>$delivery_day,
  298. "lead_time"=>$lead_time,
  299. "sample_day"=>$sample_day,
  300. "sample_fee"=>$sample_fee,
  301. "good_img"=>$good_img,
  302. "good_thumb_img"=>$good_thumb_img,
  303. "good_info_img"=>json_encode($good_info_img),
  304. "cert_fee"=>$cert_fee,
  305. "packing_fee"=>$packing_fee,
  306. "cost_fee"=>$cost_fee,
  307. "mark_fee"=>$mark_fee,
  308. "demo_fee"=>$demo_fee,
  309. "open_fee"=>$open_fee,
  310. "noble_metal"=>$noble_metal,
  311. "noble_weight"=>$noble_weight,
  312. "is_gold_price"=>$is_gold_price,
  313. "market_price"=>$market_price,
  314. "nake_price"=>$nake_price,
  315. "is_step"=>$is_step,
  316. "is_online"=>0,
  317. "status"=>0,
  318. "createrid"=>$createrid,
  319. "creater"=>$creater,
  320. "addtime"=>date("Y-m-d H:i:s"),
  321. "updatetime"=>date("Y-m-d H:i:s")
  322. ];
  323. $in = Db::name("good_basic")->insert($data);
  324. if($in){
  325. if($speclist!=="" && !empty($speclist)){
  326. $temp=[];
  327. foreach ($speclist as $value){
  328. $lemp=[];
  329. $lemp['spuCode']=$spucode;
  330. $lemp['spec_id'] = $value['spec_id'];
  331. $lemp['spec_value_id'] = $value['spec_value_id'];
  332. $lemp['addtime'] = date("Y-m-d H:i:s");
  333. $lemp['updatetime'] =date("Y-m-d H:i:s");
  334. $temp[]=$lemp;
  335. }
  336. $count = Db::name("good_spec")->insertAll($temp);
  337. if($count==0){
  338. Db::rollback();
  339. return app_show(1004,"商品规格值创建失败");
  340. }
  341. }
  342. if($good_ladder!=="" && !empty($good_ladder)){
  343. $temp=[];
  344. foreach ($good_ladder as $value){
  345. $lemp=[];
  346. $lemp['spuCode']=$spucode;
  347. $lemp['min_num'] = $value['min_num'];
  348. $lemp['nake_fee'] = $value['nake_fee'];
  349. $lemp['cost_fee'] = $value['cost_fee'];
  350. $lemp['delivery_fee'] = $value['delivery_fee'];
  351. $lemp['is_del'] = 0;
  352. $lemp['addtime'] = date("Y-m-d H:i:s");
  353. $lemp['updatetime'] =date("Y-m-d H:i:s");
  354. $temp[]=$lemp;
  355. }
  356. $count = Db::name("good_nake")->insertAll($temp);
  357. if($count==0){
  358. Db::rollback();
  359. return app_show(1004,"商品规格值创建失败");
  360. }
  361. }
  362. Db::commit();
  363. return app_show(0,"创建成功",["spuCode"=>$spucode]);
  364. }else{
  365. Db::rollback();
  366. return app_show(1004,"商品创建失败");
  367. }
  368. }catch (\Exception $e){
  369. Db::rollback();
  370. return app_show(1004,$e->getMessage());
  371. }
  372. }
  373. public function editinfo(){
  374. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  375. if($supcode==""){
  376. return error_show(1004,"参数spuCode不能为空");
  377. }
  378. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  379. if($data==false){
  380. return error_show(1004,"未找到商品数据");
  381. }
  382. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):"";
  383. if($good_name==""){
  384. return error_show(1004,"商品名称不能为空");
  385. }
  386. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):"";
  387. if($cat_id==''){
  388. return error_show(1004,"商品分类不能为空");
  389. }
  390. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"0";
  391. // if($brandid==''){
  392. // return error_show(1004,"商品品牌不能为空");
  393. // }
  394. $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):"";
  395. if($unit==''){
  396. return error_show(1004,"商品单位不能为空");
  397. }
  398. $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type'])
  399. :"";
  400. if($good_type===''){
  401. return error_show(1004,"参数good_type不能为空");
  402. }
  403. $moq=0;
  404. $customized=0;
  405. if($good_type==1){
  406. $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):"";
  407. if($moq===''){
  408. return error_show(1004,"定制商品起订量不能为空");
  409. }
  410. $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  411. if($customized===''){
  412. return error_show(1004,"参数customized不能为空");
  413. }
  414. }
  415. $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):"";
  416. if($is_exclusive===''){
  417. return error_show(1004,"参数is_exclusive不能为空");
  418. }
  419. // $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  420. // if($customized===''){
  421. // return error_show(1004,"参数customized不能为空");
  422. // }
  423. $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):"";
  424. if($tax===''){
  425. return error_show(1004,"参数tax不能为空");
  426. }
  427. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  428. if($supplierNo==''){
  429. return error_show(1004,"参数supplierNo不能为空");
  430. }
  431. $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size'])
  432. :"";
  433. if($good_size==''){
  434. return error_show(1004,"参数good_size不能为空");
  435. }
  436. $company_id = isset($this->post['company_id'])&&$this->post['company_id']!=""? trim($this->post['company_id'])
  437. :"";
  438. if($company_id==''){
  439. return error_show(1004,"参数company_id不能为空");
  440. }
  441. $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):"";
  442. if($is_auth===''){
  443. return error_show(1004,"参数is_auth不能为空");
  444. }
  445. $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):"";
  446. // if($auth_img==''){
  447. // return error_show(1004,"商品不能为空");
  448. // }
  449. $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):"";
  450. if($after_sales==""){
  451. return error_show(1004,"参数after_sales不能为空");
  452. }
  453. $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):"";
  454. $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):"";
  455. if($good_remark===""){
  456. return error_show(1004,"参数good_remark不能为空");
  457. }
  458. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  459. if($weight===""){
  460. return error_show(1004,"参数weight不能为空");
  461. }
  462. $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):"";
  463. if($packing_way===""){
  464. return error_show(1004,"参数packing_way不能为空");
  465. }
  466. $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):"";
  467. if($packing_size===""){
  468. return error_show(1004,"参数packing_size不能为空");
  469. }
  470. $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):"";
  471. if($packing_spec===""){
  472. return error_show(1004,"参数packing_spec不能为空");
  473. }
  474. $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):"";
  475. if($packing_weight===""){
  476. return error_show(1004,"参数packing_weight不能为空");
  477. }
  478. $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):"";
  479. if($packing_list===""){
  480. return error_show(1004,"参数packing_list不能为空");
  481. }
  482. $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):"";
  483. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  484. if($supply_area===""){
  485. return error_show(1004,"参数supply_area不能为空");
  486. }
  487. $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? $this->post['delivery_place']:"";
  488. if($delivery_place===""){
  489. return error_show(1004,"参数delivery_place不能为空");
  490. }
  491. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? $this->post['origin_place']:"";
  492. if($origin_place===""){
  493. return error_show(1004,"参数origin_place不能为空");
  494. }
  495. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):"";
  496. if($delivery_day===""){
  497. return error_show(1004,"参数delivery_day不能为空");
  498. }
  499. $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time'])
  500. :"0";
  501. // if($lead_time===""){
  502. // return error_show(1004,"参数lead_time不能为空");
  503. // }
  504. $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0";
  505. // if($sample_day===""){
  506. // return error_show(1004,"参数sample_day不能为空");
  507. // }
  508. $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0";
  509. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!==""? trim($this->post['good_img']):"";
  510. // if($good_img===""){
  511. // return error_show(1004,"参数good_img不能为空");
  512. // }
  513. $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):"";
  514. if($good_thumb_img===""){
  515. return error_show(1004,"参数good_thumb_img不能为空");
  516. }
  517. $good_info_img = isset($this->post['good_info_img'])&&!empty($this->post['good_info_img'])? $this->post['good_info_img']:"";
  518. if($good_info_img===""){
  519. return error_show(1004,"参数good_info_img不能为空");
  520. }
  521. $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:"";
  522. Db::startTrans();
  523. try {
  524. $temp=[
  525. "good_name"=>$good_name,
  526. "cat_id"=>$cat_id,
  527. 'brand_id'=>$brandid,
  528. "good_unit"=>$unit,
  529. "good_type"=>$good_type,
  530. "companyNo"=>$company_id,
  531. "moq"=>$moq,
  532. "is_exclusive"=>$is_exclusive,
  533. "customized"=>$customized,
  534. "tax"=>$tax,
  535. "supplierNo"=>$supplierNo,
  536. "is_auth"=>$is_auth,
  537. "good_size"=>$good_size,
  538. "auth_img"=>$auth_img,
  539. "after_sales"=>$after_sales,
  540. "craft_desc"=>$craft_desc,
  541. "good_remark"=>$good_remark,
  542. "weight"=>$weight,
  543. "packing_way"=>$packing_way,
  544. "packing_size"=>$packing_size,
  545. "packing_spec"=>$packing_spec,
  546. "packing_list"=>$packing_list,
  547. "packing_weight"=>$packing_weight,
  548. "good_bar"=>$good_bar,
  549. "supply_area"=>$supply_area,
  550. "delivery_place"=>$delivery_place,
  551. "origin_place"=>$origin_place,
  552. "delivery_day"=>$delivery_day,
  553. "lead_time"=>$lead_time,
  554. "sample_day"=>$sample_day,
  555. "sample_fee"=>$sample_fee,
  556. "good_img"=>$good_img,
  557. "good_thumb_img"=>$good_thumb_img,
  558. "good_info_img"=>json_encode($good_info_img),
  559. "status"=>"3",
  560. "updatetime"=>date("Y-m-d H:i:s")
  561. ];
  562. $field = array_diff_assoc($temp,$data);
  563. $temp['field_change'] =empty($field)?"":json_encode(array_keys($field));
  564. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($temp);
  565. if($up){
  566. if($speclist!=="" && !empty($speclist)){
  567. foreach ($speclist as $value){
  568. $lemp=[];
  569. isset($value["id"])?$lemp['id']=$value['id']:"";
  570. $lemp['spuCode']=$supcode;
  571. $lemp['spec_id'] = $value['spec_id'];
  572. $lemp['spec_value_id'] = $value['spec_value_id'];
  573. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  574. isset($value["id"])? $lemp['addtime'] = date("Y-m-d H:i:s"):"";
  575. $lemp['updatetime'] =date("Y-m-d H:i:s");
  576. $count = Db::name("good_spec")->save($lemp);
  577. if($count==false){
  578. Db::rollback();
  579. return app_show(1004,"商品规格值修改失败");
  580. }
  581. }
  582. }
  583. Db::commit();
  584. return app_show(0,"更新成功");
  585. }else{
  586. Db::rollback();
  587. return error_show(1005,"更新失败");
  588. }
  589. }catch (\Exception $e){
  590. Db::rollback();
  591. return error_show(1004,$e->getMessage());
  592. }
  593. }
  594. public function editfee(){
  595. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  596. if($supcode==""){
  597. return error_show(1004,"参数spuCode不能为空");
  598. }
  599. $datas = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  600. if($datas==false){
  601. return error_show(1004,"未找到商品数据");
  602. }
  603. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  604. $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0";
  605. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  606. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  607. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  608. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  609. $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0";
  610. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  611. $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0";
  612. $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):"";
  613. if($market_price===""){
  614. return error_show(1004,"参数market_price不能为空");
  615. }
  616. $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"";
  617. if($nake_price===""){
  618. return error_show(1004,"参数nake_price不能为空");
  619. }
  620. $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  621. if($is_step===""){
  622. return error_show(1004,"参数is_step不能为空");
  623. }
  624. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
  625. if($is_step==1 && $good_ladder==""){
  626. return error_show(1004,"启用阶梯,阶梯价不能为空");
  627. }
  628. $data=[
  629. "cert_fee"=>$cert_fee,
  630. "packing_fee"=>$packing_fee,
  631. "cost_fee"=>$cost_fee,
  632. "mark_fee"=>$mark_fee,
  633. "demo_fee"=>$demo_fee,
  634. "open_fee"=>$open_fee,
  635. "noble_metal"=>$noble_metal,
  636. "noble_weight"=>$noble_weight,
  637. "is_gold_price"=>$is_gold_price,
  638. "market_price"=>$market_price,
  639. "nake_price"=>$nake_price,
  640. "is_step"=>$is_step,
  641. "status"=>"2",
  642. "updatetime"=>date("Y-m-d H:i:s")
  643. ];
  644. $field = array_diff_assoc($data,$datas);
  645. $data['field_change'] =empty($field)?"":json_encode(array_keys($field));
  646. Db::startTrans();
  647. try{
  648. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($data);
  649. if($up){
  650. $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")]);
  651. if($good_ladder!=="" && !empty($good_ladder)){
  652. foreach ($good_ladder as $value){
  653. $lemp=[];
  654. isset($value["id"])?$lemp['id']=$value['id']:"";
  655. $lemp['spuCode']=$supcode;
  656. $lemp['min_num'] = $value['min_num'];
  657. $lemp['nake_fee'] = $value['nake_fee'];
  658. $lemp['cost_fee'] = $value['cost_fee'];
  659. $lemp['delivery_fee'] = $value['delivery_fee'];
  660. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  661. isset($value["id"])? $lemp['addtime'] = date("Y-m-d H:i:s"):"";
  662. $lemp['updatetime'] =date("Y-m-d H:i:s");
  663. $count = Db::name("good_nake")->save($lemp);
  664. if($count==false){
  665. Db::rollback();
  666. return app_show(1004,"商品规成本修改失败");
  667. }
  668. }
  669. }
  670. Db::commit();
  671. return app_show(0,"更新成功");
  672. }else{
  673. Db::rollback();
  674. return error_show(1005,"更新失败");
  675. }
  676. }catch (\Exception $e){
  677. Db::rollback();
  678. return error_show(1005,$e->getMessage());
  679. }
  680. }
  681. public function exam(){
  682. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  683. if($supcode==""){
  684. return error_show(1004,"参数spuCode不能为空");
  685. }
  686. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  687. if($data==false){
  688. return error_show(1004,"未找到商品数据");
  689. }
  690. if($data['status']==1){
  691. return error_show(1004,"商品已审核通过");
  692. }
  693. $status = isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):"";
  694. // if($status===""){
  695. // return error_show(1004,"参数status不能为空");
  696. // }
  697. $remark = isset($this->post['remark'])&&$this->post['remark']!=="" ? trim($this->post['remark']):"";
  698. // if($remark===""){
  699. // return error_show(1004,"参数remark不能为空");
  700. // }
  701. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  702. if($token==''){
  703. return error_show(1005,"参数token不能为空");
  704. }
  705. $user =GetUserInfo($token);
  706. if(empty($user)||$user['code']!=0){
  707. return error_show(1002,"用户数据不存在");
  708. }
  709. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  710. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  711. Db::startTrans();
  712. try {
  713. if($data['status']==3){
  714. $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")]);
  715. }
  716. $data['status']=$status;
  717. $data['updatetime']=date("Y-m-d H:i:s");
  718. $up= Db::name("good_basic")->save($data);
  719. if($up){
  720. $data=[
  721. "code"=>$supcode,
  722. "exam_status"=>$status,
  723. "type"=>1,
  724. "exam_id"=>$createrid,
  725. "exam_name"=>$creater,
  726. "exam_remark"=>$remark,
  727. "addtime"=>date("Y-m-d H:i:s")
  728. ];
  729. $inr=Db::name("good_exam")->insert($data);
  730. if($inr){
  731. Db::commit();
  732. return app_show(0,"审核成功");
  733. }else{
  734. Db::rollback();
  735. return error_show(1004,"审核失败");
  736. }
  737. }else{
  738. Db::rollback();
  739. return error_show(1004,"审核失败");
  740. }
  741. }catch (\Exception $e){
  742. Db::rollback();
  743. return error_show(1004,$e->getMessage());
  744. }
  745. }
  746. public function info(){
  747. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  748. if($supcode==""){
  749. return error_show(1004,"参数spuCode不能为空");
  750. }
  751. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  752. if($data==false){
  753. return error_show(1004,"未找到商品数据");
  754. }
  755. $unit =Db::name("unit")->where(["id"=>$data['good_unit']])->find();
  756. $data['unit'] = isset($unit['unit'])?$unit['unit']:'';
  757. $data['cat_info'] = made($data['cat_id'],[]);
  758. $spec = Db::name("good_spec")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  759. $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  760. $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  761. $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  762. $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  763. $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find();
  764. $data['company'] = isset($company['company'])?$company['company']:"";
  765. $data['field_change'] = $data['field_change']!=''?json_decode($data['field_change']):"";
  766. if($data['brand_id']!=0){
  767. $brand=Db::name("brand")->where(["id"=>$data['brand_id']])->find();
  768. $data["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  769. }else{
  770. $data["brand_name"]="";
  771. $data["brand_id"]="";
  772. }
  773. $data["good_info_img"]=$data['good_info_img']!=""? json_decode($data['good_info_img'],true):[];
  774. $speclist=[];
  775. if(!empty($spec)){
  776. foreach ($spec as $value){
  777. $temp=[];
  778. $temp['id']=$value['id'];
  779. $temp['spuCode']=$value['spuCode'];
  780. $temp['spec_id']=$value['spec_id'];
  781. $temp['spec_value_id']=$value['spec_value_id'];
  782. $temp['is_del']=$value['is_del'];
  783. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  784. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  785. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  786. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  787. $speclist[]=$temp;
  788. }
  789. }
  790. $data["speclist"]=empty($speclist)?[]:$speclist;
  791. // $nake=[];
  792. $nakelist = Db::name("good_nake")->where(['spuCode'=>$supcode,"is_del"=>0])->select()->toArray();
  793. $data["nakelist"]=!empty($nakelist)?$nakelist:[];
  794. return app_show(0,"获取成功",$data);
  795. }
  796. public function delall(){
  797. $supcode = isset($this->post['codes'])&&!empty($this->post['codes'])? $this->post['codes']:"";
  798. if($supcode==""){
  799. return error_show(1004,"参数codes不能为空");
  800. }
  801. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  802. if(empty($data)){
  803. return error_show(1004,"未找到商品数据");
  804. }
  805. $up= Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save(["is_del"=>1]);
  806. if($up){
  807. return app_show(0,"更新成功");
  808. }else{
  809. return error_show(1005,"更新失败");
  810. }
  811. }
  812. public function online(){
  813. $platform =isset($this->post['platform'])&&!empty($this->post['platform'])? $this->post['platform']:"";
  814. if($platform==""){
  815. return error_show(1004,"参数codes不能为空");
  816. }
  817. $spuCode =isset($this->post['codes'])&&!empty($this->post['codes'])? $this->post['codes']:"";
  818. if($spuCode===''){
  819. return error_show(1004,"参数codes不能为空");
  820. }
  821. $datas = Db::name("good_basic")->where(["spuCode"=>$spuCode,"is_del"=>0])->select()->toArray();
  822. if(empty($datas)){
  823. return error_show(1004,"未找到商品数据");
  824. }
  825. $online_reason = isset($this->post['online_reason'])&&$this->post['online_reason']!==""? trim($this->post['online_reason']):"";
  826. if($online_reason===""){
  827. return error_show(1004,"参数online_reason不能为空");
  828. }
  829. $online_remark= isset($this->post['online_remark'])&&$this->post['online_remark']!==""? trim($this->post['online_remark']):"";
  830. if($online_remark===""){
  831. return error_show(1004,"参数online_remark不能为空");
  832. }
  833. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  834. if($token==''){
  835. return error_show(1005,"参数token不能为空");
  836. }
  837. $user =GetUserInfo($token);
  838. if(empty($user)||$user['code']!=0){
  839. return error_show(1002,"用户数据不存在");
  840. }
  841. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  842. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  843. $data=[];
  844. foreach ($spuCode as $value){
  845. $count = Db::name("good_nake")->where(["spuCode"=>$value,"is_del"=>0])->count();
  846. $data[]=[
  847. "spuCode"=>$value,
  848. "skuCode"=>makeNo("SKU"),
  849. "platform_code"=>$platform,
  850. "online_reason"=>$online_reason,
  851. "online_remark"=>$online_remark,
  852. "exam_status"=>$count>0 ?3:2,
  853. "is_online"=>0,
  854. "status"=>1,
  855. "is_del"=>0,
  856. "creater"=>$creater,
  857. "createrid"=>$createrid,
  858. "addtime"=>date("Y-m-d H:i:s"),
  859. "updatetime"=>date("Y-m-d H:i:s")
  860. ];
  861. }
  862. Db::startTrans();
  863. $create =Db::name("good_platform")->insertAll($data);
  864. if($create){
  865. foreach ($datas as $value){
  866. $iso = Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  867. if($iso==false){
  868. unset($value['id']);
  869. $value['creater']=$creater;
  870. $value['createrid']=$createrid;
  871. $value['addtime']=date("Y-m-d H:i:s");
  872. $value['updatetime']=date("Y-m-d H:i:s");
  873. }else{
  874. $value['id']=$iso['id'];
  875. $value['creater']=$creater;
  876. $value['createrid']=$createrid;
  877. $value['updatetime']=date("Y-m-d H:i:s");
  878. }
  879. $up =Db::name("good")->save($value);
  880. if(!$up){
  881. Db::rollback();
  882. return error_show(1004,"提交失败");
  883. }
  884. }
  885. Db::commit();
  886. return app_show(0,"提交成功");
  887. }else{
  888. Db::rollback();
  889. return error_show(1004,"提交失败");
  890. }
  891. }
  892. public function online_exam(){
  893. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  894. if($skuCode===""){
  895. return error_show(1004,"参数skuCode不能为空");
  896. }
  897. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  898. if($platform==false){
  899. return error_show(1004,"未找到数据");
  900. }
  901. $exam_status=isset($this->post['exam_status'])&&$this->post['exam_status']!==""?intval($this->post['exam_status']):"";
  902. // if($exam_status===""){
  903. // return error_show(1004,"参数exam_status不能为空");
  904. // }
  905. if($exam_status==3){
  906. $online_time= isset($this->post['online_time'])&&$this->post['online_time']!==""?$this->post['online_time']:"";
  907. if($online_time===""){
  908. return error_show(1004,"参数online_time不能为空");
  909. }
  910. $platform['online_time']=$online_time;
  911. }
  912. if($exam_status==6){
  913. $good_code= isset($this->post['plat_code'])&&$this->post['plat_code']!==""?trim($this->post['plat_code']):"";
  914. if($good_code===""){
  915. return error_show(1004,"参数plat_code不能为空");
  916. }
  917. $platform['plat_code']=$good_code;
  918. }
  919. $exam_remark = isset($this->post['exam_remark'])&&$this->post['exam_remark']!==""?trim($this->post['exam_remark']):"";
  920. $platform['exam_status']=$exam_status;
  921. $platform['updatetime']=date("Y-m-d H:i:s");
  922. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  923. if($token==''){
  924. return error_show(1005,"参数token不能为空");
  925. }
  926. $user =GetUserInfo($token);
  927. if(empty($user)||$user['code']!=0){
  928. return error_show(1002,"用户数据不存在");
  929. }
  930. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  931. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  932. Db::startTrans();
  933. try {
  934. $up = Db::name("good_platform")->save($platform);
  935. if($up){
  936. $data=[
  937. "code"=>$platform['skuCode'],
  938. "exam_status"=>$exam_status,
  939. "type"=>2,
  940. "exam_id"=>$createrid,
  941. "exam_name"=>$creater,
  942. "exam_remark"=>$exam_remark,
  943. "addtime"=>date("Y-m-d H:i:s")
  944. ];
  945. $inr=Db::name("good_exam")->insert($data);
  946. if($inr){
  947. Db::commit();
  948. return app_show(0,"审核成功");
  949. }else{
  950. Db::rollback();
  951. return error_show(1004,"审核失败");
  952. }
  953. }else{
  954. Db::rollback();
  955. return error_show(1004,"审核失败");
  956. }
  957. }catch (\Exception $e){
  958. Db::rollback();
  959. return error_show(1004,$e->getMessage());
  960. }
  961. }
  962. public function editladder(){
  963. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  964. if($skuCode===""){
  965. return error_show(1004,"参数skuCode不能为空");
  966. }
  967. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  968. if($platform==false){
  969. return error_show(1004,"未找到数据");
  970. }
  971. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])?$this->post['good_ladder']:"";
  972. if($good_ladder==""){
  973. return error_show(1004,"参数good_ladder不能为空");
  974. }
  975. $proof_type = isset($this->post['proof_type'])&&$this->post['proof_type']!==""?intval($this->post['proof_type']):"";
  976. if($proof_type===""){
  977. return error_show(1004,"参数proof_type不能为空");
  978. }
  979. $proof_url = isset($this->post['proof_url'])&&$this->post['proof_url']!==""?trim($this->post['proof_url']):"";
  980. if($proof_url===""){
  981. return error_show(1004,"参数proof_url不能为空");
  982. }
  983. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  984. if($token==''){
  985. return error_show(1005,"参数token不能为空");
  986. }
  987. $user =GetUserInfo($token);
  988. if(empty($user)||$user['code']!=0){
  989. return error_show(1002,"用户数据不存在");
  990. }
  991. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  992. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  993. $platform['exam_status']=4;
  994. $platform['updatetime']=date("Y-m-d H:i:s");
  995. Db::startTrans();
  996. try {
  997. foreach ($good_ladder as $value){
  998. $lemp=[];
  999. isset($value["id"])&&$value["id"]!=""?$lemp['id']=$value['id']:"";
  1000. $lemp['skuCode']=$skuCode;
  1001. $lemp['min_num'] = $value['min_num'];
  1002. $lemp['max_num'] = 0;
  1003. $lemp['sale_price'] = $value['sale_price'];
  1004. // $lemp['origin_price'] = $value['origin_price'];
  1005. $lemp['market_price'] = $value['market_price'];
  1006. $lemp['market_platform'] = $value['market_platform'];
  1007. // $lemp['origin_rate'] = $value['origin_rate'];
  1008. $lemp['status'] = $value['status'];
  1009. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1010. isset($value["id"])&&$value["id"]!=""?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  1011. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1012. // var_dump(isset($value["id"]));
  1013. $count = Db::name("good_ladder")->save($lemp);
  1014. if($count==false){
  1015. Db::rollback();
  1016. return app_show(1004,"商品起订价修改失败");
  1017. }
  1018. }
  1019. $up = Db::name("good_platform")->save($platform);
  1020. if($up){
  1021. $proof=[
  1022. 'spuCode'=>$platform['spuCode'],
  1023. 'proof_type'=>$proof_type,
  1024. 'proof_url'=>$proof_url,
  1025. 'is_del'=>0,
  1026. "creater"=>$creater,
  1027. "createrid"=>$createrid,
  1028. "addtime"=>date("Y-m-d H:i:s"),
  1029. "updatetime"=>date("Y-m-d H:i:s")
  1030. ];
  1031. $inproof = Db::name("good_proof")->insert($proof);
  1032. if($inproof==false){
  1033. Db::rollback();
  1034. return app_show(1004,"商品凭证新建失败");
  1035. }
  1036. $data=[
  1037. "code"=>$platform['skuCode'],
  1038. "type"=>2,
  1039. "exam_status"=>4,
  1040. "exam_id"=>$createrid,
  1041. "exam_name"=>$creater,
  1042. "exam_remark"=>'',
  1043. "addtime"=>date("Y-m-d H:i:s")
  1044. ];
  1045. $inr=Db::name("good_exam")->insert($data);
  1046. if($inr){
  1047. Db::commit();
  1048. return app_show(0,"审核成功");
  1049. }else{
  1050. Db::rollback();
  1051. return error_show(1004,"审核失败");
  1052. }
  1053. }else{
  1054. Db::rollback();
  1055. return error_show(1004,"审核失败");
  1056. }
  1057. }catch (\Exception $e){
  1058. Db::rollback();
  1059. return error_show(1004,$e->getMessage());
  1060. }
  1061. }
  1062. public function prooflist(){
  1063. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  1064. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  1065. $where =[["is_del","=",0]];
  1066. $spuCode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1067. if($spuCode!==""){
  1068. $where[]=["spuCode","like","%$spuCode%"];
  1069. }
  1070. $count = Db::name("good_proof")->where($where)->count();
  1071. $total = ceil($count / $size);
  1072. $page = $page >= $total ? $total : $page;
  1073. $data = Db::name("good_proof")->where($where)->page($page,$size)->order("addtime desc")->select();
  1074. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  1075. }
  1076. }