StoreBargainUserDao.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. 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\bargain
  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 = 0, int $limit = 0)
  61. {
  62. return $this->search(['uid' => $bargainUserUid, 'is_del' => 0])->with('getBargain')->order('add_time DESC,id DESC')->when($page && $limit, function ($query) use ($page, $limit) {
  63. $query->page($page, $limit);
  64. })->select()->toArray();
  65. }
  66. /**
  67. * 获取砍价状态
  68. * @param $bargainId
  69. * @param $uid
  70. * @return mixed
  71. */
  72. public function getBargainUserStatus($bargainId, $uid)
  73. {
  74. return $this->search(['bargain_id' => $bargainId, 'uid' => $uid])->order('add_time DESC')->value('status');
  75. }
  76. /**
  77. * 修改砍价状态
  78. * @param int $id
  79. * @param int $status
  80. * @return \crmeb\basic\BaseModel
  81. */
  82. public function updateBargainStatus(int $id, int $status = 3)
  83. {
  84. return $this->getModel()->where('id', $id)->where('status', 1)->update(['status' => $status]);
  85. }
  86. /**
  87. * 砍价列表
  88. * @param $where
  89. * @param int $page
  90. * @param int $limit
  91. * @return array
  92. * @throws \think\db\exception\DataNotFoundException
  93. * @throws \think\db\exception\DbException
  94. * @throws \think\db\exception\ModelNotFoundException
  95. */
  96. public function bargainUserList($where, $page = 0, $limit = 0)
  97. {
  98. return $this->search($where)->with(['getBargain', 'getUser'])->when($page && $limit, function ($query) use ($page, $limit) {
  99. $query->page($page, $limit);
  100. })->order('add_time desc')->select()->toArray();
  101. }
  102. }