123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use app\common\model\Referral;
- use think\Controller;
- use think\Request;
- /**
- * 导粉推广文案
- *
- * @icon fa fa-circle-o
- */
- class Postbackreferral extends Backend
- {
- /**
- * @var Referral
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->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();
- }
- }
|