123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?php
- /**
- * Created by PhpStorm.
- * 超级管理员-管理爱答题
- * User: guanxl
- * Date: 2018/7/4
- * Time: 11:45
- */
-
- namespace App\Http\Controllers;
-
- use App\Http\Requests;
- use App\Services\DdService;
- use Illuminate\Http\Request;
- use App\Common\Api;
- use DB;
-
- use App\Models\Messages;
- use App\Models\AdminVip;
- use App\Models\Admin;
- use App\Models\Apps;
- use App\Models\Activitys;
- use App\Models\Configs;
- use App\Models\CorpVip;
- use App\Services\QuestionService;
-
- class DdController extends Controller
- {
- /**
- * 获取公告列表
- * @param Request $request
- * @return string
- */
- public function getMessageList(Request $request){
- $res = Messages::orderByDesc('create_time')->limit(10)->where('status', 1)->get();
- return Api::json(config('code.success'), trans('msg.success'), $res);
- }
-
- /**
- * DD会员开通及初始活动创建
- * @param Request $request
- * @return string
- */
- public function openVip(Request $request){
- $adminId = $request->get('admin_id');
- if(empty($adminId)){
- return Api::json(config('code.params_error'), trans('msg.params_error'));
- }
-
- //默认参数赋值
- $appId = 1;
- $authType = 'dingtalk_add';
- $clientType = 'dingtalk';
- $title = '叮当答题初体验(示例活动)';
- $sponsor_corp = '本活动解释权归迷倒万千少男少女的答题君所有';
- $extendConfigs = '{"must_question_num":2,"must_answer_wrong_num":1,"must_answer_success_km":100,"blockade_question_num":3,"blockade_answer_wrong_num":1,"blockade_answer_success_km":30,"pk_question_num":3,"pk_last_double":1,"pk_kms":"10\/20\/50","must_category_ids":"","blockade_category_ids":"","pk_category_ids":"","top_prize_num":3,"top_prize_text":"\u6392\u884c\u524d3\u540d\u8fd8\u53ef\u83b7\u5f97\u989d\u5916\u5956\u52b1\uff01","top_prize_open":1,"blockade_answer_count_down":10,"must_answer_count_down":10}';
-
- $adminInfo = Admin::where('id', $adminId)->where('status', 1)->first();
-
- if(!$adminInfo){
- return Api::json(config('code.fail'), trans('msg.admin_not_exist'));
- }
-
- //管理员VIP开通记录
- $adminCorpId = Admin::where('id', $adminId)->value('corp_id');
- $vipInfo = CorpVip::where('corp_id', $adminCorpId)->first();
- if(!$vipInfo){
- //未开通过的企业赋予七天体验版VIP
- $query = [];
- $query['corp_id'] = $adminCorpId;
- $query['app_id'] = $appId; //默认为爱答题,后续若新增新的应用,需要在管理员表表明管理员所属应用
- $query['vip_level'] = 1;
- $query['vip_start_time'] = time();
- $query['vip_end_time'] = time()+3600*24*7; //赋予七天免费版VIP
- $query['create_time'] = time();
- $query['update_time'] = time();
-
- $res = CorpVip::insert($query);
- if(!$res){
- return Api::json(config('code.fail'), '会员开通失败');
- }
- }
-
- //活动创建记录
- $activityInfo = Activitys::where('creator', $adminId)->first();
- if(!$activityInfo){
- $vipInfo = CorpVip::where('corp_id', $adminCorpId)->first();
- if($vipInfo['vip_end_time'] <= time()){
- return Api::arr(config('code.fail'), trans('msg.vip_time_out'));
- }
-
- //获取应用默认数据
- $app_info = Apps::where('app_id', $appId)->value('default_data');
- $default_data = json_decode($app_info, true);
-
- //activitys表参数拼接
- $query = [];
- $query['corp_id'] = $adminInfo['corp_id'];
- $query['app_id'] = $appId;
- $query['create_time'] = time();
- $query['update_time'] = time();
- $query['title'] = $title;
- $query['logo'] = $default_data['logo'];
- $query['regulation'] = $default_data['regulation'];
- $query['is_jobtime_limit'] = $default_data['is_jobtime_limit'];
- $query['jobtimes'] = $default_data['jobtimes'];
- $query['start_time'] = strtotime(date('Y-m-d'));
- $query['end_time'] = strtotime(date('Y-m-d'))+30*3600*24;
- $query['auth_type'] = $authType;
- $query['client_type'] = $clientType;
- $query['creator'] = $adminId;
- $query['is_complete_set'] = 1;
- $query['activity_type'] = $vipInfo['vip_level'] == 1 ? 1 : 2; //根据企业会员状态赋予活动收费状态
-
- //企业VIP信息
- $vip_level = CorpVip::where('corp_id', $adminCorpId)->value('vip_level');
- $query['vip_level'] = $vip_level; //活动vip等级,用于手机端权限控制
-
- $activity_res = Activitys::insertGetId($query);
-
- //configs表参数拼接
- $configQuery = [];
- $categoryRes = QuestionService::addDefault($activity_res); //添加默认题库
- if(!$categoryRes){
- return Api::arr($categoryRes['code'], $categoryRes['msg']);
- } else {
- $extendConfig = json_decode($extendConfigs, true);
- $extendConfig['must_category_ids'] = $categoryRes['data']['category_id'];
- $extendConfig['blockade_category_ids'] = $categoryRes['data']['category_id'];
- $extendConfig['pk_category_ids'] = $categoryRes['data']['category_id'];
- $configQuery['extend_configs'] = json_encode($extendConfig);
- }
- $configQuery['activity_id'] = $activity_res;
- $configQuery['corp_id'] = $adminInfo['corp_id'];
- $configQuery['top_banner'] = $default_data['top_banner'];
- $configQuery['home_background'] = $default_data['home_background'];
- $configQuery['mark_background'] = $default_data['mark_background'];
- $configQuery['count_down_background'] = $default_data['count_down_background'];
- $configQuery['sponsor_corp'] = $sponsor_corp;
- $configQuery['prize_banner'] = '//s1-hn.aghcdn.com/management/20181025/069cc3cd0b76a7e1ec194b97946a62052d31d143.png';
- $configQuery['copper_box_km'] = $default_data['copper_box_km'];
- $configQuery['silver_box_km'] = $default_data['silver_box_km'];
- $configQuery['gold_box_km'] = $default_data['gold_box_km'];
- $configQuery['is_open_prize'] = 1; //默认开启抽奖
- $configQuery['open_department_top'] = $default_data['open_department_top']; //默认不开启单位排行
- $configQuery['level_star_config'] = json_encode($default_data['level_star_config']); //段位的默认配置
- $configQuery['update_time'] = time();
- $configQuery['create_time'] = time();
-
- $config_res = Configs::insert($configQuery);
-
- //添加示例宝箱
- $box_res = DdService::ExampleActBox($activity_res, $adminInfo['corp_id']);
-
- if($activity_res && $config_res && $box_res) {
- //清理并生成题库缓存
- $questions_cache = env('WEB_URL').'/brainstorming/console/cache/question?activity_id='.$activity_res;
- $config_cache = env('WEB_URL').'/brainstorming/console/cache/config?activity_id='.$activity_res;
- Api::curl($config_cache);
- Api::curl($questions_cache);
-
- return Api::json(config('code.success'), trans('msg.success'));
- } else {
- return Api::arr(config('code.sql_error'), trans('msg.sql_error'));
- }
- }
- // return Api::json(config('code.success'), trans('msg.success'));
- }
- }
|