WorkbenchLogic.php 12 KB

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