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.

90 lines
2.3 KiB

<?php
namespace app\mall\model;
use think\model\concern\SoftDelete;
class MallBrowse extends Base
{
use SoftDelete;
public function getBrowseDateTextAttr($value, $data)
{
return date('m月d日', $data['browse_date']);
}
/**
* 更新浏览记录
* @date 2021-03-01
*/
public function updateBrowse($data)
{
$where = [
['uid', '=', $data['uid']],
['user_id', '=', $data['user_id']],
['product_id', '=', $data['product_id']],
['browse_date', '=', $data['browse_date']],
];
$id = $this->getOneData($where, 'id');
if (!empty($id)) {
$data['id'] = $id;
}
return $this->dataUpdate($data);
}
/**
* 获取我的浏览列表(带分页)
* @date 2022-11-30
*/
public function listMyBrowseWithPage($where, $page, $field = '*', $order = '', $per_page_number = 10)
{
// 默认排序
if (empty($order)) {
$order = 'id desc';
}
//
$dataList = $this->with(['mallProduct'])->field($field)->where($where)->order($order)
->paginate(['list_rows' => $per_page_number, 'page' => $page], false)->each(function ($item) {
$item['browse_date_text'] = $item->browse_date_text;
unset($item['mallProduct']);
});
return $dataList;
}
/**
* 远程一对多关联产品
* @date 2021-03-01
*/
// public function mallProduct()
// {
// //MallProductAttach.product_id = mallProduct.id MallAttach.id = MallProductAttach.attach_id
// return $this->hasManyThrough('MallProduct', 'MallBrowse', 'browse_date', 'browse_date', 'id', 'product_id');
// }
/**
* 当天浏览记录
* @date 2021-03-01
*/
// public function mallBrowse()
// {
// return $this->hasMany('MallBrowse', 'browse_date', 'browse_date');
// }
/**
* 一对一关联产品
* @date 2021-03-01
*/
public function mallProduct()
{
return $this->hasOne('MallProduct', 'id', 'product_id')->bind([
'product_name' => 'name',
'product_price' => 'price_min',
'product_cover_img' => 'cover_img'
])->removeOption('soft_delete');
}
}