|
@@ -16,7 +16,7 @@
|
|
|
namespace app\approve\controller;
|
|
|
|
|
|
use app\common\constant\CommonConstant;
|
|
|
-use app\common\constant\MaintainConstant;
|
|
|
+use app\common\model\Goods as model;
|
|
|
use library\Controller;
|
|
|
|
|
|
/**
|
|
@@ -50,28 +50,58 @@ class Goods extends Controller
|
|
|
public function index()
|
|
|
{
|
|
|
$status = input('status');
|
|
|
+ $goods_name = input('goods_name');
|
|
|
|
|
|
$this->title = '商品列表';
|
|
|
- $query = $this->_query($this->table)
|
|
|
- ->field('is_deleted', true)
|
|
|
+ $data = model::field('is_deleted', true)
|
|
|
->where('is_deleted', CommonConstant::IS_DELETED_0)
|
|
|
->when(array_key_exists($status, $this->get_status_list), function ($query) use ($status) {
|
|
|
$query->where('status', $status);
|
|
|
})
|
|
|
- ->like('goods_name')
|
|
|
+ ->when($goods_name,function ($query) use($goods_name){
|
|
|
+ $query->where('goods_name','like','%'.$goods_name.'%');
|
|
|
+ })
|
|
|
+ ->with(['goodsStock'])
|
|
|
->order('sort desc,id asc');
|
|
|
- $query->page();
|
|
|
+ self::init($data);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 列表数据处理
|
|
|
- * @param array $data
|
|
|
- * @throws \Exception
|
|
|
- */
|
|
|
- protected function _index_page_filter(&$data)
|
|
|
+ public function init($data, $page = true, $display = true, $total = false, $limit = 0)
|
|
|
{
|
|
|
- foreach ($data as &$value) {
|
|
|
-
|
|
|
+ $this->page = $page;
|
|
|
+ $this->total = $total;
|
|
|
+ $this->limit = $limit;
|
|
|
+ $this->display = $display;
|
|
|
+ $this->query = $data;
|
|
|
+ // 列表分页及结果集处理
|
|
|
+ if ($this->page) {
|
|
|
+ // 分页每页显示记录数
|
|
|
+ $limit = intval($this->request->get('limit', cookie('page-limit')));
|
|
|
+ cookie('page-limit', $limit = $limit >= 10 ? $limit : 20);
|
|
|
+ if ($this->limit > 0) $limit = $this->limit;
|
|
|
+ $rows = [];
|
|
|
+ $page = $data->paginate($limit, $this->total, ['query' => ($query = $this->request->get())]);
|
|
|
+ foreach ([10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200] as $num) {
|
|
|
+ list($query['limit'], $query['page'], $selected) = [$num, '1', $limit === $num ? 'selected' : ''];
|
|
|
+ // 由于加上 / 如做绑定admin模块单独入口 会导致找不到模块 在此去掉 /
|
|
|
+ $url = rtrim(url('@admin'), '/') . '#' . $this->request->baseUrl() . '?' . urldecode(http_build_query($query));
|
|
|
+ array_push($rows, "<option data-num='{$num}' value='{$url}' {$selected}>{$num}</option>");
|
|
|
+ }
|
|
|
+ $selects = "<select onchange='location.href=this.options[this.selectedIndex].value' data-auto-none>" . join('', $rows) . "</select>";
|
|
|
+ $pagetext = lang('think_library_page_html', [$page->total(), $selects, $page->lastPage(), $page->currentPage()]);
|
|
|
+ $pagehtml = "<div class='pagination-container nowrap'><span>{$pagetext}</span>{$page->render()}</div>";
|
|
|
+ $pagehtml = preg_replace('|href="(.*?)"|', 'data-open="$1" onclick="return false" href="$1"', $pagehtml);
|
|
|
+ // 由于部分自动生成的分页是href是带单引号的
|
|
|
+ $pagehtml = preg_replace("|href='(.*?)'|", 'data-open="$1" onclick="return false" href="$1"', $pagehtml);
|
|
|
+ $this->assign('pagehtml', $pagehtml);
|
|
|
+ $result = ['page' => ['limit' => intval($limit), 'total' => intval($page->total()), 'pages' => intval($page->lastPage()), 'current' => intval($page->currentPage())], 'list' => $page->items()];
|
|
|
+ } else {
|
|
|
+ $result = ['list' => $data->select()];
|
|
|
+ }
|
|
|
+ if ($this->display) {
|
|
|
+ return $this->fetch('', $result);
|
|
|
+ } else {
|
|
|
+ return $result;
|
|
|
}
|
|
|
}
|
|
|
|