Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
01cd1748
Y
yii2_fecshop
项目概览
OpenDocCN
/
yii2_fecshop
通知
18
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
yii2_fecshop
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
01cd1748
编写于
7月 22, 2017
作者:
T
Terry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
二开重写的调整:services 调用model 部分,以及controller调用block部分
上级
6d32cbc6
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
71 addition
and
47 deletion
+71
-47
app/appfront/modules/Customer/block/productfavorite/Index.php
...appfront/modules/Customer/block/productfavorite/Index.php
+1
-1
app/apphtml5/modules/Customer/block/productfavorite/Index.php
...apphtml5/modules/Customer/block/productfavorite/Index.php
+1
-1
services/Customer.php
services/Customer.php
+34
-21
services/Order.php
services/Order.php
+26
-21
services/Request.php
services/Request.php
+9
-3
未找到文件。
app/appfront/modules/Customer/block/productfavorite/Index.php
浏览文件 @
01cd1748
...
...
@@ -64,7 +64,7 @@ class Index
$product_ids
=
[];
$favorites
=
[];
foreach
(
$coll
as
$one
)
{
$p_id
=
(
string
)
$one
[
'product_id'
]
$p_id
=
(
string
)
$one
[
'product_id'
]
;
$product_ids
[]
=
$one
[
'product_id'
];
$favorites
[
$p_id
]
=
[
'updated_at'
=>
$one
[
'updated_at'
],
...
...
app/apphtml5/modules/Customer/block/productfavorite/Index.php
浏览文件 @
01cd1748
...
...
@@ -64,7 +64,7 @@ class Index
$product_ids
=
[];
$favorites
=
[];
foreach
(
$coll
as
$one
)
{
$p_id
=
(
string
)
$one
[
'product_id'
]
$p_id
=
(
string
)
$one
[
'product_id'
]
;
$product_ids
[]
=
$one
[
'product_id'
];
$favorites
[
$p_id
]
=
[
'updated_at'
=>
$one
[
'updated_at'
],
...
...
services/Customer.php
浏览文件 @
01cd1748
...
...
@@ -9,9 +9,9 @@
namespace
fecshop\services
;
use
fecshop\models\mysqldb\Customer
as
CustomerModel
;
use
fecshop\models\mysqldb\customer\CustomerLogin
;
use
fecshop\models\mysqldb\customer\CustomerRegister
;
//
use fecshop\models\mysqldb\Customer as CustomerModel;
//
use fecshop\models\mysqldb\customer\CustomerLogin;
//
use fecshop\models\mysqldb\customer\CustomerRegister;
use
Yii
;
/**
...
...
@@ -24,7 +24,20 @@ class Customer extends Service
{
public
$customer_register
;
const
USER_LOGIN_SUCCESS_REDIRECT_URL_KEY
=
'usr_login_success_redirect_url'
;
protected
$_customerModelName
=
'\fecshop\models\mysqldb\Customer'
;
protected
$_customerModel
;
protected
$_customerLoginModelName
=
'\fecshop\models\mysqldb\customer\CustomerLogin'
;
protected
$_customerLoginModel
;
protected
$_customerRegisterModelName
=
'\fecshop\models\mysqldb\customer\CustomerRegister'
;
protected
$_customerRegisterModel
;
public
function
__construct
(){
list
(
$this
->
_customerModelName
,
$this
->
_customerModel
)
=
\
Yii
::
mapGet
(
$this
->
_customerModelName
);
list
(
$this
->
_customerLoginModelName
,
$this
->
_customerLoginModel
)
=
\
Yii
::
mapGet
(
$this
->
_customerLoginModelName
);
list
(
$this
->
_customerRegisterModelName
,
$this
->
_customerRegisterModel
)
=
\
Yii
::
mapGet
(
$this
->
_customerRegisterModelName
);
}
/**
* 注册用户名字的最小长度.
*/
...
...
@@ -71,7 +84,7 @@ class Customer extends Service
*/
protected
function
actionLogin
(
$data
)
{
$model
=
new
CustomerLogin
();
$model
=
new
$this
->
_customerLoginModelName
();
$model
->
email
=
$data
[
'email'
];
$model
->
password
=
$data
[
'password'
];
$loginStatus
=
$model
->
login
();
...
...
@@ -98,7 +111,7 @@ class Customer extends Service
*/
protected
function
actionRegister
(
$param
)
{
$model
=
new
CustomerRegister
();
$model
=
new
$this
->
_customerRegisterModelName
();
$model
->
attributes
=
$param
;
if
(
$model
->
validate
())
{
$model
->
created_at
=
time
();
...
...
@@ -119,7 +132,7 @@ class Customer extends Service
*/
protected
function
actionIsRegistered
(
$email
)
{
$customer
=
C
ustomerModel
::
findOne
([
'email'
=>
$email
]);
$customer
=
$this
->
_c
ustomerModel
::
findOne
([
'email'
=>
$email
]);
if
(
$customer
[
'email'
])
{
return
true
;
}
else
{
...
...
@@ -177,10 +190,10 @@ class Customer extends Service
{
if
(
is_int
(
$identity
))
{
$customer_id
=
$identity
;
$customerModel
=
C
ustomerModel
::
findIdentity
(
$customer_id
);
$customerModel
=
$this
->
_c
ustomerModel
::
findIdentity
(
$customer_id
);
}
elseif
(
is_string
(
$identity
))
{
$email
=
$identity
;
$customerModel
=
C
ustomerModel
::
findByEmail
(
$email
);
$customerModel
=
$this
->
_c
ustomerModel
::
findByEmail
(
$email
);
}
elseif
(
is_object
(
$identity
))
{
$customerModel
=
$identity
;
}
...
...
@@ -199,7 +212,7 @@ class Customer extends Service
*/
protected
function
actionGetModelName
()
{
$model
=
new
CustomerModel
();
$model
=
new
$this
->
_customerModelName
();
return
get_class
(
$model
);
}
...
...
@@ -209,12 +222,12 @@ class Customer extends Service
protected
function
actionGetByPrimaryKey
(
$val
)
{
if
(
$val
)
{
$one
=
C
ustomerModel
::
findOne
(
$val
);
$one
=
$this
->
_c
ustomerModel
::
findOne
(
$val
);
$primaryKey
=
$this
->
getPrimaryKey
();
if
(
$one
[
$primaryKey
])
{
return
$one
;
}
else
{
return
new
CustomerModel
();
return
new
$this
->
_customerModelName
();
}
}
}
...
...
@@ -229,10 +242,10 @@ class Customer extends Service
{
if
(
is_int
(
$identity
))
{
$customer_id
=
$identity
;
$customerModel
=
C
ustomerModel
::
findIdentity
(
$customer_id
);
$customerModel
=
$this
->
_c
ustomerModel
::
findIdentity
(
$customer_id
);
}
elseif
(
is_string
(
$identity
))
{
$email
=
$identity
;
$customerModel
=
C
ustomerModel
::
findByEmail
(
$email
);
$customerModel
=
$this
->
_c
ustomerModel
::
findByEmail
(
$email
);
}
elseif
(
is_object
(
$identity
))
{
$customerModel
=
$identity
;
}
else
{
...
...
@@ -269,11 +282,11 @@ class Customer extends Service
/**
* @property $email | string , email string
* get
C
ustomerModel by Email address.
* get
$this->_c
ustomerModel by Email address.
*/
protected
function
actionGetUserIdentityByEmail
(
$email
)
{
$one
=
C
ustomerModel
::
findByEmail
(
$email
);
$one
=
$this
->
_c
ustomerModel
::
findByEmail
(
$email
);
if
(
$one
[
'email'
])
{
return
$one
;
}
else
{
...
...
@@ -311,7 +324,7 @@ class Customer extends Service
*/
protected
function
actionFindByPasswordResetToken
(
$token
)
{
return
C
ustomerModel
::
findByPasswordResetToken
(
$token
);
return
$this
->
_c
ustomerModel
::
findByPasswordResetToken
(
$token
);
}
/**
...
...
@@ -366,7 +379,7 @@ class Customer extends Service
*/
protected
function
actionGetStatusDeleted
()
{
return
C
ustomerModel
::
STATUS_DELETED
;
return
$this
->
_c
ustomerModel
::
STATUS_DELETED
;
}
/**
...
...
@@ -374,7 +387,7 @@ class Customer extends Service
*/
protected
function
actionGetStatusActive
()
{
return
C
ustomerModel
::
STATUS_ACTIVE
;
return
$this
->
_c
ustomerModel
::
STATUS_ACTIVE
;
}
/**
* 得到customer 表的主键(mysql表)
...
...
@@ -402,7 +415,7 @@ class Customer extends Service
*/
protected
function
actionColl
(
$filter
=
''
)
{
$query
=
C
ustomerModel
::
find
();
$query
=
$this
->
_c
ustomerModel
::
find
();
$query
=
Yii
::
$service
->
helper
->
ar
->
getCollByFilter
(
$query
,
$filter
);
//var_dump($query->all());exit;
return
[
...
...
@@ -420,7 +433,7 @@ class Customer extends Service
{
$arr
=
[];
if
(
is_array
(
$user_ids
)
&&
!
empty
(
$user_ids
))
{
$data
=
C
ustomerModel
::
find
()
->
where
([
$data
=
$this
->
_c
ustomerModel
::
find
()
->
where
([
'in'
,
'id'
,
$user_ids
,
])
->
all
();
if
(
is_array
(
$data
)
&&
!
empty
(
$data
))
{
...
...
services/Order.php
浏览文件 @
01cd1748
...
...
@@ -9,7 +9,7 @@
namespace
fecshop\services
;
use
fecshop\models\mysqldb\Order
as
MyOrder
;
//
use fecshop\models\mysqldb\Order as MyOrder;
use
Yii
;
/**
...
...
@@ -45,7 +45,12 @@ class Order extends Service
// 作为保存incrementId到session的key,把当前的order incrementId保存到session的时候,对应的key就是该常量。
const
CURRENT_ORDER_INCREAMENT_ID
=
'current_order_increament_id'
;
protected
$_orderModelName
=
'\fecshop\models\mysqldb\Order'
;
protected
$_orderModel
;
public
function
__construct
(){
list
(
$this
->
_orderModelName
,
$this
->
_orderModel
)
=
\
Yii
::
mapGet
(
$this
->
_orderModelName
);
}
/**
* @return array
...
...
@@ -128,28 +133,28 @@ class Order extends Service
/**
* @property $primaryKey | Int
* @return Object(
MyOrder
)
* @return Object(
$this->_orderModel
)
* 通过主键值,返回Order Model对象
*/
protected
function
actionGetByPrimaryKey
(
$primaryKey
)
{
$one
=
MyOrder
::
findOne
(
$primaryKey
);
$one
=
$this
->
_orderModel
::
findOne
(
$primaryKey
);
$primaryKey
=
$this
->
getPrimaryKey
();
if
(
$one
[
$primaryKey
])
{
return
$one
;
}
else
{
return
new
MyOrder
();
return
new
$this
->
_orderModelName
();
}
}
/**
* @property $increment_id | String , 订单号
* @return object (
MyOrder),返回 MyOrder
model
* @return object (
$this->_orderModel),返回 $this->_orderModel
model
* 通过订单号incrementId,得到订单Model对象。
*/
protected
function
actionGetByIncrementId
(
$increment_id
)
{
$one
=
MyOrder
::
findOne
([
'increment_id'
=>
$increment_id
]);
$one
=
$this
->
_orderModel
::
findOne
([
'increment_id'
=>
$increment_id
]);
$primaryKey
=
$this
->
getPrimaryKey
();
if
(
$one
[
$primaryKey
])
{
return
$one
;
...
...
@@ -214,7 +219,7 @@ class Order extends Service
if
(
!
$order_id
)
{
return
;
}
$one
=
MyOrder
::
findOne
(
$order_id
);
$one
=
$this
->
_orderModel
::
findOne
(
$order_id
);
$primaryKey
=
$this
->
getPrimaryKey
();
if
(
!
isset
(
$one
[
$primaryKey
])
||
empty
(
$one
[
$primaryKey
]))
{
return
;
...
...
@@ -251,7 +256,7 @@ class Order extends Service
*/
protected
function
actionColl
(
$filter
=
''
)
{
$query
=
MyOrder
::
find
();
$query
=
$this
->
_orderModel
::
find
();
$query
=
Yii
::
$service
->
helper
->
ar
->
getCollByFilter
(
$query
,
$filter
);
$coll
=
$query
->
all
();
...
...
@@ -271,14 +276,14 @@ class Order extends Service
$primaryKey
=
$this
->
getPrimaryKey
();
$primaryVal
=
isset
(
$one
[
$primaryKey
])
?
$one
[
$primaryKey
]
:
''
;
if
(
$primaryVal
)
{
$model
=
MyOrder
::
findOne
(
$primaryVal
);
$model
=
$this
->
_orderModel
::
findOne
(
$primaryVal
);
if
(
!
$model
)
{
Yii
::
$service
->
helper
->
errors
->
add
(
'order '
.
$this
->
getPrimaryKey
()
.
' is not exist'
);
return
;
}
}
else
{
$model
=
new
MyOrder
();
$model
=
new
$this
->
_orderModelName
();
$model
->
created_at
=
time
();
}
$model
->
updated_at
=
time
();
...
...
@@ -303,7 +308,7 @@ class Order extends Service
}
if
(
is_array
(
$ids
)
&&
!
empty
(
$ids
))
{
foreach
(
$ids
as
$id
)
{
$model
=
MyOrder
::
findOne
(
$id
);
$model
=
$this
->
_orderModel
::
findOne
(
$id
);
if
(
isset
(
$model
[
$this
->
getPrimaryKey
()])
&&
!
empty
(
$model
[
$this
->
getPrimaryKey
()]))
{
$model
->
delete
();
}
else
{
...
...
@@ -314,7 +319,7 @@ class Order extends Service
}
}
else
{
$id
=
$ids
;
$model
=
MyOrder
::
findOne
(
$id
);
$model
=
$this
->
_orderModel
::
findOne
(
$id
);
if
(
isset
(
$model
[
$this
->
getPrimaryKey
()])
&&
!
empty
(
$model
[
$this
->
getPrimaryKey
()]))
{
$model
->
delete
();
}
else
{
...
...
@@ -328,7 +333,7 @@ class Order extends Service
}
/**
* @property $increment_id | String , 订单号
* @return object (
MyOrder),返回 MyOrder
model
* @return object (
$this->_orderModel),返回 $this->_orderModel
model
* 通过订单号,得到订单以及订单产品信息。
*/
protected
function
actionGetInfoByIncrementId
(
$increment_id
)
...
...
@@ -355,7 +360,7 @@ class Order extends Service
* 在paypal 点击continue的时候,可以通过token找到对应的订单。
*/
protected
function
actionGeneratePPExpressOrder
(
$token
){
$myOrder
=
new
MyOrder
();
$myOrder
=
new
$this
->
_orderModelName
();
$myOrder
->
payment_token
=
$token
;
$myOrder
->
save
();
$order_id
=
$myOrder
[
'order_id'
];
...
...
@@ -375,7 +380,7 @@ class Order extends Service
* 通过token 得到订单 Object
*/
protected
function
actionGetByPaymentToken
(
$token
){
$one
=
MyOrder
::
find
()
->
where
([
'payment_token'
=>
$token
])
$one
=
$this
->
_orderModel
::
find
()
->
where
([
'payment_token'
=>
$token
])
->
one
();
if
(
isset
(
$one
[
'order_id'
])
&&
$one
[
'order_id'
]){
return
$one
;
...
...
@@ -455,7 +460,7 @@ class Order extends Service
$increment_id
=
$myOrder
[
'increment_id'
];
}
}
else
{
$myOrder
=
new
MyOrder
();
$myOrder
=
new
$this
->
_orderModelName
();
}
$myOrder
[
'order_status'
]
=
$this
->
payment_status_pending
;
$myOrder
[
'store'
]
=
$cartInfo
[
'store'
];
...
...
@@ -542,19 +547,19 @@ class Order extends Service
*/
protected
function
checkOrderVersion
(
$increment_id
){
# 更新订单版本号,防止被多次执行。
$sql
=
'update '
.
MyOrder
::
tableName
()
.
' set version = version + 1 where increment_id = :increment_id'
;
$sql
=
'update '
.
$this
->
_orderModel
::
tableName
()
.
' set version = version + 1 where increment_id = :increment_id'
;
$data
=
[
'increment_id'
=>
$increment_id
,
];
$result
=
MyOrder
::
getDb
()
->
createCommand
(
$sql
,
$data
)
->
execute
();
$
MyOrder
=
MyOrder
::
find
()
->
where
([
$result
=
$this
->
_orderModel
::
getDb
()
->
createCommand
(
$sql
,
$data
)
->
execute
();
$
myOrder
=
$this
->
_orderModel
::
find
()
->
where
([
'increment_id'
=>
$increment_id
,
])
->
one
();
# 如果版本号不等于1,则回滚
if
(
$
M
yOrder
[
'version'
]
>
1
){
if
(
$
m
yOrder
[
'version'
]
>
1
){
Yii
::
$service
->
helper
->
errors
->
add
(
'Your order has been paid'
);
return
false
;
}
else
if
(
$
M
yOrder
[
'version'
]
<
1
){
}
else
if
(
$
m
yOrder
[
'version'
]
<
1
){
Yii
::
$service
->
helper
->
errors
->
add
(
'Your order is error'
);
return
false
;
}
else
{
...
...
services/Request.php
浏览文件 @
01cd1748
...
...
@@ -9,7 +9,7 @@
namespace
fecshop\services
;
use
fecshop\models\mongodb\UrlRewrite
;
//
use fecshop\models\mongodb\UrlRewrite;
use
Yii
;
use
yii\base\InvalidConfigException
;
...
...
@@ -24,6 +24,12 @@ use yii\base\InvalidConfigException;
*/
class
Request
extends
\
yii\web\Request
{
protected
$_urlRewriteModelName
=
'\fecshop\models\mongodb\UrlRewrite'
;
protected
$_urlRewriteModel
;
public
function
__construct
(){
list
(
$this
->
_urlRewriteModelName
,
$this
->
_urlRewriteModel
)
=
\
Yii
::
mapGet
(
$this
->
_urlRewriteModelName
);
}
/**
* rewrite yii\web\Request resolveRequestUri().
*/
...
...
@@ -121,11 +127,11 @@ class Request extends \yii\web\Request
/**
* mongodb url_rewrite collection columns: _id, type ,custom_url, yii_url,
* if selete date from
UrlRewrite
, return the yii url.
* if selete date from
$this->_urlRewriteModel
, return the yii url.
*/
protected
function
getOriginUrl
(
$urlKey
)
{
$UrlData
=
UrlRewrite
::
find
()
->
where
([
$UrlData
=
$this
->
_urlRewriteModel
::
find
()
->
where
([
'custom_url_key'
=>
$urlKey
,
])
->
asArray
()
->
one
();
if
(
$UrlData
[
'custom_url_key'
])
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录