|
|
@@ -594,6 +594,57 @@ class MemberService extends BaseService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 设置主页背景
|
|
|
+ * @param $userId
|
|
|
+ * @param $params
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function setBg($userId, $params)
|
|
|
+ {
|
|
|
+ $cacheLockKey = "caches:members:setbg_{$userId}";
|
|
|
+ if (RedisService::get($cacheLockKey)) {
|
|
|
+ $this->error = 1034;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 用户验证
|
|
|
+ RedisService::set($cacheLockKey, ['user_id' => $userId, 'params' => $params], rand(2, 3));
|
|
|
+ $info = $this->model->where(['id' => $userId, 'mark' => 1])
|
|
|
+ ->select(['id', 'nickname','home_bg','avatar', 'status'])
|
|
|
+ ->first();
|
|
|
+ if (!$info || $info['status'] != 1) {
|
|
|
+ $this->error = 2016;
|
|
|
+ RedisService::clear($cacheLockKey);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 修改数据
|
|
|
+ $data = ['update_time' => time()];
|
|
|
+
|
|
|
+ // 背景
|
|
|
+ $homeBg = isset($params['home_bg']) ? $params['home_bg'] : '';
|
|
|
+ if (isset($params['home_bg']) && $homeBg) {
|
|
|
+ $data['home_bg'] = get_image_path($homeBg);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$this->model->where(['id' => $userId])->update($data)) {
|
|
|
+ $this->error = '设置失败';
|
|
|
+ RedisService::clear($cacheLockKey);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $oldBg = isset($info['home_bg']) ? $info['home_bg'] : '';
|
|
|
+ if ($homeBg && $oldBg && ($homeBg != $oldBg) && file_exists(ATTACHMENT_PATH . $oldBg)) {
|
|
|
+ @unlink(ATTACHMENT_PATH . $oldBg);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->error = '设置成功';
|
|
|
+ RedisService::clear($cacheLockKey);
|
|
|
+ RedisService::clear("caches:members:info_{$userId}");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 获取团队列表
|
|
|
* @param $userId
|
|
|
* @param $params
|