master
wangxinglong 2022-02-08 10:18:44 +08:00
parent 6fbd1168cd
commit 2549b509b4
2 changed files with 49 additions and 12 deletions

View File

@ -42,7 +42,7 @@ class Coupon extends Base
{
$page = $this->request->param('page/d', 1);
$size = $this->request->param('size/d', 10);
$type = $this->request->param('type', '');
//$type = $this->request->param('type', '');
$page = $page < 1 ? 1 : $page;
$size = $size < 1 ? 10 : $size;
@ -145,15 +145,22 @@ class Coupon extends Base
//到期状态
$expirationStr = '';
$endTime = strtotime($item->endTime);
//$expirationStr = '';
$status = CouponModel::status_success;//默认未使用
$endTime = strtotime($item->endTime);
$ExpirationTime = abs(($endTime - $time) / 86400);
if (($endTime > $time) ) {
$expirationStr = "还有".ceil($ExpirationTime)."天过期";
$expirationStr = "还有".ceil($ExpirationTime)."天过期";
} else {
$expirationStr = "已过期" . ceil($ExpirationTime) . "";
$status = CouponModel::status_be_overdue;
$expirationStr = "已过期" . ceil($ExpirationTime) . "";
}
$item->expirationStr =$expirationStr;
$item->expirationStr = $expirationStr;
if($item->isVerificated == CouponModel::is_verificated_on){
$status = CouponModel::status_used;
}
$item->status = $status;
//商家简称
@ -190,10 +197,10 @@ class Coupon extends Base
$businessCode = $this->request->param('business_code/s', '');
$page = $page < 1 ? 1 : $page;
$size = $size < 1 ? 10 : $size;
$page = $page < 1 ? 1 : $page;
$size = $size < 1 ? 10 : $size;
$accountCode = $this->request->user['user_code'] ?? '';
$time = time();
try {
$whereMap = [];
@ -229,13 +236,39 @@ class Coupon extends Base
]);
}, $sortOrder);
$res['list'] ->each(function ($item){
$res['list'] ->each(function ($item) use($time){
//重置优惠券名称
if(isset($item->couponMain) && $item->couponMain){
$item->couponName = $item->couponMain->name;
}
//重置过期时间
$item->endTimeText = date("Y-m-d",strtotime($item->endTime));
$status = CouponModel::status_success;//默认未使用
$endTime = strtotime($item->endTime);
$ExpirationTime = abs(($endTime - $time) / 86400);
if (($endTime > $time) ) {
$expirationStr = "还有".ceil($ExpirationTime)."天过期";
} else {
$status = CouponModel::status_be_overdue;
$expirationStr = "已过期" . ceil($ExpirationTime) . "";
}
$item->expirationStr = $expirationStr;
if($item->isVerificated == CouponModel::is_verificated_on){
$status = CouponModel::status_used;
}
$item->status = $status;
//重置优惠券名称
if(isset($item->couponMain) && $item->couponMain){
$item->couponName = $item->couponMain->name;
$item->image_url = $this->request->domain() . $item->couponMain->image_url;
}else{
$item->image_url = $this->request->domain() . '';
}
});
$res['list'] = multiTwoArrayKeysExcludeFilter($res['list']->toArray(), ['sort_weight']);

View File

@ -15,8 +15,12 @@ use think\db\exception\ModelNotFoundException;
class Coupon extends Base
{
//是否验证
const is_verificated_on = 1;//1已验证
const is_verificated_off = 0;//0未验证
const is_verificated_on = 1;//1已验证
const is_verificated_off = 0;//0未验证
const status_success = 0;//未过期未使用
const status_used = 1;//已使用
const status_be_overdue = 3;//已过期
public function couponBill()