Skip to content

Commit bc7d67f

Browse files
committed
新增:增加关联表清理方法
1 parent b8edb49 commit bc7d67f

File tree

6 files changed

+40
-22
lines changed

6 files changed

+40
-22
lines changed

module/Member/Api/Controller/MemberVipController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function info()
3636

3737
public function all()
3838
{
39-
return Response::generateSuccessData(MemberVipUtil::all());
39+
return Response::generateSuccessData(MemberVipUtil::allVisible());
4040
}
4141

4242
public function buy()

module/Member/Util/MemberVipUtil.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ public static function allWithGuest()
2525
return $vips;
2626
}
2727

28+
public static function allVisible()
29+
{
30+
$vips = array_filter(self::all(), function ($vip) {
31+
return $vip['visible'];
32+
});
33+
$vips = array_values($vips);
34+
return $vips;
35+
}
36+
2837
public static function all()
2938
{
3039
return CacheUtil::rememberForever('MemberVipList', function () {

module/Member/View/pc/memberVip/index.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class="vip-button">
112112
<div class="vip-list-container">
113113
<div class="vip-list vip-bg tw-rounded">
114114
@foreach($memberVips as $memberVip)
115-
@if(!$memberVip['isDefault'] && $memberVip['visible'])
115+
@if(!$memberVip['isDefault'])
116116
<div class="item" data-vip-id="{{$memberVip['id']}}">
117117
<div class="tw-text-xl tw-font-bold tw-py-4">
118118
{{$memberVip['title']}}
@@ -212,7 +212,7 @@ class="vip-button">
212212
@endif
213213
<div class="tw-rounded vip-bg vip-content-list">
214214
@foreach($memberVips as $memberVip)
215-
@if(!$memberVip['isDefault'] && $memberVip['visible'])
215+
@if(!$memberVip['isDefault'])
216216
<div class="item tw-hidden">
217217
<div class="tw-p-4 tw-text-lg vip-text">{{$memberVip['title']}}</div>
218218
<div class="tw-pb-4 tw-px-4 ">

module/Member/View/pc/memberVip/indexDialog.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class="vip-button">
110110
<div class="vip-list-container" style="padding:0;">
111111
<div class="vip-list vip-bg tw-rounded" style="padding:5px;">
112112
@foreach($memberVips as $memberVip)
113-
@if(!$memberVip['isDefault'] && $memberVip['visible'])
113+
@if(!$memberVip['isDefault'])
114114
<div class="item" data-vip-id="{{$memberVip['id']}}" style="padding:5px;">
115115
<div class="tw-text-xl tw-font-bold tw-py-1">
116116
{{$memberVip['title']}}
@@ -212,7 +212,7 @@ class="vip-button">
212212
@endif
213213
<div class="tw-rounded vip-bg vip-content-list">
214214
@foreach($memberVips as $memberVip)
215-
@if(!$memberVip['isDefault'] && $memberVip['visible'])
215+
@if(!$memberVip['isDefault'])
216216
<div class="item tw-hidden">
217217
<div class="tw-p-4 tw-text-lg vip-text">{{$memberVip['title']}}</div>
218218
<div class="tw-pb-4 tw-px-4 ">

module/Member/Web/Controller/MemberVipController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function index()
2727
$this->shareDialogPageViewFrame();
2828
}
2929
return $this->view($view, [
30-
'memberVips' => MemberVipUtil::all(),
30+
'memberVips' => MemberVipUtil::allVisible(),
3131
'memberVipRights' => MemberVipUtil::rights(),
3232
]);
3333
}

vendor/modstart/modstart/src/Core/Dao/ModelUtil.php

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -427,16 +427,14 @@ public static function valueMap($model, $fieldKey, $fieldValue, $where = [])
427427
}
428428

429429
/**
430-
*
431430
* 关联表列出关联信息
432431
*
433-
* @param $model : 表名称
434-
* @param $sourceField : 外键列名
435-
* @param $sourceValue : 外键值
436-
* @param array $filter : 关联过滤条件
437-
* @param array $extraFields : 额外返回字段
438-
* @param string $idField : 关系表ID列名
439-
*
432+
* @param $model string 表名称
433+
* @param $sourceField string 外键列名
434+
* @param $sourceValue mixed 外键值
435+
* @param $filter array 关联过滤条件
436+
* @param $extraFields array 额外返回字段
437+
* @param $idField string 关系表ID列名
440438
* @return array
441439
*/
442440
public static function relationList($model, $sourceField, $sourceValue, $filter = [], $extraFields = [], $idField = 'id')
@@ -445,16 +443,27 @@ public static function relationList($model, $sourceField, $sourceValue, $filter
445443
}
446444

447445
/**
448-
*
446+
* 关联表清除
447+
* @param $model string 表名称
448+
* @param $field string 外键列名
449+
* @param $value mixed 外键值
450+
* @return int
451+
*/
452+
public static function relationClean($model, $field, $value)
453+
{
454+
return self::model($model)->where($field, $field)->delete();
455+
}
456+
457+
/**
449458
* 关系表关联操作
450459
*
451-
* @param $model : 表名称
452-
* @param $sourceField : 外键列名
453-
* @param $sourceValue : 外键值
454-
* @param $targetField : 关联列名
455-
* @param $targetValues : 关联列值
456-
* @param array $filter : 关联过滤条件
457-
* @param string $idField : 关系表ID列名
460+
* @param $model string 表名称
461+
* @param $sourceField string 外键列名
462+
* @param $sourceValue mixed 外键值
463+
* @param $targetField string 关联列名
464+
* @param $targetValues array 关联列值
465+
* @param $filter array 关联过滤条件
466+
* @param $idField string 关系表ID列名
458467
*
459468
* @example
460469
*

0 commit comments

Comments
 (0)