feat: 修改了订单相关的API,优化了支付逻辑;
fix: 修复了用户地址、商品库存等错误; refactor: 重构了登录逻辑,提高了代码可读性; style: 调整了代码格式,使其更加规范; test: 增加了订单支付的测试用例; docs: 更新了相关文档; build: 更新了依赖; ops: 优化了服务器性能; chore: 更新了.gitignore文件;
This commit is contained in:
parent
42b19ff900
commit
40ec3e5ee0
app
admin
controller
store_branch_product
store_product
warehouse_order
warehouse_product
logic
store_branch_product
store_product
user
user_ship
warehouse_order
warehouse_product
api
common/logic
@ -46,18 +46,13 @@ class StoreBranchProductController extends BaseAdminController
|
||||
{
|
||||
$params = (new StoreProductValidate())->post()->goCheck('add');
|
||||
$result = StoreProductLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(StoreProductLogic::getError());
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
|
||||
}
|
||||
public function update()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
StoreBranchProductLogic::edit($params);
|
||||
if (StoreBranchProductLogic::hasError()) {
|
||||
return $this->fail(StoreBranchProductLogic::getError());
|
||||
}
|
||||
return $this->success('更新成功', [], 1, 1);
|
||||
}
|
||||
|
||||
@ -110,9 +105,6 @@ class StoreBranchProductController extends BaseAdminController
|
||||
{
|
||||
$params = (new StoreProductValidate())->post()->goCheck('delete');
|
||||
StoreBranchProductLogic::delete($params);
|
||||
if(StoreBranchProductLogic::hasError()){
|
||||
return $this->fail(StoreBranchProductLogic::getError());
|
||||
}
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
@ -44,10 +44,7 @@ class StoreProductController extends BaseAdminController
|
||||
{
|
||||
$params = (new StoreProductValidate())->post()->goCheck('add');
|
||||
$result = StoreProductLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(StoreProductLogic::getError());
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
@ -61,10 +58,8 @@ class StoreProductController extends BaseAdminController
|
||||
{
|
||||
$params = (new StoreProductValidate())->post()->goCheck('edit');
|
||||
$result = StoreProductLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(StoreProductLogic::getError());
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -58,7 +58,6 @@ class WarehouseOrderController extends BaseAdminController
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(WarehouseOrderLogic::getError());
|
||||
}
|
||||
/**
|
||||
* @notes 添加出库单
|
||||
@ -145,7 +144,6 @@ class WarehouseOrderController extends BaseAdminController
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(WarehouseOrderLogic::getError());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -173,9 +171,6 @@ class WarehouseOrderController extends BaseAdminController
|
||||
{
|
||||
$params = (new WarehouseOrderValidate())->post()->goCheck('delete');
|
||||
WarehouseOrderLogic::delete($params);
|
||||
if(WarehouseOrderLogic::hasError()){
|
||||
return $this->fail(WarehouseOrderLogic::getError());
|
||||
}
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
@ -61,12 +61,8 @@ class WarehouseProductController extends BaseAdminController
|
||||
}
|
||||
WarehouseProductLogic::add($data);
|
||||
}
|
||||
|
||||
if (WarehouseProductLogic::hasError()) {
|
||||
return $this->fail(WarehouseProductLogic::getError());
|
||||
} else {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -95,11 +91,8 @@ class WarehouseProductController extends BaseAdminController
|
||||
{
|
||||
$params = (new WarehouseProductValidate())->post()->goCheck('delete');
|
||||
WarehouseProductLogic::delete($params);
|
||||
if (WarehouseProductLogic::hasError()) {
|
||||
return $this->fail(WarehouseProductLogic::getError());
|
||||
} else {
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -52,8 +52,7 @@ class StoreBranchProductLogic extends BaseLogic
|
||||
{
|
||||
$StoreProduct = StoreBranchProduct::where('id', $params['id'])->find();
|
||||
if ($params['status'] == 1 && $StoreProduct['price'] == 0) {
|
||||
self::setError('商品价格不能为0,无法上架');
|
||||
return false;
|
||||
throw new BusinessException('商品价格不能为0,无法上架');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
@ -67,10 +66,9 @@ class StoreBranchProductLogic extends BaseLogic
|
||||
StoreBranchProduct::where('id', $params['id'])->update($data);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
throw new BusinessException('商品编辑失败:',$e->getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
@ -116,8 +114,7 @@ class StoreBranchProductLogic extends BaseLogic
|
||||
{
|
||||
$stock = StoreBranchProduct::where('id', $params['id'])->value('stock');
|
||||
if ($stock > 0) {
|
||||
self::setError('商品库存不为0,无法删除');
|
||||
return false;
|
||||
throw new BusinessException('商品库存不为0,无法删除');
|
||||
}
|
||||
StoreBranchProduct::destroy($params['id']);
|
||||
return true;
|
||||
|
@ -218,7 +218,7 @@ class StoreProductLogic extends BaseLogic
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException('编辑商品失败'.$e->getMessage());
|
||||
|
||||
|
@ -31,6 +31,7 @@ use app\common\model\user_sign\UserSign;
|
||||
use app\common\model\vip_flow\VipFlow;
|
||||
use think\facade\Db;
|
||||
use app\common\service\FileService;
|
||||
use support\exception\BusinessException;
|
||||
use Webman\Config;
|
||||
|
||||
/**
|
||||
@ -69,10 +70,9 @@ class UserLogic extends BaseLogic
|
||||
|
||||
Db::commit();
|
||||
return $res;
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,23 +81,19 @@ class UserLogic extends BaseLogic
|
||||
$user_ship=$params['user_ship']??0;
|
||||
if($user_ship==2){
|
||||
if(!isset($params['village'])){
|
||||
self::setError('请设置村参数');
|
||||
return false;
|
||||
throw new BusinessException('请设置村参数');
|
||||
}
|
||||
$arr=User::where('user_ship',$user_ship)->alias('user')->join('user_address address','user.id=address.uid and village='.$params['village'])->find();
|
||||
if ($arr) {
|
||||
self::setError('该区域已有村长请重新选择');
|
||||
return false;
|
||||
throw new BusinessException('该区域已有村长请重新选择');
|
||||
}
|
||||
}elseif($user_ship==3){
|
||||
if(!isset($params['brigade'])){
|
||||
self::setError('请设置队参数');
|
||||
return false;
|
||||
throw new BusinessException('请设置队参数');
|
||||
}
|
||||
$arr=User::where('user_ship',$user_ship)->alias('user')->join('user_address address','user.id=address.uid and village='.$params['village'] .' and brigade='.$params['brigade'])->find();
|
||||
if($arr){
|
||||
self::setError('该区域已有队长请重新选择');
|
||||
return false;
|
||||
throw new BusinessException('该区域已有队长请重新选择');
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@ -148,8 +144,7 @@ class UserLogic extends BaseLogic
|
||||
return $res;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
@ -179,8 +174,7 @@ class UserLogic extends BaseLogic
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ use app\common\model\user_ship\UserShip;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\user\User;
|
||||
use app\common\model\user\UserAddress;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
@ -106,8 +107,7 @@ class UserShipLogic extends BaseLogic
|
||||
$user_ship=$params['user_ship']??0;
|
||||
if($user_ship==2){
|
||||
if(!isset($params['village'])){
|
||||
self::setError('请设置村参数');
|
||||
return false;
|
||||
throw new BusinessException('请设置村参数');
|
||||
}
|
||||
$arr=User::where('user_ship',$user_ship)->column('id');
|
||||
if($arr){
|
||||
@ -116,14 +116,12 @@ class UserShipLogic extends BaseLogic
|
||||
if($params['uid']==$find['uid']){
|
||||
return true;
|
||||
}
|
||||
self::setError('该区域已有村长请重新选择');
|
||||
return false;
|
||||
throw new BusinessException('该区域已有村长请重新选择');
|
||||
}
|
||||
}
|
||||
}elseif($user_ship==3){
|
||||
if(!isset($params['brigade'])){
|
||||
self::setError('请设置队参数');
|
||||
return false;
|
||||
throw new BusinessException('请设置队参数');
|
||||
}
|
||||
$arr=User::where('user_ship',$user_ship)->column('id');
|
||||
if($arr){
|
||||
@ -132,8 +130,7 @@ class UserShipLogic extends BaseLogic
|
||||
if($params['uid']==$find['uid']){
|
||||
return true;
|
||||
}
|
||||
self::setError('该区域已有队长请重新选择');
|
||||
return false;
|
||||
throw new BusinessException('该区域已有队长请重新选择');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ use app\admin\logic\warehouse_product\WarehouseProductLogic;
|
||||
use app\common\model\warehouse_order\WarehouseOrder;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\warehouse_product\WarehouseProduct;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
@ -69,10 +70,9 @@ class WarehouseOrderLogic extends BaseLogic
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,8 +128,7 @@ class WarehouseOrderLogic extends BaseLogic
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,8 +144,7 @@ class WarehouseOrderLogic extends BaseLogic
|
||||
{
|
||||
$count = WarehouseProduct::where('oid', $params['id'])->count();
|
||||
if ($count >= 1) {
|
||||
self::setError('该订单下还有商品没有删除,请先删除商品');
|
||||
return false;
|
||||
throw new BusinessException('该订单下还有商品没有删除,请先删除商品');
|
||||
}
|
||||
WarehouseOrder::destroy($params['id']);
|
||||
$find = WarehouseProduct::where('oid', $params['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
|
@ -208,8 +208,7 @@ class WarehouseProductLogic extends BaseLogic
|
||||
} elseif ($res['financial_pm'] == 0) {
|
||||
$stock = StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->value('stock');
|
||||
if ($stock < $res['nums']) {
|
||||
self::setError('商品库存不足,无法退回');
|
||||
return false;
|
||||
throw new BusinessException('商品库存不足,无法退回');
|
||||
}
|
||||
StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->dec('stock', $res['nums'])->update();
|
||||
WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->inc('nums', $res['nums'])->update();
|
||||
@ -223,7 +222,7 @@ class WarehouseProductLogic extends BaseLogic
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
throw new BusinessException('没有查到出入库信息');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,9 +19,6 @@ class LoginController extends BaseApiController
|
||||
{
|
||||
$params = (new LoginAccountValidate())->post()->goCheck();
|
||||
$result = LoginLogic::login($params);
|
||||
if (false === $result) {
|
||||
return $this->fail(LoginLogic::getError());
|
||||
}
|
||||
return $this->success('', $result);
|
||||
}
|
||||
/**
|
||||
@ -44,9 +41,6 @@ class LoginController extends BaseApiController
|
||||
{
|
||||
$params = (new WechatLoginValidate())->post()->goCheck('mnpLogin');
|
||||
$res = LoginLogic::mnpLogin($params);
|
||||
if (false === $res) {
|
||||
return $this->fail(LoginLogic::getError());
|
||||
}
|
||||
$res = LoginLogic::dealStaff($res);
|
||||
return $this->success('', $res);
|
||||
}
|
||||
@ -63,9 +57,6 @@ class LoginController extends BaseApiController
|
||||
$params = (new WechatLoginValidate())->post()->goCheck("wechatAuth");
|
||||
$params['user_id'] = $this->userId;
|
||||
$result = LoginLogic::mnpAuthLogin($params);
|
||||
if ($result === false) {
|
||||
return $this->fail(LoginLogic::getError());
|
||||
}
|
||||
return $this->success('绑定成功', [], 1, 1);
|
||||
}
|
||||
|
||||
@ -79,9 +70,6 @@ class LoginController extends BaseApiController
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$result = LoginLogic::updateUser($params, $this->userId);
|
||||
if ($result === false) {
|
||||
return $this->fail(LoginLogic::getError());
|
||||
}
|
||||
return $this->success('操作成功', [], 1, 0);
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ class CartController extends BaseApiController
|
||||
if ($res) {
|
||||
return $this->success('修改成功');
|
||||
} else {
|
||||
return $this->fail(CartLogic::getError());
|
||||
return $this->fail('修改失败');
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@ class CartController extends BaseApiController
|
||||
if ($res) {
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->fail(CartLogic::getError());
|
||||
return $this->fail('删除失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,13 +105,6 @@ class OrderController extends BaseApiController
|
||||
$params = $this->request->post();
|
||||
$user = User::where('id', $this->userId)->find();
|
||||
$res = OrderLogic::cartIdByOrderInfo($cartId, $addressId, $user, $params);
|
||||
if ($res == false) {
|
||||
$msg = OrderLogic::getError();
|
||||
if ($msg == '购物车为空') {
|
||||
return $this->data([]);
|
||||
}
|
||||
return $this->fail(OrderLogic::getError());
|
||||
}
|
||||
return $this->data($res);
|
||||
}
|
||||
|
||||
@ -119,13 +112,6 @@ class OrderController extends BaseApiController
|
||||
{
|
||||
$params = (new OrderValidate())->post()->goCheck('cart');
|
||||
$res = OrderLogic::checkLeft($params, $this->userId);
|
||||
if (!$res) {
|
||||
$msg = OrderLogic::getError();
|
||||
if ($msg == '购物车为空') {
|
||||
return $this->data([]);
|
||||
}
|
||||
return $this->fail(OrderLogic::getError());
|
||||
}
|
||||
return $this->data($res);
|
||||
}
|
||||
|
||||
@ -230,8 +216,6 @@ class OrderController extends BaseApiController
|
||||
return $this->fail('支付方式错误');
|
||||
}
|
||||
// return $this->data(['order_id' => $order->id]);
|
||||
} else {
|
||||
return $this->fail(OrderLogic::getError());
|
||||
}
|
||||
}
|
||||
|
||||
@ -306,17 +290,11 @@ class OrderController extends BaseApiController
|
||||
}
|
||||
}
|
||||
$result = PaymentLogic::pay($pay_type, 'wechat_common', $order, $this->userInfo['terminal'] ?? 1, $redirectUrl);
|
||||
if (PaymentLogic::hasError()) {
|
||||
return $this->fail(PaymentLogic::getError());
|
||||
}
|
||||
return $this->success('', $result);
|
||||
break;
|
||||
case PayEnum::WECHAT_PAY_BARCODE:
|
||||
//微信条码支付
|
||||
$result = PaymentLogic::codepay($auth_code, $order);
|
||||
if (PaymentLogic::hasError()) {
|
||||
return $this->fail(PaymentLogic::getError(), $params);
|
||||
}
|
||||
if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') {
|
||||
PayNotifyLogic::handle('StoreOrder', $result['out_trade_no'], $result);
|
||||
} else {
|
||||
@ -336,9 +314,6 @@ class OrderController extends BaseApiController
|
||||
case PayEnum::ALIPAY_BARCODE:
|
||||
//支付宝条码支付
|
||||
$result = PaymentLogic::ali_auth_code($auth_code, $order);
|
||||
if (PaymentLogic::hasError()) {
|
||||
return $this->fail(PaymentLogic::getError(), $params);
|
||||
}
|
||||
if ($result['msg'] !== 'Success') {
|
||||
return $this->success('用户支付中');
|
||||
}
|
||||
@ -388,11 +363,8 @@ class OrderController extends BaseApiController
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$res = OrderLogic::frequentlyPurchase($params);
|
||||
if (OrderLogic::hasError()) {
|
||||
return $this->fail(OrderLogic::getError());
|
||||
} else {
|
||||
return $this->data($res);
|
||||
}
|
||||
return $this->data($res);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -466,7 +438,7 @@ class OrderController extends BaseApiController
|
||||
if ($res) {
|
||||
return $this->success('核销成功');
|
||||
}
|
||||
return $this->fail('核销失败' . OrderLogic::getError());
|
||||
return $this->fail('核销失败');
|
||||
}
|
||||
|
||||
|
||||
@ -476,7 +448,7 @@ class OrderController extends BaseApiController
|
||||
$date = $this->request->get('date', date('Y-m-d'));
|
||||
$store_id = SystemStoreStaff::where('phone', $this->userInfo['mobile'])->value('store_id');
|
||||
if (empty($store_id)) {
|
||||
throw new \Exception('该用户未绑定店铺');
|
||||
return $this->fail('该用户未绑定店铺');
|
||||
}
|
||||
$where[] = ['store_id', '=', $store_id];
|
||||
$where[] = ['paid', '=', 1];
|
||||
|
@ -89,20 +89,11 @@ class StoreController extends BaseApiController
|
||||
$params['create_uid']=$this->userId;
|
||||
if(isset($params['user_ship']) && in_array($params['user_ship'],[2,3])){
|
||||
UserUserLogic::checkAddress($params);
|
||||
if(UserUserLogic::hasError()){
|
||||
return $this->fail(UserUserLogic::getError());
|
||||
}
|
||||
}
|
||||
$find=UserUserLogic::StoreAdd($params);
|
||||
if(UserUserLogic::hasError()){
|
||||
return $this->fail(UserUserLogic::getError());
|
||||
}
|
||||
}else{
|
||||
if($find['user_ship']!=$params['user_ship'] && in_array($params['user_ship'],[2,3])){
|
||||
UserUserLogic::checkAddress($params);
|
||||
if(UserUserLogic::hasError()){
|
||||
return $this->fail(UserUserLogic::getError());
|
||||
}
|
||||
}
|
||||
$find['real_name']=$params['real_name'];
|
||||
$find['label_id']=$params['label_id']??0;
|
||||
@ -144,9 +135,6 @@ class StoreController extends BaseApiController
|
||||
$order['pay_price']=$order['price'];
|
||||
$order['attach']='recharge';
|
||||
$result = PaymentLogic::codepay($auth_code, $order,'条码支付');
|
||||
if (PaymentLogic::hasError()) {
|
||||
return $this->fail(PaymentLogic::getError());
|
||||
}
|
||||
if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') {
|
||||
Cache::set('trade_state' . time(), json_encode($result));
|
||||
PayNotifyLogic::handle('recharge', $result['out_trade_no'], $result);
|
||||
@ -181,9 +169,6 @@ class StoreController extends BaseApiController
|
||||
$order['pay_price']=$order['price'];
|
||||
$order['attach']='recharge';
|
||||
$result = PaymentLogic::codepay($auth_code, $order,'条码支付');
|
||||
if (PaymentLogic::hasError()) {
|
||||
return $this->fail(PaymentLogic::getError());
|
||||
}
|
||||
if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') {
|
||||
PayNotifyLogic::handle('recharge', $result['out_trade_no'], $result);
|
||||
} else {
|
||||
|
@ -23,11 +23,8 @@ class AddressController extends BaseApiController
|
||||
$params = (new UserAddressValidate())->post()->goCheck('add');
|
||||
$params['uid'] = $this->request->userId;
|
||||
$res=AddressLogic::add($params);
|
||||
if(AddressLogic::hasError()){
|
||||
return $this->fail(AddressLogic::getError());
|
||||
}else{
|
||||
return $this->success('添加成功');
|
||||
}
|
||||
return $this->success('添加成功');
|
||||
|
||||
}
|
||||
/**
|
||||
* 商户给用户添加地址
|
||||
@ -62,9 +59,8 @@ class AddressController extends BaseApiController
|
||||
$params['uid'] = $this->request->userId;
|
||||
if(AddressLogic::edit($params)){
|
||||
return $this->success('编辑成功');
|
||||
}else{
|
||||
return $this->fail(AddressLogic::getError());
|
||||
}
|
||||
return $this->fail('编辑失败');
|
||||
}
|
||||
|
||||
|
||||
|
@ -42,9 +42,7 @@ class UserController extends BaseApiController
|
||||
$params = (new UserValidate())->post()->goCheck('getMobileByMnp');
|
||||
$params['user_id'] = $this->userId;
|
||||
$result = UserLogic::getMobileByMnp($params);
|
||||
if ($result === false) {
|
||||
return $this->fail(UserLogic::getError());
|
||||
}
|
||||
|
||||
if ($result && is_numeric($result)) {
|
||||
$data = UserLogic::info($result);
|
||||
$userInfo = UserTokenService::setToken($result, 1);
|
||||
@ -104,9 +102,6 @@ class UserController extends BaseApiController
|
||||
$order = UserLogic::recharge($params);
|
||||
$redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
|
||||
$result = PaymentLogic::pay(PayEnum::WECHAT_PAY_MINI, 'recharge', $order, $this->userInfo['terminal'], $redirectUrl);
|
||||
if (PaymentLogic::hasError()) {
|
||||
return $this->fail(PaymentLogic::getError(), $params);
|
||||
}
|
||||
return $this->success('', $result);
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,6 @@
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(UserFeedbackLogic::getError());
|
||||
return $this->fail('添加失败');
|
||||
}
|
||||
}
|
||||
|
@ -30,8 +30,6 @@ class UserVisitController extends BaseApiController
|
||||
if (true === $result) {
|
||||
return $this->success('ok');
|
||||
}
|
||||
return $this->fail(UserVisitLogic::getError());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -54,7 +52,6 @@ class UserVisitController extends BaseApiController
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(UserVisitLogic::getError());
|
||||
|
||||
}
|
||||
|
||||
|
@ -38,9 +38,6 @@ class UserProductStorageController extends BaseApiController
|
||||
$store_id=$params['store_id'];
|
||||
$times=$params['times'];
|
||||
UserProductStorageLogic::supply($info,$uid,$store_id,0,$times);
|
||||
if(UserProductStorageLogic::hasError()){
|
||||
return $this->fail(UserProductStorageLogic::getError());
|
||||
}
|
||||
return $this->success('操作成功');
|
||||
}
|
||||
}
|
@ -31,10 +31,7 @@ class UserShipController extends BaseApiController
|
||||
public function is_user_ship(){
|
||||
$data=$this->request->post();
|
||||
UserShipLogic::user_ship($data);
|
||||
if(UserShipLogic::hasError()){
|
||||
return $this->fail(UserShipLogic::getError());
|
||||
}else{
|
||||
return $this->success('ok');
|
||||
}
|
||||
return $this->success('ok');
|
||||
|
||||
}
|
||||
}
|
@ -27,7 +27,7 @@ use app\common\service\{
|
||||
};
|
||||
use app\common\model\user\{User, UserAuth};
|
||||
use app\common\service\wechat\WeChatMnpService;
|
||||
|
||||
use support\exception\BusinessException;
|
||||
use Webman\Config;
|
||||
|
||||
/**
|
||||
@ -88,7 +88,7 @@ class LoginLogic extends BaseLogic
|
||||
|
||||
$user = User::where($where)->findOrEmpty();
|
||||
if ($user->isEmpty()) {
|
||||
throw new \Exception('用户不存在');
|
||||
throw new BusinessException('用户不存在');
|
||||
}
|
||||
|
||||
//更新登录信息
|
||||
@ -121,8 +121,7 @@ class LoginLogic extends BaseLogic
|
||||
'share_name' => $share_name.'No.'.preg_replace('/4/','*', $user['id']),
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -214,9 +213,8 @@ class LoginLogic extends BaseLogic
|
||||
}
|
||||
|
||||
return $userInfo;
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
} catch (\Throwable $e) {
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -242,9 +240,8 @@ class LoginLogic extends BaseLogic
|
||||
// Db::commit();
|
||||
return $userInfo;
|
||||
} catch (\Exception $e) {
|
||||
throw new BusinessException($e->getMessage());
|
||||
// Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -260,7 +257,7 @@ class LoginLogic extends BaseLogic
|
||||
{
|
||||
$user = User::findOrEmpty($userId);
|
||||
if ($user->isEmpty()) {
|
||||
throw new \Exception('用户不存在');
|
||||
throw new BusinessException('用户不存在');
|
||||
}
|
||||
|
||||
$time = time();
|
||||
@ -348,7 +345,7 @@ class LoginLogic extends BaseLogic
|
||||
//先检查openid是否有记录
|
||||
$isAuth = UserAuth::where('openid', '=', $response['openid'])->findOrEmpty();
|
||||
if (!$isAuth->isEmpty()) {
|
||||
throw new \Exception('该微信已被绑定');
|
||||
throw new BusinessException('该微信已被绑定');
|
||||
}
|
||||
|
||||
if (isset($response['unionid']) && !empty($response['unionid'])) {
|
||||
@ -356,7 +353,7 @@ class LoginLogic extends BaseLogic
|
||||
$userAuth = UserAuth::where(['unionid' => $response['unionid']])
|
||||
->findOrEmpty();
|
||||
if (!$userAuth->isEmpty() && $userAuth->user_id != $response['user_id']) {
|
||||
throw new \Exception('该微信已被绑定');
|
||||
throw new BusinessException('该微信已被绑定');
|
||||
}
|
||||
}
|
||||
|
||||
@ -456,8 +453,7 @@ class LoginLogic extends BaseLogic
|
||||
if($find){
|
||||
$auth=UserAuth::where(['user_id'=>$find['id']])->find();//别人的
|
||||
if($auth){
|
||||
self::$error ='该手机号已绑定';
|
||||
return false;
|
||||
throw new BusinessException('该手机号已绑定');
|
||||
}else{
|
||||
UserAuth::where(['user_id'=>$userId])->update(['user_id'=>$find['id']]);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ namespace app\api\logic\order;
|
||||
use app\common\model\order\Cart;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\store_product_log\StoreProductLog;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
@ -28,8 +29,7 @@ class CartLogic extends BaseLogic
|
||||
public static function add(array $params)
|
||||
{
|
||||
if ($params['store_id'] <= 0) {
|
||||
self::setError('门店ID不能为空');
|
||||
return false;
|
||||
throw new BusinessException('门店ID不能为空');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
@ -66,10 +66,9 @@ class CartLogic extends BaseLogic
|
||||
]);
|
||||
Db::commit();
|
||||
return $cart;
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,10 +92,9 @@ class CartLogic extends BaseLogic
|
||||
->update(['cart_num' => $params['cart_num']]);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,15 +67,13 @@ class OrderLogic extends BaseLogic
|
||||
static public function cartIdByOrderInfo($cartId, $addressId, $user = null, $params = [], $createOrder = 0)
|
||||
{
|
||||
if(empty($params['store_id']) || $params['store_id'] <= 0){
|
||||
self::setError('请选择门店');
|
||||
return false;
|
||||
throw new BusinessException('请选择门店');
|
||||
}
|
||||
|
||||
$where = ['is_pay' => 0];
|
||||
$cart_select = Cart::whereIn('id', $cartId)->where($where)->field('id,product_id,cart_num')->select()->toArray();
|
||||
if (empty($cart_select)) {
|
||||
self::setError('购物车为空');
|
||||
return false;
|
||||
throw new BusinessException('购物车为空');
|
||||
}
|
||||
try {
|
||||
self::$total_price = 0;
|
||||
@ -93,14 +91,12 @@ class OrderLogic extends BaseLogic
|
||||
foreach ($cart_select as $k => $v) {
|
||||
$find = StoreBranchProduct::where(['product_id' => $v['product_id'],'store_id'=>$params['store_id']])->field($field)->find();
|
||||
if (!$find) {
|
||||
self::setError('商品不存在');
|
||||
return false;
|
||||
throw new BusinessException('商品不存在');
|
||||
}
|
||||
if (convertNumber($v['cart_num']) == false) {
|
||||
$is_bulk = StoreProductUnit::where('id', $find['unit'])->value('is_bulk');
|
||||
if ($is_bulk == 0) {
|
||||
self::setError('非计量商品,不能有小数,请编辑购物车');
|
||||
return false;
|
||||
throw new BusinessException('非计量商品,不能有小数,请编辑购物车');
|
||||
}
|
||||
}
|
||||
$StoreCategory = StoreCategory::where('id', $find['cate_id'])->find();
|
||||
@ -195,8 +191,7 @@ class OrderLogic extends BaseLogic
|
||||
//判断生鲜是否大于200
|
||||
if ($createOrder == 1 && self::$fresh_price > 0) {
|
||||
if (self::$pay_price < 200) {
|
||||
self::setError('订单包含生鲜产品,订单金额必须大于200元,才能下单');
|
||||
return false;
|
||||
throw new BusinessException('订单包含生鲜产品,订单金额必须大于200元,才能下单');
|
||||
}
|
||||
}
|
||||
if (isset($params['store_id']) && $params['store_id'] == getenv('ACTIVITY_STORE_ID')) {
|
||||
@ -256,10 +251,10 @@ class OrderLogic extends BaseLogic
|
||||
$currentDate = date('Y-m-d');
|
||||
$alert = '当前时间超过配送截止时间16:00,若下单,物品送达时间为' . date('Y-m-d', strtotime($currentDate . '+2 days'));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
d($e);
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
} catch (\Throwable $e) {
|
||||
throw new BusinessException($e->getMessage());
|
||||
|
||||
|
||||
}
|
||||
return ['order' => $order, 'cart_list' => $cart_select, 'shopInfo' => $store['near_store'], 'alert' => $alert];
|
||||
}
|
||||
@ -276,17 +271,10 @@ class OrderLogic extends BaseLogic
|
||||
$params['order_id'] = $order_id;
|
||||
$params['verify_code'] = $verify_code;
|
||||
$orderInfo = self::cartIdByOrderInfo($cartId, $addressId, $user, $params, 1);
|
||||
if ($orderInfo == false) {
|
||||
self::setError(self::getError());
|
||||
return false;
|
||||
}
|
||||
if (!$orderInfo) {
|
||||
return false;
|
||||
}
|
||||
$uid = $user['id'] ?? 0;
|
||||
$_order = $orderInfo['order'];
|
||||
if ($_order['pay_price'] == 0) {
|
||||
throw new \Exception('支付金额不能为0');
|
||||
throw new BusinessException('支付金额不能为0');
|
||||
}
|
||||
$_order['uid'] = $uid;
|
||||
$_order['spread_uid'] = $params['spread_uid'] ?? 0;
|
||||
@ -327,7 +315,7 @@ class OrderLogic extends BaseLogic
|
||||
$_order['status'] = 1;
|
||||
}
|
||||
if ($_order['pay_type'] == PayEnum::BALANCE_PAY && $user != null && $user['now_money'] < $_order['pay_price']) {
|
||||
throw new \Exception('余额不足');
|
||||
throw new BusinessException('余额不足');
|
||||
}
|
||||
//生成核销码
|
||||
// $generator = new BarcodeGeneratorPNG();
|
||||
@ -356,8 +344,7 @@ class OrderLogic extends BaseLogic
|
||||
return $order;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -378,8 +365,7 @@ class OrderLogic extends BaseLogic
|
||||
$cart_select = Cart::whereIn('id', $params['cart_id'])
|
||||
->where($where)->field('id,product_id,cart_num,store_id')->select()->toArray();
|
||||
if (empty($cart_select)) {
|
||||
self::setError('购物车为空');
|
||||
return false;
|
||||
throw new BusinessException('购物车为空');
|
||||
}
|
||||
$newArr = [];
|
||||
//检查购物车对比店铺得商品数量差异
|
||||
@ -447,12 +433,11 @@ class OrderLogic extends BaseLogic
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
Log::error('支付失败' . $e->getMessage() . '。like:' . $e->getLine());
|
||||
self::setError('支付失败' . $e->getMessage());
|
||||
return false;
|
||||
throw new BusinessException('支付失败'. $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -469,9 +454,8 @@ class OrderLogic extends BaseLogic
|
||||
$goods_arr = array_unique($goods_id);
|
||||
$select = StoreBranchProduct::where('product_id', 'in', $goods_arr)->with('unitName')->field('id,store_name,price,image,unit')->select();
|
||||
return $select->toArray();
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
} catch (\Throwable $e) {
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -584,8 +568,7 @@ class OrderLogic extends BaseLogic
|
||||
'verify_code' => $params['verify_code']
|
||||
])->find();
|
||||
if (empty($order)) {
|
||||
self::setError('订单不存在');
|
||||
return false;
|
||||
throw new BusinessException('订单不存在');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
@ -631,10 +614,9 @@ class OrderLogic extends BaseLogic
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -643,7 +625,7 @@ class OrderLogic extends BaseLogic
|
||||
{
|
||||
$store_id = SystemStoreStaff::where('phone', $info['mobile'])->value('store_id');
|
||||
if (empty($store_id)) {
|
||||
throw new \Exception('该用户未绑定店铺请查看');
|
||||
throw new BusinessException('该用户未绑定店铺请查看');
|
||||
}
|
||||
$query = StoreOrderCartInfo::alias('o')
|
||||
->leftJoin('store_branch_product p', 'p.id = o.product_id')
|
||||
@ -693,7 +675,7 @@ class OrderLogic extends BaseLogic
|
||||
|
||||
$store_id = SystemStoreStaff::where('phone', $info['mobile'])->value('store_id');
|
||||
if (empty($store_id)) {
|
||||
throw new \Exception('该用户未绑定店铺请查看');
|
||||
throw new BusinessException('该用户未绑定店铺请查看');
|
||||
}
|
||||
|
||||
//先查商品相似
|
||||
@ -785,7 +767,7 @@ class OrderLogic extends BaseLogic
|
||||
self::dealChangeCartInfo($refundOrder);
|
||||
// d($leftOrder,$refundOrder);
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
|
@ -4,6 +4,7 @@ namespace app\api\logic\user;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\user\UserAddress;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
@ -48,10 +49,9 @@ class AddressLogic extends BaseLogic
|
||||
]);
|
||||
Db::commit();
|
||||
return $id;
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,10 +95,9 @@ class AddressLogic extends BaseLogic
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,8 @@
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\user\UserFeedback;
|
||||
use think\facade\Db;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
class UserFeedbackLogic extends BaseLogic
|
||||
{
|
||||
@ -29,10 +30,10 @@
|
||||
]);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
throw new BusinessException($e->getMessage());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -24,6 +24,7 @@ use app\common\{logic\BaseLogic,
|
||||
use app\common\logic\UserSignLogic;
|
||||
use app\common\model\user_label\UserLabel;
|
||||
use support\Cache;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
@ -49,7 +50,7 @@ class UserLogic extends BaseLogic
|
||||
$response = (new WeChatMnpService())->getUserPhoneNumber($params['code']);
|
||||
$phoneNumber = $response['phone_info']['purePhoneNumber'] ?? '';
|
||||
if (empty($phoneNumber)) {
|
||||
throw new \Exception('获取手机号码失败');
|
||||
throw new BusinessException('获取手机号码失败');
|
||||
}
|
||||
|
||||
$user = User::where([
|
||||
@ -75,9 +76,8 @@ class UserLogic extends BaseLogic
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
} catch (\Throwable $e) {
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -211,7 +211,7 @@ class UserLogic extends BaseLogic
|
||||
$code = generateRandomCode();
|
||||
$phone = User::where('id',$uid)->value('mobile');
|
||||
if(empty($phone)){
|
||||
throw new \Exception('用户未设置手机号');
|
||||
throw new BusinessException('用户未设置手机号');
|
||||
}
|
||||
$template = getenv('SMS_TEMPLATE');
|
||||
$check =(new SmsService())->client($phone,$template,$code);
|
||||
|
@ -5,7 +5,8 @@
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\store_visit\StoreVisit;
|
||||
use app\common\model\user\UserVisit;
|
||||
use think\facade\Db;
|
||||
use support\Log;
|
||||
use think\facade\Db;
|
||||
|
||||
class UserVisitLogic extends BaseLogic
|
||||
{
|
||||
@ -39,10 +40,9 @@
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
Log::error('添加商品浏览失败:'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,10 +70,9 @@
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
Log::error('添加用户访问失败:'.$e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
|
@ -8,7 +8,9 @@ use app\common\enum\PayEnum;
|
||||
use app\common\model\user\UserAuth;
|
||||
use app\common\service\pay\PayService;
|
||||
use Exception;
|
||||
use support\exception\BusinessException;
|
||||
use support\Log;
|
||||
use Throwable;
|
||||
|
||||
use function DI\string;
|
||||
|
||||
@ -40,34 +42,33 @@ class PaymentLogic extends BaseLogic
|
||||
return ['pay_way' => PayEnum::BALANCE_PAY];
|
||||
}
|
||||
try {
|
||||
if(isset($order['price'])){
|
||||
$order['pay_price'] = $order['price'];
|
||||
}
|
||||
switch ($payWay) {
|
||||
case PayEnum::WECHAT_PAY_MINI:
|
||||
$auth = UserAuth::where(['user_id' => $order['uid'], 'terminal' => $terminal])->findOrEmpty();
|
||||
$order = [
|
||||
'out_trade_no' => $paySn,
|
||||
'description' => '商品',
|
||||
'amount' => [
|
||||
'total' => intval($order['pay_price'] * 100),
|
||||
'currency' => 'CNY',
|
||||
],
|
||||
"payer" => [
|
||||
"openid" => $auth['openid']
|
||||
],
|
||||
'attach' => $from
|
||||
];
|
||||
$wechat = new PayService(1);
|
||||
$result = $wechat->wechat->mini($order)->toArray();
|
||||
break;
|
||||
default:
|
||||
self::$error = '订单异常';
|
||||
$result = false;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
\support\Log::info($e->extra['message']?? $e->getMessage());
|
||||
throw new \Exception($e->extra['message']?? $e->getMessage());
|
||||
if (isset($order['price'])) {
|
||||
$order['pay_price'] = $order['price'];
|
||||
}
|
||||
switch ($payWay) {
|
||||
case PayEnum::WECHAT_PAY_MINI:
|
||||
$auth = UserAuth::where(['user_id' => $order['uid'], 'terminal' => $terminal])->findOrEmpty();
|
||||
$order = [
|
||||
'out_trade_no' => $paySn,
|
||||
'description' => '商品',
|
||||
'amount' => [
|
||||
'total' => intval($order['pay_price'] * 100),
|
||||
'currency' => 'CNY',
|
||||
],
|
||||
"payer" => [
|
||||
"openid" => $auth['openid']
|
||||
],
|
||||
'attach' => $from
|
||||
];
|
||||
$wechat = new PayService(1);
|
||||
$result = $wechat->wechat->mini($order)->toArray();
|
||||
break;
|
||||
default:
|
||||
throw new BusinessException('支付方式异常');
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
Log::info($e->extra['message'] ?? $e->getMessage());
|
||||
throw new BusinessException($e->extra['message'] ?? $e->getMessage());
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
@ -75,13 +76,12 @@ class PaymentLogic extends BaseLogic
|
||||
/**
|
||||
* 微信条码支付
|
||||
*/
|
||||
public static function codepay($auth_code, $order,$description='条码商品')
|
||||
public static function codepay($auth_code, $order, $description = '条码商品')
|
||||
{
|
||||
$pattern = '/^(10|11|12|13|14|15)\d{16}$/';
|
||||
|
||||
if (!preg_match($pattern, (string)$auth_code)) {
|
||||
self::$error = '请使用正确的微信收付款条码';
|
||||
return false;
|
||||
throw new BusinessException('请使用正确的微信收付款条码');
|
||||
}
|
||||
$data = [
|
||||
'description' => $description,
|
||||
@ -94,26 +94,25 @@ class PaymentLogic extends BaseLogic
|
||||
],
|
||||
'scene_info' => [
|
||||
"store_info" => [
|
||||
'id' => (string)$order['store_id']??1
|
||||
'id' => (string)$order['store_id'] ?? 1
|
||||
]
|
||||
],
|
||||
'attach'=>'wechat_common'
|
||||
'attach' => 'wechat_common'
|
||||
];
|
||||
if(isset($order['attach']) && $order['attach']!=''){
|
||||
if (isset($order['attach']) && $order['attach'] != '') {
|
||||
$data['attach'] = $order['attach'];
|
||||
}
|
||||
$wechat = new PayService(1);
|
||||
try {
|
||||
$result = $wechat->wechat->pos($data)->toArray();
|
||||
} catch (Exception $e) {
|
||||
Log::error('条码支付报错',['message' => $e->extra['message']?? $e->getMessage(),'code'=>$e->getCode()]);
|
||||
} catch (Throwable $e) {
|
||||
Log::error('条码支付报错', ['message' => $e->extra['message'] ?? $e->getMessage(), 'code' => $e->getCode()]);
|
||||
|
||||
if (getenv('APP_DEBUG') == true) {
|
||||
self::$error = $e->extra['message'] ?? $e->getMessage();
|
||||
throw new BusinessException($e->extra['message'] ?? $e->getMessage());
|
||||
} else {
|
||||
self::$error = $e->getMessage();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
@ -126,26 +125,24 @@ class PaymentLogic extends BaseLogic
|
||||
$pattern = '/^(25|26|27|28|29|30)[0-9A-Za-z]{14,23}$/';
|
||||
|
||||
if (!preg_match($pattern, (string)$auth_code)) {
|
||||
self::$error = '请使用正确的支付宝收付款条码';
|
||||
return false;
|
||||
throw new BusinessException('请使用正确的支付宝收付款条码');
|
||||
}
|
||||
$order = [
|
||||
'subject' => '条码商品',
|
||||
'out_trade_no' => (string)$order['order_id'],
|
||||
'auth_code' => (string)$auth_code,
|
||||
'total_amount' => $order['pay_price'],
|
||||
'extend_params'=>['attach'=>'alipay_cashier']
|
||||
'extend_params' => ['attach' => 'alipay_cashier']
|
||||
];
|
||||
$wechat = new PayService();
|
||||
try {
|
||||
$result = $wechat->alipay->pos($order)->toArray();
|
||||
} catch (Exception $e) {
|
||||
} catch (Throwable $e) {
|
||||
if (getenv('APP_DEBUG') == true) {
|
||||
self::$error = $e->extra['message'] ?? $e->getMessage();
|
||||
throw new BusinessException($e->extra['message'] ?? $e->getMessage());
|
||||
} else {
|
||||
self::$error = $e->getMessage();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||
use app\common\model\user\User;
|
||||
use app\common\model\user_product_storage\UserProductStorage;
|
||||
use app\common\model\user_product_storage_log\UserProductStorageLog;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
@ -54,9 +55,7 @@ class UserProductStorageLogic extends BaseLogic
|
||||
$find=UserProductStorage::where('uid',$uid)->where('product_id',$v['product_id'])->find();
|
||||
if($find){
|
||||
if($find['nums']<$v['nums']){
|
||||
self::setError('库存不足');
|
||||
Db::commit();
|
||||
return false;
|
||||
throw new BusinessException("库存不足");
|
||||
}
|
||||
$nums=bcsub($find['nums'],$v['nums']);
|
||||
$find->nums=$nums;
|
||||
@ -86,17 +85,14 @@ class UserProductStorageLogic extends BaseLogic
|
||||
$data_log[$k]['times']=$times;
|
||||
$data_log[$k]['status']=$status;
|
||||
}else{
|
||||
self::setError('没有查询到该商品');
|
||||
Db::commit();
|
||||
return false;
|
||||
throw new BusinessException("没有查询到该商品");
|
||||
}
|
||||
}
|
||||
(new UserProductStorageLog())->saveAll($data_log);
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user