| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- <?php
- namespace addons\Clockin\backend\controllers;
- use addons\Clockin\common\models\ClockinApply;
- use addons\Clockin\common\models\ClockinRewardLog;
- use addons\Clockin\common\models\ClockinUser;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use common\models\user\UserLevel;
- use Yii;
- use common\controllers\AddonsController;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\Clockin\backend\controllers
- */
- class DefaultController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- return $this->render('index',[
- ]);
- }
- /**
- * 打卡申请列表
- * @Author: lun
- * @DateTime: 2023/7/26 0026 9:42
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionApply()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isAjax) {
- if ($retuest->isGet) {
- $get = Yii::$app->request->get();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($get,[
- [['user_id','mobile','is_pass','limit'], 'integer'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $where = [];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $where[] = ['=', 'mall_id', $this->mall_id];
- !empty($get['user_id']) && $where[] = ['=', 'user_id', $get['user_id']];
- isset($get['is_pass']) && $where[] = ['=', 'is_pass', $get['is_pass']];
- if (!empty($get['mobile'])) {
- $user_id = User::find()->select('id')->where(['mall_id' => $this->mall_id, 'mobile' => $get['mobile'], 'status' => StatusEnum::ENABLED])->scalar();
- if (empty($user_id)) return $this->error('查无此用户!');
- $where[] = ['=', 'user_id', $user_id];
- }
- $with = ['user'];
- $order = 'id desc,created_at desc';
- $params = array('where' => $where, 'order'=>$order, 'with' => $with, 'limit' => $get['limit'] ?? 20);
- $list = ClockinApply::listPage($params, false, true);
- foreach ($list['list'] as &$item) {
- $item['pic'] = json_decode($item['pic'], true);
- }
- // 获取配置
- $config = Yii::$app->services->setting->addons->get($this->mall_id, 'Clockin', 'basic');
- $config['default_score'] = json_decode($config['default_score'], true);
- $this->success('获取成功', compact('list', 'config'));
- }
- } else {
- return $this->render($this->action->id);
- }
- }
- /**
- * 拒绝申请
- * @Author: lun
- * @DateTime: 2023/7/26 0026 15:26
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionApplyAgree()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isAjax && $retuest->isPost) {
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params,[
- [['id'], 'integer'],
- [['reward'], 'safe'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- // 保存
- $params['is_pass'] = 1;
- $res = ClockinApply::changeStatus($this->mall_id, $params);
- if ($res == false) return $this->error(ClockinApply::getStaticError());
- return $this->success('操作成功');
- }
- }
- /**
- * 拒绝申请
- * @Author: lun
- * @DateTime: 2023/7/26 0026 15:26
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionApplyReject()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isAjax && $retuest->isPost) {
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params,[
- [['id'], 'integer'],
- [['reason'], 'string'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- // 保存
- $params['is_pass'] = -1;
- $res = ClockinApply::changeStatus($this->mall_id, $params);
- if ($res == false) return $this->error('操作失败:' . ClockinApply::getStaticError());
- return $this->success('操作成功');
- }
- }
- /**
- * 删除
- * @Author: lun
- * @DateTime: 2023/7/27 0027 15:23
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionApplyDel()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isAjax && $retuest->isPost) {
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params,[
- [['id'], 'integer'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- // 保存
- $params['status'] = -1;
- $res = ClockinApply::changeStatus($this->mall_id, $params);
- if ($res == false) return $this->error('操作失败:' . ClockinApply::getStaticError());
- return $this->success('操作成功');
- }
- }
- /**
- * 获取基础设置
- * @Author: lun
- * @DateTime: 2023/7/26 0026 10:37
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return string
- */
- public function actionSetting()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isAjax && $retuest->isGet) {
- // 获取配置
- $config = Yii::$app->services->setting->addons->get($this->mall_id, 'Clockin', 'basic');
- if ($config['seniority']) $config['seniority'] = json_decode($config['seniority'], true);
- if (!isset($config['is_show_reward_limit'])) $config['is_show_reward_limit'] = 1;
- if ($config['default_score']){
- $config['default_score'] = json_decode($config['default_score'], true);
- if(empty($config['default_score'] )){
- $config['default_score'] = [];
- }
- }else{
- $config['default_score'] = ['100', '200', '300', '400', '500'];
- }
- // 获取会员等级
- $levels = UserLevel::getUserListByUpgrade(['mall_id' => $this->mall_id]);
- array_unshift($levels, ['level' => 0, 'name' => '普通会员']);
- $this->success('获取成功', compact('config','levels'));
- }
- return $this->render($this->action->id);
- }
- /**
- * 基础设置提交
- * @Author: lun
- * @DateTime: 2023/7/26 0026 10:38
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionSettingSubmit()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isAjax && $retuest->isPost) {
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params,[
- [['is_enable','is_seniority','is_reward','reward_limit','upload_limit','is_show_reward_limit'], 'integer'],
- [['seniority','default_score'], 'safe'],
- [['reward_limit'], 'double'],
- [['explain'], 'string']
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- // 保存配置
- $params['default_score'] = json_encode($params['default_score']);
- $params['seniority'] = json_encode($params['seniority']);
- $config = Yii::$app->services->setting->addons->set($this->mall_id, 'Clockin', ['basic' => $params]);
- $this->success('保存成功', $config);
- }
- }
- /**
- * 奖励用户
- * @Author: lun
- * @DateTime: 2023/7/27 0027 9:33
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionUser()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isAjax) {
- if ($retuest->isGet) {
- $get = Yii::$app->request->get();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($get,[
- [['user_id','mobile','limit'], 'integer'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $where = [];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $where[] = ['=', 'mall_id', $this->mall_id];
- !empty($get['user_id']) && $where[] = ['=', 'user_id', $get['user_id']];
- if (!empty($get['mobile'])) {
- $user_id = User::find()->select('id')->where(['mall_id' => $this->mall_id, 'mobile' => $get['mobile'], 'status' => StatusEnum::ENABLED])->scalar();
- if (empty($user_id)) return $this->error('查无此用户!');
- $where[] = ['=', 'user_id', $user_id];
- }
- $with = ['user'];
- $order = 'id desc,created_at desc';
- $params = array('where' => $where, 'order'=>$order, 'with' => $with, 'limit' => $get['limit'] ?? 20);
- $list = ClockinUser::listPage($params, false, true);
- $this->success('获取成功', compact('list'));
- }
- } else {
- return $this->render($this->action->id);
- }
- }
- /**
- * 获取用户奖励记录
- * @Author: lun
- * @DateTime: 2023/7/27 0027 9:35
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionRewardLogs()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isAjax && $retuest->isGet) {
- $get = Yii::$app->request->get();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($get,[
- [['user_id','limit'], 'integer'],
- [['user_id'], 'required'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $where = [];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['=', 'user_id', $get['user_id']];
- $order = 'id desc,created_at desc';
- $params = array('where' => $where, 'order'=>$order, 'limit' => $get['limit'] ?? 20);
- $list = ClockinRewardLog::listPage($params, false, true);
- $this->success('获取成功', $list);
- }
- }
- }
|