| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- /**
- * Created by PhpStorm.
- * User: wniu
- * Date: 2022/2/17
- * Time: 3:08 下午
- */
- namespace addons\OperatingNote\backend\controllers;
- use addons\OperatingNote\common\models\AddonsOperatingNoteRewardRecord;
- use common\models\user\User;
- use Yii;
- class RewardController extends BaseController
- {
- public $enableCsrfValidation = false;
- public function actionIndex()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- if ($request->isPost) {
- $post = Yii::$app->request->post();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($post, [
- [['mobile', 'user_id', 'user_name', 'note_type', 'reward_source'], 'safe'],
- [['limit'], 'default', 'value' => '15'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $post = AddonsOperatingNoteRewardRecord::exceptNullVal($post);
- // 根据搜索手机号查询用户id
- if (isset($post['mobile']) && !empty($post['mobile'])) {
- $user_ids = User::find()->select("id")->where(['mall_id' => $this->mall_id])->andWhere(['like', 'mobile', $post['mobile'] . '%', false])->asArray()->column();
- if (empty($user_ids)) $this->success('查无此用户');
- $where[] = ['in', 'user_id', $user_ids];
- }
- // 根据搜索会员昵称查询用户id
- if (isset($post['user_name']) && !empty($post['user_name'])) {
- $user_ids = User::find()->select("id")->where(['mall_id' => $this->mall_id])->andWhere(['like', 'nickname', $post['user_name'] . '%', false])->asArray()->column();
- $where[] = ['in', 'user_id', $user_ids];
- }
- if (isset($post['user_id']) && !empty($post['user_id'])) {
- $where[] = ['=', 'user_id', $post['user_id']];
- }
- if (isset($post['note_type']) && $post['note_type'] > 0) {
- $where[] = ['=', 'note_type', $post['note_type']];
- }
- if (isset($post['reward_source']) && $post['reward_source'] > 0) {
- $where[] = ['=', 'reward_source', $post['reward_source']];
- }
- $where[] = ['=', 'mall_id', $this->mall_id];
- $order = 'id desc';
- $params = array('where' => $where, 'order' => $order, 'limit' => $post['limit'], 'with' => ['user']);
- $list = AddonsOperatingNoteRewardRecord::listPage($params, false, true);
- if ($list['list']) {
- foreach ($list['list'] as $k => &$v) {
- if ($v['note_type'] == 1) {
- $list['list'][$k]['note_type_name'] = '图文';
- } elseif ($v['note_type'] == 2) {
- $list['list'][$k]['note_type_name'] = '视频';
- } else {
- $list['list'][$k]['note_type_name'] = '广告';
- }
- if ($v['reward_source'] == 1) {
- $list['list'][$k]['reward_source_name'] = '阅读';
- } else {
- $list['list'][$k]['reward_source_name'] = '分享';
- }
- if ($v['reward_type'] == 0) {
- $v['reward_content'] = floatval($v['reward_content']) . '积分';
- } elseif ($v['reward_type'] == 1) {
- $v['reward_content'] = floatval($v['reward_content']) . '余额';
- } else {
- $v['reward_content'] = floatval($v['reward_content']) . '红包';
- }
- }
- }
- $this->success('获取成功', $list);
- }
- }
- return $this->render($this->action->id);
- }
- }
|