Demand.php 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263
  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\PlatformSwitch;
  8. use app\common\model\TopSearch;
  9. use app\common\model\User;
  10. use app\common\model\UserCollect;
  11. use app\common\model\UserDemand;
  12. use app\common\model\UserMessage;
  13. use app\common\model\UserSearch;
  14. use app\common\model\UserTrack;
  15. use app\common\service\CheckPower;
  16. use app\common\service\UserSynth;
  17. use library\tools\Data;
  18. use think\Db;
  19. /**
  20. * @title 需求【也叫项目。。。】
  21. * @controller Demand
  22. * @group base
  23. */
  24. class Demand extends Base
  25. {
  26. // 需要登录的
  27. protected $need_login = [
  28. 'demandComment',
  29. 'demandSecondComment',
  30. 'demandTags',
  31. 'commentTags',
  32. 'demandCollect',
  33. 'getMyDemandList',
  34. 'getTagsDemand',
  35. 'getDemandTrack',
  36. 'getCollectDemand',
  37. 'getMyDemandComment',
  38. 'unreadChange',
  39. 'commentMyDemand',
  40. 'praiseMyDemand',
  41. 'praiseCommentList',
  42. 'batchesDel',
  43. 'getReplyComment',
  44. 'getTagsComment',
  45. 'getReplyDemand',
  46. ];
  47. public function initialize()
  48. {
  49. parent::initialize();
  50. parent::setUid();
  51. }
  52. /**
  53. * @title 需求推荐
  54. * @desc 需求推荐
  55. * @author qc
  56. * @method GET
  57. * @url /api/Demand/getRecommendList
  58. * @header name:Authorization require:1 desc:Token
  59. * @param name:page type:int default:0 desc:页数
  60. * @param name:page_num type:int default:20 desc:每页数
  61. * @param name:is_over type:int default:0 desc:是否解决或开源【0否,1是,2开源】
  62. * @param name:rand_user type:string default:-- desc:随机id(非登录状态必传,page=1时生成(a123),其他页数(a123),一直查询到没有数据)
  63. * @return name:title type:string default:-- desc:标题
  64. * @return name:content type:string default:-- desc:内容
  65. * @return name:cover type:array default:-- desc:封面
  66. * @return name:money type:float default:-- desc:价格
  67. * @return name:app_name type:string default:-- desc:发布方名称
  68. * @return name:app_logo type:string default:-- desc:发布方头像
  69. * @return name:label_name type:array default:-- desc:标签
  70. * @return name:is_over type:int default:-- desc:是否解决或开源【0否,1是,2开源】
  71. * @return name:release_time type:string default:-- desc:上架时间
  72. *
  73. *
  74. */
  75. public function getRecommendList()
  76. {
  77. $user_id = $this->user_id ? $this->user_id : input('rand_user');
  78. if(!$user_id) $this->error('参数错误');
  79. $list = UserSynth::getRecommendList($user_id,'demand',$this->page,$this->page_num,['is_over'=>input('is_over',0)]);
  80. if($list['code'] != 200) $this->error($list['msg']);
  81. $this->success('ok',$list);
  82. $search_log = UserSearch::getSearchTitle($this->user_id,5);
  83. $app_name = sysconf('app_name');
  84. $app_logo = sysconf('app_logo');
  85. $search_arr = [];
  86. $is_over = input('is_over',0);
  87. $where_str = 'b.id > 0';
  88. foreach ($search_log as $t){
  89. $search_arr[] = " b.title like '".'%'.$t."%'" .' ';
  90. $search_arr[] = " b.label like '".'%'.$t."%'" .' ';
  91. }
  92. if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr);
  93. $field = 'a.id,cover,money,user_id,label,title,cover,a.read_num,is_over,content,IFNULL(is_recommend,0) is_recommend ';
  94. $table = 'dd_platform_demand';
  95. $order_by_two = 'a.id';
  96. $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}";
  97. $sql2 = "SELECT count(a.id) num 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 ";
  98. $list = Db::query($sql);
  99. $list = dispose_recommend($list);
  100. array_walk($list,function (&$v,$k)use ($app_name,$app_logo){
  101. if(!$v['user_id']){
  102. $v['app_name'] = $app_name;
  103. $v['app_logo'] = $app_logo;
  104. }else{
  105. $user_info = User::where('id',$v['user_id'])->field('name,headimg')->find();
  106. $v['app_name'] = $user_info ? $user_info->name : '';
  107. $v['app_logo'] = $user_info ? $user_info->headimg : '';
  108. }
  109. $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
  110. $v['cover_arr'] = explode('|',trim($v['cover'],'|'));
  111. $v['read_num'] = numTransform($v['read_num']);
  112. });
  113. $total = Db::query($sql2);
  114. $this->success('ok',['list'=>$list,'total_count'=>$total[0]['num'],'page_num'=>$this->page_num]);
  115. }
  116. /**
  117. * @title 需求列表【平台】
  118. * @desc 需求列表【平台】
  119. * @author qc
  120. * @method GET
  121. * @url /api/Demand/getDemandList
  122. * @header name:Authorization require:1 desc:Token
  123. * @param name:title type:string default:-- desc:标题
  124. * @param name:is_over type:int default:-1 desc:是否解决或开源【0待解决,1已解决,2开源】
  125. * @param name:sort_type type:int default:1 desc:1默认2时间升序3时间降序
  126. * @param name:page type:int default:0 desc:页数
  127. * @param name:page_num type:int default:20 desc:每页数
  128. * @return name:title type:string default:-- desc:标题
  129. * @return name:content type:string default:-- desc:需求
  130. * @return name:cover type:array default:-- desc:封面
  131. * @return name:images type:string default:-- desc:图片【多张|隔开】
  132. * @return name:user_name type:string default:-- desc:名称
  133. * @return name:headimg type:string default:-- desc:头像
  134. * @return name:money type:float default:-- desc:金额
  135. * @return name:is_over type:int default:-- desc:是否解决或开源【0待解决,1已解决,2开源】
  136. * @param name:company type:string default:0 desc:公司名
  137. * @param name:company_logo type:string default:0 desc:公司logo
  138. * @return name:app_name type:string default:-- desc:发布方名称
  139. * @return name:app_logo type:string default:-- desc:发布方头像
  140. * @return name:read_num type:string default:-- desc:阅读量
  141. * @return name:release_time type:string default:-- desc:上架时间
  142. */
  143. public function getDemandList()
  144. {
  145. $title = input('get.title');
  146. $is_tj = input('get.is_tj',0);
  147. $is_over = input('get.is_over',-1);
  148. $sort_type = input('get.sort_type',1);
  149. $sel_where =[];
  150. $sel_where[] = ['d.is_deleted','=',0];
  151. $sel_where[] = ['d.status','=',1];
  152. if($title) $sel_where[] = ['d.title|d.label','like','%'.$title.'%'];
  153. if($is_over > -1) $sel_where[] = ['d.is_over','=',$is_over];
  154. if($title && $this->user_id) UserSearch::saveSearchTitle($this->user_id,$title,5);
  155. $where_str = '';
  156. if($is_tj) {
  157. $search_log = UserSearch::getSearchTitle($this->user_id,5);
  158. $search_arr = [];
  159. foreach ($search_log as $t){
  160. $search_arr[] = " d.title like '".'%'.$t."%'" .' ';
  161. }
  162. if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr);
  163. }
  164. switch ($sort_type) {
  165. case 1:
  166. $order = ['sort'=>'desc','id'=>'asc'];
  167. break;
  168. case 2:
  169. $order = ['id'=>'asc','sort'=>'desc'];
  170. break;
  171. case 3:
  172. $order = ['id'=>'desc','sort'=>'desc'];
  173. break;
  174. }
  175. $list = PlatformDemand::where($sel_where)
  176. ->field('d.*,u.name user_name,u.headimg')
  177. ->alias('d')
  178. ->leftJoin('store_member u','u.id = d.user_id')
  179. ->when($where_str,function ($query)use ($where_str){if($where_str) $query->where($where_str);})
  180. ->order($order)
  181. ->limit($this->off_set,$this->page_num)->select()->toArray();
  182. array_walk($list,function (&$v){
  183. $auth_info = PlatformDemand::getAuth($v['user_id'],APPNAME,APPLOGO);
  184. $v['app_name'] = $auth_info['app_name'];
  185. $v['app_logo'] = $auth_info['app_logo'];
  186. $v['read_num'] = numTransform($v['read_num']);
  187. });
  188. $total_num = PlatformDemand::where($sel_where)->field('d.*,u.name user_name,u.headimg')
  189. ->alias('d')->leftJoin('store_member u','u.id = d.user_id')
  190. ->when($where_str,function ($query)use ($where_str){if($where_str) $query->where($where_str);})->count();
  191. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  192. }
  193. /**
  194. * @title 需求详情【平台】
  195. * @desc 需求详情【平台】
  196. * @author qc
  197. * @method GET
  198. * @url /api/Demand/getDemandInfo
  199. * @header name:Authorization require:1 desc:Token
  200. * @param name:id type:int default:-- desc:平台发布需求id
  201. * @return name:title type:string default:-- desc:标题
  202. * @return name:content type:string default:-- desc:需求
  203. * @return name:cover type:array default:-- desc:封面
  204. * @return name:images type:string default:-- desc:图片【多张|隔开】
  205. * @return name:user_name type:string default:-- desc:名称
  206. * @return name:headimg type:string default:-- desc:头像
  207. * @return name:money type:float default:-- desc:金额
  208. * @return name:is_over type:int default:-- desc:是否解决或开源【0否,1是,2开源】
  209. * @param name:company type:string default:0 desc:公司名
  210. * @param name:company_logo type:string default:0 desc:公司logo
  211. * @return name:praise_num type:int default:-- desc:点赞数量
  212. * @return name:is_praise type:int default:-- desc:是否点赞(0否1是)
  213. * @return name:is_collect type:int default:-- desc:是否收藏(0否1是)
  214. * @return name:collect_num type:int default:-- desc:收藏量
  215. * @return name:comment_num type:int default:-- desc:评论数量
  216. * @return name:link type:string default:-- desc:相关链接
  217. * @return name:datum_id type:int default:-- desc:资料id【系列id】
  218. * @return name:datum_item type:int default:-- desc:资料详情id【url_arr.id】
  219. * @return name:app_name type:string default:-- desc:发布方名称
  220. * @return name:app_logo type:string default:-- desc:发布方头像
  221. * @return name:read_num type:string default:-- desc:阅读量
  222. * @return name:create_at type:string default:-- desc:发布时间
  223. * @return name:transmit_num type:string default:-- desc:转发量
  224. * @return name:switch_open type:int default:-- desc:通知开关【0关闭1开启】
  225. * @return name:comment_switch type:int default:-- desc:评论开关【0关闭1开启】
  226. * @return name:label_name type:array default:-- desc:标签
  227. * @return name:solve_phone type:string default:-- desc:发布方电话
  228. * @return name:solve_email type:string default:-- desc:发布方邮箱
  229. * @return name:release_time type:string default:-- desc:上架时间
  230. * @return name:solve_qrcode type:string default:-- desc:发布方二维码
  231. */
  232. public function getDemandInfo()
  233. {
  234. $detail = PlatformDemand::where('id',input('get.id'))->find();
  235. if(!$detail || $detail->is_deleted == 1 || $detail->status == 0) $this->error('该需求已下架');
  236. $detail = $detail->toArray();
  237. $detail['label_name'] = $detail['label'] ? explode(',',trim($detail['label'],',')) : null;
  238. $detail['praise_num'] = PlatformLike::getPraiseNum($detail['id'],9);
  239. $detail['is_praise'] = PlatformLike::checkTags($this->user_id, $detail['id'], 9);
  240. $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id,10,$detail['id']);
  241. $detail['collect_num'] = UserCollect::getCollectNum(10,$detail['id']);
  242. UserTrack::crateTrack($this->user_id,11,input('get.id'),0);
  243. $detail['read_num'] = numTransform($detail['read_num']);
  244. $auth_info = PlatformDemand::getAuth($detail['user_id'],APPNAME,APPLOGO);
  245. $detail['app_name'] = $auth_info['app_name'];
  246. $detail['app_logo'] = $auth_info['app_logo'];
  247. $detail['switch_open'] = PlatformSwitch::checkSwitch($this->user_id,$detail['id'],12);
  248. $detail['comment_num'] = DemandComment::getCommentNum($detail['id']);
  249. PlatformDemand::where('id',input('get.id'))->setInc('read_num');
  250. if($this->user_id){
  251. TopSearch::seIncHotNum($detail['id'],$this->request->controller());
  252. }
  253. if($this->user_id){
  254. $General = new General();
  255. $General->label($detail['label']);
  256. }
  257. $this->success('ok',['detail'=>$detail]);
  258. }
  259. /**
  260. * @title 获取需求评论列表
  261. * @desc 获取需求评论列表
  262. * @author qc
  263. * @method GET
  264. * @url /api/Demand/getDemandCommentList
  265. * @header name:Authorization require:1 desc:Token
  266. * @param name:id type:int default:-- desc:需求id
  267. * @param name:sort_type type:int default:1 desc:排序规则1时间2热点
  268. * @param name:page type:int default:-- desc:页数
  269. * @return name:name type:string default:-- desc:会员名称
  270. * @return name:headimg type:string default:-- desc:会员头像
  271. * @return name:content type:string default:-- desc:内容
  272. * @return name:create_at type:string default:-- desc:时间
  273. * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
  274. * @return name:parent type:array default:-- desc:评论上一级(数据同上【一维数组】)
  275. * @return name:children type:array default:-- desc:二级评论(数据同上【二维数组】)
  276. * @return name:praise_num type:int default:-- desc:点赞数量
  277. * @return name:is_praise type:int default:-- desc:是否点赞(0否1是)
  278. * @return name:total_num type:int default:-- desc:总评论数(仅一级)
  279. */
  280. public function getDemandCommentList()
  281. {
  282. $where = [];
  283. $where[] = ['c.first_id','=',input('get.id')];
  284. $where[] = ['c.is_deleted','=',0];
  285. $where[] = ['c.type','=',1];
  286. $user_id = $this->user_id;
  287. $sort_type= input('sort_type',1);
  288. switch ($sort_type) {
  289. case 1:
  290. $order = ['c.is_top'=>'desc','c.id'=>'desc','c.like_times'=>'desc'];
  291. break;
  292. case 2:
  293. $order = ['c.is_top'=>'desc','c.like_times'=>'desc','c.id'=>'asc'];
  294. break;
  295. }
  296. $list =DemandComment::where($where)
  297. ->alias('c')
  298. ->field('c.*,u.name,u.headimg')
  299. ->leftJoin('store_member u','u.id = c.user_id')
  300. ->order($order)
  301. ->limit($this->off_set,$this->page_num)
  302. ->select()->toArray();
  303. array_walk($list,function (&$val,$k)use($user_id){
  304. $children = DemandComment::where(['c.pid'=>$val['id'],'c.is_deleted'=>0])
  305. ->alias('c')->field('c.*,u.name,u.headimg')
  306. ->leftJoin('store_member u','u.id = c.user_id')
  307. ->order('c.is_top desc,c.id asc')
  308. ->select()->toArray();
  309. $val['children'] = $children ? $children : null;
  310. $val['praise_num'] = PlatformLike::getPraiseNum($val['id'],6);
  311. $val['is_praise'] = PlatformLike::where(['like_id'=>$val['id'],'user_id'=>$user_id,'type'=>6])->count();
  312. $parent = DemandComment::where(['c.id'=>$val['pid'],'c.is_deleted'=>0])
  313. ->alias('c')->field('c.*,u.name,u.headimg')
  314. ->leftJoin('store_member u','u.id = c.user_id')
  315. ->find();
  316. $val['parent'] = $parent ? $parent->toArray() : null;
  317. $val['parent_comment'] = $val['parent'] ;
  318. });
  319. $total_num = DemandComment::where($where)->alias('c')->count();
  320. $this->success('ok',['list'=>$list,'total_num'=>numTransform($total_num),'total_count'=>$total_num,'page_num'=>$this->page_num]);
  321. }
  322. /**
  323. * @title 需求评论
  324. * @desc 需求评论
  325. * @author qc
  326. * @method POST
  327. * @url /api/Demand/demandComment
  328. * @header name:Authorization require:1 desc:Token
  329. * @param name:id type:int default:1 desc:需求id
  330. * @param name:content type:string default:-- desc:内容
  331. * @return name:name type:string default:-- desc:会员名称
  332. * @return name:headimg type:string default:-- desc:会员头像
  333. * @return name:content type:string default:-- desc:内容
  334. * @return name:create_at type:string default:-- desc:时间
  335. * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
  336. */
  337. public function demandComment()
  338. {
  339. $id = input('post.id');
  340. $content = input('post.content',0);
  341. if(!$content) $this->error('请输入评论内容');
  342. $info = PlatformDemand::where('id',$id)->find();
  343. if(!$info->comment_switch) $this->error('评论功能已关闭');
  344. $send_user =$info->user_id;
  345. $user_info = $this->userInfo('name');
  346. if($send_user && $send_user != $this->user_id) UserMessage:: sendUserMessage($send_user,'demand',4,0,$this->user_id,$id,$content);
  347. $res = DemandComment::create(['user_id'=>$this->user_id,'content'=>$content,'first_id'=>$id,'type'=>1]);
  348. $detail =DemandComment::where('p.id',$res->id)
  349. ->alias('p')
  350. ->field('p.id,p.is_top,p.content,p.create_at,u.name,u.headimg')
  351. ->leftJoin('store_member u','u.id = p.user_id')
  352. ->find()->toArray();
  353. $this->success('评论成功',['detail'=>$detail]);
  354. }
  355. /**
  356. * @title 需求二级评论
  357. * @desc 需求二级评论
  358. * @author qc
  359. * @method POST
  360. * @url /api/Demand/demandSecondComment
  361. * @header name:Authorization require:1 desc:Token
  362. * @param name:id type:int default:1 desc:评论id
  363. * @param name:content type:string default:-- desc:内容
  364. * @return name:name type:string default:-- desc:会员名称
  365. * @return name:headimg type:string default:-- desc:会员头像
  366. * @return name:content type:string default:-- desc:内容
  367. * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
  368. */
  369. public function demandSecondComment()
  370. {
  371. $comment = DemandComment::where('id',input('post.id'))->find()->toArray();
  372. $info = PlatformDemand::where('id',$comment['first_id'])->find();
  373. if(!$info->comment_switch) $this->error('评论功能已关闭');
  374. $user_info = $this->userInfo('name');
  375. if($comment['user_id'] != $this->user_id)UserMessage:: sendUserMessage($comment['user_id'],'demand',3,0,$this->user_id,$comment['id'],input('post.content'));
  376. $send_user =$info->user_id;
  377. //if($send_user && $send_user != $this->user_id) UserMessage::sendUserMessage($send_user,'demand',4,0,$this->user_id,$comment['first_id'],input('post.content'));
  378. unset($comment['id']);
  379. unset($comment['create_at']);
  380. $comment['pid'] = input('post.id');
  381. $comment['user_id'] = $this->user_id;
  382. $comment['content'] = input('post.content');
  383. $comment['lev']++;
  384. if(!$comment['source_id']) $comment['source_id'] = input('post.id');
  385. $res = DemandComment::create($comment);
  386. $detail = DemandComment::where('p.id',$res->id)
  387. ->alias('p')
  388. ->field('p.id,p.is_top,p.content,p.create_at,u.name,u.headimg')
  389. ->leftJoin('store_member u','u.id = p.user_id')
  390. ->find()->toArray();
  391. $this->success('评论成功',['detail'=>$detail]);
  392. }
  393. /**
  394. * @title 需求点赞||取消点赞[需求]
  395. * @desc 评论
  396. * @author qc
  397. * @method POST
  398. * @url /api/Demand/demandTags
  399. * @header name:Authorization require:1 desc:Token
  400. * @param name:demand_id type:int default:1 desc:需求id
  401. * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
  402. */
  403. public function demandTags()
  404. {
  405. $ret_val = PlatformLike::userTags($this->user_id,input('post.demand_id'),9);
  406. $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
  407. }
  408. /**
  409. * @title 评论点赞||取消点赞[评论]
  410. * @desc 评论
  411. * @author qc
  412. * @method POST
  413. * @url /api/Demand/commentTags
  414. * @header name:Authorization require:1 desc:Token
  415. * @param name:comment_id type:int default:1 desc:评论记录id
  416. * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
  417. */
  418. public function commentTags()
  419. {
  420. $ret_val = PlatformLike::userTags($this->user_id,input('post.comment_id'),6);
  421. if($ret_val == 1){
  422. DemandComment::where('id',input('post.comment_id'))->setInc('like_times');
  423. }else{
  424. DemandComment::where('id',input('post.comment_id'))->setDec('like_times');
  425. }
  426. $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
  427. }
  428. /**
  429. * @title 收藏||取消收藏
  430. * @desc 用户收藏
  431. * @author qc
  432. * @method POST
  433. * @url /api/Demand/demandCollect
  434. * @header name:Authorization require:1 desc:Token
  435. * @param name:id type:int require:1 default:-- desc:需求id
  436. * @return name:status type:int default:0 desc:收藏状态(0取消收藏【未收藏】,1收藏)
  437. */
  438. public function demandCollect(){
  439. $coll_status = UserCollect::plateCollect($this->user_id,10,input('post.id',0));
  440. $coll_status ? $this->success('收藏成功',['status'=>1]) : $this->success('取消收藏成功',['status'=>0]);
  441. }
  442. /**
  443. * @title 用户提交||修改需求【用户】
  444. * @desc 用户提交||修改需求
  445. * @author qc
  446. * @method POST
  447. * @url /api/Demand/commitDemand
  448. * @param name:id type:int default:-- desc:修改必传[添加不传,或是null或是空]
  449. * @param name:title type:string default:-- desc:标题
  450. * @param name:content type:string default:1 desc:内容
  451. * @param name:money type:float default:0 desc:价格【设计图没有,可以不传】
  452. * @param name:label type:string default:0 desc:标签【多个逗号隔开】
  453. * @param name:cover type:string default:0 desc:封面【一张】
  454. * @param name:images type:string default:0 desc:图片【多张|隔开】
  455. * @param name:company type:string default:0 desc:公司名
  456. * @param name:company_logo type:string default:0 desc:公司logo
  457. */
  458. /**
  459. * @title 我的发布
  460. * @desc 我的发布
  461. * @author qc
  462. * @method GET
  463. * @url /api/Demand/getMyDemandList
  464. * @header name:Authorization require:1 desc:Token
  465. * @param name:title type:string default:-- desc:标题
  466. * @param name:page type:int default:0 desc:页数
  467. * @param name:page_num type:int default:20 desc:每页数
  468. * @return name:id type:int default:-- desc:需求id
  469. * @return name:title type:string default:-- desc:标题
  470. * @return name:content type:string default:-- desc:需求
  471. * @return name:money type:float default:0 desc:价格【设计图没有,可以不传】
  472. * @return name:cover type:string default:0 desc:封面【一张】
  473. * @return name:is_over type:int default:-1 desc:是否解决或开源【0否,1是,2开源】
  474. * @return name:label_name type:array default:-- desc:标签
  475. */
  476. public function getMyDemandList()
  477. {
  478. $sel_where = [];
  479. $sel_where[] = ['is_deleted','=',0];
  480. $sel_where[] = ['status','=',1];
  481. $sel_where[] = ['user_id','=',$this->user_id];
  482. $title = input('get.title');
  483. if($title) $sel_where[] = ['title|label','like','%'.$title.'%'];
  484. $list = PlatformDemand::where($sel_where)
  485. ->field('id,title,status,cover,money,label,is_over,read_num')
  486. ->order('id desc')
  487. ->limit($this->off_set,$this->page_num)
  488. ->select()->toArray();
  489. foreach ($list as &$lv){
  490. $lv['label_name'] = $lv['label'] ? explode(',',trim($lv['label'],',')) : null;
  491. $lv['is_normal'] = CheckPower::checkModulesPower($lv['id'],0,$this->request->controller());
  492. }
  493. $total_num = PlatformDemand::where($sel_where)->order('id desc')->count();
  494. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  495. }
  496. /**
  497. * @title 我的点赞列表【需求】
  498. * @desc 我的点赞
  499. * @author qc
  500. * @method GET
  501. * @url /api/Demand/getTagsDemand
  502. * @header name:Authorization require:1 desc:Token
  503. * @param name:title type:string default:-- desc:标题
  504. * @param name:page type:int default:-- desc:页数
  505. * @param name:page_num type:int default:-- desc:每页数
  506. *
  507. * @return name:title type:string default:-- desc:标题
  508. * @return name:demand_id type:string default:-- desc:需求id
  509. * @return name:cover type:string default:-- desc:封面
  510. * @return name:content type:string default:-- desc:内容
  511. * @return name:company type:string default:-- desc:公司
  512. * @return name:company_logo type:string default:-- desc:公司logo
  513. * @return name:money type:string default:-- desc:价格
  514. * @return name:is_over type:int default:-1 desc:是否解决或开源【0否,1是,2开源】
  515. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  516. * @return name:app_name type:string default:-- desc:发布方名称
  517. * @return name:app_logo type:string default:-- desc:发布方头像
  518. * @return name:praise_num type:int default:-- desc:点赞数量
  519. * @return name:is_praise type:int default:-- desc:是否点赞(0否1是)
  520. * @return name:is_collect type:int default:-- desc:是否收藏(0否1是)
  521. * @return name:collect_num type:int default:-- desc:收藏量
  522. * @return name:comment_num type:int default:-- desc:评论数量
  523. * @return name:read_num type:string default:-- desc:阅读量
  524. * @return name:transmit_num type:string default:-- desc:转发量
  525. * @return name:create_at type:string default:-- desc:发布时间
  526. * @return name:switch_open type:int default:-- desc:通知开关【0关闭1开启】
  527. * @return name:comment_switch type:int default:-- desc:评论开关【0关闭1开启】
  528. *
  529. */
  530. public function getTagsDemand()
  531. {
  532. $sel_where = [];
  533. $title = input('get.title');
  534. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  535. $sel_where[] = ['t.user_id','=',$this->user_id];
  536. $sel_where[] = ['t.type','=',9];
  537. $list = PlatformLike::where($sel_where)
  538. ->alias('t')
  539. ->field('t.id,t.create_at,i.read_num,i.transmit_num,t.like_id demand_id,i.title,i.cover,i.user_id buid,i.content,company,money,is_over,company_logo,t.user_id,i.comment_switch')
  540. ->leftJoin('PlatformDemand i','t.like_id = i.id')
  541. ->order('i.id desc')
  542. ->limit($this->off_set,$this->page_num)
  543. ->select()->toArray();
  544. array_walk($list,function (&$v){
  545. $v['is_normal'] = CheckPower::checkModulesPower($v['demand_id'],0,$this->request->controller());
  546. $v['praise_num'] = PlatformLike::getPraiseNum($v['demand_id'],9);
  547. $v['is_praise'] = PlatformLike::checkTags($this->user_id, $v['demand_id'], 9);
  548. $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,10,$v['demand_id']);
  549. $v['collect_num'] = UserCollect::getCollectNum(10,$v['demand_id']);
  550. $v['switch_open'] = PlatformSwitch::checkSwitch($this->user_id,$v['demand_id'],12);
  551. $v['comment_num'] = DemandComment::getCommentNum($v['demand_id']);
  552. $v['read_num'] = numTransform($v['read_num']);
  553. $v['transmit_num'] = numTransform($v['transmit_num']);
  554. $auth_info = PlatformDemand::getAuth($v['buid'],APPNAME,APPLOGO);
  555. $v['app_name'] = $auth_info['app_name'];
  556. $v['app_logo'] = $auth_info['app_logo'];
  557. });
  558. $total_num = PlatformLike::where($sel_where)->alias('t')->leftJoin('PlatformDemand i','t.like_id = i.id')->count();
  559. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  560. }
  561. /**
  562. * @title 我的浏览历史【需求】
  563. * @desc 我的浏览历史
  564. * @author qc
  565. * @method GET
  566. * @url /api/Demand/getDemandTrack
  567. * @header name:Authorization require:1 desc:Token
  568. * @param name:title type:string default:-- desc:标题
  569. * @param name:page type:int default:-- desc:页数
  570. * @param name:page_num type:int default:-- desc:每页数
  571. * @return name:title type:string default:-- desc:标题
  572. * @return name:demand_id type:string default:-- desc:需求id
  573. * @return name:cover type:string default:-- desc:封面
  574. * @return name:content type:string default:-- desc:内容
  575. * @return name:company type:string default:-- desc:公司
  576. * @return name:company_logo type:string default:-- desc:公司logo
  577. * @return name:money type:string default:-- desc:价格
  578. * @return name:read_num type:string default:-- desc:阅读量
  579. * @return name:is_over type:int default:-1 desc:是否解决或开源【0否,1是,2开源】
  580. * @return name:time type:string default:-- desc:时间
  581. * @return name:app_name type:string default:-- desc:发布方名称
  582. * @return name:app_logo type:string default:-- desc:发布方头像
  583. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  584. */
  585. public function getDemandTrack()
  586. {
  587. $sel_where = [];
  588. $sel_where[] = ['t.user_id','=',$this->user_id];
  589. $sel_where[] = ['t.type','=',11];
  590. $title = input('get.title');
  591. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  592. $list = UserTrack::where($sel_where)
  593. ->alias('t')
  594. ->field('t.id,t.update_int,t.first_id demand_id,i.title,i.cover,i.content,company,money,is_over,company_logo,i.user_id,i.read_num')
  595. ->leftJoin('PlatformDemand i','t.first_id = i.id')
  596. ->order('update_int desc')
  597. ->limit($this->off_set,$this->page_num)
  598. ->select()->toArray();
  599. foreach ($list as &$v) {
  600. $v['time'] = date("Y-m-d",$v['update_int']);
  601. $v['is_normal'] = CheckPower::checkModulesPower($v['demand_id'],0,$this->request->controller());
  602. $auth_info = PlatformDemand::getAuth($v['user_id'],APPNAME,APPLOGO);
  603. $v['app_name'] = $auth_info['app_name'];
  604. $v['app_logo'] = $auth_info['app_logo'];
  605. $v['read_num'] = numTransform($v['read_num']);
  606. }
  607. $total_num = UserTrack::where($sel_where)->alias('t')->leftJoin('PlatformDemand i','t.first_id = i.id')->count();
  608. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  609. }
  610. /**
  611. * @title 我的收藏【需求】
  612. * @desc 我的收藏
  613. * @author qc
  614. * @method GET
  615. * @url /api/Demand/getCollectDemand
  616. * @header name:Authorization require:1 desc:Token
  617. * @param name:title type:string default:-- desc:标题
  618. * @param name:page type:int default:-- desc:页数
  619. * @param name:page_num type:int default:-- desc:每页数
  620. *
  621. * @return name:title type:string default:-- desc:标题
  622. * @return name:demand_id type:string default:-- desc:需求id
  623. * @return name:cover type:string default:-- desc:封面
  624. * @return name:content type:string default:-- desc:内容
  625. * @return name:money type:string default:-- desc:价格
  626. * @return name:user_id type:string default:-- desc:会员id
  627. * @return name:app_name type:string default:-- desc:发布方名称
  628. * @return name:app_logo type:string default:-- desc:发布方头像
  629. * @return name:is_over type:int default:-1 desc:是否解决或开源【0否,1是,2开源】
  630. * @return name:praise_num type:string default:-- desc:点赞数量
  631. * @return name:is_praise type:string default:-- desc:是否点赞(0否1是)
  632. * @return name:collect_num type:string default:-- desc:收藏量
  633. * @return name:comment_num type:string default:-- desc:评论数量
  634. * @return name:transmit_num type:string default:-- desc:转发量
  635. * @return name:read_num type:string default:-- desc:阅读量
  636. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  637. */
  638. public function getCollectDemand()
  639. {
  640. $sel_where = [];
  641. $title = input('get.title');
  642. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  643. $sel_where[] = ['t.user_id','=',$this->user_id];
  644. $sel_where[] = ['t.coll_type','=',10];
  645. $list = UserCollect::where($sel_where)
  646. ->alias('t')
  647. ->field('t.id,t.create_at,t.coll_id demand_id,i.title,i.cover,i.content,company,money,is_over,company_logo,i.user_id,i.transmit_num,i.read_num')
  648. ->leftJoin('PlatformDemand i','t.coll_id = i.id')
  649. ->order('id desc')
  650. ->limit($this->off_set,$this->page_num)
  651. ->select()->toArray();
  652. array_walk($list,function (&$v){
  653. $v['read_num'] = numTransform($v['read_num']);
  654. $v['is_normal'] = CheckPower::checkModulesPower($v['demand_id'],0,$this->request->controller());
  655. $auth_info = PlatformDemand::getAuth($v['user_id'],APPNAME,APPLOGO);
  656. $v['app_name'] = $auth_info['app_name'];
  657. $v['app_logo'] = $auth_info['app_logo'];
  658. $v['praise_num'] = PlatformLike::getPraiseNum($v['demand_id'],9);
  659. $v['is_praise'] = PlatformLike::checkTags($this->user_id, $v['demand_id'], 9);
  660. $v['collect_num'] = UserCollect::getCollectNum(10,$v['demand_id']);
  661. $v['switch_open'] = PlatformSwitch::checkSwitch($this->user_id,$v['demand_id'],12);
  662. $v['comment_num'] = DemandComment::getCommentNum($v['demand_id']);
  663. });
  664. $total_num = UserCollect::where($sel_where)->alias('t') ->leftJoin('PlatformDemand i','t.coll_id = i.id')->count();
  665. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  666. }
  667. /**
  668. * @title 我的评论
  669. * @desc 我的评论
  670. * @author qc
  671. * @method GET
  672. * @url /api/Demand/getMyDemandComment
  673. * @header name:Authorization require:1 desc:Token
  674. * @param name:title type:string default:-- desc:标题
  675. * @param name:page type:int default:-- desc:页数
  676. * @param name:page_num type:int default:-- desc:每页数
  677. *
  678. * @return name:title type:string default:-- desc:标题
  679. * @return name:demand_id type:string default:-- desc:需求id
  680. * @return name:content type:string default:-- desc:评论内容
  681. * @return name:cover type:string default:-- desc:封面
  682. * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
  683. * @return name:create_at type:string default:-- desc:时间
  684. * @return name:user_name type:string default:-- desc:用户名【用户自己的】
  685. * @return name:headimg type:string default:-- desc:用户头像【用户自己的】
  686. * @return name:app_name type:string default:-- desc:发布方名称
  687. * @return name:app_logo type:string default:-- desc:发布方头像
  688. * @return name:read_num type:string default:-- desc:阅读量
  689. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  690. */
  691. public function getMyDemandComment()
  692. {
  693. $title = input('get.title');
  694. $where = [];
  695. $where[] = ['t.is_deleted','=',0];
  696. $where[] = ['t.type','=',1];
  697. $where[] = ['t.user_id','=',$this->user_id];
  698. $where[] = ['t.pid','=',0];
  699. if($title) $where[] = ['i.title|i.label|t.content','like','%'.$title.'%'];
  700. $list = DemandComment::where($where)
  701. ->alias('t')
  702. ->field('t.id,t.is_top,t.create_at,t.first_id demand_id,i.is_over,t.content,i.title,i.cover,i.user_id,u.name user_name,u.headimg,i.read_num')
  703. ->leftJoin('PlatformDemand i','t.first_id = i.id')
  704. ->leftJoin('store_member u','u.id = t.user_id')
  705. ->order('t.is_top desc , id desc')
  706. ->limit($this->off_set,$this->page_num)
  707. ->select()->toArray();
  708. array_walk($list,function (&$v){
  709. $v['is_normal'] = CheckPower::checkModulesPower($v['demand_id'],0,$this->request->controller());
  710. $v['read_num'] = numTransform($v['read_num']);
  711. $auth_info = PlatformDemand::getAuth($v['user_id'],APPNAME,APPLOGO);
  712. $v['app_name'] = $auth_info['app_name'];
  713. $v['app_logo'] = $auth_info['app_logo'];
  714. });
  715. $total_num = DemandComment::where($where)
  716. ->alias('t')->leftJoin('PlatformDemand i','t.first_id = i.id')
  717. ->leftJoin('store_member u','u.id = t.user_id')->count();
  718. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  719. }
  720. /**
  721. * @title 获取角标数量
  722. * @desc 获取角标数量
  723. * @author qc
  724. * @method GET
  725. * @url /api/Demand/getMarkNum
  726. * @header name:Authorization require:1 desc:Token
  727. * @return name:comment_num type:int default:-- desc:评论我的
  728. * @return name:reply_num type:int default:-- desc:回复我的
  729. * @return name:praise_demand type:int default:-- desc:点赞我的--需求
  730. * @return name:praise_num type:int default:-- desc:点赞我的--评论
  731. * @return name:praise_comment type:int default:-- desc:点赞我的--需求+评论
  732. * @return name:total_num type:int default:-- desc:总数【comment_num+reply_num】
  733. */
  734. public function getMarkNum()
  735. {
  736. // 评论我的
  737. $comment_num = DemandComment::where([['t.is_deleted','=',0],['t.user_id','<>',$this->user_id],['t.pid','=',0],['i.user_id','=',$this->user_id],['is_read','=',0]])
  738. ->leftJoin('PlatformDemand i','t.first_id = i.id')
  739. ->alias('t')->count();
  740. // 回复我的
  741. $all_comment = DemandComment::where(['user_id'=>$this->user_id,'is_deleted'=>0])->column('id');
  742. $reply_num = DemandComment::where([['t.is_deleted','=',0],['t.lev','>=',2],['is_read','=',0],['t.pid','in',implode(',',$all_comment)]])->alias('t')->count();
  743. $total_num = $comment_num + $reply_num ;
  744. $praise_demand = PlatformLike::where([['p.type', '=', 9],['f.user_id', '=', $this->user_id],['p.to_deleted', '=', 0],['p.is_read','=',0],['p.user_id','<>',$this->user_id]])->alias('p') ->leftJoin('PlatformDemand f', 'f.id = p.like_id')->count();
  745. $praise_comment = PlatformLike::where([['p.type', '=', 6],['c.user_id', '=', $this->user_id],['p.to_deleted', '=', 0],['p.is_read','=',0],['p.user_id','<>',$this->user_id]])->alias('p')->leftJoin('DemandComment c', 'c.id = p.like_id')->count();
  746. $praise_num = $praise_demand + $praise_comment;
  747. $this->success('ok',compact(['comment_num','reply_num','total_num','praise_num','praise_comment','praise_demand']));
  748. }
  749. /**
  750. * @title 消息已读
  751. * @desc 消息已读
  752. * @author qc
  753. * @method POST
  754. * @url /api/Demand/unreadChange
  755. * @header name:Authorization require:1 desc:Token
  756. * @param name:id type:string default:-- desc:记录id(多个逗号隔开,不传修改全部])
  757. * @param name:type type:string default:1 desc:消息类型【1评论我的,2回复我的,3点赞我的--需求,4点赞我的--评论】
  758. * @param name:is_read type:int default:1 desc:变更类型【0消息变更为未读,1变更为已读】
  759. */
  760. public function unreadChange()
  761. {
  762. $type = input('post.type',1);
  763. $id = input('post.id');
  764. $is_read = input('post.is_read');
  765. switch ($type) {
  766. case 1:
  767. DemandComment::where([['i.user_id','=',$this->user_id]])
  768. ->when($id ,function ($query)use ($id){
  769. if($id) return $query->where('t.id','in',$id);
  770. })->leftJoin('PlatformDemand i','t.first_id = i.id')
  771. ->alias('t') ->update(['source_read'=>$is_read,'is_read'=>$is_read]);
  772. break;
  773. case 2:
  774. $all_comment = DemandComment::where(['user_id'=>$this->user_id,'is_deleted'=>0])->column('id');
  775. DemandComment::where([['t.pid','in',implode(',',$all_comment)]])
  776. ->when($id ,function ($query)use ($id){
  777. if($id) return $query->where('t.id','in',$id);
  778. })->alias('t')->update(['is_read'=>$is_read]);
  779. break;
  780. case 3:
  781. $ids = PlatformLike::where([['p.type', '=', 9],['f.user_id', '=', $this->user_id],['p.to_deleted', '=', 0],['p.is_read','=',0],['p.user_id','<>',$this->user_id]])->alias('p')->leftJoin('PlatformDemand f', 'f.id = p.like_id')->column('p.id');
  782. PlatformLike::where('id','in' ,$ids )->update(['is_read'=>1]);
  783. break;
  784. case 4:
  785. $ids2 = PlatformLike::where([['p.type', '=', 6],['c.user_id', '=', $this->user_id],['p.to_deleted', '=', 0],['p.is_read','=',0],['p.user_id','<>',$this->user_id]])->alias('p')->leftJoin('DemandComment c', 'c.id = p.like_id')->column('p.id');
  786. PlatformLike::where('id','in' , $ids2)->update(['is_read'=>1]);
  787. break;
  788. }
  789. $this->success('消息变更成功');
  790. }
  791. /**
  792. * @title 评论我的
  793. * @desc 评论我的
  794. * @author qc
  795. * @method GET
  796. * @url /api/Demand/commentMyDemand
  797. * @header name:Authorization require:1 desc:Token
  798. * @param name:title type:string default:-- desc:标题
  799. * @param name:page type:int default:-- desc:页数
  800. * @param name:page_num type:int default:-- desc:每页数
  801. *
  802. * @return name:title type:string default:-- desc:标题
  803. * @return name:demand_id type:string default:-- desc:需求id
  804. * @return name:cover type:string default:-- desc:封面
  805. * @return name:content type:string default:-- desc:评论内容
  806. * @return name:is_read type:int default:-- desc:是否已读(0未读1已读)
  807. * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
  808. * @return name:demand_content type:string default:-- desc:需求内容【简介】
  809. * @return name:create_at type:string default:-- desc:时间
  810. * @return name:user_name type:string default:-- desc:用户名
  811. * @return name:headimg type:string default:-- desc:用户头像
  812. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  813. * @return name:is_over type:int default:-- desc:是否解决或开源【0待解决,1已解决,2开源】
  814. * @return name:app_name type:string default:-- desc:发布方名称
  815. * @return name:app_logo type:string default:-- desc:发布方头像
  816. */
  817. public function commentMyDemand()
  818. {
  819. $sel_where = [];
  820. $title = input('get.title');
  821. if($title) $sel_where[] = ['i.title|i.label|t.content','like','%'.$title.'%'];
  822. $sel_where[] = ['t.is_deleted','=',0];
  823. $sel_where[] = ['t.to_deleted','=',0];
  824. $sel_where[] = ['i.user_id','=',$this->user_id];
  825. $sel_where[] = ['t.user_id','<>',$this->user_id];
  826. $sel_where[] = ['t.pid','=',0];
  827. $list = DemandComment::where($sel_where)
  828. ->alias('t')
  829. ->field('t.id,t.is_top,t.create_at,t.is_read,i.is_over,i.read_num,i.user_id,t.first_id demand_id,t.content,i.title,i.cover,i.content demand_content,u.name user_name,u.headimg')
  830. ->leftJoin('PlatformDemand i','t.first_id = i.id')
  831. ->leftJoin('store_member u','t.user_id = u.id')
  832. ->order('t.is_top,t.id desc')
  833. ->limit($this->off_set,$this->page_num)
  834. ->select()->toArray();
  835. array_walk($list,function (&$v){
  836. $v['is_normal'] = CheckPower::checkModulesPower($v['demand_id'],0,$this->request->controller());
  837. $v['read_num'] = numTransform($v['read_num']);
  838. $auth_info = PlatformDemand::getAuth($v['user_id'],APPNAME,APPLOGO);
  839. $v['app_name'] = $auth_info['app_name'];
  840. $v['app_logo'] = $auth_info['app_logo'];
  841. });
  842. $total_num = DemandComment::where($sel_where)->alias('t') ->leftJoin('PlatformDemand i','t.first_id = i.id')->leftJoin('store_member u','t.user_id = u.id')->count();
  843. $this->success('ok',['list'=>$list,'user_id'=>$this->user_id,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  844. }
  845. /**
  846. * @title 点赞我的--需求
  847. * @desc 点赞我的--需求
  848. * @author qc
  849. * @method GET
  850. * @url /api/Demand/praiseMyDemand
  851. * @header name:Authorization require:1 desc:Token
  852. * @param name:page type:int default:-- desc:页数
  853. * @param name:page_num type:int default:-- desc:每页数
  854. * @return name:id type:int default:-- desc:记录id
  855. * @return name:title type:string default:-- desc:标题
  856. * @return name:create_at type:string default:-- desc:时间
  857. * @return name:cover type:string default:-- desc:封面
  858. * @return name:read_num type:int default:-- desc:阅读量
  859. * @return name:is_over type:int default:-- desc:是否解决或开源【0待解决,1已解决,2开源】
  860. * @return name:user_name type:string default:-- desc:会员名称
  861. * @return name:headimg type:string default:-- desc:会员头像
  862. * @return name:content type:string default:-- desc:详情
  863. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  864. * @return name:app_name type:string default:-- desc:发布方名称
  865. * @return name:app_logo type:string default:-- desc:发布方头像
  866. */
  867. public function praiseMyDemand()
  868. {
  869. $user_info = $this->userInfo('name,headimg');
  870. $sel_where = [];
  871. $sel_where[] = ['p.type', '=', 9];
  872. $sel_where[] = ['f.user_id', '=', $this->user_id];
  873. $sel_where[] = ['p.to_deleted', '=', 0];
  874. $list = PlatformLike::where($sel_where)
  875. ->field('p.*,f.title,u.name user_name,u.headimg,f.images,f.read_num,f.content,f.is_over,f.cover')
  876. ->alias('p')
  877. ->leftJoin('PlatformDemand f', 'f.id = p.like_id')
  878. ->leftJoin('StoreMember u', 'u.id = p.user_id')
  879. ->limit($this->off_set,$this->page_num)
  880. ->select()->toArray();
  881. array_walk($list, function (&$v) use ($user_info){
  882. $v['is_normal'] = CheckPower::checkModulesPower($v['like_id'], 0, $this->request->controller());
  883. $v['app_name'] = $user_info['name'];
  884. $v['app_logo'] = $user_info['headimg'];
  885. $v['read_num'] = numTransform($v['read_num']);
  886. });
  887. $total_num = PlatformLike::where($sel_where)->alias('p')->leftJoin('PlatformDemand f', 'f.id = p.like_id')->leftJoin('StoreMember u', 'u.id = p.user_id')->count();
  888. $this->success('ok', ['list' => $list, 'total_count' => $total_num, 'page_num' => $this->page_num]);
  889. }
  890. /**
  891. * @title 点赞我的--评论
  892. * @desc 点赞我的
  893. * @author qc
  894. * @method GET
  895. * @url /api/Demand/praiseCommentList
  896. * @header name:Authorization require:1 desc:Token
  897. * @param name:page type:int default:-- desc:页数
  898. * @param name:page_num type:int default:-- desc:每页数
  899. * @return name:id type:int default:-- desc:记录id
  900. * @return name:demand_id type:int default:-- desc:需求id
  901. * @return name:title type:string default:-- desc:需求标题
  902. * @return name:create_at type:string default:-- desc:时间
  903. * @return name:user_name type:string default:-- desc:会员名称【点赞人的】
  904. * @return name:headimg type:string default:-- desc:会员头像【点赞人的】
  905. * @return name:self_name type:string default:-- desc:用户名称【自己的】
  906. * @return name:content type:string default:-- desc:评论内容
  907. * @return name:is_over type:int default:-- desc:是否解决或开源【0待解决,1已解决,2开源】
  908. * @return name:demand_content type:string default:-- desc:需求内容
  909. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  910. * @return name:app_name type:string default:-- desc:发布方名称
  911. * @return name:app_logo type:string default:-- desc:发布方头像
  912. * @return name:read_num type:int default:-- desc:阅读量
  913. * @return name:images type:string default:-- desc:图片多张|隔开
  914. * @return name:images_arr type:array default:-- desc:图片多张[数组]
  915. * @return name:comment_normal type:int default:-- desc:评论是否正常
  916. */
  917. public function praiseCommentList()
  918. {
  919. $user_info = $this->userInfo('name,headimg');
  920. $list = PlatformLike::where([['l.type','=',6],['c.user_id','=',$this->user_id],['l.to_deleted','=',0]])
  921. ->alias('l')
  922. ->field('l.id,l.user_id,m.name user_name,m.headimg,c.is_deleted,c.to_deleted,c.source_deleted,l.create_at,v.images,c.first_id demand_id,v.user_id buid,v.title,v.read_num,c.content,v.content demand_content,v.comment_switch,v.is_over,v.cover')
  923. ->leftJoin('StoreMember m','m.id = l.user_id')
  924. ->leftJoin('DemandComment c','c.id = l.like_id')
  925. ->leftJoin('PlatformDemand v','v.id = c.first_id')
  926. ->order('l.id desc')
  927. ->limit($this->off_set,$this->page_num)
  928. ->select()->toArray();
  929. array_walk($list,function (&$v,$k)use ($user_info){
  930. $info_auth = PlatformDemand::getAuth($v['buid'],APPNAME,APPLOGO);
  931. $v['app_name'] = $info_auth['app_name'];
  932. $v['app_logo'] = $info_auth['app_logo'];
  933. $v['is_normal'] = CheckPower::checkModulesPower($v['demand_id'],0,$this->request->controller());
  934. $v['read_num'] = numTransform($v['read_num']);
  935. $v['self_name'] = $user_info['name'];
  936. $v['comment_normal'] = $v['to_deleted'] || $v['is_deleted'] || $v['source_deleted'] ? 0 : 1;
  937. });
  938. $total_num = PlatformLike::where([['l.type','=',6],['c.user_id','=',$this->user_id],['l.to_deleted','=',0]])->alias('l')
  939. ->leftJoin('StoreMember m','m.id = l.user_id')
  940. ->leftJoin('DemandComment c','c.id = l.like_id')
  941. ->leftJoin('PlatformDemand v','v.id = c.first_id')->count();
  942. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  943. }
  944. /**
  945. * @title 批量删除||批量取消
  946. * @desc 删除||取消
  947. * @author qc
  948. * @method POST
  949. * @url /api/Demand/batchesDel
  950. * @header name:Authorization require:1 desc:Token
  951. * @param name:id type:string default:1 desc:记录id【多个用逗号隔开=>'1,2'】
  952. * @param name:type type:string default:1 desc:消息类型【1点赞我的,2我的评论,3回复我的,4评论我的,5我的点赞,6我的收藏,7我的回复】
  953. */
  954. public function batchesDel()
  955. {
  956. $type = input('post.type',1);
  957. $id = input('post.id');
  958. if(!$id) $this->error('请选择要删除的记录');
  959. $del_where = [];
  960. $del_where[] = ['id','in',$id];
  961. if(in_array($type,[1])) PlatformLike::where($del_where)->update(['to_deleted'=>1,'is_read'=>1]);
  962. if(in_array($type,[2])) DemandComment::where($del_where)->where(['user_id'=>$this->user_id])->update(['is_deleted'=>1]);
  963. if(in_array($type,[3,4])) DemandComment::where($del_where)->update(['to_deleted'=>1,'is_read'=>1]);
  964. if(in_array($type,[5])) PlatformLike::where($del_where)->where('user_id',$this->user_id)->delete();
  965. if(in_array($type,[6])) UserCollect::where($del_where)->where('user_id',$this->user_id)->where('coll_type',10)->delete();
  966. if(in_array($type,[7])) DemandComment::where($del_where)->where('user_id',$this->user_id)->update(['source_deleted'=>1]);
  967. $this->success('删除成功');
  968. }
  969. /**
  970. * @title 回复我的【回复我的--回复过我的评论】
  971. * @desc 回复我的
  972. * @author qc
  973. * @method GET
  974. * @url /api/Demand/getReplyComment
  975. * @header name:Authorization require:1 desc:Token
  976. * @param name:title type:string default:-- desc:标题
  977. * @param name:page type:int default:0 desc:页数
  978. * @param name:page_num type:int default:20 desc:每页数
  979. * @return name:title type:string default:-- desc:标题
  980. * @return name:cover type:string default:-- desc:封面
  981. * @return name:is_read type:int default:-- desc:是否已读(0未读1已读)
  982. * @return name:create_at type:string default:-- desc:时间
  983. * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
  984. * @return name:self_name type:string default:-- desc:用户名称【自己的】
  985. * @return name:user_name type:string default:-- desc:用户名【其他会员】
  986. * @return name:headimg type:string default:-- desc:用户头【其他会员】
  987. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  988. * @return name:parent_comment type:array default:-- desc:你的评论内容【别人回复的那个评论】
  989. * @return name:parent_comment.content type:string default:-- desc:内容
  990. * @return name:parent_comment.name type:string default:-- desc:会员名称
  991. * @return name:parent_comment.title type:string default:-- desc:标题
  992. * @return name:parent_comment.demand_id type:string default:-- desc:需求id
  993. * @return name:parent_comment.app_name type:string default:-- desc:发布方名称
  994. * @return name:parent_comment.app_logo type:string default:-- desc:发布方头像
  995. * @return name:parent_comment.read_num type:string default:-- desc:阅读量
  996. * @return name:parent_comment.is_over type:int default:-- desc:是否解决或开源【0待解决,1已解决,2开源】
  997. */
  998. public function getReplyComment()
  999. {
  1000. $all_comment = DemandComment::where(['user_id'=>$this->user_id,'is_deleted'=>0])->column('id');
  1001. if(empty($all_comment)) $this->success('ok',['list'=>null,'total_count'=>0,'page_num'=>$this->page_num]);
  1002. $sel_where = [];
  1003. $title = input('get.title');
  1004. if($title) $sel_where[] = ['i.title|i.label|t.content','like','%'.$title.'%'];
  1005. $sel_where[] = ['t.is_deleted','=',0];
  1006. $sel_where[] = ['t.lev','>=',2];
  1007. $sel_where[] = ['t.to_deleted','=',0];
  1008. $sel_where[] = ['t.user_id','<>',$this->user_id];
  1009. $sel_where[] = ['t.pid','in',implode(',',$all_comment)];
  1010. $list = DemandComment::where($sel_where)
  1011. ->alias('t')
  1012. ->field('t.id,t.is_top,t.is_read,t.create_at,t.first_id demand_id,t.lev,t.content,t.pid,u.name user_name,u.headimg,i.cover,i.images,i.read_num')
  1013. ->leftJoin('store_member u','t.user_id = u.id')
  1014. ->leftJoin('PlatformDemand i','t.first_id = i.id')
  1015. ->order('t.is_top desc,t.id desc')
  1016. ->limit($this->off_set,$this->page_num)
  1017. ->select()->toArray();
  1018. foreach ($list as &$v) {
  1019. $v['self_name'] = $this->user_info['name'];
  1020. $v['is_normal'] = CheckPower::checkModulesPower($v['demand_id'],0,$this->request->controller());
  1021. $parent_comment = DemandComment::where([['t.id','=',$v['pid']]])
  1022. ->field('t.id,t.first_id demand_id,t.is_top,t.content,i.title,i.is_over,i.cover,t.pid,u.name,i.user_id,i.read_num')
  1023. ->alias('t')
  1024. ->leftJoin('PlatformDemand i','t.first_id = i.id')
  1025. ->leftJoin('store_member u','t.user_id = u.id')
  1026. ->find()->toArray();
  1027. $v['images_arr'] = $v['images'] ? explode('|', $v['images']) : null;
  1028. $parent_comment['images_arr'] =$v['images_arr'];
  1029. $parent_comment['read_num'] = numTransform($v['read_num']);
  1030. $info_auth = PlatformDemand::getAuth($parent_comment['user_id'],APPNAME,APPLOGO);
  1031. $parent_comment['app_name'] = $info_auth['app_name'];
  1032. $parent_comment['app_logo'] = $info_auth['app_logo'];
  1033. $v['parent_comment'] = $parent_comment;
  1034. }
  1035. $total_num = DemandComment::where($sel_where)->alias('t')->leftJoin('store_member u','t.user_id = u.id')->leftJoin('PlatformDemand i','t.first_id = i.id')->count();
  1036. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1037. }
  1038. /**
  1039. * @title 需求转发(转发数量统计)
  1040. * @desc 转发成功后调用
  1041. * @author qc
  1042. * @method POST
  1043. * @url /api/Demand/demandTransmit
  1044. * @header name:Authorization require:1 desc:Token
  1045. * @param name:id type:int default:-- desc:需求id
  1046. */
  1047. public function demandTransmit()
  1048. {
  1049. $demand_id = input('post.id',0);
  1050. PlatformDemand::where('id',$demand_id)->setInc('transmit_num');
  1051. $this->success('ok');
  1052. }
  1053. /**
  1054. * @title 我的点赞--评论
  1055. * @desc 评论点赞列表
  1056. * @author qc
  1057. * @method GET
  1058. * @url /api/Demand/getTagsComment
  1059. * @header name:Authorization require:1 desc:Token
  1060. * @param name:page type:int default:0 desc:页数
  1061. * @param name:page_num type:int default:20 desc:每页数
  1062. * @return name:create_at type:string default:-- desc:时间
  1063. * @return name:self_name type:string default:-- desc:会员名称【自己的】
  1064. * @return name:self_headimg type:string default:-- desc:会员头像【自己的】
  1065. * @return name:comment_user type:string default:-- desc:会员名称【评论人】
  1066. * @return name:content type:string default:-- desc:评论内容
  1067. * @return name:cover type:string default:-- desc:封面
  1068. * @return name:title type:string default:-- desc:标题
  1069. * @return name:read_num type:string default:-- desc:浏览量
  1070. * @return name:like_id type:int default:-- desc:评论的id
  1071. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  1072. * @return name:app_name type:string default:-- desc:发布方名称
  1073. * @return name:app_logo type:string default:-- desc:发布方头像
  1074. */
  1075. public function getTagsComment()
  1076. {
  1077. $list = PlatformLike::field('l.id,l.like_id,c.content,g.read_num,g.cover,u.name comment_user,g.is_over,g.user_id,l.create_at,g.title,g.id demand_id,c.user_id cuid')
  1078. ->alias('l')
  1079. ->where(['l.user_id'=>$this->user_id,'l.type'=>6])
  1080. ->where('c.user_id','<>',$this->user_id)
  1081. ->leftJoin('DemandComment c','l.like_id = c.id')
  1082. ->leftJoin('PlatformDemand g','g.id = c.first_id')
  1083. ->leftJoin('store_member u','u.id = c.user_id')
  1084. ->order('l.id desc')
  1085. ->limit($this->off_set,$this->page_num)
  1086. ->select()->toArray();
  1087. $user_info = $this->userInfo();
  1088. foreach ($list as &$v) {
  1089. $v['is_normal'] = CheckPower::checkModulesPower($v['demand_id'],0,$this->request->controller());
  1090. $auth_info = PlatformDemand::getAuth($v['user_id'],APPNAME,APPLOGO);
  1091. $user_infos = User::where('id',$v['cuid'])->field('name,headimg')->find();
  1092. $v['app_name'] = $auth_info['app_name'];
  1093. $v['app_logo'] = $auth_info['app_logo'];
  1094. $v['read_num'] = numTransform($v['read_num']);
  1095. // 把self_headimg和self_name 删掉,
  1096. // 返回评论人的headimg和
  1097. $v['user_name'] = $user_infos['name'];
  1098. $v['headimg'] = $user_infos['headimg'];
  1099. }
  1100. $total_num = PlatformLike::where(['l.user_id'=>$this->user_id,'l.type'=>6])
  1101. ->alias('l')
  1102. ->where('c.user_id','<>',$this->user_id)
  1103. ->leftJoin('DemandComment c','l.like_id = c.id')
  1104. ->leftJoin('PlatformDemand g','g.id = c.first_id')
  1105. ->leftJoin('store_member u','u.id = c.user_id')->count();
  1106. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1107. }
  1108. /**
  1109. * @title 我的回复【我的回复--我回复过的评论】
  1110. * @desc 我的回复
  1111. * @author qc
  1112. * @method GET
  1113. * @url /api/Demand/getReplyDemand
  1114. * @header name:Authorization require:1 desc:Token
  1115. * @param name:title type:string default:-- desc:标题
  1116. * @param name:page type:int default:0 desc:页数
  1117. * @param name:page_num type:int default:20 desc:每页数
  1118. * @return name:title type:string default:-- desc:标题
  1119. * @return name:demand_id type:int default:-- desc:需求id
  1120. * @return name:cover type:string default:-- desc:封面
  1121. * @return name:create_at type:string default:-- desc:时间
  1122. * @return name:is_over type:int default:-- desc:是否解决或开源【0否,1是,2开源】
  1123. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  1124. * @return name:user_name type:string default:-- desc:用户名【用户自己的】
  1125. * @return name:headimg type:string default:-- desc:用户头像【用户自己的】
  1126. * @return name:parent_comment type:array default:-- desc:上级评论内容【你评论的那个评论】
  1127. * @return name:parent_comment.content type:string default:-- desc:内容
  1128. * @return name:parent_comment.name type:string default:-- desc:会员名称
  1129. * @return name:parent_comment.title type:string default:-- desc:标题
  1130. * @return name:parent_comment.demand_id type:string default:-- desc:需求id
  1131. * @return name:parent_comment.app_name type:string default:-- desc:发布方名称
  1132. * @return name:parent_comment.app_logo type:string default:-- desc:发布方头像
  1133. * @return name:parent_comment.read_num type:string default:-- desc:阅读量
  1134. * @return name:parent_comment.is_over type:int default:-- desc:是否解决或开源【0否,1是,2开源】
  1135. */
  1136. public function getReplyDemand()
  1137. {
  1138. $user_info = $this->userInfo();
  1139. $sel_where = [];
  1140. $title = input('get.title');
  1141. if($title) $sel_where[] = ['i.title|i.label|t.content','like','%'.$title.'%'];
  1142. $sel_where[] = ['t.user_id','=',$this->user_id];
  1143. $sel_where[] = ['t.is_deleted','=',0];
  1144. $sel_where[] = ['t.source_deleted','=',0];
  1145. $sel_where[] = ['t.lev','>=',2];
  1146. $sel_where[] = ['t.pid','>',0];
  1147. $list = DemandComment::where($sel_where)
  1148. ->alias('t')
  1149. ->field('t.id,t.is_top,t.create_at,t.first_id demand_id,t.lev,t.content,t.pid,i.title,i.cover,read_num,i.is_over')
  1150. ->leftJoin('PlatformDemand i','t.first_id = i.id')
  1151. ->order('t.is_top,t.id desc')
  1152. ->limit($this->off_set,$this->page_num)
  1153. ->select()->toArray();
  1154. foreach ($list as &$v) {
  1155. $v['user_name'] = $user_info['name'];
  1156. $v['headimg'] = $user_info['headimg'];
  1157. $v['is_normal'] = CheckPower::checkModulesPower($v['demand_id'],0,$this->request->controller());
  1158. $parent_comment = DemandComment::where([['t.id','=',$v['pid']]])
  1159. ->field('t.id,t.is_top,t.first_id demand_id,t.content,i.title,i.cover,t.pid,u.name,i.read_num,i.user_id,i.is_over')->alias('t')
  1160. ->leftJoin('PlatformDemand i','t.first_id = i.id')
  1161. ->leftJoin('store_member u','t.user_id = u.id')
  1162. ->find()->toArray();
  1163. $parent_comment['read_num'] = numTransform($v['read_num']);
  1164. $info_auth = PlatformDemand::getAuth($parent_comment['user_id'],APPNAME,APPLOGO);
  1165. $parent_comment['app_name'] = $info_auth['app_name'];
  1166. $parent_comment['app_logo'] = $info_auth['app_logo'];
  1167. $v['parent_comment'] = $parent_comment;
  1168. }
  1169. $total_num = DemandComment::where($sel_where)->alias('t') ->leftJoin('PlatformDemand i','t.first_id = i.id')->count();
  1170. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1171. }
  1172. }