| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\plugins\food\models\client;
- use app\models\Order;
- use app\models\OrderDetail;
- use app\plugins\food\models\FoodOrder;
- use app\plugins\food\models\FoodOrderDetail;
- use yii\base\Model;
- use yii\data\Pagination;
- class OrderListForm extends Model
- {
- public $store_id;
- public $user_id;
- public $page;
- public $limit;
- public function rules()
- {
- return [
- [['page', 'limit'], 'integer'],
- [['page'], 'default', 'value' => 1],
- [['limit'], 'default', 'value' => 20],
- ];
- }
- public function list() {
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $query = Order::find()->where(['store_id' => $this->store_id, 'user_id' => $this->user_id])->andWhere(['>','food_flag_id',0]);
- $count = $query->count();
- $pagination = new Pagination(['totalCount' => $count, 'page' => $this->page - 1, 'pageSize' => $this->limit]);
- $list = $query->limit($pagination->limit)->offset($pagination->offset)->orderBy('created_at DESC')->asArray()->all();
- if (empty($list)) {
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'row_count' => $count,
- 'page_count' => $pagination->pageCount,
- 'list' => [],
- ],
- ];
- }
- foreach ($list as $index => $order) {
- $list[$index]['goods_list'] = OrderDetail::find()->where(['order_id' => $order['id']])->asArray()->all();
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'row_count' => $count,
- 'page_count' => $pagination->pageCount,
- 'list' => $list,
- ],
- ];
- }
- }
|