Demand.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\UserDemand;
  4. use library\tools\Data;
  5. /**
  6. * @title 需求
  7. * @controller Demand
  8. * @group base
  9. */
  10. class Demand extends Base
  11. {
  12. // 需要登录的
  13. protected $need_login = [];
  14. public function initialize()
  15. {
  16. parent::initialize();
  17. parent::setUid();
  18. }
  19. /**
  20. * @title 需求接口说明
  21. * @desc 需求接口说明
  22. * @author qc
  23. * @url /api/Demand/classIntro
  24. * @method GET
  25. */
  26. public function classIntro(){}
  27. /**
  28. * @title 以下接口调用验证登录【需要header传Authorization】
  29. * @desc 转发成功后调用
  30. * @author qc
  31. * @method
  32. * @url /api/Demand/needLogin
  33. */
  34. public function needLogin(){}
  35. /**
  36. * @title 用户提交||修改需求【用户】
  37. * @desc 用户提交||修改需求
  38. * @author qc
  39. * @method POST
  40. * @url /api/Demand/commitDemand
  41. * @param name:id type:int default:-- desc:修改必传
  42. * @param name:title type:string default:-- desc:标题
  43. * @param name:content type:string default:1 desc:内容
  44. * @param name:money type:float default:0 desc:价格【设计图没有,可以不传】
  45. */
  46. public function commitDemand()
  47. {
  48. $title = input('post.title');
  49. $content = input('post.content');
  50. $money = input('post.money');
  51. $id = input('post.id');
  52. if(!$title ||$content) $this->error('标题和需求内容必填');
  53. Data::save('UserDemand',['title'=>$title,'content'=>$content,'user_id'=>$this->user_id,'money'=>$money,'id'=>$id],'user_id',['user_id'=>$this->user_id,'id'=>$id]);
  54. $this->success('提交成功,请等待审核');
  55. }
  56. /**
  57. * @title 获取我的需求列表【用户】
  58. * @desc 获取我的图文列表【用户】
  59. * @author qc
  60. * @method GET
  61. * @url /api/Demand/getMyDemandList
  62. * @header name:Authorization require:1 desc:Token
  63. * @param name:title type:string default:-- desc:标题
  64. * @param name:page type:int default:0 desc:页数
  65. * @param name:page_num type:int default:20 desc:每页数
  66. * @return name:title type:string default:-- desc:标题
  67. * @return name:content type:string default:-- desc:需求
  68. * @return name:status type:int default:-- desc:0待审核1审核通过2审核未通过
  69. * @return name:remark type:string default:-- desc:审核备注
  70. */
  71. public function getMyDemandList()
  72. {
  73. $sel_where = [];
  74. $sel_where[] = ['is_deleted','=',0];
  75. $sel_where[] = ['user_id','=',$this->user_id];
  76. $title = input('get.title');
  77. if($title) $sel_where[] = ['title','like','%'.$title.'%'];
  78. $list = UserDemand::where($sel_where)
  79. ->field('id,title,content,status,remark')
  80. ->order('id desc')
  81. ->limit($this->off_set,$this->page_num)
  82. ->select()->toArray();
  83. $this->success('ok',['list'=>$list]);
  84. }
  85. /**
  86. * @title 删除我的需求【用户】
  87. * @desc 删除我的需求【用户】
  88. * @author qc
  89. * @method POST
  90. * @url /api/Demand/delMyDemand
  91. * @param name:id type:int default:-- desc:需求记录id
  92. */
  93. public function delMyDemand()
  94. {
  95. UserDemand::where(['id'=>input('post.id'),'user_id'=>$this->user_id])->delete();
  96. $this->success('删除成功');
  97. }
  98. }