Yahoo před 4 roky
rodič
revize
7da58c7098

+ 6 - 10
app/common/library/Download.php

@@ -8,7 +8,7 @@
 // +----------------------------------------------------------------------
 // | Author: 萤火科技 <admin@yiovo.com>
 // +----------------------------------------------------------------------
-declare (strict_types = 1);
+declare (strict_types=1);
 
 namespace app\common\library;
 
@@ -22,9 +22,9 @@ class Download
      * @param string $url
      * @param string $prefix
      * @return string
-     * @throws BaseException
+     * @throws \cores\exception\BaseException
      */
-    public function saveTempImage(int $storeId, string $url, string $prefix = 'temp')
+    public function saveTempImage(int $storeId, string $url, string $prefix = 'temp'): string
     {
         $savePath = $this->getSavePath($storeId, $prefix, $url);
         if (!file_exists($savePath)) {
@@ -39,14 +39,12 @@ class Download
      * 写入文件
      * @param string $savePath
      * @param string $result
-     * @return false|int
      */
     private function fwrite(string $savePath, string $result)
     {
         $fp = fopen($savePath, 'w');
-        $status = fwrite($fp, $result);
+        fwrite($fp, $result);
         fclose($fp);
-        return $status;
     }
 
     /**
@@ -59,7 +57,6 @@ class Download
         $ch = curl_init($url);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-        curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
         $result = curl_exec($ch);
         curl_close($ch);
         return $result;
@@ -72,7 +69,7 @@ class Download
      * @param string $url
      * @return string
      */
-    private function getSavePath(int $storeId, string $prefix, string $url)
+    private function getSavePath(int $storeId, string $prefix, string $url): string
     {
         $dirPath = $this->getDirPath($storeId);
         return $dirPath . '/' . $prefix . '_' . md5($url) . '.png';
@@ -83,11 +80,10 @@ class Download
      * @param int $storeId
      * @return string
      */
-    private function getDirPath(int $storeId)
+    private function getDirPath(int $storeId): string
     {
         $dirPath = runtime_root_path() . "image/{$storeId}";
         !is_dir($dirPath) && mkdir($dirPath, 0755, true);
         return $dirPath;
     }
-
 }

+ 8 - 8
app/common/library/Lock.php

@@ -24,10 +24,10 @@ class Lock
 
     /**
      * 加锁
-     * @param $uniqueId
+     * @param string $uniqueId
      * @return bool
      */
-    public static function lockUp($uniqueId)
+    public static function lockUp(string $uniqueId): bool
     {
         static::$resource[$uniqueId] = fopen(static::getFilePath($uniqueId), 'w+');
         return flock(static::$resource[$uniqueId], LOCK_EX);
@@ -35,10 +35,10 @@ class Lock
 
     /**
      * 解锁
-     * @param $uniqueId
+     * @param string $uniqueId
      * @return bool
      */
-    public static function unLock($uniqueId)
+    public static function unLock(string $uniqueId): bool
     {
         if (!isset(static::$resource[$uniqueId])) return false;
         flock(static::$resource[$uniqueId], LOCK_UN);
@@ -48,10 +48,10 @@ class Lock
 
     /**
      * 获取锁文件的路径
-     * @param $uniqueId
+     * @param string $uniqueId
      * @return string
      */
-    private static function getFilePath($uniqueId)
+    private static function getFilePath(string $uniqueId): string
     {
         $dirPath = runtime_root_path() . 'lock/';
         !is_dir($dirPath) && mkdir($dirPath, 0755, true);
@@ -60,10 +60,10 @@ class Lock
 
     /**
      * 删除锁文件
-     * @param $uniqueId
+     * @param string $uniqueId
      * @return bool
      */
-    private static function deleteFile($uniqueId)
+    private static function deleteFile(string $uniqueId): bool
     {
         $filePath = static::getFilePath($uniqueId);
         return file_exists($filePath) && unlink($filePath);

+ 12 - 21
app/common/library/express/Kuaidi100.php

@@ -8,11 +8,12 @@
 // +----------------------------------------------------------------------
 // | Author: 萤火科技 <admin@yiovo.com>
 // +----------------------------------------------------------------------
-declare (strict_types = 1);
+declare (strict_types=1);
 
 namespace app\common\library\express;
 
 use think\facade\Cache;
+use cores\traits\ErrorTrait;
 use app\common\library\helper;
 
 /**
@@ -22,11 +23,11 @@ use app\common\library\helper;
  */
 class Kuaidi100
 {
-    /* @var array $config 微信支付配置 */
-    private $config;
+    use ErrorTrait;
 
-    /* @var string $error 错误信息 */
-    private $error;
+    // 微信支付配置
+    /* @var array $config */
+    private $config;
 
     /**
      * 构造方法
@@ -40,16 +41,16 @@ class Kuaidi100
 
     /**
      * 执行查询
-     * @param $code
-     * @param $expressNo
+     * @param string $code
+     * @param string $expressNo
      * @return bool
      */
-    public function query($code, $expressNo)
+    public function query(string $code, string $expressNo): bool
     {
         // 缓存索引
         $cacheIndex = "express_{$code}_$expressNo";
-        if ($data = Cache::get($cacheIndex)) {
-            return $data;
+        if ($cacheData = Cache::get($cacheIndex)) {
+            return $cacheData;
         }
         // 参数设置
         $postData = [
@@ -67,21 +68,11 @@ class Kuaidi100
         $express = helper::jsonDecode($result);
         // 记录错误信息
         if (isset($express['returnCode']) || !isset($express['data'])) {
-            $this->error = isset($express['message']) ? $express['message'] : '查询失败';
+            $this->error = $express['message'] ?? '查询失败';
             return false;
         }
         // 记录缓存, 时效5分钟
         Cache::set($cacheIndex, $express['data'], 300);
         return $express['data'];
     }
-
-    /**
-     * 返回错误信息
-     * @return string
-     */
-    public function getError()
-    {
-        return $this->error;
-    }
-
 }

+ 11 - 0
app/common/library/helper.php

@@ -223,4 +223,15 @@ class helper
         }
         return false;
     }
+
+    /**
+     * 记录info日志
+     * @param string $name
+     * @param array $content
+     */
+    public static function logInfo(string $name, array $content)
+    {
+        $content['name'] = $name;
+        log_record($content, 'info');
+    }
 }

+ 6 - 7
app/common/library/storage/Driver.php

@@ -43,10 +43,10 @@ class Driver
      * 构造方法
      * Driver constructor.
      * @param $config
-     * @param null|string $storage 指定存储方式,如不指定则为系统默认
+     * @param string|null $storage 指定存储方式,如不指定则为系统默认
      * @throws Exception
      */
-    public function __construct($config, $storage = null)
+    public function __construct($config, string $storage = null)
     {
         $this->config = $config;
         // 实例化当前存储引擎
@@ -58,7 +58,7 @@ class Driver
      * @param string $name
      * @return mixed
      */
-    public function setUploadFile($name = 'iFile')
+    public function setUploadFile(string $name = 'iFile')
     {
         return $this->engine->setUploadFile($name);
     }
@@ -78,7 +78,7 @@ class Driver
      * @param string $name
      * @return mixed
      */
-    public function setRootName($name = '')
+    public function setRootName(string $name = '')
     {
         return $this->engine->setRootName($name);
     }
@@ -131,11 +131,11 @@ class Driver
 
     /**
      * 获取当前的存储引擎
-     * @param null|string $storage 指定存储方式,如不指定则为系统默认
+     * @param string|null $storage 指定存储方式,如不指定则为系统默认
      * @return mixed
      * @throws Exception
      */
-    private function getEngineClass($storage = null)
+    private function getEngineClass(string $storage = null)
     {
         $storage = is_null($storage) ? $this->config['default'] : $storage;
         if (!isset(self::ENGINE_CLASS_LIST[$storage])) {
@@ -144,5 +144,4 @@ class Driver
         $class = self::ENGINE_CLASS_LIST[$storage];
         return new $class($storage, $this->config['engine'][$storage]);
     }
-
 }

+ 6 - 6
app/common/library/storage/engine/Aliyun.php

@@ -24,9 +24,9 @@ class Aliyun extends Basics
 {
     /**
      * 执行上传
-     * @return bool|mixed
+     * @return bool
      */
-    public function upload()
+    public function upload(): bool
     {
         try {
             $ossClient = new OssClient(
@@ -49,10 +49,10 @@ class Aliyun extends Basics
 
     /**
      * 删除文件
-     * @param string $fileName
-     * @return bool|mixed
+     * @param string $filePath
+     * @return bool
      */
-    public function delete(string $fileName)
+    public function delete(string $filePath): bool
     {
         try {
             $ossClient = new OssClient(
@@ -61,7 +61,7 @@ class Aliyun extends Basics
                 $this->config['domain'],
                 true
             );
-            $ossClient->deleteObject($this->config['bucket'], $fileName);
+            $ossClient->deleteObject($this->config['bucket'], $filePath);
         } catch (OssException $e) {
             $this->error = $e->getMessage();
             return false;

+ 2 - 3
app/common/library/storage/engine/Basics.php

@@ -175,7 +175,7 @@ abstract class Basics
     public function getSaveFileInfo(): array
     {
         // 自动生成的文件名称
-        // $hashName = $this->file->hashName(null);
+        //$hashName = $this->file->hashName(null);
         $hashName = $this->hashName();
         // 存储目录
         $filePath = $this->getFilePath($hashName);
@@ -198,7 +198,7 @@ abstract class Basics
      * 自动生成文件名
      * @return string
      */
-    private function hashName()
+    private function hashName(): string
     {
         return $this->file->hashName(function () {
             return date('Ymd') . DIRECTORY_SEPARATOR . md5(uniqid((string)mt_rand(), true));
@@ -235,5 +235,4 @@ abstract class Basics
     {
         return dirname($filePath);
     }
-
 }

+ 2 - 3
app/common/library/storage/engine/Local.php

@@ -24,7 +24,7 @@ class Local extends Basics
 {
     /**
      * 上传图片文件
-     * @return array|bool
+     * @return bool
      */
     public function upload()
     {
@@ -51,7 +51,7 @@ class Local extends Basics
      * 验证上传的文件
      * @return bool
      */
-    private function validate()
+    private function validate(): bool
     {
         $FileValidate = new FileValidate;
         if (!$FileValidate->check([$this->validateRuleScene => $this->file])) {
@@ -72,5 +72,4 @@ class Local extends Basics
         $realPath = realpath(web_path() . "uploads/{$filePath}");
         return $realPath === false || unlink($realPath);
     }
-
 }

+ 3 - 3
app/common/library/storage/engine/Qcloud.php

@@ -74,15 +74,15 @@ class Qcloud extends Basics
 
     /**
      * 删除文件
-     * @param string $fileName
+     * @param string $filePath
      * @return bool|mixed
      */
-    public function delete(string $fileName)
+    public function delete(string $filePath)
     {
         try {
             $result = $this->cosClient->deleteObject(array(
                 'Bucket' => $this->config['bucket'],
-                'Key' => $fileName
+                'Key' => $filePath
             ));
             return true;
         } catch (\Exception $e) {

+ 5 - 5
app/common/library/storage/engine/Qiniu.php

@@ -13,6 +13,7 @@ declare (strict_types = 1);
 namespace app\common\library\storage\engine;
 
 use Qiniu\Auth;
+use Qiniu\Http\Error;
 use Qiniu\Storage\UploadManager;
 use Qiniu\Storage\BucketManager;
 
@@ -40,7 +41,7 @@ class Qiniu extends Basics
         $uploadMgr = new UploadManager();
         // 调用 UploadManager 的 putFile 方法进行文件的上传
         list(, $error) = $uploadMgr->putFile($token, $this->getSaveFileInfo()['file_path'], $realPath);
-        /* @var $error \Qiniu\Http\Error */
+        /* @var $error Error */
         if ($error !== null) {
             $this->error = $error->message();
             return false;
@@ -51,15 +52,15 @@ class Qiniu extends Basics
     /**
      * 删除文件
      * @param string $filePath
-     * @return bool|mixed
+     * @return bool
      */
-    public function delete(string $filePath)
+    public function delete(string $filePath): bool
     {
         // 构建鉴权对象
         $auth = new Auth($this->config['access_key'], $this->config['secret_key']);
         // 初始化 UploadManager 对象并进行文件的上传
         $bucketMgr = new BucketManager($auth);
-        /* @var $error \Qiniu\Http\Error */
+        /* @var $error Error */
         $error = $bucketMgr->delete($this->config['bucket'], $filePath);
         if ($error !== null) {
             $this->error = $error->message();
@@ -67,5 +68,4 @@ class Qiniu extends Basics
         }
         return true;
     }
-
 }

+ 11 - 20
app/common/library/wechat/WxBase.php

@@ -13,6 +13,7 @@ declare (strict_types=1);
 namespace app\common\library\wechat;
 
 use think\facade\Cache;
+use cores\traits\ErrorTrait;
 use app\common\library\helper;
 use app\common\exception\BaseException;
 
@@ -23,11 +24,11 @@ use app\common\exception\BaseException;
  */
 class WxBase
 {
+    use ErrorTrait;
+
     protected $appId;
     protected $appSecret;
 
-    protected $error;
-
     /**
      * 构造函数
      * WxBase constructor.
@@ -48,7 +49,7 @@ class WxBase
     /**
      * 获取access_token
      * @return mixed
-     * @throws BaseException
+     * @throws \cores\exception\BaseException
      */
     protected function getAccessToken()
     {
@@ -79,7 +80,7 @@ class WxBase
      * @param string $url 请求地址
      * @param array $data
      * @return string $result
-     * @throws BaseException
+     * @throws \cores\exception\BaseException
      */
     protected function get(string $url, array $data = [])
     {
@@ -103,13 +104,13 @@ class WxBase
     /**
      * 模拟POST请求
      * @param string $url 请求地址
-     * @param array $data 请求数据
+     * @param mixed $data 请求数据
      * @param false $useCert 是否引入微信支付证书
      * @param array $sslCert 证书路径
      * @return mixed|bool|string
-     * @throws BaseException
+     * @throws \cores\exception\BaseException
      */
-    protected function post(string $url, $data = [], $useCert = false, $sslCert = [])
+    protected function post(string $url, $data = [], bool $useCert = false, array $sslCert = [])
     {
         $header = [
             'Content-type: application/json;'
@@ -142,9 +143,9 @@ class WxBase
      * @param $url
      * @param array $data
      * @return mixed
-     * @throws BaseException
+     * @throws \cores\exception\BaseException
      */
-    protected function post2($url, $data = [])
+    protected function post2($url, array $data = [])
     {
         $header = [
             'Content-Type: application/x-www-form-urlencoded'
@@ -169,7 +170,7 @@ class WxBase
      * @param $data
      * @return string
      */
-    protected function jsonEncode($data)
+    protected function jsonEncode($data): string
     {
         return helper::jsonEncode($data, JSON_UNESCAPED_UNICODE);
     }
@@ -183,14 +184,4 @@ class WxBase
     {
         return helper::jsonDecode($json);
     }
-
-    /**
-     * 返回错误信息
-     * @return mixed
-     */
-    public function getError()
-    {
-        return $this->error;
-    }
-
 }

+ 2 - 47
app/common/library/wechat/WxPay.php

@@ -204,51 +204,6 @@ class WxPay extends WxBase
         return true;
     }
 
-    /**
-     * 企业付款到零钱API
-     * @param string $orderNo 订单号
-     * @param string $openid 微信用户openid
-     * @param string $amount 支付金额
-     * @param string $desc 描述
-     * @return bool
-     * @throws BaseException
-     * @throws \cores\exception\BaseException
-     */
-    public function transfers(string $orderNo, string $openid, string $amount, string $desc): bool
-    {
-        // API参数
-        $params = [
-            'mch_appid' => $this->appId,
-            'mchid' => $this->config['mchid'],
-            'nonce_str' => md5(uniqid()),
-            'partner_trade_no' => $orderNo,
-            'openid' => $openid,
-            'check_name' => 'NO_CHECK',
-            'amount' => $amount * 100,
-            'desc' => $desc,
-            'spbill_create_ip' => \request()->ip(),
-        ];
-        // 生成签名
-        $params['sign'] = $this->makeSign($params);
-        // 请求API
-        $url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
-        $result = $this->post($url, $this->toXml($params), true, $this->getCertPem());
-        // 请求失败
-        if (empty($result)) {
-            throwError('企业付款到零钱API请求失败');
-        }
-        // 格式化返回结果
-        $prepay = $this->fromXml($result);
-        // 请求失败
-        if ($prepay['return_code'] === 'FAIL') {
-            throwError("return_msg: {$prepay['return_msg']}");
-        }
-        if ($prepay['result_code'] === 'FAIL') {
-            throwError("err_code_des: {$prepay['err_code_des']}");
-        }
-        return true;
-    }
-
     /**
      * 获取cert证书文件
      * @return string[]
@@ -284,9 +239,9 @@ class WxPay extends WxBase
     /**
      * 返回状态给微信服务器
      * @param boolean $returnCode
-     * @param string $msg
+     * @param string|null $msg
      */
-    private function returnCode($returnCode = true, $msg = null)
+    private function returnCode(bool $returnCode = true, string $msg = null)
     {
         // 返回状态
         $return = [

+ 8 - 27
app/common/service/BaseService.php

@@ -8,10 +8,11 @@
 // +----------------------------------------------------------------------
 // | Author: 萤火科技 <admin@yiovo.com>
 // +----------------------------------------------------------------------
-declare (strict_types = 1);
+declare (strict_types=1);
 
 namespace app\common\service;
 
+use cores\traits\ErrorTrait;
 use think\facade\Request;
 
 /**
@@ -21,13 +22,12 @@ use think\facade\Request;
  */
 class BaseService
 {
+    use ErrorTrait;
+
     // 请求管理类
     /* @var $request \think\Request */
     protected $request;
 
-    // 错误信息
-    protected $error;
-
     // 当前访问的商城ID
     protected $storeId;
 
@@ -39,7 +39,9 @@ class BaseService
     {
         // 请求管理类
         $this->request = Request::instance();
-        // 执行构造方法
+        // 获取当前操作的商城ID
+        $this->getStoreId();
+        // 执行子类的构造方法
         $this->initialize();
     }
 
@@ -48,38 +50,17 @@ class BaseService
      */
     protected function initialize()
     {
-        // 获取当前操作的商城ID
-        $this->getStoreId();
     }
 
     /**
      * 获取当前操作的商城ID
      * @return int|null
      */
-    protected function getStoreId()
+    protected function getStoreId(): ?int
     {
         if (empty($this->storeId) && in_array(app_name(), ['store', 'api'])) {
             $this->storeId = getStoreId();
         }
         return $this->storeId;
     }
-
-    /**
-     * 获取错误信息
-     * @return mixed
-     */
-    public function getError()
-    {
-        return empty($this->error) ? false : $this->error;
-    }
-
-    /**
-     * 是否存在错误
-     * @return bool
-     */
-    public function hasError()
-    {
-        return !empty($this->error);
-    }
-
 }

+ 18 - 18
app/common/service/Goods.php

@@ -8,12 +8,13 @@
 // +----------------------------------------------------------------------
 // | Author: 萤火科技 <admin@yiovo.com>
 // +----------------------------------------------------------------------
-declare (strict_types = 1);
+declare (strict_types=1);
 
 namespace app\common\service;
 
 use app\common\library\helper;
 use app\common\model\Goods as GoodsModel;
+use app\common\model\GoodsSku as GoodsSkuModel;
 
 /**
  * 商品服务类
@@ -24,37 +25,36 @@ class Goods extends BaseService
 {
     /**
      * 设置商品数据
-     * @param $data
-     * @param bool $isMultiple
-     * @param string $goodsIndex
+     * @param mixed $data 源数据
+     * @param bool $isMultiple 是否为列表数据
+     * @param array $hidden 隐藏的属性
+     * @param string $goodsIndex 商品ID字段名称
      * @return mixed
      */
-    public static function setGoodsData($data, $isMultiple = true, $goodsIndex = 'goods_id')
+    public static function setGoodsData($data, bool $isMultiple = true, array $hidden = [], string $goodsIndex = 'goods_id')
     {
         if (!$isMultiple) $dataSource = [&$data]; else $dataSource = &$data;
         // 获取商品列表
         $model = new GoodsModel;
         $goodsData = $model->getListByIds(helper::getArrayColumn($dataSource, $goodsIndex));
-        $goodsList = helper::arrayColumn2Key($goodsData, 'goods_id');
+        // 设置隐藏的属性
+        $goodsData->hidden(array_merge(['images'], $hidden));
         // 整理列表数据
+        $goodsList = helper::arrayColumn2Key($goodsData, 'goods_id');
         foreach ($dataSource as &$item) {
-            $item['goods'] = isset($goodsList[$item[$goodsIndex]]) ? $goodsList[$item[$goodsIndex]] : null;
+            $item['goods'] = $goodsList[$item[$goodsIndex]] ?? null;
         }
-        return $data;
+        return $dataSource->hidden($hidden);
     }
 
     /**
-     * 商品多规格信息
-     * @param GoodsModel|null $model
-     * @return null|array
+     * 获取商品的指定的某个SKU信息
+     * @param int $goodsId
+     * @param string $goodsSkuId
+     * @return GoodsSkuModel|array|null
      */
-    public static function getSpecData($model = null)
+    public static function getSkuInfo(int $goodsId, string $goodsSkuId)
     {
-        // 商品sku数据
-        if (!is_null($model) && $model['spec_type'] == 20) {
-            return $model->getManySpecData($model['spec_rel'], $model['skuList']);
-        }
-        return null;
+        return GoodsSkuModel::detail($goodsId, $goodsSkuId);
     }
-
 }

+ 1 - 2
app/common/service/Message.php

@@ -42,11 +42,10 @@ class Message extends BaseService
      * @param int $storeId 商城ID
      * @return bool
      */
-    public static function send(string $sceneName, array $param, int $storeId)
+    public static function send(string $sceneName, array $param, int $storeId): bool
     {
         if (!isset(self::$sceneList[$sceneName])) return false;
         $class = self::$sceneList[$sceneName];
         return (new $class($storeId))->send($param);
     }
-
 }

+ 4 - 4
app/common/service/Order.php

@@ -8,7 +8,7 @@
 // +----------------------------------------------------------------------
 // | Author: 萤火科技 <admin@yiovo.com>
 // +----------------------------------------------------------------------
-declare (strict_types = 1);
+declare (strict_types=1);
 
 namespace app\common\service;
 
@@ -25,12 +25,12 @@ use app\common\service\goods\source\Factory as FactoryStock;
 class Order extends BaseService
 {
     /**
-     * 生成订单号
+     * 生成订单号`
      * @return string
      */
-    public static function createOrderNo()
+    public static function createOrderNo(): string
     {
-        return date('Ymd') . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
+        return date('Ymd') . substr(implode('', array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
     }
 
     /**

+ 1 - 1
app/common/service/message/Basics.php

@@ -59,7 +59,7 @@ abstract class Basics extends BaseService
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    protected function sendSms(string $sceneValue, array $templateParams, array $sceneConfig = [])
+    protected function sendSms(string $sceneValue, array $templateParams, array $sceneConfig = []): bool
     {
         // 短信通知设置
         $smsConfig = SettingModel::getItem('sms', $this->storeId);

+ 3 - 12
app/common/service/message/order/Payment.php

@@ -57,25 +57,16 @@ class Payment extends Basics
 
     /**
      * 短信通知商家
-     * @return bool
+     * @return void
      * @throws \think\Exception
      * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    private function onSendSms()
+    private function onSendSms(): void
     {
         $orderInfo = $this->param['order'];
-        return $this->sendSms(SettingSmsScene::ORDER_PAY, ['order_no' => $orderInfo['order_no']]);
+        $this->sendSms(SettingSmsScene::ORDER_PAY, ['order_no' => $orderInfo['order_no']]);
     }
 
-    /**
-     * 格式化商品名称
-     * @param $goodsData
-     * @return string
-     */
-    private function getFormatGoodsName($goodsData)
-    {
-        return $this->getSubstr($goodsData[0]['goods_name']);
-    }
 }

+ 52 - 0
cores/traits/ErrorTrait.php

@@ -0,0 +1,52 @@
+<?php
+// +----------------------------------------------------------------------
+// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
+// +----------------------------------------------------------------------
+// | Author: 萤火科技 <admin@yiovo.com>
+// +----------------------------------------------------------------------
+namespace cores\traits;
+
+/**
+ * 错误信息Trait类
+ */
+trait ErrorTrait
+{
+    /**
+     * 错误信息
+     * @var string
+     */
+    protected $error;
+
+    /**
+     * 设置错误信息
+     * @param string|null $error
+     * @return bool
+     */
+    protected function setError(?string $error = null): bool
+    {
+        $this->error = $error ?: '未知错误';
+        return false;
+    }
+
+    /**
+     * 获取错误信息
+     * @return string
+     */
+    public function getError(): string
+    {
+        return $this->error;
+    }
+
+    /**
+     * 是否存在错误信息
+     * @return bool
+     */
+    public function hasError(): bool
+    {
+        return !empty($this->error);
+    }
+}