cxfoot/models/Model.php
2023-10-27 14:25:12 +08:00

145 lines
3.4 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* @author Any
* @description KISS
* @date 2020-10-30
* @version 1.0.0
*
* _____LOG_____
*
*/
namespace app\models;
use yii\helpers\HtmlPurifier;
class Model extends \yii\base\Model
{
/*
* 过滤html标签防止xss的问题
* $content为原始内容
*/
public static function htmlTagFilter($content)
{
return HtmlPurifier::process($content);
}
public function getModelError($model = null)
{
if($model == null)
$model = $this;
foreach ($model->errors as $errors)
return [
'code' => 1,
'msg' => $errors[0],
];
}
public static function getUserId()
{
if(!\Yii::$app->admin->isGuest){
return \Yii::$app->admin->identity->user_id;
}
if(!\Yii::$app->user->isGuest){
return \Yii::$app->user->identity->id;
}
return 0;
}
/**
* 获得平台商户ID
*/
public static function getCxMchId()
{
return \Yii::$app->controller->cx_mch_id;
}
public function apiReturnSuccess($msg = "ok", $data = [], $code = 0)
{
return [
'code' => $code,
'msg' => $msg,
'data' => $data
];
}
public function apiReturnError($msg = "failed", $data = [], $code = 1)
{
return [
'code' => $code,
'msg' => $msg,
'data' => $data
];
}
public static function getModelErrorInfo($model)
{
if($model == null)
return [
'code' => 1,
'msg' => '没有对象',
];
foreach ($model->errors as $errors)
return [
'code' => 1,
'msg' => $errors[0],
];
}
public static function asReturnSuccess($msg = "ok", $data = [], $code = 0)
{
return [
'code' => $code,
'msg' => $msg,
'data' => $data
];
}
public static function asReturnError($msg = "failed", $data = [], $code = 1)
{
return [
'code' => $code,
'msg' => $msg,
'data' => $data
];
}
/** ----- 审核状态 START ----- */
public static $reviewStatusWaitting = 0; //待审核
public static $reviewStatusApprove = 1; //审核通过
public static $reviewStatusReject = 2; //审核拒绝
public static $reviewStatusDraft = 3; //草稿
public static function getReviewStatus($key)
{
$labels = self::reviewStatusLabels();
return isset($labels[$key]) ? $labels[$key] : "未知";
}
public static function reviewStatusLabels()
{
return [
'0' => '待审核',
'1' => '审核通过',
'2' => '审核拒绝',
'3' => '草稿',
];
}
/** ----- 审核状态 END ----- */
public function dde($arg, $dumpAndDie = true)
{
echo "<pre>";
\yii\helpers\VarDumper::dump($arg);
echo "</pre>";
if ($dumpAndDie) {
die(1);
}
}
}