8000 fix · laraveladmin-cn/laraveladmin@f94d3e4 · GitHub
[go: up one dir, main page]

Skip to content

Commit f94d3e4

Browse files
author
张世平
committed
fix
1 parent 18b2e9f commit f94d3e4

File tree

5 files changed

+127
-4
lines changed

5 files changed

+127
-4
lines changed

app/Http/Controllers/Traits/ResourceController.php

+7
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ public function create(\Illuminate\Http\Request $request)
520520
'message' => trans('Create a failure!') //创建失败
521521
], HttpResponse::HTTP_INTERNAL_SERVER_ERROR)], HttpResponse::HTTP_INTERNAL_SERVER_ERROR);
522522
}
523+
$this->saveRelationBefore($item,$data);
523524
$this->saveRelation($item, $data);
524525
$this->handlePostEdit($item, $data,[]);
525526
$primaryKey = $this->newBindModel()->getKeyName() ?: 'id';
@@ -567,6 +568,7 @@ public function update($id = 0)
567568
'message' => trans('Modify the failure!') //修改失败
568569
], HttpResponse::HTTP_INTERNAL_SERVER_ERROR)], HttpResponse::HTTP_INTERNAL_SERVER_ERROR);
569570
}
571+
$this->saveRelationBefore($item,$data);
570572
$this->saveRelation($item, $data);
571573
$this->handlePostEdit($item, $data,$old);
572574

@@ -735,6 +737,10 @@ protected function saveRelation($item, $data)
735737
}
736738
}
737739

740+
protected function saveRelationBefore($item,&$data){
741+
return $data;
742+
}
743+
738744

739745
/**
740746
* 获取字段默认值
@@ -1256,6 +1262,7 @@ public function import()
12561262
$old_data = [];
12571263
$item = $bindModel::create($row);
12581264
}
1265+
$this->saveRelationBefore($item, $row);
12591266
$this->saveRelation($item, $row);
12601267
$this->handlePostEdit($item, $row,$old_data);
12611268
}

app/Models/Menu.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,10 @@ public function scopeIsUrlInMenus($query,$url,$menus,$method='get',$is_bool=true
658658
$method = self::methodValue($method);
659659
$isIn = false;
660660
$menus = collect($menus)->filter(function($item) use (&$isIn,$url,$method,&$menu){
661-
return $item['url']===$url && in_array($method,$item['method']);
661+
return $item['url']===$url && ( //url地址相等
662+
in_array($method,$item['method']) || //请求方式包含
663+
(!$method && !$item['method']) //仅权限标记
664+
);
662665
//return strpos($item['url'],$url)===0 && in_array($method,$item['method']);
663666
});
664667
$menu = collect($menus)->first(function ($item)use($url){

app/Validators/CustomValidator.php

+94
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,100 @@ public function validateDomain($attribute, $value,$parameters){
221221
return preg_match('/^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\.)+[A-Za-z]{2,6}$/', $value) > 0;
222222
}
223223

224+
/**
225+
* 银行卡验证
226+
* 16-19 位卡号校验位采用 Luhm 校验方法计算:
227+
* 1,将未带校验位的 15 位卡号从右依次编号 1 到 15,位于奇数位号上的数字乘以 2
228+
* 2,将奇位乘积的个十位全部相加,再加上所有偶数位上的数字
229+
* 3,将加法和加上校验位能被 10 整除。
230+
* @param $s
231+
* @return bool
232+
*/
233+
public function validateBankCard($attribute, $value, $parameters)
234+
{
235+
if (!$value) return true;
236+
if(!preg_match("/^[0-9]{1,}$/", $value)){
237+
return false;
238+
}
239+
$n = 0;
240+
$ns = strrev($value); // 倒序
241+
for ($i = 0; $i < strlen($value); $i++) {
242+
if ($i % 2 == 0) {
243+
$n += $ns[$i]; // 偶数位,包含校验码
244+
} else {
245+
$t = $ns[$i] * 2;
246+
if ($t >= 10) {
247+
$t = $t - 9;
248+
}
249+
$n += $t;
250+
}
251+
}
252+
$res = ($n % 10) == 0;
253+
$bank_code = Arr::get($parameters, 0, '');
254+
255+
if (!$bank_code || !$res) { //不验证所属银行代码
256+
return $res;
257+
}
258+
try {
259+
$url = 'https://ccdcapi.alipay.com/validateAndCacheCardInfo.json';
260+
$response = \App\Facades\Client::request('get', $url, [
261+
'query' => [
262+
'_input_charset' => 'utf-8',
263+
'cardNo' => $value,
264+
'cardBinCheck' => 'true'
265+
]
266+
]);
267+
if ($response->getStatusCode() == 200) {
268+
$stringBody = $response->getBody()->getContents();
269+
$result = json_decode($stringBody, true);
270+
$res_bank_code = array_get($result, 'bank', '');
271+
if (array_get($result, 'stat') == 'ok' && $res_bank_code) {
272+
$res = array_get($result, 'validated') && //有效卡号
273+
$bank_code == $res_bank_code
274+
//&& //卡号所属银行
275+
//array_get($result, 'cardType') == 'DC' //DC-储蓄卡,CC-信用卡
276+
;
277+
}
278+
}
279+
} catch (\Exception $e) {
280+
}
281+
return $res;
282+
}
283+
284+
/**
285+
* 社会统一信用码验证
286+
* @param $code
287+
* @return bool
288+
*/
289+
public function validateUnifiedSocialCreditIdentifier($attribute, $code)
290+
{
291+
if (is_null($code) || $code==='') return true;
292+
if (!preg_match('~^[0-9ABCDEFGHJKLMNPQRTUWXY]{18}$~', $code)) {
293+
return false;
294+
}
295+
$code = strtoupper($code);
296+
// 18位统一社会信用代码不使用I、O、Z、S、V这五个英文字母
297+
$alphaMap = [
298+
'0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4,
299+
'5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9,
300+
'A' => 10, 'B' => 11, 'C' => 12, 'D' => 13, 'E' => 14,
301+
'F' => 15, 'G' => 16, 'H' => 17, 'J' => 18, 'K' => 19,
302+
'L' => 20, 'M' => 21, 'N' => 22, 'P' => 23, 'Q' => 24,
303+
'R' => 25, 'T' => 26, 'U' => 27, 'W' => 28, 'X' => 29,
304+
'Y' => 30,
305+
];
306+
$weight = [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28];
307+
$chrs = str_split($code);
308+
$sum = 0;
309+
foreach (array_slice($chrs, 0, 17) as $index => $chr) {
310+
$sum += $alphaMap[$chr] * $weight[$index];
311+
}
312+
$checkNum = 31 - ($sum % 31);
313+
$checkNum = $checkNum == 31 ? 0 : $checkNum;
314+
$flipAlphaMap = array_flip($alphaMap);
315+
return $chrs[17] === (string) $flipAlphaMap[$checkNum];
316+
}
317+
224318

225319

226320

resources/js/components/passwordEdit.vue

+21-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class="form-control"
1212
autocomplete="on"
1313
:placeholder="_placeholder">
14-
<div class="input-group-addon">
14+
<div class="input-group-addon" @mouseenter="show" @mouseleave="hide">
1515
<i class="fa fa-eye" v-show="type=='password'" @click="toggle"></i>
1616
<i class="fa fa-eye-slash" v-show="type!='password'" @click="toggle"></i>
1717
</div>
@@ -43,12 +43,18 @@
4343
default: function () {
4444
return false;
4545
}
46-
}
46+
},
47+
mouseenterShow:{
48+
default: function () {
49+
return false;
50+
}
51+
},
4752
},
4853
data(){
4954
return {
5055
password:this.value,
51-
type:'password'
56+
type:'password',
57+
init_click:false
5258
};
5359
},
5460
watch:{
@@ -63,7 +69,19 @@
6369
}
6470
},
6571
methods:{
72+
show(){
73+
if(this.mouseenterShow){
74+
this.init_click = false;
75+
179B this.type = 'text';
76+
}
77+
},
78+
hide(){
79+
if(this.mouseenterShow && !this.init_click){
80+
this.type = 'password';
81+
}
82+
},
6683
toggle(){
84+
this.init_click = true;
6785
this.type = this.type=='password'?'text':'password';
6886
},
6987
randomPass(len = 16, mode = "high"){

resources/lang/zh-CN/validation.php

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
'domain'=>':attribute 必须是有效域名。',
126126
'is_idcard'=>':attribute 必须是有效的身份证号码。',
127127
'geetest'=>':attribute 验证失败。',
128+
'bank_card'=>':attribute 输入不正确',
128129
/*
129130
|--------------------------------------------------------------------------
130131
| Custom Validation Language Lines

0 commit comments

Comments
 (0)
0