| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- <?php
- namespace addons\Recharge\backend\controllers;
- use addons\Recharge\common\enums\RechargeEnum;
- use addons\Recharge\common\models\AddonsRechargeActive;
- use addons\Recharge\common\models\AddonsRechargeLog;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use Yii;
- use yii\helpers\Json;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\Recharge\backend\controllers
- */
- class DefaultController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 首页
- */
- public function actionIndex()
- {
- $request = Yii::$app->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');
- }
- }
- }
|