| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace App\Models\Api\Promoter;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- /**
- * 推广员配置模型
- * @author 唐远望
- * @version 1.0
- * @date 2025-09-05
- */
- class Configuration extends Model
- {
- use HasFactory;
- protected $table = 'promoter_configuration';
- // 是否主动维护时间戳
- public $timestamps = false;
- protected $connection = 'company';
- // 定义时间戳字段名
- // const CREATED_AT = 'insert_time';
- // const UPDATED_AT = 'update_time';
- protected $appends = ['content'];
- /**
- * 获取推广员配置内容
- * @author 唐远望
- * @version 1.0
- * @date 2025-09-05
- * @return string
- */
- public function getContentAttribute()
- {
- $content = $this->attributes['content'];
- //判断是否json格式
- if ($this->isValidJson($content)) {
- $content = json_decode($content, true);
- }
- return $content;
- }
- /**
- * 获取推广员配置内容
- * @author 唐远望
- * @version 1.0
- * @date 2025-09-05
- * @return string
- */
- function isValidJson($string)
- {
- if (!is_string($string) || empty($string)) {
- return false;
- }
- // 尝试解码
- $result = json_decode($string);
- // 检查解码错误
- if (json_last_error() !== JSON_ERROR_NONE) {
- return false;
- }
- // 确保解码后不是null(除非原始JSON就是"null")
- if ($result === null && $string !== 'null') {
- return false;
- }
- return true;
- }
- }
|