57 lines
1.6 KiB
PHP
57 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace app\api\logic;
|
|
|
|
use app\common\logic\BaseLogic;
|
|
use app\common\model\Cart;
|
|
use app\common\model\CartProduct;
|
|
use app\common\model\Order;
|
|
use app\common\model\user\User;
|
|
use app\common\model\user\UserAddress;
|
|
use think\facade\Db;
|
|
use Tinywan\Jwt\JwtToken;
|
|
|
|
class OrderLogic extends BaseLogic
|
|
{
|
|
|
|
public function check($params)
|
|
{
|
|
$query = Cart::with(['cartDishes'])
|
|
->where('uid', $params['uid'])
|
|
->where('buy_now', 0)
|
|
->where('.paid', 0);
|
|
return $query->select()->toArray();
|
|
}
|
|
|
|
public function create($params)
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
$carts = Cart::with(['cartDishes', 'cartProduct'])->where('uid', $params['uid'])->whereIn('id', $params['cart_ids'])->where('paid', 0)->where('buy_now', 0)->select()->toArray();
|
|
$orderData = [
|
|
'uid' => $params['uid'],
|
|
'order_sn' => Order::generateOrderSn(),
|
|
'order_type' => 0,
|
|
];
|
|
foreach ($carts as $cart) {
|
|
$orderData[] = [];
|
|
}
|
|
$cartWhere = ['uid' => $params['uid'], 'paid' => 0, 'buy_now' => 0];
|
|
Cart::update(['people_number' => $params['people_number']], $cartWhere);
|
|
$cartIds = Cart::where($cartWhere)->column('id');
|
|
CartProduct::whereIn('cart_id', $cartIds)->where('uid', $params['uid'])->update(['people_number' => $params['people_number']]);
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
Db::rollback();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function list()
|
|
{
|
|
|
|
}
|
|
|
|
}
|