Просмотр исходного кода

收银端商品查询去掉不属于本门店

moonsflyer 8 месяцев назад
Родитель
Сommit
f1fd6ea7b5
3 измененных файлов с 15 добавлено и 8 удалено
  1. 4 3
      addon/stock/storeapi/controller/Manage.php
  2. 9 3
      app/model/Model.php
  3. 2 2
      app/model/goods/Goods.php

+ 4 - 3
addon/stock/storeapi/controller/Manage.php

@@ -60,7 +60,8 @@ class Manage extends BaseStoreApi
         $join = array (
             [ 'goods g', 'g.goods_id = gs.goods_id', 'left' ],
         );
-
+//        $condition[] = [ 'g.sale_store', '%like%', [',11,']];
+//        $condition[] = [ 'g.sale_store', 'like', '%,'.$store_id.',%' ];
         if ($store_id > 0) {
             $join[] = [
                 'store_goods_sku sgs',
@@ -69,9 +70,9 @@ class Manage extends BaseStoreApi
             ];
             $field .= ',sgs.stock, sgs.real_stock';
         }
-
+        $gwhere = "(g.sale_store = 'all' or FIND_IN_SET(".$store_id.",g.sale_store))";
         $goods_model = new \app\model\goods\Goods();
-        $list = $goods_model->getGoodsSkuPageList($condition, $page, $page_size, 'g.create_time desc', $field, 'gs', $join);
+        $list = $goods_model->getGoodsSkuPageList($condition, $page, $page_size, 'g.create_time desc', $field, 'gs', $join,null,$gwhere);
         return $this->response($list);
     }
 

+ 9 - 3
app/model/Model.php

@@ -753,10 +753,16 @@ class Model
      * @param string $group
      * @param string $limit
      */
-    final public function Lists($condition = [], $field = true, $order = '', $page = 1, $list_rows = PAGE_LIST_ROWS, $alias = 'a', $join = [], $group = null, $limit = null)
+    final public function Lists($condition = [], $field = true, $order = '', $page = 1, $list_rows = PAGE_LIST_ROWS, $alias = 'a', $join = [], $group = null, $limit = null,$gwhere='')
     {
-        self::$query_obj = Db::name($this->table)->alias($alias)->where($condition);
-        $count_obj = Db::name($this->table)->alias($alias)->where($condition);
+        if(empty($gwhere)){
+            self::$query_obj = Db::name($this->table)->alias($alias)->where($condition) ;
+            $count_obj = Db::name($this->table)->alias($alias)->where($condition) ;
+        }else{
+            self::$query_obj = Db::name($this->table)->alias($alias)->where($condition)->where($gwhere) ;
+            $count_obj = Db::name($this->table)->alias($alias)->where($condition)->where($gwhere) ;
+        }
+
         if (!empty($join)) {
             $db_obj = self::$query_obj;
             self::$query_obj = $this->parseJoin($db_obj, $join);

+ 2 - 2
app/model/goods/Goods.php

@@ -1107,9 +1107,9 @@ class Goods extends BaseModel
      * @param string $order
      * @param string $field
      */
-    public function getGoodsSkuPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*', $alias = '', $join = '', $group = null)
+    public function getGoodsSkuPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*', $alias = '', $join = '', $group = null ,$gwhere='')
     {
-        $res = model('goods_sku')->Lists($condition, $field, $order, $page, $page_size, $alias, $join, $group);
+        $res = model('goods_sku')->Lists($condition, $field, $order, $page, $page_size, $alias, $join, $group,null,$gwhere);
         foreach ($res[ 'list' ] as $k => $v) {
             if (isset($v[ 'stock' ])) {
                 $res[ 'list' ][ $k ][ 'stock' ] = numberFormat($res[ 'list' ][ $k ][ 'stock' ]);