关于php:PHP多商城系统开发制作登录下单

6次阅读

共计 3657 个字符,预计需要花费 10 分钟才能阅读完成。

整站伪动态:加强搜索引擎的友好度,对于前期网络营销有比拟显著作用

通用帐户登陆:让您的能够应用微信号、QQ 号码、支付宝、淘宝等社会化网络账号登录您的网站

<template>
    <div class="login_container">
     <div class="login_box">
         <!-- 头像区域 -->
         <div class="avatar_box">
             <img src="../assets/logo.png" alt="">
         </div>
         <!-- 登录表单区 -->
         <el-form ref="loginFormRef" :model="loginForm" :rules="loginFormRules" label-width="0px" class="login_form">
              <!-- 用户名 -->
            <el-form-item prop="username" >
                <el-input  v-model="loginForm.username" prefix-icon="el-icon-user"></el-input>
            </el-form-item>
 
             <!-- 明码 -->
             <el-form-item prop="password">
                <el-input v-model="loginForm.password" prefix-icon="el-icon-lock" type="password"></el-input>
            </el-form-item>
 
            <!-- 按钮 -->
            <el-form-item class="btns">
               <el-button type="primary" @click="login"> 登录 </el-button>
               <el-button type="info" @click="resetloginForm"> 重置 </el-button>
            </el-form-item>
         </el-form>
     </div>
    </div>
</template>
<script>
export default {data(){
        return {
            // 登录表单的数据绑定对象
            loginForm:{
                username:'',
                password:''
            },
            // 表单的验证规定
            loginFormRules:{
                // 验证用户名是否非法
                username:[{required: true, message: '请输出登录名称', trigger: 'blur'},
                    {min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur'}
                ],
                // 验证明码是否非法
                password:[{required: true, message: '请输出登录明码', trigger: 'blur'},
                    {min: 6, max: 15, message: '长度在 6 到 15 个字符', trigger: 'blur'}
                ]
            }
        }
    },
    methods: {
        // 点击重置按钮
        resetloginForm(){this.$refs.loginFormRef.resetFields()
        },
        login(){
           this.$refs.loginFormRef.validate(async valid => {if(!valid) return;
            //    const result = await this.$http.post('login',this.loginForm);
            //    console.log(result);
            //     构造赋值 data 属性
               const {data:res} = await this.$http.post('login',this.loginForm);
               if(res.meta.status !== 200)return console.log('登录失败')
               console.log('登录胜利');
           }); 
        }
    }
}
</script>

抢购、秒杀是现在很常见的一个利用场景,次要须要解决的问题有两个:

1 高并发对数据库产生的压力

2 竞争状态下如何解决库存的正确缩小(” 超卖 ” 问题)

下单零碎:

/**
* Class redisConcurrent
*/
class RedisConcurrent
{
/** lock key
* @var string
*/
public $_lockKey = 'redis_lock';
/** Redis Class
* @var Redis
*/
private $_redis ;
/** ip
* @var mixed|string
*/
private $ip ='127.0.0.1' ;
/** port
* @var string
*/
private $port = '6379' ;
/** init redis connect
* redisConcurrent constructor.
* @param array $config
*/
public function __construct($config = [] )
{if(!empty($config)) {if(isset($config['ip'])) {$this->ip = $config['ip'];
}
if(isset($config['port'])){$this->ip = $config['port'];
}
}
/**
* Redis 连贯信息能够用原生, 也能够用其它的框架集成
*/
$this->_redis = new Redis();
$this->_redis->connect($this->ip,$this->port);
}
/** 锁定
* @param int $intTimeout 默认过期工夫 (防止死锁)
* @return bool
*/
private function lock($intTimeout = 8) {
#新版 set, 曾经集成了大多数集成操作
$strRet = $this->_redis->set($this->_lockKey, time().rand(10000,99999).rand(1000,9999).rand(100,999), 'ex', $intTimeout, 'nx');
if($strRet) {return true;}else{return false;}
}
/** 解锁
* @throws \Exception
*/
private function unlock()
{$strRet = $this->_redis->del($this->_lockKey);
if($strRet) {return true;}else{if($this->_redis->get($this->_lockKey)) {return false ;}else{return false ;}
}
}
/**
* 业务相干的 key, 能够是库存, 物品数等
*/
const ORDER_KEY = 'order_num';
/**
* 用户相干的 key
*/
const USER_KEY = 'user_num';
/** Redis 下单
* @param int $num 下单个数
* @param string $userId 用户 ID
*
* 场次是为了不便异样解决, 不便数据查找
* @param string $bout 商品场次 => order_num:1 , order_num:2
* @return bool
* @throws Exception
*/
public function order(string $userId ,string $bout = '1' ,int $num = 1)
{
$orderKey = self::ORDER_KEY.':'.$bout ;
$userKey = self::USER_KEY.':'.$bout ;
// 此办法不具备原子性 并发解决是不能做条件判断
//$len = $this->_redis->llen();
#理论为 n + 1 次触发完结, 这里只做 Redis 自减
$check = $this->_redis->lpop($orderKey);
if(!$check){
#以后 order_num 曾经为 0!
// 主动补货为 100 ,$bout 有肯定的解决规定, 不能乱传
self::autoBuild(100,$bout);
return false ;
}
// 非凡解决, 防止 n + 1 次的状况
$len = $this->_redis->llen($orderKey) ;
if($len == 0) {
// 主动补货为 100 ,$bout 有肯定的解决规定, 不能乱传
self::autoBuild(100,$bout);
return false ;
}
// 增加用户数据
$result = $this->_redis->lpush($u

竞拍零碎:在当初产品管理系统上抉择相干的产品,设置拍卖开始到完结工夫,设置起拍价格、一口价、加价幅度、保证金等参数,前台会员就能够进行商品的竞价了,价高者得。

团购零碎:在现有的产品管理系统上抉择须要团购的商品,设置开始到完结工夫、保证金、限购数量、赠送积分、价格阶梯以及整个流动的阐明,实现后所有的会员即可进行团购流动。

心愿这编文章能够帮忙到真正有须要的敌人,如果各位对于互联网开发这块还有什么问题或者有这方面的纳闷,都能够随时私信或微信 kjwenlc 我一起交换,一起提高哈~
同时,感激大家的反对与浏览,如果感觉不错欢送点赞和分享,谢谢!

正文完
 0