示例#1
0
 /**
  * 开启一个任务
  *
  * @param int $id
  * @param int $status 开启1或是关闭0
  * @param int $order 顺序
  * @param string $title 标题
  * @return PwError|boolean
  */
 public function openTask($id, $status, $order = '', $title = '')
 {
     $task = $this->_taskDs()->get($id);
     if (!$task) {
         return new PwError('TASK:id.illegal');
     }
     $taskDm = new PwTaskDm();
     $reward = unserialize($task['reward']);
     $taskDm->setTaskId($id)->setTitle($title)->setViewOrder($order)->setIsOpen($status)->setEndTime($task['end_time'])->setIsAuto($task['is_auto'])->setIsDisplayAll($task['is_display_all'])->setUserGroups(explode(',', $task['user_groups']))->setReward($reward);
     PwTaskDmFactory::addRewardDecoration($taskDm, $reward);
     return $this->_taskDs()->updateTask($taskDm);
 }
示例#2
0
 /**
  * 添加pw_task表记录
  *
  * @param PwTaskDm $dm
  * @return PwError|int
  */
 public function addTask($dm)
 {
     if (!$dm instanceof PwTaskDm) {
         return new PwError('TASK:datamodel.illegal');
     }
     if (($r = $dm->beforeAdd()) instanceof PwError) {
         return $r;
     }
     //添加pw_task表记录
     $id = $this->_taskDao()->add($dm->getData());
     if (!$id) {
         return new PwError('TASK:addtask.fail');
     }
     /*如果开启状态,则将该数据添加到group表*/
     if (1 == $dm->getField('is_open')) {
         $dm->setTaskId($id);
         $result = $this->_taskGroupDao()->batchReplaceTaskGroups($dm->getTaskGroupData());
         if ($result instanceof PwError) {
             return $result;
         }
     }
     return $id;
 }