OrderListForm.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\plugins\food\models\client;
  8. use app\models\Order;
  9. use app\models\OrderDetail;
  10. use app\plugins\food\models\FoodOrder;
  11. use app\plugins\food\models\FoodOrderDetail;
  12. use yii\base\Model;
  13. use yii\data\Pagination;
  14. class OrderListForm extends Model
  15. {
  16. public $store_id;
  17. public $user_id;
  18. public $page;
  19. public $limit;
  20. public function rules()
  21. {
  22. return [
  23. [['page', 'limit'], 'integer'],
  24. [['page'], 'default', 'value' => 1],
  25. [['limit'], 'default', 'value' => 20],
  26. ];
  27. }
  28. public function list() {
  29. if (!$this->validate()) {
  30. return [
  31. 'code' => 1,
  32. 'msg' => $this->getErrorSummary(false)[0],
  33. ];
  34. }
  35. $query = Order::find()->where(['store_id' => $this->store_id, 'user_id' => $this->user_id])->andWhere(['>','food_flag_id',0]);
  36. $count = $query->count();
  37. $pagination = new Pagination(['totalCount' => $count, 'page' => $this->page - 1, 'pageSize' => $this->limit]);
  38. $list = $query->limit($pagination->limit)->offset($pagination->offset)->orderBy('created_at DESC')->asArray()->all();
  39. if (empty($list)) {
  40. return [
  41. 'code' => 0,
  42. 'msg' => 'success',
  43. 'data' => [
  44. 'row_count' => $count,
  45. 'page_count' => $pagination->pageCount,
  46. 'list' => [],
  47. ],
  48. ];
  49. }
  50. foreach ($list as $index => $order) {
  51. $list[$index]['goods_list'] = OrderDetail::find()->where(['order_id' => $order['id']])->asArray()->all();
  52. }
  53. return [
  54. 'code' => 0,
  55. 'msg' => 'success',
  56. 'data' => [
  57. 'row_count' => $count,
  58. 'page_count' => $pagination->pageCount,
  59. 'list' => $list,
  60. ],
  61. ];
  62. }
  63. }