You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StoreOrderWapServices.php 3.1KB

2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace app\services\order;
  3. use app\dao\order\StoreOrderDao;
  4. use app\services\BaseServices;
  5. /**
  6. * Class StoreOrderWapServices
  7. * @package app\services\order
  8. * @method getOne(array $where, ?string $field = '*') 获取一条数据
  9. */
  10. class StoreOrderWapServices extends BaseServices
  11. {
  12. /**
  13. * StoreOrderWapServices constructor.
  14. * @param StoreOrderDao $dao
  15. */
  16. public function __construct(StoreOrderDao $dao)
  17. {
  18. $this->dao = $dao;
  19. }
  20. /**
  21. * 获取 今日 昨日 本月 订单金额
  22. * @return mixed
  23. */
  24. public function getOrderTimeData(int $store_id = 0)
  25. {
  26. $where = ['pid' => 0, 'timeKey' => 'add_time', 'paid' => 1, 'is_del' => 0, 'is_system_del' => 0, 'refund_status' => [0, 3], 'store_id' => $store_id];
  27. //今日成交额
  28. $data['todayPrice'] = $this->dao->together($where + ['time' => 'today'], 'pay_price');
  29. //今日订单数
  30. $data['todayCount'] = $this->dao->count($where + ['time' => 'today']);
  31. //昨日成交额
  32. $data['proPrice'] = $this->dao->together($where + ['time' => 'yesterday'], 'pay_price');
  33. //昨日订单数
  34. $data['proCount'] = $this->dao->count($where + ['time' => 'yesterday']);
  35. //本月成交额
  36. $data['monthPrice'] = $this->dao->together($where + ['time' => 'month'], 'pay_price');
  37. //本月订单数
  38. $data['monthCount'] = $this->dao->count($where + ['time' => 'month']);
  39. return $data;
  40. }
  41. /**
  42. * 订单每月统计数据
  43. * @param array $where
  44. * @param int $store_id
  45. * @return array
  46. */
  47. public function getOrderDataPriceCount(array $where = [], int $store_id = 0)
  48. {
  49. [$page, $limit] = $this->getPageValue();
  50. return $this->dao->getOrderDataPriceCount($where + ['pid' => 0, 'is_del' => 0, 'paid' => 1, 'refund_status' => [0, 3], 'is_system_del' => 0, 'store_id' => $store_id], ['sum(pay_price) as price', 'count(id) as count', 'FROM_UNIXTIME(add_time, \'%m-%d\') as time'], $page, $limit);
  51. }
  52. /**
  53. * 获取手机端订单管理
  54. * @param array $where
  55. * @param array $with
  56. * @return array
  57. * @throws \think\db\exception\DataNotFoundException
  58. * @throws \think\db\exception\DbException
  59. * @throws \think\db\exception\ModelNotFoundException
  60. */
  61. public function getWapAdminOrderList(array $where, array $with = [])
  62. {
  63. [$page, $limit] = $this->getPageValue();
  64. $list = $this->dao->getOrderList($where, ['*'], $page, $limit, $with);
  65. /** @var StoreOrderServices $orderServices */
  66. $orderServices = app()->make(StoreOrderServices::class);
  67. $list = $orderServices->tidyOrderList($list);
  68. foreach ($list as &$item) {
  69. $refund_num = array_sum(array_column($item['refund'], 'refund_num'));
  70. $cart_num = 0;
  71. foreach ($item['_info'] as $items) {
  72. if (isset($items['cart_info']['is_gift']) && $items['cart_info']['is_gift']) continue;
  73. $cart_num += $items['cart_info']['cart_num'];
  74. }
  75. $item['is_all_refund'] = $refund_num == $cart_num ? true : false;
  76. }
  77. return $list;
  78. }
  79. }