adminModel = new AdminModel(); $this->storeModel = new StoreModel(); $this->productModel = new ProductModel(); $this->orderProductModel = new OrderProductModel(); $this->productCategoryModel = new ProductCategoryModel(); } public function search($text = null) { $admins = $this->adminModel->findAdmins($text)->toArray(); $store_ids = []; foreach ($admins as &$admin) { $admin['store_ids'] = $admin['store_ids'] ? explode(',', $admin['store_ids']) : []; $store_ids = array_unique(array_merge($store_ids, $admin['store_ids'])); } $stores = $this->storeModel->findByIds($store_ids)->toArray(); $fmt_stores = []; foreach ($stores as $store) { $fmt_stores[$store['id']] = $store; } foreach ($admins as &$admin) { $now_stores = array_map(function ($store_id) use ($fmt_stores){ return $fmt_stores[$store_id]; }, $admin['store_ids']); $admin['stores'] = $now_stores; } return $admins; } public function fetchMenus($admin_id) { $admin = $this->adminModel->findById($admin_id); $group = $admin['access']['group']; $fmt_reception_rules = []; foreach (fetchReceptionRules() as $rule) { $fmt_reception_rules[$rule['id']] = $rule; } $reception_rule_ids = $group->reception_rules ? explode(',', $group->reception_rules) : []; return array_map(function ($id) use($fmt_reception_rules) { return $fmt_reception_rules[$id]; },$reception_rule_ids); } public function performance($username, $password, $start_time = null, $end_time = null) { $admin = $this->adminModel->loadByLogin($username, $password); if(!$admin) return $this->fail(lang("Account password error")); $counts = $this->orderProductModel->countByAdviser($admin->id, $start_time, $end_time); $items = [ ['key' => '销售总额', 'value' => fixed2Float($counts[0])], ['key' => '上传命理报告数', 'value' => "{$counts[1]}/{$counts[2]}"], ['key' => '紫薇斗数', 'value' => 0], ['key' => '风水服务', 'value' => 0], ['key' => '商品销售总额', 'value' => fixed2Float($counts[3])], ['key' => '大商品销售总额', 'value' => fixed2Float($counts[4])], ['key' => '服务销售总额', 'value' => fixed2Float($counts[5])] ]; $categorys = $this->productCategoryModel->findAll(); foreach ($categorys as $category) { $value = $this->orderProductModel->countByAdviserProductCategoryIds($admin->id, [$category->id], $start_time, $end_time); if($category->name == '紫薇斗数') { $res[3]['value'] = $value; } else if ($category->name == '风水服务') { $res[4]['value'] = $value; } else { array_push($items, [ 'key' => $category->name, 'value' => $value ]); } } return $this->ok($items); } }