Message.php 6.4 KB

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