model = model('Activity'); $this->view->assign("statusList", $this->model->getStatusList()); $this->view->assign("popStatusList", $this->model->getPopStatusList()); $this->view->assign("popRangeList", $this->model->getPopRangeList()); $this->assignconfig("popRangeList", $this->model->getPopRangeList()); $this->activity_type = intval($this->request->param('type') ?? 0); $this->assign('activity_type',$this->activity_type); $this->assignconfig('activity_type',$this->activity_type); $this->business_line = PayConstants::BUSINESS_WECHAT; if (in_array($this->activity_type, [2])) { $this->business_line = PayConstants::BUSINESS_APP; } $this->assignconfig('business_line', $this->business_line); } /** * 生成短链 * @return \think\response\Json */ public function sorturl(){ $ids = empty($_GET['ids'])?'':$_GET['ids']; $error = json(['error'=>1]); if(!$ids){ return $error; } $admin_id = $this->auth->id; $param = []; $param['aid'] = $ids; $param['admin_id'] = $admin_id; /** * 跳转短链生成格式 */ $channel_id = $this->auth->agent_id ? $this->auth->agent_id : $this->auth->channel_id; $jmp_url = getCurrentDomain($channel_id,'/s/' . $ids); $shorturl = new ShortUrl(); $hasRecode = model('activity_shortlink')->where($param)->find(); if(!$param['qq'] = $shorturl->tencent($channel_id,$jmp_url)){ return $error; } if(!$param['sina'] = $shorturl->sina($jmp_url)){ return $error; } $param['updatetime'] = time(); if($hasRecode){ //update $result = model('activity_shortlink')->update($param,['aid'=>$ids,'admin_id'=>$admin_id]); }else{ //insert $param['createtime'] = time(); $result = model('activity_shortlink')->insert($param); } if($result){ return json(['error'=>0,'data'=>$param]); }else{ return $error; } } /** * 查看 */ public function index() { $give_tab = 1; $activity_config = Config::get('site.activity_config'); $activity_give_config = Config::get('site.activity_give_config'); if($this->auth->agent_id || $this->group == 3){ if(!model('AdminConfig')->checkWechatConfig($this->auth->id)){ $this->error('请先授权微信服务号给本系统,正在跳转授权设置页面~', url('admin/config')); } } //设置过滤方法 $this->request->filter(['strip_tags']); $this->assignconfig('time',$this->time); $this->assign('time',$this->time); $this->assign('group',$this->group); $today = date('Ymd',$this->time); /** * 跳转短链生成格式 */ if($this->group == 4){ if($this->auth->agent_id){ $channel_id = $this->auth->agent_id; }else{ $channel_id = $this->auth->channel_id; } } if($this->group == 3){ $channel_id = $this->auth->channel_id; } $distribute = 0; $adminExtend = model('admin_extend')->where(['admin_id'=>$this->auth->id])->find(); if(!empty($adminExtend->distribute) && $adminExtend->distribute == '1' ){ $distribute = 1; } $this->assign('distribute',$distribute); $activityShowRechargePage = 0; if($this->group<3 || $this->group==6) { if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('pkey_name')) { return $this->selectpage(); } list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $total = $this->model ->where($where) ->where('type',$this->activity_type) ->count(); $list = $this->model ->join('activity_collect c','activity.id=c.aid and c.createdate='.$today.' and c.admin_id=0','left') ->join('activity_collect_all a','activity.id=a.aid and a.admin_id=0','left') ->field('activity.*,c.money,a.money as allmoney') ->where($where) ->where('activity.type',$this->activity_type) ->order($sort, $order) ->limit($offset, $limit) ->select(); if ($list && in_array($this->activity_type, [0, 2])) { //平台或APP判断是否已经设置资源 foreach ($list as &$item) { $resourceModel = model("Resource")->field("id")->where('activity_id', 'eq', $item['id'])->find(); $item['resource_id'] = 0; if ($resourceModel) { $item['resource_id'] = $resourceModel['id']; } } } $result = array("total" => $total, "rows" => $list); return json($result); } return $this->view->fetch(); }else{ if($this->group == 3 || ($this->group == 4 && $distribute==1)){ $adminConfig = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($channel_id); $activityShowRechargePage = $adminConfig['activity_show_recharge_page']; // $adminConfig = model('AdminConfig')->get($this->auth->id); if ($adminConfig['give_kandian'] == 0) { $give_tab = 0; } $ac_map = []; $this->assign('give_tab', $give_tab); //活动状态 if($this->activity_type == self::ACTIVITY_TYPE_PLATFORM){ $ac_map['activity.status'] = '1'; } if($this->activity_type == self::ACTIVIYT_TYPE_CHANNEL || $this->activity_type == self::ACTIVIYT_TYPE_GIVE){ //渠道自定义活动 & 赠币活动 //渠道商处理 if($this->group == AdminConstants::ADMIN_GROUP_ID_CHANNEL){ $ac_map['activity.admin_id'] = $this->auth->id; } //配号代理商 if($this->group == AdminConstants::ADMIN_GROUP_ID_AGENT && $distribute==1){ $ac_map['activity.admin_id'] = ['in',"{$this->auth->id},{$this->auth->channel_id}"]; }elseif($this->group == AdminConstants::ADMIN_GROUP_ID_AGENT){ //代理商 $ac_map['activity.admin_id'] = $this->auth->channel_id; } } //不展示系统活动 $ac_map['is_system'] = ['eq', 0]; $res = model('activity') ->join('activity_collect c','activity.id=c.aid and c.createdate='.$today.' and c.admin_id='.$this->auth->id,'left') ->join('activity_collect_all a','activity.id=a.aid and a.admin_id='.$this->auth->id,'left') ->join('activity_shortlink s','activity.id= s.aid and s.admin_id='.$this->auth->id,'left') ->where($ac_map) ->where('activity.id <> 100') ->where('activity.type',$this->activity_type) ->field('activity.*,c.money,a.money as allmoney,s.qq as qq, s.sina as sina,c.recharge_count,a.recharge_count as arecharge_count') ->order('activity.createtime','desc') ->paginate(10,false,['query'=>['type'=>$this->activity_type]]); }else{ //平台活动 $res = model('activity') ->join('activity_collect c','activity.id=c.aid and c.createdate='.$today.' and c.admin_id='.$this->auth->id,'left') ->join('activity_collect_all a','activity.id=a.aid and a.admin_id='.$this->auth->id,'left') ->where('activity.status','1') ->where('activity.id <> 100') ->where('activity.type',$this->activity_type) ->field('activity.*,c.money,a.money as allmoney,c.recharge_count,a.recharge_count as arecharge_count') ->order('activity.createtime','desc') ->paginate(10,false,['query'=>['type'=>$this->activity_type]]); } $rangeTitleArr = $this->model->getPopRangeList(); foreach ($res as $index => $vo) { $vo['url'] = ''; //弹窗位置 $popRangeStr = ''; if ($vo['pop_range'] || $vo['pop_range'] == '0') { $rangeArr = explode(',', $vo['pop_range']); foreach ($rangeArr as $k) { $popRangeStr .= $rangeTitleArr[$k] .' '; } } else { $popRangeStr = '-'; } $vo['pop_range_txt'] = $popRangeStr; if ($vo['endtime'] > time()) { switch ($vo['type']) { case 0: $vo['url'] = getCurrentDomain($channel_id, '/s/' . $vo['id']); break; case 1: $activity_config = Config::get('site.activity_config'); if (isset($activity_config['config'][$vo['config_id']]) && $activity_config['config'][$vo['config_id']]['status'] == 1) { $vo['url'] = getCurrentDomain($channel_id, '/s/' . $vo['id'] . '/r/' . $activity_config['config'][$vo['config_id']]['resource_id']); } break; case 3: $activity_give_config = Config::get('site.activity_give_config'); if (isset($activity_give_config['config'][$vo['config_id']]) && $activity_give_config['config'][$vo['config_id']]['status'] == 1) { $vo['url'] = getCurrentDomain($channel_id, '/s/' . $vo['id'] . '/r/' . $activity_give_config['config'][$vo['config_id']]['resource_id']); } break; } } $res[$index] = $vo; } if ($this->request->isAjax()) { return json($res); } $subscrip = model('ChannelSpecialManage')->isWhite('subscribe', $this->auth->id); $camUrl = CardFlipService::instance()->checkAuth($this->auth->id); $this->assign('camUrl',$camUrl); $this->assign('subscrip',$subscrip); $this->assign('activity_config',$activity_config); $this->assign('activity_give_config',$activity_give_config); $this->assign('channel_id',$channel_id); $this->assign('admin_id',$this->auth->id); $this->assign('res',$res); $this->assign('activity_show_recharge_page', $activityShowRechargePage); return $this->view->fetch(); } } /** * 活动列表(所有活动) * @return \think\response\Json */ public function index_ajax() { list($where, $whereFilter, $ac_map) = $this->_buildCommonCondition(); $res = model('activity')//渠道自定义活动 + 赠币活动 ->where('activity.id <> 100') ->where($where) ->where($whereFilter) ->where($ac_map) ->order('activity.createtime', 'desc') ->select(); $respt = model('activity')//平台活动 ->where('activity.id <> 100') ->where('activity.type',self::ACTIVITY_TYPE_PLATFORM) ->where($where) ->where($whereFilter) ->order('activity.createtime', 'desc') ->select(); $res = array_merge($respt, $res); $return = $this->_formatActivityUrl($res); if ($this->request->isAjax()) { return json($return); } } /** * 活动列表(渠道自定义活动 & 平台活动) * @return \think\response\Json */ public function index_channel_activity() { list($where, $whereFilter, $ac_map) = $this->_buildCommonCondition(); $res = model('activity')//渠道自定义活动 ->where('activity.id <> 100') ->where('activity.type',self::ACTIVIYT_TYPE_CHANNEL) ->where($where) ->where($whereFilter) ->where($ac_map) ->order('activity.createtime', 'desc') ->select(); $respt = model('activity')//平台活动 ->where('activity.id <> 100') ->where('activity.type',self::ACTIVITY_TYPE_PLATFORM) ->where($where) ->where($whereFilter) ->order('activity.createtime', 'desc') ->select(); $res = array_merge($respt, $res); $return = $this->_formatActivityUrl($res); if ($this->request->isAjax()) { return json($return); } } /** * 赠币活动列表 * @return \think\response\Json */ public function index_give_activity() { list($where, $whereFilter, $ac_map) = $this->_buildCommonCondition(); $res = model('activity') ->where('activity.id <> 100') ->where('activity.type',self::ACTIVIYT_TYPE_GIVE) ->where($where) ->where($whereFilter) ->where($ac_map) ->order('activity.createtime', 'desc') ->select(); $return = $this->_formatActivityUrl($res); if ($this->request->isAjax()) { return json($return); } } /** * 格式化活动链接 * @param $res * @return array */ private function _formatActivityUrl($res){ $return = []; if ($res) { $channel_id = $this->auth->agent_id ? $this->auth->agent_id : $this->auth->channel_id; foreach ($res as $index => $vo) { if ($vo['endtime'] > time()) { switch ($vo['type']) { case 0: $vo['url'] = getCurrentDomain($channel_id, '/s/' . $vo['id']); $return[] = $vo; break; case 1: $activity_config = Config::get('site.activity_config'); if (isset($activity_config['config'][$vo['config_id']]) && $activity_config['config'][$vo['config_id']]['status'] == 1) { $vo['url'] = getCurrentDomain($channel_id, '/s/' . $vo['id'] . '/r/' . $activity_config['config'][$vo['config_id']]['resource_id']); $return[] = $vo; } break; case 3: $activity_give_config = Config::get('site.activity_give_config'); if (isset($activity_give_config['config'][$vo['config_id']]) && $activity_give_config['config'][$vo['config_id']]['status'] == 1) { $vo['url'] = getCurrentDomain($channel_id, '/s/' . $vo['id'] . '/r/' . $activity_give_config['config'][$vo['config_id']]['resource_id']); $return[] = $vo; } break; } } } } return $return; } /** * 构造活动查询列表查询条件 * @return array */ private function _buildCommonCondition() { $distribute = 0; $adminExtend = model('admin_extend')->where(['admin_id' => $this->auth->id])->find(); if (!empty($adminExtend->distribute) && $adminExtend->distribute == '1') { $distribute = 1; } $ac_map = ['activity.status' => '1']; //渠道商处理 if ($this->group == AdminConstants::ADMIN_GROUP_ID_CHANNEL) { $ac_map['activity.admin_id'] = $this->auth->id; } //配号代理商 if ($this->group == AdminConstants::ADMIN_GROUP_ID_AGENT && $distribute == 1) { $ac_map['activity.admin_id'] = ['in', "{$this->auth->id},{$this->auth->channel_id}"]; } elseif ($this->group == AdminConstants::ADMIN_GROUP_ID_AGENT) { //代理商 $ac_map['activity.admin_id'] = $this->auth->channel_id; } list($whereFilter, $sort, $order, $offset, $limit) = $this->buildparams(); $where = []; if ($this->request->request('name')) { $where['name'] = ['LIKE', '%' . $this->request->request('name') . '%']; } return [$where, $whereFilter, $ac_map]; } public function config(){ if ($this->activity_type == self::ACTIVIYT_TYPE_CHANNEL) { $map = ['group'=>'activity','name'=>'activity_config']; $config_res = model('Config')->where($map)->value('value'); } elseif ($this->activity_type == self::ACTIVIYT_TYPE_GIVE){ $map = ['group'=>'activity','name'=>'activity_give_config']; $config_res = model('Config')->where($map)->value('value'); }else{ $config_res = []; $this->error("错误的请求"); } if($this->request->isAjax()){ $params = $this->request->param(); if(!isset($params['config'])){ $this->error('参数错误'); } $config = $params['config']; unset($params['config']); foreach($config['id'] as $key => $id){ if(isset($config['name'][$key]) && isset($config['resource_id'][$key]) && isset($config['resource_id'][$key])){ $params['config'][$id] = [ 'name' => $config['name'][$key], 'resource_id' => $config['resource_id'][$key], 'status' => $config['status'][$key], 'limit_day' => $config['limit_day'][$key] ]; } } if(model('Config')->where($map)->find()){ $is_ok = model('Config')->where($map)->update(['value'=>json_encode($params)]); }else{ if($this->activity_type == self::ACTIVIYT_TYPE_CHANNEL){ $is_ok = model('Config')->insert(array_merge($map,[ 'content'=>'活动自定义配置', 'value'=>json_encode($params), 'type' => 'array', ])); } elseif ($this->activity_type == self::ACTIVIYT_TYPE_GIVE) { $is_ok = model('Config')->insert(array_merge($map,[ 'content'=>'赠币活动自定义配置', 'value'=>json_encode($params), 'type' => 'array' ])); }else{ $is_ok = false; } } $redis = Redis::instance(); $redis->del('site'); if($is_ok !== false){ $this->success('操作成功'); }else{ $this->error('操作失败'); } } $this->assign('configRes',json_decode($config_res,true)); return $this->view->fetch(); } public function changestatus(){ $id = $_POST['id']; $status = $_POST['status']; $row = $this->model->where('id', 'eq', $id)->find(); $res = Db::table('activity')->where(['id'=>$id])->update(['status'=>$status]); //删除前台弹窗redis if ($row['type'] == self::ACTIVIYT_TYPE_CHANNEL) { $popKey = "S-P-T-C:N:{$row['admin_id']}"; Redis::instance()->del($popKey); } elseif ($row['type'] == self::ACTIVIYT_TYPE_GIVE) { $popKey = "S-P-T-G:N:{$row['admin_id']}"; Redis::instance()->del($popKey); } elseif ($this->activity_type == self::ACTIVITY_TYPE_PLATFORM) { $popKey = "S-P-T-P:N:"; Redis::instance()->del($popKey); } return $res; } public function changepopstatus(){ $id = $_POST['id']; $status = $_POST['status']; $row = $this->model->where('id', 'eq', $id)->find(); $res = Db::table('activity')->where(['id'=>$id])->update(['pop_status'=>$status]); //删除前台弹窗redis if ($row['type'] == self::ACTIVIYT_TYPE_CHANNEL) { $popKey = "S-P-T-C:N:{$row['admin_id']}"; Redis::instance()->del($popKey); } elseif ($row['type'] == self::ACTIVIYT_TYPE_GIVE) { $popKey = "S-P-T-G:N:{$row['admin_id']}"; Redis::instance()->del($popKey); } elseif ($this->activity_type == self::ACTIVITY_TYPE_PLATFORM) { $popKey = "S-P-T-P:N:"; Redis::instance()->del($popKey); } return $res; } public function showrechargepage() { if ($this->request->isPost()) { $id = $_POST['id']; $status = $_POST['status']; $iStatus = $status == 'on' ? 1 : 0; $res = $this->model->where(['id' => $id])->update(['show_for_recharge_page' => $iStatus]); return $res; } return false; } /** * 添加 */ public function add() { $redis = Redis::instance(); if($this->activity_type == self::ACTIVIYT_TYPE_CHANNEL){ $activity_config = Config::get('site.activity_config'); } elseif ($this->activity_type == self::ACTIVIYT_TYPE_GIVE){ $activity_config = Config::get('site.activity_give_config'); }else{ $activity_config = []; } if ($this->request->isPost()) { $params = $this->request->post("row/a"); if ($params) { $params['status'] = 1;//自定义活动 状态永远是正常 if (!in_array($this->activity_type, [self::ACTIVIYT_TYPE_CHANNEL, self::ACTIVIYT_TYPE_GIVE])) { //非自定义活动或赠币活动 if (in_array($this->group, [3, 4, 7, 8])) { //这些角色不能创建 $this->error("没有权限!"); } } $redisKeyPrefix = 'AT-M:'; if (in_array($this->group, [7, 8])) { //VIP或VIP创建模板 if ($this->activity_type == self::ACTIVIYT_TYPE_CHANNEL || $this->activity_type == self::ACTIVIYT_TYPE_GIVE) { $params['admin_id'] = $this->auth->id; $config_id = $params['config_id'] ?? null; if(!$config_id){ $this->error("活动金额不能为空!"); } //渠道商自定义活动限制活动时间 $vali_time = strtotime($params['endtime']) - strtotime($params['starttime']); //config_id来判断活动时间 if ($this->activity_type == self::ACTIVIYT_TYPE_CHANNEL) { $map = ['group'=>'activity','name'=>'activity_config']; $config_res = model('Config')->where($map)->value('value'); } elseif ($this->activity_type == self::ACTIVIYT_TYPE_GIVE){ $map = ['group'=>'activity','name'=>'activity_give_config']; $config_res = model('Config')->where($map)->value('value'); } $configArr = json_decode($config_res,true); $source = $configArr['config'][$params['config_id']] ?? []; if ($source && isset($source['limit_day']) && $source['limit_day']) { if($vali_time > (intval($source['limit_day'])*86400)){ $this->error("活动时间间隔不能大于 {$source['limit_day']} 天"); } } else { if($vali_time > (intval($activity_config['time_interval'])*86400)){ $this->error("活动时间间隔不能大于 {$activity_config['time_interval']} 天"); } } } } else { //检查渠道商和配号代理商 if ($this->activity_type == self::ACTIVIYT_TYPE_CHANNEL || $this->activity_type == self::ACTIVIYT_TYPE_GIVE) { if ($this->activity_type == self::ACTIVIYT_TYPE_CHANNEL) { $redisKeyPrefix = 'AT-M:'; } else if ($this->activity_type == self::ACTIVIYT_TYPE_GIVE) { $redisKeyPrefix = 'AT-M-G:'; } $count = intval($redis->hget($redisKeyPrefix.date('Ym'),$this->auth->id)); $limited_number = intval($activity_config['limited_number'] ?? 0); if($limited_number <= $count){ $this->error("当月只能创建 {$limited_number} 条活动"); } $params['admin_id'] = $this->auth->id; $config_id = $params['config_id'] ?? null; if(!$config_id){ $this->error("活动金额不能为空!"); } //渠道商自定义活动限制活动时间 $vali_time = strtotime($params['endtime']) - strtotime($params['starttime']); //config_id来判断活动时间 if ($this->activity_type == self::ACTIVIYT_TYPE_CHANNEL) { $map = ['group'=>'activity','name'=>'activity_config']; $config_res = model('Config')->where($map)->value('value'); } elseif ($this->activity_type == self::ACTIVIYT_TYPE_GIVE){ $map = ['group'=>'activity','name'=>'activity_give_config']; $config_res = model('Config')->where($map)->value('value'); } $configArr = json_decode($config_res,true); $source = $configArr['config'][$params['config_id']] ?? []; if ($source && isset($source['limit_day']) && $source['limit_day']) { if($vali_time > (intval($source['limit_day'])*86400)){ $this->error("活动时间间隔不能大于 {$source['limit_day']} 天"); } } else { if($vali_time > (intval($activity_config['time_interval'])*86400)){ $this->error("活动时间间隔不能大于 {$activity_config['time_interval']} 天"); } } } } $params['type'] = $this->activity_type; if ($this->dataLimit) { $params[$this->dataLimitField] = $this->auth->id; } if($params['starttime']>=$params['endtime']){ $this->error('活动开始时间不能大于活动结束时间'); } $params['popstarttime'] = $params['starttime']; $params['popendtime'] = $params['endtime']; if (isset($params['pop_range']) && !empty($params['pop_range'])) { $params['pop_range'] = implode(',', $params['pop_range']); } try { //是否采用模型验证 if ($this->modelValidate) { $name = basename(str_replace('\\', '/', get_class($this->model))); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate; $this->model->validate($validate); } $id = $this->model->allowField(true)->save($params); if ($id !== false) { $redis->hIncrBy($redisKeyPrefix.date('Ym'),$this->auth->id,1); $redis->expire($redisKeyPrefix.date('Ym'),31*86400); //删除前台弹窗redis if ($this->activity_type == self::ACTIVIYT_TYPE_CHANNEL) { $popKey = "S-P-T-C:N:{$this->auth->id}"; $redis->del($popKey); } elseif ($this->activity_type == self::ACTIVIYT_TYPE_GIVE) { $popKey = "S-P-T-G:N:{$this->auth->id}"; $redis->del($popKey); } elseif ($this->activity_type == self::ACTIVITY_TYPE_PLATFORM) { $popKey = "S-P-T-P:N:"; Redis::instance()->del($popKey); } $this->success(); } else { $this->error($this->model->getError()); } } catch (\think\exception\PDOException $e) { $this->error($e->getMessage()); } } $this->error(__('Parameter %s can not be empty', '')); } if(isset($activity_config['config']) && $activity_config['config']){ $activity_config['config'] = array_filter($activity_config['config'],function($val){ if(intval($val['status'])){ return true; } }); } $this->assign('activity_config',$activity_config); return $this->view->fetch(); } /** * 编辑 */ public function edit($ids = NULL) { if($this->activity_type == self::ACTIVIYT_TYPE_CHANNEL){ $activity_config = Config::get('site.activity_config'); } elseif ($this->activity_type == self::ACTIVIYT_TYPE_GIVE){ $activity_config = Config::get('site.activity_give_config'); }else{ $activity_config = []; } $row = $this->model->get($ids); if (!$row) $this->error(__('No Results were found')); $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { if (!in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } } if ($this->request->isPost()) { $params = $this->request->post("row/a"); if ($params) { if($this->activity_type == self::ACTIVIYT_TYPE_CHANNEL || $this->activity_type == self::ACTIVIYT_TYPE_GIVE){ //渠道自定义活动 || 赠币活动 //渠道商自定义活动限制活动时间 $vali_time = strtotime($params['endtime']) - strtotime($params['starttime']); //资源自定义时间 $source = $activity_config['config'][$row['config_id']] ?? []; if ($source && isset($source['limit_day']) && $source['limit_day']) { if($vali_time > (intval($source['limit_day'])*86400)){ $this->error("活动时间间隔不能大于 {$source['limit_day']} 天"); } } else { if($vali_time > (intval($activity_config['time_interval'])*86400)){ $this->error("活动时间间隔不能大于 {$activity_config['time_interval']} 天"); } } $time = time(); if($row['endtime'] < $time){ $this->error('已结束的活动不能编辑'); }elseif($row['starttime'] < $time && $row['endtime'] > $time){ $this->error('进行中的活动不能编辑'); } } if($params['starttime']>=$params['endtime']){ $this->error('活动开始时间不能大于活动结束时间'); } $params['popstarttime'] = $params['starttime']; $params['popendtime'] = $params['endtime']; if (isset($params['pop_range']) && !empty($params['pop_range'])) { $params['pop_range'] = implode(',', $params['pop_range']); } try { //是否采用模型验证 if ($this->modelValidate) { $name = basename(str_replace('\\', '/', get_class($this->model))); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : true) : $this->modelValidate; $row->validate($validate); } $result = $row->allowField(true)->save($params); if ($result !== false) { //清理缓存 $key1 = 'A-I:'.$ids; Redis::instance()->del($key1); $key2 = 'A-R:'.$ids; Redis::instance()->del($key2); //删除前台弹窗redis if ($this->activity_type == self::ACTIVIYT_TYPE_CHANNEL) { $popKey = "S-P-T-C:N:{$this->auth->id}"; Redis::instance()->del($popKey); } elseif ($this->activity_type == self::ACTIVIYT_TYPE_GIVE) { $popKey = "S-P-T-G:N:{$this->auth->id}"; Redis::instance()->del($popKey); } elseif ($this->activity_type == self::ACTIVITY_TYPE_PLATFORM) { $popKey = "S-P-T-P:N:"; Redis::instance()->del($popKey); } //判断是否是VIP活动 如果是需要同步更新 $slaveRows = model("VipActivityRelation")->field("slave_activity_id, slave_admin_id")->where('master_admin_id', 'eq', $this->auth->id)->where('master_activity_id', 'eq', $ids)->select(); if ($slaveRows) { unset($params['id']); foreach ($slaveRows as $slaveRow) { $slaveAdminId = $slaveRow['slave_admin_id']; $slaveActivity = $this->model->get($slaveRow['slave_activity_id']); $slaveActivity->allowField(true)->save($params); $key1 = 'A-I:'.$slaveActivity['id']; Redis::instance()->del($key1); $key2 = 'A-R:'.$slaveActivity['id']; Redis::instance()->del($key2); //删除前台弹窗redis if ($this->activity_type == self::ACTIVIYT_TYPE_CHANNEL) { $popKey = "S-P-T-C:N:{$slaveAdminId}"; Redis::instance()->del($popKey); } elseif ($this->activity_type == self::ACTIVIYT_TYPE_GIVE) { $popKey = "S-P-T-G:N:{$slaveAdminId}"; Redis::instance()->del($popKey); } } } $this->success(); } else { $this->error($row->getError()); } } catch (\think\exception\PDOException $e) { $this->error($e->getMessage()); } } $this->error(__('Parameter %s can not be empty', '')); } if(isset($activity_config['config']) && $activity_config['config']){ $activity_config['config'] = array_filter($activity_config['config'],function($val){ if(intval($val['status'])){ return true; } }); } $this->assign('activity_config',$activity_config); //弹窗位置转换 $popRangeSelected = []; if (strlen($row['pop_range']) > 0) { $popRangeSelected = explode(',', $row['pop_range']); } $this->view->assign("row", $row); $this->view->assign("popRangeSelected", $popRangeSelected); return $this->view->fetch(); } public function select() { $params = $this->request->get(); $type = $params['type'] ?? 0; $status = $params['status'] ?? '1'; if ($this->request->isAjax()) { list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $maps['activity.type'] = ['eq', $type]; $maps['activity.status'] = ['eq', $status]; $list = []; $total = model('activity') ->where($maps) ->where($where) ->order('activity.createtime', 'desc') ->count(); if ($total) { $list = model('activity') ->where($maps) ->where($where) ->order('activity.createtime', 'desc') ->limit($offset, $limit) ->select(); } $result = array("total" => $total, "rows" => $list); return json($result); } $this->assignconfig('type', $type); return $this->view->fetch(); } /** * 设置弹窗位置 * @return int|string * @throws \think\Exception * @throws \think\exception\PDOException */ public function set_pop_range() { $id = $_POST['id']; $status = $_POST['status']; $pop_range = $_POST['pop_range']; $pop_ispay = $_POST['pop_ispay']; $row = $this->model->where('id', 'eq', $id)->find(); //需要验证权限 if (in_array($this->group, [3, 4, 7, 8])) { if ($row['admin_id'] != $this->auth->id) { $this->error(__('You have no permission')); } } $res = Db::table('activity')->where(['id'=>$id])->update(['pop_status'=>$status, 'pop_range' => $pop_range, 'pop_ispay' => $pop_ispay ]); //删除前台弹窗redis if ($row['type'] == self::ACTIVIYT_TYPE_CHANNEL) { $popKey = "S-P-T-C:N:{$row['admin_id']}"; Redis::instance()->del($popKey); } elseif ($row['type'] == self::ACTIVIYT_TYPE_GIVE) { $popKey = "S-P-T-G:N:{$row['admin_id']}"; Redis::instance()->del($popKey); } elseif ($this->activity_type == self::ACTIVITY_TYPE_PLATFORM) { $popKey = "S-P-T-P:N:"; Redis::instance()->del($popKey); } return $res; } }