1
This commit is contained in:
parent
b0f124070c
commit
5bbaaeab44
@ -52,12 +52,13 @@ class StoreOrderController extends BaseAdminController
|
|||||||
*/
|
*/
|
||||||
public function add()
|
public function add()
|
||||||
{
|
{
|
||||||
$params = (new StoreOrderValidate())->post()->goCheck('add');
|
$params = $this->request->post();
|
||||||
$result = StoreOrderLogic::add($params);
|
$result = StoreOrderLogic::add($params);
|
||||||
if (true === $result) {
|
if (StoreOrderLogic::hasError()) {
|
||||||
return $this->success('添加成功', [], 1, 1);
|
return $this->fail(StoreOrderLogic::getError());
|
||||||
|
}else{
|
||||||
|
return $this->success('添加成功,请在30分钟内支付', [], 1, 1);
|
||||||
}
|
}
|
||||||
return $this->fail(StoreOrderLogic::getError());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,11 +2,14 @@
|
|||||||
|
|
||||||
namespace app\admin\logic\store_order;
|
namespace app\admin\logic\store_order;
|
||||||
|
|
||||||
|
use app\api\logic\order\CartLogic;
|
||||||
|
use app\api\logic\order\OrderLogic;
|
||||||
use app\common\enum\PayEnum;
|
use app\common\enum\PayEnum;
|
||||||
use app\common\model\store_order\StoreOrder;
|
use app\common\model\store_order\StoreOrder;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
use app\common\logic\PayNotifyLogic;
|
use app\common\logic\PayNotifyLogic;
|
||||||
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||||
|
use app\common\model\user\User;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
|
|
||||||
|
|
||||||
@ -28,15 +31,23 @@ class StoreOrderLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
public static function add(array $params): bool
|
public static function add(array $params): bool
|
||||||
{
|
{
|
||||||
Db::startTrans();
|
$cartId = [];
|
||||||
try {
|
foreach ($params['product_arr'] as $k => $v) {
|
||||||
StoreOrder::create([]);
|
$v['uid'] = $params['user_id'];
|
||||||
|
$v['store_id'] = $params['store_id'];
|
||||||
Db::commit();
|
$v['product_id'] = $v['id'];
|
||||||
|
$v['cart_num'] = $v['stock'];
|
||||||
|
$res = CartLogic::add($v);
|
||||||
|
$cartId[] = $res['id'];
|
||||||
|
}
|
||||||
|
$user = User::where('id', $params['user_id'])->find();
|
||||||
|
$params['shipping_type'] = 2;
|
||||||
|
$params['pay_type'] = 7;
|
||||||
|
$order = OrderLogic::createOrder($cartId, null, $user, $params);
|
||||||
|
if ($order != false) {
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} else {
|
||||||
Db::rollback();
|
OrderLogic::getError();
|
||||||
self::setError($e->getMessage());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,9 @@ class CartLogic extends BaseLogic
|
|||||||
* @author likeadmin
|
* @author likeadmin
|
||||||
* @date 2024/04/24 10:37
|
* @date 2024/04/24 10:37
|
||||||
*/
|
*/
|
||||||
public static function add(array $params): bool
|
public static function add(array $params)
|
||||||
{
|
{
|
||||||
if($params['store_id']<=0){
|
if ($params['store_id'] <= 0) {
|
||||||
self::setError('门店ID不能为空');
|
self::setError('门店ID不能为空');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -38,35 +38,35 @@ class CartLogic extends BaseLogic
|
|||||||
'uid' => $params['uid'],
|
'uid' => $params['uid'],
|
||||||
'store_id' => $params['store_id'],
|
'store_id' => $params['store_id'],
|
||||||
'product_id' => $params['product_id'],
|
'product_id' => $params['product_id'],
|
||||||
'is_pay'=>0
|
'is_pay' => 0
|
||||||
])->field('id')->find();
|
])->field('id')->find();
|
||||||
if($check){
|
if ($check) {
|
||||||
Cart::where('id',$check['id'])->inc('cart_num',$params['cart_num'])
|
Cart::where('id', $check['id'])->inc('cart_num', $params['cart_num'])
|
||||||
->update();
|
->update();
|
||||||
$cart['id'] = $check['id'];
|
$cart['id'] = $check['id'];
|
||||||
}else{
|
} else {
|
||||||
$cart = Cart::create([
|
$cart = Cart::create([
|
||||||
'uid' => $params['uid'],
|
'uid' => $params['uid'],
|
||||||
'type' => $params['type']??'',
|
'type' => $params['type'] ?? '',
|
||||||
'product_id' => $params['product_id'],
|
'product_id' => $params['product_id'],
|
||||||
'store_id' => $params['store_id']??0,
|
'store_id' => $params['store_id'] ?? 0,
|
||||||
'staff_id' => $params['staff_id']??0,
|
'staff_id' => $params['staff_id'] ?? 0,
|
||||||
'product_attr_unique' => '',
|
'product_attr_unique' => '',
|
||||||
'cart_num' => $params['cart_num'],
|
'cart_num' => $params['cart_num'],
|
||||||
'is_new' => $params['is_new']??0,
|
'is_new' => $params['is_new'] ?? 0,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
StoreProductLog::create([
|
StoreProductLog::create([
|
||||||
'type'=>'cart',
|
'type' => 'cart',
|
||||||
'uid' => $params['uid'],
|
'uid' => $params['uid'],
|
||||||
'cart_id' => $cart['id'],
|
'cart_id' => $cart['id'],
|
||||||
'store_id' => $params['store_id']??0,
|
'store_id' => $params['store_id'] ?? 0,
|
||||||
'visit_num' => 1,
|
'visit_num' => 1,
|
||||||
'product_id' => $params['product_id'],
|
'product_id' => $params['product_id'],
|
||||||
'cart_num' => $params['cart_num'],
|
'cart_num' => $params['cart_num'],
|
||||||
]);
|
]);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return $cart;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Db::rollback();
|
Db::rollback();
|
||||||
self::setError($e->getMessage());
|
self::setError($e->getMessage());
|
||||||
@ -82,14 +82,16 @@ class CartLogic extends BaseLogic
|
|||||||
* @author likeadmin
|
* @author likeadmin
|
||||||
* @date 2024/04/24 10:37
|
* @date 2024/04/24 10:37
|
||||||
*/
|
*/
|
||||||
public static function edit(array $params,$type='inc'): bool
|
public static function edit(array $params, $type = 'inc'): bool
|
||||||
{
|
{
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
Cart::where(['uid'=>$params['uid'],
|
Cart::where([
|
||||||
'store_id'=>$params['store_id'],
|
'uid' => $params['uid'],
|
||||||
'product_id'=>$params['product_id']])
|
'store_id' => $params['store_id'],
|
||||||
->update(['cart_num'=>$params['cart_num']]);
|
'product_id' => $params['product_id']
|
||||||
|
])
|
||||||
|
->update(['cart_num' => $params['cart_num']]);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -124,4 +126,4 @@ class CartLogic extends BaseLogic
|
|||||||
{
|
{
|
||||||
return Cart::findOrEmpty($params['id'])->toArray();
|
return Cart::findOrEmpty($params['id'])->toArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user