ActivityController.php 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <?php
  2. /**
  3. * 2018-06-25 韩
  4. */
  5. namespace App\Http\Controllers;
  6. use App\Http\Requests;
  7. use App\Models\VipConfig;
  8. use Illuminate\Http\Request;
  9. use DB;
  10. use Excel;
  11. use Session;
  12. use App\Common\Api;
  13. use App\Models\Activitys;
  14. use App\Models\Apps;
  15. use App\Models\Corps;
  16. use App\Models\AdminVip;
  17. use App\Models\CorpVip;
  18. use Qiniu\Auth;
  19. class ActivityController extends Controller
  20. {
  21. public function __construct(){
  22. }
  23. /**
  24. * 超级管理员获取企业列表
  25. * 2018-06-26 10:32:00
  26. * @param Request $request
  27. * @return string
  28. */
  29. public function getCorpList(Request $request){
  30. try {
  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. $corp_info = Corps::orderByDesc("corp_id")->paginate($page_size);
  36. } else {
  37. $corp_info = Corps::where("corp_name", "like", "%" . $keyword . "%")
  38. ->orderByDesc("corp_id")->paginate($page_size);
  39. }
  40. $data = Api::page($corp_info);
  41. //时间戳转换
  42. foreach ($data['data'] as $key => $val) {
  43. $data['data'][$key] = Api::dateFormat($val);
  44. }
  45. return Api::json(config('code.success'), trans('msg.success'), $data);
  46. }catch(\Exception $e) {
  47. return Api::serviceError($e);
  48. }
  49. }
  50. /**
  51. * 应用列表
  52. * corp_id 企业ID
  53. */
  54. public function getAppList(Request $request){
  55. try {
  56. $res = Apps::get();
  57. $data = json_decode($res, true);
  58. $params = $request->all();
  59. if (empty($params['corp_id'])) {
  60. return Api::json(config('code.params_error'), trans('params.corp_id').trans('msg.params_error'));
  61. }
  62. $userInfo = $request->session()->get('userInfo');
  63. //给超级管理员的企业ID赋值。赋予当前选中的企业ID
  64. if ($userInfo['is_admin'] == 1) {
  65. $userInfo['corp_id'] = $params['corp_id'];
  66. $request->session()->put('userInfo', $userInfo);
  67. }
  68. return Api::json(config('code.success'), trans('msg.success'), $data);
  69. }catch(\Exception $e) {
  70. return Api::serviceError($e);
  71. }
  72. }
  73. /**
  74. * 获取应用详情
  75. * id int 活动类行ID
  76. */
  77. public function getAppInfo(Request $request){
  78. try {
  79. $params = $request->all();
  80. if (empty($params['app_id'])) {
  81. return Api::json(config('code.params_error'), trans('params.app_id').trans('msg.params_error'));
  82. }
  83. $data = Apps::where('app_id', $params['app_id'])->first();
  84. return Api::json(config('code.success'), trans('msg.success'), $data);
  85. }catch(\Exception $e) {
  86. return Api::serviceError($e);
  87. }
  88. }
  89. /**
  90. * 获取七牛上传头token
  91. */
  92. public function getUploadToken(Request $request){
  93. try {
  94. $accessKey = env("QINIU_ACCESS_KEY");
  95. $secretKey = env("QINIU_SECRET_KEY");
  96. $auth = new Auth($accessKey, $secretKey);
  97. $bucket = env("QINIU_BUCKET");
  98. // 生成上传Token
  99. $token = $auth->uploadToken($bucket);
  100. $data['token'] = $token;
  101. return Api::json(config('code.success'), trans('msg.success'), $data);
  102. }catch(\Exception $e) {
  103. return Api::serviceError($e);
  104. }
  105. }
  106. /**
  107. * 获取活动列表
  108. * Corp_id int() 企业ID
  109. * 2018-05-08 16:55 韩
  110. */
  111. public function getList(Request $request){
  112. try {
  113. $params = $request->all();
  114. $keys = array('corp_id');
  115. foreach ($keys as $key) {
  116. if (empty($params[$key])) {
  117. return Api::json(config('code.params_error'), trans('params.'.$key) . trans('msg.params_error'));
  118. }
  119. }
  120. $page_size = empty($params['page_size']) ? 10 : $params['page_size'];
  121. $user_info = Session::get('userInfo');
  122. if (isset($params['keyword']) && !empty($params['keyword'])) {
  123. $data = Activitys::where('corp_id', $params['corp_id'])
  124. ->where('status', '1')
  125. // ->where('creator', $user_info['id'])
  126. ->where('is_complete_set', '1')
  127. ->where('title', 'like', "%" . $params['keyword'] . "%")
  128. ->orderByDesc("create_time")->paginate($page_size);
  129. } else {
  130. $data = Activitys::where('corp_id', $params['corp_id'])
  131. ->where('status', '1')
  132. // ->where('creator', $user_info['id'])
  133. ->where('is_complete_set', '1')
  134. ->orderByDesc("create_time")->paginate($page_size);
  135. }
  136. $data = Api::page($data);
  137. foreach ($data['data'] as $k => $v) {
  138. //管理路由地址
  139. $app_info = Apps::where('app_id', $v['app_id'])->first()->toArray();
  140. $data['data'][$k]['admin_url'] = $app_info['admin_url'];
  141. //游戏路由地址
  142. $data['data'][$k]['game_url'] = env('WEB_URL') . '/' . $app_info['app_code'] . '?activity_id=' . $v['activity_id'];
  143. }
  144. //时间戳格式化
  145. foreach ($data['data'] as $key => $val) {
  146. $data['data'][$key] = Api::dateFormat($val);
  147. //活动状态
  148. if ($val['start_time'] > time()) {
  149. $data['data'][$key]['activity_status_text'] = '未开始';
  150. } elseif ($val['end_time'] < time()) {
  151. $data['data'][$key]['activity_status_text'] = '已结束';
  152. } else {
  153. if ($val['is_temp_stop'] == 1) {
  154. $data['data'][$key]['activity_status_text'] = '已暂停';
  155. } else {
  156. $data['data'][$key]['activity_status_text'] = '进行中';
  157. }
  158. }
  159. }
  160. return Api::json(config('code.success'), trans('msg.success'), $data);
  161. } catch(\Exception $e) {
  162. return Api::serviceError($e);
  163. }
  164. }
  165. /**
  166. * 获取用户信息
  167. * @param Request $request
  168. * @return string
  169. */
  170. public function getBaseAdmin(Request $request){
  171. $params = $request->all();
  172. $user_info = $request->session()->get('userInfo');
  173. if($user_info['corp_id'] != 0){
  174. $user_info['corp_short_name'] = Corps::where('corp_id', $user_info['corp_id'])->value('corp_short_name');
  175. }
  176. if(empty($params['app_id'])){
  177. // $admin_vip_config = AdminVip::where('admin_id', $user_info['id'])
  178. $admin_vip_config = CorpVip::where('corp_id', $user_info['corp_id'])
  179. ->where('vip_end_time', '>', time())
  180. ->orderByDesc('vip_level')
  181. ->first();
  182. } else {
  183. // $admin_vip_config = AdminVip::where('admin_id', $user_info['id'])
  184. $admin_vip_config = CorpVip::where('corp_id', $user_info['corp_id'])
  185. ->where('vip_end_time', '>', time())
  186. ->where('app_id', $params['app_id'])
  187. ->orderByDesc('vip_level')
  188. ->first();
  189. }
  190. if(!empty($admin_vip_config)){
  191. $vipConfig = VipConfig::where('vip_level', $admin_vip_config['vip_level'])->first();
  192. $user_info['time_range'] = ceil(($admin_vip_config['vip_end_time']-time())/(3600*24));
  193. $user_info['vip_name'] = $vipConfig['vip_name'];
  194. $user_info['vip_end_time'] = date('Y-m-d H:i:s', $admin_vip_config['vip_end_time']);
  195. $user_info['vip_level'] = $admin_vip_config['vip_level'];
  196. //当前用户可创建活动数和已创建且在线的活动数
  197. $user_info['online_act_num'] = $vipConfig['online_act_num'];
  198. $user_info['new_online_act'] = Activitys::where('corp_id', $user_info['corp_id'])
  199. ->where('status', 1)
  200. ->where('end_time', '>', time())
  201. ->where('is_complete_set', 1)
  202. ->count();
  203. }
  204. $user_info['env'] = env('APP_ENV');
  205. return Api::json(config('code.success'), trans('msg.success'), $user_info);
  206. }
  207. // /**2018-10-29 迁移到DdController
  208. // * 获取公告列表
  209. // * @param Request $request
  210. // * @return string
  211. // */
  212. // public function getMessageList(Request $request){
  213. // $res = Messages::orderByDesc('create_time')->limit(10)->get();
  214. // return Api::json(config('code.success'), trans('msg.success'), $res);
  215. // }
  216. }
  217. ?>