AdminService.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. namespace app\api\service;
  3. use app\admin\controller\AuthGroup;
  4. use app\common\model\AdminModel;
  5. use app\common\model\OrderProductModel;
  6. use app\common\model\ProductCategoryModel;
  7. use app\common\model\ProductModel;
  8. use app\common\model\StoreModel;
  9. class AdminService extends \app\BaseService
  10. {
  11. private $adminModel;
  12. private $storeModel;
  13. private $productModel;
  14. private $orderProductModel;
  15. private $productCategoryModel;
  16. public function __construct()
  17. {
  18. $this->adminModel = new AdminModel();
  19. $this->storeModel = new StoreModel();
  20. $this->productModel = new ProductModel();
  21. $this->orderProductModel = new OrderProductModel();
  22. $this->productCategoryModel = new ProductCategoryModel();
  23. }
  24. public function search($text = null) {
  25. $admins = $this->adminModel->findAdmins($text)->toArray();
  26. $store_ids = [];
  27. foreach ($admins as &$admin) {
  28. $admin['store_ids'] = $admin['store_ids'] ? explode(',', $admin['store_ids']) : [];
  29. $store_ids = array_unique(array_merge($store_ids, $admin['store_ids']));
  30. }
  31. $stores = $this->storeModel->findByIds($store_ids)->toArray();
  32. $fmt_stores = [];
  33. foreach ($stores as $store) {
  34. $fmt_stores[$store['id']] = $store;
  35. }
  36. foreach ($admins as &$admin) {
  37. $now_stores = array_map(function ($store_id) use ($fmt_stores){
  38. return $fmt_stores[$store_id];
  39. }, $admin['store_ids']);
  40. $admin['stores'] = $now_stores;
  41. }
  42. return $admins;
  43. }
  44. public function fetchMenus($admin_id) {
  45. $admin = $this->adminModel->findById($admin_id);
  46. $group = $admin['access']['group'];
  47. $fmt_reception_rules = [];
  48. foreach (fetchReceptionRules() as $rule) {
  49. $fmt_reception_rules[$rule['id']] = $rule;
  50. }
  51. $reception_rule_ids = $group->reception_rules ? explode(',', $group->reception_rules) : [];
  52. return array_map(function ($id) use($fmt_reception_rules) {
  53. return $fmt_reception_rules[$id];
  54. },$reception_rule_ids);
  55. }
  56. public function performance($username, $password, $start_time = null, $end_time = null) {
  57. $admin = $this->adminModel->loadByLogin($username, $password);
  58. if(!$admin) return $this->fail(lang("Account password error"));
  59. $counts = $this->orderProductModel->countByAdviser($admin->id, $start_time, $end_time);
  60. $res = [
  61. 'total_sales' => fixed2Float($counts[0]),
  62. 'numerology' => "{$counts[1]}/{$counts[2]}",
  63. 'crape_myrtle' => rand(1000,100000),
  64. 'geomancy_serve' => rand(1000,100000),
  65. ];
  66. $items = [
  67. ['key' => '商品销售总额', 'value' => fixed2Float($counts[3])],
  68. ['key' => '大商品销售总额', 'value' => fixed2Float($counts[4])],
  69. ['key' => '服务销售总额', 'value' => fixed2Float($counts[5])],
  70. ];
  71. $categorys = $this->productCategoryModel->findAll();
  72. foreach ($categorys as $category) {
  73. array_push($items, [
  74. 'key' => $category->name,
  75. 'value' => rand(1,999),
  76. ]);
  77. }
  78. $res['items'] = $items;
  79. return $this->ok($res);
  80. }
  81. }