user; $config = Yii::$app->services->setting->addons->get($this->mall_id, 'Clockin', 'basic'); if (empty($config['is_enable'])) return $this->error('插件未开启'); $data = [ 'user_id' => $this->user_id, 'nickname' => $user['nickname'], 'avatar_url' => $user['avatar_url'], 'success_num' => 0, 'total_reward' => 0, 'reward_limit' => $config['reward_limit'] ?? 0, 'is_show_reward_limit' => $config['is_show_reward_limit'] ?? 1, ]; $clockin_user = ClockinUser::findOne(['user_id' => $this->user_id, 'status' => StatusEnum::ENABLED, 'mall_id' => $this->mall_id]); if (!empty($clockin_user)) { $data['success_num'] = $clockin_user['success_num']; $data['total_reward'] = $clockin_user['total_reward']; } return $this->success('success', $data); } public function actionActivityDetail() { $config = Yii::$app->services->setting->addons->get($this->mall_id, 'Clockin', 'basic'); $data = [ 'explain' => $config['explain'] ?? '', ]; return $this->success('success', $data); } public function actionRewardLogList() { $params = Yii::$app->request->get(); $res = Yii::$app->services->validate->validate($params, [ [['limit', 'page'], 'integer'], ]); 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' => $this->user_id]; $order = 'id desc,created_at desc'; $params['where'] = $where; $params['order'] = $order; $params['select'] = 'id,apply_id,reward,created_at'; if (empty($params['limit'])) $params['limit'] = 10; if (empty($params['page'])) $params['limit'] = 1; $list = ClockinRewardLog::listPage($params, false, true); if (!empty($list['list'])) { $apply_ids = array_column($list['list'], 'apply_id'); $apply_list = ClockinApply::lists([ 'where' => [ ['id' => $apply_ids], ], 'index' => 'id', ]); foreach ($list['list'] as &$item) { $item['desc'] = ''; $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']); if (isset($apply_list[$item['apply_id']])) { $item['desc'] = '您在' . date('m/d H:i', $apply_list[$item['apply_id']]['created_at']) . '分享审核已通过!'; } unset($item['apply_id']); } } return $this->success('success', $list); } public function actionApplyList() { $params = Yii::$app->request->get(); $res = Yii::$app->services->validate->validate($params, [ [['limit', 'page'], 'integer'], [['is_pass'], 'safe'], ]); 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' => $this->user_id]; if (isset($params['is_pass'])) { if ($params['is_pass'] == -1) { $where[] = ['is_pass' => [-1,-2]];// 驳回+撤销 } else { $where[] = ['is_pass' => $params['is_pass']]; } } $order = 'id desc,created_at desc'; $params['where'] = $where; $params['order'] = $order; if (empty($params['limit'])) $params['limit'] = 10; if (empty($params['page'])) $params['limit'] = 1; $list = ClockinApply::listPage($params, false, true); if (!empty($list['list'])) { foreach ($list['list'] as &$item) { $item['pic'] = json_decode($item['pic'], true); } } $list['is_pass_map'] = [ -2 => '已撤销', -1 => '未通过', 0 => '审核中', 1 => '已通过', ]; return $this->success('success', $list); } public function actionApply() { try { $params = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['pic'], 'required'], [['remark','id'], 'safe'], ]); if ($res === false) throw new \Exception (Yii::$app->services->validate->getErrorMessage()); $res = $this->check(); $upload_limit = $res['upload_limit'] ?? 1; if (count($params['pic']) > $upload_limit) { throw new \Exception("至多可上传{$upload_limit}张图片"); } if(!empty($params['id'])){ $params['is_pass'] = 0; } $params['user_id'] = $this->user_id; $params['mall_id'] = $this->mall_id; $params['pic'] = json_encode($params['pic']); $res = ClockinApply::setData($this->mall_id, $params); if ($res == false) throw new \Exception(ClockinApply::getStaticError()); return $this->success('success'); } catch (\Exception $e) { return $this->error($e->getMessage()); } } /** * 用户主动撤销 * @Author: hua * @DateTime: 2023/8/8 0008 17:59 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void */ public function actionCancel() { try { $params = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['id'], 'required'], ]); if ($res === false) throw new \Exception (Yii::$app->services->validate->getErrorMessage()); $this->check(); $params['user_id'] = $this->user_id; $params['mall_id'] = $this->mall_id; $params['reason'] = '用户已撤销'; $params['is_pass'] = -2; $res = ClockinApply::changeStatus($this->mall_id, $params); if ($res == false) throw new \Exception(ClockinApply::getStaticError()); return $this->success('success'); } catch (\Exception $e) { return $this->error($e->getMessage()); } } public function actionApplyDetail() { try { $params = Yii::$app->request->get(); $res = Yii::$app->services->validate->validate($params, [ [['id'], 'required'], ]); if ($res === false) throw new \Exception (Yii::$app->services->validate->getErrorMessage()); $this->check(); $detail = ClockinApply::getOne([ ['id'=>$params['id']], ['mall_id'=>$this->mall_id], ['user_id'=>$this->user_id] ] ); if (empty($detail)) throw new \Exception('记录不存在'); $detail['pic'] = json_decode($detail['pic'],true); $detail['reason'] = $detail['reason'] ??''; return $this->success('success',$detail,ApiStatusEnum::CODE_SUCCESS, 0); } catch (\Exception $e) { return $this->error($e->getMessage()); } } public function actionCheck() { try { $res = $this->check(); return $this->success('success', ['upload_limit' => $res['upload_limit'] ?? 1]); } catch (\Exception $e) { return $this->error($e->getMessage()); } } public function check() { $config = Yii::$app->services->setting->addons->get($this->mall_id, 'Clockin', 'basic'); if (empty($config['is_enable'])) throw new \Exception('插件未开启'); if (!empty($config['is_seniority'])) { $seniority = json_decode($config['seniority'], true); if (empty($seniority)) $seniority = []; $user_level = $this->user['level']; if (!in_array($user_level, $seniority)) { throw new \Exception('你还没有参与打卡奖励资格!请尽快升级哦!'); } } return $config; } }