123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- <?php
- /**
- * Created by PhpStorm
- * Author: 向往那片天空
- * Date: 2020/6/8
- * Time: 16:21
- * 微信/QQ: 250023777
- * 格言: 抓住中心,宁精勿杂,宁专勿多
- */
- namespace app\admin\controller\ump;
- use app\admin\controller\AuthController;
- use app\Request;
- use crmeb\services\FormBuilder as Form;
- use crmeb\services\JsonService;
- use crmeb\services\UtilService;
- use app\admin\model\ump\StoreActivity as StoreActivityModel;
- use think\facade\Route as Url;
- use app\admin\model\ump\StoreTryProduct as StoreTryProductModel;
- use app\admin\model\store\StoreCategory;
- use app\admin\model\ump\StoreTryRecord;
- class StoreTryProduct extends AuthController
- {
- public function index(Request $request)
- {
- $this->assign('countCombination', StoreTryProductModel::where('is_del=0')->count());
- $this->assign('combinationId', StoreTryProductModel::getCombinationIdAll());
- return $this->fetch();
- }
- /**
- * 异步获取活动数据
- */
- public function get_combination_list()
- {
- $where = UtilService::getMore([
- ['page', 1],
- ['limit', 20],
- ['export', 0],
- ['is_show', ''],
- ['store_name', ''],
- ['is_finish', '']
- ]);
- $combinationList = StoreTryProductModel::systemPage($where);
- if (is_object($combinationList['list'])) $combinationList['list'] = $combinationList['list']->toArray();
- $data = $combinationList['list']['data'];
- foreach ($data as &$value) {
- $value['start_time'] = date('Y-m-d H:i:s', $value['start_time']);
- $value['stop_time'] = date('Y/m/d H:i:s', $value['stop_time']);
- $value['add_time'] = date('Y-m-d H:i:s', $value['add_time']);
- $value['join_people'] = StoreTryRecord::where('tid', $value['id'])->where('is_del=0')->count();
- }
- $count = StoreTryProductModel::setWhere($where)->count();
- return JsonService::successlayui(['data' => $data, 'count' => $count]);
- }
- public function set_show(Request $request)
- {
- $param = UtilService::getMore([
- 'id',
- 'is_show'
- ], $request);
- if (!$param['id']) return JsonService::fail('参数错误');
- StoreTryProductModel::update([
- 'id' => $param['id'],
- 'is_show' => $param['is_show']
- ]);
- return JsonService::success("修改成功");
- }
- /**
- * 删除指定资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function delete($id)
- {
- if (!$id) return $this->failed('数据不存在');
- $product = StoreTryProductModel::get($id);
- if (!$product) return JsonService::fail('数据不存在!');
- if ($product['is_del']) return JsonService::fail('已删除!');
- $data['is_del'] = 1;
- if (!StoreTryProductModel::edit($data, $id))
- return JsonService::fail(StoreTryProductModel::getErrorInfo('删除失败,请稍候再试!'));
- else
- return JsonService::successful('删除成功!');
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function create(Request $request)
- {
- $f = [];
- $f[] = Form::frameImageOne('product', '选择商品', Url::buildUrl('productList', array('fodder' => 'product')))->icon('plus')->width('100%')->height('500px');
- $f[] = Form::hidden('product_id', '');
- $f[] = Form::input('store_name', '商品名称');
- $f[] = Form::input('explain', '试用说明')->type('textarea');
- $f[] = Form::dateTimeRange('section_time', '开始结束时间');
- $f[] = Form::frameImageOne('image', '商品主图片(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')))->icon('image')->width('100%')->height('500px');
- $f[] = Form::number('quota', '试用人数', 2)->min(2)->col(12);
- $f[] = Form::number('sort', '排序', 1)->min(2)->col(12);
- $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('save'));
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- /**
- * 获取商品列表
- * @return string
- * @throws \Exception
- */
- public function productList()
- {
- $cate = StoreCategory::getTierList(null, 1);
- $this->assign('cate', $cate);
- return $this->fetch();
- }
- /**
- * 保存新建的资源
- * @param int $id
- */
- public function save($id = 0)
- {
- $data = UtilService::postMore([
- 'product_id',
- 'store_name',
- ['image', ''],
- ['explain', ''],
- ['section_time', ''],
- ['quota', 0],
- ['sort', 1],
- ]);
- if (!$data['store_name']) return JsonService::fail('请输入商品名称');
- if (!$data['explain']) return JsonService::fail('请输入试用说明');
- if (!$data['image']) return JsonService::fail('请上传商品图片');
- if (count($data['section_time']) < 1) return JsonService::fail('请选择活动时间');
- $data['start_time'] = strtotime($data['section_time'][0]);
- $data['stop_time'] = strtotime($data['section_time'][1]);
- unset($data['section_time']);
- if ($id) {
- $product = StoreTryProductModel::get($id);
- if (!$product) return JsonService::fail('数据不存在!');
- $data['product_id'] = $product['product_id'];
- StoreTryProductModel::edit($data, $id);
- return JsonService::successful('编辑成功!');
- } else {
- $data['add_time'] = time();
- StoreTryProductModel::create($data);
- return JsonService::successful('添加活动成功!');
- }
- }
- /**
- * 显示编辑资源表单页.
- *
- * @param int $id
- * @return \think\Response
- */
- public function edit($id)
- {
- if (!$id) return $this->failed('数据不存在');
- $product = StoreTryProductModel::get($id);
- if (!$product) return JsonService::fail('数据不存在!');
- $f = [];
- $f[] = Form::input('product_id', '产品ID', $product->getData('product_id'))->disabled(true);
- $f[] = Form::input('store_name', '商品名称', $product->getData('store_name'));
- $f[] = Form::input('explain', '试用说明', $product->getData('explain'))->type('textarea');
- $f[] = Form::dateTimeRange('section_time', '活动时间', date("Y-m-d H:i:s", $product->getData('start_time')), date("Y-m-d H:i:s", $product->getData('stop_time')));
- $f[] = Form::frameImageOne('image', '商品主图片(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')), $product->getData('image'))->icon('image')->width('100%')->height('500px');
- $f[] = Form::number('quota', '试用人数', $product['quota'])->min(2)->col(12);
- $f[] = Form::number('sort', '排序', $product['sort'])->min(2)->col(12);
- $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('save', compact('id')));
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- public function finish(Request $request)
- {
- $param = UtilService::getMore([
- 'id'
- ], $request);
- StoreTryProductModel::where("id={$param['id']}")->update([
- 'is_finish' => 1,
- ]);
- return JsonService::successful('结束成功!');
- }
- }
|