Task.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\store\model\bargain;
  3. use app\common\model\bargain\Task as TaskModel;
  4. use app\store\service\Goods as GoodsService;
  5. /**
  6. * 砍价任务模型
  7. * Class Task
  8. * @package app\store\model\bargain
  9. */
  10. class Task extends TaskModel
  11. {
  12. /**
  13. * 获取列表数据
  14. * @param string $search
  15. * @return mixed|\think\Paginator
  16. * @throws \think\db\exception\DataNotFoundException
  17. * @throws \think\db\exception\ModelNotFoundException
  18. * @throws \think\exception\DbException
  19. */
  20. public function getList($search = '')
  21. {
  22. $this->setBaseQuery($this->alias, [
  23. ['goods', 'goods_id'],
  24. ['user', 'user_id'],
  25. ]);
  26. // 检索查询条件
  27. if (!empty($search)) {
  28. $this->where(function ($query) use ($search) {
  29. $query->whereOr('goods.goods_name', 'like', "%{$search}%");
  30. $query->whereOr('user.nickName', 'like', "%{$search}%");
  31. });
  32. }
  33. // 获取活动列表
  34. $list = $this->with(['user'])
  35. ->where("{$this->alias}.is_delete", '=', 0)
  36. ->order(["{$this->alias}.create_time" => 'desc'])
  37. ->paginate(15, false, [
  38. 'query' => \request()->request()
  39. ]);
  40. if (!$list->isEmpty()) {
  41. // 设置商品数据
  42. $list = GoodsService::setGoodsData($list);
  43. }
  44. return $list;
  45. }
  46. /**
  47. * 软删除
  48. * @return false|int
  49. */
  50. public function setDelete()
  51. {
  52. return $this->allowField(true)->save(['is_delete' => 1]);
  53. }
  54. }