model = model('referral'); $ruleId = $this->request->get('rule_id'); $this->assignconfig('rule_id', $ruleId); $action = $this->request->get('action', 'relation'); $this->assignconfig('action', $action); $this->view->assign('action', $action); $type = $this->request->get('type', 'tout'); $this->assignconfig('type', $type); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法 * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * 查看 */ public function index() { //设置过滤方法 $this->request->filter(['strip_tags']); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('pkey_name')) { return $this->selectpage(); } list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $ruleId = $this->request->get('rule_id'); $action = $this->request->get('action', 'relation'); $rules = model('postbackrules')->where('id', $ruleId)->find(); $referralIds = explode(',', $rules['referral_ids']); if ($rules['channel_ids']) { $channelIds = explode(',', $rules['channel_ids']); if (!$referralIds) { array_push($referralIds, 0); } $aWhere = [ 'admin_id'=>['in', $channelIds] ]; if ($action == 'relation') { if ($rules['referral_ids'] == '*') { $aWhere['id'] = '-1'; } else { $aWhere['id'] = ['not in', $referralIds]; } } else { if ($rules['referral_ids'] != '*') { $aWhere['id'] = ['in', $referralIds]; } } $total = $this->model ->where($aWhere) ->where($where) ->order($sort, $order) ->count(); $list = $this->model ->where($aWhere) ->where($where) ->order($sort, $order) ->limit($offset, $limit) ->select(); $result = array("total" => $total, "rows" => $list); } else { $result = array("total" => 0, "rows" => []); } return json($result); } return $this->view->fetch(); } public function batch_relation() { $referralIds = $this->request->param('referral_ids'); $rule_id = $this->request->param('rule_id'); $action = $this->request->param('action'); $mRule = model('postbackrules'); $ruleData = $mRule->where(['id' => $rule_id])->find(); $originReferralIds = explode(',', $ruleData['referral_ids']); $paramReferralIds = explode(',', $referralIds); //查询有效的推广id if ($ruleData['channel_ids'] != '*') { $channelIds = explode(',', $ruleData['channel_ids']); $existReferralIds = model('referral')->whereIn('admin_id', $channelIds)->whereIn('id', $paramReferralIds)->column('id'); $paramReferralIds = array_intersect($paramReferralIds, $existReferralIds); } if ($action == 'add') { if ($referralIds == '-1') { $update = ['*']; } else { $update = array_unique(array_merge($originReferralIds, $paramReferralIds));; } } else { if ($referralIds == '-1') { $update = []; } else { $update = array_unique(array_diff($originReferralIds, $paramReferralIds)); } } $update = array_filter($update, function($value){ return $value; }); $mRule->update(['referral_ids' => implode(',', $update)], ['id' => $rule_id]); $this->success(); } }