StoreOrderStoreOrderStatusDao.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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\dao\order;
  12. use app\dao\BaseDao;
  13. use app\model\order\StoreOrder;
  14. use app\model\order\StoreOrderStatus;
  15. /**
  16. * Class StoreOrderStoreOrderStatusDao
  17. * @package app\dao\order
  18. */
  19. class StoreOrderStoreOrderStatusDao extends BaseDao
  20. {
  21. protected $alias = 'o';
  22. protected $joinAlis = 's';
  23. /**
  24. * 设置模型
  25. * @return string
  26. */
  27. protected function setModel(): string
  28. {
  29. return StoreOrder::class;
  30. }
  31. /**
  32. * 设置链表模型
  33. * @return string
  34. */
  35. protected function setJoinModel(): string
  36. {
  37. return StoreOrderStatus::class;
  38. }
  39. /**
  40. * 设置模型
  41. * @return \crmeb\basic\BaseModel
  42. */
  43. protected function getModel()
  44. {
  45. $name = app()->make($this->setJoinModel())->getName();
  46. return parent::getModel()->join($name . ' ' . $this->joinAlis, $this->joinAlis . '.oid = ' . $this->alias . '.id')->alias($this->alias);
  47. }
  48. /**
  49. * 搜索
  50. * @param array $where
  51. * @return \crmeb\basic\BaseModel|mixed|\think\Model
  52. */
  53. protected function search(array $where = [])
  54. {
  55. return $this->getModel()->when(isset($where['paid']), function ($query) use ($where) {
  56. $query->where($this->alias . '.paid', $where['paid']);
  57. })->when(isset($where['status']), function ($query) use ($where) {
  58. $query->where($this->alias . '.status', $where['status']);
  59. })->when(isset($where['refund_status']), function ($query) use ($where) {
  60. $query->where($this->alias . '.refund_status', $where['refund_status']);
  61. })->when(isset($where['is_del']), function ($query) use ($where) {
  62. $query->where($this->alias . '.is_del', $where['is_del']);
  63. })->when(isset($where['change_type']), function ($query) use ($where) {
  64. $query->whereIn($this->joinAlis . '.change_type', $where['change_type']);
  65. })->when(isset($where['change_time']), function ($query) use ($where) {
  66. $query->where($this->joinAlis . '.change_time', '<', $where['change_time']);
  67. });
  68. }
  69. /**
  70. * 根据条件获取订单
  71. * @param array $where
  72. * @param int $page
  73. * @param int $limit
  74. * @return array
  75. * @throws \think\db\exception\DataNotFoundException
  76. * @throws \think\db\exception\DbException
  77. * @throws \think\db\exception\ModelNotFoundException
  78. */
  79. public function getOrderIds(array $where, int $page = 0, int $limit = 0)
  80. {
  81. return $this->search($where)->whereIn('refund_type', [0, 3])->where('pid', '<>', -1)->when($page && $limit, function ($query) use ($page, $limit) {
  82. $query->page($page, $limit);
  83. })->field([$this->alias . '.*'])->select()->toArray();
  84. }
  85. /**
  86. * 根据条件获取订单数量
  87. * @param array $where
  88. * @return int
  89. */
  90. public function getOrderCount(array $where)
  91. {
  92. return $this->search($where)->whereIn('refund_type', [0, 3])->where('pid', '<>', -1)->field([$this->alias . '.*'])->count();
  93. }
  94. }