IndexController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. *
  4. * @author Mike <m@9026.com>
  5. * @version 1.0
  6. * @date 2015年10月12日
  7. *
  8. */
  9. namespace App\Http\Controllers\Admin\Base;
  10. use App\Http\Controllers\Admin\Controller;
  11. use App\Models\InnerDevice;
  12. use App\Models\Option;
  13. use App\Models\Order;
  14. use App\Models\Project;
  15. use App\Models\User;
  16. use App\Models\UserAuth;
  17. use App\Services\Base\Tree;
  18. use App\Services\Base\BaseArea;
  19. use App\Services\Admin\Menus;
  20. use App\Services\Admin\Acl;
  21. use Carbon\Carbon;
  22. class IndexController extends Controller
  23. {
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. }
  28. function index() {
  29. if($this->_user['is_root']) {
  30. $obj = new Menus();
  31. $menus = $obj->search(array('level'=>2,'display'=>1),$orderby=array('sort'=>'desc'),$pagesize = 100000);
  32. $menus = $menus->toArray();
  33. $menus = list_to_tree($menus['data']);
  34. }else{
  35. $obj = new Acl();
  36. $data = $obj->getRoleMenu($this->_user['admin_role_id']);
  37. $menus = list_to_tree($data);
  38. }
  39. return view('admin.base.index.index',compact('menus'));
  40. }
  41. function welcome() {
  42. // return redirect('/admin/AdminUser/index');
  43. $total_device = InnerDevice::count();
  44. $total_project = Project::count();
  45. $total_money = Order::sum('money') / 100;
  46. $users_total = User::count();
  47. $users_not_auth_total = UserAuth::where('active', 2)->count();
  48. $users_auth_total = UserAuth::count();
  49. $items = InnerDevice::get();
  50. $types = ['free', 'using', 'repair', 'scrap'];
  51. $device_stat = [];
  52. foreach ($types as $type) {
  53. $id = Option::get('inner_devices', 'status', $type);
  54. $num = $items->where('status', $id)->count();
  55. $device_stat[$type] = $num;
  56. }
  57. $user_auths = UserAuth::where('active', 2)->limit(8)->get();
  58. $min_order = Order::orderBy('created_at', 'desc')->first();
  59. $min_year = $min_order ? $min_order->created_at->year : Carbon::now()->year;
  60. $max_year = Carbon::now()->year;
  61. $year_options = [];
  62. for($i = $min_year; $i <= $max_year; ++$i) {
  63. array_push($year_options, ['id' => $i, 'name' => $i . '年']);
  64. }
  65. $month_options = [['id' => '', 'name' => '所有月份']];
  66. for($i = 1; $i <= 12; ++$i) {
  67. array_push($month_options, ['id' => $i, 'name' => $i . '月']);
  68. }
  69. $select_year = $max_year;
  70. $select_month = '';
  71. return view('admin.base.index.welcome', compact('total_device', 'total_project', 'total_money', 'users_total', 'users_auth_total', 'users_not_auth_total', 'device_stat', 'user_auths', 'year_options', 'month_options', 'select_year', 'select_month'));
  72. }
  73. function createAreaDate(){
  74. //Base-index-createareadate.do
  75. header("Content-type:text/html;charset=utf-8");
  76. $areaObj = new BaseArea();
  77. $data = $areaObj->getLevel();
  78. $treeObj = new Tree();
  79. $treeObj -> init($data);
  80. $info = $treeObj -> getTree();
  81. $output = array();
  82. foreach($info AS $key => $val){
  83. if($val['id'] == '100000') continue;
  84. $val['level'] = $val['level'] - 1;
  85. unset($val['grade'], $val['spacer']);
  86. $output[]= $val;
  87. }
  88. $str = json_encode($output);
  89. $area_path = public_path() . '/base/js/areadata.js';
  90. file_put_contents($area_path, $str);
  91. echo $str;exit;
  92. }
  93. }