|
@@ -35,9 +35,9 @@ class BaReceiveAddressForm extends Model
|
|
|
|
|
|
|
|
public function init() {
|
|
public function init() {
|
|
|
parent::init();
|
|
parent::init();
|
|
|
- $this->adminOperateLogger = new UserOperate([
|
|
|
|
|
- 'fetchClass' => BaReceiveAddress::class,
|
|
|
|
|
- ]);
|
|
|
|
|
|
|
+// $this->adminOperateLogger = new UserOperate([
|
|
|
|
|
+// 'fetchClass' => BaReceiveAddress::class,
|
|
|
|
|
+// ]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -86,23 +86,25 @@ class BaReceiveAddressForm extends Model
|
|
|
*/
|
|
*/
|
|
|
public function beforeValidate()
|
|
public function beforeValidate()
|
|
|
{
|
|
{
|
|
|
|
|
+ $userId = \Yii::$app->getUser()->getId();
|
|
|
$parentResult = parent::beforeValidate();
|
|
$parentResult = parent::beforeValidate();
|
|
|
if ($this->scenario == 'userAdd' || $this->scenario == 'userEdit' || $this->scenario == 'userIsDefault') {
|
|
if ($this->scenario == 'userAdd' || $this->scenario == 'userEdit' || $this->scenario == 'userIsDefault') {
|
|
|
if ($this->scenario == 'userAdd') {
|
|
if ($this->scenario == 'userAdd') {
|
|
|
- $count = BaReceiveAddress::find()->where('USER_ID=:USER_ID', [':USER_ID' => \Yii::$app->user->id])->count();
|
|
|
|
|
|
|
+
|
|
|
|
|
+ $count = BaReceiveAddress::find()->where('USER_ID=:USER_ID', [':USER_ID' => $userId])->count();
|
|
|
if ($count > 10) {
|
|
if ($count > 10) {
|
|
|
- $this->addError('id', '最多只能添加10个收货地址');
|
|
|
|
|
|
|
+ $this->addError('id', 'A maximum of 10 shipping addresses can be added'); // 最多只能添加10个收货地址
|
|
|
return $parentResult;
|
|
return $parentResult;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if ($this->id) {
|
|
if ($this->id) {
|
|
|
$this->_model = BaReceiveAddress::findOne(["ID" => $this->id]);
|
|
$this->_model = BaReceiveAddress::findOne(["ID" => $this->id]);
|
|
|
if (!$this->_model){
|
|
if (!$this->_model){
|
|
|
- $this->addError('id', '地址不存在');
|
|
|
|
|
|
|
+ $this->addError('id', 'Address does not exist'); // 地址不存在
|
|
|
return $parentResult;
|
|
return $parentResult;
|
|
|
}
|
|
}
|
|
|
- if ($this->_model['USER_ID'] != \Yii::$app->user->id){
|
|
|
|
|
- $this->addError('id', '无权修改此地址');
|
|
|
|
|
|
|
+ if ($this->_model['USER_ID'] != $userId){
|
|
|
|
|
+ $this->addError('id', 'You have no right to modify this address'); // 无权修改此地址
|
|
|
return $parentResult;
|
|
return $parentResult;
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
@@ -122,17 +124,19 @@ class BaReceiveAddressForm extends Model
|
|
|
if(!$this->validate()){
|
|
if(!$this->validate()){
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ $userId = \Yii::$app->getUser()->getId();
|
|
|
$db = \Yii::$app->db;
|
|
$db = \Yii::$app->db;
|
|
|
$transaction = $db->beginTransaction();
|
|
$transaction = $db->beginTransaction();
|
|
|
try {
|
|
try {
|
|
|
// 如果设置了此项为默认则清空所有默认
|
|
// 如果设置了此项为默认则清空所有默认
|
|
|
if ($this->isDefault) {
|
|
if ($this->isDefault) {
|
|
|
- BaReceiveAddress::updateAll(['IS_DEFAULT' => 0], 'USER_ID=:USER_ID', [':USER_ID' => \Yii::$app->user->id]);
|
|
|
|
|
|
|
+ BaReceiveAddress::updateAll(['IS_DEFAULT' => 0], 'USER_ID=:USER_ID', [':USER_ID' => $userId]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if($this->scenario == 'userAdd'){
|
|
if($this->scenario == 'userAdd'){
|
|
|
- $this->_model->USER_ID = \Yii::$app->user->id;
|
|
|
|
|
- $this->_model->USER_NAME = Info::getUserNameByUserId(\Yii::$app->user->id); // TODO:
|
|
|
|
|
|
|
+ $this->_model->USER_ID = $userId;
|
|
|
|
|
+ $this->_model->USER_NAME = Info::getBaUserNameByUserId($userId); // TODO:
|
|
|
$this->_model->CONSIGNEE = $this->consignee;
|
|
$this->_model->CONSIGNEE = $this->consignee;
|
|
|
$this->_model->MOBILE = $this->mobile;
|
|
$this->_model->MOBILE = $this->mobile;
|
|
|
$this->_model->PROVINCE = $this->province;
|
|
$this->_model->PROVINCE = $this->province;
|
|
@@ -153,7 +157,7 @@ class BaReceiveAddressForm extends Model
|
|
|
} elseif($this->scenario == 'userIsDefault') {
|
|
} elseif($this->scenario == 'userIsDefault') {
|
|
|
$this->_model->IS_DEFAULT = $this->isDefault ? 1 : 0;
|
|
$this->_model->IS_DEFAULT = $this->isDefault ? 1 : 0;
|
|
|
} else {
|
|
} else {
|
|
|
- throw new Exception('提交场景不存在');
|
|
|
|
|
|
|
+ throw new Exception('The scene does not exist'); // 场景不存在
|
|
|
}
|
|
}
|
|
|
if(!$this->_model->save()){
|
|
if(!$this->_model->save()){
|
|
|
throw new Exception(Form::formatErrorsForApi($this->_model->getErrors()));
|
|
throw new Exception(Form::formatErrorsForApi($this->_model->getErrors()));
|
|
@@ -166,11 +170,11 @@ class BaReceiveAddressForm extends Model
|
|
|
}
|
|
}
|
|
|
if($this->scenario == 'adminAdd'){
|
|
if($this->scenario == 'adminAdd'){
|
|
|
$this->adminOperateLogger->afterInsert($this->_model)->clean()->save([
|
|
$this->adminOperateLogger->afterInsert($this->_model)->clean()->save([
|
|
|
- 'optType' => '添加收货地址',
|
|
|
|
|
|
|
+ 'optType' => 'Add shipping address', // 添加收货地址
|
|
|
]);
|
|
]);
|
|
|
} elseif($this->scenario == 'adminEdit') {
|
|
} elseif($this->scenario == 'adminEdit') {
|
|
|
$this->adminOperateLogger->afterUpdate($this->_model)->clean()->save([
|
|
$this->adminOperateLogger->afterUpdate($this->_model)->clean()->save([
|
|
|
- 'optType' => '编辑收货地址',
|
|
|
|
|
|
|
+ 'optType' => 'Edit shipping address', // 编辑收货地址
|
|
|
]);
|
|
]);
|
|
|
}
|
|
}
|
|
|
return $this->_model;
|
|
return $this->_model;
|
|
@@ -191,7 +195,7 @@ class BaReceiveAddressForm extends Model
|
|
|
*/
|
|
*/
|
|
|
public function delete($selected) {
|
|
public function delete($selected) {
|
|
|
$this->adminOperateLogger->clean()->save([
|
|
$this->adminOperateLogger->clean()->save([
|
|
|
- 'optType' => '删除收货地址',
|
|
|
|
|
|
|
+ 'optType' => 'Delete shipping address', // 删除收货地址
|
|
|
]);
|
|
]);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|