OrderService.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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','shop' => function($query){
  15. $query->field("shop_id,shop_name");
  16. }])->paginate([
  17. "list_rows" => $param['pageSize'],
  18. "page" => $param['page']
  19. ]);
  20. }
  21. public function getTotal(array $param = []): array
  22. {
  23. $this->mode = new SaasOrder();
  24. $total = ['t0' => 0, 't1' => 0, 't2' => 0, 't3' => 0, 't4' => 0, 't5' => 0, 't6' => 0, 'ta' => 0];
  25. $where = [];
  26. if (!empty($param['shop'])) {
  27. $where[] = ['shop_id','=',$param['shop']];
  28. }
  29. $where[] = ['status',">",0];
  30. foreach ($this->searchVal($param,$where)->field('create_at,status,count(1) total')->group('status,create_at')->cursor() as $vo)
  31. {
  32. [$total["t{$vo['status']}"] += $vo['total'], $total['ta'] += $vo['total']];
  33. }
  34. return $total;
  35. }
  36. public function getTotalToday(array $param = []): array
  37. {
  38. $this->mode = new SaasOrder();
  39. $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];
  40. $where = [];
  41. if (!empty($param['shop'])) {
  42. $where[] = ['shop_id','=',$param['shop']];
  43. }
  44. 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)
  45. {
  46. $total["t{$vo['status']}"] += $vo['total'];
  47. $total['ta'] += $vo['total'];
  48. $total['tm'] += $vo['money'];
  49. if ($vo['pay_type'] == 1) {
  50. $total["p1"] += $vo['total'];
  51. $total["p1m"] += $vo['money'];
  52. }
  53. if ($vo['pay_type'] == 2) {
  54. $total["p2"] += $vo['total'];
  55. $total["p2m"] += $vo['money'];
  56. }
  57. }
  58. return $total;
  59. }
  60. protected function searchFilter(array $param = []): array
  61. {
  62. $filter = [];
  63. !empty($param['status']) && $filter[] = ["status", '=', ($param['status']-1)];
  64. !empty($param['statusGt']) && $filter[] = ["status", '>', ($param['statusGt']-1)];
  65. !empty($param['orderid']) && $filter[] = ["order_sn", 'like', "%{$param['orderid']}%"];
  66. !empty($param['shop']) && $filter[] = ["shop_id", '=', $param['shop']];
  67. return $filter;
  68. }
  69. }