IndexController.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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\Config;
  12. use App\Models\InnerDevice;
  13. use App\Models\Option;
  14. use App\Models\Order;
  15. use App\Models\Project;
  16. use App\Models\User;
  17. use App\Models\UserAuth;
  18. use App\Services\Base\Tree;
  19. use App\Services\Base\BaseArea;
  20. use Carbon\Carbon;
  21. class IndexController extends Controller
  22. {
  23. public function __construct()
  24. {
  25. parent::__construct();
  26. }
  27. function index() {
  28. $menus = $this->getMenus();
  29. $title = Config::getTitle();
  30. return view('admin.base.index.index',compact('menus', 'title'));
  31. }
  32. function welcome() {
  33. // return redirect('/admin/AdminUser/index');
  34. $total_device = InnerDevice::count();
  35. $total_project = Project::count();
  36. $total_money = Order::sum('money') / 100;
  37. $users_total = User::count();
  38. $users_not_auth_total = UserAuth::where('active', 2)->count();
  39. $users_auth_total = UserAuth::count();
  40. $items = InnerDevice::get();
  41. $types = ['free', 'using', 'repair', 'scrap'];
  42. $device_stat = [];
  43. foreach ($types as $type) {
  44. $id = Option::get('inner_devices', 'status', $type);
  45. $num = $items->where('status', $id)->count();
  46. $device_stat[$type] = $num;
  47. }
  48. $user_auths = UserAuth::where('active', 2)->limit(8)->get();
  49. $min_order = Order::orderBy('created_at', 'desc')->first();
  50. $min_year = $min_order ? $min_order->created_at->year : Carbon::now()->year;
  51. $max_year = Carbon::now()->year;
  52. $year_options = [];
  53. for($i = $min_year; $i <= $max_year; ++$i) {
  54. array_push($year_options, ['id' => $i, 'name' => $i . '年']);
  55. }
  56. $month_options = [['id' => '', 'name' => '所有月份']];
  57. for($i = 1; $i <= 12; ++$i) {
  58. array_push($month_options, ['id' => $i, 'name' => $i . '月']);
  59. }
  60. $select_year = $max_year;
  61. $select_month = '';
  62. 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'));
  63. }
  64. function createAreaDate(){
  65. //Base-index-createareadate.do
  66. header("Content-type:text/html;charset=utf-8");
  67. $areaObj = new BaseArea();
  68. $data = $areaObj->getLevel();
  69. $treeObj = new Tree();
  70. $treeObj -> init($data);
  71. $info = $treeObj -> getTree();
  72. $output = array();
  73. foreach($info AS $key => $val){
  74. if($val['id'] == '100000') continue;
  75. $val['level'] = $val['level'] - 1;
  76. unset($val['grade'], $val['spacer']);
  77. $output[]= $val;
  78. }
  79. $str = json_encode($output);
  80. $area_path = public_path() . '/base/js/areadata.js';
  81. file_put_contents($area_path, $str);
  82. echo $str;exit;
  83. }
  84. }