OrderController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\plugins\food\controllers\client;
  8. use app\models\Option;
  9. use app\plugins\food\controllers\BaseController;
  10. use app\plugins\food\models\client\OrderForm;
  11. use app\plugins\food\models\client\OrderListForm;
  12. use app\plugins\food\models\FoodOrder;
  13. use app\plugins\food\models\FoodOrderDetail;
  14. use yii\base\BaseObject;
  15. use yii\base\Controller;
  16. use yii\helpers\Json;
  17. class OrderController extends BaseController
  18. {
  19. /**
  20. * 订单提交接口
  21. * @return array
  22. */
  23. public function actionSubmit() {
  24. $form = new OrderForm();
  25. $form->store_id = get_store_id();
  26. $form->user_id = get_user_id();
  27. $form->attributes = post_params();
  28. return $form->submit();
  29. }
  30. /**
  31. * 订单支付接口
  32. * @return array
  33. */
  34. public function actionPay() {
  35. $form = new OrderForm();
  36. $form->store_id = get_store_id();
  37. $form->user_id = get_user_id();
  38. $form->order_id = post_params('order_id');
  39. $form->pay_type = post_params('pay_type');
  40. return $form->pay();
  41. }
  42. /**
  43. * 订单列表
  44. */
  45. public function actionList() {
  46. $form = new OrderListForm();
  47. $form->store_id = get_store_id();
  48. $form->user_id = get_user_id();
  49. return $form->list();
  50. }
  51. /**
  52. * 订单详情
  53. */
  54. public function actionDetail() {
  55. $order_id = get_params('order_id');
  56. $food_times = FoodOrderDetail::find()->where(['order_id' => $order_id])->groupBy('times')->select('times')->asArray()->all();
  57. $food_times = array_column($food_times, 'times');
  58. $food_order = FoodOrder::findOne($order_id);
  59. $goods_counts = FoodOrderDetail::find()->where(['order_id' => $order_id])->sum('num');
  60. // 组装返回数据
  61. $data = [
  62. 'table_num' => $food_order->table_num,
  63. 'pay_type' => is_wechat_platform() ? 1 : 4,
  64. 'total_price' => $food_order->total_price,
  65. 'pay_price' => $food_order->pay_price,
  66. 'goods_count' => $goods_counts,
  67. 'order_no' => $food_order->order_no,
  68. 'created_at' => date('Y-m-d H:i:s', $food_order->created_at),
  69. ];
  70. rsort($food_times);
  71. $result = [];
  72. foreach ($food_times as $times) {
  73. $goods_list = FoodOrderDetail::find()->where(['order_id' => $order_id, 'times' => $times])->asArray()->all();
  74. $tmp = [];
  75. foreach ($goods_list as $goods) {
  76. $tmp['time'] = date('Y-m-d H:i:s', $goods['created_at']);
  77. $tmp['goods_list'][] = [
  78. 'id' => $goods['goods_id'],
  79. 'name' => $goods['goods_name'],
  80. 'price' => $goods['total_price'],
  81. 'num' => $goods['num'],
  82. 'pic' => $goods['pic'],
  83. 'attr' => Json::decode($goods['attr'])
  84. ];
  85. }
  86. $result[] = $tmp;
  87. }
  88. $option = Option::get('food_book', get_store_id(), 'store', [
  89. 'tips' => '菜品已在制作中,请耐心等待',
  90. 'say_time' => '10',
  91. ]);
  92. $option = is_string($option['value']) ? json_decode($option['value'], true) : $option['value'];
  93. $data['tips'] = $option['tips'];
  94. $data['say_time'] = $option['say_time'];
  95. $data['list'] = $result;
  96. return [
  97. 'code' => 0,
  98. 'msg' => 'success',
  99. 'data' => $data
  100. ];
  101. }
  102. }