| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\plugins\food\controllers\client;
- use app\models\Option;
- use app\plugins\food\controllers\BaseController;
- use app\plugins\food\models\client\OrderForm;
- use app\plugins\food\models\client\OrderListForm;
- use app\plugins\food\models\FoodOrder;
- use app\plugins\food\models\FoodOrderDetail;
- use yii\base\BaseObject;
- use yii\base\Controller;
- use yii\helpers\Json;
- class OrderController extends BaseController
- {
- /**
- * 订单提交接口
- * @return array
- */
- public function actionSubmit() {
- $form = new OrderForm();
- $form->store_id = get_store_id();
- $form->user_id = get_user_id();
- $form->attributes = post_params();
- return $form->submit();
- }
- /**
- * 订单支付接口
- * @return array
- */
- public function actionPay() {
- $form = new OrderForm();
- $form->store_id = get_store_id();
- $form->user_id = get_user_id();
- $form->order_id = post_params('order_id');
- $form->pay_type = post_params('pay_type');
- return $form->pay();
- }
- /**
- * 订单列表
- */
- public function actionList() {
- $form = new OrderListForm();
- $form->store_id = get_store_id();
- $form->user_id = get_user_id();
- return $form->list();
- }
- /**
- * 订单详情
- */
- public function actionDetail() {
- $order_id = get_params('order_id');
- $food_times = FoodOrderDetail::find()->where(['order_id' => $order_id])->groupBy('times')->select('times')->asArray()->all();
- $food_times = array_column($food_times, 'times');
- $food_order = FoodOrder::findOne($order_id);
- $goods_counts = FoodOrderDetail::find()->where(['order_id' => $order_id])->sum('num');
- // 组装返回数据
- $data = [
- 'table_num' => $food_order->table_num,
- 'pay_type' => is_wechat_platform() ? 1 : 4,
- 'total_price' => $food_order->total_price,
- 'pay_price' => $food_order->pay_price,
- 'goods_count' => $goods_counts,
- 'order_no' => $food_order->order_no,
- 'created_at' => date('Y-m-d H:i:s', $food_order->created_at),
- ];
- rsort($food_times);
- $result = [];
- foreach ($food_times as $times) {
- $goods_list = FoodOrderDetail::find()->where(['order_id' => $order_id, 'times' => $times])->asArray()->all();
- $tmp = [];
- foreach ($goods_list as $goods) {
- $tmp['time'] = date('Y-m-d H:i:s', $goods['created_at']);
- $tmp['goods_list'][] = [
- 'id' => $goods['goods_id'],
- 'name' => $goods['goods_name'],
- 'price' => $goods['total_price'],
- 'num' => $goods['num'],
- 'pic' => $goods['pic'],
- 'attr' => Json::decode($goods['attr'])
- ];
- }
- $result[] = $tmp;
- }
- $option = Option::get('food_book', get_store_id(), 'store', [
- 'tips' => '菜品已在制作中,请耐心等待',
- 'say_time' => '10',
- ]);
- $option = is_string($option['value']) ? json_decode($option['value'], true) : $option['value'];
- $data['tips'] = $option['tips'];
- $data['say_time'] = $option['say_time'];
- $data['list'] = $result;
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $data
- ];
- }
- }
|