VideoService.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services\Api;
  12. use App\Models\MemberModel;
  13. use App\Models\VideoCollectModel;
  14. use App\Models\VideoModel;
  15. use App\Services\BaseService;
  16. use App\Services\ConfigService;
  17. use App\Services\RedisService;
  18. use Illuminate\Support\Facades\DB;
  19. /**
  20. * 短视频管理-服务类
  21. * @author laravel开发员
  22. * @since 2020/11/11
  23. * @package App\Services\Api
  24. */
  25. class VideoService extends BaseService
  26. {
  27. // 静态对象
  28. protected static $instance = null;
  29. /**
  30. * 构造函数
  31. * @author laravel开发员
  32. * @since 2020/11/11
  33. * GoodsService constructor.
  34. */
  35. public function __construct()
  36. {
  37. $this->model = new VideoModel();
  38. }
  39. /**
  40. * 静态入口
  41. * @return static|null
  42. */
  43. public static function make()
  44. {
  45. if (!self::$instance) {
  46. self::$instance = (new static());
  47. }
  48. return self::$instance;
  49. }
  50. /**
  51. * 列表数据
  52. * @param $params
  53. * @param int $pageSize
  54. * @return array
  55. */
  56. public function getDataList($params, $pageSize = 18, $field = '', $userId=0)
  57. {
  58. $where = ['a.mark' => 1,'b.mark'=>1];
  59. $field = $field? $field : 'lev_a.*';
  60. $order = 'lev_a.id desc';
  61. $list = $this->model->with(['member'])->from('videos as a')
  62. ->leftJoin('member as b', 'b.id', '=', 'a.user_id')
  63. ->where($where)
  64. ->where(function ($query) use ($params) {
  65. $type = isset($params['type']) ? $params['type'] : 0;
  66. if ($type > 0) {
  67. $query->where('a.type', $type);
  68. }
  69. $uid = isset($params['uid']) ? $params['uid'] : 0;
  70. if ($uid > 0) {
  71. $query->where('a.user_id', $uid);
  72. }else{
  73. $query->where('a.status', 2);
  74. }
  75. })
  76. ->where(function ($query) use ($params) {
  77. $keyword = isset($params['kw']) ? $params['kw'] : '';
  78. if ($keyword) {
  79. $query->where('a.title', 'like', "%{$keyword}%")
  80. ->orWhere('a.tags', 'like', "%{$keyword}%")
  81. ->orWhere('a.description', 'like', "%{$keyword}%")
  82. ->orWhere('b.nickname', 'like', "%{$keyword}%");
  83. }
  84. })
  85. ->where(function ($query) use ($params, $userId) {
  86. $query->where(function($query) use($userId){
  87. // 所有人可见
  88. $query->where('a.visible_type', 1);
  89. })->orWhere(function($query) use($userId){
  90. // 关注视频发布用户可见
  91. $uids = $uids = MemberCollectService::make()->getCollectUsers(['user_id'=> $userId,'status'=>1,'mark'=>1],'collect_uid');
  92. $uids = $uids? $uids : [0];
  93. $query->where('a.visible_type', 2)->where('a.user_id', $uids); // 仅自己可见
  94. })->orWhere(function($query) use($userId){
  95. // 仅自己可见
  96. $query->where('a.visible_type', 3)->where('a.user_id', $userId); // 仅自己可见
  97. });
  98. })
  99. ->selectRaw($field)
  100. ->orderByRaw($order)
  101. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  102. $list = $list ? $list->toArray() : [];
  103. if ($list && $list['data']) {
  104. foreach ($list['data'] as &$item) {
  105. $item['create_time'] = isset($item['create_time']) ? datetime($item['create_time'], 'Y-m-d H.i.s') : '';
  106. $item['thumb'] = isset($item['thumb']) && $item['thumb'] ? get_image_url($item['thumb']) : '';
  107. if(isset($item['albums'])){
  108. $albums = $item['albums']? json_decode($item['albums'], true):[];
  109. $item['albums'] = $albums? get_images_preview($albums) : [];
  110. }
  111. if(isset($item['file_url'])){
  112. $item['file_url'] = $item['file_url']? get_image_url($item['file_url']) : '';
  113. }
  114. if(isset($item['music_url'])){
  115. $item['music_url'] = $item['music_url']? get_image_url($item['music_url']) : '';
  116. }
  117. $member = isset($item['member'])? $item['member'] : [];
  118. if($member){
  119. $member['avatar'] = isset($member['avatar']) && $member['avatar']? get_image_url($member['avatar']) : get_image_url('/images/member/logo.png');
  120. }
  121. $item['tags'] = isset($item['tags']) && $item['tags']? explode(',', $item['tags']) : [];
  122. $item['like_num'] = isset($item['like_num']) && $item['like_num']? format_num($item['like_num']) : 0;
  123. $item['collect_num'] = isset($item['collect_num']) && $item['collect_num']? format_num($item['collect_num']) : 0;
  124. $item['comment_num'] = isset($item['comment_num']) && $item['comment_num']? format_num($item['comment_num']) : 0;
  125. $item['views'] = isset($item['views']) && $item['views']? format_num($item['views']) : 0;
  126. $item['member'] = $member;
  127. }
  128. }
  129. return [
  130. 'pageSize' => $pageSize,
  131. 'total' => isset($list['total']) ? $list['total'] : 0,
  132. 'list' => isset($list['data']) ? $list['data'] : []
  133. ];
  134. }
  135. /**
  136. * 列表数据
  137. * @param $params
  138. * @param int $pageSize
  139. * @return array
  140. */
  141. public function getIndexList($params, $pageSize = 6, $field='', $userId=0)
  142. {
  143. $where = ['a.mark' => 1,'a.status'=>2,'b.mark'=>1];
  144. $field = $field? $field : 'lev_a.*';
  145. $order = 'rand()';
  146. $model = $this->model->with(['member'])->from('videos as a')
  147. ->leftJoin('member as b', 'b.id', '=', 'a.user_id')
  148. ->where($where)
  149. ->where(function ($query) use ($params) {
  150. $type = isset($params['type']) ? $params['type'] : 0;
  151. if ($type > 0) {
  152. $query->where('a.type', $type);
  153. }
  154. $uid = isset($params['user_id']) ? $params['user_id'] : 0;
  155. if ($uid > 0) {
  156. $query->where('a.user_id', $uid);
  157. }
  158. })
  159. ->where(function ($query) use ($params) {
  160. $keyword = isset($params['kw']) ? $params['kw'] : '';
  161. if ($keyword) {
  162. $query->where('a.title', 'like', "%{$keyword}%")
  163. ->orWhere('a.tags', 'like', "%{$keyword}%")
  164. ->orWhere('a.description', 'like', "%{$keyword}%")
  165. ->orWhere('b.nickname', 'like', "%{$keyword}%");
  166. }
  167. })
  168. ->where(function ($query) use ($params, $userId) {
  169. $query->where(function($query) use($userId){
  170. // 所有人可见
  171. $query->where('a.visible_type', 1);
  172. })->orWhere(function($query) use($userId){
  173. // 关注视频发布用户可见
  174. $uids = $uids = MemberCollectService::make()->getCollectUsers(['user_id'=> $userId,'status'=>1,'mark'=>1],'collect_uid');
  175. $uids = $uids? $uids : [0];
  176. $query->where('a.visible_type', 2)->where('a.user_id', $uids); // 仅自己可见
  177. })->orWhere(function($query) use($userId){
  178. // 仅自己可见
  179. $query->where('a.visible_type', 3)->where('a.user_id', $userId); // 仅自己可见
  180. });
  181. });
  182. // 推荐的数据
  183. $uids = [];
  184. $countModel = clone $model;
  185. $countModel = $countModel->whereNotIn('user_id',[$userId])
  186. ->where(function($query) use($params, $userId, &$uids){
  187. // 推荐视频数据
  188. $isRecommend = isset($params['is_recommend']) ? $params['is_recommend'] : 0;
  189. if ($isRecommend > 0) {
  190. $recommendData = VideoCollectService::make()->getRecommendData($userId);
  191. $uids = isset($recommendData['uids'])? $recommendData['uids'] : []; // 按用户推荐
  192. $tags = isset($recommendData['tags'])? $recommendData['tags'] : []; // 按标签推荐
  193. $uids = array_unique($uids);
  194. if($uids){
  195. $query->orWhere(function($query) use($uids){
  196. $query->whereIn('a.user_id', $uids);
  197. });
  198. }
  199. if($tags){
  200. $query->orWhere(function($query) use($tags){
  201. foreach($tags as $tag){
  202. $query->where('a.tags', 'like',"%{$tag}%")
  203. ->orWhere('a.description','like',"%{$tag}%");
  204. }
  205. });
  206. }
  207. }
  208. });
  209. $total = $countModel->count('a.id');
  210. // 随机优先匹配推送
  211. $match = false;
  212. $list = [];
  213. if($total > 3 ){
  214. // 关联推荐数据
  215. $list = $countModel->selectRaw($field)
  216. // ->orderByRaw($uids?DB::raw("FIND_IN_SET(user_id,'".implode(',', $uids)."')"):'lev_a.create_time desc')
  217. ->orderByRaw($order)
  218. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  219. $list = $list ? $list->toArray() : [];
  220. $list = isset($list['data']) && $list['data']? $list['data'] :[];
  221. }
  222. // 数据不够补充默认匹配数据
  223. if($total<$pageSize){
  224. // 默认推荐数据
  225. $list1 = $model->selectRaw($field)
  226. // ->orderByRaw('lev_a.create_time desc')
  227. ->orderByRaw($order)
  228. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  229. $list1 = $list1 ? $list1->toArray() : [];
  230. $list1 = isset($list1['data']) && $list1['data']? $list1['data'] :[];
  231. $list = array_merge($list, $list1);
  232. }
  233. if ($list) {
  234. foreach ($list as &$item) {
  235. $item['time_text'] = isset($item['create_time']) ? dateFormat($item['create_time'], 'Y-m-d H:i') : '';
  236. $item['thumb'] = isset($item['thumb']) && $item['thumb'] ? get_image_url($item['thumb']) : '';
  237. if(isset($item['albums'])){
  238. $albums = $item['albums']? json_decode($item['albums'], true):[];
  239. $item['albums'] = $albums? get_images_preview($albums) : [];
  240. }
  241. if(isset($item['file_url'])){
  242. $item['file_url'] = $item['file_url']? get_image_url($item['file_url']) : '';
  243. }
  244. if(isset($item['music_url'])){
  245. $item['music_url'] = $item['music_url']? get_image_url($item['music_url']) : '';
  246. }
  247. $member = isset($item['member'])? $item['member'] : [];
  248. if($member){
  249. $member['avatar'] = isset($member['avatar']) && $member['avatar']? get_image_url($member['avatar']) : get_image_url('/images/member/logo.png');
  250. }
  251. $item['tags'] = isset($item['tags']) && $item['tags']? explode(',', $item['tags']) : [];
  252. $item['like_num'] = isset($item['like_num']) && $item['like_num']? intval($item['like_num']) : 0;
  253. $item['collect_num'] = isset($item['collect_num']) && $item['collect_num']? intval($item['collect_num']) : 0;
  254. $item['views'] = isset($item['views']) && $item['views']? intval($item['views']) : 0;
  255. $item['comment_num'] = isset($item['comment_num']) && $item['comment_num']? intval($item['comment_num']) : 0;
  256. $item['is_like'] = VideoCollectService::make()->checkCollect($userId, $item['id'], 3);
  257. $item['is_collect'] = VideoCollectService::make()->checkCollect($userId, $item['id'], 2);
  258. $item['is_follow'] = MemberCollectService::make()->checkCollect($userId, $item['user_id'], 1);
  259. $item['is_fans'] = MemberCollectService::make()->checkCollect($item['user_id'], $userId, 1);
  260. $item['is_publisher'] = $userId == $item['user_id']? 1 : 0;
  261. $item['member'] = $member;
  262. }
  263. }
  264. return [
  265. 'pageSize' => $pageSize,
  266. "match"=> $match,
  267. 'sss'=> $list,
  268. 'sss1'=> $list1,
  269. 'total' => count($list),
  270. 'list' => isset($list['data']) ? $list['data'] : []
  271. ];
  272. }
  273. /**
  274. * 详情
  275. * @param $id
  276. * @return array
  277. */
  278. public function getInfo($id, $userId=0, $field=[])
  279. {
  280. $field = $field? $field : ['a.*'];
  281. $info = $this->model->from('videos as a')->with(['member'])
  282. ->leftJoin('member as b','b.id','=','a.user_id')
  283. ->where(['a.id'=> $id,'a.mark'=>1,'b.mark'=>1])
  284. ->select($field)
  285. ->first();
  286. $info = $info? $info->toArray() : [];
  287. if($info){
  288. if(isset($info['thumb'])){
  289. $info['thumb'] = $info['thumb']? get_image_url($info['thumb']) : '';
  290. }
  291. if(isset($info['file_url'])){
  292. $info['file_url'] = $info['file_url']? get_image_url($info['file_url']) : '';
  293. }
  294. if(isset($item['music_url'])){
  295. $item['music_url'] = $item['music_url']? get_image_url($item['music_url']) : '';
  296. }
  297. if(isset($info['albums'])){
  298. $info['albums'] = $info['albums']? json_decode($info['albums'], true) : [];
  299. $info['albums'] = $info['albums']? get_images_preview($info['albums']) : [];
  300. }
  301. $member = isset($info['member'])? $info['member'] : [];
  302. if($member){
  303. $member['avatar'] = isset($member['avatar']) && $member['avatar']? get_image_url($member['avatar']) : get_image_url('/images/member/logo.png');
  304. }
  305. $info['member'] = $member;
  306. $info['tags'] = isset($info['tags']) && $info['tags']? explode(',', $info['tags']) : [];
  307. $info['like_num'] = isset($info['like_num']) && $info['like_num']? intval($info['like_num']) : 0;
  308. $info['collect_num'] = isset($info['collect_num']) && $info['collect_num']? intval($info['collect_num']) : 0;
  309. $info['views'] = isset($info['views']) && $info['views']? intval($info['views']) : 0;
  310. $info['comment_num'] = isset($info['comment_num']) && $info['comment_num']? intval($info['comment_num']) : 0;
  311. $info['is_like'] = VideoCollectService::make()->checkCollect($userId, $info['id'], 3);
  312. $info['is_collect'] = VideoCollectService::make()->checkCollect($userId, $info['id'], 2);
  313. $info['is_follow'] = MemberCollectService::make()->checkCollect($userId, $info['user_id'], 1);
  314. $info['is_fans'] = MemberCollectService::make()->checkCollect($info['user_id'], $userId, 1);
  315. $info['is_publisher'] = $userId == $info['user_id']? 1 : 0;
  316. $info['time_text'] = isset($info['create_time']) ? dateFormat($info['create_time'], 'Y-m-d H:i') : '';
  317. // 浏览历史
  318. if(!VideoCollectService::make()->getCollectCacheInfo($userId, $id, 1)){
  319. $data = [
  320. 'user_id'=> $userId,
  321. 'type'=> 1,
  322. 'collect_id'=> $id,
  323. 'collect_uid'=> isset($info['user_id'])? $info['user_id'] : 0,
  324. 'tags'=> isset($info['tags'])? $info['tags'] : '',
  325. 'create_time'=> time(),
  326. 'status'=> 1,
  327. ];
  328. VideoCollectModel::insert($data);
  329. RedisService::set("caches:videos:collect:temp_{$userId}_{$id}_1_1", $data, rand(10,30));
  330. RedisService::clear("caches:videos:recommend:{$userId}_1");
  331. RedisService::clear("caches:member:fans:{$userId}_{$id}_1");
  332. }
  333. // 浏览量
  334. $this->updateView($userId, $id);
  335. }
  336. return $info;
  337. }
  338. /**
  339. * 更新播放浏览历史
  340. * @param $userId 用户ID
  341. * @param $id 视频ID
  342. * @return false
  343. */
  344. public function updatePlay($userId, $id)
  345. {
  346. // 浏览历史
  347. if(!VideoCollectService::make()->getCollectCacheInfo($userId, $id, 1)){
  348. $info = $this->model->from('videos as a')
  349. ->where(['a.id'=> $id,'a.mark'=>1])
  350. ->select(['a.id','a.tags','a.user_id'])
  351. ->first();
  352. if(empty($info)){
  353. return false;
  354. }
  355. $data = [
  356. 'user_id'=> $userId,
  357. 'type'=> 1,
  358. 'collect_id'=> $id,
  359. 'collect_uid'=> isset($info['user_id'])? $info['user_id'] : 0,
  360. 'tags'=> isset($info['tags'])? $info['tags'] : '',
  361. 'create_time'=> time(),
  362. 'status'=> 1,
  363. ];
  364. VideoCollectModel::insert($data);
  365. RedisService::set("caches:videos:collect:temp_{$userId}_{$id}_1_1", $data, rand(10,30));
  366. RedisService::clear("caches:videos:recommend:{$userId}_1");
  367. RedisService::clear("caches:member:fans:{$userId}_{$id}_1");
  368. }
  369. // 浏览量
  370. $this->updateView($userId, $id);
  371. $this->error = 1010;
  372. return true;
  373. }
  374. /**
  375. * 更新浏览量
  376. * @param $userId
  377. * @param $dynamicId
  378. * @return array|mixed
  379. */
  380. public function updateView($userId, $id)
  381. {
  382. $cacheKey = "caches:videos:views:u{$userId}_d{$id}";
  383. $data = RedisService::get($cacheKey);
  384. if($data){
  385. return false;
  386. }
  387. // 浏览视频任务处理
  388. TaskService::make()->updateTask($userId,2, $id);
  389. $data = $this->model->where(['id'=> $id])->update(['views'=>DB::raw('views + 1'),'update_time'=>time()]);
  390. RedisService::set($cacheKey, $id, rand(1,3)*3600);
  391. return $data;
  392. }
  393. /**
  394. * 发布
  395. * @param $goodsId
  396. * @return bool
  397. */
  398. public function publish($userId, $params, $request)
  399. {
  400. $goodsId = isset($params['goods_id'])? intval($params['goods_id']) : 0;
  401. $type = isset($params['type'])? intval($params['type']) : 2;
  402. $userInfo = MemberModel::where(['id'=> $userId,'mark'=>1])
  403. ->select(['id','nickname','status'])
  404. ->first();
  405. $status = isset($userInfo['status'])? $userInfo['status'] : 0;
  406. $nickname = isset($userInfo['nickname'])? $userInfo['nickname'] : '';
  407. if(empty($userInfo) || $status != 1){
  408. $this->error = 2017;
  409. return false;
  410. }
  411. $thumb = isset($params['thumb'])? trim($params['thumb']) : '';
  412. if($thumb){
  413. $result = upload_base64($thumb);
  414. $thumb = isset($result['file_path'])? $result['file_path'] : '';
  415. if(empty($thumb)){
  416. $this->error = 2208;
  417. return false;
  418. }
  419. }
  420. // 音乐
  421. $musicUrl = isset($params['music_url'])? trim($params['music_url']) : '';
  422. if($musicUrl){
  423. $result = upload_remote_image($musicUrl,'mp3','music');
  424. $musicUrl = isset($result['file_path'])? $result['file_path'] : '';
  425. if(empty($musicUrl)){
  426. $this->error = 2209;
  427. return false;
  428. }
  429. }
  430. // 视频
  431. $fileUrl = isset($params['file_url'])? trim($params['file_url']) : '';
  432. $albums = isset($params['album_urls'])?json_decode( $params['album_urls'],true) : [];
  433. if($type == 1) {
  434. if($fileUrl){
  435. $result = upload_video($request,'video');
  436. $data = isset($result['data'])? $result['data'] : [];
  437. $fileUrl = isset($data['file_path'])? $data['file_path'] : '';
  438. if(empty($fileUrl)){
  439. $this->error = 2212;
  440. return false;
  441. }
  442. }else{
  443. $this->error = 2213;
  444. return false;
  445. }
  446. }
  447. // 相册
  448. else if($type == 2){
  449. if(empty($albums) || !is_array($albums)){
  450. $this->error = 2211;
  451. return false;
  452. }
  453. $albums = get_format_images($albums);
  454. }
  455. $title = isset($params['title']) && $params['title']? trim($params['title']) : "{$nickname} 发布的短视频";
  456. $description = isset($params['description']) && $params['description']? trim($params['description']) : "{$nickname} 发布的短视频";
  457. $publishCheck = ConfigService::make()->getConfigByCode('video_publish_check',0);
  458. $publishCheck = $publishCheck>0? $publishCheck : 0;
  459. $tags = isset($params['tags']) && $params['tags']? $params['tags'] : '';
  460. $data = [
  461. 'user_id' => $userId,
  462. 'title' => $title,
  463. 'type' => $type,
  464. 'description' => $description,
  465. 'tags' => $tags && is_array($tags)? implode(',', $tags) : $tags,
  466. 'file_url' => $fileUrl,
  467. 'thumb' => $thumb,
  468. 'albums' => $albums? $albums : '',
  469. 'music_hash' => isset($params['music_hash'])? trim($params['music_hash']) : '',
  470. 'music_name' => isset($params['music_name'])? trim($params['music_name']) : '',
  471. 'music_url' => $musicUrl,
  472. 'goods_id' => $goodsId,
  473. 'visible_type' => isset($params['visible_type'])? intval($params['visible_type']) : 1,
  474. 'is_comment' => isset($params['is_comment'])? intval($params['is_comment']) : 1,
  475. 'status' => $publishCheck? 1 : 2,
  476. 'mark' => 1,
  477. 'publish_at' => date('Y-m-d H:i:s'),
  478. 'create_time' => time(),
  479. ];
  480. RedisService::set('caches:videos:publish', ['params'=> $params,'data'=> $data], 600);
  481. if($id = $this->model->insertGetId($data)){
  482. $this->error = 1023;
  483. // 发布视频任务处理
  484. TaskService::make()->updateTask($userId,5, $id);
  485. return ['id'=> $id];
  486. }
  487. $this->error = 1024;
  488. return false;
  489. }
  490. /**
  491. * 状态设置
  492. * @return bool
  493. */
  494. public function status()
  495. {
  496. $id = request()->post('id', 0);
  497. $status = request()->post('status', 1);
  498. if ($id && !$this->model->where(['id' => $id, 'mark' => 1])->value('id')) {
  499. $this->error = 2981;
  500. return false;
  501. }
  502. if($this->model->where(['id'=> $id,'mark'=>1])->update(['status'=>$status, 'update_time'=> time()])){
  503. $this->error = 1002;
  504. return true;
  505. }
  506. $this->error = 1003;
  507. return true;
  508. }
  509. /**
  510. * 删除
  511. * @return bool
  512. */
  513. public function delete()
  514. {
  515. // 参数
  516. $param = request()->all();
  517. $id = getter($param, "id");
  518. if (empty($id)) {
  519. $this->error = 2014;
  520. return false;
  521. }
  522. if(!$this->model->where(['id'=> $id])->value('id')){
  523. $this->error = 1039;
  524. return false;
  525. }
  526. if($this->model->where(['id'=> $id])->update(['mark'=>0,'update_time'=>time()])){
  527. $this->model->where(['mark'=> 0])->where('update_time','<=', time() - 3 * 86400)->delete();
  528. $this->error = 1025;
  529. return true;
  530. }else{
  531. $this->error = 1026;
  532. return false;
  533. }
  534. }
  535. }