GamesController.php 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * 超级管理员-管理爱答题
  5. * User: hanl
  6. * Date: 2018/9/14
  7. * Time: 11:45
  8. */
  9. namespace App\Http\Controllers\SuperAdmin;
  10. use Illuminate\Http\Request;
  11. use App\Http\Controllers\Controller;
  12. use Illuminate\Support\Facades\Redis;
  13. use DB;
  14. use Excel;
  15. use App\Common\Api;
  16. class GamesController extends Controller
  17. {
  18. //中秋寄相思活动列表
  19. public function autumnList(Request $request){
  20. $page_size = empty($params['page_size']) ? 10 : $params['page_size'];
  21. $keyword = $request->get("keyword");
  22. if (is_null($keyword)) {
  23. $data = DB::table('topic_e16_zq_corps')->orderBy("corp_id")->paginate($page_size);
  24. } else {
  25. $data = DB::table('topic_e16_zq_corps')->where("corp_name", "like", "%" . $keyword . "%")->orderBy("corp_id")->paginate($page_size);
  26. }
  27. $data->withPath("list?keyword=".$keyword);
  28. return view("superadmin.games.autumn.list", ['data'=>$data]);
  29. }
  30. public function autumnUserUpload(Request $request){
  31. $params = $request->all();
  32. $corp_id = $params['corp_id'];
  33. if($request->isMethod('post')){
  34. $filePath = $_FILES['file']['tmp_name'];
  35. Excel::load($filePath, function ($reader) {
  36. $reader = $reader->getSheet(0);
  37. $res = $reader->toArray();
  38. if($res[0][0] != '姓名' || $res[0][1] != '电话号码'){
  39. print_r(Api::json(config('code.fail'), '文件错误'));
  40. exit;
  41. }
  42. unset($res[0]);
  43. $res = json_encode($res);
  44. Redis::set('autumn_user_load', $res);
  45. });
  46. $data = Redis::get('autumn_user_load');
  47. $userData = json_decode($data, true);
  48. foreach($userData as $k=>$v){
  49. $userQuery = [];
  50. $userQuery['corp_id'] = $corp_id;
  51. $userQuery['realname'] = $v[0];
  52. $userQuery['phone'] = $v[1];
  53. $userQuery['create_time'] = time();
  54. $repeat_res = DB::table('topic_e16_zq_user')->where('corp_id', $corp_id)->where('phone', $v[1])->first();
  55. if($repeat_res){
  56. DB::table('topic_e16_zq_user')->where('corp_id', $corp_id)->where('phone', $v[1])->update($userQuery);
  57. } else {
  58. DB::table('topic_e16_zq_user')->insert($userQuery);
  59. }
  60. }
  61. return Api::json(config('code.success'), trans('msg.success'));
  62. }
  63. }
  64. }