123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- <?php
- /**
- *
- * @author: xaboy<365615158@qq.com>
- * @day: 2017/11/11
- */
- namespace app\admin\controller\luck;
- use app\admin\controller\AuthController;
- use crmeb\repositories\OrderRepository;
- use crmeb\repositories\ShortLetterRepositories;
- use crmeb\services\{ExpressService,
- JsonService,
- JsonService as Json,
- MiniProgramService,
- WechatService,
- FormBuilder as Form,
- CacheService,
- UtilService as Util};
- use app\admin\model\ump\StorePink;
- use crmeb\basic\BaseModel;
- use think\facade\Route as Url;
- use crmeb\services\YLYService;
- use think\facade\Log;
- use think\facade\Validate;
- /**
- * 订单管理控制器 同一个订单表放在一个控制器
- * Class StoreOrder
- * @package app\admin\controller\store
- */
- class LuckOrder extends AuthController
- {
- /**
- * @return mixed
- */
- public function index()
- {
- return $this->fetch();
- }
- public function list()
- {
- $where = Util::getMore([
- ['status', ''],
- ['page', 1],
- ['limit', 20],
- ['name', '']
- ]);
- return Json::successlayui(\app\admin\model\luck\LuckOrder::list($where));
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function create($id = 0)
- {
- $f = [];
- $f[] = Form::input('name', '名称')->col(12);
- // $f[] = Form::frameImageOne('image', '封面图(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')))->icon('image')->width('100%')->height('500px');
- $f[] = Form::input('money', '额度');
- $f[] = Form::input('increase', '自动增长额度', 0);
- $f[] = Form::input('second', '自动增长时间(秒)', 0);
- $f[] = Form::input('upper_limit', '参与上限');
- $f[] = Form::input('single', '单次上限');
- $f[] = Form::input('lower_limit', '单次下限');
- $f[] = Form::dateTime('add_time', '开启时间');
- $f[] = Form::dateTime('end_time', '结束时间');
- $f[] = Form::input('sort', '排序',0);
- if ($id) $f[] = Form::hidden('id', $id);
- $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- public function save()
- {
- $model = new \app\admin\model\many\Many();
- $data = Util::postMore([
- 'name',
- // 'image',
- 'money',
- 'upper_limit',
- 'add_time',
- 'end_time',
- 'sort',
- 'increase',
- 'second',
- 'single',
- 'lower_limit'
- ]);
- $validate = Validate::rule('name', 'require')->rule([
- 'name' => 'require',
- // 'image' => 'require',
- 'money' => 'require',
- 'upper_limit' => 'require',
- 'add_time' => 'require',
- 'end_time' => 'require',
- 'single' => 'require',
- 'lower_limit' => 'require',
- ]);
- $validate->message([
- 'name.require' => '名称不能为空',
- // 'image.require' => '图片不能为空',
- 'money.require' => '额度不能为空',
- 'upper_limit.require' => '上限不能为空',
- 'add_time.require' => '请选择进场时间',
- 'end_time.require' => '请选择结束时间',
- 'single.require' => '请填写单次上限',
- 'lower_limit.require' => '请填写单次下限',
- ]);
- if (!$validate->check($data)) {
- return Json::fail($validate->getError());
- }
- $data['add_time'] = strtotime($data['add_time']);
- $data['end_time'] = strtotime($data['end_time']);
- $res = $model->save($data);
- if ($res) return Json::successful('添加成功');
- return Json::fail('添加失败');
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function edit($id = 0)
- {
- $data = \app\admin\model\luck\LuckDraw::find($id);
- $f = [];
- $f[] = Form::input('title', '名称',$data->getData('title'))->col(12);
- // $f[] = Form::frameImageOne('image', '封面图(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')), $data->getData('image'))->icon('image')->width('100%')->height('500px');
- $f[] = Form::input('count', '数量', $data->getData('count'));
- $f[] = Form::input('price', '价格', $data->getData('price'));
- $f[] = Form::hidden('id', $id);
- $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- /**
- * 修改
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function update()
- {
- $model = new \app\admin\model\luck\LuckDraw();
- $data = Util::postMore([
- 'id',
- 'title',
- // 'image',
- 'count',
- 'price',
- ]);
- $validate = Validate::rule([
- 'title' => 'require',
- // 'image' => 'require',
- 'count' => 'require',
- 'price' => 'require',
- ]);
- $validate->message([
- 'title.require' => '名称不能为空',
- // 'image.require' => '图片不能为空',
- 'count.require' => '数量不能为空',
- 'price.require' => '价格不能为空',
- ]);
- if (!$validate->check($data)) {
- return Json::fail($validate->getError());
- }
- $details = $model->find($data['id']);
- $details['title'] = $data['title'];
- $details['count'] = $data['count'];
- $details['price'] = $data['price'];
- $res = $details->save();
- if ($res) return Json::successful('修改成功');
- return Json::fail('修改失败');
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function next($id = 0)
- {
- $f = [];
- $f[] = Form::dateTime('add_time', '开启时间');
- $f[] = Form::dateTime('end_time', '结束时间');
- $f[] = Form::hidden('id', $id);
- $form = Form::make_post_form('添加', $f, Url::buildUrl('next_save'));
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- public function next_save()
- {
- $model = new \app\admin\model\many\Many();
- $data = Util::postMore([
- 'id',
- 'add_time',
- 'end_time',
- ]);
- $validate = Validate::rule([
- 'add_time' => 'require',
- 'end_time' => 'require',
- ]);
- $validate->message([
- 'add_time.require' => '请选择开启时间',
- 'end_time.require' => '请选择结束时间',
- ]);
- if (!$validate->check($data)) {
- return Json::fail($validate->getError());
- }
- $details = $model->find($data['id']);
- if ($details['status'] == 1) return Json::fail('未结束不能进行下一场');
- if ($details['suc'] == 2) return Json::fail('已众筹失败无法就行下一场');
- if (strtotime($data['end_time']) < strtotime($data['add_time'])) return Json::fail('结束时间不能小于开启时间');
- $details['stage'] += 1;
- $details['status'] = 1;
- $details['number'] = 0;//重置额度
- $details['money'] = intval($details['money'] * 1.3);//提搞额度130%
- $details['suc'] = 0;
- $details['add_time'] = strtotime($data['add_time']);
- $details['end_time'] = strtotime($data['end_time']);
- $res = $details->save();
- if ($res) return Json::successful('成功');
- return Json::fail('失败');
- }
- /**
- * 删除
- * @param $id
- * @return void
- * @throws \Exception
- */
- public function delete($id)
- {
- if (!$id) Json::fail('删除失败');
- $model = new \app\admin\model\luck\LuckOrder();
- $res = \app\admin\model\luck\LuckOrder::destroy($id);
- if ($res){
- return Json::success('删除成功!');
- }else{
- return Json::fail($model->getErrorInfo());
- }
- }
- }
|