Task.php 1.7 KB

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