StoreGroupOrderDao.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\common\dao\store\order;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\store\order\StoreGroupOrder;
  5. /**
  6. * Class StoreGroupOrderDao
  7. * @package app\common\dao\store\order
  8. * @author zfy
  9. * @day 2020/6/9
  10. */
  11. class StoreGroupOrderDao extends BaseDao
  12. {
  13. /**
  14. * @return string
  15. * @author zfy
  16. * @day 2020/6/9
  17. */
  18. protected function getModel(): string
  19. {
  20. return StoreGroupOrder::class;
  21. }
  22. /**
  23. * @param null $uid
  24. * @return int
  25. * @author zfy
  26. * @day 2020/6/11
  27. */
  28. public function orderNumber($uid = null)
  29. {
  30. return StoreGroupOrder::when($uid, function ($query, $uid) {
  31. $query->where('uid', $uid);
  32. })->where('is_del', 0)->where('paid', 0)->count();
  33. }
  34. /**
  35. * @param array $where
  36. * @return \think\db\BaseQuery
  37. * @author zfy
  38. * @day 2020/6/9
  39. */
  40. public function search(array $where)
  41. {
  42. return StoreGroupOrder::getDB()->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
  43. $query->where('paid', $where['paid']);
  44. })->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
  45. $query->where('uid', $where['uid']);
  46. })->order('create_time DESC')->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use ($where) {
  47. $query->where('is_del', $where['is_del']);
  48. }, function ($query) {
  49. $query->where('is_del', 0);
  50. });
  51. }
  52. /**
  53. * @param $time
  54. * @param bool $is_remind
  55. * @return array
  56. * @author zfy
  57. * @day 2020/6/9
  58. */
  59. public function getTimeOutIds($time, $is_remind = false)
  60. {
  61. return StoreGroupOrder::getDB()->where('is_del', 0)->where('paid', 0)
  62. ->when($is_remind, function ($query) {
  63. $query->where('is_remind', 0);
  64. })->where('create_time', '<=', $time)->column('group_order_id');
  65. }
  66. public function isRemind($id)
  67. {
  68. return StoreGroupOrder::getDB()->where('group_order_id', $id)->update(['is_remind' => 1]);
  69. }
  70. public function totalNowMoney($uid)
  71. {
  72. return StoreGroupOrder::getDB()->where('pay_type', 0)->where('uid', $uid)->sum('pay_price') ?: 0;
  73. }
  74. }