StoreOrderWapServices.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\order;
  12. use app\dao\order\StoreOrderDao;
  13. use app\services\BaseServices;
  14. /**
  15. * Class StoreOrderWapServices
  16. * @package app\services\order
  17. * @mixin StoreOrderDao
  18. */
  19. class StoreOrderWapServices extends BaseServices
  20. {
  21. /**
  22. * StoreOrderWapServices constructor.
  23. * @param StoreOrderDao $dao
  24. */
  25. public function __construct(StoreOrderDao $dao)
  26. {
  27. $this->dao = $dao;
  28. }
  29. /**
  30. * 获取 今日 昨日 本月 订单金额
  31. * @return mixed
  32. */
  33. public function getOrderTimeData(int $store_id = 0)
  34. {
  35. $where = ['pid' => 0, 'timeKey' => 'add_time', 'paid' => 1, 'is_del' => 0, 'is_system_del' => 0, 'refund_status' => [0, 3], 'store_id' => $store_id, 'plat_type' => 0];
  36. //今日成交额
  37. $data['todayPrice'] = $this->dao->together($where + ['time' => 'today'], 'pay_price');
  38. //今日订单数
  39. $data['todayCount'] = $this->dao->count($where + ['time' => 'today']);
  40. //昨日成交额
  41. $data['proPrice'] = $this->dao->together($where + ['time' => 'yesterday'], 'pay_price');
  42. //昨日订单数
  43. $data['proCount'] = $this->dao->count($where + ['time' => 'yesterday']);
  44. //本月成交额
  45. $data['monthPrice'] = $this->dao->together($where + ['time' => 'month'], 'pay_price');
  46. //本月订单数
  47. $data['monthCount'] = $this->dao->count($where + ['time' => 'month']);
  48. return $data;
  49. }
  50. /**
  51. * 订单每月统计数据
  52. * @param array $where
  53. * @param int $store_id
  54. * @return array
  55. */
  56. public function getOrderDataPriceCount(array $where = [], int $store_id = 0)
  57. {
  58. [$page, $limit] = $this->getPageValue();
  59. 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);
  60. }
  61. /**
  62. * 获取手机端订单管理
  63. * @param array $where
  64. * @param array $with
  65. * @return array
  66. * @throws \think\db\exception\DataNotFoundException
  67. * @throws \think\db\exception\DbException
  68. * @throws \think\db\exception\ModelNotFoundException
  69. */
  70. public function getWapAdminOrderList(array $where, array $with = [])
  71. {
  72. [$page, $limit] = $this->getPageValue();
  73. $list = $this->dao->getOrderList($where, ['*'], $page, $limit, $with);
  74. /** @var StoreOrderServices $orderServices */
  75. $orderServices = app()->make(StoreOrderServices::class);
  76. $list = $orderServices->tidyOrderList($list);
  77. foreach ($list as &$item) {
  78. $refund_num = array_sum(array_column($item['refund'], 'refund_num'));
  79. $cart_num = 0;
  80. foreach ($item['_info'] as $items) {
  81. if (isset($items['cart_info']['is_gift']) && $items['cart_info']['is_gift']) continue;
  82. $cart_num += $items['cart_info']['cart_num'];
  83. }
  84. $item['is_all_refund'] = $refund_num == $cart_num;
  85. }
  86. return $list;
  87. }
  88. }