1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- /**
- * Created by PhpStorm.
- * 超级管理员-管理爱答题
- * User: hanl
- * Date: 2018/9/14
- * Time: 11:45
- */
-
- namespace App\Http\Controllers\SuperAdmin;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\Redis;
- use DB;
- use Excel;
- use App\Common\Api;
-
- class GamesController extends Controller
- {
- //中秋寄相思活动列表
- public function autumnList(Request $request){
- $page_size = empty($params['page_size']) ? 10 : $params['page_size'];
-
- $keyword = $request->get("keyword");
-
- if (is_null($keyword)) {
- $data = DB::table('topic_e16_zq_corps')->orderBy("corp_id")->paginate($page_size);
- } else {
- $data = DB::table('topic_e16_zq_corps')->where("corp_name", "like", "%" . $keyword . "%")->orderBy("corp_id")->paginate($page_size);
- }
-
- $data->withPath("list?keyword=".$keyword);
- return view("superadmin.games.autumn.list", ['data'=>$data]);
- }
-
- public function autumnUserUpload(Request $request){
- $params = $request->all();
- $corp_id = $params['corp_id'];
-
- if($request->isMethod('post')){
- $filePath = $_FILES['file']['tmp_name'];
- Excel::load($filePath, function ($reader) {
- $reader = $reader->getSheet(0);
- $res = $reader->toArray();
- if($res[0][0] != '姓名' || $res[0][1] != '电话号码'){
- print_r(Api::json(config('code.fail'), '文件错误'));
- exit;
- }
- unset($res[0]);
-
- $res = json_encode($res);
- Redis::set('autumn_user_load', $res);
- });
-
- $data = Redis::get('autumn_user_load');
- $userData = json_decode($data, true);
-
- foreach($userData as $k=>$v){
- $userQuery = [];
- $userQuery['corp_id'] = $corp_id;
- $userQuery['realname'] = $v[0];
- $userQuery['phone'] = $v[1];
- $userQuery['create_time'] = time();
-
- $repeat_res = DB::table('topic_e16_zq_user')->where('corp_id', $corp_id)->where('phone', $v[1])->first();
- if($repeat_res){
- DB::table('topic_e16_zq_user')->where('corp_id', $corp_id)->where('phone', $v[1])->update($userQuery);
- } else {
- DB::table('topic_e16_zq_user')->insert($userQuery);
- }
- }
-
- return Api::json(config('code.success'), trans('msg.success'));
- }
- }
- }
|