Browse Source

优惠券数量统计

master
parent
commit
9128c98ca1
  1. 31
      app/Controller/CouponController.php

31
app/Controller/CouponController.php

@ -60,25 +60,20 @@ class CouponController extends BaseController
//统计用户
public function userCouponAccount()
{
$user_id = $this->request->input('user_id');
$userId = $this->request->input("user_id");
$nowTime = time();
$userCouponCount = DB::table('ims_system_coupon_user_receive')
->select(['ims_system_coupon_user_receive.number_remain'])
->leftJoin('ims_system_coupon_user',
'ims_system_coupon_user_receive.system_coupon_user_id',
'=',
'ims_system_coupon_user.id')
->where('ims_system_coupon_user.usable_end_time','>',$nowTime)
->where('ims_system_coupon_user_receive.user_id','=',$user_id)
->whereIn('ims_system_coupon_user_receive.status',[0,1])
->get();
if (count($userCouponCount)){
$count = array_sum(array_column($userCouponCount->toArray(),'number_remain'));
}else{
$count = 0;
}
return $this->success(['total' => $count]);
$num = Db::table('ims_system_coupon_user_receive as receive')
->join('ims_system_coupon_user as u', 'u.id', '=', 'receive.system_coupon_user_id')
->where([
['receive.user_id','=',$userId],
['receive.number_remain','>',0],
['u.usable_end_time','>',$nowTime],
])
->whereIn('receive.status',[0,1])
->sum('receive.number_remain');
return $this->success(['total' => $num]);
}
@ -160,7 +155,7 @@ class CouponController extends BaseController
->get();
foreach ($coupons as $key => $coupon) {
if ($coupon->usable_end_time < $nowTime || $coupon->status != 1 || $coupon->number_remain <= 0) {
if ($coupon->usable_end_time < $nowTime || $coupon->number_remain <= 0) {
$expired[] = $coupon;
} else {
$not_expired[] = $coupon;

Loading…
Cancel
Save