validate()){ return $this->getModelError(); } if(is_array($this->address_id)){ foreach ($this->address_id as $address_id){ $model = Address::findOne([ 'id' => $address_id, 'is_delete' => 0, 'user_id' => $this->user_id, 'cx_mch_id' => $this->cx_mch_id ]); if($model == null) continue; $model->is_delete = 1; if(!$model->save()){ return $this->getModelError($model); } } } else { $model = Address::findOne([ 'id' => $this->address_id, 'is_delete' => 0, 'user_id' => $this->user_id, 'cx_mch_id' => $this->cx_mch_id ]); if($model == null){ return $this->apiReturnError('地址不存在或已经删除'); } $model->is_delete = 1; if(!$model->save()){ return $this->getModelError($model); } } return $this->apiReturnSuccess("删除成功"); } public function set_default() { if(!$this->validate()){ return $this->getModelError(); } $t = \Yii::$app->db->beginTransaction(); $model = Address::findOne([ 'id' => $this->address_id, 'is_delete' => 0, 'user_id' => $this->user_id, 'cx_mch_id' => $this->cx_mch_id ]); if($model == null){ return $this->apiReturnError('地址不存在或已经删除'); } Address::updateAll(['is_default' => 0],[ 'is_delete' => 0, 'user_id' => $this->user_id, 'cx_mch_id' => $this->cx_mch_id ]); $model->is_default = 1; if(!$model->save()){ $t->rollBack(); return $this->getModelError($model); } $t->commit(); return $this->apiReturnSuccess("设置成功"); } }