优化数据
This commit is contained in:
@@ -145,7 +145,7 @@ class User extends Authenticatable
|
||||
* @param string $date
|
||||
* @return int
|
||||
*/
|
||||
public function getCouponCount($type, $date = ''): int
|
||||
public function getCouponCount($type, $date = false)
|
||||
{
|
||||
$data = $this->checkCouponCount($date);
|
||||
|
||||
@@ -169,16 +169,17 @@ class User extends Authenticatable
|
||||
*/
|
||||
public function checkCouponCount($date)
|
||||
{
|
||||
$date = $date ? 'today' : 'all';
|
||||
|
||||
$name = "user_{$this->id}_coupon_count_date_{$date}";
|
||||
|
||||
if (Cache::has($name)) {
|
||||
return Cache::get($name, []);
|
||||
} else {
|
||||
$res = DB::table('coupons')
|
||||
->where('user_id', $this->id)
|
||||
$res = $this->coupons()
|
||||
->whereIn('status', [2])
|
||||
->when($date, function ($q) {
|
||||
$q->whereDate('created_at', now()->format('Y-m-d'));
|
||||
->when($date == 'today', function ($q) {
|
||||
$q->whereDate('created_at', '2020-11-11');
|
||||
})
|
||||
->select('thirdPartyGoodsId', DB::raw('count(*) as total'))
|
||||
->groupBy('thirdPartyGoodsId')
|
||||
|
||||
Reference in New Issue
Block a user