chenl
2018-12-06 891735606aed8b7dd6b1a5ede1011afd84f31d32
添加市场用绑定应用组接口
1 files added
5 files modified
221 ■■■■■ changed files
api/appGroupApi.php 121 ●●●●● patch | view | raw | blame | history
data/tpl/web/default/common/header.tpl.php 17 ●●●● patch | view | raw | blame | history
framework/model/user.mod.php 28 ●●●● patch | view | raw | blame | history
web/common/interface.func.php 3 ●●●● patch | view | raw | blame | history
web/themes/default/common/header.html 13 ●●●●● patch | view | raw | blame | history
web/themes/default/user/register.html 39 ●●●●● patch | view | raw | blame | history
api/appGroupApi.php
New file
@@ -0,0 +1,121 @@
<?php
/**
 * 应用权限组绑定用户组 Api
 *  chenlei
 */
require '../framework/bootstrap.inc.php';
require '../web/common/interface.func.php';
if($_SERVER['REQUEST_METHOD'] != 'POST'){
    http_response_code(405);
} else {
    $retData=checkParam($_POST);
    switch ($retData["regMsg"]){
        case "e00000":
            switch (getUrl($_SERVER['REQUEST_URI']))
            {
                case "setAuth":
                    exit(json_encode(setAuth($retData["regData"]), JSON_UNESCAPED_UNICODE));
                    break;
                default: http_response_code(404);
            }
        case "e00001":
            exit(array(
                "rspCode"=>"e00001",
                "rspMsg"=>"接入平台不存在"
            ));
        case "e00002":
        exit(array(
            "rspCode"=>"e00002",
            "rspMsg"=>"鉴权失败"
        ));
    }
}
function setAuth($regData) {
    $names = empty($regData['name']) ? null : explode(",", $regData['name']);
    $types = empty($regData['type']) ? null: explode(",", $regData['type']);
    $openid = $regData['openid'];
    if (empty($openid) || empty($names) || empty($types)
        || count($names) == 0 ||  count($types) == 0 || count($names) != count($types)) {
        return array(
            "rspCode"=>"e10001",
            "rspMsg"=>"参数有误"
        );
    }
    // 判断该用户和用户组是否存在
    $usersGroup = pdo_fetch("SELECT g.* FROM ".tablename('users')." AS u INNER JOIN ".tablename('users_group')."  AS g ON u.groupid=g.id WHERE u.openid = :openid", array(':openid' => $openid));
    if (empty($usersGroup)) {
        return array(
            "rspCode"=>"e10002",
            "rspMsg"=>"该用户或用户组不存在"
        );
    } else {
        $groupid = $usersGroup['id'];
    }
    $package = (array)iunserializer($usersGroup['package']);
    if (empty($package)) {
        $package = array();
    }
    for ($i = 0; $i < count($names); $i++) {
        $name = $names[$i];
        $type = $types[$i];
        // 根据name查询该应用是否存在
        $module_info = table('modules')->getByName($name);
        if (empty($module_info)) {
            // 返回该应用不存在
            return array(
                "rspCode"=>"e10002",
                "rspMsg"=>"应用不存在"
            );
        }
        // 判断应用组是否存在,不存在则新增
        $name_exist = pdo_get('uni_group', array('modules like' => '%'."\"".$name."\"".'%'));
        if (empty($name_exist)) {
            $data = array(
                'modules' => array('modules' => array(), 'wxapp' => array(), 'webapp' => array(), 'xzapp' => array(), 'phoneapp' => array(), 'aliapp' => array()),
                'templates' => null,
                'name' => $name.'应用组',
            );
            switch ($type) {
                case ACCOUNT_TYPE_OFFCIAL_NORMAL:
                case ACCOUNT_TYPE_OFFCIAL_AUTH:
                    array_push($data['modules']['modules'], $name);
                    break;
                case ACCOUNT_TYPE_APP_NORMAL:
                case ACCOUNT_TYPE_APP_AUTH:
                case ACCOUNT_TYPE_WXAPP_WORK:
                    array_push($data['modules']['wxapp'], $name);
                    break;
                case ACCOUNT_TYPE_WEBAPP_NORMAL:
                    array_push($data['modules']['webapp'], $name);
                    break;
                case ACCOUNT_TYPE_XZAPP_NORMAL:
                case ACCOUNT_TYPE_XZAPP_AUTH:
                    array_push($data['modules']['xzapp'], $name);
                    break;
                case ACCOUNT_TYPE_PHONEAPP_NORMAL:
                    array_push($data['modules']['phoneapp'], $name);
                    break;
            }
            $data['modules'] = iserializer($data['modules']);
            pdo_insert('uni_group', $data);
            $gropIds = pdo_insertid();
        } else {
            $gropIds = $name_exist['id'];
        }
        if (!in_array($gropIds, $package)) {
            array_push($package, $gropIds);
        }
        // 用户组下挂应用组
        $rst = pdo_update('users_group', array('package' => iserializer($package)), array('id' => $groupid));
        return array(
            "rspCode"=>"e00000",
            "rspMsg"=>"请求成功"
        );
    }
}
data/tpl/web/default/common/header.tpl.php
@@ -40,20 +40,19 @@
                    <a href="<?php  if(empty($nav['url'])) { ?><?php  echo url('home/welcome/' . $nav['name']);?><?php  } else { ?><?php  echo $nav['url'];?><?php  } ?>" <?php  if(!empty($nav['blank'])) { ?>target="_blank"<?php  } ?>><?php  echo $nav['title'];?></a>
                    </li>
                    <?php  } } ?>
                       <!--  2018-11-28 添加市场菜单 start -->
                    <!--  2018-11-28 添加市场菜单 start -->
                    <ul class="other nav navbar-nav navbar-left">
                        <?php  if(is_array($nav_top_tiled_other)) { foreach($nav_top_tiled_other as $nav) { ?>
                        <?php if ($nav['title'] != '市场') {?>
                        <li <?php  if(FRAME == $nav['name'] && !defined('IN_MODULE')) { ?> class="active" <?php  } ?>>
                        <a href="<?php  if(empty($nav['url'])) { ?><?php  echo url('home/welcome/' . $nav['name']);?><?php  } else { ?><?php  echo $nav['url'];?><?php  } ?>" <?php  if(!empty($nav['blank'])) { ?>target="_blank"<?php  } ?>> <?php  echo $nav['title'];?> </a>
                        </li>
                        <?php  } } } ?>
                        <?php  if($nav['title'] != '市场') { ?>
                            <li <?php  if(FRAME == $nav['name'] && !defined('IN_MODULE')) { ?> class="active" <?php  } ?>>
                            <a href="<?php  if(empty($nav['url'])) { ?><?php  echo url('home/welcome/' . $nav['name']);?><?php  } else { ?><?php  echo $nav['url'];?><?php  } ?>" <?php  if(!empty($nav['blank'])) { ?>target="_blank"<?php  } ?>> <?php  echo $nav['title'];?> </a>
                            </li>
                        <?php  } ?>
                        <?php  } } ?>
                        <li>
                            <a href="<?php echo SHOP_URL."/index.php?openid=".$_W['user']['openid']?>" target="_blank"> 市场</a>
                            <a href="<?php echo SHOP_URL.'/index.php?openid='.$_W['user']['openid']?>" target="_blank"> 市场</a>
                        </li>
                    </ul>
                       <!-- // 2018-11-28 添加市场菜单 start -->
                </ul>
                <ul class="nav navbar-nav navbar-left hidden">
                    <?php  global $top_nav?>
framework/model/user.mod.php
@@ -54,11 +54,31 @@
        $paramter = makeInterfaceParam($post_data, "1000001");
        $result = json_decode(doCurlPostRequest($url, $paramter, 10), JSON_UNESCAPED_UNICODE);
        if ($result != null && $result != "" && $result['rspCode'] == 'e00000') {
            $user = array_remove($user, "register_shop");
            $result = pdo_insert('users', $user);
            if (!empty($result)) {
                $user['uid'] = pdo_insertid();
            // 新增用户组
            $user_group = array(
                'id' => 0,
                'name' => $user['username']."用户组",
                'package' => null,
                'maxaccount' => 10,
                'maxwxapp' => 10,
                'maxwebapp' => 10,
                'maxphoneapp' => 10,
                'maxxzapp' => 10,
                'maxaliapp' => 10,
                'timelimit' => 3
            );
            $user_group_info = user_save_group($user_group);
            $gropId = pdo_insertid();
            if (!is_error($user_group_info)) {
                $user = array_remove($user, "register_shop");
                $user['groupid'] = intval($gropId);
                $result = pdo_insert('users', $user);
                if (!empty($result)) {
                    $user['uid'] = pdo_insertid();
                }
            }
        }
    } else {
        $result = pdo_insert('users', $user);
web/common/interface.func.php
@@ -63,7 +63,8 @@
function getUrl($url) 
{
    $arr = explode('/', $url);
    return substr($arr[count($arr)-1],0,strpos($arr[count($arr)-1], '?'));
    $end = !strpos($arr[count($arr)-1], '?') ? strlen($arr[count($arr)-1]) : strpos($arr[count($arr)-1], '?');
    return substr($arr[count($arr)-1],0,$end);
}
web/themes/default/common/header.html
@@ -40,13 +40,18 @@
                    <a href="{if empty($nav['url'])}{php echo url('home/welcome/' . $nav['name']);}{else}{$nav['url']}{/if}" {if !empty($nav['blank'])}target="_blank"{/if}>{$nav['title']}</a>
                    </li>
                    {/loop}
                    <!--  2018-11-28 添加市场菜单 start -->
                    <ul class="other nav navbar-nav navbar-left">
                        {loop $nav_top_tiled_other $nav}
                        <li {if FRAME == $nav['name'] && !defined('IN_MODULE')} class="active" {/if}>
                        <a href="{if empty($nav['url'])}{php echo url('home/welcome/' . $nav['name']);}{else}{$nav['url']}{/if}" {if !empty($nav['blank'])}target="_blank"{/if}> {$nav['title']} </a>
                        </li>
                        {if $nav['title'] != '市场'}
                            <li {if FRAME == $nav['name'] && !defined('IN_MODULE')} class="active" {/if}>
                            <a href="{if empty($nav['url'])}{php echo url('home/welcome/' . $nav['name']);}{else}{$nav['url']}{/if}" {if !empty($nav['blank'])}target="_blank"{/if}> {$nav['title']} </a>
                            </li>
                        {/if}
                        {/loop}
                        <li>
                            <a href="{php echo SHOP_URL.'/index.php?openid='.$_W['user']['openid']}" target="_blank"> 市场</a>
                        </li>
                    </ul>
                </ul>
                <ul class="nav navbar-nav navbar-left hidden">
web/themes/default/user/register.html
@@ -1,5 +1,22 @@
{template 'common/header-base'}
<script>
    <script>
    // 2018-11-28 添加邀请码URL传值设置 chenlei start
    $(function(){
        var invitationCode = getParam("invitation_code");
        if (invitationCode != null && invitationCode != "" && invitationCode != undefined && invitationCode.length == 6) {
            document.getElementById("invitation_code").value = invitationCode;
            document.getElementById("invitation_code").readOnly  = true;
        }
    });
    function getParam(paramName) {
        paramValue = "", isFound = !1;
        if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
            arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0;
            while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
        }
        return paramValue == "" && (paramValue = null), paramValue
    }
    // 2018-11-28 添加邀请码URL传值设置 chenlei end
    $('#form1').submit(function(){
        if ($.trim($(':text[name="username"]').val()) == '') {
            util.message('没有输入用户名.', '', 'error');
@@ -81,6 +98,26 @@
                            <span ng-class="{true:'color-red',false:'sr-only'}[repasswordErr]" ng-bind="repasswordMsg"></span>
                        </div>
                    </div>
                    <!-- 2018-11-28 添加邀请码,手机号码 chenlei start -->
                    <div class="form-group">
                        <label for="" class="control-label col-sm-1">邀请码:</label>
                        <div class="col-sm-11">
                            <input name="invitation_code" id="invitation_code" type="text" class="form-control" placeholder="请输入6位邀请码" ng-model="invitation_code" ng-blur="" required>
                            <span ng-class="{true:'fa fa-times form-control-feedback reg-system-valid',false:'fa fa-check form-control-feedback reg-system-valid'}[invitation_codeErr]" aria-hidden="true"></span>
                            <span ng-class="{true:'color-red',false:'sr-only'}[invitation_codeErr]" ng-bind="invitation_codeMsg"></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="" class="control-label col-sm-1">手机号:<span class="color-red">*</span></label>
                        <div class="col-sm-11">
                            <input name="phone" type="text" class="form-control" placeholder="请输入手机号" ng-model="phone" ng-blur="checkPhone()" required>
                            <span ng-class="{true:'fa fa-times form-control-feedback reg-system-valid',false:'fa fa-check form-control-feedback reg-system-valid'}[phoneErr]" aria-hidden="true"></span>
                            <span ng-class="{true:'color-red',false:'sr-only'}[phoneErr]" ng-bind="phoneMsg"></span>
                        </div>
                    </div>
                    <input name="register_shop" id=""register_shop"" type="hidden" value="true">
                    <!-- 2018-11-28 添加邀请码,手机号码 chenlei end -->
                    <!--用户注册拓展字段 end -->
                    {if $extendfields}