// +---------------------------------------------------------------------- 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 { $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']]; } if (isset($params['min_profit_rate']) && $params['min_profit_rate']) { $where[] = ['profit_rate', '>=', $params['min_profit_rate']]; } if (isset($params['max_profit_rate']) && $params['max_profit_rate']) { $where[] = ['profit_rate', '<=', $params['max_profit_rate']]; } if (isset($params['min_price']) && $params['min_price']) { $where[] = ['net_price', '>=', $params['min_price']]; } if (isset($params['max_price']) && $params['max_price']) { $where[] = ['net_price', '<=', $params['max_price']]; } $list = Db::connect("dataCenterMysql")->table('goods_sku') ->where($where) ->order($sort." ".$order) ->paginate($this->request->param('per_page', 15))->each(function ($item, $key){ $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']] ?? ""; return $item; }); return $this->renderSuccess(compact('list')); } }