|
|
@ -9,6 +9,7 @@ declare(strict_types=1); |
|
|
* @contact group@hyperf.io |
|
|
* @contact group@hyperf.io |
|
|
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE |
|
|
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
namespace App\Controller; |
|
|
namespace App\Controller; |
|
|
|
|
|
|
|
|
use App\Model\CouponUserRecType; |
|
|
use App\Model\CouponUserRecType; |
|
|
@ -24,42 +25,66 @@ class CouponController extends BaseController |
|
|
/** |
|
|
/** |
|
|
* 获取用户可领取优惠卷接口 |
|
|
* 获取用户可领取优惠卷接口 |
|
|
*/ |
|
|
*/ |
|
|
public function getSystemCouponUserList(){ |
|
|
|
|
|
|
|
|
public function getSystemCouponUserList() |
|
|
|
|
|
{ |
|
|
$user_id = $this->request->input('user_id'); |
|
|
$user_id = $this->request->input('user_id'); |
|
|
$receive_type = $this->request->input('receive_type'); |
|
|
$receive_type = $this->request->input('receive_type'); |
|
|
|
|
|
|
|
|
$c_ids = CouponUserRecType::where('receive_type', $receive_type)->pluck('system_coupon_user_id'); |
|
|
$c_ids = CouponUserRecType::where('receive_type', $receive_type)->pluck('system_coupon_user_id'); |
|
|
$nowTime = time(); |
|
|
$nowTime = time(); |
|
|
$cr_ids = CouponRec::where('user_id',$user_id)->pluck('system_coupon_user_id'); |
|
|
|
|
|
|
|
|
$cr_ids = CouponRec::where( |
|
|
|
|
|
'user_id',$user_id |
|
|
|
|
|
)->pluck('system_coupon_user_id'); |
|
|
|
|
|
|
|
|
$ids = array_merge($c_ids->toArray(), $cr_ids->toArray()); |
|
|
$ids = array_merge($c_ids->toArray(), $cr_ids->toArray()); |
|
|
|
|
|
|
|
|
$ids = collect($ids)->unique(); |
|
|
$ids = collect($ids)->unique(); |
|
|
|
|
|
|
|
|
$c = Coupon::where('start_time','<=',$nowTime) |
|
|
|
|
|
->where('end_time','>',$nowTime) |
|
|
|
|
|
->whereRaw('inventory_use < inventory') |
|
|
|
|
|
->whereIn('id',$ids) |
|
|
|
|
|
->orderBy('weigh','desc') |
|
|
|
|
|
|
|
|
$c = Db::table('ims_system_coupon_user as u') |
|
|
|
|
|
->where([ |
|
|
|
|
|
['u.end_time','>',$nowTime], |
|
|
|
|
|
['u.start_time','<=',$nowTime], |
|
|
|
|
|
['type.receive_type','=',$receive_type], |
|
|
|
|
|
['u.status','=',1], |
|
|
|
|
|
]) |
|
|
|
|
|
->join('ims_system_coupon_user_receivetype as type', 'u.id', '=', 'type.system_coupon_user_id') |
|
|
|
|
|
->whereRaw('inventory_use <= inventory') |
|
|
|
|
|
->whereIn('u.id',$ids) |
|
|
|
|
|
->select('u.*','type.one_receive_number') |
|
|
|
|
|
->orderBy('u.weigh','desc') |
|
|
->limit(4) |
|
|
->limit(4) |
|
|
->get(); |
|
|
->get(); |
|
|
return $this->success(['not_reveive'=>$c]); |
|
|
return $this->success(['not_reveive'=>$c]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//统计用户
|
|
|
public function userCouponAccount() |
|
|
public function userCouponAccount() |
|
|
{ |
|
|
{ |
|
|
$user_id = $this->request->input('user_id'); |
|
|
$user_id = $this->request->input('user_id'); |
|
|
$nowTime = time(); |
|
|
$nowTime = time(); |
|
|
|
|
|
|
|
|
$userCouponCount = DB::table('ims_system_coupon_user_receive') |
|
|
$userCouponCount = DB::table('ims_system_coupon_user_receive') |
|
|
->leftJoin('ims_system_coupon_user', 'ims_system_coupon_user_receive.system_coupon_user_id', '=', 'ims_system_coupon_user.id') |
|
|
|
|
|
->count(); |
|
|
|
|
|
// $userCouponCount = CouponRec::with('coupon')->where('user_id',$user_id)->where('usable_start_time','<=',$nowTime)
|
|
|
|
|
|
// ->where('usable_end_time','>',$nowTime)->count();
|
|
|
|
|
|
return $this->success(['total'=>$userCouponCount]); |
|
|
|
|
|
|
|
|
->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]); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 用户领取优惠卷 |
|
|
|
|
|
*/ |
|
|
public function userReceiveCoupon() |
|
|
public function userReceiveCoupon() |
|
|
{ |
|
|
{ |
|
|
$userId = $this->request->input("user_id"); |
|
|
$userId = $this->request->input("user_id"); |
|
|
|