186 lines
6.8 KiB
PHP
186 lines
6.8 KiB
PHP
<?php
|
|
/**
|
|
* SaaSMall商城系统 - 团队十年电商经验汇集巨献!
|
|
* =========================================================
|
|
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
|
|
* ----------------------------------------------
|
|
* 官方网址: https://www.gobuysaas.com
|
|
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
|
|
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
|
|
* =========================================================
|
|
*/
|
|
|
|
namespace addon\store\shopapi\controller;
|
|
|
|
use app\model\member\MemberCoupon;
|
|
use app\model\system\Promotion as PromotionModel;
|
|
|
|
|
|
class Coupon extends BaseStoreApi
|
|
{
|
|
/**
|
|
* 列表
|
|
*/
|
|
public function lists()
|
|
{
|
|
$from_type = $this->params[ 'from_type' ] ?? '';
|
|
$page = $this->params[ 'page' ] ?? 1;
|
|
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
|
|
$from_type_id = $this->params[ 'from_type_id' ] ?? 0;
|
|
$from_type_name = $this->params[ 'from_type_name' ] ?? '';
|
|
$name = $this->params[ 'name' ] ?? '';
|
|
$start_time = $this->params[ 'fetch_time_start' ] ?? '';
|
|
$end_time = $this->params[ 'fetch_time_end' ] ?? '';
|
|
$type = $this->params[ 'type' ] ?? '';
|
|
$use_type = $this->params[ 'use_type' ] ?? '';
|
|
|
|
$coupon_model = new MemberCoupon();
|
|
|
|
$condition = [
|
|
[ 'site_id', "=", $this->site_id ],
|
|
];
|
|
if (!empty($from_type)) {
|
|
$condition[] = [ "from_type", "=", $from_type ];
|
|
if (!empty($from_type_id)) {
|
|
$condition[] = [ "from_type_id", "=", $from_type_id ];
|
|
}
|
|
}
|
|
|
|
if (!empty($from_type_name)) {
|
|
$condition[] = [ "from_type_name", 'like', '%' . $from_type_name . '%' ];
|
|
}
|
|
|
|
if (!empty($type)) {
|
|
$condition[] = [ "type", '=', $type ];
|
|
}
|
|
if (!empty($use_type)) {
|
|
$condition[] = [ "use_type", '=', $use_type ];
|
|
}
|
|
if ($name !== '') {
|
|
$condition[] = [ "name", 'like', '%' . $name . '%' ];
|
|
}
|
|
if (!empty($start_time) && empty($end_time)) {
|
|
$condition[] = [ 'create_time', '>=', date_to_time($start_time) ];
|
|
} elseif (empty($start_time) && !empty($end_time)) {
|
|
$condition[] = [ "create_time", "<=", date_to_time($end_time) ];
|
|
} elseif (!empty($start_time) && !empty($end_time)) {
|
|
$condition[] = [ 'create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
|
|
}
|
|
$list = $coupon_model->getCouponPageList($condition, $page, $page_size, 'id desc');
|
|
return $this->response($list);
|
|
}
|
|
|
|
/**
|
|
* 顶部活动列表
|
|
*/
|
|
public function couponList()
|
|
{
|
|
$promotion_model = new PromotionModel();
|
|
$promotion_type_list = $promotion_model->getPromotionType('member');
|
|
$coupon_list = [];
|
|
foreach ($promotion_type_list as $k => $v) {
|
|
if ($v[ 'name' ] == 'sitecoupon') {
|
|
$coupon_list [ $v[ 'name' ] ] = $v;
|
|
}
|
|
}
|
|
return $this->response($this->success($coupon_list));
|
|
}
|
|
|
|
/**
|
|
* 账户优惠券数据
|
|
*/
|
|
public function couponAccount()
|
|
{
|
|
$coupon_model = new MemberCoupon();
|
|
$site_id = $this->site_id;
|
|
|
|
//累计发放优惠券数
|
|
$total_info = $coupon_model->getMemberCouponInfo([ [ 'site_id', '=', $site_id ] ], 'count(coupon_id) as count_coupon')[ 'data' ];
|
|
//累计使用
|
|
$use_info = $coupon_model->getMemberCouponInfo([ [ 'site_id', '=', $site_id ], [ 'state', '=', 2 ] ], 'count(coupon_id) as count_coupon')[ 'data' ];
|
|
//剩余
|
|
$surplus_info = $coupon_model->getMemberCouponInfo([ [ 'site_id', '=', $site_id ], [ 'state', '=', 1 ] ], 'count(coupon_id) as count_coupon')[ 'data' ];
|
|
|
|
$data = [];
|
|
$data[ 'coupon_count' ] = $total_info[ 'count_coupon' ] ?? 0;
|
|
$data[ 'use_coupon' ] = $use_info[ 'count_coupon' ] ?? 0;
|
|
$data[ 'surplus_coupon' ] = $surplus_info[ 'count_coupon' ] ?? 0;
|
|
return $this->response($this->success($data));
|
|
}
|
|
|
|
/**
|
|
* 会员优惠券
|
|
*/
|
|
public function receivelists()
|
|
{
|
|
$site_id = $this->site_id;
|
|
$from_type = $this->params[ 'from_type' ] ?? '';
|
|
$page = $this->params[ 'page' ] ?? 1;
|
|
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
|
|
$from_type_id = $this->params[ 'from_type_id' ] ?? 0;
|
|
$from_type_name = $this->params[ 'from_type_name' ] ?? '';
|
|
$coupon_code = $this->params[ 'coupon_code' ] ?? '';
|
|
$start_time = $this->params[ 'fetch_time_start' ] ?? '';
|
|
$end_time = $this->params[ 'fetch_time_end' ] ?? '';
|
|
$type = $this->params[ 'type' ] ?? '';
|
|
$parent_id = $this->params[ 'parent_id' ] ?? '';
|
|
$nick_name = $this->params[ 'nickname' ] ?? '';
|
|
$state = $this->params[ 'state' ] ?? '';
|
|
|
|
$coupon_model = new MemberCoupon();
|
|
|
|
$condition = [
|
|
[ 'site_id', "=", $site_id ],
|
|
];
|
|
if (!empty($from_type)) {
|
|
$condition[] = [ "from_type", "=", $from_type ];
|
|
if (!empty($from_type_id)) {
|
|
$condition[] = [ "from_type_id", "=", $from_type_id ];
|
|
}
|
|
}
|
|
|
|
if (!empty($from_type_name)) {
|
|
$condition[] = [ "from_type_name", 'like', '%' . $from_type_name . '%' ];
|
|
}
|
|
if (!empty($parent_id)) {
|
|
$condition[] = [ "parent_id", "=", $parent_id ];
|
|
}
|
|
if (!empty($coupon_code)) {
|
|
$condition[] = [ "coupon_code", 'like', '%' . $coupon_code . '%' ];
|
|
}
|
|
|
|
if (!empty($nick_name)) {
|
|
$condition[] = [ "member_name", 'like', '%' . $nick_name . '%' ];
|
|
}
|
|
if (!empty($type)) {
|
|
$condition[] = [ "type", '=', $type ];
|
|
}
|
|
if ($state !== '') {
|
|
$condition[] = [ "state", '=', $state ];
|
|
}
|
|
if (!empty($start_time) && empty($end_time)) {
|
|
$condition[] = [ 'fetch_time', '>=', date_to_time($start_time) ];
|
|
} elseif (empty($start_time) && !empty($end_time)) {
|
|
$condition[] = [ "fetch_time", "<=", date_to_time($end_time) ];
|
|
} elseif (!empty($start_time) && !empty($end_time)) {
|
|
$condition[] = [ 'fetch_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
|
|
}
|
|
|
|
$list = $coupon_model->getMemberCouponPageList($condition, $page, $page_size);
|
|
return $this->response($list);
|
|
}
|
|
|
|
/**
|
|
* 优惠券详情
|
|
*/
|
|
public function detail()
|
|
{
|
|
$id = $this->params[ 'id' ] ?? 0;
|
|
$site_id = $this->site_id;
|
|
$coupon_model = new MemberCoupon();
|
|
$info = $coupon_model->getCouponDetail($id, $site_id);
|
|
return $this->response($info);
|
|
|
|
}
|
|
|
|
} |