From bbb78240f2043ca71df4bb8287cae49185d673d8 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Fri, 20 Oct 2023 18:03:44 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=EF=BC=9A=E6=9D=83=E9=87=8D?= =?UTF-8?q?=E5=80=BC=E8=BD=AC=E8=B5=A0=20-=20=E7=94=B1=E7=BB=8F=E9=94=80?= =?UTF-8?q?=E5=95=86=E7=9B=B4=E6=8E=A5=E5=8F=AF=E4=BB=A5=E8=B5=A0=E9=80=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=BA=E5=8F=AA=E8=83=BD=E5=90=8C=E7=AD=89?= =?UTF-8?q?=E7=BA=A7=E6=88=96=E8=80=85=E6=88=90=E4=B8=BA=E8=BF=87=E8=AF=A5?= =?UTF-8?q?=E7=AD=89=E7=BA=A7=E7=9A=84=E7=BB=8F=E9=94=80=E5=95=86=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E4=BA=92=E7=9B=B8=E8=B5=A0=E9=80=81=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=AF=86=E7=A0=81=E6=94=AF=E6=8C=81=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=89=8B=E7=BB=AD=E8=B4=B9=E6=94=AF=E6=8C=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/WeightValueController.php | 110 ---- .../src/admin/IndexController.php | 30 + .../weight-value/src/api/IndexController.php | 136 +++++ .../weight-value/src/models/WeightValue.php | 1 + .../src/models/WeightValueLog.php | 39 +- .../src/models/WeightValueTransfer.php | 19 + .../weight-value/views/index/set.blade.php | 530 ++---------------- 7 files changed, 260 insertions(+), 605 deletions(-) delete mode 100644 app/frontend/modules/finance/controllers/WeightValueController.php create mode 100644 plugins/weight-value/src/models/WeightValueTransfer.php diff --git a/app/frontend/modules/finance/controllers/WeightValueController.php b/app/frontend/modules/finance/controllers/WeightValueController.php deleted file mode 100644 index a9b9fd0f..00000000 --- a/app/frontend/modules/finance/controllers/WeightValueController.php +++ /dev/null @@ -1,110 +0,0 @@ -getMemberId(); - $data = [ - 'weight_value' => sprintf("%.2f",Member::where('uid', $uid)->value('weight_value')), - 'list' => WeightValueLog::uniacid()->where('member_id',$uid)->limit(10)->get(['type','change_type','change_quantity','change_after','remark','created_at']), - ]; - - return $this->successJson('成功', $data); - } - /** - * Common: 获取用户权重值信息 - * Author: wu-hui - * Time: 2023/09/27 16:31 - * @return \Illuminate\Http\JsonResponse - */ - public function memberWeightValue(){ - if ($memberInfo = Member::where('uid', \YunShop::app()->getMemberId())->first()) { - $data['weight_value'] = $memberInfo->weight_value; - $data['has_password'] = $memberInfo->yzMember->hasPayPassword(); - $data['need_password'] = false;//(new PasswordService())->isNeed('balance', 'transfer'); - - return $this->successJson('获取数据成功', $data); - } - return $this->errorJson('未获取到会员数据'); - } - /** - * Common: 权重值转账 - * Author: wu-hui - * Time: 2023/09/27 17:17 - * @return \Illuminate\Http\JsonResponse - */ - public function transfer(){ - // 参数获取 - $uid = \YunShop::app()->getMemberId(); - $transferId = (int)request()->input('transfer_id'); - $transferMoney = abs((float)request()->input('transfer_money')); - if($transferId <= 0 || $transferMoney <= 0) return $this->errorJson('无受让人或者转赠数量为0!'); - // 判断:双方必须都是经销商 - $currentMemberIs = (int)TeamDividendAgencyModel::uniacid()->where('uid',$uid)->value('id'); - $transferMemberIs = (int)TeamDividendAgencyModel::uniacid()->where('uid',$transferId)->value('id'); - if($currentMemberIs <= 0 || $transferMemberIs <= 0) return $this->errorJson('身份非法,双方都必须为经纪人才能进行当前操作!'); - DB::beginTransaction(); - try{ - // 获取用户信息 - $currentMemberName = Member::uniacid()->where('uid',$uid)->value('nickname'); - $transferMemberName = Member::uniacid()->where('uid',$transferId)->value('nickname'); - // 减少当前用户持有权重值 - (new WeightValueLog())->weightValueOperate($uid,$transferMoney,0,"赠送给【{$transferMemberName}】"); - // 增加受让人持有权重值 - (new WeightValueLog())->weightValueOperate($transferId,$transferMoney,1,"来自【{$currentMemberName}】的赠送"); - - DB::commit(); - - return $this->successJson('操作成功'); - }catch(\Exception $e){ - DB::rollBack(); - return $this->errorJson($e->getMessage()); - } - } - /** - * Common: 获取权重值变更记录列表 - * Author: wu-hui - * Time: 2023/09/27 17:40 - * @return \Illuminate\Http\JsonResponse - */ - public function record(){ - //参数获取 - $pageSize = request()->input('page_size',10); - $search = request()->input('search'); - $search['member_id'] = \YunShop::app()->getMemberId(); - // 列表获取 - $field = ['id','member_id','type','change_type','change_quantity','change_front','change_after','remark','created_at']; - $result = WeightValueLog::getList($pageSize,$search,$field); - $data = [ - 'current_page' => $result['current_page'], - 'last_page' => $result['last_page'], - 'list' => $result['data'], - 'income' => WeightValueLog::getChangeTypeSum($search['member_id'],1), - 'expenditure' => WeightValueLog::getChangeTypeSum($search['member_id'],0), - ]; - - - return $this->successJson('成功', $data); - } - - - -} diff --git a/plugins/weight-value/src/admin/IndexController.php b/plugins/weight-value/src/admin/IndexController.php index 735e10e1..2696931b 100644 --- a/plugins/weight-value/src/admin/IndexController.php +++ b/plugins/weight-value/src/admin/IndexController.php @@ -6,6 +6,8 @@ use app\common\helpers\PaginationHelper; use Yunshop\TeamDividend\models\TeamDividendLevelModel; use Yunshop\WeightValue\models\WeightValue; use Yunshop\WeightValue\models\WeightValueLog; +use app\common\facades\Setting; +use app\common\helpers\Url; class IndexController extends BaseController{ @@ -75,6 +77,34 @@ class IndexController extends BaseController{ 'is_get' => $isGet, ])->render(); } + /** + * Common: 设置信息编辑 + * Author: wu-hui + * Time: 2023/10/20 14:33 + * @return array|mixed|string|void + * @throws \Throwable + */ + public function set(){ + // 获取设置信息 判断是否为设置 + $setInfo = request()->input('weight_value'); + if ($setInfo) { + // 信息校验 + if((int)$setInfo['is_open_commission'] == 1 && ((float)$setInfo['commission'] <= 0 || (float)$setInfo['commission'] > 100)){ + return $this->message('手续费比例填写错误','','error'); + } + // 设置信息 + if (Setting::set('plugin.weight_value', $setInfo)) return $this->message('设置成功', Url::absoluteWeb('plugin.weight-value.admin.index.set')); + else $this->message('设置失败','','error'); + }else{ + // 获取信息 + $set = Setting::get('plugin.weight_value'); + + return view('Yunshop\WeightValue::index.set',[ + 'set' => $set, + ])->render(); + } + } + diff --git a/plugins/weight-value/src/api/IndexController.php b/plugins/weight-value/src/api/IndexController.php index 25d839e8..58bdce21 100644 --- a/plugins/weight-value/src/api/IndexController.php +++ b/plugins/weight-value/src/api/IndexController.php @@ -3,12 +3,17 @@ namespace Yunshop\WeightValue\Api; use app\common\components\ApiController; +use app\common\facades\Setting; use app\common\models\Income; use app\common\models\Member; use app\common\models\member\MemberChildren; +use app\common\services\password\PasswordService; +use Illuminate\Support\Facades\DB; +use Yunshop\TeamDividend\models\TeamDividendAgencyModel; use Yunshop\TeamDividend\models\TeamDividendLevelModel; use Yunshop\WeightValue\models\WeightValue; use Yunshop\WeightValue\models\WeightValueLog; +use Yunshop\WeightValue\models\WeightValueTransfer; class IndexController extends ApiController{ /** @@ -91,6 +96,137 @@ class IndexController extends ApiController{ 'last_page' => (int)$result['last_page'], ]); } + /** + * Common: 获取我的权重值信息 + * Author: wu-hui + * Time: 2023/10/20 13:42 + * @return \Illuminate\Http\JsonResponse + */ + public function myWeightValue(){ + // 基本参数 + $uid = \YunShop::app()->getMemberId(); + $teamLevelId = (int)request()->input('team_level_id');// 经销商等级id + // 信息获取 + $weightValue = WeightValue::getWeightValueQuantity((int)$uid,(int)$teamLevelId); + $logList = WeightValueLog::uniacid() + ->where('member_id',$uid) + ->when($teamLevelId > 0,function($query) use ($teamLevelId){ + $query->where('team_dividend_agency_level_id',$teamLevelId); + }) + ->with([ + 'level' => function($query){ + $query->select(['id','level_name']); + }, + ]) + ->orderBy('created_at','DESC') + ->limit(10) + ->get(['team_dividend_agency_level_id','change_type','change_quantity','change_after','remark','created_at']) + ->toArray(); + $levelName = '我的'; + if($teamLevelId > 0) $levelName = TeamDividendLevelModel::uniacid()->where('id',$teamLevelId)->value('level_name'); + + return $this->successJson('成功',[ + 'weight_value' => $weightValue, + 'level_name' => $levelName . '权重值', + 'list' => $logList + ]); + } + /** + * Common: 获取用户权重值转赠相关信息 + * Author: wu-hui + * Time: 2023/10/20 16:51 + * @return \Illuminate\Http\JsonResponse + */ + public function transferInfo(){ + // 基本参数 + $uid = \YunShop::app()->getMemberId(); + $teamLevelId = (int)request()->input('team_level_id');// 经销商等级id + if($teamLevelId <= 0) return $this->errorJson('非法请求,等级不明确!'); + $levelName = TeamDividendLevelModel::uniacid()->where('id',$teamLevelId)->value('level_name'); + // 信息处理 + if ($memberInfo = Member::where('uid', $uid)->first()) { + $set = Setting::get('plugin.weight_value'); + // 信息获取 + $data = [ + 'weight_value' => WeightValue::getWeightValueQuantity((int)$uid,(int)$teamLevelId), + 'has_password' => $memberInfo->yzMember->hasPayPassword(), + 'need_password' => (int)$set['is_password'], + 'is_open_commission' => (int)$set['is_open_commission'], + 'commission' => (float)$set['commission'], + 'level_name' => $levelName, + ]; + + return $this->successJson('获取数据成功', $data); + } + + return $this->errorJson('未获取到会员数据'); + } + /** + * Common: 权重值转账 + * Author: wu-hui + * Time: 2023/10/20 18:01 + * @return \Illuminate\Http\JsonResponse + */ + public function transfer(){ + // 参数获取 + $uid = \YunShop::app()->getMemberId(); + $teamLevelId = (int)request()->input('team_level_id');// 经销商等级id + $transferId = (int)request()->input('transfer_id'); + $transferMoney = abs((float)request()->input('transfer_money')); + $password = request()->input('password'); + if($transferId <= 0 || $transferMoney <= 0) return $this->errorJson('无受让人或者转赠数量为0!'); + if($teamLevelId <= 0) return $this->errorJson('非法请求,等级不明确!'); + $levelName = TeamDividendLevelModel::uniacid()->where('id',$teamLevelId)->value('level_name'); + $set = Setting::get('plugin.weight_value'); + // 开始处理 + DB::beginTransaction(); + try{ + // 判断:受让人不能是本人 + if($uid == $transferId) throw new \Exception("身份非法,受让人不能是自己!"); + // 判断:密码是否正确 + if((int)$set['is_password'] == 1) (new PasswordService())->checkPayPassword($uid, $password); + // 判断:双方必须存在当前等级的权重值信息 + $currentMember = WeightValue::uniacid()->where('member_id',$uid)->where('team_dividend_agency_level_id',$teamLevelId)->first();// 当前用户 + $transferMember = WeightValue::uniacid()->where('member_id',$transferId)->where('team_dividend_agency_level_id',$teamLevelId)->first();// 受让人 + if((int)$currentMember->id <= 0 || (int)$transferMember->id <= 0) throw new \Exception("身份非法,双方都必须为${$levelName}才能进行当前操作!"); + // 计算手续费和减少金额 + $reduceMoney = $transferMoney;// 减少数量 默认为转赠数量 + $commission = (int)0;// 默认手续费 + if((int)$set['is_open_commission'] == 1 && (float)$set['commission'] > 0){ + $commission = (float)sprintf("%.2f", $transferMoney * (float)$set['commission'] / 100);// 手续费 + $reduceMoney = (float)sprintf("%.2f",$transferMoney + $commission);// 添加手续费后的减少数量 + } + // 获取用户信息 + $currentMemberName = Member::uniacid()->where('uid',$uid)->value('nickname'); + $transferMemberName = Member::uniacid()->where('uid',$transferId)->value('nickname'); + // 减少当前用户持有权重值 + (new WeightValueLog())->transferHandle((int)$uid,(float)$reduceMoney,0,"赠送给【{$transferMemberName}】", (int)$teamLevelId); + // 增加受让人持有权重值 + (new WeightValueLog())->transferHandle((int)$transferId,(float)$transferMoney,1,"来自【{$currentMemberName}】的赠送",(int)$teamLevelId); + // 记录转赠信息 + WeightValueTransfer::insert([ + 'uniacid' => \YunShop::app()->uniacid, + 'team_dividend_agency_level_id' => $teamLevelId, + 'member_id' => $uid, + 'transfer_member_id' => $transferId, + 'transfer_num' => $transferMoney, + 'receipt_num' => $transferMoney, + 'service_charge' => $commission, + 'remark' => "【{$currentMemberName}】赠送给【{$transferMemberName}】", + 'created_at' => time(), + ]); + + DB::commit(); + + return $this->successJson('操作成功'); + }catch(\Exception $e){ + DB::rollBack(); + return $this->errorJson($e->getMessage()); + } + } + + + diff --git a/plugins/weight-value/src/models/WeightValue.php b/plugins/weight-value/src/models/WeightValue.php index febb939e..0c63e1c5 100644 --- a/plugins/weight-value/src/models/WeightValue.php +++ b/plugins/weight-value/src/models/WeightValue.php @@ -401,6 +401,7 @@ class WeightValue extends BaseModel{ } + /** * Common: 统计信息 - 全部统计信息获取及处理 * Author: wu-hui diff --git a/plugins/weight-value/src/models/WeightValueLog.php b/plugins/weight-value/src/models/WeightValueLog.php index 2f5b63fc..b91ef5d4 100644 --- a/plugins/weight-value/src/models/WeightValueLog.php +++ b/plugins/weight-value/src/models/WeightValueLog.php @@ -61,7 +61,44 @@ class WeightValueLog extends BaseModel{ return $list ? $list->toArray() : []; } - + /** + * Common: 转赠后权重值变更处理 + * Author: wu-hui + * Time: 2023/10/20 17:59 + * @param int $uid + * @param float $money + * @param int $changeType + * @param string $remark + * @param int $teamLevelId + */ + public function transferHandle(int $uid,float $money,int $changeType,string $remark,int $teamLevelId){ + // 获取当前用户持有数量 + $changeFront = (float)WeightValue::getWeightValueQuantity((int)$uid,(int)$teamLevelId); + // 变更后的数量 + $changeAfter = $changeType == 1 ? $changeFront + $money : $changeFront - $money; + // 变更记录 + $data = [ + 'uniacid' => \YunShop::app()->uniacid, + 'member_id' => $uid,// 用户id + 'team_dividend_agency_level_id' => $teamLevelId,// 经销商等级id + 'goods_id' => 0,// 商品id + 'order_id' => 0,// 订单id + 'order_goods_id' => 0,// 订单商品id + 'change_type' => $changeType,// 变更类型:0=减少,1=增加 + 'change_quantity' => $money,// 变更数量 + 'change_front' => (float)$changeFront,// 变更前拥有的数量 + 'change_after' => sprintf("%.2f",$changeAfter),// 变更后拥有的数量 + 'remark' => $remark,// 备注 + 'created_at' => time(),// 变更时间 + 'source' => 2,// 变更时间 + ]; + $this->insert($data); + // 修改用户持有 + WeightValue::uniacid() + ->where('member_id',$uid) + ->where('team_dividend_agency_level_id',$teamLevelId) + ->update(['quantity' => $changeAfter]); + } /** * Common: 一对一关联 用户信息 diff --git a/plugins/weight-value/src/models/WeightValueTransfer.php b/plugins/weight-value/src/models/WeightValueTransfer.php new file mode 100644 index 00000000..979a3a15 --- /dev/null +++ b/plugins/weight-value/src/models/WeightValueTransfer.php @@ -0,0 +1,19 @@ + - .commission{ - width: 1100px; - } - .commission .commission-box{ - width: 100%; - display: inline-flex; - flex-direction: row; - flex-wrap: nowrap; - align-items: center; - justify-content: flex-start; - border-bottom: 1px solid #CCCCCC; - padding: 20px 0; - } - .commission .commission-box:first-child{ - padding: 0!important; - } - .commission .commission-box:last-child{ - border-bottom: none!important; - } - .commission .commission-box .level-title{ - width: 220px; - text-align: center; - font-size: 15px; - border-right: 1px solid #ccc; - height: 130px; - line-height: 130px; - } - .commission .commission-box:first-child .level-title{ - font-weight: bold; - height: 35px; - line-height: 35px; - border-right: none!important; - } - .commission .commission-box .commission-line-content{ - width: 880px; - } - .commission .commission-box .commission-line{ - width: 880px; - display: inline-flex; - flex-direction: row; - flex-wrap: nowrap; - align-items: center; - justify-content: flex-start; - margin-bottom: 15px; - } - .commission .commission-box .commission-line:last-child{ - margin-bottom: 0!important; - } - .commission .commission-box:first-child .commission-line{ - font-weight: bold; - height: 35px; - line-height: 35px; - margin-bottom: 0px!important; - } - .commission .commission-box .commission-line .line-cells{ - width: 220px; - text-align: center; - } - .hide{ - display: none; - } - .el-pagination{ - margin-top: 20px; - text-align: right!important; - } - +
- {{--设置表单--}}
- {{--设置内容--}} - - -
-
- -
- - -
-
-
-
- -
-
- -
- - -
-
-
- -
- - 值必须为0.01-100;为空则无平级奖。 -
-
-
- -
- -
-
-
- -
-
-
-
经销商等级
-
-
商品规格
-
首次返佣
-
每期返佣
-
分期数量
-
-
- @foreach($level as $levelItem => $levelValue) -
- {{--经销商等级--}} -
{{$levelValue['level_name']}}
- {{--规格及佣金设置--}} -
- @foreach($goods_label as $goodsLabelItem => $goodsLabelValue) -
-
{{$goodsLabelValue}}
-
- -
-
- -
-
- -
-
- @endforeach -
-
- @endforeach -
-
-
-
-
- - {{--计算金额--}} -
- -
-
-
-
G10
- -
-
G15
- -
-
G20
- -
-
-
-
-
- {{--默认比例--}} -
- -
-
-
-
- -
%
-
- -
%
-
- -
%
-
-
-
-
- {{--独立比例--}} -
- -
- {{--添加按钮--}} -
- 添加地区 -
- {{--独立规则列表--}} - - - - - - - - - - -
-
-
-
+
+ +
+ + +
+
+
+ +
+ + 值必须为0.01-100;手续费为实际转增数量的百分比; +
+
+
+ +
+ + + 转赠是否需要密码 +
+
{{--提交按钮--}}
@@ -272,249 +46,17 @@
- {{--地区选择器--}} - - - - - - - - - - - - - - - - - - - - - - -
@endsection