123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- namespace app\admin\controller\ump;
- use app\admin\controller\AuthController;
- use app\models\store\Card;
- use app\admin\model\store\{StoreDescription,
- StoreProductAttr,
- StoreProductAttrResult,
- StoreProduct as ProductModel,
- StoreProductAttrValue
- };
- use crmeb\traits\CurdControllerTrait;
- use think\Exception;
- use think\exception\ErrorException;
- use think\exception\ValidateException;
- use think\facade\Route as Url;
- use app\admin\model\system\{SystemAttachment, SystemGroupData, ShippingTemplates};
- use crmeb\services\{
- FormBuilder as Form, UtilService as Util, JsonService as Json
- };
- use app\admin\model\store\StoreCategory;
- /**
- * 限时秒杀 控制器
- * Class StoreSeckill
- * @package app\admin\controller\store
- */
- class StoreCard extends AuthController
- {
- use CurdControllerTrait;
- protected $bindModel = Card::class;
- /**
- * 显示资源列表
- *
- * @return \think\Response
- */
- public function index()
- {
- $this->assign('count', Card::count());
- return $this->fetch();
- }
- public function save_excel()
- {
- $where = Util::getMore([
- ['status', ''],
- ['name', '']
- ]);
- Card::SaveExcel($where);
- }
- /**
- * 异步获取砍价数据
- */
- public function get_list()
- {
- $where = Util::getMore([
- ['page', 1],
- ['limit', 20],
- ['status', ''],
- ['name', '']
- ]);
- $seckillList = Card::systemPage($where);
- if (is_object($seckillList['list'])) $seckillList['list'] = $seckillList['list']->toArray();
- $data = $seckillList['list']['data'];
- return Json::successlayui(['count' => $seckillList['list']['total'], 'data' => $data]);
- }
- /**
- * 添加秒杀商品
- * @return form-builder
- */
- public function create()
- {
- $f = array();
- $f[] = Form::input('name', '标题')->required('请输入礼品卡标题');
- $f[] = Form::number('price', '价格')->step(0.01)->required();
- $f[] = Form::number('store_award', '奖金')->step(0.01)->required();
- $f[] = Form::number('num', '数量')->step(1)->required()->min(1);
- $form = Form::make_post_form('添加礼品卡', $f, Url::buildUrl('save_cards'));
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- /**
- * 保存秒杀商品
- * @param int $id
- */
- public function save_cards()
- {
- $data = Util::postMore([
- 'name',
- 'price',
- 'store_award',
- 'num',
- ]);
- for ($i = 0; $i < $data['num']; $i++) {
- $item = [
- 'add_time' => time(),
- 'name' => $data['name'],
- 'code' => Card::createCode(),
- 'password' => Card::createPassword(),
- 'price' => $data['price'],
- 'store_award' => $data['store_award'],
- ];
- Card::create($item);
- }
- return Json::successful('添加成功!');
- }
- }
|