|
@@ -10,6 +10,8 @@ namespace app\api\controller;
|
|
use app\api\BaseController;
|
|
use app\api\BaseController;
|
|
use app\api\exception\ApiException;
|
|
use app\api\exception\ApiException;
|
|
use app\api\model\BrandModel;
|
|
use app\api\model\BrandModel;
|
|
|
|
+use app\api\model\CartProductModel;
|
|
|
|
+use app\api\model\CartModel;
|
|
use app\api\model\GroupModel;
|
|
use app\api\model\GroupModel;
|
|
use app\api\model\OrderModel;
|
|
use app\api\model\OrderModel;
|
|
use app\api\model\ProductModel;
|
|
use app\api\model\ProductModel;
|
|
@@ -60,8 +62,8 @@ class Order extends BaseController {
|
|
$where = [];
|
|
$where = [];
|
|
|
|
|
|
$model::where([['status', '=', 1], ['create_time', '<',
|
|
$model::where([['status', '=', 1], ['create_time', '<',
|
|
- date('Y-m-d H:i:s',strtotime('-15minutes'))]])
|
|
|
|
- ->update(['status' => OrderModel::IS_CLOSE]);
|
|
|
|
|
|
+ date('Y-m-d H:i:s', strtotime('-15minutes'))]])
|
|
|
|
+ ->update(['status' => OrderModel::IS_CLOSE]);
|
|
if (!empty($input['orderSn'])) {
|
|
if (!empty($input['orderSn'])) {
|
|
$where[] = ['o.order_sn', 'like', "%{$input['orderSn']}%"];
|
|
$where[] = ['o.order_sn', 'like', "%{$input['orderSn']}%"];
|
|
}
|
|
}
|
|
@@ -79,7 +81,7 @@ class Order extends BaseController {
|
|
}
|
|
}
|
|
|
|
|
|
if (!empty($input['discussStatus'])) {
|
|
if (!empty($input['discussStatus'])) {
|
|
- $where[] = ['discussOrder.id','=',null];
|
|
|
|
|
|
+ $where[] = ['discussOrder.id', '=', null];
|
|
}
|
|
}
|
|
|
|
|
|
if (!empty($input['storeId'])) {
|
|
if (!empty($input['storeId'])) {
|
|
@@ -102,22 +104,22 @@ class Order extends BaseController {
|
|
|
|
|
|
if (!$this->isAdmin()) {
|
|
if (!$this->isAdmin()) {
|
|
$where[] = ['o.user_id', '=', $this->userId];
|
|
$where[] = ['o.user_id', '=', $this->userId];
|
|
- if (empty($input['orderStatus'])){
|
|
|
|
|
|
+ if (empty($input['orderStatus'])) {
|
|
$where[] = ['o.status', '<>', OrderModel::IS_DELETE];
|
|
$where[] = ['o.status', '<>', OrderModel::IS_DELETE];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
$model->setWhere($where);
|
|
$model->setWhere($where);
|
|
$data = $model->getOrderList();
|
|
$data = $model->getOrderList();
|
|
- $statusFilter = [1=>'未支付',2=>'已支付',3=>'已关闭'];
|
|
|
|
|
|
+ $statusFilter = [1 => '未支付', 2 => '已支付', 3 => '已关闭'];
|
|
|
|
|
|
- foreach ($data['list'] as &$one){
|
|
|
|
|
|
+ foreach ($data['list'] as &$one) {
|
|
$one['statusText'] = $statusFilter[$one['status']];
|
|
$one['statusText'] = $statusFilter[$one['status']];
|
|
- if($one['status'] === OrderModel::IS_PAY) {
|
|
|
|
|
|
+ if ($one['status'] === OrderModel::IS_PAY) {
|
|
if ($one['write_off_status'] == 1) {
|
|
if ($one['write_off_status'] == 1) {
|
|
$one['statusText'] = '待消费';
|
|
$one['statusText'] = '待消费';
|
|
- }else if ($one['write_off_status'] == 2) {
|
|
|
|
- if (empty($one['discuss_id']) && !empty($input['discussStatus'])){
|
|
|
|
|
|
+ } else if ($one['write_off_status'] == 2) {
|
|
|
|
+ if (empty($one['discuss_id']) && !empty($input['discussStatus'])) {
|
|
$one['statusText'] = '未评价';
|
|
$one['statusText'] = '未评价';
|
|
}
|
|
}
|
|
$one['statusText'] = '已消费';
|
|
$one['statusText'] = '已消费';
|
|
@@ -225,7 +227,7 @@ class Order extends BaseController {
|
|
];
|
|
];
|
|
Until::check($rule, $input);
|
|
Until::check($rule, $input);
|
|
if (empty($input['endTime'])) {
|
|
if (empty($input['endTime'])) {
|
|
- $input['endTime'] = date('Y-m-d H:i',strtotime($input['appointmentTime']) + 1800);
|
|
|
|
|
|
+ $input['endTime'] = date('Y-m-d H:i', strtotime($input['appointmentTime']) + 1800);
|
|
}
|
|
}
|
|
if (strtotime($input['appointmentTime']) >= strtotime($input['endTime'])) {
|
|
if (strtotime($input['appointmentTime']) >= strtotime($input['endTime'])) {
|
|
throw new ApiException('结束时间必须大于开始时间');
|
|
throw new ApiException('结束时间必须大于开始时间');
|
|
@@ -259,9 +261,9 @@ class Order extends BaseController {
|
|
public function createFoodOrder() {
|
|
public function createFoodOrder() {
|
|
$input = Until::getInput();
|
|
$input = Until::getInput();
|
|
$rule = [
|
|
$rule = [
|
|
- 'productIdAndNum|商品id和数量' => 'require',
|
|
|
|
- 'storeId|门店id' => 'require',
|
|
|
|
- 'mobile|手机号' => 'require'
|
|
|
|
|
|
+ 'productIdAndNum|商品id和数量' => 'require',
|
|
|
|
+ 'storeId|门店id' => 'require',
|
|
|
|
+ 'mobile|手机号' => 'require'
|
|
];
|
|
];
|
|
Until::check($rule, $input);
|
|
Until::check($rule, $input);
|
|
$data = (new OrderService())->payOrder($input);
|
|
$data = (new OrderService())->payOrder($input);
|
|
@@ -330,7 +332,7 @@ class Order extends BaseController {
|
|
throw new ApiException('该订单已支付');
|
|
throw new ApiException('该订单已支付');
|
|
}
|
|
}
|
|
$model::where(['id' => (int)$input['orderId']])->update([
|
|
$model::where(['id' => (int)$input['orderId']])->update([
|
|
- 'status' => OrderModel::IS_PAY,
|
|
|
|
|
|
+ 'status' => OrderModel::IS_PAY,
|
|
|
|
|
|
'pay_time' => date('Y-m-d H:i:s')
|
|
'pay_time' => date('Y-m-d H:i:s')
|
|
]);
|
|
]);
|
|
@@ -348,13 +350,13 @@ class Order extends BaseController {
|
|
'OrderNumber|订单号' => 'require',
|
|
'OrderNumber|订单号' => 'require',
|
|
];
|
|
];
|
|
Until::check($rule, $input);
|
|
Until::check($rule, $input);
|
|
- if (md5('ef17f532-4661-b07c-5346-65dfa304c0d8'.$input['OrderNumber']) === $this->request->header('serchkey')){
|
|
|
|
|
|
+ if (md5('ef17f532-4661-b07c-5346-65dfa304c0d8' . $input['OrderNumber']) === $this->request->header('serchkey')) {
|
|
(new OrderService())->notify($input['OrderNumber']);
|
|
(new OrderService())->notify($input['OrderNumber']);
|
|
Until::output([]);
|
|
Until::output([]);
|
|
}
|
|
}
|
|
-// (new OrderService())->notify($input['OrderNumber']);
|
|
|
|
- Until::output(['decode' => md5('ef17f532-4661-b07c-5346-65dfa304c0d8'.$input['OrderNumber']),
|
|
|
|
- 'encode' => $this->request->header('serchkey')]);
|
|
|
|
|
|
+ // (new OrderService())->notify($input['OrderNumber']);
|
|
|
|
+ Until::output(['decode' => md5('ef17f532-4661-b07c-5346-65dfa304c0d8' . $input['OrderNumber']),
|
|
|
|
+ 'encode' => $this->request->header('serchkey')]);
|
|
}
|
|
}
|
|
|
|
|
|
public function changeCode() {
|
|
public function changeCode() {
|
|
@@ -363,12 +365,12 @@ class Order extends BaseController {
|
|
'orderId|订单号' => 'require',
|
|
'orderId|订单号' => 'require',
|
|
];
|
|
];
|
|
Until::check($rule, $input);
|
|
Until::check($rule, $input);
|
|
- $ser = new OrderService();
|
|
|
|
|
|
+ $ser = new OrderService();
|
|
$code = $ser->changeCode();
|
|
$code = $ser->changeCode();
|
|
$wModel = new WriteOffModel();
|
|
$wModel = new WriteOffModel();
|
|
- $wModel::where(['order_id' => $input['orderId'],'write_off_status' => 1])->update([
|
|
|
|
|
|
+ $wModel::where(['order_id' => $input['orderId'], 'write_off_status' => 1])->update([
|
|
'write_off_code' => $code,
|
|
'write_off_code' => $code,
|
|
- 'over_time' => date('Y-m-d H:i:s', time() + 2 * 60),
|
|
|
|
|
|
+ 'over_time' => date('Y-m-d H:i:s', time() + 2 * 60),
|
|
]);
|
|
]);
|
|
Until::output(['code' => $code]);
|
|
Until::output(['code' => $code]);
|
|
}
|
|
}
|
|
@@ -394,7 +396,7 @@ class Order extends BaseController {
|
|
$input = Until::getInput();
|
|
$input = Until::getInput();
|
|
$rule = [
|
|
$rule = [
|
|
'orderId|订单id' => 'require',
|
|
'orderId|订单id' => 'require',
|
|
- 'code|核销码' => 'require'
|
|
|
|
|
|
+ 'code|核销码' => 'require'
|
|
];
|
|
];
|
|
Until::check($rule, $input);
|
|
Until::check($rule, $input);
|
|
$rs = (new OrderModel())::where(['id' => $input['orderId']])->find();
|
|
$rs = (new OrderModel())::where(['id' => $input['orderId']])->find();
|
|
@@ -408,11 +410,11 @@ class Order extends BaseController {
|
|
throw new ApiException('核销码错误');
|
|
throw new ApiException('核销码错误');
|
|
}
|
|
}
|
|
|
|
|
|
- if($writeOff['write_off_status'] == 2){
|
|
|
|
|
|
+ if ($writeOff['write_off_status'] == 2) {
|
|
throw new ApiException('该订单已经核销了');
|
|
throw new ApiException('该订单已经核销了');
|
|
}
|
|
}
|
|
$userModel = new UserModel();
|
|
$userModel = new UserModel();
|
|
- $userModel::where([['id','=', $rs['user_id']],['first_store_id','=',0]])->update(['first_store_id' => $rs['store_id']]);
|
|
|
|
|
|
+ $userModel::where([['id', '=', $rs['user_id']], ['first_store_id', '=', 0]])->update(['first_store_id' => $rs['store_id']]);
|
|
$model::where($where)
|
|
$model::where($where)
|
|
->update([
|
|
->update([
|
|
'write_off_status' => 2,
|
|
'write_off_status' => 2,
|
|
@@ -473,4 +475,115 @@ class Order extends BaseController {
|
|
$data = (new OrderService())->payAgain((int)$input['orderId']);
|
|
$data = (new OrderService())->payAgain((int)$input['orderId']);
|
|
Until::output($data);
|
|
Until::output($data);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @OA\Post(path="/api/Order/updateCart",
|
|
|
|
+ * 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="productId", type="integer", default="1"),
|
|
|
|
+ * @OA\Property(description="商品数量", property="num", type="integer", default="1"),
|
|
|
|
+ * @OA\Property(description="购物车id", property="cartId", type="integer", default="1"),
|
|
|
|
+ * @OA\Property(description="类型1增加 2减少", property="type", type="integer", default="1"),
|
|
|
|
+ * required={"productId","num","cartId","type"})
|
|
|
|
+ * )
|
|
|
|
+ * ),
|
|
|
|
+ * @OA\Response(response="200", description="请求成功")
|
|
|
|
+ * )
|
|
|
|
+ */
|
|
|
|
+ public function updateCart() {
|
|
|
|
+ $input = Until::getInput();
|
|
|
|
+ $rule = [
|
|
|
|
+ 'productId|订单id' => 'require',
|
|
|
|
+ 'num|数量' => 'require',
|
|
|
|
+ 'cartId|购物车id' => 'require',
|
|
|
|
+ ];
|
|
|
|
+ Until::check($rule, $input);
|
|
|
|
+ $cartModel = new CartModel();
|
|
|
|
+ $cartInfo = $cartModel::where([
|
|
|
|
+ 'id' => $input['cartId']
|
|
|
|
+ ])->find();
|
|
|
|
+ if (empty($cartInfo)) {
|
|
|
|
+ throw new ApiException('不存在的购物车id');
|
|
|
|
+ }
|
|
|
|
+ $cartProductModel = new CartProductModel();
|
|
|
|
+ $rs = $cartProductModel::where(['product_id' => $input['productId'], 'cart_id' => $input['cartId']])->find();
|
|
|
|
+ if (empty($rs)) {
|
|
|
|
+ $cartProductModel->insertGetId([
|
|
|
|
+ 'product_id' => $input['productId'],
|
|
|
|
+ 'cart_id' => $input['cartId'],
|
|
|
|
+ 'num' => $input['num'] ?? 1
|
|
|
|
+ ]);
|
|
|
|
+ }else {
|
|
|
|
+ if ($input['type'] == 1) {
|
|
|
|
+ $cartProductModel::where(['id' => $rs['id']])->inc('num', 1)->update();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ($input['type'] == 2) {
|
|
|
|
+ $cartProductModel::where(['id' => $rs['id']])->dec('num', 1)->update();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $cartInfo = Until::modelToArray($cartInfo);
|
|
|
|
+ $rs = $cartModel->getCartList();
|
|
|
|
+ $cartInfo['list'] = $rs;
|
|
|
|
+ Until::output($cartInfo);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ Until::output();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @OA\Post(path="/api/Order/getCart",
|
|
|
|
+ * 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="storeId", type="integer", default="1"),
|
|
|
|
+ * @OA\Property(description="桌台id", property="tableId", type="integer", default="1"),
|
|
|
|
+ * required={"storeId","tableId"})
|
|
|
|
+ * )
|
|
|
|
+ * ),
|
|
|
|
+ * @OA\Response(response="200", description="请求成功")
|
|
|
|
+ * )
|
|
|
|
+ */
|
|
|
|
+ public function getCart() {
|
|
|
|
+ $input = Until::getInput();
|
|
|
|
+ $rule = [
|
|
|
|
+ 'storeId|门店id' => 'require',
|
|
|
|
+ 'tableId|桌台id' => 'require'
|
|
|
|
+ ];
|
|
|
|
+ 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'],
|
|
|
|
+ 'store_id' => (int)$input['storeId'],
|
|
|
|
+ 'user_id' => $this->userId,
|
|
|
|
+ 'status' => CartModel::NORMAL
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+ $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);
|
|
|
|
+ $rs = $model->getCartList();
|
|
|
|
+ $cartInfo['list'] = $rs;
|
|
|
|
+ Until::output($cartInfo);
|
|
|
|
+ }
|
|
}
|
|
}
|