| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace addons\YunfastPay\common\services;
- use addons\YunfastPay\common\models\PaymentOrder;
- use addons\YunfastPay\common\models\PaymentTrade;
- use addons\YunfastPay\common\models\Store;
- use addons\YunfastPay\common\models\User;
- use yii\data\Pagination;
- /**
- * 支付订单
- * @package addons\YunfastPay\common\services
- */
- class OrderService extends BaseService
- {
- /**
- * 获取分页列表
- *
- * @param array $params
- * @return array
- */
- public function getPageList(array $params = [])
- {
- $limit = $params['limit'] ?? 20;
- $page = $params['page'] ?? 1;
- $model = PaymentOrder::find();
- $model->with(['trade', 'user']);
- $model->andWhere(['mall_id' => $this->mall_id]);
- if (!empty($params['user_id'])) {
- $model->andWhere(['user_id' => $params['user_id']]);
- }
- if (!empty($params['user_keyword'])) {
- $model->andWhere([
- 'user_id' => User::getUserIdsByKeyword($this->mall_id, $params['user_keyword'])
- ]);
- }
- if (!empty($params['order_no'])) {
- $model->andWhere([
- 'trade_id' => PaymentTrade::getIdsByNo($this->mall_id, $params['order_no'])
- ]);
- }
- if (!empty($params['time'])) {
- $model->andFilterWhere([
- 'between',
- 'created_at',
- strtotime($params['time'][0]),
- strtotime($params['time'][1])
- ]);
- }
- $pagination = new Pagination(['totalCount' => $model->count(), 'pageSize' => $limit]);
- $model->limit($pagination->limit)->offset($pagination->offset);
- $list = $model->orderBy('id desc')
- ->asArray()
- ->all();
- $data['list'] = $list;
- $data['page_count'] = $pagination->pageCount;
- $data['current_page'] = $page + 1;
- return $data;
- }
- /**
- * 获取分账信息
- *
- * @param integer $id
- * @return array
- */
- public function getSplitBill(int $id)
- {
- $order = PaymentOrder::findOne(['id' => $id]);
- if (!$order->isSplitBill()) return [];
- if (empty($order->splitBill)) return [];
- $result = [];
- $item_list = $order->splitBill->item;
- foreach ($item_list as $item) {
- $result[] = [
- 'store_type' => $item->store_id > 0 ? 1 : 0,
- 'amount' => $item->amount,
- 'store_name' => Store::getStoreNameById($item->store_id),
- ];
- }
- return $result;
- }
- }
|