89 lines
2.2 KiB
PHP
89 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Model;
|
|
|
|
use App\Constants\Common\CouponCode;
|
|
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)
|
|
->update([
|
|
'receive_count' => $count,
|
|
'is_receive' => CouponCode::DISPENSE_STATUS_IS_RECEIVED
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @param int $userId
|
|
* @return array
|
|
*/
|
|
public function getNoReceiveCountByUserId(int $userId): array
|
|
{
|
|
return $this
|
|
->where('user_id', $userId)
|
|
->where('receive_count',CouponCode::DISPENSE_STATUS_IS_NO_RECEIVED)
|
|
->pluck('coupon_dispense_id')
|
|
->toArray();
|
|
}
|
|
}
|