提交 01cd1748 编写于 作者: T Terry

二开重写的调整:services 调用model 部分,以及controller调用block部分

上级 6d32cbc6
......@@ -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'],
......
......@@ -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'],
......
......@@ -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 = CustomerModel::findOne(['email' => $email]);
$customer = $this->_customerModel::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 = CustomerModel::findIdentity($customer_id);
$customerModel = $this->_customerModel::findIdentity($customer_id);
} elseif (is_string($identity)) {
$email = $identity;
$customerModel = CustomerModel::findByEmail($email);
$customerModel = $this->_customerModel::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 = CustomerModel::findOne($val);
$one = $this->_customerModel::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 = CustomerModel::findIdentity($customer_id);
$customerModel = $this->_customerModel::findIdentity($customer_id);
} elseif (is_string($identity)) {
$email = $identity;
$customerModel = CustomerModel::findByEmail($email);
$customerModel = $this->_customerModel::findByEmail($email);
} elseif (is_object($identity)) {
$customerModel = $identity;
} else {
......@@ -269,11 +282,11 @@ class Customer extends Service
/**
* @property $email | string , email string
* get CustomerModel by Email address.
* get $this->_customerModel by Email address.
*/
protected function actionGetUserIdentityByEmail($email)
{
$one = CustomerModel::findByEmail($email);
$one = $this->_customerModel::findByEmail($email);
if ($one['email']) {
return $one;
} else {
......@@ -311,7 +324,7 @@ class Customer extends Service
*/
protected function actionFindByPasswordResetToken($token)
{
return CustomerModel::findByPasswordResetToken($token);
return $this->_customerModel::findByPasswordResetToken($token);
}
/**
......@@ -366,7 +379,7 @@ class Customer extends Service
*/
protected function actionGetStatusDeleted()
{
return CustomerModel::STATUS_DELETED;
return $this->_customerModel::STATUS_DELETED;
}
/**
......@@ -374,7 +387,7 @@ class Customer extends Service
*/
protected function actionGetStatusActive()
{
return CustomerModel::STATUS_ACTIVE;
return $this->_customerModel::STATUS_ACTIVE;
}
/**
* 得到customer 表的主键(mysql表)
......@@ -402,7 +415,7 @@ class Customer extends Service
*/
protected function actionColl($filter = '')
{
$query = CustomerModel::find();
$query = $this->_customerModel::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 = CustomerModel::find()->where([
$data = $this->_customerModel::find()->where([
'in', 'id', $user_ids,
])->all();
if (is_array($data) && !empty($data)) {
......
......@@ -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($MyOrder['version'] > 1){
if($myOrder['version'] > 1){
Yii::$service->helper->errors->add('Your order has been paid');
return false;
}else if($MyOrder['version'] < 1){
}else if($myOrder['version'] < 1){
Yii::$service->helper->errors->add('Your order is error');
return false;
}else{
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册