105 lines
2.8 KiB
PHP
105 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Model;
|
|
|
|
use App\Constants\Common\CouponCode;
|
|
use Hyperf\Collection\Collection;
|
|
use Hyperf\DbConnection\Model\Model;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property string $title
|
|
* @property string $coupon_name
|
|
* @property int $coupon_template_id
|
|
* @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 string $appoint_value
|
|
* @property string $use_scene_ids
|
|
* @property int $validity_time_type
|
|
* @property string $validity_time_value
|
|
* @property int $status
|
|
* @property string $remark
|
|
* @property string $create_time
|
|
* @property string $update_time
|
|
*/
|
|
class CouponDispenseLog extends Model
|
|
{
|
|
/**
|
|
* The table associated with the model.
|
|
*/
|
|
protected ?string $table = 'coupon_dispense_log';
|
|
|
|
/**
|
|
* 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','status' => '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 array $ids
|
|
* @return array
|
|
*/
|
|
public function getListByIds(array $ids): array
|
|
{
|
|
return $this->whereIn('id',$ids)->get()->toArray();
|
|
}
|
|
|
|
/**
|
|
* @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);
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function getNoReceiveCount(): array
|
|
{
|
|
return $this
|
|
->where('claim_rule',CouponCode::DISPENSE_CLAIM_RULE_HOME_POPUPS)
|
|
->whereColumn('total_count','!=','receive_count')
|
|
->where('appoint_group',CouponCode::DISPENSE_APPOINT_GROUP_ALL_PEOPLE)
|
|
->where('status',CouponCode::DISPENSE_VALIDITY)
|
|
->pluck('id')
|
|
->toArray();
|
|
}
|
|
|
|
/**
|
|
* @param array $ids
|
|
* @return Collection
|
|
*/
|
|
public function getInfoByIds(array $ids)
|
|
{
|
|
return $this->whereIn('id',$ids)->get();
|
|
}
|
|
}
|
|
|
|
|