public function add() { $goodsId = (int) $this->postParam('goodsId', 0); $skuAttr = $this->postParam('skuAttr', ''); $skuValue = $this->postParam('skuValue', ''); $amount = (int) $this->postParam('amount', 0); if ($goodsId <= 0 || !Check::isSkuAttr($skuAttr) || !Check::isSkuValue($skuValue) || $amount <= 0) { $this->ajaxReturn(ERR_PARAMS_ERROR, '参数错误'); return; } $goodsSKU = GoodsSKUModel::getSKUInfo($goodsId, $skuAttr, $skuValue); if (empty($goodsSKU)) { $this->ajaxReturn(ERR_PARAMS_ERROR, '参数错误'); return; } $cartAmount = UserCartModel::getCartAmount($this->userId()); if ($cartAmount > UserCartModel::MAX_CART_GOODS_AMOUNT) { $this->ajaxReturn(ERR_OPT_FAIL, '您的购物车已满,赶快清理一下吧'); return; } $ret = UserCartModel::newOne($this->userId(), $goodsId, $skuAttr, $skuValue, $amount, ''); if ($ret === false) { $this->ajaxReturn(ERR_SYSTEM_ERROR, '系统错误,加入购物车失败'); return; } $this->ajaxReturn(0, ''); }
public function register() { $phone = $this->postParam('phone', ''); $code = $this->postParam('code', ''); if (Check::isPhone($phone)) { $this->ajaxReturn(ERR_PARAMS_ERROR, '您输入的手机号无效'); return; } if (Check::isVerifyCode($code)) { $this->ajaxReturn(ERR_PARAMS_ERROR, '验证码无效'); return; } $nk = Nosql::NK_REG_SMS_CODE . $phone; $ret = Nosql::get($nk); if (empty($ret) || $ret != $code) { $this->ajaxReturn(ERR_PARAMS_ERROR, '验证码错误,请重新输入'); return; } Nosql::del($nk); $userInfo = UserModel::findUserByPhone($phone); if (empty($userInfo)) { $this->ajaxReturn(ERR_PARAMS_ERROR, '该手机号码未注册,请先注册~'); return; } $nickname = UserModel::getRandomNickname('wx'); $passwd = ''; $sex = 0; $headimgurl = ''; $ret = UserModel::newOne($phone, $passwd, $nickname, $sex, $headimgurl, UserModel::USER_ST_DEFAULT); if (!$ret) { $this->ajaxReturn(ERR_PARAMS_ERROR, '注册失败-系统出现异常,请稍后重试'); return; } $userInfo = UserModel::findUserByPhone($phone); if (empty($userInfo)) { $this->ajaxReturn(ERR_PARAMS_ERROR, '注册失败-系统出现异常,请稍后重试'); return; } UserModel::onLoginOk($userInfo['id'], ''); // TODO 是不是会自动绑定微信? $this->ajaxReturn(0, '登录成功', '/TODO'); }
public function passwdLogin() { $phone = $this->getParam('phone', ''); $passwd = $this->getParam('passwd', ''); if (Check::isPhone($phone)) { $this->ajaxReturn(ERR_PARAMS_ERROR, '您输入的手机号无效'); return; } if (Check::isPasswd($passwd)) { $this->ajaxReturn(ERR_PARAMS_ERROR, '密码格式不正确'); return; } $userInfo = UserModel::findUserByPhone($phone); if (empty($userInfo)) { $this->ajaxReturn(ERR_PARAMS_ERROR, '该手机号码未注册,请先注册~'); return; } if ($userInfo['passwd'] != md5($passwd)) { $this->ajaxReturn(ERR_PASSWD_ERROR, '您输入的密码不正确,请重新输入'); return; } $this->onLoginOk($userInfo); $this->ajaxReturn(0, '登陆成功', '/TODO'); }
public function edit() { $reName = $this->postParam('name', ''); // 收件人 $rePhone = $this->postParam('phone', ''); $provinceId = (int) $this->postParam('provinceId', 0); $cityId = (int) $this->postParam('cityId', 0); $districtId = (int) $this->postParam('districtId', 0); $detail = $this->postParam('detail', ''); $reIdCard = $this->postParam('reIdCard', ''); $isDefault = (int) $this->postParam('isDefault', 0); $sysCityCodeBook = (include CONFIG_PATH . '/city_code_book.php'); $reName = preg_replace('/\\s| /', '', $reName); if (!Check::isName($reName) || !Check::isPhone($rePhone) || !isset($sysCityCodeBook[$provinceId]) || !isset($sysCityCodeBook[$cityId]) || !isset($sysCityCodeBook[$districtId]) || empty($detail) || strlen($detail) > 255) { $this->ajaxReturn(ERR_PARAMS_ERROR, '输入不合法,请重新输入'); return; } if ($isDefault == 1) { UserAddressModel::clearDefaultAddr($this->userId()); } $ret = UserAddressModel::update($this->userId(), $addrId, array('re_name' => $reName, 're_phone' => $rePhone, 'province_id' => $provinceId, 'city_id' => $cityId, 'district_id' => $districtId, 'detail' => $detail, 're_id_card' => $reIdCard, 'is_default' => $isDefault)); if ($ret === false) { $this->ajaxReturn(ERR_SYSTEM_ERROR, '系统异常,更新地址失败'); return; } $this->ajaxReturn(0, ''); }