Explorar el Código

Merge branch 'master' of http://git.dongerkj.com:9095/waibao/NN2022060401

49107199@qq.com hace 3 años
padre
commit
3da8daa60b

+ 1 - 0
app/api/model/Imchat.php

@@ -63,6 +63,7 @@ class Imchat extends ImchatModel
                 ->field($this->name.".*")
                 ->group($this->name.'.chat_key')
                 ->order($this->name.'.sendtime','desc')
+                ->order($this->name.'.is_push desc,'.$this->name.'.sendtime','desc')
                 ->paginate($listRows);
 
         return $this->setListDataFromApi($list, $param);

+ 19 - 0
app/api/model/SpecialityBook.php

@@ -126,4 +126,23 @@ class SpecialityBook extends SpecialityBookModel
         $status = $status == 1? 1 : 3;
         return (int)self::where($where)->where('status','>=', $status)->count('order_id');
     }
+
+    /**
+     * 统计今日新增报名数
+     * @param int $status 状态:1-包含待支付,2-已支付
+     * @param  $schoolId
+     * @return int
+     */
+    public static function getBooksByToday(int $status = 3, $schoolId=0)
+    {
+        $status = $status == 1? 1 : 3;
+        return (int)self::where('status','>=', $status)
+            ->where(function($query) use($schoolId){
+                if($schoolId>0){
+                    $query->where('school_id', $schoolId);
+                }
+            })
+            ->where('create_time','>=', strtotime(date('Y-m-d')))
+            ->count('order_id');
+    }
 }

+ 11 - 0
app/common/model/UserDynamic.php

@@ -270,4 +270,15 @@ class UserDynamic extends BaseModel
         }
        return static::get($filter, $with);
     }
+
+    /**
+     * 今日新增数量
+     * @return int
+     */
+    public static function getTodayCounts()
+    {
+        return self::where(['status'=> 1])
+            ->where('create_time','>=', strtotime(date('Y-m-d')))
+            ->count('id');
+    }
 }

+ 2 - 0
app/common/model/store/User.php

@@ -69,4 +69,6 @@ class User extends BaseModel
     {
         return static::get($where, $with);
     }
+
+
 }

+ 6 - 0
app/common/service/store/User.php

@@ -58,6 +58,9 @@ class User extends BaseService
         Cache::set($token, [
             'user' => $userInfo,
             'store_id' => $userInfo['store_id'],
+            'school_id' => $userInfo['school_id'],
+            'parent_id' => $userInfo['parent_id'],
+            'user_type' => $userInfo['user_type'],
             'is_login' => true,
         ], 86400 * 7);
         return $token;
@@ -83,6 +86,9 @@ class User extends BaseService
         return Cache::set(self::getToken(), [
             'user' => $userInfo,
             'store_id' => $userInfo['store_id'],
+            'school_id' => $userInfo['school_id'],
+            'parent_id' => $userInfo['parent_id'],
+            'user_type' => $userInfo['user_type'],
             'is_login' => true,
         ], 86400 * 7);
     }

+ 4 - 0
app/store/controller/Controller.php

@@ -31,6 +31,9 @@ class Controller extends BaseController
     // 当前商城ID
     protected $storeId;
 
+    // 管理绑定的学校ID
+    protected $schoolId;
+
     // 当前控制器名称
     protected $controller = '';
 
@@ -85,6 +88,7 @@ class Controller extends BaseController
     private function setStoreInfo()
     {
         $this->store = StoreUserService::getLoginInfo();
+        $this->schoolId = isset($this->store['school_id'])? intval($this->store['school_id']) : 0;
     }
 
     /**

+ 1 - 1
app/store/controller/Home.php

@@ -29,7 +29,7 @@ class Home extends Controller
     {
         // 获取首页数据
         $model = new HomeService;
-        $data =  $model->getData();
+        $data =  $model->getData($this->schoolId);
         return $this->renderSuccess(compact('data'));
     }
 

+ 30 - 0
app/store/model/User.php

@@ -264,4 +264,34 @@ class User extends UserModel
         return $this->setDec(['user_id' => $userId], 'expend_money', $expendMoney);
     }
 
+    /**
+     * 统计数据
+     * @param $userType
+     * @return mixed
+     */
+    public static function getCounts($userType)
+    {
+        return self::alias('a')
+            ->leftJoin('user_info ui','ui.user_id=a.user_id')
+            ->where(['a.user_type'=> $userType, 'a.is_delete'=>0,'a.status'=>1,'ui.status'=>1])
+            ->count('a.user_id');
+    }
+
+    /**
+     * 今日新增用户数
+     * @param $userType
+     * @return mixed
+     */
+    public static function getTodayCounts($userType)
+    {
+        $where = ['a.is_delete'=>0,'a.status'=>1,'ui.status'=>1];
+        if($userType>0){
+            $where['a.user_type'] = $userType;
+        }
+        return self::alias('a')
+            ->leftJoin('user_info ui','ui.user_id=a.user_id')
+            ->where($where)
+            ->where('a.create_time','>=', strtotime(date('Y-m-d')))
+            ->count('a.user_id');
+    }
 }

+ 17 - 3
app/store/model/store/User.php

@@ -8,7 +8,7 @@
 // +----------------------------------------------------------------------
 // | Author: thinkphp <admin@yiovo.com>
 // +----------------------------------------------------------------------
-declare (strict_types = 1);
+declare (strict_types=1);
 
 namespace app\store\model\store;
 
@@ -50,11 +50,11 @@ class User extends StoreUserModel
         }
         // 验证商城状态是否正常
         if (empty($userInfo['store']) || $userInfo['store']['is_delete']) {
-            $this->error = '登录失败, 未找到当前商城信息';
+            $this->error = '登录失败, 未找到当前账号信息';
             return false;
         }
         if ($userInfo['store']['is_recycle']) {
-            $this->error = '登录失败, 当前商城已删除';
+            $this->error = '登录失败, 当前账号已删除';
             return false;
         }
         // 记录登录状态, 并记录token
@@ -238,4 +238,18 @@ class User extends StoreUserModel
         return true;
     }
 
+    /**
+     * @param int $userType
+     * @param $schoolId
+     * @return int
+     */
+    public static function getCounts(int $userType, $schoolId = 0)
+    {
+        $where = ['user_type' => $userType, 'is_delete' => 0, 'store_id' => getStoreId()];
+        if ($schoolId > 0) {
+            $where['school_id'] = $schoolId;
+        }
+        return self::where($where)
+            ->count('store_user_id');
+    }
 }

+ 21 - 52
app/store/service/Home.php

@@ -16,8 +16,10 @@ use app\api\model\School;
 use app\api\model\SchoolSpeciality;
 use app\api\model\SpecialityBook;
 use app\common\library\helper;
+use app\common\model\UserDynamic;
 use app\common\service\BaseService;
 use app\store\model\User as UserModel;
+use app\store\model\store\User as StoreUserModel;
 use app\store\model\Goods as GoodsModel;
 use app\store\model\Order as OrderModel;
 use app\store\model\OrderRefund as OrderRefundModel;
@@ -36,8 +38,9 @@ class Home extends BaseService
     /* @var OrderModel $GoodsModel */
     private $OrderModel;
 
-    /* @var UserModel $GoodsModel */
+    /* @var UserModel $GoodsModel $StoreUserModel */
     private $UserModel;
+    private $StoreUserModel;
 
     /**
      * 构造方法
@@ -49,13 +52,14 @@ class Home extends BaseService
         $this->GoodsModel = new GoodsModel;
         $this->OrderModel = new OrderModel;
         $this->UserModel = new UserModel;
+        $this->StoreUserModel = new StoreUserModel;
     }
 
     /**
      * 后台首页数据
      * @return array
      */
-    public function getData(): array
+    public function getData($schoolId=0): array
     {
         // 今天的日期
         $today = date('Y-m-d');
@@ -65,6 +69,7 @@ class Home extends BaseService
         $lately7days = $this->getLately7days();
 
         $type = $this->request->param('type', 1);
+        $type = $this->request->param('type', 1);
         if($type == 1){
             $ranks = $this->getSchoolViewsRank(10);
         }else if($type == 2){
@@ -74,50 +79,23 @@ class Home extends BaseService
         }
 
         $data = [
-            // 实时概况
-            'overview' => [
-                // 销售额(元)
-                'orderTotalPrice' => [
-                    'tday' => $this->getOrderTotalPrice($today),
-                    'ytd' => $this->getOrderTotalPrice($yesterday)
-                ],
-                // 支付订单数
-                'orderTotal' => [
-                    'tday' => $this->getPayOrderTotal($today),
-                    'ytd' => $this->getPayOrderTotal($yesterday)
-                ],
-                // 新增会员数
-                'newUserTotal' => [
-                    'tday' => $this->getUserTotal($today),
-                    'ytd' => $this->getUserTotal($yesterday)
-                ],
-                // 付款会员数
-                'consumeUserTotal' => [
-                    'tday' => $this->getPayOrderUserTotal($today),
-                    'ytd' => $this->getPayOrderUserTotal($yesterday)
-                ]
-            ],
             // 数据统计
             'statistics' => [
-                // 商品总数量
-                'goodsTotal' => $this->getGoodsTotal(),
-                // 会员总人数
-                'userTotal' => $this->getUserTotal(),
-                // 付款订单总量
-                'orderTotal' => $this->getPayOrderTotal(),
-                // 消费总人
-                'consumeUserTotal' => $this->getUserTotal(null, true)
+                // 学校总数量
+                'schoolTotal' => School::getTotal(),
+                // 学生总人数
+                'userTotal' => UserModel::getCounts(1),
+                // 招生老师总数
+                'teacherTotal' => UserModel::getCounts(3),
+                // 代理总数
+                'agentTotal' => $this->StoreUserModel::getCounts(3, $schoolId),
             ],
-            // 待办事项
-            'pending' => [
-                // 待发货订单
-                'deliverOrderTotal' => $this->getNotDeliveredOrderTotal(),
-                // 待处理售后单
-                'refundTotal' => $this->getRefundTotal(),
-                // 待付款订单(笔)
-                'paidOrderTotal' => $this->getNotPayOrderTotal(),
-                // 已售罄商品数量
-                'soldoutGoodsTotal' => $this->getSoldoutGoodsTotal()
+            // 今日统计
+            'todays' => [
+                'users'=> UserModel::getTodayCounts(0),
+                'teacher'=> UserModel::getTodayCounts(3),
+                'book'=> SpecialityBook::getBooksByToday(3, $schoolId),  // 成交的报名数量
+                'dynamic'=> UserDynamic::getTodayCounts(),
             ],
             // 交易走势
             'tradeTrend' => [
@@ -266,15 +244,6 @@ class Home extends BaseService
     }
 
     /**
-     * 获取商品总量
-     * @return string
-     */
-    private function getGoodsTotal()
-    {
-        return number_format($this->GoodsModel->getGoodsTotal());
-    }
-
-    /**
      * 会员总人数
      * @param string $date 注册日期
      * @param true $isConsume 是否已消费