更新异常处理
This commit is contained in:
parent
04372b88b2
commit
ba26f89ed8
@ -24,10 +24,10 @@ class AddressController extends BaseApiController
|
|||||||
$params = (new UserAddressValidate())->post()->goCheck('add');
|
$params = (new UserAddressValidate())->post()->goCheck('add');
|
||||||
$params['uid'] = $this->request->userId;
|
$params['uid'] = $this->request->userId;
|
||||||
$res=AddressLogic::add($params);
|
$res=AddressLogic::add($params);
|
||||||
if($res){
|
if(AddressLogic::hasError()){
|
||||||
return $this->success('添加成功');
|
|
||||||
}else{
|
|
||||||
return $this->fail(AddressLogic::getError());
|
return $this->fail(AddressLogic::getError());
|
||||||
|
}else{
|
||||||
|
return $this->success('添加成功');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -35,7 +35,7 @@ class AddressController extends BaseApiController
|
|||||||
*/
|
*/
|
||||||
public function merchant_create()
|
public function merchant_create()
|
||||||
{
|
{
|
||||||
$params = (new UserAddressValidate())->post()->goCheck('add');
|
$params = $this->request->post();
|
||||||
if($params['order_id'] && $params['order_id']!=0){
|
if($params['order_id'] && $params['order_id']!=0){
|
||||||
$uid=Cashierclass::where('id',$params['order_id'])->value('uid');
|
$uid=Cashierclass::where('id',$params['order_id'])->value('uid');
|
||||||
if(!$uid || $uid<=0){
|
if(!$uid || $uid<=0){
|
||||||
@ -44,10 +44,11 @@ class AddressController extends BaseApiController
|
|||||||
}
|
}
|
||||||
$params['uid'] = $uid;
|
$params['uid'] = $uid;
|
||||||
$res=AddressLogic::add($params);
|
$res=AddressLogic::add($params);
|
||||||
if($res){
|
if(AddressLogic::hasError()){
|
||||||
return $this->success('添加成功');
|
|
||||||
}else{
|
|
||||||
return $this->fail(AddressLogic::getError());
|
return $this->fail(AddressLogic::getError());
|
||||||
|
}else{
|
||||||
|
Cashierclass::where('id',$params['order_id'])->update(['address_id'=>$res,'real_name'=>$params['real_name'],'user_phone'=>$params['phone'],'user_address'=>$params['detail']]);
|
||||||
|
return $this->success('添加成功');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -24,12 +24,14 @@ class AddressLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
public static function add(array $params): bool
|
public static function add(array $params): bool
|
||||||
{
|
{
|
||||||
// Db::startTrans();
|
Db::startTrans();
|
||||||
// try {
|
try {
|
||||||
if($params['is_default']==1){
|
if(isset($params['is_default'])&&$params['is_default']==1){
|
||||||
UserAddress::where('uid',$params['uid'])->update(['is_default'=>0]);
|
UserAddress::where('uid',$params['uid'])->update(['is_default'=>0]);
|
||||||
|
}else{
|
||||||
|
$params['is_default']=1;
|
||||||
}
|
}
|
||||||
UserAddress::create([
|
$id=UserAddress::insertGetId([
|
||||||
'uid' => $params['uid'],
|
'uid' => $params['uid'],
|
||||||
'real_name' => $params['real_name'],
|
'real_name' => $params['real_name'],
|
||||||
'phone' => $params['phone'],
|
'phone' => $params['phone'],
|
||||||
@ -37,12 +39,12 @@ class AddressLogic extends BaseLogic
|
|||||||
'is_default' => $params['is_default'],
|
'is_default' => $params['is_default'],
|
||||||
]);
|
]);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return $id;
|
||||||
// } catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
// Db::rollback();
|
Db::rollback();
|
||||||
// self::setError($e->getMessage());
|
self::setError($e->getMessage());
|
||||||
// return false;
|
return false;
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,11 +5,11 @@ namespace app\common\service;
|
|||||||
|
|
||||||
|
|
||||||
use app\common\enum\ExportEnum;
|
use app\common\enum\ExportEnum;
|
||||||
use app\common\exception\HttpException;
|
|
||||||
use app\common\lists\BaseDataLists;
|
use app\common\lists\BaseDataLists;
|
||||||
use app\common\lists\ListsExcelInterface;
|
use app\common\lists\ListsExcelInterface;
|
||||||
use app\common\lists\ListsExtendInterface;
|
use app\common\lists\ListsExtendInterface;
|
||||||
use support\Response;
|
use support\Response;
|
||||||
|
use support\exception\BusinessException;
|
||||||
|
|
||||||
class JsonService
|
class JsonService
|
||||||
{
|
{
|
||||||
@ -81,7 +81,7 @@ class JsonService
|
|||||||
public static function throw(string $msg = 'fail', array $data = [], int $code = 0, int $show = 1)
|
public static function throw(string $msg = 'fail', array $data = [], int $code = 0, int $show = 1)
|
||||||
{
|
{
|
||||||
$data = compact('code', 'show', 'msg', 'data');
|
$data = compact('code', 'show', 'msg', 'data');
|
||||||
throw new HttpException(json_encode($data));
|
throw new BusinessException(json_encode($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user