| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- namespace app\api\service;
- use app\admin\controller\AuthGroup;
- use app\common\model\AdminModel;
- use app\common\model\OrderProductModel;
- use app\common\model\ProductCategoryModel;
- use app\common\model\ProductModel;
- use app\common\model\StoreModel;
- class AdminService extends \app\BaseService
- {
- private $adminModel;
- private $storeModel;
- private $productModel;
- private $orderProductModel;
- private $productCategoryModel;
- public function __construct()
- {
- $this->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);
- }
- }
|