123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use Think\Db;
- class Couponuser extends Backend
- {
-
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\Couponuser;
- $this->view->assign("statusList", $this->model->getStatusList());
- $this->view->assign("genderList", $this->model->getGenderList());
- }
-
-
- public function index()
- {
- $coupon_id = input('coupon_id', 0, 'intval');
- if (!$coupon_id) {
- $coupon_id = input('ids', 0, 'intval');
- }
- $this->assign('coupon_id', $coupon_id);
- $this->assignconfig('coupon_id', $coupon_id);
-
- $this->relationSearch = false;
-
- $this->request->filter(['strip_tags', 'trim']);
- if ($this->request->isAjax()) {
-
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $list = $this->model
- ->where(['status' => 1])
- ->where($where)
- ->order($sort, $order)
- ->paginate($limit);
- foreach ($list as $row) {
- $row->visible(['id','username','nickname','mobile','avatar','money','status','realname','gender','birthday','idcard','passport','emergencycontact','contactmobile','outdoorduration','invite_no','growthvalue','growthlevel','experiencelevel','experiencetime','maxlevel','freenumber']);
-
- }
- $result = array("total" => $list->total(), "rows" => $list->items());
- return json($result);
- }
- return $this->view->fetch();
- }
-
- public function giveout() {
- $ids = input('ids', '', 'trim');
- $coupon_id = input('coupon_id', 0, 'intval');
- if (!$ids || !$coupon_id) {
- $this->error('参数缺失');
- }
- $info = Db::name('coupon')->find($coupon_id);
- if (!$info) {
- $this->error('优惠券不存在');
- }
- if ($info['purpose'] != 3) {
- $this->error('优惠券类型错误');
- }
- $ids = explode(',', $ids);
- $coupon_data = [
- 'coupon_id' => $info['id'],
- 'title' => $info['title'],
- 'desc' => $info['desc'],
- 'type' => $info['type'],
- 'money' => $info['money'],
- 'minmoney' => $info['minmoney'],
- 'purpose' => $info['purpose'],
- 'starttime' => time(),
- 'endtime' => time() + $info['effectiveday'] * 86400,
- 'createtime' => time()
- ];
- $user_coupon = Db::name('user_coupon');
- foreach ($ids as &$v) {
- $coupon_data['user_id'] = $v;
- $coupon_rs = $user_coupon->insertGetId($coupon_data);
- }
- $this->success('发放成功');
- }
- }
|