StoreBargainUserDao.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. declare (strict_types=1);
  12. namespace app\dao\activity\bargain;
  13. use app\dao\BaseDao;
  14. use app\model\activity\bargain\StoreBargainUser;
  15. /**
  16. *
  17. * Class StoreBargainUserDao
  18. * @package app\dao\activity
  19. */
  20. class StoreBargainUserDao extends BaseDao
  21. {
  22. /**
  23. * 设置模型
  24. * @return string
  25. */
  26. protected function setModel(): string
  27. {
  28. return StoreBargainUser::class;
  29. }
  30. /**
  31. * 获取帮砍数量
  32. * @param array $where
  33. * @return array
  34. */
  35. public function getAllCount(array $where = [])
  36. {
  37. return $this->getModel()->where($where)->group('bargain_id')->column('count(*)', 'bargain_id');
  38. }
  39. /**
  40. * 获取砍价表ID
  41. * @param int $bargainId $bargainId 砍价商品
  42. * @param int $bargainUserUid $bargainUserUid 开启砍价用户编号
  43. * @param int $status $status 砍价状态 1参与中 2 活动结束参与失败 3活动结束参与成功
  44. * @return mixed
  45. */
  46. public function getBargainUserTableId(int $bargainId = 0, int $bargainUserUid = 0)
  47. {
  48. return $this->value(['bargain_id' => $bargainId, 'uid' => $bargainUserUid, 'is_del' => 0, 'status' => 1], 'id') ?? 0;
  49. }
  50. /**
  51. * 获取用户砍价列表
  52. * @param int $bargainUserUid
  53. * @param int $page
  54. * @param int $limit
  55. * @return array
  56. * @throws \think\db\exception\DataNotFoundException
  57. * @throws \think\db\exception\DbException
  58. * @throws \think\db\exception\ModelNotFoundException
  59. */
  60. public function userAll(int $bargainUserUid, int $page, int $limit)
  61. {
  62. return $this->search(['uid' => $bargainUserUid, 'is_del' => 0])->with('getBargain')->order('add_time DESC,id DESC')->page($page, $limit)->select()->toArray();
  63. }
  64. /**
  65. * 获取砍价状态
  66. * @param $bargainId
  67. * @param $uid
  68. * @return mixed
  69. */
  70. public function getBargainUserStatus($bargainId, $uid)
  71. {
  72. return $this->search(['bargain_id' => $bargainId, 'uid' => $uid])->order('add_time DESC')->value('status');
  73. }
  74. /**
  75. * 修改砍价状态
  76. * @param int $id
  77. * @param int $status
  78. * @return \crmeb\basic\BaseModel
  79. */
  80. public function updateBargainStatus(int $id, int $status = 3)
  81. {
  82. return $this->getModel()->where('id', $id)->where('status', 1)->update(['status' => $status]);
  83. }
  84. /**
  85. * 砍价列表
  86. * @param $where
  87. * @param int $page
  88. * @param int $limit
  89. * @return array
  90. * @throws \think\db\exception\DataNotFoundException
  91. * @throws \think\db\exception\DbException
  92. * @throws \think\db\exception\ModelNotFoundException
  93. */
  94. public function bargainUserList($where, $page = 0, $limit = 0)
  95. {
  96. return $this->search($where)->with(['getBargain', 'getUser'])
  97. ->when(isset($where['real_name']) && $where['real_name'] != '', function ($query) use ($where) {
  98. $query->where('uid', $where['real_name']);
  99. })->when($page != 0, function ($query) use ($page, $limit) {
  100. $query->page($page, $limit);
  101. })->order('add_time desc')->select()->toArray();
  102. }
  103. }