WorkbenchLogic.php 7.7 KB

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