WorkbenchLogic.php 13 KB

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