ProductModel = new Product(); $this->OrderModel = new Order(); $this->UserModel = new User(); $this->OrderRefund = new OrderRefund(); $this->StoreModel = new Store(); $this->AgentModel = new Agent(); $this->ClientModel = new Client(); } /** * 后台首页数据 */ public function getHomeData($username) { $agent_id= (new AgentUser())//获取当前登录的代理商id ->where('user_name', '=', $username[0]) ->where('is_delete', '=', 0)->find(); $today = date('Y-m-d'); $yesterday = date('Y-m-d', strtotime('-1 day')); // 最近七天日期 $lately7days = $this->getLately7days(); $data = [ 'top_data' => [ // 客户总量 'product_total' => $this->getClinetTotal($agent_id['agent_id']), // 代理商总量 'order_total' => $this->getAgentTotal($agent_id['agent_id']), // 门店总量 'user_total' => $this->getStoreTotal($agent_id['agent_id']), // 账户余额 'supplier_total' => $this->getBalanceTotal($agent_id['agent_id']), // // 订单总量 // 'order_total' => $this->getOrderTotal(), // // 用户总量 // 'user_total' => $this->getUserTotal(), // // 店铺总量 // 'supplier_total' => $this->getSupplierTotal() ], 'wait_data' => [ //订单 'order' => [ 'disposal' => $this->getReviewOrderTotal(), 'refund' => $this->getRefundOrderTotal(), 'plate' => $this->getPlateOrderTotal(), ], // //分销商 // 'agent' => [ // 'cash_apply' => $this->getAgentApplyTotal(10), // 'apply' => AgentApplyModel::getApplyCount(), // 'cash_money' => $this->getAgentApplyTotal(20), // ], // //供应商 // 'supplier' => [ // 'apply' => SupplierApplyModel::getApplyCount(), // 'cash_apply' => SupplierCashModel::getApplyCount(10), // 'cash_money' => SupplierCashModel::getApplyCount(20), // 'refund' => DepositRefundModel::getRefundCount(), // 'service' => ServiceApplyModel::getApplyCount(), // ], // //活动 // 'activity' => [ // 'point' => PointProductModel::getApplyCount(), // 'bargain' => BargainProductModel::getApplyCount(), // 'assemble' => AssembleProductModel::getApplyCount(), // 'seckill' => SeckillProductModel::getApplyCount(), // ], // // 待审核 // 'audit' => [ // 'comment' => $this->getReviewCommentTotal(), // 'product' => $this->ProductModel->getProductTotal([ // 'product_status' => '40' // ]), // ] ], 'today_data' => [ // 销售额(元)-->余额变动 'order_total_price' => $this->getBalanceByDay($agent_id['agent_id']), // 支付订单数 'order_total' => [ 'tday' => $this->getOrderTotal($today), 'ytd' => $this->getOrderTotal($yesterday) ], // 新增门店数 'new_user_total' => [ 'tday' => $this->getStoreTotal($agent_id['agent_id'],$today), 'ytd' => $this->getStoreTotal($agent_id['agent_id'],$yesterday) ], // 新供应商数-->新增客户 'new_supplier_total' => $this->getClinetByDay($agent_id['agent_id']), // 申请供应商数--客户申请 'apply_supplier_total' => [ 'tday' => SupplierApplyModel::getApplyCountByDay($today), 'ytd' => SupplierApplyModel::getApplyCountByDay($yesterday) ] ], ]; return $data; } //获取代理商余额 private function getBalanceTotal($id){ return number_format($this->AgentModel->getBalanceTotal($id)); } //获取下级代理商总数 private function getAgentTotal($id) { return number_format($this->AgentModel->getAgentTotal($id)); } //获取代理商下的客户总数 private function getClinetTotal($id) { return number_format($this->ClientModel->getClinetTotal($id)); } //获取代理商下的 客户 今日昨日 private function getClinetByDay($id) { return $this->ClientModel->getClinetByDay($id); } //获取余额变动 private function getBalanceByDay($id) { return $this->AgentModel->getBalanceByDay($id); } /** * 最近七天日期 */ private function getLately7days() { // 获取当前周几 $date = []; for ($i = 0; $i < 7; $i++) { $date[] = date('Y-m-d', strtotime('-' . $i . ' days')); } return array_reverse($date); } /** * 获取商品总量 */ private function getProductTotal() { return number_format($this->ProductModel->getProductTotal()); } /** * 获取待审核提现总数量 */ private function getAgentApplyTotal($apply_status) { $model = new AgentCashModel; return number_format($model->getAgentApplyTotal($apply_status)); } /** * 获取门店总量 */ private function getStoreTotal($agent_id,$day = null) { return number_format($this->StoreModel->getStoreTotal($agent_id,$day)); } /** * 获取订单总量 */ private function getOrderTotal($day = null) { return number_format($this->OrderModel->getOrderData($day, null, 'order_total')); } /** * 获取待处理订单总量 */ private function getReviewOrderTotal() { return number_format($this->OrderModel->getReviewOrderTotal()); } /** * 获取售后订单总量 */ private function getRefundOrderTotal() { return number_format($this->OrderRefund->getRefundOrderTotal()); } /** * 获取平台售后订单总量 */ private function getPlateOrderTotal() { return number_format($this->OrderRefund->getPlateOrderTotal()); } /** * 获取供应商总量 */ private function getSupplierTotal() { $model = new SupplierModel; return number_format($model->getSupplierTotal()); } /** * 获取待审核评价总量 */ private function getReviewCommentTotal() { $model = new Comment; return number_format($model->getReviewCommentTotal()); } /** * 获取某天的总销售额 */ private function getOrderTotalPrice($day) { return sprintf('%.2f', $this->OrderModel->getOrderTotalPrice($day)); } }