# 软删除和追加字段
```
~~~
protected $name ='web_page_single';
use SoftDelete;
protected $defaultSoftDelete = null;
protected $append = [
'status_text'
];
// 状态
const IS_STATUS = [
'2' => '关闭',
'1' => '开启',
];
~~~
```
# 设定属性 获取和设定
```
~~~
public function getStatusTextAttr($value, $data): string
{
if (!isset($data['status'])) return '';
return self::IS_STATUS[$data['status']] ?? $data['status'];
}
~~~
public function getStatusTextAttr($value, $data): string
{
if (!isset($data['status'])) return '';
return self::IS_STATUS[$data['status']] ?? $data['status'];
}
public function getTypeTextAttr($value, $data): string
{
if (!isset($data['type'])) return '';
return self::IS_TYPE[$data['type']] ?? $data['type'];
}
------------------------------------------------------------------------
~~~
protected function setShowTimeAttr($value)
{
if($value != 0){
return strtotime($value);
}else{
return $value;
}
}
~~~
```
# 模型关联查询数据
~~~
$query = (new UserCommissionLog)->alias('c')->where(['customer_id' => config('sys.platform_id')])
// 收益类型 金额 账户余额 粉丝手机号 时间 来源 状态 应用类型
->field('c.id, c.user_id, c.user_grade, c.amount, c.after_amount, c.create_time, c.order_type, c.status, c.app_type')
->whereIn('c.user_id', $user_ids)
->when(key_exists('status', $params), function (Query $query) use ($params) {
$query->where(['c.status' => $params['status']]);
})
->when(key_exists('user_grade', $params), function (Query $query) use ($params) {
$query->where(['c.user_grade' => $params['user_grade']]);
})
->when(key_exists('create_time', $params), function (Query $query) use ($params) {
$tmpTime = explode(' - ', $params['create_time']);
$query->whereBetween('c.create_time', [@$tmpTime[0], @$tmpTime[1]]);
})
->when(key_exists('mobile', $params), function (Query $query) use ($params) {
$query->leftJoin('user u', 'u.id=c.user_id')->where(['u.mobile' => $params['mobile']]);
})
->with(['user' => function(Query $query) {
$query->field('id, mobile');
}])
->order('c.id desc')->paginate($this->limit);
~~~
# 模型关联
```
~~~
$data = $this->model->where(['id' => $id])
->field('id, order_no, status, user_id, create_time, pay_time, pay_type, deliver_time, express_no, username, mobile, province, city, area, location, remarks, service_remarks')
->where(['customer_id' => config('sys.platform_id')])
->with(['user' => function (Query $query) {
$query->field('id, nickname, mobile');
}, 'order_details' => function (Query $query) {
$query->field('goods_order_id, goods_image, goods_name, goods_code, goods_price, goods_num, goods_total_price, discount_price, freight_price, goods_total_price, real_price');
}])
->find();
~~~
~~~
public function user(): HasOne
{
return $this->hasOne(User::class, 'id', 'user_id');
}
public function orderDetails(): HasMany
{
return $this->hasMany(GoodsOrderDetail::class, 'goods_order_id');
}
~~~
```
- tp5图片上传
- 文件上传到七牛云
- 上传到阿里云
- 富文本编辑器
- phpexcel和spreadsheet
- phpexcel导出
- phpexcel导入
- spreadsheet
- tp5_api接口
- 跨域请求
- JWT
- 图片和视频上传接口
- 验证码
- tp5小程序登录
- tp5小程序支付
- tp5基础架构
- 验证层
- 模型层Model
- 控制器构找
- tp5.0支付宝
- 海报二维码
- 轮播图
- echarts柱状图
- layui的图片弹窗
- p标签显示指定行数(全部)
- jquery和layerdate调用日期
- ajax发送文件和图片的坑啊
- JS日期点击上一天和下一天
- 百度分享js
- POST请求
- 商品数据表
- tp5.0支付宝最全
- tp5路由的坑
- 二维数组排序
- tp5模型分组group错误
- 二维变一维数组
- 无限树形结构
- json对象转数组
- 模型关联查询
- tp5的模型获取器和字段设定
- 经纬度获取距离排序