IndexController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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\AdminUserModel;
  12. use App\Models\AlbumAgentModel;
  13. use App\Models\AlbumStatisticalModel;
  14. use App\Models\AlbumUserModel;
  15. use App\Models\AlbumWatchRecord;
  16. use App\Models\AppInfoModel;
  17. use App\Models\CustomerDetailsModel;
  18. use App\Models\UserInfoModel;
  19. use Illuminate\Http\Request;
  20. use App\Services\Base\Tree;
  21. use App\Services\Base\BaseArea;
  22. use App\Services\Admin\Menus;
  23. use App\Services\Admin\Acl;
  24. use Auth;
  25. class IndexController extends Controller
  26. {
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. }
  31. function index()
  32. {
  33. if ($this->_user['is_root']) {
  34. $obj = new Menus();
  35. $menus = $obj->search(array('level'=>2,'display'=>1),$orderby=array('sort'=>'desc'),$pagesize = 100000);
  36. $menus = $menus->toArray();
  37. $menus = list_to_tree($menus['data']);
  38. } else {
  39. $obj = new Acl();
  40. $data = $obj->getRoleMenu($this->_user['admin_role_id']);
  41. $menus = list_to_tree($data);
  42. }
  43. $user = $this->_user;
  44. return view('admin.base.index.index',compact('menus', 'user'));
  45. }
  46. function welcome()
  47. {
  48. $userAuth = Auth::guard('admin')->user();
  49. if ($userAuth->is_root == 1 && !empty(request('store_id'))) {
  50. session()->put('store_id', request('store_id'));
  51. return redirect('/admin');
  52. }
  53. $time = mktime(24, 60, 60, date('m'), date('d'), date('Y'));
  54. $day = '[';
  55. $count = '[';
  56. for ($i = 15; $i >= 1; $i --) {
  57. $startTime = $time - $i * 86400;
  58. $day .= "\"" . date('m-d', $startTime) . "\",";
  59. $start_time = date('Y-m-d H:i:s', $startTime);
  60. $end_time = date('Y-m-d H:i:s', $startTime + 86400);
  61. $num = AlbumWatchRecord::where([['store_id',$this->getStoreId()],['created_at','>=',$start_time],['created_at','<=',$end_time],['action',4]])->groupBy('open_id')->count();
  62. $count .= $num . ",";
  63. }
  64. $agents = AlbumAgentModel::where('status', 1)->get()->toArray();
  65. $data = array();
  66. $geoCoordMap = (object)[];
  67. foreach ($agents as $key => $val) {
  68. $count_all = AlbumWatchRecord::where([
  69. ['agent_id', $val['id']],
  70. ['store_id', $this->getStoreId()]
  71. ])->groupBy('open_id')->count();
  72. $data[] = (object)[
  73. 'name' => $val['realname'],
  74. 'value' => ($count_all + 20),
  75. 'num' => $count_all,
  76. ];
  77. $name = $val['realname'];
  78. if (empty($name) || empty($val['lon']) || $val['lat']) {
  79. continue;
  80. }
  81. $geoCoordMap->$name = [$val['lon'], $val['lat']];
  82. }
  83. //dd($geoCoordMap);
  84. $data = json_encode($data);
  85. $geoCoordMap = json_encode($geoCoordMap);
  86. $day = substr($day, 0, strlen($day) - 1) . ']';
  87. $count = substr($count, 0, strlen($count) - 1) . ']';
  88. return view('admin.base.index.welcome', [
  89. 'day' => $day,
  90. 'count' => $count,
  91. 'data' => $data,
  92. 'geoCoordMap' => $geoCoordMap
  93. ]);
  94. }
  95. public function getData(Request $request)
  96. {
  97. $data = $request->input();
  98. $time = mktime(24,60,60,date('m'),date('d'),date('Y'));
  99. $startTime = $time-$data['day']*86400;
  100. $start_time = date('Y-m-d H:i:s',$startTime);
  101. $newUser = AlbumUserModel::where([['created_at','>=',$start_time],['store_id',$this->getStoreId()]])->count();
  102. $shareTimes = AlbumStatisticalModel::where([['store_id',$this->getStoreId()],['time','>=',$startTime]])->sum('share_times');
  103. $favoriteTimes = AlbumStatisticalModel::where([['store_id',$this->getStoreId()],['time','>=',$startTime]])->sum('favorite_times');
  104. $watchCount = AlbumWatchRecord::where([['store_id',$this->getStoreId()],['created_at','>=',$start_time]])->groupBy('open_id')->count();
  105. $followCount = CustomerDetailsModel::where([['store_id',$this->getStoreId()],['created_at','>=',$start_time]])->groupBy('open_id')->count();
  106. return $this->api(['newUser'=>$newUser,'shareTimes'=>$shareTimes,'favoriteTimes'=>$favoriteTimes,'watchCount'=>$watchCount,'followCount'=>$followCount],0,'success');
  107. }
  108. function createAreaDate(){
  109. //Base-index-createareadate.do
  110. header("Content-type:text/html;charset=utf-8");
  111. $areaObj = new BaseArea();
  112. $data = $areaObj->getLevel();
  113. $treeObj = new Tree();
  114. $treeObj -> init($data);
  115. $info = $treeObj -> getTree();
  116. $output = array();
  117. foreach($info AS $key => $val){
  118. if($val['id'] == '100000') continue;
  119. $val['level'] = $val['level'] - 1;
  120. unset($val['grade'], $val['spacer']);
  121. $output[]= $val;
  122. }
  123. $str = json_encode($output);
  124. $area_path = public_path() . '/base/js/areadata.js';
  125. file_put_contents($area_path, $str);
  126. echo $str;exit;
  127. }
  128. // public function __construct()
  129. // {
  130. // parent::__construct();
  131. // }
  132. //
  133. // function index(Request $request)
  134. // {
  135. //
  136. // $menus = $this->getMenus($this->_user);
  137. //
  138. // session('level', $this->_user->level);
  139. // $_user = $this->_user;
  140. // return view('admin.base.index.index', compact('menus', 'template_info', 'template_id', 'app_id','_user'));
  141. // }
  142. //
  143. // function welcome()
  144. // {
  145. // return view('admin.base.index.welcome');
  146. // }
  147. //
  148. // function createAreaDate()
  149. // {
  150. // //Base-index-createareadate.do
  151. // header("Content-type:text/html;charset=utf-8");
  152. // $areaObj = new BaseArea();
  153. // $data = $areaObj->getLevel();
  154. //
  155. // $treeObj = new Tree();
  156. // $treeObj->init($data);
  157. // $info = $treeObj->getTree();
  158. // $output = array();
  159. //
  160. // foreach ($info AS $key => $val) {
  161. // if ($val['id'] == '100000') continue;
  162. // $val['level'] = $val['level'] - 1;
  163. // unset($val['grade'], $val['spacer']);
  164. // $output[] = $val;
  165. // }
  166. //
  167. // $str = json_encode($output);
  168. //
  169. // $area_path = public_path() . '/base/js/areadata.js';
  170. // file_put_contents($area_path, $str);
  171. //
  172. // echo $str;
  173. // exit;
  174. // }
  175. //
  176. // public function getMenus($user)
  177. // {
  178. // if ($user->level >= 1) {
  179. // $menus = [
  180. // ['name' => '名片管理', 'path' => "/list?id=2", 'ico' => 'fa-bar-chart-o'],
  181. // ['name' => '公司管理', 'path' => "Sw/Company/Info/index?id=2", 'ico' => 'fa-bar-chart-o'],
  182. // ['name' => '画册管理', 'path' => "/Album/Manufacturer/list?isalbum=1", 'ico' => 'fa-bar-chart-o'],
  183. // ['name' => '家具管理', 'path' => "/Album/Manufacturer/list", 'ico' => 'fa-bar-chart-o'],
  184. // ];
  185. // return $menus;
  186. // }
  187. //
  188. // if ($user->level === 0) {
  189. // $iscp = UserInfoModel::where('menus', 'like', '%' . '公司' . '%')->where('account', $user->account)->count();
  190. // $iscard = UserInfoModel::where('menus', 'like', '%' . '名片' . '%')->where('account', $user->account)->count();
  191. // $isalbum = UserInfoModel::where('menus', 'like', '%' . 'album' . '%')->where('account', $user->account)->count();
  192. // $isfurniture = UserInfoModel::where('menus', 'like', '%' . 'furniture' . '%')->where('account', $user->account)->count();
  193. //
  194. //
  195. // $_app_info = AppInfoModel::where('account','like','%' . $user->account . '%')->first();
  196. //
  197. // $uniacid = isset($_app_info->uniacid)?$_app_info->uniacid:'';
  198. //
  199. // if ($iscp) {
  200. // // 体验模板
  201. // $menus = [
  202. // ['name' => '公司管理', 'path' => "/Sw/Company/Info/update?appid=$uniacid", 'ico' => 'fa-bar-chart-o'],
  203. // ];
  204. // return $menus;
  205. // }
  206. // if ($iscard) {
  207. // // 名片模板
  208. // $menus = [
  209. // ['name' => '名片管理', 'path' => "/Card/User/Info/update?appid=$uniacid", 'ico' => 'fa-bar-chart-o'],
  210. // ];
  211. // return $menus;
  212. // }
  213. //
  214. // if ($isalbum) {
  215. // // 画册模板
  216. // return $this->albumMenus($user,$user->user_template_id);
  217. // }
  218. //
  219. // if ($isfurniture) {
  220. // // 家具模板
  221. // return $this->furntureMenus($user,$user->user_template_id);
  222. // }
  223. // }
  224. //
  225. // }
  226. //
  227. // public function albumMenus($user,$storeid){ //画册
  228. // session()->put('store_id', $storeid);
  229. // session()->put('app', 'album');
  230. // $baseMenus = $this->baseMenus();
  231. //
  232. // $_menus = [
  233. // $baseMenus['base_setting'],
  234. // $baseMenus['album_goods'],
  235. // $baseMenus['album_user'],
  236. // ];
  237. // return $_menus;
  238. // }
  239. //
  240. // public function furntureMenus($user,$storeid){
  241. // session()->put('store_id', $storeid);
  242. // session()->put('app', 'furniture');
  243. // $baseMenus = $this->baseMenus();
  244. // if($user->role == 1) //客服
  245. // {
  246. // $_menus = [
  247. // $baseMenus['fur_user'],
  248. // $baseMenus['fur_service_order'],
  249. // $baseMenus['fur_service_review'],
  250. // $baseMenus['fur_service_goodsattr'],
  251. // ];
  252. // }elseif(!$user->role){ //超级管理员
  253. // $_menus = [
  254. // $baseMenus['base_setting'],
  255. // $baseMenus['fur_user'],
  256. // $baseMenus['fur_navbar'],
  257. // $baseMenus['fur_banner'],
  258. // $baseMenus['fur_goods'],
  259. // $baseMenus['fur_news'],
  260. // $baseMenus['fur_service_order'],
  261. // $baseMenus['fur_service_review'],
  262. // $baseMenus['fur_service_goodsattr']
  263. // ];
  264. // }else{ //经理
  265. // $_menus = [
  266. // $baseMenus['fur_service_order'],
  267. // $baseMenus['fur_service_review'],
  268. // ];
  269. // }
  270. //
  271. // return $_menus;
  272. // }
  273. //
  274. //
  275. //
  276. // public function baseMenus(){
  277. // $menus = [
  278. // ['name' => 'CRUD', 'path' => "/Base/Crud/create", 'ico' => 'fa fa-bar-chart-o'],
  279. // ['name' => '字典', 'path' => "/Base/Dictionary/Option/index", 'ico' => 'fa fa-bar-chart-o'],
  280. //
  281. // 'base_setting'=>
  282. // ['name' => '系统设置', 'path' => "/Album/Manufacturer/index", 'ico' => 'glyphicon glyphicon-cog'],
  283. // 'fur_navbar'=>
  284. // ['name' => '导航栏设置', 'path' => "/Album/Nav/index", 'ico' => 'glyphicon glyphicon-th-list'],
  285. //
  286. // 'fur_banner'=>
  287. // ['name' => '轮播图管理', 'path' => "Album/Banner/index", 'ico' => 'glyphicon glyphicon-picture'],
  288. // 'fur_news'=>
  289. // ['name' => '新闻管理', 'path' => "#", 'ico' => 'fa fa-bar-chart-o', '_child' =>
  290. // [
  291. // ['name' => '新闻列表', 'path' => '/Album/News/index', 'ico' => ''],
  292. // ['name' => '评论列表', 'path' => '/Album/Comments/index', 'ico' => ''],
  293. // ]
  294. // ],
  295. // 'fur_goods'=>
  296. // ['name' => '产品管理', 'path' => "#", 'ico' => 'fa fa-bar-chart-o', '_child' =>
  297. // [
  298. // ['name' => '产品列表', 'path' => '/Furniture/Goods/index', 'ico' => ''],
  299. // ]
  300. // ],
  301. // 'fur_user'=>
  302. // ['name' => '用户管理', 'path' => "#", 'ico' => 'glyphicon glyphicon-user', '_child' =>
  303. // [
  304. // ['name' => '用户列表', 'path' => '/Album/User/index', 'ico' => ''],
  305. // ]
  306. // ],
  307. // 'fur_service_order'=>
  308. // ['name' => '订单管理', 'path' => "#", 'ico' => 'glyphicon glyphicon-briefcase', '_child' =>
  309. // [
  310. // ['name' => '待审核', 'path' => '/Album/Order/index?status=0', 'ico' => ''],
  311. // ['name' => '待生产', 'path' => '/Album/Order/index?status=1', 'ico' => ''],
  312. // ['name' => '生产中', 'path' => '/Album/Order/index?status=2', 'ico' => ''],
  313. // ['name' => '待发货', 'path' => '/Album/Order/index?status=3', 'ico' => ''],
  314. // ['name' => '待收货', 'path' => '/Album/Order/index?status=4', 'ico' => ''],
  315. // ['name' => '已签收', 'path' => '/Album/Order/index?status=5', 'ico' => ''],
  316. // ['name' => '逾期', 'path' => '/Album/Order/index?expected=1', 'ico' => ''],
  317. // ]
  318. // ],
  319. // 'fur_service_review'=>
  320. // ['name' => '评论管理', 'path' => "#", 'ico' => 'glyphicon glyphicon-briefcase', '_child' => [
  321. // ['name' => '评论列表', 'path' => '/Album/Review/index', 'ico' => '']
  322. // ]
  323. // ],
  324. // 'fur_service_goodsattr'=>['name' => '产品属性', 'path' => "#", 'ico' => 'glyphicon glyphicon-briefcase', '_child' => [
  325. // ['name' => '属性列表', 'path' => '/Album/Product/Attr/index', 'ico' => '']
  326. // ]
  327. // ],
  328. //
  329. // 'album_goods'=>
  330. // ['name' => '产品管理', 'path' => "#", 'ico' => 'glyphicon glyphicon-briefcase', '_child' =>
  331. // [
  332. // ['name' => '分类管理', 'path' => '/Album/Cat/index', 'ico' => ''],
  333. // ['name' => '样式管理', 'path' => '/Album/Product/Style/index', 'ico' => ''],
  334. // ['name' => '产品管理', 'path' => 'Album/Product/index', 'ico' => ''],
  335. // ]
  336. // ],
  337. // 'album_user'=>
  338. // ['name' => '用户管理', 'path' => "#", 'ico' => 'glyphicon glyphicon-user', '_child' =>
  339. // [
  340. // ['name' => '用户列表', 'path' => '/Album/Xyx/User/index', 'ico' => ''],
  341. // ['name' => '经销商列表', 'path' => '/Album/Agent/index', 'ico' => ''],
  342. // ]
  343. // ],
  344. // ];
  345. //
  346. // return $menus;
  347. // }
  348. }