123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use app\main\constants\AdminConstants;
- use app\main\service\TransferService;
- /**
- * 粉丝迁移
- *
- * @icon fa fa-circle-o
- */
- class Transfer extends Backend{
- /**
- * Transfer模型对象
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('Transfer');
- }
- /**
- * 添加
- */
- public function add()
- {
- if ($this->request->isPost())
- {
- $params = $this->request->post("row/a");
- if ($params)
- {
- if ($this->dataLimit)
- {
- $params[$this->dataLimitField] = $this->auth->id;
- }
- 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);
- }
- if(!$this->auth->isSuperAdmin()){
- $params['admin_id'] = $this->auth->id;
- //检查转移渠道开户人
- $this->checkCreateBy($params['transfer_id']);
- //检查接收渠道开户人
- $this->checkCreateBy($params['receive_id']);
- }else{
- $params['admin_id'] = 0;
- //检查转移渠道
- if(!$this->checkChannelOrAgent($params['transfer_id'])){
- $this->error("请选择渠道商OR配号代理商[ {$params['transfer_id']} ]");
- }
- //检查接收渠道
- if(!$this->checkChannelOrAgent($params['receive_id'])){
- $this->error("请选择渠道商OR配号代理商[ {$params['receive_id']} ]");
- }
- }
- $result = $this->model->allowField(true)->save($params);
- if ($result !== false)
- {
- $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', ''));
- }
- return $this->view->fetch();
- }
- public function index(){
- //设置过滤方法
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax())
- {
- if(!$this->auth->isSuperAdmin()){
- $map['admin_id'] = $this->auth->id;
- }else{
- $map = null;
- }
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('pkey_name'))
- {
- return $this->selectpage();
- }
- $filter = $this->request->get("filter", '');
- $sort = $this->request->get("sort", "id");
- $order = $this->request->get("order", "DESC");
- $offset = $this->request->get("offset", 0);
- $limit = $this->request->get("limit", 0);
- $filter = json_decode($filter, TRUE);
- $where = [];
- if($filter){
- foreach ($filter as $k => $v){
- if($k == 'transfer_nickname' || $k == 'receive_nickname' || $k == 'id'){
- if($k == 'transfer_nickname'){
- $where['ad.nickname'] = ['like',"%{$v}%"];
- }
- if($k == 'receive_nickname'){
- $where['ads.nickname'] = ['like',"%{$v}%"];
- }
- if($k == 'id'){
- $where['transfer.id'] = $v;
- }
- }else{
- $where[$k] = $v;
- }
- }
- }
- if($sort == 'id'){
- $sort = 'transfer.id';
- }
- $total = $this->model
- ->join('admin ad','ad.id = transfer.transfer_id')
- ->join('admin ads','ads.id = transfer.receive_id')
- ->where($map)
- ->where($where)
- ->field('transfer.*,ad.nickname as transfer_nickname,ads.nickname as receive_nickname')
- ->order($sort, $order)
- ->count();
- $list = $this->model
- ->join('admin ad','ad.id = transfer.transfer_id')
- ->join('admin ads','ads.id = transfer.receive_id')
- ->where($map)
- ->where($where)
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->field('transfer.*,ad.nickname transfer_nickname,ads.nickname receive_nickname')
- ->select();
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- return $this->fetch();
- }
- public function backups(){
- $next = null;
- if(!$id = $this->request->param('ids')){
- $this->error('参数错误');
- }
- if($this->request->has('next')){
- $next = $this->request->param('next');
- }
- if(!$result = $this->model->where('id',$id)->find()){
- $this->error('数据获取失败');
- }
- if(intval($result['transfer_status']) == 2){
- $this->error('这条数据已完成了粉丝迁移');
- }
- $is_update = $this->model->where('id',$id)->update(['backup_status'=>'1','remark'=>'']);
- if($is_update !== false ){
- TransferService::instance()->setBackups($id,$next)->push();
- $this->success('操作成功');
- }else{
- $this->error('操作失败');
- }
- }
- public function transfer(){
- $next = null;
- if(!$id = $this->request->param('ids')){
- $this->error('参数错误');
- }
- if(!$result = $this->model->where('id',$id)->find()){
- $this->error('数据获取失败');
- }
- if($this->request->has('next')){
- $next = intval($this->request->param('next'));
- }
- if(intval($result['backup_status']) != 2){
- $this->error('请先完成粉丝备份');
- }
- if(intval($result['transfer_status']) == 2){
- $this->error('这条数据已完成了粉丝迁移');
- }
- $is_update = $this->model->where('id',$id)->update(['transfer_status'=>'1','remark'=>'']);
- if($is_update !== false ){
- TransferService::instance()->setTransfer($id,$next)->push();
- $this->success('操作成功');
- }else{
- $this->error('操作失败');
- }
- }
- public function checkCreateBy($admin_id){
- $create_by = null;
- $group_id = model('AuthGroupAccess')->getGroupId($admin_id);
- //获取渠道开户人
- if(AdminConstants::ADMIN_GROUP_ID_CHANNEL == $group_id){
- $create_by = model('AdminExtend')->where('admin_id',$admin_id)->value('create_by');
- }else if(AdminConstants::ADMIN_GROUP_ID_AGENT == $group_id){
- //检查配号代理商,并检查开户人
- $adminExtend = model('AdminExtend')->where('admin_id',$admin_id)->column('distribute,create_by');
- if(!$adminExtend){
- $this->error("获取代理商[ {$admin_id} ]信息失败");
- }
- if(!key($adminExtend)){
- $this->error("请输入配号代理商的ID,普通代理商[ {$admin_id} ]不能进行迁移");
- }
- $create_by = model('AdminExtend')->where('admin_id',current($adminExtend))->value('create_by');
- }else{
- $this->error("请选择渠道商OR配号代理商[ {$admin_id} ]");
- }
- if(intval($this->auth->id) != intval($create_by)){
- $this->error("请选择自己名下的渠道商OR配号代理商[ {$admin_id} ]");
- }
- }
- public function checkChannelOrAgent($admin_id){
- $group_id = model('AuthGroupAccess')->getGroupId($admin_id);
- if(AdminConstants::ADMIN_GROUP_ID_CHANNEL == $group_id){
- return true;
- }
- if(AdminConstants::ADMIN_GROUP_ID_AGENT == $group_id){
- $distribute = model('AdminExtend')->where('admin_id',$admin_id)->value('distribute');
- if($distribute){
- return true;
- }
- }
- return false;
- }
- }
|