Pārlūkot izejas kodu

普通調整代碼

joe 4 gadi atpakaļ
vecāks
revīzija
96c4d8f04a

+ 3 - 3
app/admin/controller/Index.php

@@ -7,7 +7,7 @@ use think\facade\Config;
 use app\admin\model\order\StoreOrder as StoreOrderModel;//订单
 use app\admin\model\system\{SystemConfig, SystemMenus, SystemRole};
 use app\admin\model\user\{User, UserExtract as UserExtractModel, User as UserModel};
-use app\admin\model\store\{StoreProduct, StoreProductReply as StoreProductReplyModel, StoreProduct as ProductModel};
+use app\admin\model\store\{StoreProduct, StoreProductReply as StoreProductReplyModel};
 
 /**
  * 首页控制器
@@ -56,7 +56,7 @@ class Index extends AuthController
             ->count();
         //库存预警
         $replenishment_num = sys_config('store_stock') > 0 ? sys_config('store_stock') : 20;//库存预警界限
-        $topData['stockProduct'] = StoreProduct::where('stock', '<=', $replenishment_num)->where('is_show', 1)->where('is_del', 0)->count();
+        $topData['stockProduct'] = StoreProduct::getProductNumStockLessThan($replenishment_num);
         //待处理提现
         $topData['treatedExtract'] = UserExtractModel::where('status', 0)->count();
 
@@ -589,7 +589,7 @@ class Index extends AuthController
         $data = [];
         $data['ordernum'] = StoreOrderModel::statusByWhere(1)->count();//待发货
         $replenishment_num = sys_config('store_stock') > 0 ? sys_config('store_stock') : 2;//库存预警界限
-        $data['inventory'] = ProductModel::where('stock', '<=', $replenishment_num)->where('is_show', 1)->where('is_del', 0)->count();//库存
+        $data['inventory'] = StoreProduct::getProductNumStockLessThan($replenishment_num);//库存
         $data['commentnum'] = StoreProductReplyModel::where('is_reply', 0)->count();//评论
         $data['reflectnum'] = UserExtractModel::where('status', 0)->count();;//提现
         $data['msgcount'] = intval($data['ordernum']) + intval($data['inventory']) + intval($data['commentnum']) + intval($data['reflectnum']);

+ 9 - 1
app/admin/model/store/StoreProduct.php

@@ -474,7 +474,7 @@ class StoreProduct extends BaseModel
     /**
      * 设置查询条件
      * @param array $where
-     * @return array
+     * @return object
      */
     public static function setWhere($where)
     {
@@ -698,4 +698,12 @@ class StoreProduct extends BaseModel
         return self::alias('p')->join('store_product_provider s', 'p.provider_id=s.id')
             ->where('p.id', $id)->field('p.store_name, p.sources, s.*')->find();
     }
+
+    /**
+     * 获取库存低于 @stock 的商品数量
+     */
+    public static function getProductNumStockLessThan(int $stock) : int
+    {
+        return self::where('stock', '<=', $stock)->where('is_show', 1)->where('is_del', 0)->count();
+    }
 }

+ 48 - 0
crmeb/subscribes/ProductSubscribe.php

@@ -52,4 +52,52 @@ class ProductSubscribe
         //$relationType 操作类型   like  点赞  collect 收藏
         //$uid 用户编号
     }
+
+    /**
+     * 添加产品
+     */
+    public function onStoreProductCreated($event)
+    {
+
+    }
+
+    /**
+     * 删除产品
+     */
+    public function onStoreProductDeleted($event)
+    {
+
+    }
+
+    /**
+     * 上下架产品
+     */
+    public function onStoreProductOnOffShelf($event)
+    {
+
+    }
+
+    /**
+     * 增加分类
+     */
+    public function onStoreCategoryCreated($event)
+    {
+
+    }
+
+    /**
+     * 删除分类
+     */
+    public function onStoreCategoryDeleted($event)
+    {
+
+    }
+
+    /**
+     * 编辑分类
+     */
+    public function onStoreCategoryEdited($event)
+    {
+
+    }
 }

+ 1 - 1
crmeb/traits/ModelTrait.php

@@ -222,7 +222,7 @@ trait ModelTrait
      * 获取时间段之间的model
      * @param int|string $time
      * @param string $ceil
-     * @return array
+     * @return object
      */
     public static function getModelTime($where, $model = null, $prefix = 'add_time', $data = 'data', $field = ' - ')
     {