SuperAdminController.php 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: gevnc
  5. * Date: 2018/7/3
  6. * Time: 17:39
  7. */
  8. namespace App\Http\Controllers;
  9. use App\Http\Controllers\Controller;
  10. use App\Models\CorpVip;
  11. use App\Models\VipConfig;
  12. use Illuminate\Http\Request;
  13. use App\Common\Api;
  14. use App\Models\Corps;
  15. use App\Models\Activitys;
  16. use App\Models\Admin;
  17. class SuperAdminController extends Controller
  18. {
  19. public function index(){
  20. return view("superadmin.index");
  21. }
  22. public function home(){
  23. return redirect("/manage/super/brainstorming/board");
  24. }
  25. /**
  26. * 企业管理
  27. * @param Request $request
  28. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  29. */
  30. public function corp(Request $request){
  31. $params = $request->all();
  32. $page_size = empty($params['page_size']) ? 10 : $params['page_size'];
  33. $keyword = $request->get("keyword");
  34. if (is_null($keyword)) {
  35. $corpInfos = Corps::orderBy("corp_id")->paginate($page_size);
  36. } else {
  37. $corpInfos = Corps::where("corp_name", "like", "%" . $keyword . "%")
  38. ->orderBy("corp_id")->paginate($page_size);
  39. }
  40. //数据处理
  41. foreach($corpInfos as $k=>$corpInfo){
  42. if($corpInfo['source_type'] == 'agh'){
  43. $corpInfos[$k]['source_type'] = '爱关怀';
  44. }
  45. $corpInfos[$k]['has_wesuit'] = $corpInfo['has_wesuit'] == 0 ? '未开启':'已开启';
  46. $corpInfos[$k]['activity_num'] = Activitys::where('corp_id', $corpInfo['corp_id'])->where('status', 1)->where('is_complete_set', 1)->count();
  47. }
  48. $corpInfos->withPath("corp?keyword=".$keyword);
  49. return view("superadmin.corp_manage", ['data'=>$corpInfos]);
  50. }
  51. /**
  52. * 新增企业
  53. * @param Request $request
  54. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string
  55. */
  56. public function corpAdd(Request $request){
  57. if($request->isMethod('post')){
  58. $params = $request->all();
  59. $query = [];
  60. $query['corp_name'] = $params['corp_name'];
  61. $query['corp_short_name'] = $params['corp_short_name'];
  62. $query['contact_name'] = $params['contact_name'];
  63. $query['contact_phone'] = $params['contact_phone'];
  64. $query['contact_email'] = $params['contact_email'];
  65. $query['contact_address'] = $params['contact_address'];
  66. $query['update_time'] = time();
  67. $query['create_time'] = time();
  68. $res = Corps::insert($query);
  69. if($res){
  70. return Api::json(config('code.success'), trans('msg.success'));
  71. } else {
  72. return Api::json(config('code.fail'), trans('msg.fail'));
  73. }
  74. } else {
  75. return view("superadmin.corp_add");
  76. }
  77. }
  78. /**
  79. * 管理员管理
  80. * @param Request $request
  81. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  82. */
  83. public function adminAdd(Request $request){
  84. $params = $request->all();
  85. if($request->isMethod('post')){
  86. $query = [];
  87. $query['name'] = $params['name'];
  88. $query['username'] = $params['username'];
  89. $query['password'] = md5($params['password']);
  90. $query['is_admin'] = $params['is_admin'];
  91. $query['corp_id'] = $params['corp_id'];
  92. $query['status'] = 1;
  93. $query['update_time'] = time();
  94. $query['create_time'] = time();
  95. $userNameRepeat = Admin::where('username', $params['username'])->first();
  96. if($userNameRepeat){
  97. return Api::json(config('code.fail'), '账号已存在,请重新输入!');
  98. }
  99. $res = Admin::insert($query);
  100. if($res){
  101. return Api::json(config('code.success'), trans('msg.success'));
  102. } else {
  103. return Api::json(config('code.fail'), trans('msg.fail'));
  104. }
  105. } else {
  106. $corp_id = $params['corp_id'];
  107. $admins = Admin::where('corp_id', $corp_id)->get();
  108. $data['corp_id'] = $corp_id;
  109. $data['admins'] = $admins;
  110. return view("superadmin.admin_add", ['data'=>$data]);
  111. }
  112. }
  113. /**
  114. * 会员设置
  115. * @param Request $request
  116. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string
  117. */
  118. public function vipSet(Request $request){
  119. $params = $request->all();
  120. if(isset($params['vip_time_set']) && !empty($params['vip_time_set'])){
  121. $vipInfo = CorpVip::where('corp_id', $params['corp_id'])->first();
  122. if($vipInfo){
  123. CorpVip::where('corp_id', $params['corp_id'])->update(['vip_end_time'=>strtotime($params['vip_time_set']) + 3600*24 -1, 'vip_level'=>$params['vip_level']]);
  124. } else {
  125. $query = [];
  126. $query['corp_id'] = $params['corp_id'];
  127. $query['app_id'] = 1;
  128. $query['vip_level'] = $params['vip_level'];
  129. $query['vip_start_time'] = time();
  130. $query['vip_end_time'] = strtotime($params['vip_time_set']) + 3600*24 -1;
  131. $query['update_time'] = $query['create_time'] = time();
  132. CorpVip::insert($query);
  133. }
  134. //修改该企业已有活动的收费状态(体验版升级为其他版本时修改状态)
  135. $vipInfo = CorpVip::where('corp_id', $params['corp_id'])->first();
  136. if($vipInfo['vip_level'] != 1){
  137. Activitys::where('corp_id', $params['corp_id'])->where('activity_type', 1)->update(['activity_type'=>2]);
  138. }
  139. return Api::json(config('code.success'), trans('msg.success'));
  140. } else {
  141. $corpInfo = Corps::where('corp_id', $params['corp_id'])->first();
  142. if(!$corpInfo){
  143. return Api::json(config('code.fail'), '企业不存在');
  144. }
  145. $vipInfo = CorpVip::where('corp_id', $params['corp_id'])->first();
  146. $data = [];
  147. $data['corp_id'] = $params['corp_id'];
  148. $data['vipConfigs'] = VipConfig::get();
  149. if($vipInfo) {
  150. $data['corp_name'] = $corpInfo['corp_name'];
  151. $data['vip_end_time'] = $vipInfo['vip_end_time'];
  152. $data['vip_name'] = VipConfig::where('vip_level', $vipInfo['vip_level'])->value('vip_name');
  153. $data['online_user_num'] = VipConfig::where('vip_level', $vipInfo['vip_level'])->value('online_user_num');
  154. } else {
  155. $data['corp_name'] = $corpInfo['corp_name'];
  156. $data['vip_name'] = '非会员';
  157. }
  158. return view("superadmin.vip_set", ['data'=>$data]);
  159. }
  160. }
  161. }