feat : auto coupon

This commit is contained in:
2025-02-26 18:01:02 +08:00
parent 14ca3b6377
commit c8db3e170d
10 changed files with 605 additions and 86 deletions

View File

@@ -11,16 +11,14 @@ use Hyperf\DbConnection\Model\Model;
* @property string $title
* @property string $coupon_name
* @property int $coupon_template_id
* @property int $send_count
* @property int $receive_count
* @property int $left_count
* @property int $total_count
* @property int $receive_count
* @property int $item_count
* @property int $appoint_group
* @property int $claim_rule
* @property string $claim_value
* @property int $appoint_city_id
* @property string $claim_value
* @property string $appoint_value
* @property string $use_scen_ids
* @property string $use_scene_ids
* @property int $validity_time_type
* @property string $validity_time_value
* @property string $remark
@@ -38,9 +36,34 @@ class CouponDispenseLog extends Model
* 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_template_id' => 'integer', 'send_count' => 'integer', 'receive_count' => 'integer', 'left_count' => 'integer', 'item_count' => 'integer', 'appoint_group' => 'integer', 'claim_rule' => 'integer', 'appoint_city_id' => 'integer', 'validity_time_type' => 'integer'];
const string CREATED_AT = 'create_time';
const string UPDATED_AT = 'update_time';
/**
* @param int $id
* @return CouponDispenseLog|CouponDispenseLog[]|\Hyperf\Database\Model\Model|null
*/
public function getInfoById(int $id): \Hyperf\Database\Model\Model|CouponDispenseLog|array|null
{
return $this->find($id);
}
/**
* @param int $id
* @param int $receiveCount
* @return int
*/
public function updateReceiveCountById(int $id,int $receiveCount): int
{
return $this->where('id', $id)->increment('receive_count' , $receiveCount);
}
}

View 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);
}
}

42
app/Model/UserCoupon.php Normal file
View File

@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace App\Model;
use Hyperf\DbConnection\Model\Model;
/**
* @property int $id
* @property int $coupon_template_id
* @property int $coupon_dispense_id
* @property int $user_id
* @property int $status
* @property string $coupon_name
* @property string $use_time
* @property string $validity_start_time
* @property string $validity_end_time
* @property string $create_time
* @property string $update_time
*/
class UserCoupon extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'user_coupon';
/**
* 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_template_id' => 'integer', 'coupon_dispense_id' => 'integer', 'user_id' => 'integer', 'status' => 'integer'];
const string CREATED_AT = 'created_time';
const string UPDATED_AT = 'updated_time';
}