|
@@ -14,6 +14,7 @@ use app\api\model\CartProductModel;
|
|
|
use app\api\model\CartModel;
|
|
|
use app\api\model\GroupModel;
|
|
|
use app\api\model\OrderModel;
|
|
|
+use app\api\model\OrderProductModel;
|
|
|
use app\api\model\ProductModel;
|
|
|
use app\api\model\UserModel;
|
|
|
use app\api\model\WriteOffModel;
|
|
@@ -72,8 +73,13 @@ class Order extends BaseController {
|
|
|
$where[] = ['o.mobile', 'like', "%{$input['mobile']}%"];
|
|
|
}
|
|
|
|
|
|
+
|
|
|
if (!empty($input['writeOffStatus'])) {
|
|
|
- $where[] = ['wo.write_off_status', '=', (int)$input['writeOffStatus']];
|
|
|
+ if (empty($input['foodOrder'])) {
|
|
|
+ $where[] = ['wo.write_off_status', '=', (int)$input['writeOffStatus']];
|
|
|
+ }else if ($input['foodOrder'] == 2){
|
|
|
+ $model->setOp('write_off_status', 'left');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (!empty($input['orderStatus'])) {
|
|
@@ -99,7 +105,7 @@ class Order extends BaseController {
|
|
|
}
|
|
|
|
|
|
if (!empty($input['orderType'])) {
|
|
|
- $where[] = ['store.order_type', '=', $input['orderType']];
|
|
|
+ $where[] = ['o.order_type', '=', $input['orderType']];
|
|
|
}
|
|
|
|
|
|
if (!$this->isAdmin()) {
|
|
@@ -111,9 +117,20 @@ class Order extends BaseController {
|
|
|
|
|
|
$model->setWhere($where);
|
|
|
$data = $model->getOrderList();
|
|
|
+ $orderIds = array_column($data['list'], 'id');
|
|
|
+ $productList = (new OrderProductModel())::where([['order_id', 'in', $orderIds]])->select();
|
|
|
+ $productList = Until::modelToArray($productList);
|
|
|
+ $product = [];
|
|
|
+ foreach ($productList as &$v) {
|
|
|
+ unset($v['product_snap']);
|
|
|
+ $product[$v['order_id']][] = $v;
|
|
|
+ }
|
|
|
+
|
|
|
$statusFilter = [1 => '未支付', 2 => '已支付', 3 => '已关闭'];
|
|
|
|
|
|
foreach ($data['list'] as &$one) {
|
|
|
+
|
|
|
+ $one['productList'] = $product[$one['id']] ?? [];
|
|
|
$one['statusText'] = $statusFilter[$one['status']];
|
|
|
if ($one['status'] === OrderModel::IS_PAY) {
|
|
|
if ($one['write_off_status'] == 1) {
|
|
@@ -171,6 +188,12 @@ class Order extends BaseController {
|
|
|
$where[] = ['o.id', '=', (int)$id];
|
|
|
$model->setWhere($where);
|
|
|
$info = $model->getOrderInfo();
|
|
|
+ $productList = (new OrderProductModel())::where([['order_id', '=', $info['id']]])->select();
|
|
|
+ $productList = Until::modelToArray($productList);
|
|
|
+ foreach ($productList as &$v) {
|
|
|
+ unset($v['product_snap']);
|
|
|
+ }
|
|
|
+ $info['productList'] = $productList;
|
|
|
Until::output(['info' => $info]);
|
|
|
}
|
|
|
|
|
@@ -250,7 +273,8 @@ class Order extends BaseController {
|
|
|
* mediaType="multipart/form-data",
|
|
|
* @OA\Schema(
|
|
|
* @OA\Property(description="购物车id", property="cartId", type="integer", default="1"),
|
|
|
- * required={"cartId"})
|
|
|
+ * @OA\Property(description="台桌id", property="tableId", type="integer", default="1"),
|
|
|
+ * required={"cartId","tableId"})
|
|
|
* )
|
|
|
* ),
|
|
|
* @OA\Response(response="200", description="请求成功")
|
|
@@ -260,6 +284,7 @@ class Order extends BaseController {
|
|
|
$input = Until::getInput();
|
|
|
$rule = [
|
|
|
'cartId|商品id和数量' => 'require',
|
|
|
+ 'tableId|桌台id' => 'require',
|
|
|
];
|
|
|
Until::check($rule, $input);
|
|
|
$data = (new OrderService())->payFoodOrder($input);
|
|
@@ -520,17 +545,28 @@ class Order extends BaseController {
|
|
|
}
|
|
|
|
|
|
if ($input['type'] == 2) {
|
|
|
+ if ($rs['num'] == 1) {
|
|
|
+ $cartProductModel::where(['id' => $rs['id']])->delete();
|
|
|
+ }
|
|
|
$cartProductModel::where(['id' => $rs['id']])->dec('num', 1)->update();
|
|
|
}
|
|
|
}
|
|
|
$cartInfo = Until::modelToArray($cartInfo);
|
|
|
- $cartModel->setFields('cp.product_id,cp.num,p.product_name,p.current_price,p.product_img');
|
|
|
+ $cartModel->setFields('c.*,cp.product_id,cp.num,p.product_name,p.current_price,p.product_img');
|
|
|
$rs = $cartModel->getCartList();
|
|
|
- $cartInfo['list'] = $rs;
|
|
|
+ $cartInfo['totalNum'] = 0;
|
|
|
+ $cartInfo['totalPrice'] = 0;
|
|
|
+ foreach ($rs as $v) {
|
|
|
+ $cartInfo['totalNum'] += $v['num'];
|
|
|
+ $cartInfo['totalPrice'] += $v['num'] * $v['current_price'];
|
|
|
+ }
|
|
|
+ $cartInfo['id'] = $v['id'];
|
|
|
+ $cartInfo['table_id'] = $v['table_id'];
|
|
|
+ $cartInfo['store_id'] = $v['store_id'];
|
|
|
+ $cartInfo['user_id'] = $v['user_id'];
|
|
|
+ $cartInfo['create_time'] = $v['create_time'];
|
|
|
+ $cartInfo['list'] = $cartInfo['totalNum'] == 0 ? [] : $rs;
|
|
|
Until::output($cartInfo);
|
|
|
-
|
|
|
-
|
|
|
- Until::output();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -558,30 +594,74 @@ class Order extends BaseController {
|
|
|
];
|
|
|
Until::check($rule, $input);
|
|
|
$model = new CartModel();
|
|
|
- $cartInfo = $model::where([
|
|
|
- 'table_id' => $input['tableId'],
|
|
|
- 'store_id' => (int)$input['storeId'],
|
|
|
- 'user_id' => $this->userId,
|
|
|
- 'status' => CartModel::NORMAL
|
|
|
- ])->find();
|
|
|
- if (empty($cartInfo)) {
|
|
|
- $model->insertGetId([
|
|
|
- 'table_id' => $input['tableId'],
|
|
|
+ try {
|
|
|
+ $model->startTrans();
|
|
|
+ $whereData = [
|
|
|
+ 'table_id' => (int)$input['tableId'],
|
|
|
'store_id' => (int)$input['storeId'],
|
|
|
'user_id' => $this->userId,
|
|
|
'status' => CartModel::NORMAL
|
|
|
+ ];
|
|
|
+ $cartInfo = $model::where($whereData)->find();
|
|
|
+ $cartInfo = Until::modelToArray($cartInfo);
|
|
|
+ if (empty($cartInfo)) {
|
|
|
+ $id = $model->insertGetId($whereData);
|
|
|
+ }
|
|
|
+ $model->setWhere([
|
|
|
+ 'c.status' => CartModel::NORMAL,
|
|
|
+ 'c.user_id' => $this->userId,
|
|
|
+ 'c.table_id' => (int)$input['tableId'],
|
|
|
+ 'c.store_id' => (int)$input['storeId']
|
|
|
]);
|
|
|
+
|
|
|
+ $model->setFields('c.*,cp.product_id,cp.num,p.product_name,p.current_price,p.product_img');
|
|
|
+ $rs = $model->getCartList();
|
|
|
+ $model->commit();
|
|
|
+ }catch (\Exception $e) {
|
|
|
+ $model->rollback();
|
|
|
+ throw new ApiException($e->getMessage());
|
|
|
}
|
|
|
- $model->setWhere([
|
|
|
- 'c.status' => CartModel::NORMAL,
|
|
|
- 'c.user_id' => $this->userId,
|
|
|
- 'c.table_id' => $input['tableId'],
|
|
|
- 'c.store_id' => $input['storeId']
|
|
|
- ]);
|
|
|
- $cartInfo = Until::modelToArray($cartInfo);
|
|
|
- $model->setFields('cp.product_id,cp.num,p.product_name,p.current_price,p.product_img');
|
|
|
- $rs = $model->getCartList();
|
|
|
- $cartInfo['list'] = $rs;
|
|
|
+
|
|
|
+ $cartInfo['totalPrice'] = 0;
|
|
|
+ $cartInfo['totalNum'] = 0;
|
|
|
+ foreach ($rs as $v) {
|
|
|
+ $cartInfo['totalNum'] += $v['num'];
|
|
|
+ $cartInfo['totalPrice'] += $v['num'] * $v['current_price'];
|
|
|
+ }
|
|
|
+ $cartInfo['id'] = $v['id'];
|
|
|
+ $cartInfo['table_id'] = $v['table_id'];
|
|
|
+ $cartInfo['store_id'] = $v['store_id'];
|
|
|
+ $cartInfo['user_id'] = $v['user_id'];
|
|
|
+ $cartInfo['create_time'] = $v['create_time'];
|
|
|
+ $cartInfo['totalPrice'] = number_format($cartInfo['totalPrice'], 2);
|
|
|
+ $cartInfo['list'] = $cartInfo['totalNum'] == 0 ? [] : $rs;
|
|
|
Until::output($cartInfo);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @OA\Post(path="/api/Order/clearCart",
|
|
|
+ * tags={"订单管理"},
|
|
|
+ * summary="清空购物车",
|
|
|
+ * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
|
|
|
+ * @OA\RequestBody(
|
|
|
+ * @OA\MediaType(
|
|
|
+ * mediaType="multipart/form-data",
|
|
|
+ * @OA\Schema(
|
|
|
+ * @OA\Property(description="购物车id", property="cartId", type="integer", default="1"),
|
|
|
+ * required={"cartId"})
|
|
|
+ * )
|
|
|
+ * ),
|
|
|
+ * @OA\Response(response="200", description="请求成功")
|
|
|
+ * )
|
|
|
+ */
|
|
|
+ public function clearCart() {
|
|
|
+ $input = Until::getInput();
|
|
|
+ $rule = [
|
|
|
+ 'cartId|购物车id' => 'require',
|
|
|
+ ];
|
|
|
+ Until::check($rule, $input);
|
|
|
+ $model = new CartModel();
|
|
|
+ $model::where(['id' => $input['cartId']])->update(['status' => 0]);
|
|
|
+ Until::output();
|
|
|
+ }
|
|
|
}
|