From ec9b5c08e2f13727aa05fbd7d69ee1ccf8667f27 Mon Sep 17 00:00:00 2001 From: fengxinyhyl Date: Thu, 11 Apr 2024 20:40:46 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/UserAssetsLogRepository.php | 8 +- .../user/UserAssetsRepository.php | 92 ++++++++-------- .../repositories/user/UserGroupRepository.php | 9 +- app/controller/admin/user/UserGroup.php | 2 +- app/controller/api/Auth.php | 102 ++++++++++++++++++ app/controller/api/user/User.php | 84 +++++++++++++++ app/validate/admin/UserGroupValidate.php | 7 +- route/api.php | 28 +++++ view/admin/package.json | 2 +- view/admin/src/views/user/group/index.vue | 35 +++++- view/mer/package.json | 2 +- 11 files changed, 314 insertions(+), 57 deletions(-) diff --git a/app/common/repositories/user/UserAssetsLogRepository.php b/app/common/repositories/user/UserAssetsLogRepository.php index 7b30563..11d40a8 100644 --- a/app/common/repositories/user/UserAssetsLogRepository.php +++ b/app/common/repositories/user/UserAssetsLogRepository.php @@ -144,10 +144,10 @@ class UserAssetsLogRepository extends BaseRepository $order = $orderRepository->getDetail($orderItem['order_id']); // 爆单奖励 -// $this->hotAward($order); -// -// // 分享奖励 -// $this->shareAward($order); + $this->hotAward($order); + + // 分享奖励 + $this->shareAward($order); $this->serveAward($order); } diff --git a/app/common/repositories/user/UserAssetsRepository.php b/app/common/repositories/user/UserAssetsRepository.php index 7cdce17..0ed130a 100644 --- a/app/common/repositories/user/UserAssetsRepository.php +++ b/app/common/repositories/user/UserAssetsRepository.php @@ -39,7 +39,13 @@ class UserAssetsRepository extends BaseRepository * @var GroupDataRepository $groupDataRepository */ $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'); } @@ -118,11 +124,11 @@ class UserAssetsRepository extends BaseRepository * @author zhangkxiang * @editor */ - public function consumeToShare($uid, $count) + public function integralToDiamond($uid, $count) { $config = $this->getConfig(); $assets = $this->assets($uid); - if ($assets['consume'] < $config['consume_to_share'] * $count) { + if ($assets['consume'] < $config['integralToDiamond'] * $count) { throw new \Exception('消费积分不足'); } $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())); } + /** + * 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 惠通宝转账 @@ -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) diff --git a/app/common/repositories/user/UserGroupRepository.php b/app/common/repositories/user/UserGroupRepository.php index d0879a5..fe422a8 100755 --- a/app/common/repositories/user/UserGroupRepository.php +++ b/app/common/repositories/user/UserGroupRepository.php @@ -79,8 +79,13 @@ class UserGroupRepository extends BaseRepository $isCreate = is_null($id); $action = Route::buildUrl($isCreate ? 'systemUserGroupCreate' : 'systemUserGroupUpdate', $isCreate ? [] : compact('id'))->build(); return Elm::createForm($action, [ - Elm::input('group_name', '用户分组名称:')->placeholder('请输入用户分组名称')->required() - ])->setTitle($isCreate ? '添加用户分组' : '编辑用户分组')->formData($formData); + Elm::input('group_name', '等级名称:')->placeholder('请输入等级名称')->required(), + 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); } /** diff --git a/app/controller/admin/user/UserGroup.php b/app/controller/admin/user/UserGroup.php index 62ec117..81f5935 100755 --- a/app/controller/admin/user/UserGroup.php +++ b/app/controller/admin/user/UserGroup.php @@ -145,7 +145,7 @@ class UserGroup extends BaseController */ 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); return $data; } diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index 83c3ce6..ccaa8b9 100755 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -17,8 +17,12 @@ namespace app\controller\api; use app\common\repositories\store\order\StoreGroupOrderRepository; use app\common\repositories\store\order\StoreOrderRepository; 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\SystemNoticeRepository; 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\UserRechargeRepository; use app\common\repositories\user\UserRepository; @@ -173,9 +177,107 @@ class Auth extends BaseController 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); } + + 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 * @return mixed diff --git a/app/controller/api/user/User.php b/app/controller/api/user/User.php index 5d103a9..59e8615 100755 --- a/app/controller/api/user/User.php +++ b/app/controller/api/user/User.php @@ -18,6 +18,8 @@ use app\common\repositories\store\IntegralRepository; use app\common\repositories\store\service\StoreServiceRepository; use app\common\repositories\system\CacheRepository; 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\UserBrokerageRepository; use app\common\repositories\user\UserRepository; @@ -30,6 +32,7 @@ use think\App; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; +use think\facade\Log; class User extends BaseController { @@ -43,6 +46,87 @@ class User extends BaseController $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 * @author xaboy diff --git a/app/validate/admin/UserGroupValidate.php b/app/validate/admin/UserGroupValidate.php index 13ce4bc..a203e03 100755 --- a/app/validate/admin/UserGroupValidate.php +++ b/app/validate/admin/UserGroupValidate.php @@ -21,6 +21,11 @@ class UserGroupValidate extends Validate protected $failException = true; 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', ]; } diff --git a/route/api.php b/route/api.php index 0676954..7344bc9 100755 --- a/route/api.php +++ b/route/api.php @@ -21,6 +21,24 @@ use think\facade\Route; Route::group('api/', function () { 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('v2', function () { @@ -105,6 +123,16 @@ Route::group('api/', function () { Route::post('user/cancel', 'api.Auth/cancel'); //用户 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::post('switch', 'User/switchUser'); diff --git a/view/admin/package.json b/view/admin/package.json index ef93fef..e9ed5ae 100644 --- a/view/admin/package.json +++ b/view/admin/package.json @@ -5,7 +5,7 @@ "author": "Pan ", "license": "MIT", "scripts": { - "dev": "vue-cli-service serve", + "dev": "vue-cli-service serve --open --inline --hot", "build:prod": "vue-cli-service build", "build:stage": "vue-cli-service build --mode staging", "preview": "node build/index.js --preview", diff --git a/view/admin/src/views/user/group/index.vue b/view/admin/src/views/user/group/index.vue index c036ee8..c87e182 100644 --- a/view/admin/src/views/user/group/index.vue +++ b/view/admin/src/views/user/group/index.vue @@ -1,9 +1,9 @@ + + + + + @@ -92,7 +117,7 @@ export default { this.getList() }, watch:{ - '$route.path': { + '$route.path': { handler: function() { this.getList() }, diff --git a/view/mer/package.json b/view/mer/package.json index f7da6b1..aa865c1 100644 --- a/view/mer/package.json +++ b/view/mer/package.json @@ -5,7 +5,7 @@ "author": "Pan ", "license": "MIT", "scripts": { - "dev": "vue-cli-service serve", + "dev": "vue-cli-service serve --open --inline --hot", "build:prod": "vue-cli-service build", "build:stage": "vue-cli-service build --mode staging", "preview": "node build/index.js --preview",