request; if ($request->isAjax && $request->isPost) { $post = Yii::$app->request->post(); $where = []; $where[] = ['=', 'mall_id', $this->mall_id]; if ($post['give_cond'] != '') { $where[] = ['=', 'give_cond', $post['give_cond']]; } if ($post['name'] != '') { $where[] = ['like', 'name', $post['name']]; } if ($post['active_status'] != '') { $where[] = ['=', 'active_status', $post['active_status']]; } $where[] = ['>', 'status', StatusEnum::DELETE]; $with = []; $order = ["FIELD(active_status, 1,3,0,2)" => true]; $params = array('where' => $where, 'order' => $order, 'with' => $with, 'limit' => $post['limit']); $list = AddonsRechargeActive::listPage($params, false, true); if ($list['list']) { foreach ($list['list'] as &$item) { if ($item['give_info']) { $item['give_info'] = \Qiniu\json_decode($item['give_info']); } } } $this->success('获取成功', $list); } else { return $this->render('index', []); } } /** * 编辑配置 */ public function actionEdit() { if (\Yii::$app->request->isAjax) { $post = \Yii::$app->request->post(); $post['give_info'] = Json::encode($post['give_info']); $now = time(); if (!isset($post['id'])) { if ($post['start_at'] < $now && $post['end_at'] > $now + 5) { $post['active_status'] = RechargeEnum::ACTIVE_STATUS1; } else { $post['active_status'] = RechargeEnum::ACTIVE_STATUS0; } $post['status'] = StatusEnum::ENABLED; } $res = AddonsRechargeActive::setData($post, $this->mall_id); $this->success('操作成功', $res); } else { return $this->render('edit'); } } public function actionDetail() { $post = \Yii::$app->request->post(); $detail = AddonsRechargeActive::getOne([['id' => $post['id']]]); if ($detail) { $detail['give_info'] = Json::decode($detail['give_info']); } $this->success('操作成功', $detail); } public function actionDelete() { if (\Yii::$app->request->isAjax) { $post = \Yii::$app->request->post(); $res = AddonsRechargeActive::setData($post, $this->mall_id); $this->success('操作成功', $res); } else { return $this->render('data'); } } public function actionList() { if (\Yii::$app->request->isAjax) { $post = \Yii::$app->request->post(); $where = []; $all = []; if ($post['page'] == 1) { $all = AddonsRechargeLog::getOne([['recharge_active_id' => $post['recharge_active_id']]], true, [], false, 'sum(give_score) as all_score,sum(give_balance) as all_balance'); } if ($post['user_id'] != '') { $where[] = ['=', 'user_id', $post['user_id']]; } if ($post['word'] != '') { $user_list = User::lists(['where' => [['mall_id' => $this->mall_id], ['or', ['like', 'mobile', trim($post['word'])], ['like', 'nickname', trim($post['word'])]], ['status' => StatusEnum::ENABLED]], 'select' => 'id']); $user_id_arr = array_column($user_list, 'id'); $where[] = ['user_id' => $user_id_arr]; } if ($post['start_date'] != '') { $where[] = ['>', 'start_date', strtotime($post['start_date'])]; } if ($post['end_date'] != '') { $where[] = ['<', 'end_date', strtotime($post['end_date'])]; } $where[] = ['=', 'recharge_active_id', $post['recharge_active_id']]; $with = ['user']; $order = 'created_at desc'; $params = array('where' => $where, 'order' => $order, 'with' => $with, 'limit' => $post['limit']); $list = AddonsRechargeLog::listPage($params, false, true); if ($list['list']) { foreach ($list['list'] as $k => &$v) { $v['give_content'] = \Qiniu\json_decode($v['give_content']); } } $this->success('获取成功', compact('all', 'list')); } else { return $this->render('list'); } } public function actionUpdate() { if (\Yii::$app->request->isAjax) { $post = \Yii::$app->request->post(); $post['active_status'] = $post['active_status'] == 1 ? 3 : 1; $res = AddonsRechargeActive::setData($post, $this->mall_id); $this->success('修改成功', $res); } else { return $this->render('index'); } } }