예제 #1
0
 /**
  * 更新一条用户任务
  *
  * @param int $taskid
  * @param int $uid
  * @param PwTaskUserDm $dm
  * @return PwError|boolean
  */
 public function update($taskid, $uid, PwTaskUserDm $dm)
 {
     if (0 >= ($taskid = intval($taskid)) || 0 >= ($uid = intval($uid))) {
         return new PwError('TASK:id.illegal');
     }
     return $this->_taskUserDao()->updateByTaskIdAndUid($taskid, $uid, $dm->getData());
 }
예제 #2
0
 /**
  * 更新用户任务
  * 
  * @param int $taskId
  * @param array $conditions
  * @param array $step
  * @return boolean
  */
 private function _doTask($taskInfo, $conditions, $step)
 {
     $result = $this->doTask->doTask($conditions, $step);
     if (!is_array($result) || !isset($result['isComplete']) || !isset($result['step'])) {
         return false;
     }
     $dm = new PwTaskUserDm();
     $dm->setTaskStatus($result['isComplete'] === true ? 2 : 1);
     if (true === $result['isComplete']) {
         /* @var $notice PwNoticeService */
         $notice = Wekit::load('message.srv.PwNoticeService');
         $taskInfo['complete'] = 1;
         $notice->sendNotice($this->uid, 'task', $this->uid, $taskInfo);
         is_array($result['step']) && ($result['step']['percent'] = '100%');
     }
     $dm->setStep(is_array($result['step']) ? serialize($result['step']) : $result['step']);
     return $this->_getTaskUserDs()->update($taskInfo['taskid'], $this->uid, $dm);
 }
예제 #3
0
 /**
  * 获取奖励
  * 
  * 1:如果该任务是自动发放的任务,自动任务完成之后更新pw_task_cache"表:
  * 1-1:如果该任务是周期任务:更新task_ids中完成的自动周期任务的ID列表
  * 1-2:该任务是否是某些自动任务的前置任务,则将满足如下条件的任务推送给用户acceptTask:
  * 1-2-1:已该任务为前置的任务
  * 1-2-2:这些任务是自动任务
  * 1-2-3:这些任务是没有过期的任务
  * 1-2-4:这些任务是当前用户所在组可以申领的任务
  * 
  * @param int $task_id 任务ID
  * @return boolean|PwError
  */
 public function gainReward()
 {
     if (true !== $this->error) {
         return $this->error;
     }
     $dm = new PwTaskUserDm();
     $dm->setTaskStatus(PwTaskUser::COMPLETE)->setFinishTime(Pw::getTime());
     $this->_getTaskUserDs()->update($this->taskId, $this->uid, $dm);
     $this->updateUserCache();
     $r = $this->runWithVerified('gainReward', $this->uid, $this->taskInfo['reward'], $this->taskInfo['title']);
     if (true !== $r) {
         return $r;
     }
     return $this->sendNextAutoApplicableTaskList();
 }
예제 #4
0
 /**
  * 添加一个任务申领
  *
  * @param array $task
  * @return Ambigous <boolean, PwError>
  */
 private function doApply($task)
 {
     $dm = new PwTaskUserDm();
     $dm->setTaskid($task['taskid'])->setUid($this->uid)->setTaskStatus(1)->setIsPeriod($task['period'] > 0 ? 1 : 0)->setCreatedTime(Pw::getTime());
     $r = $this->_getTaskUserDs()->replaceUserTask($dm);
     if ($r instanceof PwError) {
         return $r;
     }
     return $this->_getTaskDs()->get($task['taskid']);
 }