123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- <?php
- /**
- *
- * @author: xaboy<365615158@qq.com>
- * @day: 2017/11/11
- */
- namespace app\admin\controller\store;
- use app\admin\controller\AuthController;
- use app\admin\model\user\User;
- use app\admin\model\user\User as UserModel;
- 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 ProductCode extends AuthController
- {
- /**
- * @return mixed
- */
- public function index($id)
- {
- $this->assign('id', $id);
- return $this->fetch();
- }
- public function list()
- {
- $where = Util::getMore([
- ['status', ''],
- ['bd', ''],
- ['page', 1],
- ['limit', 20],
- ['id']
- ]);
- return Json::successlayui(\app\admin\model\store\ProductCode::list($where));
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function code($id = 0)
- {
- $f = [];
- $f[] = Form::input('number', '生成数量');
- 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\store\ProductCode();
- $data = Util::postMore([
- 'number',
- 'id'
- ]);
- $validate = Validate::rule([
- 'number' => 'require',
- ]);
- $validate->message([
- 'number.require' => '数量不能为空',
- ]);
- if (!$validate->check($data)) {
- return Json::fail($validate->getError());
- }
- for ($i=1; $i <=$data['number']; $i++){
- $save[] = [
- 'product_id' => $data['id'],
- 'code' => generate_promotion_code(1),
- ];
- }
- $res = $model->saveAll($save);
- if ($res) return Json::successful('生成成功');
- return Json::fail('生成失败');
- }
- public function grant($id)
- {
- $f = [];
- $f[] = Form::select('uid', '绑定推荐人')->options(UserModel::field('uid as value,nickname as label')->select()->toArray())->filterable(true);
- $f[] = Form::hidden('id', $id);
- $form = Form::make_post_form('添加', $f, Url::buildUrl('bd_grant'));
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- public function bd_grant()
- {
- $model = new \app\admin\model\store\ProductCode();
- $data = Util::postMore([
- 'uid',
- 'id'
- ]);
- $code = $model::where('id', 'in', $data['id'])->where('uid', '>', 0)->select()->toArray();
- if ($code){
- return Json::fail('兑换码已绑定');
- }
- $res = $model->where('id', 'in', $data['id'])->update(['uid' => $data['uid']]);
- if ($res) return Json::successful('绑定成功');
- return Json::fail('绑定失败');
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function edit($id = 0)
- {
- $data = \app\admin\model\many\Many::find($id);
- $f = [];
- $f[] = Form::input('name', '名称',$data->getData('name'))->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('money', '额度', $data->getData('money'));
- $f[] = Form::input('upper_limit', '参与上限', $data->getData('upper_limit'));
- $f[] = Form::dateTime('add_time', '开启时间', date('Y-m-d H:i:s', $data->getData('add_time')));
- $f[] = Form::dateTime('end_time', '结束时间', date('Y-m-d H:i:s', $data->getData('end_time')));
- $f[] = Form::input('sort', '排序',$data->getData('sort'));
- $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\many\Many();
- $data = Util::postMore([
- 'id',
- 'name',
- 'image',
- 'money',
- 'upper_limit',
- 'add_time',
- 'end_time',
- 'sort',
- ]);
- $validate = Validate::rule('name', 'require')->rule([
- 'name' => 'require',
- 'image' => 'require',
- 'money' => 'require',
- 'upper_limit' => 'require',
- 'add_time' => 'require',
- 'end_time' => 'require',
- ]);
- $validate->message([
- 'name.require' => '名称不能为空',
- 'image.require' => '图片不能为空',
- 'money.require' => '额度不能为空',
- 'upper_limit.require' => '上限不能为空',
- 'add_time.require' => '请选择进场时间',
- 'end_time.require' => '请选择结束时间',
- ]);
- if (!$validate->check($data)) {
- return Json::fail($validate->getError());
- }
- $details = $model->find($data['id']);
- $details['name'] = $data['name'];
- $details['image'] = $data['image'];
- $details['money'] = $data['money'];
- $details['upper_limit'] = $data['upper_limit'];
- $details['add_time'] = strtotime($data['add_time']);
- $details['end_time'] = strtotime($data['end_time']);
- $details['sort'] = $data['sort'];
- $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\store\ProductCode();
- $res = $model->where('id', $id)->delete();
- if ($res){
- return Json::success('删除成功!');
- }else{
- return Json::fail($model->getErrorInfo());
- }
- }
- }
|