| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\plugins\food\controllers\client;
- use app\models\Option;
- use app\models\Store;
- use app\modules\client\models\v1\LoginForm;
- use app\plugins\food\controllers\BaseController;
- use app\plugins\food\models\client\BookForm;
- use app\plugins\food\models\FoodBook;
- use yii\base\BaseObject;
- use yii\base\Controller;
- /**
- * 点餐预约
- * Class BookController
- * @package app\plugins\food\controllers\client
- */
- class BookController extends BaseController
- {
- public function actionSubmit() {
- $form = new BookForm();
- $form->attributes = post_params();
- $form->store_id = get_store_id();
- $form->user_id = get_user_id();
- return $form->submit();
- }
- /**
- * 发送验证码
- */
- public function actionSendCode()
- {
- $form = new BookForm();
- $form->mobile = post_params('mobile');
- $form->store_id = get_store_id();
- return $form->sendCode();
- }
- /**
- * 预约配置
- * @return array
- */
- public function actionConfig() {
- $store_id = get_store_id();
- $user_id = get_user_id();
- // 商户信息
- $store_info = Store::findOne(['id' => $store_id, 'is_delete' => 0]);
- $food_config = Option::getFoodBookConfig();
- $store = [
- 'name' => $food_config['name'],
- 'address' => $food_config['address'],
- 'phone' => $food_config['phone'],
- 'logo' => $food_config['logo'],
- 'open_time' => $food_config['open_time'],
- 'latitude' => explode(',', $store_info['coordinate'])[0] ?: '',
- 'longitude' => explode(',', $store_info['coordinate'])[1] ?: ''
- ];
- $book = FoodBook::find()->where(['store_id' => $store_id, 'user_id' => $user_id, 'status' => FoodBook::BOOK_WAIT])
- ->orderBy('id desc')->limit(1)->one();
- if (!empty($book)) {
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'switch' => $food_config['switch'],
- 'description' => $food_config['description'],
- 'result' => 1,
- 'id' => $book->id,
- 'store' => $store,
- 'order_code' => BookForm::bookNumber($book->start_time),
- 'order_time' => date('Y-m-d H:i', $book->start_time) . '-' . date('H:i', $book->end_time)
- ]
- ];
- }
- // 预约配置
- if (empty($food_config)) {
- return [
- 'code' => 1,
- 'msg' => '配置信息有误'
- ];
- }
- if ($food_config['switch'] == 0) {
- return [
- 'code' => 1,
- 'msg' => '店铺未开启预约'
- ];
- }
-
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'description' => $food_config['description'],
- 'result' => 0,
- 'time' => $food_config['time'],
- 'person' => $food_config['person']
- ]
- ];
- }
- /**
- * 预约取消
- */
- public function actionCancel()
- {
- $book = FoodBook::findOne(['id' => post_params('id'), ['in', 'status', [FoodBook::BOOK_WAIT, FoodBook::BOOK_CONFIRM]]]);
- if (!$book) {
- return [
- 'code' => 1,
- 'msg' => '未找到该预约记录'
- ];
- }
- $book->status = FoodBook::BOOK_NOT_EXIST;
- if ($book->save()) {
- return [
- 'code' => 0,
- 'msg' => '取消成功'
- ];
- } else{
- return [
- 'code' => 1,
- 'msg' => $book->errors[0]
- ];
- }
- }
- }
|