IndexController.php 15 KB

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