likeshop商城删除登录注册直接购买商品逻辑修改

getfuner 348 0

整个修改逻辑就是打开页面时给他默认注册一个账号并且登录

likeshop商城删除登录注册直接购买商品逻辑修改-第1张图片-九零博客 - 一个分享技术、记录生活的个人技术博客

第一步:后端逻辑修改,找到/application/api/logic/LoginLogic.php添加一个默认注册登录处理方法

  public static function autregister(){
        $client = Client_::h5;
        $time = time();
        $mobile='138'.mt_rand(1000,9999).mt_rand(1000,9999);
        $salt = substr(md5($time . $mobile), 0, 4);//随机4位密码盐
        $password = create_password('123456', $salt);//生成密码
        $user_data = [
            'avatar'        => ConfigServer::get('website', 'user_image'),
            'sn'            => create_user_sn(),
            'mobile'        => $mobile,
            'salt'          => $salt,
            'password'      => $password,
            'create_time'   => $time,
            'distribution_code' => generate_invite_code(),//分销邀请码
            'is_distribution' => DistributionLogic::isDistributionMember(),//是否为分销会员
        ];

        $user_data['nickname'] = '用户'.$user_data['sn'];

        $user = new User();
        $user->save($user_data);

        $token = self::createSession($user->id, $client);
        //登录逻辑
        $user_info = Db::name('user')
            ->field(['id', 'nickname', 'avatar', 'level', 'disable', 'distribution_code'])
            ->where(['account|mobile' => $mobile])
            ->find();
        $user_info['token'] = self::createSession($user_info['id'], $client);
        if (empty($user_info['avatar'])) {
            $user_info['avatar'] = UrlServer::getFileUrl(ConfigServer::get('website', 'user_image'));
        } else {
            $user_info['avatar'] = UrlServer::getFileUrl($user_info['avatar']);
        }
        return $user_info;
        
    }

第二步,打开application/api/controller/Account.php再注册逻辑下面添加

//自定注册
public function autregister(){
            $data = LoginLogic::autregister();
            if($data){
                $this->_success('登录成功', $data);
            }

}

第三步:再uniapp页面里面找到首页index.vue修改

引入vuex中的登录方法把获取的data值存到引入的mapMutations里面写好的LOGIN方法里面

在improt里面加入

import {
        mapMutations,
import {
        getHome,
        getMenu,
        autregister,//自定义的方法
        getBestList
    } from '@/api/store';

在method加入

methods: {
            ...mapMutations(['LOGIN']),
            ...mapActions(['getUser']),

接着在下面写入自动获取方法

async getloginFun() {
                const {
                    code,
                    data
                } = await autregister({
                    type: 1
                });
                this.LOGIN(data)//返回的登录数据存入LOGIN
            },


标签: likeshop

发布评论 0条评论)

  • Refresh code

还木有评论哦,快来抢沙发吧~