SupplyDemandLists.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\api\lists\supply_demand;
  15. use app\api\lists\BaseApiDataLists;
  16. use app\common\enum\YesNoEnum;
  17. use app\common\lists\ListsSearchInterface;
  18. use app\common\model\agricultural_machinery\UserService;
  19. use app\common\model\supply_demand\SupplyDemandInfo;
  20. /**
  21. * 供应列表
  22. * Class ArticleLists
  23. * @package app\api\lists\article
  24. */
  25. class SupplyDemandLists extends BaseApiDataLists implements ListsSearchInterface
  26. {
  27. /**
  28. * @notes 搜索条件
  29. * @return \string[][]
  30. * @author 段誉
  31. * @date 2022/9/16 18:54
  32. */
  33. public function setSearch(): array
  34. {
  35. return [
  36. '%like%' => ['title','mobile','address'],
  37. '=' => ['type']
  38. ];
  39. }
  40. /**
  41. * @notes 自定查询条件
  42. * @return array
  43. * @author 段誉
  44. * @date 2022/10/25 16:53
  45. */
  46. public function queryWhere()
  47. {
  48. $where[] = ['status', '=', 2];
  49. // $where[] = ['expiration_time', '>=', time()];
  50. // if (!empty($this->params['cate_id'])) {
  51. //
  52. // $where[] = ['cate_id', 'like', '%' . ',' .$this->params['cate_id'].',' . '%'];
  53. // }
  54. //
  55. // if (!empty($this->params['area_id'])) {
  56. //
  57. // $where[] = ['area_id', 'like', '%' . ',' .$this->params['area_id'].',' . '%'];
  58. // }
  59. return $where;
  60. }
  61. /**
  62. * @notes 获取供需列表
  63. * @return array
  64. * @throws \think\db\exception\DataNotFoundException
  65. * @throws \think\db\exception\DbException
  66. * @throws \think\db\exception\ModelNotFoundException
  67. * @author 段誉
  68. * @date 2022/9/16 18:55
  69. */
  70. public function lists(): array
  71. {
  72. $orderRaw = 'id desc';
  73. $field = 'id,user_id,title,type,mobile,images,address,number,content,status,remark,create_time';
  74. $result = SupplyDemandInfo::field($field)
  75. ->where($this->queryWhere())
  76. ->where($this->searchWhere)
  77. ->orderRaw($orderRaw)
  78. ->append(['type_desc','status_desc','images','user'])
  79. ->limit($this->limitOffset, $this->limitLength)
  80. ->select()->toArray();
  81. return $result;
  82. }
  83. /**
  84. * @notes 获取服务商数量
  85. * @return int
  86. * @author 段誉
  87. * @date 2022/9/16 18:55
  88. */
  89. public function count(): int
  90. {
  91. return SupplyDemandInfo::where($this->searchWhere)
  92. ->where($this->queryWhere())
  93. ->count();
  94. }
  95. }