From 121b714d710cf3c865f4a1b5efe81abec11056d1 Mon Sep 17 00:00:00 2001
From: quanwei <419654421@qq.com>
Date: Sat, 01 Nov 2025 14:36:36 +0800
Subject: [PATCH] 修复名片模板生成失败问题 修复后台名片查看不显示头像和logo问题
---
admin/app/common/model/plus/business/Business.php | 118 ++++++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 84 insertions(+), 34 deletions(-)
diff --git a/admin/app/common/model/plus/business/Business.php b/admin/app/common/model/plus/business/Business.php
index 943052b..58a6405 100644
--- a/admin/app/common/model/plus/business/Business.php
+++ b/admin/app/common/model/plus/business/Business.php
@@ -1,6 +1,7 @@
<?php
namespace app\common\model\plus\business;
+
use app\common\model\BaseModel;
use app\common\model\settings\Region;
@@ -9,7 +10,7 @@
*/
class Business extends BaseModel
{
- protected $name='business_card';
+ protected $name = 'business_card';
/**
* 追加字段
* @var string[]
@@ -30,60 +31,88 @@
'region' => $data['region_id'] == 0 ? '' : Region::getNameById($data['region_id']),
];
}
- public function getSexAttr($value){
- $data=[10=>'未知',20=>'男',30=>'女'];
+
+ public function getSexAttr($value)
+ {
+ $data = [10 => '未知', 20 => '男', 30 => '女'];
return $data[$value];
}
+
/**
* 关联用户
* @return \think\model\relation\HasOne
*/
- public function user(){
- $model=self::getCalledModule()?:'common';
- return $this->hasOne("app\\$model\\model\\user\\User",'user_id','user_id');
+ public function user()
+ {
+ $model = self::getCalledModule() ?: 'common';
+ return $this->hasOne("app\\$model\\model\\user\\User", 'user_id', 'user_id');
}
/**
* 头像
* @return \think\model\relation\HasOne
*/
- public function image(){
- $model=self::getCalledModule()?:'common';
- return $this->hasOne("app\\$model\\model\\file\\UploadFile",'file_id','file_id')->bind(['file_path']);
+ public function image()
+ {
+ $model = self::getCalledModule() ?: 'common';
+ return $this->hasOne("app\\$model\\model\\file\\UploadFile", 'file_id', 'file_id')->bind(['file_path']);
}
+
/**
* logo
* @return \think\model\relation\HasOne
*/
- public function logoImage(){
- $model=self::getCalledModule()?:'common';
- return $this->hasOne("app\\$model\\model\\file\\UploadFile",'file_id','logo')->bind(['file_path']);
+ public function logoImage()
+ {
+ $model = self::getCalledModule() ?: 'common';
+ return $this->hasOne("app\\$model\\model\\file\\UploadFile", 'file_id', 'logo');
}
+
+ /**
+ * 等级
+ * @return \think\model\relation\HasOne
+ */
+ public function grade()
+ {
+ $model = self::getCalledModule() ?: 'common';
+ return $this->hasOne("app\\$model\\model\\plus\\business\\Grade", 'grade_id', 'grade_id');
+ }
+ public function industry()
+ {
+ $model = self::getCalledModule() ?: 'common';
+ return $this->hasOne("app\\$model\\model\\plus\\business\\Industry", 'industry_id', 'industry_id');
+ }
+
/**
* 添加
* @param $data
* @return false|int
*/
- public function add($data){
- $data['app_id']=self::$app_id;
- $data['grade_id']=(new Grade())->getDefaultGradeId();
+ public function add($data)
+ {
+ $data['app_id'] = self::$app_id;
+ $data['grade_id'] = (new Grade())->getDefaultGradeId();
return $this->save($data);
}
+
public function getUnitAttr($name)
{
return json_decode($name);
}
+
public function getDutiesAttr($name)
{
return json_decode($name);
}
+
public function getAddressAttr($name)
{
return json_decode($name);
}
+
public function getPositionAttr($name)
{
- return $name?json_decode($name):[];
+ return $name ? json_decode($name) : [];
}
/**
@@ -92,32 +121,53 @@
* @return \think\Paginator
* @throws \think\db\exception\DbException
*/
- public function getList($param=[]){
- $paramr=array_merge(['listRow'=>15],$param);
- $where=[];
- !empty($paramr['name'])&&$where['name']=['like','%'.$paramr['name'].'%'];
- !empty($paramr['search'])&&$where['name|duties|unit']=['like','%'.$paramr['search'].'%'];
- !empty($paramr['user_id'])&&$where['user_id']=$paramr['user_id'];
- if(!empty($paramr['sort'])){
- if($paramr['sort']=='name'){
- $order=['name'=>"asc"];
- }else if($paramr['sort']=='time'){
- $order=['create_time'=>"asc"];
- }else{
- $order=['unit'=>"asc"];
+ public function getList($param = [])
+ {
+ $paramr = array_merge(['listRow' => 15], $param);
+ $where = [];
+ !empty($paramr['name']) && $where['name'] = ['like', '%' . $paramr['name'] . '%'];
+ !empty($paramr['search']) && $where['name|duties|unit'] = ['like', '%' . $paramr['search'] . '%'];
+ !empty($paramr['user_id']) && $where['user_id'] = $paramr['user_id'];
+ !empty($paramr['industry_id']) && $where['industry_id'] = $paramr['industry_id'];
+ !empty($paramr['province_id']) && $where['province_id'] = $paramr['province_id'];
+ !empty($paramr['city_id']) && $where['city_id'] = $paramr['city_id'];
+ !empty($paramr['region_id']) && $where['region_id'] = $paramr['region_id'];
+ if (!empty($paramr['sort'])) {
+ if ($paramr['sort'] == 'name') {
+ $order = ['name' => "asc"];
+ } else if ($paramr['sort'] == 'time') {
+ $order = ['create_time' => "asc"];
+ } else {
+ $order = ['unit' => "asc"];
}
- }else{
- $order=['is_default'=>'desc','create_time'=>'desc'];
+ } else {
+ // 检查置顶时间是否过期,如果过期则设置为非置顶
+ $this->checkTopExpire();
+
+ // 按置顶状态和创建时间排序
+ $order = ['is_top' => 'desc', 'top_time' => 'desc', 'create_time' => 'desc'];
}
- return $this->with(['user','image','logoImage'])->order($order)->where($where)->paginate($paramr);
+ return $this->with(['user', 'image', 'logoImage', 'grade'])->order($order)->where($where)->paginate($paramr);
}
+
+ /**
+ * 检查并更新过期的置顶名片
+ */
+ private function checkTopExpire()
+ {
+ $this->where('is_top', 1)
+ ->where('top_time', '<', time())
+ ->update(['is_top' => 0]);
+ }
+
/**
* 获取名片详情
* @param $business_card_id
* @return array|false|\think\Model|null
* @throws \think\db\exception\DbException
*/
- public function detail($business_card_id){
- return $this->with(['user','image','logoImage'])->where(['business_card_id'=>$business_card_id])->find();
+ public static function detail($business_card_id)
+ {
+ return (new self())->with(['user', 'image', 'logoImage', 'grade', 'industry'])->where(['business_card_id' => $business_card_id])->find();
}
}
\ No newline at end of file
--
Gitblit v1.9.2