You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
4.6 KiB

<?php
namespace app\mall\model;
use app\base\model\user\UserInfo;
use think\model\concern\SoftDelete;
class MallEvaluate extends Base
{
use SoftDelete;
protected $type = [
'img_path' => 'serialize',
'video_path' => 'serialize'
];
/**
* 获取前台显示的时间
* @date 2022-05-24
*/
public function getShowCreateTimeAttr($value, $data)
{
return date("Y.m.d H:i", $data['create_time']);
}
/**
* 查找我的订单列表
* @date 2021-03-01
*/
public function getEvaluateList($where, $page, $field = '*', $order = '', $per_page_number = 10)
{
$primary_key_name = $this->getPk();
if (empty($order)) {
$order = (empty($data[$primary_key_name]) ? 'id' : $data[$primary_key_name]) . ' desc';
}
$dataList = $this->with(['mallEvaluate', 'userInfo'])->field($field)->where($where)->order($order)
->paginate(['list_rows' => $per_page_number, 'page' => $page], false)->each(function ($item, $key) {
//显示评论时间
$item['show_create_time'] = $item->show_create_time;
$arr = [];
if ($item['has_video'] == 2) {
foreach ($item['video_path'] as $k => $v) {
$arr[] = [
'type' => 2,
'image_url' => $v['image_url'],
'video_url' => $v['video_url'],
];
}
}
if ($item['has_img'] == 2) {
foreach ($item['img_path'] as $k => $v) {
$arr[] = [
'type' => 1,
'image_url' => $v,
'video_url' => '',
];
}
}
$item['photos'] = $arr;
$item['add_evaluate_photos'] = [];
if ($item['is_add'] == 1) {
$item['add_evaluate_space_day'] = floor((strtotime($item['add_evaluate_create_time']) - strtotime($item['create_time'])) / 86400);
$arr = [];
if ($item['add_evaluate_has_video'] == 2) {
foreach ($item['add_evaluate_video_path'] as $k => $v) {
$arr[] = [
'type' => 2,
'video_url' => $v['video_url'],
'image_url' => $v['image_url'],
];
}
}
if ($item['add_evaluate_has_img'] == 2) {
foreach ($item['add_evaluate_img_path'] as $k => $v) {
$arr[] = [
'type' => 1,
'image_url' => $v,
'video_url' => '',
];
}
}
$item['add_evaluate_photos'] = $arr;
}
unset($item['add_evaluate_has_video']);
unset($item['add_evaluate_video_path']);
unset($item['add_evaluate_has_img']);
unset($item['add_evaluate_img_path']);
unset($item['has_video']);
unset($item['video_path']);
unset($item['has_img']);
unset($item['img_path']);
unset($item['user_id']);
return $item;
});
return $dataList;
}
/**
* 一对一关联追加评论
* @date 2021-03-01
*/
public function mallEvaluate()
{
return $this->hasOne('mallEvaluate', 'evaluate_id', 'id')->bind([
'add_evaluate_create_time' => 'create_time', //追加评价时间
'add_evaluate_content' => 'content', //追加评价内容
'add_evaluate_has_video' => 'has_video', //评论是否有视频 1-没有 2-有
'add_evaluate_video_path' => 'video_path', //评论视频路径
'add_evaluate_has_img' => 'has_img', //是否有图 1--无图 2--有图
'add_evaluate_img_path' => 'img_path', //图片(序列化)
]);
}
/**
* 一对一关联用户信息
* @date 2021-03-01
*/
public function userInfo()
{
return $this->hasOne(UserInfo::class, 'user_id', 'user_id')->bind([
'user_nick_name' => 'nick_name', //昵称
'user_head_img' => 'head_img' //头像
]);
}
}