From 9925ef19189cff64431af9e4d4889caa00af23c4 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Fri, 10 Nov 2023 16:12:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E7=A7=AF=E5=88=86?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3(?= =?UTF-8?q?=E5=95=86=E6=88=B7=E7=A7=AF=E5=88=86=E5=88=97=E8=A1=A8=E3=80=81?= =?UTF-8?q?=E7=A7=AF=E5=88=86=E8=BD=AC=E6=8D=A2=E6=8E=A5=E5=8F=A3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/user/Integral.php | 5 ++ .../repositories/user/IntegralRepository.php | 26 +++++- .../repositories/user/UserBillRepository.php | 2 + app/controller/api/user/User.php | 86 ++++++++++++++++++- route/api.php | 3 + 5 files changed, 118 insertions(+), 4 deletions(-) diff --git a/app/common/model/user/Integral.php b/app/common/model/user/Integral.php index e43f815..c327f18 100644 --- a/app/common/model/user/Integral.php +++ b/app/common/model/user/Integral.php @@ -15,6 +15,7 @@ namespace app\common\model\user; use app\common\model\BaseModel; +use app\common\model\system\merchant\Merchant; class Integral extends BaseModel { @@ -44,4 +45,8 @@ class Integral extends BaseModel return $this->hasOne(User::class, 'uid', 'uid'); } + public function mer(){ + return $this->hasOne(Merchant::class,'mer_id','mer_id'); + } + } diff --git a/app/common/repositories/user/IntegralRepository.php b/app/common/repositories/user/IntegralRepository.php index 6830770..2219887 100644 --- a/app/common/repositories/user/IntegralRepository.php +++ b/app/common/repositories/user/IntegralRepository.php @@ -108,10 +108,30 @@ class IntegralRepository extends BaseRepository return compact('integral','convert_integral','convert_rate'); } + /** + * Common: 获取商户积分列表 + * Author: wu-hui + * Time: 2023/11/10 14:20 + * @param int $uid + * @param int $page + * @param int $limit + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getMerIntegralList(int $uid,int $page,int $limit):array{ + $query = $this->dao->getSearch(['uid'=>$uid]) + ->where('mer_id','>',0) + ->with(['mer'=>function($query){ + $query->field('mer_id,mer_name,mer_avatar,mer_integral_platform_rate')->bind(['mer_name','mer_avatar','mer_integral_platform_rate']); + }]) + ->order('create_time DESC'); + $count = $query->count(); + $list = $query->page($page,$limit)->select(); - - - + return compact('count','list'); + } diff --git a/app/common/repositories/user/UserBillRepository.php b/app/common/repositories/user/UserBillRepository.php index 2eff727..6822afe 100644 --- a/app/common/repositories/user/UserBillRepository.php +++ b/app/common/repositories/user/UserBillRepository.php @@ -54,10 +54,12 @@ class UserBillRepository extends BaseRepository 'integral/sys_inc' => '系统增加积分', 'integral/timeout' => '积分过期', 'integral/mer_give' => '商户赠送', + 'integral/convert' => '积分转换', 'mer_integral/deduction' => '积分抵扣', 'mer_integral/refund' => '订单退款', 'mer_integral/lock' => '下单赠送积分', 'mer_integral/mer_give' => '商户赠送', + 'mer_integral/convert' => '积分转换', 'mer_lock_money/order' => '商户佣金冻结', 'now_money/brokerage' => '佣金转入余额', 'now_money/pay_product' => '购买商品', diff --git a/app/controller/api/user/User.php b/app/controller/api/user/User.php index 8940d46..6ee0253 100644 --- a/app/controller/api/user/User.php +++ b/app/controller/api/user/User.php @@ -17,6 +17,7 @@ namespace app\controller\api\user; use app\common\repositories\store\IntegralRepository; use app\common\repositories\store\service\StoreServiceRepository; use app\common\repositories\system\CacheRepository; +use app\common\repositories\user\IntegralGiveRecordRepository; use app\common\repositories\user\MemberinterestsRepository; use app\common\repositories\user\UserBillRepository; use app\common\repositories\user\UserBrokerageRepository; @@ -26,10 +27,12 @@ use app\validate\api\UserBaseInfoValidate; use crmeb\basic\BaseController; use crmeb\services\MiniProgramService; use crmeb\services\SmsService; +use Exception; use think\App; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; +use think\facade\Db; class User extends BaseController { @@ -426,8 +429,10 @@ class User extends BaseController } $nextClearDay = date('m月d日', $nextClearDay); $clear = compact('nextClearDay', 'status', 'nextClearIntegral'); + // 获取用户平台积分 + $platform_integral = app()->make(\app\common\repositories\user\IntegralRepository::class)->getMerIntegral((int)$this->user->uid,(int)0); - return app('json')->success(compact('integral', 'lockIntegral', 'deductionIntegral', 'totalGainIntegral', 'clear')); + return app('json')->success(compact('integral', 'lockIntegral', 'deductionIntegral', 'totalGainIntegral', 'clear','platform_integral')); } public function integralList(UserBillRepository $repository) @@ -440,6 +445,85 @@ class User extends BaseController return app('json')->success($data); } + /** + * Common: 获取用户商户积分列表 + * Author: wu-hui + * Time: 2023/11/10 14:21 + * @return mixed + */ + public function merIntegralList(){ + [$page, $limit] = $this->getPage(); + $data = app()->make(\app\common\repositories\user\IntegralRepository::class)->getMerIntegralList((int)$this->user->uid,(int)$page,(int)$limit); + + return app('json')->success($data); + } + /** + * Common: 积分转换 + * Author: wu-hui + * Time: 2023/11/10 15:37 + * @param $merId + * @return mixed + */ + public function merIntegralConvert($merId){ + $params = $this->request->params(['convert_integral']); + $convertIntegral = (float)abs($params['convert_integral']); + if($convertIntegral <= 0) return app('json')->fail('转换数量不能小于0!'); + // 转换操作 + try { + Db::transaction(function () use ($merId, $convertIntegral) { + $mer_integral_platform_rate = (float)merchantConfig($merId,'mer_integral_platform_rate'); + if($mer_integral_platform_rate <= 0) throw new Exception('转换失败,商户未设置转换比例!'); + $uid = $this->request->uid(); + $user = app()->make(UserRepository::class)->get($uid); + $integralMake = app()->make(\app\common\repositories\user\IntegralRepository::class); + $bills = []; + // 计算转换后的积分 应得平台积分 + $convertAfterIntegral = (float)sprintf("%.2f",$convertIntegral * $mer_integral_platform_rate); + // 减少商户积分 + $integralMake->changeIntegral((int)$uid,(int)$merId,(float)sprintf('%.2f',0 - $convertIntegral)); + $user->integral = bcsub($user->integral,$convertIntegral,2); + $bills[] = [ + 'uid' => $uid, + 'link_id' => $merId, + 'pm' => 0, + 'title' => '积分转换', + 'category' => 'mer_integral', + 'type' => 'convert', + 'number' => $convertIntegral, + 'balance' => $user->integral, + 'mark' => "将({$convertIntegral})本商户积分转换为平台积分,获得{$convertAfterIntegral}平台积分", + 'mer_id' => $merId, + 'status' => 1 + ]; + // 增加平台积分 + $integralMake->changeIntegral((int)$uid,(int)0,(float)sprintf('%.2f', $convertAfterIntegral)); + $user->integral = bcadd($user->integral,$convertAfterIntegral,2); + $bills[] = [ + 'uid' => $uid, + 'link_id' => $merId, + 'pm' => 0, + 'title' => '积分转换', + 'category' => 'integral', + 'type' => 'convert', + 'number' => $convertAfterIntegral, + 'balance' => $user->integral, + 'mark' => "将({$convertIntegral})商户积分转换为平台积分,获得{$convertAfterIntegral}平台积分", + 'mer_id' => 0, + 'status' => 1 + ]; + // 修改总积分 + $user->save(); + // 添加记录 + app()->make(UserBillRepository::class)->insertAll($bills); + }); + + return app('json')->success('操作成功'); + } catch (\Throwable $e) { + return app('json')->fail($e->getMessage()); + } + } + + public function services() { $uid = $this->user->uid; diff --git a/route/api.php b/route/api.php index 979b13e..3d75e8d 100644 --- a/route/api.php +++ b/route/api.php @@ -202,6 +202,9 @@ Route::group('api/', function () { //积分 Route::get('integral/info', 'User/integralInfo'); Route::get('integral/lst', 'User/integralList'); + Route::post('integral/mer_list', 'User/merIntegralList'); + Route::post('integral/integral_convert/:merId', 'User/merIntegralConvert'); + //客服列表 Route::get('services', 'User/services');