DefaultController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <?php
  2. namespace addons\Clockin\backend\controllers;
  3. use addons\Clockin\common\models\ClockinApply;
  4. use addons\Clockin\common\models\ClockinRewardLog;
  5. use addons\Clockin\common\models\ClockinUser;
  6. use common\enums\StatusEnum;
  7. use common\models\user\User;
  8. use common\models\user\UserLevel;
  9. use Yii;
  10. use common\controllers\AddonsController;
  11. /**
  12. * 默认控制器
  13. *
  14. * Class DefaultController
  15. * @package addons\Clockin\backend\controllers
  16. */
  17. class DefaultController extends BaseController
  18. {
  19. public $enableCsrfValidation = false;
  20. /**
  21. * 首页
  22. *
  23. * @return string
  24. */
  25. public function actionIndex()
  26. {
  27. return $this->render('index',[
  28. ]);
  29. }
  30. /**
  31. * 打卡申请列表
  32. * @Author: lun
  33. * @DateTime: 2023/7/26 0026 9:42
  34. * @Copyright: copyright (c) 2021 广东七件事集团
  35. * @return mixed|string|void
  36. */
  37. public function actionApply()
  38. {
  39. $retuest = Yii::$app->request;
  40. if ($retuest->isAjax) {
  41. if ($retuest->isGet) {
  42. $get = Yii::$app->request->get();
  43. // 检查提交的参数
  44. $res = Yii::$app->services->validate->validate($get,[
  45. [['user_id','mobile','is_pass','limit'], 'integer'],
  46. ]);
  47. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  48. $where = [];
  49. $where[] = ['=', 'status', StatusEnum::ENABLED];
  50. $where[] = ['=', 'mall_id', $this->mall_id];
  51. !empty($get['user_id']) && $where[] = ['=', 'user_id', $get['user_id']];
  52. isset($get['is_pass']) && $where[] = ['=', 'is_pass', $get['is_pass']];
  53. if (!empty($get['mobile'])) {
  54. $user_id = User::find()->select('id')->where(['mall_id' => $this->mall_id, 'mobile' => $get['mobile'], 'status' => StatusEnum::ENABLED])->scalar();
  55. if (empty($user_id)) return $this->error('查无此用户!');
  56. $where[] = ['=', 'user_id', $user_id];
  57. }
  58. $with = ['user'];
  59. $order = 'id desc,created_at desc';
  60. $params = array('where' => $where, 'order'=>$order, 'with' => $with, 'limit' => $get['limit'] ?? 20);
  61. $list = ClockinApply::listPage($params, false, true);
  62. foreach ($list['list'] as &$item) {
  63. $item['pic'] = json_decode($item['pic'], true);
  64. }
  65. // 获取配置
  66. $config = Yii::$app->services->setting->addons->get($this->mall_id, 'Clockin', 'basic');
  67. $config['default_score'] = json_decode($config['default_score'], true);
  68. $this->success('获取成功', compact('list', 'config'));
  69. }
  70. } else {
  71. return $this->render($this->action->id);
  72. }
  73. }
  74. /**
  75. * 拒绝申请
  76. * @Author: lun
  77. * @DateTime: 2023/7/26 0026 15:26
  78. * @Copyright: copyright (c) 2021 广东七件事集团
  79. * @return mixed|void
  80. */
  81. public function actionApplyAgree()
  82. {
  83. $retuest = Yii::$app->request;
  84. if ($retuest->isAjax && $retuest->isPost) {
  85. $params = Yii::$app->request->post();
  86. $res = Yii::$app->services->validate->validate($params,[
  87. [['id'], 'integer'],
  88. [['reward'], 'safe'],
  89. ]);
  90. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  91. // 保存
  92. $params['is_pass'] = 1;
  93. $res = ClockinApply::changeStatus($this->mall_id, $params);
  94. if ($res == false) return $this->error(ClockinApply::getStaticError());
  95. return $this->success('操作成功');
  96. }
  97. }
  98. /**
  99. * 拒绝申请
  100. * @Author: lun
  101. * @DateTime: 2023/7/26 0026 15:26
  102. * @Copyright: copyright (c) 2021 广东七件事集团
  103. * @return mixed|void
  104. */
  105. public function actionApplyReject()
  106. {
  107. $retuest = Yii::$app->request;
  108. if ($retuest->isAjax && $retuest->isPost) {
  109. $params = Yii::$app->request->post();
  110. $res = Yii::$app->services->validate->validate($params,[
  111. [['id'], 'integer'],
  112. [['reason'], 'string'],
  113. ]);
  114. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  115. // 保存
  116. $params['is_pass'] = -1;
  117. $res = ClockinApply::changeStatus($this->mall_id, $params);
  118. if ($res == false) return $this->error('操作失败:' . ClockinApply::getStaticError());
  119. return $this->success('操作成功');
  120. }
  121. }
  122. /**
  123. * 删除
  124. * @Author: lun
  125. * @DateTime: 2023/7/27 0027 15:23
  126. * @Copyright: copyright (c) 2021 广东七件事集团
  127. * @return mixed|void
  128. */
  129. public function actionApplyDel()
  130. {
  131. $retuest = Yii::$app->request;
  132. if ($retuest->isAjax && $retuest->isPost) {
  133. $params = Yii::$app->request->post();
  134. $res = Yii::$app->services->validate->validate($params,[
  135. [['id'], 'integer'],
  136. ]);
  137. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  138. // 保存
  139. $params['status'] = -1;
  140. $res = ClockinApply::changeStatus($this->mall_id, $params);
  141. if ($res == false) return $this->error('操作失败:' . ClockinApply::getStaticError());
  142. return $this->success('操作成功');
  143. }
  144. }
  145. /**
  146. * 获取基础设置
  147. * @Author: lun
  148. * @DateTime: 2023/7/26 0026 10:37
  149. * @Copyright: copyright (c) 2021 广东七件事集团
  150. * @return string
  151. */
  152. public function actionSetting()
  153. {
  154. $retuest = Yii::$app->request;
  155. if ($retuest->isAjax && $retuest->isGet) {
  156. // 获取配置
  157. $config = Yii::$app->services->setting->addons->get($this->mall_id, 'Clockin', 'basic');
  158. if ($config['seniority']) $config['seniority'] = json_decode($config['seniority'], true);
  159. if (!isset($config['is_show_reward_limit'])) $config['is_show_reward_limit'] = 1;
  160. if ($config['default_score']){
  161. $config['default_score'] = json_decode($config['default_score'], true);
  162. if(empty($config['default_score'] )){
  163. $config['default_score'] = [];
  164. }
  165. }else{
  166. $config['default_score'] = ['100', '200', '300', '400', '500'];
  167. }
  168. // 获取会员等级
  169. $levels = UserLevel::getUserListByUpgrade(['mall_id' => $this->mall_id]);
  170. array_unshift($levels, ['level' => 0, 'name' => '普通会员']);
  171. $this->success('获取成功', compact('config','levels'));
  172. }
  173. return $this->render($this->action->id);
  174. }
  175. /**
  176. * 基础设置提交
  177. * @Author: lun
  178. * @DateTime: 2023/7/26 0026 10:38
  179. * @Copyright: copyright (c) 2021 广东七件事集团
  180. * @return mixed|void
  181. */
  182. public function actionSettingSubmit()
  183. {
  184. $retuest = Yii::$app->request;
  185. if ($retuest->isAjax && $retuest->isPost) {
  186. $params = Yii::$app->request->post();
  187. $res = Yii::$app->services->validate->validate($params,[
  188. [['is_enable','is_seniority','is_reward','reward_limit','upload_limit','is_show_reward_limit'], 'integer'],
  189. [['seniority','default_score'], 'safe'],
  190. [['reward_limit'], 'double'],
  191. [['explain'], 'string']
  192. ]);
  193. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  194. // 保存配置
  195. $params['default_score'] = json_encode($params['default_score']);
  196. $params['seniority'] = json_encode($params['seniority']);
  197. $config = Yii::$app->services->setting->addons->set($this->mall_id, 'Clockin', ['basic' => $params]);
  198. $this->success('保存成功', $config);
  199. }
  200. }
  201. /**
  202. * 奖励用户
  203. * @Author: lun
  204. * @DateTime: 2023/7/27 0027 9:33
  205. * @Copyright: copyright (c) 2021 广东七件事集团
  206. * @return mixed|string|void
  207. */
  208. public function actionUser()
  209. {
  210. $retuest = Yii::$app->request;
  211. if ($retuest->isAjax) {
  212. if ($retuest->isGet) {
  213. $get = Yii::$app->request->get();
  214. // 检查提交的参数
  215. $res = Yii::$app->services->validate->validate($get,[
  216. [['user_id','mobile','limit'], 'integer'],
  217. ]);
  218. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  219. $where = [];
  220. $where[] = ['=', 'status', StatusEnum::ENABLED];
  221. $where[] = ['=', 'mall_id', $this->mall_id];
  222. !empty($get['user_id']) && $where[] = ['=', 'user_id', $get['user_id']];
  223. if (!empty($get['mobile'])) {
  224. $user_id = User::find()->select('id')->where(['mall_id' => $this->mall_id, 'mobile' => $get['mobile'], 'status' => StatusEnum::ENABLED])->scalar();
  225. if (empty($user_id)) return $this->error('查无此用户!');
  226. $where[] = ['=', 'user_id', $user_id];
  227. }
  228. $with = ['user'];
  229. $order = 'id desc,created_at desc';
  230. $params = array('where' => $where, 'order'=>$order, 'with' => $with, 'limit' => $get['limit'] ?? 20);
  231. $list = ClockinUser::listPage($params, false, true);
  232. $this->success('获取成功', compact('list'));
  233. }
  234. } else {
  235. return $this->render($this->action->id);
  236. }
  237. }
  238. /**
  239. * 获取用户奖励记录
  240. * @Author: lun
  241. * @DateTime: 2023/7/27 0027 9:35
  242. * @Copyright: copyright (c) 2021 广东七件事集团
  243. * @return mixed|void
  244. */
  245. public function actionRewardLogs()
  246. {
  247. $retuest = Yii::$app->request;
  248. if ($retuest->isAjax && $retuest->isGet) {
  249. $get = Yii::$app->request->get();
  250. // 检查提交的参数
  251. $res = Yii::$app->services->validate->validate($get,[
  252. [['user_id','limit'], 'integer'],
  253. [['user_id'], 'required'],
  254. ]);
  255. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  256. $where = [];
  257. $where[] = ['=', 'status', StatusEnum::ENABLED];
  258. $where[] = ['=', 'mall_id', $this->mall_id];
  259. $where[] = ['=', 'user_id', $get['user_id']];
  260. $order = 'id desc,created_at desc';
  261. $params = array('where' => $where, 'order'=>$order, 'limit' => $get['limit'] ?? 20);
  262. $list = ClockinRewardLog::listPage($params, false, true);
  263. $this->success('获取成功', $list);
  264. }
  265. }
  266. }