Goodup.php 53 KB

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