OrderService.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace app\extra\service\saas;
  3. use app\extra\basic\Service;
  4. use app\model\saas\SaasOrder;
  5. class OrderService extends Service
  6. {
  7. /**
  8. * 列表
  9. * @param array $param
  10. */
  11. public function getList(array $param = [])
  12. {
  13. $this->mode = new SaasOrder();
  14. return $this->searchVal($param,$this->searchFilter($param))->field("*")->with(['detail'])->paginate([
  15. "list_rows" => $param['pageSize'],
  16. "page" => $param['page']
  17. ]);
  18. }
  19. public function getTotal(array $param = []): array
  20. {
  21. $this->mode = new SaasOrder();
  22. $total = ['t0' => 0, 't1' => 0, 't2' => 0, 't3' => 0, 't4' => 0, 't5' => 0, 't6' => 0, 'ta' => 0];
  23. $where = [];
  24. if (!empty($param['shop'])) {
  25. $where[] = ['shop_id','=',$param['shop']];
  26. }
  27. $where[] = ['status',">",0];
  28. foreach ($this->searchVal($param,$where)->field('create_at,status,count(1) total')->group('status,create_at')->cursor() as $vo)
  29. {
  30. [$total["t{$vo['status']}"] += $vo['total'], $total['ta'] += $vo['total']];
  31. }
  32. return $total;
  33. }
  34. public function getTotalToday(array $param = []): array
  35. {
  36. $this->mode = new SaasOrder();
  37. $total = ['ta' => 0,'t0' => 0, 't1' => 0, 't2' => 0, 't3' => 0, 't4' => 0, 't5' => 0, 't6' => 0, 'tm' => 0, 'p1' => 0, 'p2' => 0, 'p1m' => 0, 'p2m' => 0];
  38. $where = [];
  39. if (!empty($param['shop'])) {
  40. $where[] = ['shop_id','=',$param['shop']];
  41. }
  42. foreach ($this->mode->whereDay("create_at")->where($where)->whereIn("status",[1,2,3])->field('create_at,pay_type,status,sum(discount) as money,count(1) as total')->group('status,create_at,pay_type')->cursor() as $vo)
  43. {
  44. $total["t{$vo['status']}"] += $vo['total'];
  45. $total['ta'] += $vo['total'];
  46. $total['tm'] += $vo['money'];
  47. if ($vo['pay_type'] == 1) {
  48. $total["p1"] += $vo['total'];
  49. $total["p1m"] += $vo['money'];
  50. }
  51. if ($vo['pay_type'] == 2) {
  52. $total["p2"] += $vo['total'];
  53. $total["p2m"] += $vo['money'];
  54. }
  55. }
  56. return $total;
  57. }
  58. protected function searchFilter(array $param = []): array
  59. {
  60. $filter = [];
  61. !empty($param['status']) && $filter[] = ["status", '=', ($param['status']-1)];
  62. !empty($param['statusGt']) && $filter[] = ["status", '>', ($param['statusGt']-1)];
  63. !empty($param['orderid']) && $filter[] = ["order_sn", 'like', "%{$param['orderid']}%"];
  64. !empty($param['shop']) && $filter[] = ["shop_id", '=', $param['shop']];
  65. return $filter;
  66. }
  67. }