示例#1
0
 /**
  * 根据用户的行为数据分析并发送自动任务
  *
  * @param array $behavior
  * @return boolean
  */
 public function sendAutoTask($behavior)
 {
     if (!Wekit::C('site', 'task.isOpen')) {
         return false;
     }
     $whitBehavior = array('login_days', 'post_days', 'thread_count');
     if (!in_array($behavior['behavior'], $whitBehavior)) {
         return false;
     }
     $tody = Pw::time2str(Pw::getTime(), 'Y-m-d');
     $isSend = false;
     switch ($behavior['behavior']) {
         case 'login_days':
             $isSend = $behavior['number'] % 3 == 0;
             break;
         case 'post_days':
             $is_tody = $tody == Pw::time2str($behavior['extend_info'], 'Y-m-d');
             $isSend = $is_tody && $behavior['number'] % 2 == 0;
             break;
         case 'thread_count':
             $isSend = $behavior['number'] == 1 || $behavior['number'] % 50 == 0;
             break;
     }
     if (!$isSend) {
         return false;
     }
     Wind::import('SRV:task.srv.PwTaskApply');
     $userTask = new PwTaskApply($behavior['uid']);
     $userTask->autoApplies($this->getAutoApplicableTaskList($behavior['uid'], 1));
     return true;
 }
 public function welcome(PwUserBo $userBo, $ip)
 {
     if (!Wekit::C('site', 'task.isOpen')) {
         return true;
     }
     /* @var $behaviorDs PwUserBehavior */
     $behaviorDs = Wekit::load('user.PwUserBehavior');
     $info = $behaviorDs->getBehavior($userBo->uid, 'login_days');
     $time = $info['extend_info'] ? $info['extend_info'] : 0;
     if (!$time || Pw::time2str($time, 'Y-m-d') < Pw::time2str(Pw::getTime(), 'Y-m-d')) {
         /* @var $taskService PwTaskService */
         $taskService = Wekit::load('SRV:task.srv.PwTaskService');
         $userTask = new PwTaskApply($userBo->uid);
         $autoTaskIds = $taskService->getAutoApplicableTaskList($userBo->uid, 5);
         $userTask->autoApplies($autoTaskIds);
     }
     return true;
 }
示例#3
0
 /**
  * 将该任务的后置自动任务发送给用户
  *
  * @param int $task_id
  * @return boolean
  */
 private function sendNextAutoApplicableTaskList()
 {
     /* @var $taskService PwTaskService */
     $taskService = Wekit::load('task.srv.PwTaskService');
     $childs = $taskService->getNextAutoApplicableTaskList($this->taskId, $this->uid);
     if (!$childs) {
         return true;
     }
     $userService = new PwTaskApply($this->uid);
     $userService->autoApplies($childs);
     return true;
 }
示例#4
0
 /**
  * 申领任务
  */
 public function applyTaskAction()
 {
     $id = intval($this->getInput('id'));
     if ($id < 0) {
         $this->showError('TASK:id.illegal');
     }
     Wind::import('SRV:task.srv.PwTaskApply');
     /*@var $taskApply PwTaskApply */
     $taskApply = new PwTaskApply($this->loginUser->uid);
     if (($result = $taskApply->apply($id)) instanceof PwError) {
         $this->showError($result->getError());
     }
     $condition = unserialize($result['conditions']);
     $reward = unserialize($result['reward']);
     $url = $condition['url'] ? $condition['url'] : 'task/index/run';
     //去做任务地址
     $this->addMessage(WindUrlHelper::createUrl($url), 'url');
     //奖励
     $this->addMessage($reward['descript'] ? $reward['descript'] : '无', 'reward');
     //标题
     $this->addMessage($result['title'], 'title');
     //目标
     $this->addMessage($result['description'], 'description');
     //前置任务
     $parent = '';
     if ($result['pre_task']) {
         $pre_task = Wekit::load('task.PwTask')->get($result['pre_task']);
         $parent['parent'] = $pre_task['title'];
     }
     $this->addMessage($parent, 'pre_task');
     //时限
     $time = '不限';
     if ($result['start_time'] || $result['end_time'] != PwTaskDm::MAXENDTIME) {
         $start_time = $result['start_time'] ? Pw::time2str($result['start_time'], 'Y-m-d') : '不限';
         $end_time = $result['end_time'] == PwTaskDm::MAXENDTIME ? '不限' : Pw::time2str($result['end_time'], 'Y-m-d');
         $time = $start_time . ' 至 ' . $end_time;
     }
     $this->addMessage($time, 'time');
     $this->showMessage('TASK:apply.success');
 }