code
stringlengths 15
9.96M
| docstring
stringlengths 1
10.1k
| func_name
stringlengths 1
124
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 6
186
| url
stringlengths 50
236
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
public function getExpressReturnUrl($payment_method = '')
{
if (!$payment_method) {
$payment_method = $this->getPaymentMethod();
}
if ($payment_method) {
$paymentConfig = $this->paymentConfig;
if (isset($paymentConfig['express'][$payment_method]['return_url'])) {
if (!empty($paymentConfig['express'][$payment_method]['return_url'])) {
return $this->getUrl($paymentConfig['express'][$payment_method]['return_url']);
}
}
}
} | @param $payment_method | String 支付方式。
@return 返回进行数据交互的express的signature。 | getExpressReturnUrl | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
public function getExpressCancelUrl($payment_method = '')
{
if (!$payment_method) {
$payment_method = $this->getPaymentMethod();
}
if ($payment_method) {
$paymentConfig = $this->paymentConfig;
if (isset($paymentConfig['express'][$payment_method]['cancel_url'])) {
if (!empty($paymentConfig['express'][$payment_method]['cancel_url'])) {
return $this->getUrl($paymentConfig['express'][$payment_method]['cancel_url']);
}
}
}
} | @param $payment_method | String 支付方式。
@return 返回进行数据交互的express的signature。 | getExpressCancelUrl | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
public function getExpressSuccessRedirectUrl($payment_method = '')
{
if (!$payment_method) {
$payment_method = $this->getPaymentMethod();
}
if ($payment_method) {
$paymentConfig = $this->paymentConfig;
if (isset($paymentConfig['express'][$payment_method]['success_redirect_url'])) {
if (!empty($paymentConfig['express'][$payment_method]['success_redirect_url'])) {
return $this->getUrl($paymentConfig['express'][$payment_method]['success_redirect_url']);
}
}
}
} | @param $payment_method | String 支付方式。
@return 第三方支付成功后,返回到网站的url
#从配置信息中获取 | getExpressSuccessRedirectUrl | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
public function getExpressIpnUrl($payment_method = '')
{
if (!$payment_method) {
$payment_method = $this->getPaymentMethod();
}
if ($payment_method) {
$paymentConfig = $this->paymentConfig;
if (isset($paymentConfig['express'][$payment_method]['ipn_url'])) {
if (!empty($paymentConfig['express'][$payment_method]['ipn_url'])) {
return $this->getUrl($paymentConfig['express'][$payment_method]['ipn_url']);
}
}
}
} | @param $payment_method | String 支付方式。
@return 返回进行数据交互的express的signature。 | getExpressIpnUrl | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
protected function resolveRequestUri()
{
if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { // IIS
$requestUri = $_SERVER['HTTP_X_REWRITE_URL'];
} elseif (isset($_SERVER['REQUEST_URI'])) {
$requestUri = $_SERVER['REQUEST_URI'];
if ($requestUri !== '' && $requestUri[0] !== '/') {
$requestUri = preg_replace('/^(http|https):\/\/[^\/]+/i', '', $requestUri);
}
} elseif (isset($_SERVER['ORIG_PATH_INFO'])) { // IIS 5.0 CGI
$requestUri = $_SERVER['ORIG_PATH_INFO'];
if (!empty($_SERVER['QUERY_STRING'])) {
$requestUri .= '?' . $_SERVER['QUERY_STRING'];
}
} else {
throw new InvalidConfigException('Unable to determine the request URI.');
}
/*
* Replace Code
* //return $requestUri;
* To:
*/
return $this->getRewriteUri($requestUri);
} | rewrite yii\web\Request resolveRequestUri(). | resolveRequestUri | php | fecshop/yii2_fecshop | services/Request.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Request.php | BSD-3-Clause |
protected function getOriginUrl($urlKey)
{
$UrlData = $this->_urlRewriteModel->find()->where([
'custom_url_key' => $urlKey,
])->asArray()->one();
if ($UrlData['custom_url_key']) {
return $UrlData['origin_url'];
}
} | mongodb url_rewrite collection columns: _id, type ,custom_url, yii_url,
if selete date from $this->_urlRewriteModel, return the yii url. | getOriginUrl | php | fecshop/yii2_fecshop | services/Request.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Request.php | BSD-3-Clause |
public function getRegisterNameMinLength()
{
if (isset($this->customer_register['min_name_length'])) {
return $this->customer_register['min_name_length'];
}
return null;
} | 注册用户名字的最小长度.
@return int|null | getRegisterNameMinLength | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function getRegisterNameMaxLength()
{
if (isset($this->customer_register['max_name_length'])) {
return $this->customer_register['max_name_length'];
}
return null;
} | 注册用户名字的最大长度.
@return int|null | getRegisterNameMaxLength | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function getRegisterPassMinLength()
{
if (isset($this->customer_register['min_pass_length'])) {
return $this->customer_register['min_pass_length'];
}
return null;
} | 注册用户密码的最小长度.
@return int|null | getRegisterPassMinLength | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function getRegisterPassMaxLength()
{
if (isset($this->customer_register['max_pass_length'])) {
return $this->customer_register['max_pass_length'];
}
return null;
} | 注册用户密码的最大长度.
@return int|null | getRegisterPassMaxLength | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function register($param)
{
$model = $this->_customerRegisterModel;
$model->attributes = $param;
if ($model->validate()) {
$model->created_at = time();
$model->updated_at = time();
if (Yii::$service->email->customer->registerAccountIsNeedEnableByEmail) {
$model->generateRegisterEnableToken();
$model->status = $model::STATUS_REGISTER_DISABLE;
}
$saveStatus = $model->save();
if (!$saveStatus) {
$errors = $model->errors;
Yii::$service->helper->errors->addByModelErrors($errors);
return false;
}
// 如果用户勾选了订阅邮件,那么添加到订阅
if ($param['is_subscribed'] == 1) {
Yii::$service->customer->newsletter->subscribe($param['email'], true);
}
// 发送注册信息到trace系统
Yii::$service->page->trace->sendTraceRegisterInfoByApi($model->email);
return true;
} else {
$errors = $model->errors;
Yii::$service->helper->errors->addByModelErrors($errors);
return false;
}
} | Register customer account.
@param array $param
数据格式如下:
```php
[
'email',
'firstname',
'lastname',
'password'
]
```
@return bool whether the customer is registered ok | register | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function isRegistered($email)
{
$customer = $this->_customerModel->findOne(['email' => $email]);
if ($customer['email']) {
return true;
} else {
return false;
}
} | Check whether the given email is registered
@param string $email
@return bool whether the given email is registered | isRegistered | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function save($param)
{
$primaryKey = $this->getPrimaryKey();
$primaryVal = isset($param[$primaryKey]) ? $param[$primaryKey] : '';
if ($primaryVal) {
$model = $this->_customerRegisterModel;
$model->attributes = $param;
if (!$model->validate()) {
$errors = $model->errors;
Yii::$service->helper->errors->addByModelErrors($errors);
return false;
}
$model = $this->getByPrimaryKey($primaryVal);
if ($model[$primaryKey]) {
unset($param[$primaryKey]);
$param['updated_at'] = time();
$password = isset($param['password']) ? $param['password'] : '';
if ($password) {
$model->setPassword($password);
unset($param['password']);
}
$saveStatus = Yii::$service->helper->ar->save($model, $param);
if ($saveStatus) {
return true;
} else {
$errors = $model->errors;
Yii::$service->helper->errors->addByModelErrors($errors);
return false;
}
}
} else {
if ($this->register($param)) {
return true;
}
}
return false;
} | Save the customer info.
@param array $param
数据格式如下:
['email' => 'xxx', 'password' => 'xxxx','firstname' => 'xxx','lastname' => 'xxx']
@return bool | save | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function viewInfo($customerId)
{
} | @param int $customerId
@deprecated 该方法已废弃 | viewInfo | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function getModelName()
{
$model = new $this->_customerModelName();
return get_class($model);
} | 得到category model的全名. | getModelName | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function getByPrimaryKey($val)
{
$one = $this->_customerModel->findOne($val);
$primaryKey = $this->getPrimaryKey();
if ($one[$primaryKey]) {
return $one;
} else {
return new $this->_customerModelName();
}
} | @param int $val
@return \fecshop\models\mysqldb\Customer | getByPrimaryKey | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function registerEnableByTokenAndClearToken($token)
{
$identity = $this->findByRegisterEnableToken($token);
if (!$identity['id']) {
Yii::$service->helper->errors->add('token is invalid');
return false;
}
$identity->status = $identity::STATUS_ACTIVE;
$identity->updated_at = time();
return $identity->save();
} | @param $password|string
@param $customerId|int or String or Object
change customer password.
更改密码,然后,清空token | registerEnableByTokenAndClearToken | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function changeNameAndPassword($data)
{
} | @deprecated 已废弃 | changeNameAndPassword | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function getCurrentAccount()
{
} | @deprecated 已废弃 | getCurrentAccount | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function getUserIdentityByEmail($email)
{
$one = $this->_customerModel->findByEmail($email);
if ($one['email']) {
return $one;
} else {
return null;
}
} | Get customer by email address
@param string $email
@return \fecshop\models\mysqldb\Customer|null return customer or null if not found | getUserIdentityByEmail | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function getAvailableUserIdentityByEmail($email)
{
$one = $this->_customerModel->findAvailableByEmail($email);
if ($one['email']) {
return $one;
} else {
return null;
}
} | 得到可用的账户 | getAvailableUserIdentityByEmail | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function generatePasswordResetToken($identify)
{
if (is_string($identify)) {
$email = $identify;
$one = $this->getUserIdentityByEmail($email);
} else {
$one = $identify;
}
if ($one) {
$one->generatePasswordResetToken();
$one->updated_at = time();
$one->save();
return $one->password_reset_token;
}
return false;
} | 生成resetToken,用来找回密码
@param string|IdentityInterface $identify identity can be customer email, or customer object
@return string|null 生成的resetToken,如果生成失败返回false | generatePasswordResetToken | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function generateRegisterEnableToken($identify)
{
if (is_string($identify)) {
$email = $identify;
$one = $this->getAvailableUserIdentityByEmail($email);
} else {
$one = $identify;
}
if ($one) {
$one->generateRegisterEnableToken();
$one->updated_at = time();
$one->save();
return $one->register_enable_token;
}
return false;
} | 生成resetToken,用来找回密码
@param string|IdentityInterface $identify identity can be customer email, or customer object
@return string|null 生成的resetToken,如果生成失败返回false | generateRegisterEnableToken | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function findByPasswordResetToken($token)
{
return $this->_customerModel->findByPasswordResetToken($token);
} | @param string $token the password reset token
通过PasswordResetToken 得到user.
@return \fecshop\models\mysqldb\Customer|null returns customer or null if not found | findByPasswordResetToken | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function setLoginSuccessRedirectUrl($url)
{
return Yii::$service->session->set($this::USER_LOGIN_SUCCESS_REDIRECT_URL_KEY, $url);
} | @param $url|string
**注意**:该方法不能在接口类型里面使用
在一些功能中,需要用户进行登录操作,等用户操作成功后,应该跳转到相应的页面中,这里通过session存储需要跳转到的url。
某些页面 , 譬如评论页面,需要用户登录后才能进行登录操作,那么可以通过这个方法把url set 进去,登录成功
后,页面不会跳转到账户中心,而是需要操作的页面中。 | setLoginSuccessRedirectUrl | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function getLoginSuccessRedirectUrl()
{
$url = Yii::$service->session->get($this::USER_LOGIN_SUCCESS_REDIRECT_URL_KEY);
return $url ? $url : '';
} | @param $url|string
**注意**:该方法不能在接口类型里面使用
**注意**:该方法不能在接口类型里面使用
在一些功能中,需要用户进行登录操作,等用户操作成功后,应该跳转到相应的页面中,这里通过session得到需要跳转到的url。 | getLoginSuccessRedirectUrl | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function getStatusDeleted()
{
$model = $this->_customerModel;
return $model::STATUS_DELETED;
} | 得到status为删除状态的值 | getStatusDeleted | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function getStatusActive()
{
$model = $this->_customerModel;
return $model::STATUS_ACTIVE;
} | 得到status为激活状态的值 | getStatusActive | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function getPrimaryKey()
{
return 'id';
} | Get primary key field name. | getPrimaryKey | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function coll($filter = [])
{
$query = $this->_customerModel->find();
$query = Yii::$service->helper->ar->getCollByFilter($query, $filter);
return [
'coll' => $query->all(),
'count'=> $query->limit(null)->offset(null)->count(),
];
} | Get customer collection by filter array
@param array $filter
filter example:
[
'numPerPage' => 20,
'pageNum' => 1,
'orderBy' => ['_id' => SORT_DESC, 'sku' => SORT_ASC ],
'where' => [
['>','price','1'],
['<','price','10'],
['sku' => 'uk10001'],
],
'asArray' => true,
]
@return array | coll | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function getEmailByIds($user_ids)
{
$arr = [];
if (is_array($user_ids) && !empty($user_ids)) {
$data = $this->_customerModel->find()->where([
'in', 'id', $user_ids,
])->all();
if (is_array($data) && !empty($data)) {
foreach ($data as $one) {
$arr[$one['id']] = $one['email'];
}
}
}
return $arr;
} | @param $user_ids | Array , 子项为Int类型
@return Array ,数据格式为:
['id' => 'email']
得到customer id 和customer email的对应数组。 | getEmailByIds | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function registerThirdPartyAccountAndLogin($user, $type)
{
// 查看邮箱是否存在
$email = $user['email'];
$customer_one = Yii::$service->customer->getUserIdentityByEmail($email);
if ($customer_one) {
$loginStatus = \Yii::$app->user->login($customer_one);
if ($loginStatus) {
$customer_one->generateAccessToken();
$customer_one->access_token_created_at = time();
$customer_one->save();
return $this->setHeaderAccessToken($customer_one->access_token);
}
// 不存在,注册。
} else {
if (!(isset($user['password']) && $user['password'])) {
$user['password'] = $this->getRandomPassword();
}
$registerData = [
'email' => $email,
'firstname' => $user['first_name'],
'lastname' => $user['last_name'],
'password' => $user['password'],
'type' => $type,
];
$registerStatus = Yii::$service->customer->register($registerData);
if ($registerStatus) {
return Yii::$service->customer->loginAndGetAccessToken($registerData['email'], $registerData['password']);
}
}
return false;
} | @param $user | Array ,example:
['first_name' => $first_name,'last_name' => $last_name,'email' => $email,]
@param $type | String 代表第三方登录的名称,譬如google,facebook
@return bool
如果用户emai存在,则直接登录,成功后返回true
如果用户不存在,则注册用户,然后直接登录,成功后返回true | registerThirdPartyAccountAndLogin | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
protected function getRandomPassword()
{
srand((float) microtime() * 1000000); //create a random number feed.
$ychar = '0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z';
$list = explode(',', $ychar);
for ($i = 0; $i < 6; $i++) {
$randnum = rand(0, 35); // 10+26;
$authnum .= $list[$randnum];
}
return $authnum;
} | 生成账户密码 | getRandomPassword | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function loginByIdentityAndGetAccessToken($identity, $wx_session_key='', $duration = 0)
{
$header = Yii::$app->request->getHeaders();
if (isset($header['access-token']) && $header['access-token']) {
$accessToken = $header['access-token'];
}
// 如果request header中有access-token,则查看这个 access-token 是否有效
if ($accessToken) {
$access_token_identity = Yii::$app->user->loginByAccessToken($accessToken);
if ($access_token_identity !== null) {
$access_token_created_at = $access_token_identity->access_token_created_at;
$timeout = Yii::$service->session->timeout;
if ($access_token_created_at + $timeout > time()) {
return $accessToken;
}
}
}
// 执行登陆
if (!$duration) {
if (Yii::$service->session->timeout) {
$duration = Yii::$service->session->timeout;
}
}
//var_dump($identity);exit;
if (\Yii::$app->user->login($identity, $duration)) {
$identity->generateAccessToken();
$identity->access_token_created_at = time();
$identity->wx_session_key = $wx_session_key;
$identity->save();
// 执行购物车合并等操作。
Yii::$service->cart->mergeCartAfterUserLogin();
$this->setHeaderAccessToken($identity->access_token);
return $identity->access_token;
}
} | @param $identity | Object, customer model
#param $duration
通过identity 进行登陆账户
通过 | loginByIdentityAndGetAccessToken | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function loginAndGetAccessToken($email, $password)
{
$header = Yii::$app->request->getHeaders();
if (isset($header['access-token']) && $header['access-token']) {
$accessToken = $header['access-token'];
}
// 如果request header中有access-token,则查看这个 access-token 是否有效
if ($accessToken) {
$identity = Yii::$app->user->loginByAccessToken($accessToken);
if ($identity !== null) {
$access_token_created_at = $identity->access_token_created_at;
$timeout = Yii::$service->session->timeout;
if ($access_token_created_at + $timeout > time()) {
return $accessToken;
}
}
}
// 如果上面access-token不存在
$data = [
'email' => $email,
'password' => $password,
];
if (Yii::$service->customer->login($data)) {
$identity = Yii::$app->user->identity;
$identity->generateAccessToken();
$identity->access_token_created_at = time();
$identity->save();
// 执行购物车合并等操作。
Yii::$service->cart->mergeCartAfterUserLogin();
$this->setHeaderAccessToken($identity->access_token);
return $identity->access_token;
}
} | AppServer 部分使用的函数
@param $email | String
@param $password | String
无状态登录,通过email 和password进行登录
登录成功后,合并购物车,返回accessToken
** 该函数是未登录用户,通过参数进行登录需要执行的函数。 | loginAndGetAccessToken | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function loginByAccessToken($type = null)
{
$header = Yii::$app->request->getHeaders();
if (isset($header['access-token']) && $header['access-token']) {
$accessToken = $header['access-token'];
} else {
return null;
}
/** @var \fecshop\models\mysqldb\Customer|null $identity */
$identity = Yii::$app->user->loginByAccessToken($accessToken, $type);
if ($identity !== null) {
$access_token_created_at = $identity->access_token_created_at;
$timeout = Yii::$service->session->timeout;
// 如果时间没有过期,则返回 identity
if ($access_token_created_at + $timeout > time()) {
// 如果时间没有过期,但是快要过期了,在过$updateTimeLimit段时间就要过期,那么更新access_token_created_at。
$updateTimeLimit = Yii::$service->session->updateTimeLimit;
if ($access_token_created_at + $timeout <= (time() + $updateTimeLimit)) {
$identity->access_token_created_at = time();
$identity->save();
}
return $identity;
} else {
$this->logoutByAccessToken();
return null;
}
}
return null;
} | Logs in a user by the given access token.
Token is passed through headers. So you can get it from the key 'access-token'.
@param $type
@return IdentityInterface|null the identity associated with the given access token. Null is returned if
the access token is invalid.
@see [[\yii\web\User::loginByAccessToken()]] | loginByAccessToken | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function getByWxOpenid($openid)
{
$one = $this->_customerModel->findOne(['wx_openid' => $openid]);
$primaryKey = $this->getPrimaryKey();
if ($one[$primaryKey]) {
return $one;
}
return null;
} | @param $openid | string
通过微信的openid 得到 user | getByWxOpenid | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function getByWxMicroOpenid($openid)
{
$one = $this->_customerModel->findOne(['wx_micro_openid' => $openid]);
$primaryKey = $this->getPrimaryKey();
if ($one[$primaryKey]) {
return $one;
}
return null;
} | @param $openid | string
通过微信小程序的openid 得到 user | getByWxMicroOpenid | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function logoutByAccessToken()
{
$userComponent = Yii::$app->user;
$identity = $userComponent->identity;
if ($identity !== null) {
if (!Yii::$app->user->isGuest) {
$identity->access_token = null;
$identity->access_token_created_at = null;
$identity->save();
}
$userComponent->switchIdentity(null);
// 刷新uuid
Yii::$service->session->reflushUUID();
}
return $userComponent->getIsGuest();
} | 通过accessToek的方式,进行登出从操作。 | logoutByAccessToken | php | fecshop/yii2_fecshop | services/Customer.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Customer.php | BSD-3-Clause |
public function init()
{
parent::init();
list($this->_modelName, $this->_model) = Yii::mapGet($this->_modelName);
} | protected $_serilizeAttr = [
"service_db",
]; | init | php | fecshop/yii2_fecshop | services/StoreBaseConfig.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/StoreBaseConfig.php | BSD-3-Clause |
public function save($one)
{
$currentDateTime = \fec\helpers\CDate::getCurrentDateTime();
$primaryVal = isset($one[$this->getPrimaryKey()]) ? $one[$this->getPrimaryKey()] : '';
if ($primaryVal) {
$model = $this->_model->findOne($primaryVal);
if (!$model) {
Yii::$service->helper->errors->add('config {primaryKey} is not exist', ['primaryKey' => $this->getPrimaryKey()]);
return;
}
} else {
$model = new $this->_modelName();
$model->created_at = time();
}
$model->updated_at = time();
$primaryKey = $this->getPrimaryKey();
$model = Yii::$service->helper->ar->save($model, $one);
$primaryVal = $model[$primaryKey];
return true;
} | @param $one|array
save $data to cms model,then,add url rewrite info to system service urlrewrite. | save | php | fecshop/yii2_fecshop | services/StoreBaseConfig.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/StoreBaseConfig.php | BSD-3-Clause |
public function saveConfig($one)
{
if (!$one['key'] || !$one['value']) {
return false;
}
$model = $this->_model->findOne(['key' => $one['key']]);
if (!$model['id']) {
$model = new $this->_modelName();
$model->created_at = time();
$model->key = $one['key'];
}
if (is_array($one['value'])) {
$model->value = serialize($one['value']);
} else {
$model->value = $one['value'];
}
$model->updated_at = time();
return $model->save();
} | 保存配置值 | saveConfig | php | fecshop/yii2_fecshop | services/StoreBaseConfig.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/StoreBaseConfig.php | BSD-3-Clause |
public function getCartQty($package_number, $addQty)
{
if ($package_number >= 2) {
return (int)($addQty * $package_number);
} else {
return $addQty;
}
} | @param int $package_number 打包销售的个数,这个是产品编辑的时候,如果某个商品想打包作为销售单位,填写的值
@param int $addQty 加入购物车的产品个数。
@return int 得到在购物车个数变动数,根据产品的打包销售数进行改变 | getCartQty | php | fecshop/yii2_fecshop | services/Cart.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Cart.php | BSD-3-Clause |
public function getCartItemQty()
{
return Yii::$service->cart->quote->getCartItemCount();
} | 得到购物车中产品的个数,详情参看调用的函数注释 | getCartItemQty | php | fecshop/yii2_fecshop | services/Cart.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Cart.php | BSD-3-Clause |
public function getCartInfo($activeProduct = true, $shipping_method = '', $country = '', $region = '*')
{
return Yii::$service->cart->quote->getCartInfo($activeProduct, $shipping_method, $country, $region);
} | @param $shipping_method | String 货运方式code
@param $country | String 国家code
@param $region | String 省市code
得到购物车中的信息。详情参看调用的函数注释 | getCartInfo | php | fecshop/yii2_fecshop | services/Cart.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Cart.php | BSD-3-Clause |
public function addOneItem($item_id)
{
$status = Yii::$service->cart->quoteItem->addOneItem($item_id);
if (!$status) {
return false;
}
Yii::$service->cart->quote->computeCartInfo();
return true;
} | @param $item_id | Int 购物车产品表的id字段
通过item id 将购物车中的某个产品的个数加一 | addOneItem | php | fecshop/yii2_fecshop | services/Cart.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Cart.php | BSD-3-Clause |
public function lessOneItem($item_id)
{
$status = Yii::$service->cart->quoteItem->lessOneItem($item_id);
if (!$status) {
return false;
}
Yii::$service->cart->quote->computeCartInfo();
return true;
} | @param $item_id | Int 购物车产品表的id字段
通过item id 将购物车中的某个产品的个数减一 | lessOneItem | php | fecshop/yii2_fecshop | services/Cart.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Cart.php | BSD-3-Clause |
public function removeItem($item_id)
{
$status = Yii::$service->cart->quoteItem->removeItem($item_id);
if (!$status) {
return false;
}
Yii::$service->cart->quote->computeCartInfo();
return true;
} | @param $item_id | Int 购物车产品表的id字段
通过item id 删除购物车中的某个产品 | removeItem | php | fecshop/yii2_fecshop | services/Cart.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Cart.php | BSD-3-Clause |
public function selectOneItem($item_id, $checked)
{
$status = Yii::$service->cart->quoteItem->selectOneItem($item_id, $checked);
if (!$status) {
return false;
}
Yii::$service->cart->quote->computeCartInfo();
return true;
} | @param $item_id | Int 购物车产品表的id字段
通过item id 将购物车中的某个产品的个数加一 | selectOneItem | php | fecshop/yii2_fecshop | services/Cart.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Cart.php | BSD-3-Clause |
public function selectAllItem($checked)
{
$status = Yii::$service->cart->quoteItem->selectAllItem($checked);
if (!$status) {
return false;
}
Yii::$service->cart->quote->computeCartInfo();
return true;
} | @param $item_id | Int 购物车产品表的id字段
通过item id 将购物车中的某个产品的个数加一 | selectAllItem | php | fecshop/yii2_fecshop | services/Cart.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Cart.php | BSD-3-Clause |
public function mergeCartAfterUserLogin()
{
Yii::$service->cart->quote->mergeCartAfterUserLogin();
} | 购物车合并:对应的是用户登录前后购物车的合并
1. 用户未登录账号,把一部分产品加入购物车
2. 当用户登录账号的时候,账号对应的购物车信息和用户未登录前的购物车产品信息进行合并的操作
在用户登录账户的时候,会执行该方法。 | mergeCartAfterUserLogin | php | fecshop/yii2_fecshop | services/Cart.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Cart.php | BSD-3-Clause |
public function updateGuestCart($address, $shipping_method, $payment_method)
{
return Yii::$service->cart->quote->updateGuestCart($address, $shipping_method, $payment_method);
} | @param $address|array
@param $shipping_method | String 发货方式
@param $payment_method | String 支付方式
此函数对应的是保存游客用户的购物车数据。
保存购物车中的货运地址保存购物车中的货运地址(姓名,电话,邮编,地址等),货运方式,支付方式等信息。
详细参看相应函数 | updateGuestCart | php | fecshop/yii2_fecshop | services/Cart.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Cart.php | BSD-3-Clause |
public function updateLoginCart($address_id, $shipping_method, $payment_method)
{
return Yii::$service->cart->quote->updateLoginCart($address_id, $shipping_method, $payment_method);
} | @param $address_id | Int
@param $shipping_method | String 货运方式
@param $payment_method | String 支付方式
此函数对应的是登录用户的购物车数据的更新。 | updateLoginCart | php | fecshop/yii2_fecshop | services/Cart.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Cart.php | BSD-3-Clause |
public function clearCartProductAndCoupon()
{
Yii::$service->cart->quoteItem->removeNoActiveItemsByCartId();
// 清空cart中的优惠券
$cart = Yii::$service->cart->quote->getCurrentCart();
if (!$cart['cart_id']) {
Yii::$service->helper->errors->add('current cart is empty');
return false;
}
// 如果购物车中存在优惠券,则清空优惠券。
if ($cart->coupon_code) {
$cart->coupon_code = null;
$cart->save();
}
return true;
} | 清空购物车中的产品和优惠券
在生成订单的时候被调用.
清空cart item active的产品,而对于noActive的购物车产品保留 | clearCartProductAndCoupon | php | fecshop/yii2_fecshop | services/Cart.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Cart.php | BSD-3-Clause |
public function clearCart()
{
Yii::$service->cart->quote->clearCart();
} | 完全与当前购物车脱节,执行该函数后,如果产品添加购物车,会创建新的cart_id
目前仅仅在登录用户退出账号的时候使用。
该操作仅仅remove掉session保存的cart_id,并没有删除购物车的数据。 | clearCart | php | fecshop/yii2_fecshop | services/Cart.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Cart.php | BSD-3-Clause |
public function addItemsByPendingOrder($order_id)
{
} | 该函数被遗弃
add cart items by pending order Id
1. check if the order is exist ,and belong to current customer.
2. get all item sku and custom option.
3. add to cart like in product page ,click add to cart button. | addItemsByPendingOrder | php | fecshop/yii2_fecshop | services/Cart.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Cart.php | BSD-3-Clause |
public function getVersion()
{
return '2.17.4';
} | Returns a string representing the current version of the fecmall framework.
@return string the version of fecmall framework | getVersion | php | fecshop/yii2_fecshop | services/Helper.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Helper.php | BSD-3-Clause |
public function getAppName()
{
return Yii::$app->params['appName'];
} | 得到当前的app入口的名字,譬如 appfront apphtml5 appserver等. | getAppName | php | fecshop/yii2_fecshop | services/Helper.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Helper.php | BSD-3-Clause |
public function setAppServiceDomain($domain)
{
$this->_param['appServiceDomain'] = $domain;
return true;
} | @param $domain | String vue类型的appserver传递的domain
这个是appservice发送邮件,在邮件里面的url链接地址,在这里保存 | setAppServiceDomain | php | fecshop/yii2_fecshop | services/Helper.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Helper.php | BSD-3-Clause |
public function isApiApp()
{
if (\Yii::$service->store->isApiStore() == true) {
return true;
} else {
return false;
}
} | 该端口是否是Api入口,譬如appserver appapi等,都是属于api的入口
api入口都会将 Yii::$app->user->enableSession 关闭,因此通过该值判断, 是否是Api App | isApiApp | php | fecshop/yii2_fecshop | services/Helper.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Helper.php | BSD-3-Clause |
public function deleteDir($path) {
if (is_dir($path)) {
//扫描一个目录内的所有目录和文件并返回数组
$dirs = scandir($path);
foreach ($dirs as $dir) {
//排除目录中的当前目录(.)和上一级目录(..)
if ($dir != '.' && $dir != '..') {
//如果是目录则递归子目录,继续操作
$sonDir = $path.'/'.$dir;
if (is_dir($sonDir)) {
//递归删除
$this->deleteDir($sonDir);
//目录内的子目录和文件删除后删除空目录
@rmdir($sonDir);
} else {
//如果是文件直接删除
@unlink($sonDir);
}
}
}
@rmdir($path);
}
return true;
} | 递归删除文件夹以及里面的所有的子文件夹和子文件 | deleteDir | php | fecshop/yii2_fecshop | services/Helper.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Helper.php | BSD-3-Clause |
public function copyDirImage($sourcePath, $targetPath, $isForce = true)
{
if (empty($sourcePath) || empty($targetPath)) {
return false;
}
$dir = opendir($sourcePath);
$this->dir_mkdir($targetPath);
while (false !== ($file = readdir($dir))) {
if (($file != '.') && ($file != '..')) {
$sourcePathFile = $sourcePath . '/' . $file;
$targetPathFile = $targetPath . '/' . $file;
if (is_dir($sourcePathFile)){
$this->copyDirImage($sourcePathFile, $targetPathFile);
} else if (Yii::$service->image->isAllowImgType($sourcePathFile, $file)){
if ($isForce) {
copy($sourcePathFile, $targetPathFile);
} else if (!file_exists($targetPathFile)) {
copy($sourcePathFile, $targetPathFile);
} else {
Yii::$service->helper->errors->add('target path:' . $targetPathFile . ' is exist.');
}
} else {
Yii::$service->helper->errors->add('file is not image:' . $sourcePathFile);
}
}
}
closedir($dir);
return true;
} | 图片文件复制,注意,如果某个文件不是图片类型,则不会被复制(仅仅复制图片)
文件夹图片文件拷贝, 如果文件存在,则会被强制覆盖。
@param string $sourcePath 来源文件夹
@param string $targetPath 目的地文件夹
@param boolean $isForce 是否强制复制
@return bool | copyDirImage | php | fecshop/yii2_fecshop | services/Helper.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Helper.php | BSD-3-Clause |
public function copyDir($sourcePath, $targetPath, $isForce = true)
{
if (empty($sourcePath) || empty($targetPath))
{
return false;
}
$dir = opendir($sourcePath);
$this->dir_mkdir($targetPath);
while (false !== ($file = readdir($dir)))
{
if (($file != '.') && ($file != '..')) {
$sourcePathFile = $sourcePath . '/' . $file;
$targetPathFile = $targetPath . '/' . $file;
if (is_dir( $sourcePathFile)) {
$this->copyDir( $sourcePathFile, $targetPathFile);
} else {
//copy($sourcePath . '/' . $file, $targetPath . '/' . $file);
if ($isForce) {
copy($sourcePathFile, $targetPathFile);
} else if (!file_exists($targetPathFile)) {
copy($sourcePathFile, $targetPathFile);
} else {
Yii::$service->helper->errors->add('target path:' . $targetPathFile . ' is exist.');
}
}
}
}
closedir($dir);
return true;
} | 文件夹文件拷贝
@param string $sourcePath 来源文件夹
@param string $targetPath 目的地文件夹
@param boolean $isForce 是否强制复制
@return bool | copyDir | php | fecshop/yii2_fecshop | services/Helper.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Helper.php | BSD-3-Clause |
public function dir_mkdir($path = '', $mode = 0777, $recursive = true)
{
clearstatcache();
if (!is_dir($path))
{
mkdir($path, $mode, $recursive);
return chmod($path, $mode);
}
return true;
} | 创建文件夹
@param string $path 文件夹路径
@param int $mode 访问权限
@param bool $recursive 是否递归创建
@return bool | dir_mkdir | php | fecshop/yii2_fecshop | services/Helper.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Helper.php | BSD-3-Clause |
public function getGmtDateStr($timestamp='')
{
if (!$timestamp) {
$timestamp = time();
}
return gmdate ('l d F Y H:i:s', $timestamp).' GMT';
} | @param $timestamp | int, 时间戳
得到字符串GMT格式日期时间 | getGmtDateStr | php | fecshop/yii2_fecshop | services/Helper.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Helper.php | BSD-3-Clause |
public function contactsEmailAddress()
{
$mailerInfo = $this->mailerInfo;
if (isset($mailerInfo['contacts']['emailAddress'])) {
return $mailerInfo['contacts']['emailAddress'];
}
} | 在邮箱中显示的 邮箱地址 | contactsEmailAddress | php | fecshop/yii2_fecshop | services/Email.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Email.php | BSD-3-Clause |
public function storeName()
{
$mailerInfo = $this->mailerInfo;
if (isset($mailerInfo['storeName'])) {
return $mailerInfo['storeName'];
}
} | 在邮箱中显示的 商城名字(Store Name). | storeName | php | fecshop/yii2_fecshop | services/Email.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Email.php | BSD-3-Clause |
public function contactsPhone()
{
$mailerInfo = $this->mailerInfo;
if (isset($mailerInfo['phone'])) {
return $mailerInfo['phone'];
}
} | 在邮件中显示的 联系手机号
Yii::$service->email->customer->contactsPhone();. | contactsPhone | php | fecshop/yii2_fecshop | services/Email.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Email.php | BSD-3-Clause |
protected function defaultForm($mailerConfig)
{
if (isset($mailerConfig['transport']['username'])) {
if (!empty($mailerConfig['transport']['username'])) {
return $mailerConfig['transport']['username'];
}
}
return '';
} | 默认的默认form。邮件from. | defaultForm | php | fecshop/yii2_fecshop | services/Email.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Email.php | BSD-3-Clause |
public function getSubjectAndBody($widget, $viewPath, $langCode = '', $params = [])
{
if (!$langCode) {
$langCode = Yii::$service->store->currentLangCode;
}
if (!$langCode) {
Yii::$service->helper->errors->add('langCode is empty');
return;
}
$defaultLangCode = Yii::$service->fecshoplang->defaultLangCode;
// 得到body部分的配置数组
$bodyViewFile = $viewPath.'/body_'.$langCode.'.php';
$bodyViewFilePath = Yii::getAlias($bodyViewFile);
if (!file_exists($bodyViewFilePath)) { //如果当前语言的模板不存在,则使用默认语言的模板。
$bodyViewFile = $viewPath.'/body_'.$defaultLangCode.'.php';
$bodyViewFilePath = Yii::getAlias($bodyViewFile);
}
$bodyConfig = [
'class' => $widget,
'view' => $bodyViewFilePath,
];
if (!empty($params)) {
$bodyConfig['params'] = $params;
}
// 得到subject部分的配置数组
$subjectViewFile = $viewPath.'/subject_'.$langCode.'.php';
$subjectViewFilePath = Yii::getAlias($subjectViewFile);
if (!file_exists($subjectViewFilePath)) {
$subjectViewFile = $viewPath.'/subject_'.$defaultLangCode.'.php';
$subjectViewFilePath = Yii::getAlias($subjectViewFile);
}
$subjectConfig = [
'class' => $widget,
'view' => $subjectViewFilePath,
];
if (!empty($params)) {
$subjectConfig['params'] = $params;
}
$emailSubject = $this->getHtmlContent($subjectConfig);
$emailBody = $this->getHtmlContent($bodyConfig);
return [$emailSubject, $emailBody];
} | @param $widget | String,邮件模板中的动态数据的提供部分的class
@param $viewPath | String,邮件模板中的显示数据的html部分。
@param $langCode 当前的语言
@proeprty $params 传递给 $widget 对应的class,用于将数据传递过去。
根据提供的动态数据提供者$widget 和 view路径$viewPath,语言$langCode,以及其他参数$params(这个数组会设置到$widget对应的class的params变量中)
最终得到邮件标题和邮件内容
如果当前语言的邮件模板不存在,则使用默认语言的模板。
关于函数参数的例子值,可以参看配置文件 @fecshop/config/services/Email.php
打开这个配置文件,可以看到 emailTheme部分的配置, 里面有 widget 和 viewPath的配置,
配置和下面的参数是对应起来的,在执行下面的函数,会使用配置里面的参数,譬如:
@fecshop/services/email/Customer.php 中的函数 sendRegisterEmail($emailInfo) 里面对该函数的调用。 | getSubjectAndBody | php | fecshop/yii2_fecshop | services/Email.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Email.php | BSD-3-Clause |
public function validateFormat($email_address)
{
if (preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^", $email_address)) {
return true;
} else {
return false;
}
} | @param $email_address | String 邮箱地址字符串
@return bool 如果格式正确,返回true | validateFormat | php | fecshop/yii2_fecshop | services/Email.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Email.php | BSD-3-Clause |
public function getCacheConfig()
{
$appName = Yii::$service->helper->getAppName();
$cacheConfig = Yii::$app->store->get($appName.'_cache');
if (!$cacheConfig || !is_array($cacheConfig)) {
return null;
}
if (isset($cacheConfig['allPageCache']) && $cacheConfig['allPageCache'] == Yii::$app->store->enable) {
$this->enable = true;
}
$this->_cache_config = $cacheConfig;
return true;
} | 得到当前的入口对应的cache的配置信息 | getCacheConfig | php | fecshop/yii2_fecshop | services/Cache.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Cache.php | BSD-3-Clause |
public function isEnable($cacheKey)
{
$cacheConfigKey = $this->cacheArr[$cacheKey];
if ($this->enable && isset($this->_cache_config[$cacheConfigKey]) &&
$this->_cache_config[$cacheConfigKey] == Yii::$app->store->enable
) {
return true;
} else {
return false;
}
} | @param $cacheKey | String , 具体的缓存名字,譬如 product category
@return boolean, 如果enable为true,则返回为true
根据传递的$cacheKey,从配置中读取是否开启cache | isEnable | php | fecshop/yii2_fecshop | services/Cache.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Cache.php | BSD-3-Clause |
public function timeout($cacheKey)
{
if (isset($this->cacheConfig[$cacheKey]['timeout'])) {
return $this->cacheConfig[$cacheKey]['timeout'];
} else {
return 0;
}
} | @param $cacheKey | String , 具体的缓存名字,譬如 product category
@return int, 如果enable为true,则返回为true
得到$cacheKey 对应的超时时间 | timeout | php | fecshop/yii2_fecshop | services/Cache.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Cache.php | BSD-3-Clause |
public function disableUrlParam($cacheKey)
{
if (isset($this->cacheConfig[$cacheKey]['disableUrlParam'])) {
return $this->cacheConfig[$cacheKey]['disableUrlParam'];
} else {
return '';
}
} | @param $cacheKey | String , 具体的缓存名字,譬如 product category
@return string, 如果enable为true,则返回为true | disableUrlParam | php | fecshop/yii2_fecshop | services/Cache.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Cache.php | BSD-3-Clause |
public function cacheUrlParam($cacheKey)
{
if (isset($this->cacheConfig[$cacheKey]['cacheUrlParam'])) {
return $this->cacheConfig[$cacheKey]['cacheUrlParam'];
} else {
return '';
}
} | @param $cacheKey | String , 具体的缓存名字,譬如 product category
@return string, 如果enable为true,则返回为true
url的参数,哪一些参数作为缓存唯一的依据,譬如p(分页的值) | cacheUrlParam | php | fecshop/yii2_fecshop | services/Cache.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Cache.php | BSD-3-Clause |
public function init()
{
parent::init();
if (!$this->_shipping_methods) {
// 是否开启缓存,如果开启,则从缓存中直接读取
if ($this->_cache_shipping_methods_config) {
$cache = Yii::$app->cache->get(self::CACHE_SHIPPING_METHODS_CONFIG);
if (is_array($cache) && !empty($cache)) {
$this->_shipping_methods = $cache;
}
}
// 如果无法从缓存中读取
if (!$this->_shipping_methods) {
$allmethod = $this->shippingConfig;
$this->_shipping_methods = [];
// 从配置中读取shipping method的配置信息
if (is_array($allmethod) && !empty($allmethod)) {
foreach ($allmethod as $s_method => $v) {
$formula = $v['formula'];
if ($formula == 'csv') {
$csv_content = $this->getShippingByTableCsv($s_method);
if ($csv_content) {
$this->_shipping_methods[$s_method] = $v;
$this->_shipping_methods[$s_method]['csv_content'] = $csv_content;
}
} else {
$this->_shipping_methods[$s_method] = $v;
}
}
}
if ($this->_cache_shipping_methods_config) {
Yii::$app->cache->set(self::CACHE_SHIPPING_METHODS_CONFIG, $this->_shipping_methods);
}
}
}
return $this->_shipping_methods;
} | 1.从配置中取出来所有的shipping method
2.对于公式为csv的shipping method,将对应的csv文件中的配置信息取出来
3.如果开启了数据缓存,那么直接从缓存中读取。
最后合并成一个整体的配置文件。赋值与-> $this->_shipping_methods | init | php | fecshop/yii2_fecshop | services/Shipping.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Shipping.php | BSD-3-Clause |
public function getVolumeWeight($long, $width, $high)
{
$volume_weight = ($long * $width * $high) / $this->volumeWeightCoefficient * 1000;
return (float)$volume_weight;
} | @param $long | Float ,长度,单位cm
@param $width | Float ,宽度,单位cm
@param $high | Float ,高度,单位cm
@return 体积重,单位g | getVolumeWeight | php | fecshop/yii2_fecshop | services/Shipping.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Shipping.php | BSD-3-Clause |
public function getVolume($long, $width, $high)
{
return Yii::$service->helper->format->numberFormat($long * $width * $high);
} | @param $long | Float ,长度,单位cm
@param $width | Float ,宽度,单位cm
@param $high | Float ,高度,单位cm
@return 体积体积,单位cm | getVolume | php | fecshop/yii2_fecshop | services/Shipping.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Shipping.php | BSD-3-Clause |
public function getShippingCost($method, $shippingInfo, $weight, $country, $region)
{
// 得到shipping计算的字符串公式
$formula = $shippingInfo['formula'];
// 如果公式的值为`csv`
if ($formula === 'csv') {
// 通过csv表格的配置,得到运费(基础货币)
$usdCost = $this->getShippingCostByCsv($method, $shippingInfo, $weight, $country, $region);
// 当前货币
$currentCost = Yii::$service->page->currency->getCurrentCurrencyPrice($usdCost);
return [
'currCost' => $currentCost,
'baseCost' => $usdCost,
];
} else { // 通过公式计算得到运费。
$formula = str_replace('[weight]', $weight, $formula);
//echo $formula;exit;
$baseCost = eval("return $formula;");
$currCost = Yii::$service->page->currency->getCurrentCurrencyPrice($baseCost);
return [
'currCost' => Yii::$service->helper->format->numberFormat($currCost, 2),
'baseCost' => Yii::$service->helper->format->numberFormat($baseCost, 2),
];
}
} | @proeprty $shipping_method 货运方式的key
@proeprty $weight 产品的总重量
@proeprty $country 货运国家
@return array 当前货币下的运费的金额。
此处只做运费计算,不管该shipping是否可用。
结果数据示例:
[
'currCost' => 66,
'baseCost' => 11,
] | getShippingCost | php | fecshop/yii2_fecshop | services/Shipping.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Shipping.php | BSD-3-Clause |
public function getCurrentShippingMethod($customShippingMethod, $cartShippingMethod, $country, $region, $weight)
{
$available_method = $this->getAvailableShippingMethods($country, $region, $weight);
if ($customShippingMethod) {
if (isset($available_method[$customShippingMethod])) {
return $customShippingMethod;
}
}
if ($cartShippingMethod) {
if (isset($available_method[$cartShippingMethod])) {
return $cartShippingMethod;
}
}
// 如果都不存在,则将可用物流中的第一个取出来$available_method
foreach ($available_method as $method => $v) {
return $method;
}
} | @proeprty $customShippingMethod 自定义的货运方式,这个一般是通过前端传递过来的shippingMethod
@proeprty $cartShippingMethod 购物车中的货运方式,这个是从购物车表中取出来的。
@return string 返回当前的货运方式。 | getCurrentShippingMethod | php | fecshop/yii2_fecshop | services/Shipping.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Shipping.php | BSD-3-Clause |
public function getShippingLabelByMethod($shipping_method)
{
$s = $this->_shipping_methods[$shipping_method];
return isset($s['label']) ? $s['label'] : '';
} | @param $shipping_method | String
@return 得到货运方式的名字 | getShippingLabelByMethod | php | fecshop/yii2_fecshop | services/Shipping.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Shipping.php | BSD-3-Clause |
public function ifIsCorrect($country, $region, $shipping_method, $weight)
{
$available_method = $this->getAvailableShippingMethods($country, $region, $weight);
if (isset($available_method[$shipping_method]) && !empty($available_method[$shipping_method])) {
return true;
} else {
return false;
}
} | @param $shipping_method | String
@return bool 发货方式
判断前端传递的shipping method是否有效(做安全性验证) | ifIsCorrect | php | fecshop/yii2_fecshop | services/Shipping.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Shipping.php | BSD-3-Clause |
public function getDefaultShippingMethod($countryCode, $region, $weight)
{
$available_method = $this->getAvailableShippingMethods($countryCode, $region, $weight);
foreach ($available_method as $method => $v) {
return $method;
}
} | @param $countryCode | String
@param $region | String
@param weight | Float
将可用的shipping method数组的第一个取出来作为默认的shipping。 | getDefaultShippingMethod | php | fecshop/yii2_fecshop | services/Shipping.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Shipping.php | BSD-3-Clause |
protected function getShippingByTableCsv($shipping_method)
{
$shippingCsvArr = [];
// 从csv文件中读取shipping信息。
$commonDir = Yii::getAlias($this->shippingCsvDir);
$csv = $commonDir.'/'.$shipping_method.'.csv';
if (!file_exists($csv)) {
return false;
}
$fp = fopen($csv, 'r');
$i = 0;
while (!feof($fp)) {
if ($i) {
$content = fgets($fp);
$arr = explode(',', $content);
$country = $arr[0];
$Region = $arr[1];
$Weight = $arr[3];
$ShippingPrice = $arr[4];
$shippingCsvArr[$country][$Region][] = [$Weight, $ShippingPrice];
}
$i++;
}
fclose($fp);
return $shippingCsvArr;
} | @param $shipping_method | String 货运方式的key
@return array ,通过csv表格,得到对应的运费数组信息
内部函数,将csv表格中的shipping数据读出来
返回的数据格式为:
[
'fast_shipping' => [
'US' => [
'*' => [
[0.5100, 22.9],
[1.0100, 25.9],
[2.5100, 34.9],
]
],
'DE' => [
'*' => [
[0.5100, 22.9],
[1.0100, 25.9],
[2.5100, 34.9],
]
],
]
] | getShippingByTableCsv | php | fecshop/yii2_fecshop | services/Shipping.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Shipping.php | BSD-3-Clause |
protected function isCountryLimit($countryLimit, $countryCode)
{
// 如果存在国家方面的限制
if (is_array($countryLimit) && !empty($countryLimit)) {
$type = isset($countryLimit['type']) ? $countryLimit['type'] : '';
$code = isset($countryLimit['code']) ? $countryLimit['code'] : '';
if ($type == 'allow') {
// 如果不存在于数组,则代表不允许
if (!in_array($countryCode, $code)) {
return true;
}
} elseif ($type == 'not_allow') {
if (in_array($countryCode, $code)) {
return true;
}
}
}
return false;
} | @param $countryLimit | Array 配置中的国家限制数组
@param $countryCode | String 判断的国家code
判断 $countryCode 是否存在国家方面的限制 | isCountryLimit | php | fecshop/yii2_fecshop | services/Shipping.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Shipping.php | BSD-3-Clause |
protected function isCsvCountryReginLimit($shippingConfig, $countryCode, $region)
{
$csv_content = isset($shippingConfig['csv_content']) ? $shippingConfig['csv_content'] : '';
// 如果不存在全局国家,省市 的通用配置
if (!isset($csv_content['*']['*'])) {
// 如果当前的国家对应的配置不存在,则不可用
if (!isset($csv_content[$countryCode])) {
return true;
} elseif ($region) { // 如果参数传递的$region不为空
// 国家可用,如果不存在省市的通用配置
if (!isset($csv_content[$countryCode]['*'])) {
// 如果不存在相应省市的配置,则不可用
if (!isset($csv_content[$countryCode][$region])) {
return true;
}
}
}
}
return false;
} | @param $shippingConfig | Array , shipping method对应的配置
@param $countryCode | String 国家简码
@param $region | String 省市
根据csv content里面的配置,判断是否存在国家 省市限制 | isCsvCountryReginLimit | php | fecshop/yii2_fecshop | services/Shipping.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Shipping.php | BSD-3-Clause |
public function changeToMongoStorage()
{
$this->storage = 'ProductMongodb';
$currentService = $this->getStorageService($this);
$this->_product = new $currentService();
} | 动态更改为mongodb model | changeToMongoStorage | php | fecshop/yii2_fecshop | services/Product.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Product.php | BSD-3-Clause |
public function changeToMysqlStorage()
{
$this->storage = 'ProductMysqldb';
$currentService = $this->getStorageService($this);
$this->_product = new $currentService();
} | 动态更改为mongodb model | changeToMysqlStorage | php | fecshop/yii2_fecshop | services/Product.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Product.php | BSD-3-Clause |
public function getCustomAttrGroup()
{
$customAttrGroup = $this->customAttrGroup;
$arr = array_keys($customAttrGroup);
$arr[] = $this->_defaultAttrGroup;
return $arr;
} | 得到产品的所有的属性组。 | getCustomAttrGroup | php | fecshop/yii2_fecshop | services/Product.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Product.php | BSD-3-Clause |
public function getGroupAttrInfo($productAttrGroup)
{
$arr = [];
if ($productAttrGroup == $this->_defaultAttrGroup) {
return [];
}
// 得到普通属性
if (isset($this->customAttrGroup[$productAttrGroup]['general_attr'])
&& is_array($this->customAttrGroup[$productAttrGroup]['general_attr'])
) {
$arr = array_merge($arr, $this->customAttrGroup[$productAttrGroup]['general_attr']);
}
// 得到用于spu,细分sku的属性,譬如颜色尺码之类。
if (isset($this->customAttrGroup[$productAttrGroup]['spu_attr'])
&& is_array($this->customAttrGroup[$productAttrGroup]['spu_attr'])
) {
$arr = array_merge($arr, $this->customAttrGroup[$productAttrGroup]['spu_attr']);
}
return $arr;
} | @param $productAttrGroup|string
得到这个产品属性组里面的所有的产品属性详细,
注解:不同类型的产品,对应不同的属性组,譬如衣服有颜色尺码,电脑类型的有不同cpu型号等
属性组,以及属性组对应的属性,是在Product Service config中配置的。 | getGroupAttrInfo | php | fecshop/yii2_fecshop | services/Product.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Product.php | BSD-3-Clause |
public function getGroupAttr($productAttrGroup)
{
$arr = [];
// 得到普通属性
if (isset($this->customAttrGroup[$productAttrGroup]['general_attr'])
&& is_array($this->customAttrGroup[$productAttrGroup]['general_attr'])
) {
$general_attr = $this->customAttrGroup[$productAttrGroup]['general_attr'];
if (is_array($general_attr)) {
foreach ($general_attr as $attr => $info) {
$arr[] = $attr;
}
}
}
// 得到用于spu,细分sku的属性,譬如颜色尺码之类。
if (isset($this->customAttrGroup[$productAttrGroup]['spu_attr'])
&& is_array($this->customAttrGroup[$productAttrGroup]['spu_attr'])
) {
$spu_attr = $this->customAttrGroup[$productAttrGroup]['spu_attr'];
if (is_array($spu_attr)) {
foreach ($spu_attr as $attr => $info) {
$arr[] = $attr;
}
}
}
return $arr;
} | @param $productAttrGroup|string
得到这个产品属性组里面的所有的产品属性,
注解:不同类型的产品,对应不同的属性组,譬如衣服有颜色尺码,电脑类型的有不同cpu型号等
属性组,以及属性组对应的属性,是在Product Service config中配置的。 | getGroupAttr | php | fecshop/yii2_fecshop | services/Product.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Product.php | BSD-3-Clause |
public function getSpuAttr($productAttrGroup)
{
$arr = [];
if ($productAttrGroup == $this->_defaultAttrGroup) {
return [];
}
// 得到用于spu,细分sku的属性,譬如颜色尺码之类。
if (isset($this->customAttrGroup[$productAttrGroup]['spu_attr'])
&& is_array($this->customAttrGroup[$productAttrGroup]['spu_attr'])
) {
$arr = array_merge($arr, $this->customAttrGroup[$productAttrGroup]['spu_attr']);
}
return array_keys($arr);
} | @param $productAttrGroup|string
@return array 一维数组
得到这个产品属性组里面的属性,也就是原来的产品属性+属性组对应的属性 | getSpuAttr | php | fecshop/yii2_fecshop | services/Product.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Product.php | BSD-3-Clause |
public function getSpuImgAttr($productAttrGroup)
{
if ($productAttrGroup == $this->_defaultAttrGroup) {
return '';
}
// 得到用于spu,细分sku的属性,譬如颜色尺码之类。
if (isset($this->customAttrGroup[$productAttrGroup]['spu_attr'])
&& is_array($this->customAttrGroup[$productAttrGroup]['spu_attr'])
) {
foreach ($this->customAttrGroup[$productAttrGroup]['spu_attr'] as $attr => $one) {
if (isset($one['showAsImg']) && $one['showAsImg']) {
return $attr;
}
}
}
return '';
} | @param $productAttrGroup | String
@return string 显示图片的spu属性。 | getSpuImgAttr | php | fecshop/yii2_fecshop | services/Product.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Product.php | BSD-3-Clause |
public function isActive($status)
{
return ($status == 1) ? true : false;
} | 产品状态是否是 active
@param int $status
@return boolean 如果产品状态是 active 返回 true, 否则返回 false | isActive | php | fecshop/yii2_fecshop | services/Product.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Product.php | BSD-3-Clause |
public function getCustomOptionAttrInfo($productAttrGroup)
{
if ($productAttrGroup == $this->_defaultAttrGroup) {
return [];
}
if (isset($this->customAttrGroup[$productAttrGroup]['custom_options'])
&& is_array($this->customAttrGroup[$productAttrGroup]['custom_options'])
) {
return $this->customAttrGroup[$productAttrGroup]['custom_options'];
}
return [];
} | @param $productAttrGroup | String 产品属性组
通过产品属性组,从配置中得到对应的custom_options部分的配置
@return array | getCustomOptionAttrInfo | php | fecshop/yii2_fecshop | services/Product.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Product.php | BSD-3-Clause |
public function getDefaultAttrGroup()
{
return $this->_defaultAttrGroup;
} | 得到默认的产品属性组。 | getDefaultAttrGroup | php | fecshop/yii2_fecshop | services/Product.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Product.php | BSD-3-Clause |
public function getPrimaryKey()
{
return $this->_product->getPrimaryKey();
} | 得到主键的名称. | getPrimaryKey | php | fecshop/yii2_fecshop | services/Product.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Product.php | BSD-3-Clause |
public function getByPrimaryKey($primaryKey)
{
return $this->_product->getByPrimaryKey($primaryKey);
} | get Product model by primary key. | getByPrimaryKey | php | fecshop/yii2_fecshop | services/Product.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Product.php | BSD-3-Clause |
public function getArrByPrimaryKey($primaryKey)
{
return $this->_product->getArrByPrimaryKey($primaryKey);
} | get Product model by primary key. | getArrByPrimaryKey | php | fecshop/yii2_fecshop | services/Product.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Product.php | BSD-3-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.