<?php
namespace app\store\controller\market;
use app\store\controller\Controller;
use app\store\model\Coupon as CouponModel;
use app\store\model\UserCoupon as UserCouponModel;
class Coupon extends Controller
{
private $model;
public function _initialize()
{
parent::_initialize();
$this->model = new CouponModel;
}
public function index()
{
$list = $this->model->getList();
return $this->fetch('index', compact('list'));
}
public function add()
{
if (!$this->request->isAjax()) {
return $this->fetch('add');
}
if ($this->model->add($this->postData('coupon'))) {
return $this->renderSuccess('添加成功', url('market.coupon/index'));
}
return $this->renderError($this->model->getError() ?: '添加失败');
}
public function edit($coupon_id)
{
$model = CouponModel::detail($coupon_id);
if (!$this->request->isAjax()) {
return $this->fetch('edit', compact('model'));
}
if ($model->edit($this->postData('coupon'))) {
return $this->renderSuccess('更新成功', url('market.coupon/index'));
}
return $this->renderError($model->getError() ?: '更新失败');
}
public function delete($coupon_id)
{
$model = CouponModel::detail($coupon_id);
if ($model->setDelete()) {
return $this->renderSuccess('删除成功', url('market.coupon/index'));
}
return $this->renderError($model->getError() ?: '删除成功');
}
public function receive()
{
$model = new UserCouponModel;
$list = $model->getList();
return $this->fetch('receive', compact('list'));
}
}