Message.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\GoodsOrder;
  4. use app\common\model\StoreGoodsItem;
  5. use app\common\model\UserMessage;
  6. use library\tools\Data;
  7. use think\Db;
  8. /**
  9. * @title 消息管理
  10. * @controller Message
  11. * @group base
  12. */
  13. class Message extends Base
  14. {
  15. public function initialize()
  16. {
  17. parent::initialize();
  18. parent::checkLogin();
  19. }
  20. /**
  21. * @title 获取视频平台消息
  22. * @desc 获取视频平台消息
  23. * @author qc
  24. * @url /api/Message/getVideoPlatformNews
  25. * @method GET
  26. * @return name:content type:string default:-- desc:标题
  27. * @return name:is_read type:string default:-- desc:是否已读(0否)
  28. */
  29. public function getVideoPlatformNews()
  30. {
  31. $video = PlatformMessage::where(['type'=>1])->order('id desc')->find();
  32. if(!$video)$this->success('ok',['detail'=>['content'=>'','is_read'=>0]]);
  33. $detail = $video->toArray();
  34. $detail['is_read'] = PlatformReadLog::where(['user_id'=>$this->user_id,'type'=>1,'relation_id'=>$detail['id']])->count();
  35. $this->success('ok',['detail'=>$detail]);
  36. }
  37. /**
  38. * @title 获取交易物流消息(菜单)
  39. * @desc 获取交易物流消息
  40. * @author qc
  41. * @url /api/Message/getExpressMessageMenu
  42. * @method GET
  43. * @header name:Authorization require:1 desc:Token
  44. * @return name:create_at type:string default:-- desc:时间
  45. * @return name:content type:string default:-- desc:内容
  46. * @return name:is_read type:int default:-- desc:是否已读(0否)
  47. */
  48. public function getExpressMessageMenu()
  49. {
  50. $where[] = ['user_id','=',$this->user_id];
  51. $where[] = ['type_id','in','2,3'];
  52. $detail = UserMessage::where($where)->order('id desc')->find();
  53. $this->success('ok',['detail'=>$detail ? $detail->toArray():['content'=>'','is_read'=>0]]);
  54. }
  55. /**
  56. * @title 获取交易物流消息(内页列表)
  57. * @desc 获取交易物流消息(内页列表)
  58. * @author qc
  59. * @url /api/Message/getExpressMessageList
  60. * @method GET
  61. * @header name:Authorization require:1 desc:Token
  62. * @param name:page type:int default:1 desc:页数
  63. * @param name:page_num type:int default:20 desc:每页数
  64. * @return name:create_at type:string default:-- desc:时间
  65. * @return name:content type:string default:-- desc:内容
  66. * @return name:type_id type:int default:-- desc:类型[2发货通知,3收货通知]
  67. * @return name:order_info type:array default:-- desc:订单信息
  68. * @return name:order_info.id type:int default:-- desc:订单id
  69. * @return name:order_info.express_send_no type:string default:-- desc:发货单号
  70. * @return name:order_info.order_no type:string default:-- desc:订单号
  71. * @return name:goods_list type:array default:-- desc:商品列表
  72. * @return name:goods_list.goods_name type:string default:-- desc:商品名
  73. * @return name:goods_list.cover type:string default:-- desc:商品图
  74. * @return name:goods_list.goods_spec type:string default:-- desc:商品规格
  75. */
  76. public function getExpressMessageList()
  77. {
  78. $where[] = ['user_id','=',$this->user_id];
  79. $where[] = ['type_id','in','2,3'];
  80. $list = UserMessage::where($where)
  81. ->limit($this->off_set,$this->page_num)
  82. ->order('id desc')
  83. ->select()->toArray();
  84. foreach ($list as &$v) {
  85. $v['goods_list'] = StoreGoodsItem::field('goods_name,cover,goods_spec')->where(['order_id'=>$v['relation_id']])->select()->toArray();
  86. $v['order_info'] = GoodsOrder::field('id,order_no,express_send_no')->where('id',$v['relation_id'])->find()->toArray();
  87. }
  88. $this->success('ok',['list'=>$list]);
  89. }
  90. /**
  91. * @title 获取活动平台消息(菜单)
  92. * @desc 获取活动平台消息(菜单)
  93. * @author qc
  94. * @url /api/Message/getActivityNews
  95. * @method GET
  96. * @return name:content type:string default:-- desc:标题
  97. * @return name:is_read type:string default:-- desc:是否已读(0否)
  98. */
  99. public function getActivityNews()
  100. {
  101. $detail = PlatformMessage::where(['type'=>2])->order('id desc')->find();
  102. if(!$detail)$this->success('ok',['detail'=>['content'=>'','is_read'=>0]]);
  103. $detail = $detail->toArray();
  104. $detail['is_read'] = PlatformReadLog::where(['user_id'=>$this->user_id,'type'=>2,'relation_id'=>$detail['id']])->count();
  105. $this->success('ok',['detail'=>$detail]);
  106. }
  107. /**
  108. * @title 获取活动平台消息(内页)
  109. * @desc 获取活动平台消息(内页)
  110. * @author qc
  111. * @url /api/Message/getActivityNewsList
  112. * @method GET
  113. * @return name:title type:string default:-- desc:标题
  114. * @return name:cover type:string default:-- desc:封面
  115. * @return name:start_time type:string default:-- desc:活动开始时间
  116. * @return name:end_time type:string default:-- desc:活动结束时间
  117. * @return name:goods_list type:array default:-- desc:商品列表(最多查3个)
  118. * @return name:goods_list.name type:string default:-- desc:商品名
  119. * @return name:goods_list.cover type:string default:-- desc:商品图
  120. */
  121. public function getActivityNewsList()
  122. {
  123. $sel_where = [];
  124. $sel_where[] = ['is_deleted','=',0];
  125. $sel_where[] = ['status','=',1];
  126. $list = SeckillActivity::where($sel_where)
  127. ->field('id,title,cover,start_time,end_time')
  128. ->order('id desc')->limit(0,5)->select()->toArray();
  129. if(!empty($list)){
  130. $relation_id = PlatformMessage::where(['type'=>2])->max('id');// 最新的一条视频推荐
  131. Data::save('PlatformReadLog',['user_id'=>$this->user_id,'type'=>2,'relation_id'=>$relation_id,'create_at'=>date('Y-m-d H:i:s')],'user_id',['user_id'=>$this->user_id,'type'=>2,'relation_id'=>$relation_id]);
  132. }
  133. foreach ($list as &$v){
  134. $v['goods_list'] = SeckillGoods::field('g.id,g.name,g.cover')
  135. ->alias('s')
  136. ->leftJoin('StoreGoods g','g.id = s.goods_id')
  137. ->order('s.id desc')
  138. ->limit(0,3)
  139. ->select()->toArray();
  140. }
  141. $this->success('ok',['list'=>$list]);
  142. }
  143. }