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.
yanzong/app/admin/controller/Goods.php

85 lines
2.8 KiB

<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\admin\controller;
use think\response\Json;
use think\facade\Db;
/**
* 商城管理
* Class Store
* @package app\admin\controller
*/
class Goods extends Controller
{
/**
* 强制验证当前访问的控制器方法method
* @var array
*/
protected array $methodRules = [
'index' => 'GET',
'recycle' => 'GET',
'add' => 'POST',
'move' => 'POST',
'delete' => 'POST',
];
/**
* 商城列表
* @return Json
* @throws \think\db\exception\DbException
*/
public function index(): Json
{
10 months ago
$params = $this->request->param();
$sort = $this->request->param('sort', 'id');
$order = $this->request->param('order', 'desc');
$where = [];
if (isset($params['channel']) && $params['channel']) {
$where[] = ['channel', '=', $params['channel']];
}
10 months ago
if (isset($params['min_profit_rate']) && $params['min_profit_rate']) {
$where[] = ['profit_rate', '>=', $params['min_profit_rate']];
}
10 months ago
if (isset($params['max_profit_rate']) && $params['max_profit_rate']) {
$where[] = ['profit_rate', '<=', $params['max_profit_rate']];
}
10 months ago
if (isset($params['min_price']) && $params['min_price']) {
$where[] = ['net_price', '>=', $params['min_price']];
}
10 months ago
if (isset($params['max_price']) && $params['max_price']) {
$where[] = ['net_price', '<=', $params['max_price']];
}
10 months ago
$list = Db::connect("dataCenterMysql")->table('goods_sku')
->where($where)
->order($sort." ".$order)
->paginate($this->request->param('per_page', 15))->each(function ($item, $key){
10 months ago
$item['create_time'] = date("Y-m-d H:i:s", $item['create_time']);
$item['update_time'] = date("Y-m-d H:i:s", $item['update_time']);
$item['channel'] = config('app.platformList')[$item['channel']] ?? "";
10 months ago
return $item;
});
return $this->renderSuccess(compact('list'));
}
10 months ago
}