Order.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace app\shop\model\plus\agent;
  3. use app\common\model\plus\agent\Order as OrderModel;
  4. use app\common\service\order\OrderService;
  5. use app\shop\service\order\ExportService;
  6. /**
  7. * 分销商订单模型
  8. */
  9. class Order extends OrderModel
  10. {
  11. /**
  12. * 获取分销商订单列表
  13. */
  14. public function getList($user_id = null, $is_settled = -1)
  15. {
  16. $model = $this;
  17. // 检索查询条件
  18. if ($user_id > 1) {
  19. $model = $model->where('first_user_id|second_user_id|third_user_id', '=', $user_id);
  20. }
  21. if ($is_settled > -1) {
  22. $model = $model->where('is_settled', '=', $is_settled);
  23. }
  24. // 获取分销商订单列表
  25. $data = $model->with([
  26. 'agent_first',
  27. 'agent_second',
  28. 'agent_third'
  29. ])
  30. ->order(['create_time' => 'desc'])
  31. ->paginate(15);
  32. if ($data->isEmpty()) {
  33. return $data;
  34. }
  35. // 获取订单的主信息
  36. $with = ['product' => ['image', 'refund'], 'address', 'user'];
  37. return OrderService::getOrderList($data, 'order_master', $with);
  38. }
  39. /**
  40. * 订单导出
  41. */
  42. public function exportList($user_id = null, $is_settled = -1)
  43. {
  44. $model = $this;
  45. // 检索查询条件
  46. if ($user_id > 1) {
  47. $model = $model->where('first_user_id|second_user_id|third_user_id', '=', $user_id);
  48. }
  49. if ($is_settled > -1) {
  50. $model = $model->where('is_settled', '=', $is_settled);
  51. }
  52. // 获取分销商订单列表
  53. $data = $model->with([
  54. 'agent_first',
  55. 'agent_second',
  56. 'agent_third'
  57. ])
  58. ->order(['create_time' => 'desc'])
  59. ->select();
  60. if ($data->isEmpty()) {
  61. return $data;
  62. }
  63. // 获取订单的主信息
  64. $with = ['product' => ['image', 'refund'], 'address', 'user'];
  65. $list = OrderService::getOrderList($data, 'order_master', $with);
  66. // 导出excel文件
  67. (new Exportservice)->agentOrderList($list);
  68. }
  69. }