StoreWholesale.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace app\admin\controller\ump;
  3. use app\admin\controller\AuthController;
  4. use app\admin\model\system\SystemGroupData;
  5. use app\models\store\StoreWholesale as Wholesale;
  6. use crmeb\services\{UtilService,JsonService as Json,UtilService as Util};
  7. class StoreWholesale extends AuthController
  8. {
  9. public function index()
  10. {
  11. $this->assign('countSeckill', Wholesale::getWholeCount());
  12. $this->assign('seckillId', Wholesale::getWholeIdAll());
  13. return $this->fetch();
  14. }
  15. public function save_excel()
  16. {
  17. $where = Util::getMore([
  18. ['status', ''],
  19. ['store_name', '']
  20. ]);
  21. Wholesale::SaveExcel($where);
  22. }
  23. /**
  24. * 异步获取砍价数据
  25. */
  26. public function getlist()
  27. {
  28. $where = UtilService::getMore([
  29. ['page', 1],
  30. ['limit', 20],
  31. ['status', ''],
  32. ['store_name', '']
  33. ]);
  34. $seckillList = Wholesale::systemPage($where);
  35. if (is_object($seckillList['list'])) $seckillList['list'] = $seckillList['list']->toArray();
  36. $data = $seckillList['list']['data'];
  37. foreach ($data as $k => $v) {
  38. $end_time = $v['stop_time'];
  39. if ($end_time) {
  40. $config = SystemGroupData::get($v['time_id']);
  41. if ($config) {
  42. $arr = json_decode($config->value, true);
  43. $start_hour = intval($arr['time']['value']);
  44. $continued = intval($arr['continued']['value']);
  45. $end_hour = $start_hour + $continued;
  46. $end_time = $end_time . ' ' . $end_hour . ':00:00';
  47. }
  48. }
  49. $data[$k]['_stop_time'] = $end_time;
  50. }
  51. return Json::successlayui(['count' => $seckillList['list']['total'], 'data' => $data]);
  52. }
  53. public function create($id=0)
  54. {
  55. $this->assign('id', (int)$id);
  56. return $this->fetch();
  57. }
  58. /**
  59. * 获取产品详细信息
  60. * @param int $id
  61. * @throws \think\db\exception\DataNotFoundException
  62. * @throws \think\db\exception\DbException
  63. * @throws \think\db\exception\ModelNotFoundException
  64. */
  65. public function get_product_info($id = 0)
  66. {
  67. $data['productInfo'] = [];
  68. if ($id) {
  69. $productInfo = Wholesale::get($id);
  70. $data['productInfo'] = $productInfo;
  71. }
  72. $data['time_id'] = sys_data('whole_time');
  73. return Json::successful($data);
  74. }
  75. /**
  76. * 保存新建的资源
  77. *
  78. *
  79. */
  80. public function save($id)
  81. {
  82. $data = Util::postMore([
  83. 'title',
  84. 'info',
  85. 'keyword',
  86. ['unit_name', '件'],
  87. ['image', []],
  88. ['images', []],
  89. ['price',0],
  90. ['cost',0],
  91. ['postage', 0],
  92. ['ot_price', 0],
  93. ['give_integral', 0],
  94. ['sort',0],
  95. ['stock', 0],
  96. ['description', ''],
  97. ['start_time', ''],
  98. ['stop_time', ''],
  99. ['time_id', 0],
  100. ['is_hot', 0],
  101. ['is_news', 0],
  102. ['num', 1],
  103. ['is_show',1]
  104. ]);
  105. if (count($data['image']) < 1) return Json::fail('请上传产品图片');
  106. if (count($data['images']) < 1) return Json::fail('请上传产品轮播图');
  107. $data['image'] = $data['image'][0];
  108. $data['images'] = json_encode($data['images']);
  109. Wholesale::beginTrans();
  110. if ($id) {
  111. unset($data['sales']);
  112. $attr_res = Wholesale::edit($data, $id);
  113. if ($attr_res) {
  114. Wholesale::commitTrans();
  115. return Json::success('修改成功!');
  116. } else {
  117. Wholesale::rollbackTrans();
  118. return Json::fail(Wholesale::getErrorInfo());
  119. }
  120. } else {
  121. $data['add_time'] = time();
  122. $res = Wholesale::create($data);
  123. if ($res) {
  124. Wholesale::commitTrans();
  125. return Json::success('添加产品成功!');
  126. } else {
  127. Wholesale::rollbackTrans();
  128. return Json::fail(StoreProductAttr::getErrorInfo());
  129. }
  130. }
  131. }
  132. public function delete($id)
  133. {
  134. if (!$id) return $this->failed('数据不存在');
  135. $product = Wholesale::get($id);
  136. if (!$product) return Json::fail('数据不存在!');
  137. $data['is_del'] = 1;
  138. if (!Wholesale::edit($data, $id))
  139. return Json::fail(Wholesale::getErrorInfo('删除失败,请稍候再试!'));
  140. else
  141. return Json::successful('删除成功!');
  142. }
  143. }