wangtengyu
2018-12-07 f459412e0dac4ed94106da043b4c6f8576bfe496
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
 
/**
 * 获取登录信息
*/
    define('IN_ECS', true);
    require('includes/init.php');
 
if($_POST['acr'] == 'app')
{
    if($_POST['act'] == 'reg')
    {
        $user= isset($_POST['user'])? $_POST['user'] : '';
        $email= isset($_POST['email']) ? $_POST['email'] : '';
        $sex= $_POST['sex'];
        $pwd=md5($_POST['pwd']);
        $reg_list = $_POST['reg_field'];//会员注册项
    
        $res_field = explode(',',$reg_list);//拆分数组
        $reg_field = array_filter($res_field);//去除数组中的空值
        $msn = '';
        $qq = '';
        $office_phone = '';
        $home_phone = '';
        $mobile_phone = '';
        $extend_field_str = '';
        if($reg_field)
        {
            foreach($reg_field as $value)
            {
                $field = explode('@',$value);
                if($field['0'] == 1)
                {
                    $msn = $field['1'];
                }
                if($field['0'] == 2)
                {
                    $qq = $field['1'];
                }
                if($field['0'] == 3)
                {
                    $office_phone = $field['1'];
                }
                if($field['0'] == 4)
                {
                    $home_phone = $field['1'];
                }
                if($field['0'] == 5)
                {
                    $mobile_phone = $field['1'];
                }
                if($field['0'] > 6)
                {
                    //$extend_field_str .= " ('" . $_SESSION['user_id'] . "', '" . $field['0'] . "', '" . $field['1'] . "'),";
                    $extend_field_str.= $field['0'].",".$field['1']."@";
                }
            }
        }
        $result=array();
        $row = $db -> getRow("SELECT * FROM ".$ecs->table('users')."  WHERE  `user_name`='$user'");
        if(!empty($row)){
            $result['code']=2;
            $result['info']="该用户名已经存在";
            print_r(json_encode($result));
            exit();
        }
        $row = $db -> getRow("SELECT * FROM ".$ecs->table('users')."  WHERE  `email`='$email'");
        if(!empty($row)){
            $result['code']=3;
            $result['info']="该邮箱已经存在";
            print_r(json_encode($result));
            exit();
        }
 
        $add = array(  
            'user_name' => $user,
            'email' => $email, 
            'password' => $pwd, 
            'reg_time' => gmtime(), 
            'sex' => $sex,
            //注册项
            'msn' => $msn,
            'qq' => $qq,
            'office_phone' => $office_phone,
            'home_phone' => $home_phone,
            'mobile_phone' => $mobile_phone,
            'froms' => 'app'
        ); 
        $set=$db->autoExecute($ecs->table('users'), $add, 'INSERT');
        if($set){
            /*注册赠送积分*/
            $sql="SELECT value FROM ".$ecs->table('shop_config')." WHERE id='220'";
            $shop_config=$db ->getRow($sql);
            $shop_config_integral=intval($shop_config['value']);
            if($shop_config_integral>0){
                $row = $db -> getRow("SELECT * FROM ".$ecs->table('users')."  WHERE  `user_name`='$user'");
                $uid=$row['user_id'];
                $user_log=array();
               $user_log['user_id'] = $uid;
               $user_log['user_money'] = '0.00';
               $user_log['frozen_money'] = '0.00';
               $user_log['rank_points'] ='0';
               $user_log['pay_points'] = $shop_config_integral;
               $user_log['change_desc'] = '注册赠送积分';
               $user_log['change_type'] = '99';
               $user_log['change_time'] = gmtime();
               $db->autoExecute($ecs->table('account_log'), $user_log, 'INSERT');
               $sql="UPDATE ".$ecs->table('users') . " SET `pay_points`=`pay_points`+$shop_config_integral WHERE `user_id`='$uid'";
                $db->query($sql);
            }
            if ($extend_field_str)      //插入注册扩展数据
            {
                $extend_str = explode('@',$extend_field_str);//拆分数组
                $extend_field = array_filter($extend_str);//去除数组中的空值
                foreach($extend_field as $value)
                {
                    $extend = explode(',',$value);
                    $extend_list.=" (' $uid ', '" . $extend['0'] . "', '" . $extend['1'] . "'),";
                }
                 $extend_list = substr($extend_list, 0, -1);
                $sql = 'INSERT INTO '. $ecs->table('reg_extend_info') . ' (`user_id`, `reg_field_id`, `content`) VALUES' . $extend_list;
                $db->query($sql);
            }
            
            $row = $db -> getRow("SELECT * FROM ".$ecs->table('users')."  WHERE  `user_name`='$user'");
            $result['code']=1;
            $result['info']=$row;
            print_r(json_encode($result));
            exit();
        }
    }
}
else
{
    $redirect_url =  "http://".$_SERVER["HTTP_HOST"].str_replace("user.php", "index.php");
    header('Location: '.$redirect_url);
}
?>