OrderService.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace addons\YunfastPay\common\services;
  3. use addons\YunfastPay\common\models\PaymentOrder;
  4. use addons\YunfastPay\common\models\PaymentTrade;
  5. use addons\YunfastPay\common\models\Store;
  6. use addons\YunfastPay\common\models\User;
  7. use yii\data\Pagination;
  8. /**
  9. * 支付订单
  10. * @package addons\YunfastPay\common\services
  11. */
  12. class OrderService extends BaseService
  13. {
  14. /**
  15. * 获取分页列表
  16. *
  17. * @param array $params
  18. * @return array
  19. */
  20. public function getPageList(array $params = [])
  21. {
  22. $limit = $params['limit'] ?? 20;
  23. $page = $params['page'] ?? 1;
  24. $model = PaymentOrder::find();
  25. $model->with(['trade', 'user']);
  26. $model->andWhere(['mall_id' => $this->mall_id]);
  27. if (!empty($params['user_id'])) {
  28. $model->andWhere(['user_id' => $params['user_id']]);
  29. }
  30. if (!empty($params['user_keyword'])) {
  31. $model->andWhere([
  32. 'user_id' => User::getUserIdsByKeyword($this->mall_id, $params['user_keyword'])
  33. ]);
  34. }
  35. if (!empty($params['order_no'])) {
  36. $model->andWhere([
  37. 'trade_id' => PaymentTrade::getIdsByNo($this->mall_id, $params['order_no'])
  38. ]);
  39. }
  40. if (!empty($params['time'])) {
  41. $model->andFilterWhere([
  42. 'between',
  43. 'created_at',
  44. strtotime($params['time'][0]),
  45. strtotime($params['time'][1])
  46. ]);
  47. }
  48. $pagination = new Pagination(['totalCount' => $model->count(), 'pageSize' => $limit]);
  49. $model->limit($pagination->limit)->offset($pagination->offset);
  50. $list = $model->orderBy('id desc')
  51. ->asArray()
  52. ->all();
  53. $data['list'] = $list;
  54. $data['page_count'] = $pagination->pageCount;
  55. $data['current_page'] = $page + 1;
  56. return $data;
  57. }
  58. /**
  59. * 获取分账信息
  60. *
  61. * @param integer $id
  62. * @return array
  63. */
  64. public function getSplitBill(int $id)
  65. {
  66. $order = PaymentOrder::findOne(['id' => $id]);
  67. if (!$order->isSplitBill()) return [];
  68. if (empty($order->splitBill)) return [];
  69. $result = [];
  70. $item_list = $order->splitBill->item;
  71. foreach ($item_list as $item) {
  72. $result[] = [
  73. 'store_type' => $item->store_id > 0 ? 1 : 0,
  74. 'amount' => $item->amount,
  75. 'store_name' => Store::getStoreNameById($item->store_id),
  76. ];
  77. }
  78. return $result;
  79. }
  80. }