Message.php 6.2 KB

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