Ulog.php 6.9 KB

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