/**
  * 自动勋章发放 条件最高的一个
  *
  * 写入状态为可领取
  */
 protected function awardMaxMedal()
 {
     $ds = Wekit::load('medal.PwMedalLog');
     //$ds->deleteInfosByUidMedalIds($this->medalBo->uid, array_keys($this->medalBo->getAlreadyMedals()));//删除已发放给用户这一类型的勋章
     Wekit::load('medal.dm.PwMedalLogDm');
     $dm = new PwMedalLogDm();
     $time = Pw::getTime();
     $dm->setMedalid($this->awardMedalId)->setUid($this->userBo->uid)->setAwardStatus(3)->setCreatedTime($time)->setExpiredTime(0);
     $resource = $ds->replaceMedalLog($dm);
     if (!$resource instanceof PwError) {
         Wekit::load('medal.srv.PwMedalService')->sendNotice($this->userBo->uid, $resource, $this->awardMedalId, 1);
     }
 }
 /**
  * 管理员批量颁发勋章策略
  * Enter description here ...
  */
 public function doAddAwardAction()
 {
     $username = trim($this->getInput('username', 'post'));
     $medalId = (int) $this->getInput('medalid', 'post');
     $message = $this->getInput('message', 'post');
     if ($medalId < 1) {
         $this->showError('MEDAL:fail');
     }
     if (!$username) {
         $this->showError('MEDAL:award.username.require');
     }
     $usernames = array_unique(explode(' ', $username));
     if (count($usernames) < 1) {
         $this->showError('MEDAL:award.username.require');
     }
     $userDs = Wekit::load('SRV:user.PwUser');
     $users = $userDs->fetchUserByName($usernames);
     //$users = array_keys($userInfos);
     if (!is_array($users) || count($users) < 1) {
         $this->showError('MEDAL:username.fail');
     }
     $info = $this->_getMedalDs()->getMedalInfo($medalId);
     if (!$info) {
         $this->showError('MEDAL:medal.fail');
     }
     $time = Pw::getTime();
     $expired = $info['receive_type'] == 2 && $info['expired_days'] > 0 ? $time + $info['expired_days'] * 24 * 60 : 0;
     $userSrv = Wekit::load('user.srv.PwUserService');
     $medalSrv = $this->_getMedalService();
     Wind::import('SRV:medal.dm.PwMedalLogDm');
     $ds = $this->_getMedalLogDs();
     $msg = '';
     foreach ($users as $user) {
         if (!$user['uid']) {
             continue;
         }
         /*$userGids = $userSrv->getGidsByUid($user['uid']);
         		if (!$medalSrv->allowAwardMedal($userGids, $info['medal_gids'])) {
         			$msg .= $user['username'] . '所在用户组不能颁发;';
         			continue;
         		}*/
         $log = $this->_getMedalLogDs()->getInfoByUidMedalId($user['uid'], $medalId);
         if (isset($log['award_status']) && $log['award_status'] == 4) {
             $msg .= $user['username'] . '已拥有该勋章;';
             continue;
         }
         if (isset($log['log_id']) && $log['log_id'] > 1) {
             $dm = new PwMedalLogDm($log['log_id']);
             $dm->setMedalid($medalId)->setUid($user['uid'])->setAwardStatus(PwMedalLog::STATUS_AWARD)->setCreatedTime($time)->setExpiredTime($expired);
             $resource = $ds->updateInfo($dm);
         } else {
             $dm = new PwMedalLogDm();
             $dm->setMedalid($medalId)->setUid($user['uid'])->setAwardStatus(PwMedalLog::STATUS_AWARD)->setCreatedTime($time)->setExpiredTime($expired);
             $resource = $ds->replaceMedalLog($dm);
         }
         if (!$resource instanceof PwError) {
             $this->_getMedalService()->updateMedalUser($user['uid']);
             $this->_getMedalService()->sendNotice($user['uid'], $resource, $medalId, 2, $message);
         }
     }
     $msg = $msg ? $msg : 'MEDAL:success';
     $this->showMessage($msg);
 }
 /**
  * 颁发勋章,用于完成的自动任务获取的勋章
  * 
  * @param int $uid
  * @param int $medalId
  */
 public function awardTaskMedal($uid, $medalId)
 {
     $info = $this->_getMedalDs()->getMedalInfo($medalId);
     if (!$info) {
         return false;
     }
     $userLog = $this->_getMedalLogDs()->getInfoByUidMedalId($uid, $medalId);
     Wind::import('SRV:medal.dm.PwMedalLogDm');
     $time = Pw::getTime();
     if ($userLog && $userLog['award_status'] < 4) {
         $dm = new PwMedalLogDm($userLog['log_id']);
         $dm->setAwardStatus(3);
         $resource = $this->_getMedalLogDs()->updateInfo($dm);
     } else {
         $dm = new PwMedalLogDm();
         $dm->setMedalid($medalId)->setUid($uid)->setAwardStatus(3)->setCreatedTime($time);
         $resource = $this->_getMedalLogDs()->replaceMedalLog($dm);
     }
 }
Exemple #4
0
 public function doApplyAction()
 {
     $medalId = (int) $this->getInput('medalid', 'post');
     $medal = $this->_getMedalDs()->getMedalInfo($medalId);
     if (!$medal || $medal['receive_type'] == 1) {
         $this->showError('MEDAL:fail');
     }
     if (!$this->_getMedalService()->allowAwardMedal($this->loginUser->gid, $medal['medal_gids'])) {
         $this->showError('MEDAL:not.user.group');
     }
     $log = $this->_getMedalLogDs()->getInfoByUidMedalId($this->loginUser->uid, $medalId);
     if ($log) {
         $this->showError('MEDAL:already.apply');
     }
     Wind::import('SRV:medal.dm.PwMedalLogDm');
     $time = Pw::getTime();
     $dm = new PwMedalLogDm();
     $dm->setMedalid($medalId)->setUid($this->loginUser->uid)->setAwardStatus(2)->setCreatedTime($time);
     $resource = $this->_getMedalLogDs()->replaceMedalLog($dm);
     if ($resource instanceof PwError) {
         $this->showError('MEDAL:fail');
     }
     $this->showMessage("MEDAL:apply.success");
 }