Ulog.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class Ulog extends Base {
  5. // 设置数据表(不含前缀)
  6. protected $name = 'ulog';
  7. // 定义时间戳字段名
  8. protected $createTime = '';
  9. protected $updateTime = '';
  10. // 自动完成
  11. protected $auto = [];
  12. protected $insert = [];
  13. protected $update = [];
  14. public function listData($where,$order,$page=1,$limit=20,$start=0)
  15. {
  16. if(!is_array($where)){
  17. $where = json_decode($where,true);
  18. }
  19. $limit_str = ($limit * ($page-1) + $start) .",".$limit;
  20. $total = $this->where($where)->count();
  21. $list = Db::name('Ulog')->where($where)->order($order)->limit($limit_str)->select();
  22. $user_ids=[];
  23. foreach($list as $k=>&$v){
  24. if($v['user_id'] >0){
  25. $user_ids[$v['user_id']] = $v['user_id'];
  26. }
  27. if($v['ulog_mid']==1){
  28. $vod_info = model('Vod')->infoData(['vod_id'=>['eq',$v['ulog_rid']]],'*',1);
  29. if($v['ulog_sid']>0 && $v['ulog_nid']>0){
  30. if($v['ulog_type']==5){
  31. $vod_info['info']['link'] = mac_url_vod_down($vod_info['info'],['sid'=>$v['ulog_sid'],'nid'=>$v['ulog_nid']]);
  32. }
  33. else{
  34. $vod_info['info']['link'] = mac_url_vod_play($vod_info['info'],['sid'=>$v['ulog_sid'],'nid'=>$v['ulog_nid']]);
  35. }
  36. }
  37. else{
  38. $vod_info['info']['link'] = mac_url_vod_detail($vod_info['info']);
  39. }
  40. $v['data'] = [
  41. 'id'=>$vod_info['info']['vod_id'],
  42. 'name'=>$vod_info['info']['vod_name'],
  43. 'pic'=>mac_url_img($vod_info['info']['vod_pic']),
  44. 'link'=>$vod_info['info']['link'],
  45. 'type'=>[
  46. 'type_id'=>$vod_info['info']['type']['type_id'],
  47. 'type_name'=>$vod_info['info']['type']['type_name'],
  48. 'link'=>mac_url_type($vod_info['info']['type']),
  49. ],
  50. ];
  51. }
  52. elseif($v['ulog_mid']==2){
  53. $art_info = model('Art')->infoData(['art_id'=>['eq',$v['ulog_rid']]],'*',1);
  54. $art_info['info']['link'] = mac_url_art_detail($art_info['info']);
  55. $v['data'] = [
  56. 'id'=>$art_info['info']['art_id'],
  57. 'name'=>$art_info['info']['art_name'],
  58. 'pic'=>mac_url_img($art_info['info']['art_pic']),
  59. 'link'=>$art_info['info']['link'],
  60. 'type'=>[
  61. 'type_id'=>$art_info['info']['type']['type_id'],
  62. 'type_name'=>$art_info['info']['type']['type_name'],
  63. 'link'=>mac_url_type($art_info['info']['type']),
  64. ],
  65. ];
  66. }
  67. elseif($v['ulog_mid']==3){
  68. $topic_info = model('Topic')->infoData(['topic_id'=>['eq',$v['ulog_rid']]],'*',1);
  69. $topic_info['info']['link'] = mac_url_topic_detail($topic_info['info']);
  70. $v['data'] = [
  71. 'id'=>$topic_info['info']['topic_id'],
  72. 'name'=>$topic_info['info']['topic_name'],
  73. 'pic'=>mac_url_img($topic_info['info']['topic_pic']),
  74. 'link'=>$topic_info['info']['link'],
  75. 'type'=>[],
  76. ];
  77. }
  78. elseif($v['ulog_mid']==8){
  79. $actor_info = model('Actor')->infoData(['actor_id'=>['eq',$v['ulog_rid']]],'*',1);
  80. $actor_info['info']['link'] = mac_url_actor_detail($actor_info['info']);
  81. $v['data'] = [
  82. 'id'=>$actor_info['info']['actor_id'],
  83. 'name'=>$actor_info['info']['actor_name'],
  84. 'pic'=>mac_url_img($actor_info['info']['actor_pic']),
  85. 'link'=>$actor_info['info']['link'],
  86. 'type'=>[],
  87. ];
  88. }
  89. }
  90. if(!empty($user_ids)){
  91. $where2=[];
  92. $where['user_id'] = ['in', $user_ids];
  93. $order='user_id desc';
  94. $user_list = model('User')->listData($where2,$order,1,999);
  95. $user_list = mac_array_rekey($user_list['list'],'user_id');
  96. foreach($list as $k=>&$v){
  97. $list[$k]['user_name'] = $user_list[$v['user_id']]['user_name'];
  98. }
  99. }
  100. return ['code'=>1,'msg'=>lang('data_list'),'page'=>$page,'pagecount'=>ceil($total/$limit),'limit'=>$limit,'total'=>$total,'list'=>$list];
  101. }
  102. public function infoData($where,$field='*')
  103. {
  104. if(empty($where) || !is_array($where)){
  105. return ['code'=>1001,'msg'=>lang('param_err')];
  106. }
  107. $info = $this->field($field)->where($where)->find();
  108. if(empty($info)){
  109. return ['code'=>1002,'msg'=>lang('obtain_err')];
  110. }
  111. $info = $info->toArray();
  112. return ['code'=>1,'msg'=>lang('obtain_ok'),'info'=>$info];
  113. }
  114. public function saveData($data)
  115. {
  116. $data['user_id'] = intval(cookie('user_id'));
  117. $data['ulog_time'] = time();
  118. $validate = \think\Loader::validate('Ulog');
  119. if(!$validate->check($data)){
  120. return ['code'=>1001,'msg'=>lang('param_err').':'.$validate->getError() ];
  121. }
  122. if($data['user_id']==0 || !in_array($data['ulog_mid'],['1','2','3','8']) || !in_array($data['ulog_type'],['1','2','3','4','5']) ) {
  123. return ['code'=>1002,'msg'=>lang('param_err')];
  124. }
  125. if(!empty($data['ulog_id'])){
  126. $where=[];
  127. $where['ulog_id'] = ['eq',$data['ulog_id']];
  128. $res = $this->allowField(true)->where($where)->update($data);
  129. }
  130. else{
  131. $res = $this->allowField(true)->insert($data);
  132. }
  133. if(false === $res){
  134. return ['code'=>1004,'msg'=>lang('save_err').':'.$this->getError() ];
  135. }
  136. return ['code'=>1,'msg'=>lang('save_ok')];
  137. }
  138. public function delData($where)
  139. {
  140. $res = $this->where($where)->delete();
  141. if($res===false){
  142. return ['code'=>1001,'msg'=>lang('del_err').':'.$this->getError() ];
  143. }
  144. return ['code'=>1,'msg'=>lang('del_ok')];
  145. }
  146. public function fieldData($where,$col,$val)
  147. {
  148. if(!isset($col) || !isset($val)){
  149. return ['code'=>1001,'msg'=>lang('param_err')];
  150. }
  151. $data = [];
  152. $data[$col] = $val;
  153. $res = $this->allowField(true)->where($where)->update($data);
  154. if($res===false){
  155. return ['code'=>1001,'msg'=>lang('set_err').':'.$this->getError() ];
  156. }
  157. return ['code'=>1,'msg'=>lang('set_ok')];
  158. }
  159. }