feat : auto coupon
This commit is contained in:
71
app/Model/CouponDispenseUser.php
Normal file
71
app/Model/CouponDispenseUser.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $coupon_dispense_id
|
||||
* @property int $user_id
|
||||
* @property int $total_count
|
||||
* @property int $receive_count
|
||||
* @property string $create_time
|
||||
* @property string $update_time
|
||||
*/
|
||||
class CouponDispenseUser extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'coupon_dispense_user';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = [];
|
||||
protected array $guarded = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*/
|
||||
protected array $casts = ['id' => 'integer', 'coupon_dispense_id' => 'integer', 'user_id' => 'integer', 'total_count' => 'integer', 'receive_count' => 'integer'];
|
||||
|
||||
const string CREATED_AT = 'create_time';
|
||||
const string UPDATED_AT = 'update_time';
|
||||
|
||||
/**
|
||||
* @param int $dispenseId
|
||||
* @return int
|
||||
*/
|
||||
public function getNoSendCountByDispenseId(int $dispenseId): int
|
||||
{
|
||||
return $this
|
||||
->where('dispense_id', $dispenseId)
|
||||
->where('receive_count',0)
|
||||
->count() ?? 0;
|
||||
}
|
||||
|
||||
public function getNoSendUserListByDispenseId(int $dispenseId): array
|
||||
{
|
||||
return $this
|
||||
->where('dispense_id', $dispenseId)
|
||||
->where('receive_count',0)
|
||||
->pluck('user_id')
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $userIds
|
||||
* @param int $count
|
||||
* @return int
|
||||
*/
|
||||
public function updateReceiveCountByUserIds(array $userIds,int $count): int
|
||||
{
|
||||
return $this
|
||||
->whereIn('user_id', $userIds)
|
||||
->increment('receive_count', $count);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user