You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
ymww_backend/application/admin/controller/shopro/user/Coupon.php

64 lines
1.6 KiB

<?php
namespace app\admin\controller\shopro\user;
use app\admin\controller\shopro\Common;
use app\admin\model\shopro\order\Order;
use app\admin\model\shopro\user\Coupon as UserCouponModel;
use think\Db;
class Coupon extends Common
{
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new UserCouponModel;
}
public function index()
{
if (!$this->request->isAjax()) {
return $this->view->fetch();
}
$coupon_id = $this->request->param('coupon_id');
$coupons = $this->model->sheepFilter()->with(['user', 'order'])
->where('coupon_id', $coupon_id)
->paginate($this->request->param('list_rows', 10));
$this->success('获取成功', null, $coupons);
}
/**
* 删除优惠券
*
* @param string $id 要删除的优惠券
* @return void
*/
public function delete($id)
{
if (empty($id)) {
$this->error(__('Parameter %s can not be empty', 'id'));
}
$id = explode(',', $id);
$list = $this->model->where('id', 'in', $id)->select();
$result = Db::transaction(function () use ($list) {
$count = 0;
foreach ($list as $item) {
$count += $item->delete();
}
return $count;
});
if ($result) {
$this->success('删除成功', null, $result);
} else {
$this->error(__('No rows were deleted'));
}
}
}