<?php
namespace app\api\controller\bargain;
use app\api\controller\Controller;
use app\api\model\bargain\Task as TaskModel;
use app\api\model\bargain\Setting as SettingModel;
class Task extends Controller
{
public function lists()
{
$model = new TaskModel;
$myList = $model->getMyList($this->getUser()['user_id']);
return $this->renderSuccess(compact('myList'));
}
public function partake($active_id, $goods_sku_id)
{
$user = $this->getUser();
$model = new TaskModel;
if (!$model->partake($user['user_id'], $active_id, $goods_sku_id)) {
return $this->renderError($model->getError() ?: '砍价任务创建失败');
}
return $this->renderSuccess([
'task_id' => $model['task_id']
]);
}
public function detail($task_id)
{
$model = new TaskModel;
$detail = $model->getTaskDetail($task_id, $this->getUser(false));
if ($detail === false) {
return $this->renderError($model->getError());
}
$setting = SettingModel::getBasic();
return $this->renderSuccess(array_merge($detail, ['setting' => $setting]));
}
public function help_cut($task_id)
{
$model = TaskModel::detail($task_id);
$cut_money = $model->getCutMoney();
if ($model->helpCut($this->getUser())) {
return $this->renderSuccess(compact('cut_money'), '砍价成功');
}
return $this->renderError($model->getError() ?: '砍价失败');
}
}