用户接口

main
fengxinyhyl 8 months ago
parent 7d7720d63d
commit ec9b5c08e2
  1. 8
      app/common/repositories/user/UserAssetsLogRepository.php
  2. 92
      app/common/repositories/user/UserAssetsRepository.php
  3. 9
      app/common/repositories/user/UserGroupRepository.php
  4. 2
      app/controller/admin/user/UserGroup.php
  5. 102
      app/controller/api/Auth.php
  6. 84
      app/controller/api/user/User.php
  7. 7
      app/validate/admin/UserGroupValidate.php
  8. 28
      route/api.php
  9. 2
      view/admin/package.json
  10. 35
      view/admin/src/views/user/group/index.vue
  11. 2
      view/mer/package.json

@ -144,10 +144,10 @@ class UserAssetsLogRepository extends BaseRepository
$order = $orderRepository->getDetail($orderItem['order_id']); $order = $orderRepository->getDetail($orderItem['order_id']);
// 爆单奖励 // 爆单奖励
// $this->hotAward($order); $this->hotAward($order);
//
// // 分享奖励 // 分享奖励
// $this->shareAward($order); $this->shareAward($order);
$this->serveAward($order); $this->serveAward($order);
} }

@ -39,7 +39,13 @@ class UserAssetsRepository extends BaseRepository
* @var GroupDataRepository $groupDataRepository * @var GroupDataRepository $groupDataRepository
*/ */
$groupDataRepository = app()->make(GroupDataRepository::class); $groupDataRepository = app()->make(GroupDataRepository::class);
$config = $groupDataRepository->getGroupDataLst(0, 100, 1, 100); $config = $groupDataRepository->getGroupDataLst(0, 104, 1, 100);
/**
* integralToDiamond 积分兑钻石
* diamondToStock 钻石兑本票
* withdrawRate 提现手续费
* transferRate 转让手续费
*/
return array_column($config['list'], "value", 'key'); return array_column($config['list'], "value", 'key');
} }
@ -118,11 +124,11 @@ class UserAssetsRepository extends BaseRepository
* @author zhangkxiang * @author zhangkxiang
* @editor * @editor
*/ */
public function consumeToShare($uid, $count) public function integralToDiamond($uid, $count)
{ {
$config = $this->getConfig(); $config = $this->getConfig();
$assets = $this->assets($uid); $assets = $this->assets($uid);
if ($assets['consume'] < $config['consume_to_share'] * $count) { if ($assets['consume'] < $config['integralToDiamond'] * $count) {
throw new \Exception('消费积分不足'); throw new \Exception('消费积分不足');
} }
$logList = array(); $logList = array();
@ -145,6 +151,46 @@ class UserAssetsRepository extends BaseRepository
$this->dao->update($uid, array('consume' => $assets['consume'] + $consume, 'share_point' => $assets['share_point'] + $count, 'share_point_time' => time())); $this->dao->update($uid, array('consume' => $assets['consume'] + $consume, 'share_point' => $assets['share_point'] + $count, 'share_point_time' => time()));
} }
/**
* notes
* @param $uid
* @param $count
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @create 2024/3/19 22:33
* @update 2024/3/19 22:33
* @author zhangkxiang
* @editor
*/
public function diamondToStock($uid, $count)
{
$config = $this->getConfig();
$assets = $this->assets($uid);
if ($assets['diamond'] < $config['diamondToStock'] * $count) {
throw new \Exception('钻石不足');
}
$logList = array();
$diamond = -1 * $config['diamondToStock'] * $count;
$logList[] = array(
'uid' => $uid,
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_DIAMOND,
'type' => UserAssetsLogRepository::CHANGE_TYPE_STOCK,
'status' => UserAssetsLogRepository::STATUS_USE,
'count' => $diamond,
);
$stock = $count;
$logList[] = array(
'uid' => $uid,
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_STOCK,
'type' => UserAssetsLogRepository::CHANGE_TYPE_STOCK,
'status' => UserAssetsLogRepository::STATUS_GET,
'count' => $stock,
);
app()->make(UserAssetsLogRepository::class)->addLog($logList);
$this->dao->update($uid, array('diamond' => $assets['diamond'] + $diamond, 'stock' => $assets['stock'] + $stock));
}
/** /**
* notes 惠通宝转账 * notes 惠通宝转账
@ -205,45 +251,7 @@ class UserAssetsRepository extends BaseRepository
} }
/**
* notes
* @param $uid
* @param $count
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @create 2024/3/19 22:33
* @update 2024/3/19 22:33
* @author zhangkxiang
* @editor
*/
public function huitongToConsume($uid, $count)
{
$current = app(HuitongRepository::class)->getCurrent();
$assets = $this->assets($uid);
if ($assets['huitong'] < $count) {
throw new \Exception('惠通宝不足');
}
$logList = array();
$consume = $current * $count;
$logList[] = array(
'uid' => $uid,
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_CONSUME,
'type' => UserAssetsLogRepository::CHANGE_TYPE_HUITONG,
'status' => UserAssetsLogRepository::STATUS_SUCCESS,
'count' => $consume,
);
$huitong = -1 * $count;
$logList[] = array(
'uid' => $uid,
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_HUITONG,
'type' => UserAssetsLogRepository::CHANGE_TYPE_HUITONG,
'status' => UserAssetsLogRepository::STATUS_SUCCESS,
'count' => $huitong,
);
app()->make(UserAssetsLogRepository::class)->addLog($logList);
$this->dao->update($uid, array('consume' => $assets['consume'] + $consume, 'huitong' => $assets['huitong'] + $huitong));
}
public function getSum($field) public function getSum($field)

@ -79,8 +79,13 @@ class UserGroupRepository extends BaseRepository
$isCreate = is_null($id); $isCreate = is_null($id);
$action = Route::buildUrl($isCreate ? 'systemUserGroupCreate' : 'systemUserGroupUpdate', $isCreate ? [] : compact('id'))->build(); $action = Route::buildUrl($isCreate ? 'systemUserGroupCreate' : 'systemUserGroupUpdate', $isCreate ? [] : compact('id'))->build();
return Elm::createForm($action, [ return Elm::createForm($action, [
Elm::input('group_name', '用户分组名称:')->placeholder('请输入用户分组名称')->required() Elm::input('group_name', '等级名称:')->placeholder('请输入等级名称')->required(),
])->setTitle($isCreate ? '添加用户分组' : '编辑用户分组')->formData($formData); Elm::number('order_count', '订单量:')->placeholder('请输入订单量')->min(0)->required(),
Elm::number('order_sum', '营业额:')->placeholder('请输入营业额')->min(0)->required(),
Elm::number('diamond', '赠送钻石数/天:')->placeholder('请输入赠送钻石数')->min(0)->required(),
Elm::number('diamond_max', '赠送最大钻石数:')->placeholder('请输入赠送最大钻石数')->min(0)->required(),
Elm::number('rate', '业绩分红比例:')->placeholder('请输入业绩分红比例')->max(100)->min(0)->required(),
])->setTitle($isCreate ? '添加用户分组' : '编辑等级配置')->formData($formData);
} }
/** /**

@ -145,7 +145,7 @@ class UserGroup extends BaseController
*/ */
protected function checkParams(UserGroupValidate $validate) protected function checkParams(UserGroupValidate $validate)
{ {
$data = $this->request->params(['group_name']); $data = $this->request->params(['group_name','order_count', 'order_sum', 'diamond', 'diamond_max', 'rate']);
$validate->check($data); $validate->check($data);
return $data; return $data;
} }

@ -17,8 +17,12 @@ namespace app\controller\api;
use app\common\repositories\store\order\StoreGroupOrderRepository; use app\common\repositories\store\order\StoreGroupOrderRepository;
use app\common\repositories\store\order\StoreOrderRepository; use app\common\repositories\store\order\StoreOrderRepository;
use app\common\repositories\store\order\StoreRefundOrderRepository; use app\common\repositories\store\order\StoreRefundOrderRepository;
use app\common\repositories\system\HuitongRepository;
use app\common\repositories\system\notice\SystemNoticeConfigRepository; use app\common\repositories\system\notice\SystemNoticeConfigRepository;
use app\common\repositories\system\notice\SystemNoticeRepository;
use app\common\repositories\user\UserAssetsLogRepository; use app\common\repositories\user\UserAssetsLogRepository;
use app\common\repositories\user\UserAssetsRepository;
use app\common\repositories\user\UserGroupRepository;
use app\common\repositories\user\UserOrderRepository; use app\common\repositories\user\UserOrderRepository;
use app\common\repositories\user\UserRechargeRepository; use app\common\repositories\user\UserRechargeRepository;
use app\common\repositories\user\UserRepository; use app\common\repositories\user\UserRepository;
@ -173,9 +177,107 @@ class Auth extends BaseController
Cache::set($key, true, new \DateTime($day . ' 23:59:59')); Cache::set($key, true, new \DateTime($day . ' 23:59:59'));
} }
} }
$groupRepository = app(UserGroupRepository::class);
$groupData = $groupRepository->getList([], 1, 10);
$groupList = array_column($groupData['list']->toArray(), 'group_name', 'group_id');
$data['group_name'] = $groupList[$data['group_id']] ?? '';
// 用户资产
$assets = app(UserAssetsRepository::class)->assets($data['uid']);
$data['assets'] = $assets;
return app('json')->success($data);
}
public function noticeList()
{
[$page, $limit] = $this->getPage();
$where = array('type' => 5);
return app('json')->success(app(SystemNoticeRepository::class)->getList($where, $page, $limit));
}
/**
* notes 兑换配置
* @return mixed
* @create 2024/3/19 22:20
* @update 2024/3/19 22:20
* @author zhangkxiang
* @editor
*/
public function exchangeConfig(){
$config = app(UserAssetsRepository::class)->getConfig();
$data = [
'integralToDiamond' => $config['integralToDiamond'],
'diamondToStock' => $config['diamondToStock']
];
return app('json')->success($data); return app('json')->success($data);
} }
public function assetsLog(){
$uid = 3;
// $uid = 3;
$page = $this->request->param('page', 1);
$limit = $this->request->param('limit', 10);
$asset_type = $this->request->param('asset_type', 1);
$change_type = $this->request->param('change_type');
$where = array();
$where[] = array('asset_type','=',$asset_type);
if($change_type) $where[] = array('type','=',$change_type);
$where[] = array('status','in',[UserAssetsLogRepository::STATUS_GET, UserAssetsLogRepository::STATUS_WITHDRAW, UserAssetsLogRepository::STATUS_USE]);
return app('json')->success(app(UserAssetsLogRepository::class)->list($uid, $where, $page, $limit));
}
public function integralToDiamond(){
$count = $this->request->param('count', 1);
$uid = 3;
try {
app(UserAssetsRepository::class)->consumeToShare($uid, $count);
}catch (\Exception $e){
return app('json')->fail($e->getMessage());
}
return app('json')->success();
}
public function diamondToStock(){
$count = $this->request->param('count', 1);
$uid = 3;
try {
app(UserAssetsRepository::class)->consumeToShare($uid, $count);
}catch (\Exception $e){
return app('json')->fail($e->getMessage());
}
return app('json')->success();
}
public function toHuitong(){
$count = $this->request->param('count', 1);
$phone = $this->request->param('phoneTo', "13166665555");
$smsCode = $this->request->param('smsCode', 0156);
$type = $this->request->param('type', 'intention');
$uid = 3;
Log::info("code: {$smsCode}, type: {$type}");
$checkSms = app()->make(SmsService::class)->checkSmsCode('18362705640', $smsCode, $type);
if (!$smsCode || !$checkSms)
return app('json')->fail('验证码不正确');
try {
app(UserAssetsRepository::class)->sendHuitong($uid, $phone, $count);
}catch (\Exception $e){
return app('json')->fail($e->getMessage());
}
return app('json')->success();
}
/** /**
* @param UserRepository $repository * @param UserRepository $repository
* @return mixed * @return mixed

@ -18,6 +18,8 @@ use app\common\repositories\store\IntegralRepository;
use app\common\repositories\store\service\StoreServiceRepository; use app\common\repositories\store\service\StoreServiceRepository;
use app\common\repositories\system\CacheRepository; use app\common\repositories\system\CacheRepository;
use app\common\repositories\user\MemberinterestsRepository; use app\common\repositories\user\MemberinterestsRepository;
use app\common\repositories\user\UserAssetsLogRepository;
use app\common\repositories\user\UserAssetsRepository;
use app\common\repositories\user\UserBillRepository; use app\common\repositories\user\UserBillRepository;
use app\common\repositories\user\UserBrokerageRepository; use app\common\repositories\user\UserBrokerageRepository;
use app\common\repositories\user\UserRepository; use app\common\repositories\user\UserRepository;
@ -30,6 +32,7 @@ use think\App;
use think\db\exception\DataNotFoundException; use think\db\exception\DataNotFoundException;
use think\db\exception\DbException; use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException; use think\db\exception\ModelNotFoundException;
use think\facade\Log;
class User extends BaseController class User extends BaseController
{ {
@ -43,6 +46,87 @@ class User extends BaseController
$this->user = $this->request->userInfo(); $this->user = $this->request->userInfo();
} }
public function assetsLog(){
$user = $this->request->userInfo();
$uid = $user->uid;
// $uid = 3;
$page = $this->request->param('page', 1);
$limit = $this->request->param('limit', 10);
$asset_type = $this->request->param('asset_type', 1);
$change_type = $this->request->param('change_type');
$where = array();
$where[] = array('asset_type','=',$asset_type);
if($change_type) $where[] = array('type','=',$change_type);
$where[] = array('status','in',[UserAssetsLogRepository::STATUS_FROZEN, UserAssetsLogRepository::STATUS_SUCCESS, UserAssetsLogRepository::STATUS_USED, UserAssetsLogRepository::STATUS_REFUND]);
return app('json')->success(app(UserAssetsLogRepository::class)->list($uid, $where, $page, $limit));
}
/**
* notes 消费积分兑分红点
* @return mixed
* @create 2024/3/19 22:39
* @update 2024/3/19 22:39
* @author zhangkxiang
* @editor
*/
public function consumeToShare(){
$count = $this->request->param('count', 1);
$uid = $this->user->uid;
try {
app(UserAssetsRepository::class)->consumeToShare($uid, $count);
}catch (\Exception $e){
return app('json')->fail($e->getMessage());
}
return app('json')->success();
}
/**
* notes 赠送惠通宝
* @return mixed
* @create 2024/3/20 11:00
* @update 2024/3/20 11:00
* @author zhangkxiang
* @editor
*/
public function sendHuitong(){
$count = $this->request->param('count', 1);
$phone = $this->request->param('phoneTo');
$smsCode = $this->request->param('smsCode');
$type = $this->request->param('type', 'intention');
$uid = $this->user->uid;
Log::info("code: {$smsCode}, type: {$type}");
$checkSms = app()->make(SmsService::class)->checkSmsCode($this->user->phone, $smsCode, $type);
if (!$smsCode || !$checkSms)
return app('json')->fail('验证码不正确');
try {
app(UserAssetsRepository::class)->sendHuitong($uid, $phone, $count);
}catch (\Exception $e){
return app('json')->fail($e->getMessage());
}
return app('json')->success();
}
public function huitongToConsume(){
$count = $this->request->param('count', 1);
$uid = $this->user->uid;
try {
app(UserAssetsRepository::class)->huitongToConsume($uid, $count);
}catch (\Exception $e){
return app('json')->fail($e->getMessage());
}
return app('json')->success();
}
/** /**
* @return mixed * @return mixed
* @author xaboy * @author xaboy

@ -21,6 +21,11 @@ class UserGroupValidate extends Validate
protected $failException = true; protected $failException = true;
protected $rule = [ protected $rule = [
'group_name|分组名称' => 'require|max:32' 'group_name|分组名称' => 'require|max:32',
'order_count|分组名称' => 'require',
'order_sum|分组名称' => 'require',
'diamond|分组名称' => 'require',
'diamond_max|分组名称' => 'require',
'rate|分组名称' => 'require',
]; ];
} }

@ -21,6 +21,24 @@ use think\facade\Route;
Route::group('api/', function () { Route::group('api/', function () {
Route::any('test', 'api.Auth/test'); Route::any('test', 'api.Auth/test');
//兑换配置
Route::get('exchange/config', 'api.Auth/exchangeConfig');
Route::get('notice/list', 'api.Auth/noticeList');
//用户资产明细
Route::get('assets/log', 'api.Auth/assetsLog');
//积分兑换钻石
Route::post('exchange/diamond', 'api.Auth/consumeToShare');
//钻石兑本票
Route::post('exchange/stock', 'api.Auth/huitongToConsume');
//赠送积分
Route::post('send/integral', 'api.Auth/sendIntegral');
Route::post('send/diamond', 'api.Auth/sendDiamond');
//强制登录 //强制登录
Route::group(function () { Route::group(function () {
Route::group('v2', function () { Route::group('v2', function () {
@ -105,6 +123,16 @@ Route::group('api/', function () {
Route::post('user/cancel', 'api.Auth/cancel'); Route::post('user/cancel', 'api.Auth/cancel');
//用户 //用户
Route::group('user', function () { Route::group('user', function () {
//用户资产明细
Route::get('assetsLog', 'User/assetsLog');
//积分兑换钻石
Route::post('exchange/diamond', 'User/consumeToShare');
//赠送积分
Route::post('send/integral', 'User/sendIntegral');
Route::post('send/diamond', 'User/sendDiamond');
//钻石兑本票
Route::post('exchange/stock', 'User/huitongToConsume');
//切换账号 //切换账号
Route::get('account', 'User/account'); Route::get('account', 'User/account');
Route::post('switch', 'User/switchUser'); Route::post('switch', 'User/switchUser');

@ -5,7 +5,7 @@
"author": "Pan <panfree23@gmail.com>", "author": "Pan <panfree23@gmail.com>",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"dev": "vue-cli-service serve", "dev": "vue-cli-service serve --open --inline --hot",
"build:prod": "vue-cli-service build", "build:prod": "vue-cli-service build",
"build:stage": "vue-cli-service build --mode staging", "build:stage": "vue-cli-service build --mode staging",
"preview": "node build/index.js --preview", "preview": "node build/index.js --preview",

@ -1,9 +1,9 @@
<template> <template>
<div class="divBox"> <div class="divBox">
<el-card> <el-card>
<div class="mb20"> <!-- <div class="mb20">-->
<el-button size="small" type="primary" @click="onAdd">{{ $route.path.indexOf('group') !== -1?'添加用户分组':'添加用户标签' }}</el-button> <!-- <el-button size="small" type="primary" @click="onAdd">{{ $route.path.indexOf('group') !== -1?'添加用户分组':'添加用户标签' }}</el-button>-->
</div> <!-- </div>-->
<el-table <el-table
v-loading="listLoading" v-loading="listLoading"
:data="tableData.data" :data="tableData.data"
@ -26,6 +26,31 @@
<span v-text="$route.path.indexOf('group') !== -1?row.group_name:row.label_name" /> <span v-text="$route.path.indexOf('group') !== -1?row.group_name:row.label_name" />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column
prop="order_count"
label="总订单量"
min-width="150"
/>
<el-table-column
prop="order_sum"
label="总消费金额"
min-width="150"
/>
<el-table-column
prop="diamond"
label="每天赠送钻石数量"
min-width="150"
/>
<el-table-column
prop="diamond_max"
label="当前等级最大钻石数量"
min-width="150"
/>
<el-table-column
prop="rate"
label="业绩分红比例"
min-width="150"
/>
<el-table-column <el-table-column
prop="create_time" prop="create_time"
label="创建时间" label="创建时间"
@ -34,7 +59,7 @@
<el-table-column label="操作" min-width="90" fixed="right"> <el-table-column label="操作" min-width="90" fixed="right">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button type="text" size="small" @click="onEdit($route.path.indexOf('group') !== -1?scope.row.group_id:scope.row.label_id)">编辑</el-button> <el-button type="text" size="small" @click="onEdit($route.path.indexOf('group') !== -1?scope.row.group_id:scope.row.label_id)">编辑</el-button>
<el-button type="text" size="small" @click="handleDelete($route.path.indexOf('group') !== -1?scope.row.group_id:scope.row.label_id, scope.$index)">删除</el-button> <!-- <el-button type="text" size="small" @click="handleDelete($route.path.indexOf('group') !== -1?scope.row.group_id:scope.row.label_id, scope.$index)">删除</el-button>-->
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@ -92,7 +117,7 @@ export default {
this.getList() this.getList()
}, },
watch:{ watch:{
'$route.path': { '$route.path': {
handler: function() { handler: function() {
this.getList() this.getList()
}, },

@ -5,7 +5,7 @@
"author": "Pan <panfree23@gmail.com>", "author": "Pan <panfree23@gmail.com>",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"dev": "vue-cli-service serve", "dev": "vue-cli-service serve --open --inline --hot",
"build:prod": "vue-cli-service build", "build:prod": "vue-cli-service build",
"build:stage": "vue-cli-service build --mode staging", "build:stage": "vue-cli-service build --mode staging",
"preview": "node build/index.js --preview", "preview": "node build/index.js --preview",

Loading…
Cancel
Save