123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- <?php namespace App\Http\Controllers\Admin;
- use App\Models\Work\State as Model;
- use App\Facades\Servers\WechatWork\ContactWay as Work;
- use App\Facades\Servers\WechatWork\User as WorkUser;
- use App\Facades\Servers\WechatWork\CorpTag as WorkTag;
- use App\Http\Requests\Admin\ContactWay as Request;
- use App\Models\Custom;
- /**
- * 联系方式-联系我
- *
- * @author 刘相欣
- *
- */
- class ContactWay extends Auth{
-
- protected function _initialize(){
- parent::_initialize();
- $this->assign('breadcrumb1','联系方式');
- $this->assign('breadcrumb2','渠道活码');
- }
- /**
- * 列表页
- *
- * */
- public function index(Model $Model,Custom $Custom){
- // 接受参数
- $user = request('user','');
- $remark = request('remark','');
- $customUid = request('customUid','');
- // 查询条件
- $map = [];
- // 组合条件
- if( $remark ) $map[] = ['remark','LIKE','%'.$remark.'%'];
- if( $user ) $map[] = ['user','LIKE','%'.$user.'%'];
- if( $customUid ) $map[] = ['custom_uid','=',$customUid];
- // 查询数据
- $list = $Model->query()->where($map)->orderByDesc('id')->paginate(config('page_num',10));
- // 循环处理数据
- foreach ($list as $key => $value) {
- // 接待成员
- $value['user'] = explode(',',$value['user']);
- // 标签信息
- $value['tags'] = explode(',',$value['tags']);
- // 使用对象
- $value['custom_name'] = $Custom->getValue($value['custom_uid'],'username');
- // 重组
- $list[$key] = $value;
- }
- // 获取部门数据
- $partUserList = WorkUser::getListDepart();
- // 获取标签数据
- $corpTagList = WorkTag::getList();
- // 获取商业与地区代表
- $customList = $Custom->getListUserType();
- // 分配数据
- $this->assign('list',$list);
- $this->assign('partUserList',$partUserList);
- $this->assign('customList',$customList);
- $this->assign('corpTagList',$corpTagList);
- $this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
- // 加载模板
- return $this->fetch();
- }
- /**
- * 添加
- *
- * */
- public function add(Request $request,Model $Model,Custom $Custom){
- if( request()->isMethod('post') ){
- // 验证参数
- $request->scene('add')->validate();
- // 状态
- $state['remark'] = request('remark','');
- $state['user_type'] = request('user_type','');
- $state['custom_uid'] = request('custom_uid',0);
- $state['tags'] = request('tags',[]);
- $state['user'] = request('user',[]);
- // 数据处理
- $state['tags'] = implode(',',$state['tags']);
- $state['user'] = implode(',',$state['user']);
- // 获取ID
- $id = $Model->add($state);
- // 如果操作失败
- if( !$id ) return json_send(['code'=>'error','msg'=>'参数创建失败','path'=>'']);
- // 接收数据
- $data['user'] = request('user',[]);
- $data['remark'] = request('remark','');
- $data['state'] = http_build_query(['state_id'=>$id]);
- // 写入数据表
- $data = Work::add($data,2,2);
- // 如果操作失败
- if( !$data ) return json_send(['code'=>'error','msg'=>'活码创建失败','path'=>'']);
- // 写入数据表
- $result = $Model->edit($id,$data);
- // 如果操作失败
- if( !$result ) return json_send(['code'=>'error','msg'=>'活码创建失败','path'=>'']);
- // 告知结果
- return json_send(['code'=>'success','msg'=>'新增成功','action'=>'add']);
- }
- // 获取部门数据
- $partUserList = WorkUser::getListDepart();
- // 获取标签数据
- $corpTagList = WorkTag::getList();
- // 获取商业与地区代表
- $customList = $Custom->getListUserType();
- // 分配数据
- $this->assign('crumbs','新增');
- $this->assign('partUserList',$partUserList);
- $this->assign('corpTagList',$corpTagList);
- $this->assign('customList',$customList);
- // 加载模板
- return $this->fetch();
- }
- /**
- * 添加
- *
- * */
- public function edit(Request $request,Model $Model,Custom $Custom){
- // 接收数据
- $id = request('id','');
- // 获取旧数据
- $oldData = $Model->getOne($id);
- // 修改
- if( request()->isMethod('post') ){
- // 验证参数
- $request->scene('edit')->validate();
- // 如果操作失败
- if( !$oldData ) return json_send(['code'=>'error','msg'=>'数据不存在','path'=>'']);
- // 状态
- $state['remark'] = request('remark','');
- $state['user_type'] = request('user_type','');
- $state['custom_uid'] = request('custom_uid',0);
- $state['tags'] = request('tags',[]);
- $state['user'] = request('user',[]);
- // 数据处理
- $state['tags'] = implode(',',$state['tags']);
- $state['user'] = implode(',',$state['user']);
- // 接收数据
- $data['user'] = request('user',[]);
- $data['remark'] = request('remark','');
- // 写入数据表
- $result = Work::edit($oldData['config_id'],$data);
- // 如果操作失败
- if( !$result ) return json_send(['code'=>'error','msg'=>'活码编辑失败','path'=>'']);
- // 写入数据表
- $result = $Model->edit($id,$state);
- // 如果操作失败
- if( !$result ) return json_send(['code'=>'error','msg'=>'活码编辑失败','path'=>'']);
- // 告知结果
- return json_send(['code'=>'success','msg'=>'编辑成功','action'=>'edit']);
- }
- // 如果不存在的话
- if( !$oldData ) return $this->error('数据未查到');
- // 标签切割
- $oldData['tags'] = explode(',',$oldData['tags']);
- // 接待人员切割
- $oldData['user'] = explode(',',$oldData['user']);
- // 获取部门数据
- $partUserList = WorkUser::getListDepart();
- // 获取标签数据
- $corpTagList = WorkTag::getList();
- // 获取商业与地区代表
- $customList = $Custom->getListUserType();
- // 分配数据
- $this->assign('crumbs','修改');
- $this->assign('oldData',$oldData);
- $this->assign('customList',$customList);
- $this->assign('corpTagList',$corpTagList);
- $this->assign('partUserList',$partUserList);
- // 加载模板
- return $this->fetch();
- }
- /**
- * 设置为客服推送
- * @param string $code 授权码
- *
- * */
- public function set_follow(Request $request,Model $Model){
- // 验证参数
- $request->scene('set_follow')->validate();
- // 接收参数
- $id = request('id',0);
- // 如果需要默认当前的话
- $Model->query()->where([])->update(['is_follow'=>0]);
- // 查询是否已经提交过
- $result = $Model->edit($id,['is_follow'=>1]);
- // 提示
- if( !$result ) return json_send(['code'=>'error','msg'=>'设置失败,请重试','data'=>['error'=>'写入失败']]);
- // 二维码
- $Model->getFollowQrcode(true);
- // 记录行为
- // $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,[],['is_follow'=>1]);
- // 返回结果
- return json_send(['code'=>'success','msg'=>'设置成功','path'=>'']);
- }
- }
|