121 lines
4.8 KiB
PHP
121 lines
4.8 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||
// +----------------------------------------------------------------------
|
||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||
// | 开源版本可自由商用,可去除界面版权logo
|
||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||
// | 访问官网:https://www.likeadmin.cn
|
||
// | likeadmin团队 版权所有 拥有最终解释权
|
||
// +----------------------------------------------------------------------
|
||
// | author: likeadminTeam
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\adminapi\lists;
|
||
|
||
|
||
use app\adminapi\lists\BaseAdminDataLists;
|
||
use app\common\model\Goods;
|
||
use app\common\lists\ListsSearchInterface;
|
||
use think\facade\Db;
|
||
|
||
/**
|
||
* Goods列表
|
||
* Class GoodsLists
|
||
* @package app\adminapi\lists
|
||
*/
|
||
class GoodsLists extends BaseAdminDataLists implements ListsSearchInterface
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 设置搜索条件
|
||
* @return \string[][]
|
||
* @author likeadmin
|
||
* @date 2025/05/08 15:34
|
||
*/
|
||
public function setSearch(): array
|
||
{
|
||
return [
|
||
'=' => ['name', 'code', 'first_category_id', 'second_category_id', 'third_category_id', 'brand_id', 'supplier_id', 'status', 'image', 'video', 'poster', 'remark', 'content', 'sort', 'sales_sum', 'virtual_sales_sum', 'click_count', 'virtual_click', 'spec_type', 'max_price', 'min_price', 'market_price', 'stock', 'stock_warn', 'is_show_stock', 'free_shipping_type', 'free_shipping', 'free_shipping_template_id', 'is_commission', 'first_ratio', 'second_ratio', 'three_ratio', 'is_share_bouns', 'region_ratio', 'shareholder_ratio', 'is_new', 'is_best', 'is_like', 'is_team', 'is_integral', 'is_member', 'give_integral_type', 'give_integral', 'del', 'is_express', 'is_selffetch'],
|
||
];
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取列表
|
||
* @return array
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\DbException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
* @author likeadmin
|
||
* @date 2025/05/08 15:34
|
||
*/
|
||
public function lists(): array
|
||
{
|
||
$data = Goods::where($this->searchWhere)
|
||
->field(['id', 'name', 'code', 'first_category_id', 'second_category_id',
|
||
'third_category_id', 'brand_id', 'supplier_id', 'status', 'image',
|
||
'video', 'poster', 'remark', 'content', 'sort',
|
||
'sales_sum', 'virtual_sales_sum', 'click_count',
|
||
'virtual_click', 'spec_type', 'max_price', 'min_price',
|
||
'market_price', 'stock', 'stock_warn', 'is_show_stock',
|
||
'free_shipping_type', 'free_shipping', 'free_shipping_template_id',
|
||
'is_commission', 'first_ratio', 'second_ratio', 'three_ratio',
|
||
'is_share_bouns', 'region_ratio', 'shareholder_ratio', 'is_new',
|
||
'is_best', 'is_like', 'is_team', 'is_integral', 'is_member',
|
||
'give_integral_type', 'give_integral', 'del', 'is_express',
|
||
'is_selffetch','cat_name','price','total_sales_sum'])
|
||
->limit($this->limitOffset, $this->limitLength)
|
||
->order(['id' => 'desc'])
|
||
->select()
|
||
->toArray();
|
||
$goods_category_list = Db::name('goods_category')->where(['del'=>0])->column('name','id');
|
||
foreach($data as &$item){
|
||
$item['cat_name'] = self::getCateName($goods_category_list, $item);
|
||
$item['price'] = '¥'.$item['min_price'];
|
||
if($item['spec_type'] == 2 && $item['max_price'] !== $item['min_price']){
|
||
$item['price'] = '¥'.$item['min_price'].'~'.'¥'.$item['max_price'];
|
||
}
|
||
$r = Db::name('goods_image')
|
||
->where(['goods_id'=>$item['id']])
|
||
->select()
|
||
->toArray();
|
||
$arr = array();
|
||
foreach($r as $key=>$value){
|
||
$arr[] = $value['url'];
|
||
}
|
||
$item['goods_image'] = $arr;
|
||
}
|
||
return $data;
|
||
}
|
||
public static function getCateName($cates, $item)
|
||
{
|
||
if(isset($cates[$item['third_category_id']])) {
|
||
return $cates[$item['third_category_id']];
|
||
}
|
||
|
||
if(isset($cates[$item['second_category_id']])) {
|
||
return $cates[$item['second_category_id']];
|
||
}
|
||
|
||
if(isset($cates[$item['first_category_id']])) {
|
||
return $cates[$item['first_category_id']];
|
||
}
|
||
|
||
return '';
|
||
}
|
||
|
||
/**
|
||
* @notes 获取数量
|
||
* @return int
|
||
* @author likeadmin
|
||
* @date 2025/05/08 15:34
|
||
*/
|
||
public function count(): int
|
||
{
|
||
return Goods::where($this->searchWhere)->count();
|
||
}
|
||
|
||
} |