WorkbenchLogic.php 8.2 KB

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