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.

55 lines
1.5 KiB

<?php
namespace app\mall\model;
use think\model\concern\SoftDelete;
class MallCollect extends Base
{
use SoftDelete;
/**
* 查找全部数据
* @date 2022-12-01
*/
public function listAllCollect($where = [], $where_mall_product = [], $field = '*', $order = '')
{
// 默认排序
if (empty($order)) {
$order = 'id desc';
}
return $this->with(['mallProduct'])
->hasWhere('mallProduct', $where_mall_product, $field)
->where($where)->order($order)->select()->each(function ($item, $key) {
if ($item['product_is_publish'] == 0 || !empty($item['product_delete_time'])) {
// 是否有效 0--失效 1--有效
$item['is_effective'] = 0;
} else {
$item['is_effective'] = 1;
}
unset($item['mallProduct']);
unset($item['product_delete_time']);
unset($item['product_is_publish']);
});
}
/**
* 一对一关联产品
* @date 2022-12-01
*/
public function mallProduct()
{
return $this->hasOne('mallProduct', 'id', 'product_id')->removeOption('soft_delete')->bind([
'product_name' => 'name',
'product_cover_img' => 'cover_img',
'product_price' => 'price_min',
'product_is_publish' => 'is_publish',
'product_delete_time' => 'delete_time',
]);
}
}