WorkbenchLogic.php 11 KB

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