StoreGroupOrderDao.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\dao\store\order;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\store\order\StoreGroupOrder;
  14. /**
  15. * Class StoreGroupOrderDao
  16. * @package app\common\dao\store\order
  17. * @author xaboy
  18. * @day 2020/6/9
  19. */
  20. class StoreGroupOrderDao extends BaseDao
  21. {
  22. /**
  23. * @return string
  24. * @author xaboy
  25. * @day 2020/6/9
  26. */
  27. protected function getModel(): string
  28. {
  29. return StoreGroupOrder::class;
  30. }
  31. /**
  32. * @param null $uid
  33. * @return int
  34. * @author xaboy
  35. * @day 2020/6/11
  36. */
  37. public function orderNumber($uid = null)
  38. {
  39. return StoreGroupOrder::when($uid, function ($query, $uid) {
  40. $query->where('uid', $uid);
  41. })->where('is_del', 0)->where('paid', 0)->count();
  42. }
  43. /**
  44. * @param array $where
  45. * @return \think\db\BaseQuery
  46. * @author xaboy
  47. * @day 2020/6/9
  48. */
  49. public function search(array $where)
  50. {
  51. return StoreGroupOrder::getDB()->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
  52. $query->where('paid', $where['paid']);
  53. })->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
  54. $query->where('uid', $where['uid']);
  55. })->order('create_time DESC')->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use ($where) {
  56. $query->where('is_del', $where['is_del']);
  57. }, function ($query) {
  58. $query->where('is_del', 0);
  59. });
  60. }
  61. /**
  62. * @param $time
  63. * @param bool $is_remind
  64. * @return array
  65. * @author xaboy
  66. * @day 2020/6/9
  67. */
  68. public function getTimeOutIds($time, $is_remind = false)
  69. {
  70. return StoreGroupOrder::getDB()->where('is_del', 0)->where('paid', 0)
  71. ->when($is_remind, function ($query) {
  72. $query->where('is_remind', 0);
  73. })->where('create_time', '<=', $time)->column('group_order_id');
  74. }
  75. public function isRemind($id)
  76. {
  77. return StoreGroupOrder::getDB()->where('group_order_id', $id)->update(['is_remind' => 1]);
  78. }
  79. public function totalNowMoney($uid)
  80. {
  81. return StoreGroupOrder::getDB()->where('pay_type', 0)->where('uid', $uid)->sum('pay_price') ?: 0;
  82. }
  83. }