123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use app\main\constants\PostbackConstants;
- use app\main\service\AdminService;
- use app\main\service\ReportKlService;
- use app\main\service\ToutiaoNotifyService;
- use think\Controller;
- use think\Request;
- /**
- *
- *
- * @icon fa fa-circle-o
- */
- class Postbackklreferral extends Backend
- {
- /**
- * @var \app\admin\model\Postbackklreferral
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('Postbackklreferral');
- $this->view->assign("stateList", $this->model->getStateList());
- $this->view->assign('rule_id', $this->request->get('rule_id'));
- $this->view->assign('type', $this->request->get('type'));
- $this->assignconfig('rule_id', $this->request->get('rule_id'));
- $this->assignconfig('type', $this->request->get('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();
- }
- $where_u = [
- 'type' => $this->request->get('type'),
- 'rule_id' => $this->request->get('rule_id'),
- ];
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $total = $this->model
- ->where($where_u)
- ->where($where)
- ->order($sort, $order)
- ->count();
- $list = $this->model
- ->where($where_u)
- ->where($where)
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->select();
- foreach ($list as $index => $item) {
- if ($item['money'] == '-1') {
- $list[$index]['money'] = ReportKlService::instance()->getValue($item['rule_id'], $item['type'], 'money')->data;
- if ($list[$index]['money'] == '-1') {
- $list[$index]['money'] = '未配置';
- } else {
- $list[$index]['money'] .= '(渠道配置)';
- }
- }
- if ($item['man_val'] == '-1') {
- $list[$index]['man_val'] = ReportKlService::instance()->getValue($item['rule_id'], $item['type'], 'man_val')->data;
- if ($list[$index]['man_val'] == '-1') {
- $list[$index]['man_val'] = '未配置';
- } else {
- $list[$index]['man_val'] .= '(渠道配置)';
- }
- }
- if ($item['kou_val'] == '-1') {
- $list[$index]['kou_val'] = ReportKlService::instance()->getValue($item['rule_id'], $item['type'], 'kou_val')->data;
- if ($list[$index]['kou_val'] == '-1') {
- $list[$index]['kou_val'] = '未配置';
- } else {
- $list[$index]['kou_val'] .= '(渠道配置)';
- }
- }
- }
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 添加
- */
- public function add()
- {
- if ($this->request->isPost()) {
- $params = $this->request->post("row/a");
- $params['rule_id'] = $this->request->get("rule_id");
- $params['type'] = $this->request->get("type");
- $params['referral_id'] = explode(",", $params['referral_id']);
- $params['state'] = PostbackConstants::STATE_SHOW;
- $params['updatetime'] = $params['createtime'] = time();
- $oRule = model('postbackrules')->where('id', $params['rule_id'])->find();
- $channel_ids = $oRule['channel_ids'];
- if (!$channel_ids) {
- $this->error('请先添加渠道');
- }
- if ($channel_ids != '*') {
- $where['admin_id'] = ['in', $channel_ids];
- } else {
- $where = [];
- }
- $referralList = model('referral')
- ->where($where)
- ->whereIn('id', $params['referral_id'])
- ->column('id,admin_id');
- $exists = $this->model
- ->where('type', $params['type'])
- ->where('rule_id', $params['rule_id'])
- ->whereIn('referral_id', $params['referral_id'])
- ->column('referral_id');
- $ids = array_diff(array_keys($referralList), $exists);
- if ($ids) {
- $inserts = [];
- foreach ($ids as $id) {
- $params['referral_id'] = $id;
- $params['admin_id'] = $referralList[$id];
- $inserts[] = $params;
- }
- $this->model->insertAll($inserts);
- } else {
- $this->error('未查询到需要添加的推广链接');
- }
- $this->success();
- }
- return $this->view->fetch();
- }
- public function changestate($id, $state)
- {
- $row = $this->model->where([
- 'id' => $id,
- 'state' => $state,
- ])->find();
- if (!$row) {
- $this->error('未查询到可更新数据');
- }
- $update = [
- 'updatetime' => time(),
- ];
- if ($state == PostbackConstants::STATE_SHOW) {
- $update['state'] = PostbackConstants::STATE_HIDE;
- } else {
- $update['state'] = PostbackConstants::STATE_SHOW;
- }
- $status = $this->model->update($update, ['id' => $id]);
- if ($status) {
- $this->success();
- } else {
- $this->error('更新失败');
- }
- }
- }
|