TaskHelp.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\api\model\bargain;
  10. use app\common\model\bargain\TaskHelp as TaskHelpModel;
  11. /**
  12. * 砍价任务助力记录模型
  13. * Class TaskHelp
  14. * @package app\api\model\bargain
  15. */
  16. class TaskHelp extends TaskHelpModel
  17. {
  18. /**
  19. * 隐藏的字段
  20. * @var array
  21. */
  22. protected $hidden = [
  23. 'wxapp_id',
  24. 'create_time',
  25. ];
  26. /**
  27. * 获取助力列表记录
  28. * @param $taskId
  29. * @return false|\PDOStatement|string|\think\Collection
  30. */
  31. public static function getListByTaskId($taskId)
  32. {
  33. // 获取列表数据
  34. $list = (new static)->with(['user'])
  35. ->where('task_id', '=', $taskId)
  36. ->order(['create_time' => 'desc'])
  37. ->select();
  38. // 隐藏会员昵称
  39. foreach ($list as &$item) {
  40. $item['user']['nickName'] = \substr_cut($item['user']['nickName']);
  41. }
  42. return $list;
  43. }
  44. /**
  45. * 新增记录
  46. * @param $task
  47. * @param $userId
  48. * @param $cutMoney
  49. * @param $isCreater
  50. * @return false|int
  51. */
  52. public function add($task, $userId, $cutMoney, $isCreater = false)
  53. {
  54. return $this->save([
  55. 'task_id' => $task['task_id'],
  56. 'active_id' => $task['active_id'],
  57. 'user_id' => $userId,
  58. 'cut_money' => $cutMoney,
  59. 'is_creater' => $isCreater,
  60. 'wxapp_id' => static::$wxapp_id,
  61. ]);
  62. }
  63. /**
  64. * 根据砍价活动id获取正在砍价的助力信息列表
  65. * @param $activeId
  66. * @return false|\PDOStatement|string|\think\Collection
  67. * @throws \think\db\exception\DataNotFoundException
  68. * @throws \think\db\exception\ModelNotFoundException
  69. * @throws \think\exception\DbException
  70. */
  71. public function getHelpListByActiveId($activeId)
  72. {
  73. return $this
  74. ->with('user') // todo: 废弃
  75. ->alias('help')
  76. ->field(['help.user_id', 'user.nickName', 'user.avatarUrl'])
  77. ->join('user', 'user.user_id = help.user_id')
  78. ->join('bargain_task task', 'task.task_id = help.task_id')
  79. ->where('help.active_id', '=', $activeId)
  80. // is_creater 只统计发起人
  81. // ->where('help.is_creater', '=', 1)
  82. ->where('task.status', '=', 1)
  83. ->where('task.is_delete', '=', 0)
  84. ->group('help.user_id')
  85. ->limit(5)
  86. ->select();
  87. }
  88. /**
  89. * 根据砍价活动id获取正在砍价的助力人数
  90. * @param $activeId
  91. * @return int|string
  92. * @throws \think\Exception
  93. */
  94. public function getHelpCountByActiveId($activeId)
  95. {
  96. return $this->alias('help')
  97. ->join('user', 'user.user_id = help.user_id')
  98. ->join('bargain_task task', 'task.task_id = help.task_id')
  99. ->where('help.active_id', '=', $activeId)
  100. // is_creater 只统计发起人
  101. // ->where('help.is_creater', '=', 1)
  102. ->where('task.status', '=', 1)
  103. ->where('task.is_delete', '=', 0)
  104. ->group('help.user_id')
  105. ->count();
  106. }
  107. }