Demand.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\ArticleCommentLike;
  4. use app\common\model\PlatformDemand;
  5. use app\common\model\DemandComment;
  6. use app\common\model\PlatformLike;
  7. use app\common\model\User;
  8. use app\common\model\UserCollect;
  9. use app\common\model\UserDemand;
  10. use app\common\model\UserMessage;
  11. use app\common\model\UserSearch;
  12. use app\common\model\UserTrack;
  13. use library\tools\Data;
  14. use think\Db;
  15. /**
  16. * @title 需求【也叫项目。。。】
  17. * @controller Demand
  18. * @group base
  19. */
  20. class Demand extends Base
  21. {
  22. // 需要登录的
  23. protected $need_login = [
  24. 'demandComment',
  25. 'demandSecondComment',
  26. 'commentTags',
  27. 'commitDemand',
  28. 'getMyDemandList',
  29. 'getMyDemandDetail',
  30. 'delMyDemand',
  31. ];
  32. public function initialize()
  33. {
  34. parent::initialize();
  35. parent::setUid();
  36. }
  37. /**
  38. * @title 需求接口说明
  39. * @desc 需求接口说明
  40. * @author qc
  41. * @url /api/Demand/classIntro
  42. * @method GET
  43. */
  44. public function classIntro(){}
  45. /**
  46. * @title 需求推荐
  47. * @desc 需求推荐
  48. * @author qc
  49. * @method GET
  50. * @url /api/Demand/getRecommendList
  51. * @header name:Authorization require:1 desc:Token
  52. * @param name:page type:int default:0 desc:页数
  53. * @param name:page_num type:int default:20 desc:每页数
  54. * @param name:is_over type:int default:20 desc:是否解决或开源【0否,1是,2开源】
  55. * @return name:title type:string default:-- desc:标题
  56. * @return name:content type:string default:-- desc:内容
  57. * @return name:cover type:array default:-- desc:封面
  58. * @return name:money type:float default:-- desc:价格
  59. * @return name:app_name type:string default:-- desc:发布方名称
  60. * @return name:app_logo type:string default:-- desc:发布方头像
  61. * @return name:is_over type:int default:-- desc:是否解决或开源【0否,1是,2开源】
  62. *
  63. */
  64. public function getRecommendList()
  65. {
  66. $search_log = UserSearch::getSearchTitle($this->user_id,5);
  67. $app_name = sysconf('app_name');
  68. $app_logo = sysconf('app_logo');
  69. $search_arr = [];
  70. $is_over = input('is_over',0);
  71. $where_str = 'b.id > 0';
  72. foreach ($search_log as $t){
  73. $search_arr[] = " b.title like '".'%'.$t."%'" .' ';
  74. $search_arr[] = " b.label like '".'%'.$t."%'" .' ';
  75. }
  76. if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr);
  77. $field = 'a.id,cover,money,user_id,label,title,cover,is_over,content,IFNULL(is_recommend,0) is_recommend ';
  78. $table = 'dd_platform_demand';
  79. $order_by_two = 'id';
  80. $sql = "SELECT $field FROM " .$table . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM $table b WHERE ( $where_str )) AS c ON c.id = a.id WHERE a.is_deleted = 0 AND a.status = 1 AND a.is_over = ".$is_over ." ORDER BY is_recommend DESC , $order_by_two desc LIMIT {$this->off_set},{$this->page_num}";
  81. $list = Db::query($sql);
  82. array_walk($list,function (&$v,$k)use ($app_name,$app_logo){
  83. if(!$v['user_id']){
  84. $v['app_name'] = $app_name;
  85. $v['app_logo'] = $app_logo;
  86. }else{
  87. $user_info = User::where('id',$v['user_id'])->field('name,headimg')->find();
  88. $v['app_name'] = $user_info ? $user_info->name : '';
  89. $v['app_logo'] = $user_info ? $user_info->headimg : '';
  90. }
  91. $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
  92. $v['cover_arr'] = explode('|',trim($v['cover'],'|'));
  93. });
  94. $this->success('ok',['list'=>$list]);
  95. }
  96. /**
  97. * @title 需求列表【平台】
  98. * @desc 需求列表【平台】
  99. * @author qc
  100. * @method GET
  101. * @url /api/Demand/getDemandList
  102. * @header name:Authorization require:1 desc:Token
  103. * @param name:title type:string default:-- desc:标题
  104. * @param name:is_over type:int default:-1 desc:是否解决或开源【0否,1是,2开源】
  105. * @param name:sort_type type:int default:1 desc:1默认2时间升序3时间降序
  106. * @param name:page type:int default:0 desc:页数
  107. * @param name:page_num type:int default:20 desc:每页数
  108. * @return name:title type:string default:-- desc:标题
  109. * @return name:content type:string default:-- desc:需求
  110. * @return name:images type:string default:-- desc:图片【多张|隔开】
  111. * @return name:user_name type:string default:-- desc:名称
  112. * @return name:headimg type:string default:-- desc:头像
  113. * @return name:money type:float default:-- desc:金额
  114. * @return name:is_over type:int default:-- desc:是否解决或开源【0否,1是,2开源】
  115. * @param name:company type:string default:0 desc:公司名
  116. * @param name:company_logo type:string default:0 desc:公司logo
  117. */
  118. public function getDemandList()
  119. {
  120. $title = input('get.title');
  121. $is_tj = input('get.is_tj',0);
  122. $is_over = input('get.is_over',-1);
  123. $sort_type = input('get.sort_type',1);
  124. $sel_where =[];
  125. $sel_where[] = ['d.is_deleted','=',0];
  126. $sel_where[] = ['d.status','=',1];
  127. if($title) $sel_where[] = ['d.title|d.label','like','%'.$title.'%'];
  128. if($is_over > -1) $sel_where[] = ['d.is_over','=',$is_over];
  129. if($title && $this->user_id) UserSearch::saveSearchTitle($this->user_id,$title,5);
  130. $where_str = '';
  131. if($is_tj) {
  132. $search_log = UserSearch::getSearchTitle($this->user_id,5);
  133. $search_arr = [];
  134. foreach ($search_log as $t){
  135. $search_arr[] = " d.title like '".'%'.$t."%'" .' ';
  136. }
  137. if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr);
  138. }
  139. $app_name = sysconf('app_name');
  140. $app_log = sysconf('app_log');
  141. switch ($sort_type) {
  142. case 1:
  143. $order = ['sort'=>'desc','id'=>'desc'];
  144. break;
  145. case 2:
  146. $order = ['id'=>'asc','sort'=>'desc'];
  147. break;
  148. case 3:
  149. $order = ['id'=>'desc','sort'=>'desc'];
  150. break;
  151. }
  152. $list = PlatformDemand::where($sel_where)
  153. ->field('d.*,u.name user_name,u.headimg')
  154. ->alias('d')
  155. ->leftJoin('store_member u','u.id = d.user_id')
  156. ->when($where_str,function ($query)use ($where_str){if($where_str) $query->where($where_str);})
  157. ->order($order)
  158. ->limit($this->off_set,$this->page_num)->select()->toArray();
  159. array_walk($list,function (&$v)use ($app_name,$app_log){
  160. if(!$v['user_name']) $v['user_name'] = $app_name;
  161. if(!$v['headimg']) $v['headimg'] = $app_log;
  162. });
  163. $this->success('ok',['list'=>$list]);
  164. }
  165. /**
  166. * @title 需求详情【平台】
  167. * @desc 需求详情【平台】
  168. * @author qc
  169. * @method GET
  170. * @url /api/Demand/getDemandInfo
  171. * @header name:Authorization require:1 desc:Token
  172. * @param name:id type:int default:-- desc:平台发布需求id
  173. * @return name:title type:string default:-- desc:标题
  174. * @return name:content type:string default:-- desc:需求
  175. * @return name:images type:string default:-- desc:图片【多张|隔开】
  176. * @return name:user_name type:string default:-- desc:名称
  177. * @return name:headimg type:string default:-- desc:头像
  178. * @return name:money type:float default:-- desc:金额
  179. * @return name:is_over type:int default:-- desc:是否解决或开源【0否,1是,2开源】
  180. * @param name:company type:string default:0 desc:公司名
  181. * @param name:company_logo type:string default:0 desc:公司logo
  182. * @return name:like_num type:int default:-- desc:点赞数量
  183. * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
  184. * @return name:is_collect type:int default:-- desc:是否收藏(0否1是)
  185. * @return name:collect_num type:int default:-- desc:收藏量
  186. * @return name:app_name type:string default:-- desc:发布方名称
  187. * @return name:app_logo type:string default:-- desc:发布方头像
  188. */
  189. public function getDemandInfo()
  190. {
  191. $detail = PlatformDemand::where('id',input('get.id'))->find();
  192. $app_name = sysconf('app_name');
  193. $app_logo = sysconf('app_logo');
  194. if(!$detail || $detail->is_deleted == 1) $this->error('该需求已删除');
  195. $detail = $detail->toArray();
  196. $detail['label_name'] = $detail['label'] ? explode(',',trim($detail['label'],',')) : null;
  197. $detail['like_num'] = PlatformLike::getPraiseNum($detail['id'],9);
  198. $detail['is_like'] = PlatformLike::checkTags($this->user_id, $detail['id'], 9);
  199. $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id,10,$detail['id']);
  200. $detail['collect_num'] = UserCollect::getCollectNum(10,$detail['id']);
  201. UserTrack::crateTrack($this->user_id,11,input('get.id'),0);
  202. if(!$detail['user_id']){
  203. $detail['app_name'] = $app_name;
  204. $detail['app_logo'] = $app_logo;
  205. }else{
  206. $user_info = $this->userInfo('name,headimg');
  207. $detail['app_name'] = $user_info['name'];
  208. $detail['app_logo'] = $user_info['headimg'];
  209. }
  210. $this->success('ok',['detail'=>$detail]);
  211. }
  212. /**
  213. * @title 获取需求评论列表
  214. * @desc 获取需求评论列表
  215. * @author qc
  216. * @method GET
  217. * @url /api/Demand/getDemandCommentList
  218. * @header name:Authorization require:1 desc:Token
  219. * @param name:id type:int default:-- desc:需求id
  220. * @param name:sort_type type:int default:1 desc:排序规则1时间2热点
  221. * @param name:page type:int default:-- desc:页数
  222. * @return name:name type:string default:-- desc:会员名称
  223. * @return name:headimg type:string default:-- desc:会员头像
  224. * @return name:content type:string default:-- desc:内容
  225. * @return name:parent type:array default:-- desc:评论上一级(数据同上【一维数组】)
  226. * @return name:children type:array default:-- desc:二级评论(数据同上【二维数组】)
  227. * @return name:like_num type:int default:-- desc:点赞数量
  228. * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
  229. * @return name:total_num type:int default:-- desc:总评论数(仅一级)
  230. */
  231. public function getDemandCommentList()
  232. {
  233. $where = [];
  234. $where[] = ['c.first_id','=',input('get.id')];
  235. $where[] = ['c.is_deleted','=',0];
  236. $where[] = ['c.type','=',1];
  237. $user_id = $this->user_id;
  238. $sort_type= input('sort_type',1);
  239. $order = $sort_type == 1 ? 'c.id desc' : 'c.like_times desc';
  240. $list =DemandComment::where($where)
  241. ->alias('c')
  242. ->field('c.*,u.name,u.headimg')
  243. ->leftJoin('store_member u','u.id = c.user_id')
  244. ->order($order)
  245. ->limit($this->off_set,$this->page_num)
  246. ->select()->toArray();
  247. array_walk($list,function (&$val,$k)use($user_id){
  248. $children = DemandComment::where(['c.pid'=>$val['id'],'c.is_deleted'=>0])
  249. ->alias('c')->field('c.*,u.name,u.headimg')
  250. ->leftJoin('store_member u','u.id = c.user_id')
  251. ->order('c.id asc')
  252. ->select()->toArray();
  253. $val['children'] = $children ? $children : null;
  254. $val['like_num'] = PlatformLike::getPraiseNum($val['id'],6);
  255. $val['is_like'] = PlatformLike::where(['like_id'=>$val['id'],'user_id'=>$user_id,'type'=>6])->count();
  256. $parent = DemandComment::where(['c.id'=>$val['pid'],'c.is_deleted'=>0])
  257. ->alias('c')->field('c.*,u.name,u.headimg')
  258. ->leftJoin('store_member u','u.id = c.user_id')
  259. ->find();
  260. $val['parent'] = $parent ? $parent->toArray() : null;
  261. });
  262. $total_num = DemandComment::where($where)->alias('c')->count();
  263. $this->success('ok',['list'=>$list,'total_num'=>$total_num]);
  264. }
  265. /**
  266. * @title 以下接口调用验证登录【需要header传Authorization】
  267. * @desc
  268. * @author qc
  269. * @method
  270. * @url /api/Demand/needLogin
  271. */
  272. public function needLogin(){}
  273. /**
  274. * @title 需求评论
  275. * @desc 需求评论
  276. * @author qc
  277. * @method POST
  278. * @url /api/Demand/demandComment
  279. * @header name:Authorization require:1 desc:Token
  280. * @param name:id type:int default:1 desc:需求id
  281. * @param name:content type:string default:-- desc:内容
  282. * @return name:name type:string default:-- desc:会员名称
  283. * @return name:headimg type:string default:-- desc:会员头像
  284. * @return name:content type:string default:-- desc:内容
  285. * @return name:create_at type:string default:-- desc:时间
  286. */
  287. public function demandComment()
  288. {
  289. $id = input('post.id');
  290. $content = input('post.content',0);
  291. if(!$content) $this->error('请输入评论内容');
  292. $send_user = PlatformDemand::where('id',$id)->value('user_id');
  293. $user_info = $this->userInfo('name');
  294. if($send_user) UserMessage:: sendUserMessage($send_user,'demand',4,0,$this->user_id,$id,$user_info['name'].'评论了您的需求');
  295. $res = DemandComment::create(['user_id'=>$this->user_id,'content'=>$content,'first_id'=>$id,'type'=>1]);
  296. $detail =DemandComment::where('p.id',$res->id)
  297. ->alias('p')
  298. ->field('p.id,p.content,p.create_at,u.name,u.headimg')
  299. ->leftJoin('store_member u','u.id = p.user_id')
  300. ->find()->toArray();
  301. $this->success('评论成功',['detail'=>$detail]);
  302. }
  303. /**
  304. * @title 需求二级评论
  305. * @desc 需求二级评论
  306. * @author qc
  307. * @method POST
  308. * @url /api/Demand/demandSecondComment
  309. * @header name:Authorization require:1 desc:Token
  310. * @param name:id type:int default:1 desc:评论id
  311. * @param name:content type:string default:-- desc:内容
  312. * @return name:name type:string default:-- desc:会员名称
  313. * @return name:headimg type:string default:-- desc:会员头像
  314. * @return name:content type:string default:-- desc:内容
  315. */
  316. public function demandSecondComment()
  317. {
  318. $comment = DemandComment::where('id',input('post.id'))->find()->toArray();
  319. $user_info = $this->userInfo('name');
  320. UserMessage:: sendUserMessage($comment['user_id'],'demand',3,0,$this->user_id,$comment['id'],$user_info['name'].'回复了您的评论');
  321. $send_user = PlatformDemand::where('id',$comment['first_id'])->value('user_id');
  322. if($send_user) UserMessage::sendUserMessage($send_user,'demand',4,0,$this->user_id,$comment['first_id'],$user_info['name'].'评论了您的需求');
  323. unset($comment['id']);
  324. unset($comment['create_at']);
  325. $comment['pid'] = input('post.id');
  326. $comment['user_id'] = $this->user_id;
  327. $comment['content'] = input('post.content');
  328. $comment['lev']++;
  329. if(!$comment['source_id']) $comment['source_id'] = input('post.id');
  330. $res = DemandComment::create($comment);
  331. $detail = DemandComment::where('p.id',$res->id)
  332. ->alias('p')
  333. ->field('p.id,p.content,p.create_at,u.name,u.headimg')
  334. ->leftJoin('store_member u','u.id = p.user_id')
  335. ->find()->toArray();
  336. $this->success('评论成功',['detail'=>$detail]);
  337. }
  338. /**
  339. * @title 需求点赞||取消点赞[需求]
  340. * @desc 评论
  341. * @author qc
  342. * @method POST
  343. * @url /api/Demand/demandTags
  344. * @header name:Authorization require:1 desc:Token
  345. * @param name:demand_id type:int default:1 desc:需求id
  346. * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
  347. */
  348. public function demandTags()
  349. {
  350. $ret_val = PlatformLike::userTags($this->user_id,input('post.demand_id'),9);
  351. $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
  352. }
  353. /**
  354. * @title 评论点赞||取消点赞[评论]
  355. * @desc 评论
  356. * @author qc
  357. * @method POST
  358. * @url /api/Demand/commentTags
  359. * @header name:Authorization require:1 desc:Token
  360. * @param name:comment_id type:int default:1 desc:评论记录id
  361. * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
  362. */
  363. public function commentTags()
  364. {
  365. $ret_val = PlatformLike::userTags($this->user_id,input('post.comment_id'),6);
  366. $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
  367. }
  368. /**
  369. * @title 收藏||取消收藏
  370. * @desc 用户收藏
  371. * @author qc
  372. * @method POST
  373. * @url /api/Demand/demandCollect
  374. * @header name:Authorization require:1 desc:Token
  375. * @param name:id type:int require:1 default:-- desc:需求id
  376. * @param name:status type:int default:0 desc:收藏状态(0取消收藏【未收藏】,1收藏)
  377. */
  378. public function demandCollect(){
  379. $coll_status = UserCollect::plateCollect($this->user_id,10,input('post.id',0));
  380. $coll_status ? $this->success('收藏成功',['status'=>1]) : $this->success('取消收藏成功',['status'=>0]);
  381. }
  382. /**
  383. * @title 用户提交||修改需求【用户】
  384. * @desc 用户提交||修改需求
  385. * @author qc
  386. * @method POST
  387. * @url /api/Demand/commitDemand
  388. * @param name:id type:int default:-- desc:修改必传[添加不传,或是null或是空]
  389. * @param name:title type:string default:-- desc:标题
  390. * @param name:content type:string default:1 desc:内容
  391. * @param name:money type:float default:0 desc:价格【设计图没有,可以不传】
  392. * @param name:label type:string default:0 desc:标签【多个逗号隔开】
  393. * @param name:cover type:string default:0 desc:封面【一张】
  394. * @param name:images type:string default:0 desc:图片【多张|隔开】
  395. * @param name:company type:string default:0 desc:公司名
  396. * @param name:company_logo type:string default:0 desc:公司logo
  397. */
  398. public function commitDemand()
  399. {
  400. $title = input('post.title');
  401. $content = input('post.content');
  402. $money = input('post.money');
  403. $cover = input('post.cover');
  404. $images = input('post.images');
  405. $label = input('post.label');
  406. $id = input('post.id');
  407. $company = input('post.company');
  408. $company_logo = input('post.company_logo');
  409. if(!$title || !$content) $this->error('标题和需求内容必填');
  410. if($id) {
  411. $demand_status = UserDemand::where('id',$id)->value('status');
  412. if($demand_status == 1) $this->error('已审核通过,不允许修改');
  413. }
  414. $res = Data::save('UserDemand',[
  415. 'title'=>$title,
  416. 'content'=>$content,
  417. 'user_id'=>$this->user_id,
  418. 'money'=>$money,
  419. 'id'=>$id ? $id : null,
  420. 'cover'=>$cover,
  421. 'images'=>$images,
  422. 'label'=>$label,
  423. 'company'=>$company,
  424. 'company_logo'=>$company_logo,
  425. ],'user_id',['user_id'=>$this->user_id,'id'=>$id]);
  426. UserMessage::sendUserMessage($this->user_id,'demand',1,0,0,$id ? $id: intval($res));
  427. $this->success('提交成功,请等待审核');
  428. }
  429. /**
  430. * @title 获取我的需求列表【我的发布】
  431. * @desc 获取我的图文列表【我的发布】
  432. * @author qc
  433. * @method GET
  434. * @url /api/Demand/getMyDemandList
  435. * @header name:Authorization require:1 desc:Token
  436. * @param name:title type:string default:-- desc:标题
  437. * @param name:page type:int default:0 desc:页数
  438. * @param name:page_num type:int default:20 desc:每页数
  439. * @return name:title type:string default:-- desc:标题
  440. * @return name:content type:string default:-- desc:需求
  441. * @return name:status type:int default:-- desc:0待审核1审核通过2审核未通过
  442. * @return name:remark type:string default:-- desc:审核备注
  443. * @return name:money type:float default:0 desc:价格【设计图没有,可以不传】
  444. * @return name:cover type:string default:0 desc:封面【一张】
  445. * @return name:images type:string default:0 desc:图片【多张|隔开】
  446. * @return name:images_arr type:array default:null desc:图片【多张】
  447. * @return name:company type:string default:0 desc:公司名
  448. * @return name:company_logo type:string default:0 desc:公司logo
  449. */
  450. public function getMyDemandList()
  451. {
  452. $sel_where = [];
  453. $sel_where[] = ['is_deleted','=',0];
  454. $sel_where[] = ['user_id','=',$this->user_id];
  455. $title = input('get.title');
  456. if($title) $sel_where[] = ['title|label','like','%'.$title.'%'];
  457. $list = UserDemand::where($sel_where)
  458. ->field('id,title,content,status,remark,cover,images,money,company,company_logo')
  459. ->order('id desc')
  460. ->limit($this->off_set,$this->page_num)
  461. ->select()->toArray();
  462. foreach ($list as &$lv){
  463. $lv['images_arr'] = $lv['images'] ? explode('|',$lv['images']) : null;
  464. }
  465. $this->success('ok',['list'=>$list]);
  466. }
  467. /**
  468. * @title 获取我的需求详情【用户】
  469. * @desc 获取我的需求详情【用户】
  470. * @author qc
  471. * @method GET
  472. * @url /api/Demand/getMyDemandDetail
  473. * @header name:Authorization require:1 desc:Token
  474. * @param name:id type:int default:0 desc:需求记录id
  475. * @return name:title type:string default:-- desc:标题
  476. * @return name:content type:string default:-- desc:需求
  477. * @return name:status type:int default:-- desc:0待审核1审核通过2审核未通过
  478. * @return name:remark type:string default:-- desc:审核备注
  479. * @return name:money type:float default:-- desc:金额
  480. * @return name:cover type:string default:0 desc:封面【一张】
  481. * @return name:images type:string default:0 desc:图片【多张|隔开】
  482. * @return name:images_arr type:array default:null desc:图片【多张】
  483. * @return name:company type:string default:0 desc:公司名
  484. * @return name:company_logo type:string default:0 desc:公司logo
  485. */
  486. public function getMyDemandDetail()
  487. {
  488. $detail = UserDemand::where(['user_id'=>$this->user_id,'id'=>input('get.id')])->find();
  489. if(!$detail || $detail->is_deleted == 1) $this->error('该需求已删除');
  490. $detail = $detail->toArray();
  491. $detail['label_name'] = $detail['label'] ? explode(',',trim($detail['label'],',')) : null;
  492. $detail['images_arr'] = $detail['images'] ? explode('|',$detail['images']) : null;
  493. $this->success('ok',['detail'=>$detail]);
  494. }
  495. /**
  496. * @title 删除我的需求【用户】
  497. * @desc 删除我的需求【用户】
  498. * @author qc
  499. * @method POST
  500. * @url /api/Demand/delMyDemand
  501. * @param name:id type:int default:-- desc:需求记录id
  502. */
  503. public function delMyDemand()
  504. {
  505. UserDemand::where(['id'=>input('post.id'),'user_id'=>$this->user_id])->delete();
  506. $this->success('删除成功');
  507. }
  508. /**
  509. * @title 我的点赞列表【需求】
  510. * @desc 我的点赞
  511. * @author qc
  512. * @method GET
  513. * @url /api/Demand/getTagsDemand
  514. * @header name:Authorization require:1 desc:Token
  515. * @param name:title type:string default:-- desc:标题
  516. * @param name:page type:int default:-- desc:页数
  517. * @param name:page_num type:int default:-- desc:每页数
  518. *
  519. * @return name:title type:string default:-- desc:标题
  520. * @return name:demand_id type:string default:-- desc:需求id
  521. * @return name:cover type:string default:-- desc:封面
  522. * @return name:content type:string default:-- desc:内容
  523. * @return name:company type:string default:-- desc:公司
  524. * @return name:company_logo type:string default:-- desc:公司logo
  525. * @return name:money type:string default:-- desc:价格
  526. * @return name:is_over type:int default:-1 desc:是否解决或开源【0否,1是,2开源】
  527. */
  528. public function getTagsDemand()
  529. {
  530. $sel_where = [];
  531. $title = input('get.title');
  532. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  533. $sel_where[] = ['t.user_id','=',$this->user_id];
  534. $sel_where[] = ['t.type','=',9];
  535. $list = PlatformLike::where($sel_where)
  536. ->alias('t')
  537. ->field('t.id,t.create_at,t.like_id demand_id,i.title,i.cover,i.content,company,money,is_over,company_logo')
  538. ->leftJoin('PlatformDemand i','t.like_id = i.id')
  539. ->order('id desc')
  540. ->limit($this->off_set,$this->page_num)
  541. ->select()->toArray();
  542. $this->success('ok',['list'=>$list]);
  543. }
  544. /**
  545. * @title 我的浏览历史【需求】
  546. * @desc 我的浏览历史
  547. * @author qc
  548. * @method GET
  549. * @url /api/Demand/getDemandTrack
  550. * @header name:Authorization require:1 desc:Token
  551. * @param name:title type:string default:-- desc:标题
  552. * @param name:page type:int default:-- desc:页数
  553. * @param name:page_num type:int default:-- desc:每页数
  554. *
  555. * @return name:title type:string default:-- desc:标题
  556. * @return name:demand_id type:string default:-- desc:需求id
  557. * @return name:cover type:string default:-- desc:封面
  558. * @return name:content type:string default:-- desc:内容
  559. * @return name:company type:string default:-- desc:公司
  560. * @return name:company_logo type:string default:-- desc:公司logo
  561. * @return name:money type:string default:-- desc:价格
  562. * @return name:is_over type:int default:-1 desc:是否解决或开源【0否,1是,2开源】
  563. * @return name:time type:string default:-- desc:时间
  564. */
  565. public function getDemandTrack()
  566. {
  567. $sel_where = [];
  568. $sel_where[] = ['t.user_id','=',$this->user_id];
  569. $sel_where[] = ['t.type','=',11];
  570. $title = input('get.title');
  571. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  572. $list = UserTrack::where($sel_where)
  573. ->alias('t')
  574. ->field('t.id,t.update_int,t.first_id demand_id,i.title,i.cover,i.content,company,money,is_over,company_logo')
  575. ->leftJoin('PlatformDemand i','t.first_id = i.id')
  576. ->order('update_int desc')
  577. ->limit($this->off_set,$this->page_num)
  578. ->select()->toArray();
  579. foreach ($list as &$v) {
  580. $v['time'] = date("Y-m-d H:i:s",$v['update_int']);
  581. }
  582. $this->success('ok',['list'=>$list]);
  583. }
  584. /**
  585. * @title 我的收藏列表【需求】
  586. * @desc 我的收藏列表
  587. * @author qc
  588. * @method GET
  589. * @url /api/Demand/getCollectDemand
  590. * @header name:Authorization require:1 desc:Token
  591. * @param name:title type:string default:-- desc:标题
  592. * @param name:page type:int default:-- desc:页数
  593. * @param name:page_num type:int default:-- desc:每页数
  594. *
  595. * @return name:title type:string default:-- desc:标题
  596. * @return name:demand_id type:string default:-- desc:需求id
  597. * @return name:cover type:string default:-- desc:封面
  598. * @return name:content type:string default:-- desc:内容
  599. * @return name:company type:string default:-- desc:公司
  600. * @return name:company_logo type:string default:-- desc:公司logo
  601. * @return name:money type:string default:-- desc:价格
  602. * @return name:is_over type:int default:-1 desc:是否解决或开源【0否,1是,2开源】
  603. */
  604. public function getCollectDemand()
  605. {
  606. $sel_where = [];
  607. $title = input('get.title');
  608. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  609. $sel_where[] = ['t.user_id','=',$this->user_id];
  610. $sel_where[] = ['t.coll_type','=',10];
  611. $list = UserCollect::where($sel_where)
  612. ->alias('t')
  613. ->field('t.id,t.create_at,t.coll_id demand_id,i.title,i.cover,i.content,company,money,is_over,company_logo')
  614. ->leftJoin('PlatformDemand i','t.coll_id = i.id')
  615. ->order('id desc')
  616. ->limit($this->off_set,$this->page_num)
  617. ->select()->toArray();
  618. $this->success('ok',['list'=>$list]);
  619. }
  620. }