StoreOrderStoreOrderStatusDao.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 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. public function search(array $where = [], bool $search = false)
  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. * 获取确认收货订单id
  71. * @param array $where
  72. * @param int $limit
  73. * @return array
  74. * @throws \think\db\exception\DataNotFoundException
  75. * @throws \think\db\exception\DbException
  76. * @throws \think\db\exception\ModelNotFoundException
  77. * @author 吴汐
  78. * @email 442384644@qq.com
  79. * @date 2023/03/01
  80. */
  81. public function getTakeOrderIds(array $where, int $limit = 0)
  82. {
  83. return $this->search($where)->whereIn('refund_type', [0, 3])->where('pid', '<>', -1)->field([$this->alias . '.*'])
  84. ->when($limit != 0, function ($query) use ($limit) {
  85. $query->limit($limit);
  86. })->select()->toArray();
  87. }
  88. }