model = new UserCouponModel; } public function index() { if (!$this->request->isAjax()) { return $this->view->fetch(); } $coupon_id = $this->request->param('coupon_id'); $coupons = $this->model->sheepFilter()->with(['user', 'order']) ->where('coupon_id', $coupon_id) ->paginate($this->request->param('list_rows', 10)); $this->success('获取成功', null, $coupons); } /** * 删除优惠券 * * @param string $id 要删除的优惠券 * @return void */ public function delete($id) { if (empty($id)) { $this->error(__('Parameter %s can not be empty', 'id')); } $id = explode(',', $id); $list = $this->model->where('id', 'in', $id)->select(); $result = Db::transaction(function () use ($list) { $count = 0; foreach ($list as $item) { $count += $item->delete(); } return $count; }); if ($result) { $this->success('删除成功', null, $result); } else { $this->error(__('No rows were deleted')); } } }