feat : coupon
This commit is contained in:
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use App\Constants\Common\CouponCode;
|
||||
use Hyperf\Collection\Collection;
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
|
||||
/**
|
||||
@@ -55,6 +57,15 @@ class CouponDispenseLog extends Model
|
||||
return $this->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
* @return array
|
||||
*/
|
||||
public function getListByIds(array $ids): array
|
||||
{
|
||||
return $this->whereIn('id',$ids)->get()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $receiveCount
|
||||
@@ -64,6 +75,30 @@ class CouponDispenseLog extends Model
|
||||
{
|
||||
return $this->where('id', $id)->increment('receive_count' , $receiveCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getNoReceiveCount(): array
|
||||
{
|
||||
$all = $this
|
||||
->where('claim_rule',CouponCode::DISPENSE_CLAIM_RULE_HOME_POPUPS)
|
||||
->whereColumn('total_count','!=','receive_count')
|
||||
->where('appoint_group',CouponCode::DISPENSE_APPOINT_GROUP_ALL_PEOPLE)
|
||||
->pluck('id')
|
||||
->toArray();
|
||||
|
||||
$appoint = $this
|
||||
->where('claim_rule',CouponCode::DISPENSE_CLAIM_RULE_HOME_POPUPS)
|
||||
->where('appoint_group','!=',CouponCode::DISPENSE_APPOINT_GROUP_ALL_PEOPLE)
|
||||
->pluck('id')
|
||||
->toArray();
|
||||
|
||||
return [
|
||||
'all' => $all,
|
||||
'appoint' => $appoint
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -72,4 +72,17 @@ class CouponDispenseUser extends Model
|
||||
'is_receive' => CouponCode::DISPENSE_STATUS_IS_RECEIVED
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $userIds
|
||||
* @return array
|
||||
*/
|
||||
public function getNoReceiveCountByUserIds(array $userIds): array
|
||||
{
|
||||
return $this
|
||||
->whereIn('user_id', $userIds)
|
||||
->where('receive_count',CouponCode::DISPENSE_STATUS_IS_NO_RECEIVED)
|
||||
->pluck('coupon_dispense_id')
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,4 +39,13 @@ class UserCoupon extends Model
|
||||
|
||||
const string CREATED_AT = 'created_time';
|
||||
const string UPDATED_AT = 'updated_time';
|
||||
|
||||
public function getReceiveCountByUserIds(int $user_id,array $couponIdArr): array
|
||||
{
|
||||
return $this
|
||||
->where('user_id', $user_id)
|
||||
->whereIn('coupon_id', $couponIdArr)
|
||||
->pluck('coupon_id')
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user