106 lines
3.3 KiB
PHP
106 lines
3.3 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
require_once APPPATH . 'controllers/api/BaseController.php';
|
|
|
|
class ProductCoupon extends BaseController
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('agent/auto_product_coupon_model', 'autoProductCoupon');
|
|
$this->load->helper('image');
|
|
$this->load->model('area_model');
|
|
}
|
|
|
|
public function page_get()
|
|
{
|
|
$params = $this->input_param();
|
|
$page = $this->input_param('page');
|
|
$limit = $this->input_param('limit');
|
|
$title = $this->input_param('title');
|
|
!$page && $page = 1;
|
|
!$limit && $limit = 10;
|
|
$sort_order = 'id desc';
|
|
$list = [];
|
|
$where = ['status>=' => 0, 'product_id' => $params['productId']];
|
|
$title && $where['title LIKE "%' . trim($title) . '%"'] = null;
|
|
$count = $this->autoProductCoupon->count($where);
|
|
if ($count) {
|
|
$res = $this->autoProductCoupon->select($where, $sort_order, $page, $limit, '', 'AutoProductCouponEntity');
|
|
/** @var AutoProductCouponEntity[] $res */
|
|
foreach ($res as $v) {
|
|
$temp = (array)$v;
|
|
$temp['status'] = intval($v->status);
|
|
$temp['dateRange'] = [$v->timeStart, $v->timeEnd];
|
|
$temp['userType'] = intval($v->userType) ?: 0;
|
|
$temp['bizs'] = $v->getBizs();
|
|
$temp['selectBiz'] = $v->getShowBiz($temp['bizs']);
|
|
$temp['typeCn'] = $v->getTypeCn();
|
|
$list[] = $temp;
|
|
}
|
|
}
|
|
$data = ['list' => $list, 'count' => $count];
|
|
$this->return_response_list($data);
|
|
}
|
|
|
|
public function index_post()
|
|
{
|
|
$params = $this->input_param();
|
|
if (!$params['productId']) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
$res = $this->autoProductCoupon->saveOrUpdate($params);
|
|
if (!$res) {
|
|
$this->return_json('添加失败');
|
|
}
|
|
$this->return_response();
|
|
}
|
|
|
|
public function index_put()
|
|
{
|
|
$params = $this->input_param();
|
|
if (!$this->autoProductCoupon->get(['id' => $params['id']])) {
|
|
$this->return_json('数据不存在');
|
|
}
|
|
$res = $this->autoProductCoupon->saveOrUpdate($params);
|
|
if (!$res) {
|
|
$this->return_json('更新失败');
|
|
}
|
|
$this->return_response();
|
|
}
|
|
|
|
/**
|
|
* 修改状态
|
|
*/
|
|
public function status_put()
|
|
{
|
|
$id = $this->input_param('id');
|
|
$status = $this->input_param('status');
|
|
if (!$this->autoProductCoupon->get(['id' => $id])) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
$update = [
|
|
'status' => $status,
|
|
];
|
|
$this->autoProductCoupon->update($update, ['id' => $id]);
|
|
$this->return_response();
|
|
}
|
|
|
|
/**
|
|
* 删除
|
|
*/
|
|
public function index_delete()
|
|
{
|
|
$ids = $this->input_param('ids');
|
|
if (!$ids) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
$str_ids = is_array($ids) ? implode(',', $ids) : $ids;
|
|
if ($str_ids) {
|
|
$this->autoProductCoupon->update(['status' => -1], ["id in($str_ids)" => null]);
|
|
}
|
|
$this->return_response();
|
|
}
|
|
}
|