添加用户选择消费金类型
This commit is contained in:
parent
fb2f2c6a86
commit
5334f402c6
52
app/common/dao/store/StoreActivityUserDao.php
Normal file
52
app/common/dao/store/StoreActivityUserDao.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
}
|
36
app/common/dao/store/consumption/StoreConsumptionDao.php
Normal file
36
app/common/dao/store/consumption/StoreConsumptionDao.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\dao\store\consumption;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use \app\common\model\store\consumption\StoreConsumption;
|
||||
|
||||
class StoreConsumptionDao extends BaseDao
|
||||
{
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return StoreConsumption::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取有效的消费金列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getValidList()
|
||||
{
|
||||
return StoreConsumption::whereIn('type', [StoreConsumption::TYPE_OWNER_CONSUMPTION, StoreConsumption::TYPE_PULL_CONSUMPTION])->where('status', StoreConsumption::STATUS_ENABLE)->field('coupon_id,start_time,end_time,title')->select()->toArray();
|
||||
}
|
||||
|
||||
public function getOne($id)
|
||||
{
|
||||
return StoreConsumption::where('coupon_id', $id)->where('status', StoreConsumption::STATUS_ENABLE)->find();
|
||||
}
|
||||
|
||||
}
|
21
app/common/model/store/StoreActivityUser.php
Normal file
21
app/common/model/store/StoreActivityUser.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\store;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class StoreActivityUser extends BaseModel
|
||||
{
|
||||
|
||||
public static function tablePk(): string
|
||||
{
|
||||
return 'id';
|
||||
}
|
||||
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'store_activity_user';
|
||||
}
|
||||
|
||||
|
||||
}
|
28
app/common/model/store/consumption/StoreConsumption.php
Normal file
28
app/common/model/store/consumption/StoreConsumption.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\store\consumption;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class StoreConsumption extends BaseModel
|
||||
{
|
||||
|
||||
protected $json = ['config'];
|
||||
protected $jsonAssoc = true;
|
||||
|
||||
const STATUS_ENABLE = 1; //启用
|
||||
|
||||
const TYPE_OWNER_CONSUMPTION = 13; //个人消费金
|
||||
const TYPE_PULL_CONSUMPTION = 14; //拉新消费金
|
||||
|
||||
public static function tablePk(): string
|
||||
{
|
||||
return 'coupon_id';
|
||||
}
|
||||
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'store_consumption';
|
||||
}
|
||||
|
||||
}
|
41
app/controller/api/store/StoreActivity.php
Normal file
41
app/controller/api/store/StoreActivity.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\api\store;
|
||||
|
||||
use app\common\dao\store\consumption\StoreConsumptionDao;
|
||||
use app\common\dao\store\StoreActivityUserDao;
|
||||
use crmeb\basic\BaseController;
|
||||
|
||||
class StoreActivity extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 消费金列表
|
||||
* @param StoreConsumptionDao $dao
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function consumption(StoreConsumptionDao $dao)
|
||||
{
|
||||
$list = $dao->getValidList();
|
||||
return app('json')->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择消费金类型
|
||||
* @param StoreConsumptionDao $dao
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function choose(StoreActivityUserDao $dao)
|
||||
{
|
||||
$userId = $this->request->uid();
|
||||
$couponId = $this->request->post('coupon_id');
|
||||
$activityId = $this->request->post('activity_id', 1);
|
||||
$dao->choose($userId, $couponId, $activityId);
|
||||
return app('json')->success('提交成功');
|
||||
}
|
||||
|
||||
}
|
@ -457,6 +457,7 @@ Route::group('api/', function () {
|
||||
//价格列表
|
||||
Route::post('pay/:id', '/createOrder')->middleware(\app\common\middleware\BlockerMiddleware::class);
|
||||
})->prefix('api.user.Svip');
|
||||
Route::post('chooseConsumption', 'api.store.StoreActivity/choose'); //选择消费金类型
|
||||
})->middleware(UserTokenMiddleware::class, true);
|
||||
|
||||
//非强制登录
|
||||
@ -635,6 +636,7 @@ Route::group('api/', function () {
|
||||
Route::get('subscribe', 'api.Common/subscribe');
|
||||
Route::resource('store/product/cloudWarehouse', 'api.store.product.CloudWarehouse');
|
||||
Route::get('store/product/town_cloud', 'api.store.product.CloudWarehouse/town');
|
||||
Route::get('consumption', 'api.store.StoreActivity/consumption'); //消费金列表
|
||||
})->middleware(UserTokenMiddleware::class, false);
|
||||
|
||||
//微信支付回调
|
||||
|
Loading…
x
Reference in New Issue
Block a user