StoreCard.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace app\admin\controller\ump;
  3. use app\admin\controller\AuthController;
  4. use app\models\store\Card;
  5. use app\admin\model\store\{StoreDescription,
  6. StoreProductAttr,
  7. StoreProductAttrResult,
  8. StoreProduct as ProductModel,
  9. StoreProductAttrValue
  10. };
  11. use crmeb\traits\CurdControllerTrait;
  12. use think\Exception;
  13. use think\exception\ErrorException;
  14. use think\exception\ValidateException;
  15. use think\facade\Route as Url;
  16. use app\admin\model\system\{SystemAttachment, SystemGroupData, ShippingTemplates};
  17. use crmeb\services\{
  18. FormBuilder as Form, UtilService as Util, JsonService as Json
  19. };
  20. use app\admin\model\store\StoreCategory;
  21. /**
  22. * 限时秒杀 控制器
  23. * Class StoreSeckill
  24. * @package app\admin\controller\store
  25. */
  26. class StoreCard extends AuthController
  27. {
  28. use CurdControllerTrait;
  29. protected $bindModel = Card::class;
  30. /**
  31. * 显示资源列表
  32. *
  33. * @return \think\Response
  34. */
  35. public function index()
  36. {
  37. $this->assign('count', Card::count());
  38. return $this->fetch();
  39. }
  40. public function save_excel()
  41. {
  42. $where = Util::getMore([
  43. ['status', ''],
  44. ['name', '']
  45. ]);
  46. Card::SaveExcel($where);
  47. }
  48. /**
  49. * 异步获取砍价数据
  50. */
  51. public function get_list()
  52. {
  53. $where = Util::getMore([
  54. ['page', 1],
  55. ['limit', 20],
  56. ['status', ''],
  57. ['name', '']
  58. ]);
  59. $seckillList = Card::systemPage($where);
  60. if (is_object($seckillList['list'])) $seckillList['list'] = $seckillList['list']->toArray();
  61. $data = $seckillList['list']['data'];
  62. return Json::successlayui(['count' => $seckillList['list']['total'], 'data' => $data]);
  63. }
  64. /**
  65. * 添加秒杀商品
  66. * @return form-builder
  67. */
  68. public function create()
  69. {
  70. $f = array();
  71. $f[] = Form::input('name', '标题')->required('请输入礼品卡标题');
  72. $f[] = Form::number('price', '价格')->step(0.01)->required();
  73. $f[] = Form::number('store_award', '奖金')->step(0.01)->required();
  74. $f[] = Form::number('num', '数量')->step(1)->required()->min(1);
  75. $form = Form::make_post_form('添加礼品卡', $f, Url::buildUrl('save_cards'));
  76. $this->assign(compact('form'));
  77. return $this->fetch('public/form-builder');
  78. }
  79. /**
  80. * 保存秒杀商品
  81. * @param int $id
  82. */
  83. public function save_cards()
  84. {
  85. $data = Util::postMore([
  86. 'name',
  87. 'price',
  88. 'store_award',
  89. 'num',
  90. ]);
  91. for ($i = 0; $i < $data['num']; $i++) {
  92. $item = [
  93. 'add_time' => time(),
  94. 'name' => $data['name'],
  95. 'code' => Card::createCode(),
  96. 'password' => Card::createPassword(),
  97. 'price' => $data['price'],
  98. 'store_award' => $data['store_award'],
  99. ];
  100. Card::create($item);
  101. }
  102. return Json::successful('添加成功!');
  103. }
  104. }