53 lines
1.3 KiB
PHP
53 lines
1.3 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace app\common\dao\store;
|
||
|
|
||
|
use app\common\dao\BaseDao;
|
||
|
use app\common\model\store\StoreActivityUser;
|
||
|
|
||
|
class StoreActivityUserDao extends BaseDao
|
||
|
{
|
||
|
|
||
|
protected function getModel(): string
|
||
|
{
|
||
|
return StoreActivityUser::class;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 选择消费金类型
|
||
|
* @param int $userId
|
||
|
* @param int $couponId
|
||
|
* @param int $activityId
|
||
|
* @return void
|
||
|
* @throws \Exception
|
||
|
*/
|
||
|
public function choose(int $userId, int $couponId, int $activityId)
|
||
|
{
|
||
|
$exist = StoreActivityUser::where('user_id', $userId)->where('activity_id', $activityId)->find();
|
||
|
if (!empty($exist)) {
|
||
|
throw new \Exception('请勿重复提交');
|
||
|
}
|
||
|
$model = new StoreActivityUser();
|
||
|
$model->user_id = $userId;
|
||
|
$model->value = $couponId;
|
||
|
$model->activity_id = $activityId;
|
||
|
$model->create_time = time();
|
||
|
if (!$model->save()) {
|
||
|
throw new \Exception('请勿重复提交');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 获取用户选择的消费金类型
|
||
|
* @param int $userId
|
||
|
* @param int $activityId
|
||
|
* @return int
|
||
|
*/
|
||
|
public function getValue(int $userId, int $activityId = 1)
|
||
|
{
|
||
|
$data = StoreActivityUser::where('user_id', $userId)->where('activity_id', $activityId)->find();
|
||
|
return $data->value ?? 0;
|
||
|
}
|
||
|
|
||
|
}
|