public function add($model = null)
 {
     $id = I('id', 0, 'intval');
     $this->assign('id', $id);
     $model = $this->model;
     if (IS_POST) {
         foreach ($_POST as &$v) {
             $v = trim($v);
         }
         $_POST['token'] = $_POST['public_id'];
         $_POST['group_id'] = intval(C('DEFAULT_PUBLIC_GROUP_ID'));
         $_POST['uid'] = $this->mid;
         $Model = D(parse_name(get_table_name($model['id']), 1));
         // 获取模型的字段信息
         $Model = $this->checkAttr($Model, $model['id']);
         if (empty($id)) {
             if ($Model->create() && ($id = $Model->add())) {
                 // 增加公众号与用户的关联关系
                 $data['uid'] = $this->mid;
                 $data['mp_id'] = $id;
                 $data['is_creator'] = 1;
                 M('member_public_link')->add($data);
                 $this->success('添加基本信息成功!', U('step_1?id=' . $id));
             } else {
                 $this->error($Model->getError());
             }
         } else {
             $_POST['id'] = $id;
             $Model->create() && ($res = $Model->save());
             if ($res) {
                 $this->success('保存基本信息成功!', U('step_1?id=' . $id));
             } elseif ($res === 0) {
                 $this->success(' ', U('step_1?id=' . $id));
             } else {
                 $this->error($Model->getError());
             }
         }
     } else {
         if (empty($id)) {
             $allow_add_count = getPublicMax($this->mid);
             $has_add_count = M('member_public_link')->where("uid='{$this->mid}'")->getField('sum(is_creator)');
             if ($allow_add_count <= $has_add_count) {
                 $this->error('您最多只能创建 ' . $allow_add_count . ' 个公众号!');
                 exit;
             }
         } else {
             $data = M(get_table_name($model['id']))->find($id);
         }
         $data['type'] = intval($data['type']);
         $this->assign('info', $data);
         $this->display('step_0');
     }
 }
 public function add($model = null)
 {
     $model = $this->model;
     if (IS_POST) {
         $_POST['token'] = $_POST['public_id'];
         $_POST['group_id'] = intval(C('DEFAULT_PUBLIC_GROUP_ID'));
         $Model = D(parse_name(get_table_name($model['id']), 1));
         // 获取模型的字段信息
         $Model = $this->checkAttr($Model, $model['id']);
         if ($Model->create() && ($id = $Model->add())) {
             // 增加公众号与用户的关联关系
             $data['uid'] = $this->mid;
             $data['mp_id'] = $id;
             $data['is_creator'] = 1;
             M('member_public_link')->add($data);
             $this->success('添加' . $model['title'] . '成功!', U('lists?model=' . $model['name']));
         } else {
             $this->error($Model->getError());
         }
     } else {
         $allow_add_count = getPublicMax($this->mid);
         $has_add_count = M('member_public_link')->where("uid='{$this->mid}'")->getField('sum(is_creator)');
         if ($allow_add_count <= $has_add_count) {
             $this->error('您最多只能创建 ' . $allow_add_count . ' 个公众号!');
             exit;
         }
         $fields = get_model_attribute($model['id']);
         $this->assign('fields', $fields);
         $this->meta_title = '新增' . $model['title'];
         $this->_display($model['template_add'] ? $model['template_add'] : '');
     }
 }
Ejemplo n.º 3
0
 function step_0()
 {
     //$map ['uid'] = $this->mid;
     //$data = D ( 'Common/Public' )->where ( $map )->find ();
     //var_dump($data);
     $id = I('id');
     $this->assign('id', $id);
     $model = $this->model;
     //var_dump($model);
     if (IS_POST) {
         foreach ($_POST as &$v) {
             $v = trim($v);
         }
         // 检查专属域名是否已被占用
         if (C('DIV_DOMAIN')) {
             $map2['domain'] = $domain = $_POST['domain'];
             if (empty($domain)) {
                 $this->error('专属域名不能为空');
                 exit;
             }
             if (is_numeric($domain)) {
                 $this->error('专属域名不能为纯数字');
                 exit;
             }
             $plen = strlen($domain);
             // ! preg_match ( "/^(([a-z]+[0-9]+)|([0-9]+[a-z]+))[a-z0-9]*$/i", $domain ) ||
             if ($plen < 3 || $plen > 10) {
                 $this->error('专属域名必须为3-10位的字母和数字的组合');
                 exit;
             }
             empty($id) || ($map2['id'] = array('exp', '!=' . $id));
             $arr = array('www' => 1);
             if (isset($arr[$domain]) || D('Common/Public')->where($map2)->getField('id')) {
                 $this->error('该专属域名已经存在,请换别的再试');
                 exit;
             }
         }
         $_POST['token'] = $_POST['public_id'];
         $_POST['group_id'] = intval(C('DEFAULT_PUBLIC_GROUP_ID'));
         $_POST['uid'] = $this->mid;
         $_POST['has_public'] = 1;
         // 更新缓存
         D('Common/Public')->clear($id);
         session('token', $_POST['token']);
         $Model = D(parse_name(get_table_name($model['id']), 1));
         // 获取模型的字段信息
         $Model = $this->checkAttr($Model, $model['id']);
         if (empty($id)) {
             if ($Model->create() && ($id = $Model->add())) {
                 // 增加公众号与用户的关联关系
                 $data['uid'] = $this->mid;
                 $data['mp_id'] = $id;
                 $data['is_creator'] = 1;
                 M('public_link')->add($data);
                 $url = U('lists');
                 $url = chang_domain($url, $_POST['domain']);
                 $this->success('添加基本信息成功!', $url);
             } else {
                 $this->error($Model->getError());
             }
         } else {
             $_POST['id'] = $id;
             $url = U('lists');
             $url = chang_domain($url, $_POST['domain']);
             $Model->create() && ($res = $Model->save());
             if ($res) {
                 $this->success('保存基本信息成功!', $url);
             } elseif ($res === 0) {
                 $this->success(' ', $url);
             } else {
                 $this->error($Model->getError());
             }
         }
     } else {
         if (empty($id)) {
             $allow_add_count = getPublicMax($this->mid);
             $has_add_count = M('public_link')->where("uid='{$this->mid}'")->getField('sum(is_creator)');
             if ($allow_add_count <= $has_add_count) {
                 $this->error('您最多只能创建 ' . $allow_add_count . ' 个公众号!');
                 exit;
             }
         } else {
             $data = M(get_table_name($model['id']))->find($id);
         }
         $data['type'] = intval($data['type']);
         $this->assign('info', $data);
         $this->display('Publics/step_0');
     }
 }
 public function public_count()
 {
     if (IS_POST) {
         $map['uid'] = $this->mid;
         $public_count = intval($_POST['public_count']);
         M('member')->where($map)->setField('public_count', $public_count);
         $this->success('设置完成', U('Admin/User/index'));
     } else {
         $public_count = getPublicMax($this->mid);
         $this->assign('public_count', $public_count);
         $this->display();
     }
 }
Ejemplo n.º 5
0
 function step_0()
 {
     // $wechat = new TPWechatLogin('*****@*****.**','idouly123');
     // $wechat->setImgPath('./Uploads/Picture/WechatLogin');
     // $wechat->getMpInfo();
     $res['title'] = '公众号基本信息';
     $res['url'] = U('step_0', array('id' => I('id')));
     $res['class'] = 'current';
     $nav[] = $res;
     $res['title'] = '高级功能参数';
     $res['url'] = U('step_1', array('id' => I('id')));
     $res['class'] = '';
     $nav[] = $res;
     $res['title'] = '接口配置';
     $res['url'] = U('mp_interface', array('id' => I('id')));
     $res['class'] = '';
     $nav[] = $res;
     $this->assign('nav', $nav);
     // die;
     $map['id'] = $id = I('id');
     $data = D('Common/Public')->where($map)->find();
     if (!empty($data) && $data['uid'] != $this->mid) {
         $this->error('非法操作');
     }
     $this->assign('id', $id);
     $model = $this->model;
     if (IS_POST) {
         foreach ($_POST as &$v) {
             $v = trim($v);
         }
         // 检查专属域名是否已被占用
         if (C('DIV_DOMAIN')) {
             $map2['domain'] = $domain = I('domain');
             if (empty($domain)) {
                 $this->error('专属域名不能为空');
                 exit;
             }
             if (is_numeric($domain)) {
                 $this->error('专属域名不能为纯数字');
                 exit;
             }
             $plen = strlen($domain);
             // ! preg_match ( "/^(([a-z]+[0-9]+)|([0-9]+[a-z]+))[a-z0-9]*$/i", $domain ) ||
             if ($plen < 3 || $plen > 10) {
                 $this->error('专属域名必须为3-10位的字母和数字的组合');
                 exit;
             }
             $map2['uid'] = array('exp', '!=' . $this->mid);
             $arr = array('www' => 1);
             // CHECKOUT
             if (isset($arr[$domain]) || D('Common/Public')->where($map2)->getField('id')) {
                 $this->error('该专属域名已经存在,请换别的再试');
                 exit;
             }
         }
         $_POST['token'] = $_POST['public_id'];
         $_POST['group_id'] = intval(C('DEFAULT_PUBLIC_GROUP_ID'));
         $_POST['uid'] = $this->mid;
         $_POST['mp_token'] = get_rand_char(32);
         // 生成32位随机字符串用于做接口验证
         $_POST['interface_url'] = U('home/weixin/index');
         // 更新缓存
         D('Common/Public')->clear($id);
         session('token', $_POST['token']);
         $map2['uid'] = $this->mid;
         M('manager')->where($map2)->setField('has_public', 1);
         D('Common/User')->clear($this->mid);
         $Model = D(parse_name(get_table_name($model['id']), 1));
         // 获取模型的字段信息
         $Model = $this->checkAttr($Model, $model['id']);
         if (empty($id)) {
             if ($Model->create() && ($id = $Model->add())) {
                 // 增加公众号与用户的关联关系
                 $data['uid'] = $this->mid;
                 $data['mp_id'] = $id;
                 $data['is_creator'] = 1;
                 M('public_link')->add($data);
                 $url = U('step_1?id=' . $id);
                 $this->success('添加基本信息成功!', $url);
             } else {
                 $this->error($Model->getError());
             }
         } else {
             $_POST['id'] = $id;
             $url = U('lists');
             $Model->create() && ($res = $Model->save());
             if ($res) {
                 $this->success('保存基本信息成功!', $url);
             } elseif ($res === 0) {
                 $this->success(' ', $url);
             } else {
                 $this->error($Model->getError());
             }
         }
     } else {
         if (empty($id)) {
             $allow_add_count = getPublicMax($this->mid);
             $has_add_count = M('public_link')->where("uid='{$this->mid}'")->getField('sum(is_creator)');
             if ($allow_add_count <= $has_add_count) {
                 $this->error('您最多只能创建 ' . $allow_add_count . ' 个公众号!');
                 exit;
             }
         } else {
             $data = M(get_table_name($model['id']))->find($id);
         }
         $data['type'] = intval($data['type']);
         $this->assign('info', $data);
         $this->display('Publics/step_0');
     }
 }