commit | author | age
|
2207d6
|
1 |
<?php |
W |
2 |
/** |
|
3 |
* @copyright ©2018 浙江禾匠信息科技 |
|
4 |
* @author Lu Wei |
|
5 |
* @link http://www.zjhejiang.com/ |
|
6 |
* Created by IntelliJ IDEA |
|
7 |
* Date Time: 2018/10/30 12:00 |
|
8 |
*/ |
|
9 |
|
|
10 |
|
|
11 |
namespace app\models; |
|
12 |
|
|
13 |
use app\core\response\ApiCode; |
|
14 |
use yii\data\Pagination; |
|
15 |
use yii\db\ActiveQuery; |
|
16 |
use yii\db\ActiveRecord; |
|
17 |
|
|
18 |
class Model extends \yii\base\Model |
|
19 |
{ |
|
20 |
protected $sign = ''; |
|
21 |
|
|
22 |
/** |
|
23 |
* ActiveRecord 数据验证,返回第一条错误验证 |
|
24 |
* @param array $model |
|
25 |
* @return array |
|
26 |
*/ |
|
27 |
public function getErrorResponse($model = []) |
|
28 |
{ |
|
29 |
if (!$model) { |
|
30 |
$model = $this; |
|
31 |
} |
|
32 |
|
|
33 |
$msg = isset($model->errors) ? current($model->errors)[0] : '数据异常!'; |
|
34 |
|
|
35 |
return [ |
|
36 |
'code' => ApiCode::CODE_ERROR, |
|
37 |
'msg' => $msg |
|
38 |
]; |
|
39 |
} |
|
40 |
|
|
41 |
/** |
|
42 |
* ActiveRecord 数据验证,返回第一条错误验证 |
|
43 |
* @param array $model |
|
44 |
* @return string |
|
45 |
*/ |
|
46 |
public function getErrorMsg($model = null) |
|
47 |
{ |
|
48 |
if (!$model) { |
|
49 |
$model = $this; |
|
50 |
} |
|
51 |
$msg = isset($model->errors) ? current($model->errors)[0] : '数据异常!'; |
|
52 |
return $msg; |
|
53 |
} |
|
54 |
|
|
55 |
public function setSign($val) |
|
56 |
{ |
|
57 |
$this->sign = $val; |
|
58 |
return $this; |
|
59 |
} |
|
60 |
} |