WorkbenchLogic.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\logic;
  15. use app\common\logic\BaseLogic;
  16. use app\common\service\ConfigService;
  17. use app\common\service\FileService;
  18. use app\common\model\asset\AssetInfo;
  19. use function Qiniu\arraySort;
  20. /**
  21. * 工作台
  22. * Class WorkbenchLogic
  23. * @package app\adminapi\logic
  24. */
  25. class WorkbenchLogic extends BaseLogic
  26. {
  27. /**
  28. * @notes 工作套
  29. * @param $adminInfo
  30. * @return array
  31. * @author 段誉
  32. * @date 2021/12/29 15:58
  33. */
  34. public static function index()
  35. {
  36. return [
  37. // 版本信息
  38. 'version' => self::versionInfo(),
  39. // 今日数据
  40. 'today' => self::today(),
  41. // 常用功能
  42. 'menu' => self::menu(),
  43. // 近15日访客数
  44. 'visitor' => self::visitor(),
  45. // 服务支持
  46. 'support' => self::support(),
  47. // 销售数据
  48. 'sale' => self::sale()
  49. ];
  50. }
  51. /**
  52. * @notes 常用功能
  53. * @return array[]
  54. * @author 段誉
  55. * @date 2021/12/29 16:40
  56. */
  57. public static function menu(): array
  58. {
  59. return [
  60. [
  61. 'name' => '管理员',
  62. 'image' => FileService::getFileUrl(config('project.default_image.menu_admin')),
  63. 'url' => '/permission/admin'
  64. ],
  65. [
  66. 'name' => '角色管理',
  67. 'image' => FileService::getFileUrl(config('project.default_image.menu_role')),
  68. 'url' => '/permission/role'
  69. ],
  70. [
  71. 'name' => '部门管理',
  72. 'image' => FileService::getFileUrl(config('project.default_image.menu_dept')),
  73. 'url' => '/organization/department'
  74. ],
  75. [
  76. 'name' => '字典管理',
  77. 'image' => FileService::getFileUrl(config('project.default_image.menu_dict')),
  78. 'url' => '/dev_tools/dict'
  79. ],
  80. [
  81. 'name' => '代码生成器',
  82. 'image' => FileService::getFileUrl(config('project.default_image.menu_generator')),
  83. 'url' => '/dev_tools/code'
  84. ],
  85. [
  86. 'name' => '素材中心',
  87. 'image' => FileService::getFileUrl(config('project.default_image.menu_file')),
  88. 'url' => '/material/index'
  89. ],
  90. [
  91. 'name' => '菜单权限',
  92. 'image' => FileService::getFileUrl(config('project.default_image.menu_auth')),
  93. 'url' => '/permission/menu'
  94. ],
  95. [
  96. 'name' => '网站信息',
  97. 'image' => FileService::getFileUrl(config('project.default_image.menu_web')),
  98. 'url' => '/setting/website/information'
  99. ],
  100. ];
  101. }
  102. /**
  103. * @notes 版本信息
  104. * @return array
  105. * @author 段誉
  106. * @date 2021/12/29 16:08
  107. */
  108. public static function versionInfo(): array
  109. {
  110. return [
  111. 'version' => config('project.version'),
  112. 'website' => config('project.website.url'),
  113. 'name' => ConfigService::get('website', 'name'),
  114. 'based' => 'vue3.x、ElementUI、MySQL',
  115. 'channel' => [
  116. 'website' => 'https://www.likeadmin.cn',
  117. 'gitee' => 'https://gitee.com/likeadmin/likeadmin_php',
  118. ]
  119. ];
  120. }
  121. /**
  122. * @notes 今日数据
  123. * @return int[]
  124. * @author 段誉
  125. * @date 2021/12/29 16:15
  126. */
  127. public static function today(): array
  128. {
  129. return [
  130. 'time' => date('Y-m-d H:i:s'),
  131. // 今日销售额
  132. 'today_sales' => 100,
  133. // 总销售额
  134. 'total_sales' => 1000,
  135. // 今日访问量
  136. 'today_visitor' => 10,
  137. // 总访问量
  138. 'total_visitor' => 100,
  139. // 今日新增用户量
  140. 'today_new_user' => 30,
  141. // 总用户量
  142. 'total_new_user' => 3000,
  143. // 订单量 (笔)
  144. 'order_num' => 12,
  145. // 总订单量
  146. 'order_sum' => 255
  147. ];
  148. }
  149. /**
  150. * @notes 访问数
  151. * @return array
  152. * @author 段誉
  153. * @date 2021/12/29 16:57
  154. */
  155. public static function visitor(): array
  156. {
  157. $num = [];
  158. $date = [];
  159. $j=16;
  160. for ($i = 0; $i < 15; $i++) {
  161. $where_start = strtotime("- " . $i . "day");
  162. $date[] = date('m/d', $where_start);
  163. $search_date[$j] = date('Y-m-d', $where_start);
  164. $j--;
  165. }
  166. array_multisort( $search_date); // 先按年龄排序,再按名字排
  167. foreach($search_date as $k=>$v){
  168. $where = [];
  169. $where[] = ['lease_status','=',3];
  170. $where[] = ['lease_expiration_time','<',$v];
  171. $asset_number = AssetInfo::where($where)->count();
  172. $num[$k] = $asset_number;
  173. }
  174. return [
  175. 'date' => $date,
  176. 'list' => [
  177. ['name' => '访客数', 'data' => $num]
  178. ]
  179. ];
  180. }
  181. /**
  182. * @notes 访问数
  183. * @return array
  184. * @author 段誉
  185. * @date 2021/12/29 16:57
  186. */
  187. public static function sale(): array
  188. {
  189. $num = [];
  190. $date = [];
  191. $j=7;
  192. for ($i = 0; $i < 7; $i++) {
  193. $where_start = strtotime("- " . $i . "day");
  194. $date[] = date('m/d', $where_start);
  195. $search_date[$j] = date('Y-m-d', $where_start);
  196. $j--;
  197. }
  198. array_multisort( $search_date); // 先按年龄排序,再按名字排
  199. foreach($search_date as $k=>$v){
  200. $where = [];
  201. $end_time = strtotime($v.' 23:59:59');
  202. $where[] = ['lease_status','=',2];
  203. $where[] = ['create_time','<',$end_time];
  204. $asset_number = AssetInfo::where($where)->count();
  205. $num[$k] = $asset_number;
  206. }
  207. return [
  208. 'date' => $date,
  209. 'list' => [
  210. ['name' => '销售量', 'data' => $num]
  211. ]
  212. ];
  213. }
  214. /**
  215. * @notes 服务支持
  216. * @return array[]
  217. * @author 段誉
  218. * @date 2022/7/18 11:18
  219. */
  220. public static function support()
  221. {
  222. return [
  223. [
  224. 'image' => FileService::getFileUrl(config('project.default_image.qq_group')),
  225. 'title' => '官方公众号',
  226. 'desc' => '关注官方公众号',
  227. ],
  228. [
  229. 'image' => FileService::getFileUrl(config('project.default_image.customer_service')),
  230. 'title' => '添加企业客服微信',
  231. 'desc' => '想了解更多请添加客服',
  232. ]
  233. ];
  234. }
  235. }