Browse Source

规格展示

zhanglinxin 1 year ago
parent
commit
44d14c0b07

+ 0 - 12
application/approve/controller/ApproveInfo.php

@@ -18,7 +18,6 @@ namespace app\approve\controller;
 use app\common\constant\CommonConstant;
 use app\common\constant\OfferConstant;
 use app\common\service\CommonService;
-use app\common\service\UserService;
 use app\common\model\ApproveInfo as model;
 use library\Controller;
 
@@ -143,17 +142,6 @@ class ApproveInfo extends Controller
         }
     }
 
-    /**
-     * 列表数据处理
-     * @param array $data
-     * @throws \Exception
-     */
-    protected function _index_page_filter(&$data)
-    {
-        foreach ($data as &$value) {
-
-        }
-    }
 
     /**
      * 编辑

+ 43 - 13
application/approve/controller/Goods.php

@@ -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;
         }
     }
 

+ 6 - 0
application/approve/view/goods/index.html

@@ -26,6 +26,7 @@
             <th class='text-left nowrap'>商品编号</th>
             <th class='text-left nowrap'>商品名称</th>
             <th class='text-left nowrap'>商品品牌</th>
+            <th class='text-left nowrap'>商品规格</th>
             <th class='text-left nowrap'>权重</th>
             <th class='text-left nowrap'>状态</th>
             <th class='text-left nowrap'>创建时间</th>
@@ -43,6 +44,11 @@
             <td class='text-left nowrap'>{$vo.goods_no|default='--'}</td>
             <td class='text-left nowrap'>{$vo.goods_name|default='--'}</td>
             <td class='text-left nowrap'>{$vo.goods_brand|default='--'}</td>
+            <td class='text-left nowrap'>
+                {foreach $vo.goods_stock as $k=>$v}
+                <p><span class="color-desc">{$v.name}</span><span>库存:{$v.stock}</span></p>
+                {/foreach}
+            </td>
             <td class='list-table-sort-td'>
                 <input data-action-blur="{:request()->url()}" data-value="id#{$vo.id};action#sort;sort#{value}" data-loading="false" value="{$vo.sort}" class="list-sort-input">
             </td>