更新:用户领取的优惠卷查询接口
parent
8999c4d911
commit
9601d5dc32
|
@ -499,7 +499,7 @@ if (!function_exists('checkMobile')) {
|
|||
|
||||
if (!function_exists('arrayKeysFilter')) {
|
||||
/**
|
||||
* 数组键名过滤
|
||||
* 一维数组键名过滤
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $allowKeys
|
||||
|
@ -517,6 +517,29 @@ if (!function_exists('arrayKeysFilter')) {
|
|||
}
|
||||
}
|
||||
|
||||
if (!function_exists('multiTwoArrayKeysFilter')) {
|
||||
/**
|
||||
* 二维数组键名过滤
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $allowKeys 允许的字段
|
||||
* @return array
|
||||
*/
|
||||
function multiTwoArrayKeysFilter(array $data, array $allowKeys): array
|
||||
{
|
||||
foreach ($data as $ki => $item) {
|
||||
$list = [];
|
||||
foreach ($item as $key => $val) {
|
||||
if (in_array($key, $allowKeys)) {
|
||||
$list[$key] = $val;
|
||||
}
|
||||
}
|
||||
$data[$ki] = $list;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('getFilesize')) {
|
||||
/**
|
||||
* 尺寸单位转换
|
||||
|
@ -586,7 +609,7 @@ if (!function_exists('arrayNullToString')) {
|
|||
|
||||
if (!function_exists('arrayKeysExcludeFilter')) {
|
||||
/**
|
||||
* 数组键名排除过滤
|
||||
* 一维数组键名排除过滤
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $excludeKeys 排除的字段
|
||||
|
@ -603,6 +626,29 @@ if (!function_exists('arrayKeysExcludeFilter')) {
|
|||
}
|
||||
}
|
||||
|
||||
if (!function_exists('multiTwoArrayKeysExcludeFilter')) {
|
||||
/**
|
||||
* 二维维数组键名排除过滤
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $excludeKeys 排除的字段
|
||||
* @return array
|
||||
*/
|
||||
function multiTwoArrayKeysExcludeFilter(array $data, array $excludeKeys): array
|
||||
{
|
||||
foreach ($data as $ki => $item) {
|
||||
foreach ($item as $key => $val) {
|
||||
if (in_array($key, $excludeKeys)) {
|
||||
unset($item[$key]);
|
||||
}
|
||||
}
|
||||
$data[$ki] = $item;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('getLatelyWeekDate')) {
|
||||
/**
|
||||
* 获取本周的周一 到周日的日期
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
namespace app\controller\api;
|
||||
|
||||
use app\exception\RepositoryException;
|
||||
use app\repository\CouponRepository;
|
||||
|
||||
/**
|
||||
* 优惠卷相关
|
||||
* Class Coupon
|
||||
* @package app\controller\api
|
||||
*/
|
||||
class Coupon extends Base
|
||||
{
|
||||
protected $noNeedLogin = [
|
||||
'getMyCouponList'
|
||||
];
|
||||
|
||||
/**
|
||||
* 我的优惠卷列表
|
||||
*
|
||||
* type in ['', 'notUsed', 'normal', 'used']
|
||||
*/
|
||||
public function getMyCouponList()
|
||||
{
|
||||
$page = $this->request->param('page/d', 1);
|
||||
$size = $this->request->param('size/d', 10);
|
||||
$type = $this->request->param('type', '');
|
||||
|
||||
$page = $page < 1 ? 1 : $page;
|
||||
$size = $size < 1 ? 10 : $size;
|
||||
$accountCode = $this->request->user['user_code'] ?? '';
|
||||
|
||||
|
||||
try {
|
||||
$whereMap = [];
|
||||
$sortOrder = ['received_time' => 'desc'];
|
||||
$fields = ['*', '(end_time > NOW()) as sort_weight'];
|
||||
// TODO `status`字段需要核实是否用于筛选条件
|
||||
|
||||
$whereMap[] = ['consumer_code', '=', $accountCode];
|
||||
switch ($type) {
|
||||
case 'notUsed':
|
||||
// 未使用(包含已过期)
|
||||
$whereMap[] = ['is_verificated', '=', self::BOOL_FALSE];
|
||||
$sortOrder = ['sort_weight' => 'desc', 'end_time' => 'asc'];
|
||||
break;
|
||||
case 'normal':
|
||||
// 未使用且未过期
|
||||
$whereMap[] = ['is_verificated', '=', self::BOOL_FALSE];
|
||||
$whereMap[] = ['end_time', '< TIME', date('Y-m-d H:i:s')];
|
||||
$fields = [];
|
||||
break;
|
||||
case 'used':
|
||||
// 已使用
|
||||
$whereMap[] = ['is_verificated', '=', self::BOOL_TRUE];
|
||||
$sortOrder = ['verificate_time' => 'desc'];
|
||||
$fields = [];
|
||||
break;
|
||||
}
|
||||
|
||||
$res = CouponRepository::getInstance()->findList($whereMap, $fields, $page, $size, null, $sortOrder);
|
||||
$res['list'] = multiTwoArrayKeysExcludeFilter($res['list']->toArray(), ['sort_weight']);
|
||||
|
||||
return $this->json(0, 'success', $res);
|
||||
} catch (RepositoryException | \Exception $e) {
|
||||
return $this->json(5001, '优惠卷查询失败!');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -32,4 +32,9 @@ class Coupon extends Base
|
|||
{
|
||||
return $this->hasOne(Business::class,"code","business_code");
|
||||
}
|
||||
|
||||
public function couponMain()
|
||||
{
|
||||
return $this->hasOne(CouponMain::class, 'id', 'coupon_id');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue