feat : auto coupon
This commit is contained in:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use App\Constants\Common\CouponCode;
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
|
||||
/**
|
||||
@@ -66,6 +67,9 @@ class CouponDispenseUser extends Model
|
||||
{
|
||||
return $this
|
||||
->whereIn('user_id', $userIds)
|
||||
->increment('receive_count', $count);
|
||||
->update([
|
||||
'receive_count' => $count,
|
||||
'is_receive' => CouponCode::DISPENSE_STATUS_IS_RECEIVED
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,4 +46,26 @@ class CouponTemplate extends Model
|
||||
{
|
||||
return $this->find($id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取所有数据
|
||||
* @param array $ids
|
||||
* @return array
|
||||
*/
|
||||
public function getDataByIds(array $ids): array
|
||||
{
|
||||
$data = $this->whereIn('id',$ids)->get();
|
||||
if (empty($data)){
|
||||
return [];
|
||||
}
|
||||
|
||||
$res = [];
|
||||
foreach ($data->toArray() as $one)
|
||||
{
|
||||
$res[$one['id']] = $one;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user