|
|
@@ -0,0 +1,157 @@
|
|
|
+<?php
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | Laravel框架 [ Laravel ]
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | 版权所有 2017~2021 Laravel研发中心
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | 官方网站: http://www.laravel.cn
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | Author: wesmiler <12345678@qq.com>
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+
|
|
|
+namespace App\Services;
|
|
|
+
|
|
|
+use App\Models\BuddhistCollectModel;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 佛音歌单管理-服务类
|
|
|
+ * @author wesmiler
|
|
|
+ * @since 2020/11/11
|
|
|
+ * Class BuddhistCollectService
|
|
|
+ * @package App\Services
|
|
|
+ */
|
|
|
+class BuddhistCollectService extends BaseService
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ * @author wesmiler
|
|
|
+ * @since 2020/11/11
|
|
|
+ * MusicCollectService constructor.
|
|
|
+ */
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ $this->model = new BuddhistCollectModel();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取列表
|
|
|
+ * @return array
|
|
|
+ * @since 2020/11/11
|
|
|
+ * @author wesmiler
|
|
|
+ */
|
|
|
+ public function getList()
|
|
|
+ {
|
|
|
+ $params = request()->all();
|
|
|
+
|
|
|
+ return parent::getList();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取列表
|
|
|
+ * @return array
|
|
|
+ * @since 2020/11/11
|
|
|
+ * @author wesmiler
|
|
|
+ */
|
|
|
+ public function getDataList($params)
|
|
|
+ {
|
|
|
+ $page = isset($params['pageSize']) ? intval($params['pageSize']) : PAGE;
|
|
|
+ $pageSize = isset($params['pageSize']) ? intval($params['pageSize']) : PERPAGE;
|
|
|
+
|
|
|
+ $dataList = $this->model::from('buddhist_collect as a')
|
|
|
+ ->leftJoin('buddhist_cates as bc', 'bc.id', '=', 'a.cate_id')
|
|
|
+ ->leftJoin('buddhists as b', 'b.id', '=', 'a.source_id')
|
|
|
+ ->where(function ($query) use ($params) {
|
|
|
+ $query->where(['a.mark'=>1,'a.status'=> 1]);
|
|
|
+
|
|
|
+ $userId = isset($params['user_id']) ? intval($params['user_id']) : 0;
|
|
|
+ if ($userId > 0) {
|
|
|
+ $query->where('a.user_id', $userId);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ->select(['a.id', 'a.source_id', 'b.title','b.thumb','bc.name as cate_name','b.view_num', 'a.user_id', 'a.status', 'a.create_time', 'a.update_time'])
|
|
|
+ ->orderBy('a.create_time', 'desc')
|
|
|
+ ->paginate($pageSize);
|
|
|
+
|
|
|
+ $dataList = $dataList ? $dataList->toArray() : [];
|
|
|
+ if ($dataList) {
|
|
|
+ foreach ($dataList['data'] as &$item) {
|
|
|
+ $item['thumb'] = $item['thumb'] ? get_image_url($item['thumb']) : '';
|
|
|
+ $item['create_time'] = $item['create_time'] ? datetime($item['create_time'],'Y-m-d H:i:s') : '';
|
|
|
+ }
|
|
|
+ unset($item);
|
|
|
+ }
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'code' => 0,
|
|
|
+ 'success'=> true,
|
|
|
+ 'msg' => '操作成功',
|
|
|
+ 'count' => isset($dataList['total']) ? $dataList['total'] : 0,
|
|
|
+ 'data' => isset($dataList['data']) ? $dataList['data'] : 0,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加或编辑
|
|
|
+ * @return array
|
|
|
+ * @since 2020/11/11
|
|
|
+ * @author wesmiler
|
|
|
+ */
|
|
|
+ public function edit()
|
|
|
+ {
|
|
|
+ $data = request()->all();
|
|
|
+ $data['update_time'] = time();
|
|
|
+ return parent::edit($data); // TODO: Change the autogenerated stub
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加或编辑
|
|
|
+ * @return array
|
|
|
+ * @since 2020/11/11
|
|
|
+ * @author wesmiler
|
|
|
+ */
|
|
|
+ public function save($userId)
|
|
|
+ {
|
|
|
+
|
|
|
+ $params = request()->all();
|
|
|
+ $id = isset($params['id'])? $params['id'] : 0;
|
|
|
+ $status = isset($params['status'])? $params['status'] : 1;
|
|
|
+ if($id<=0){
|
|
|
+ return message('参数错误', false);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!in_array($status, [1,2])){
|
|
|
+ return message('参数错误', false);
|
|
|
+ }
|
|
|
+
|
|
|
+ $info = $this->model::where(['user_id'=> $userId, 'source_id'=> $id])->select(['id','status'])->first();
|
|
|
+ if($info && $info->status == 1 && $status == 1){
|
|
|
+ return message("您已收藏过", false);
|
|
|
+ }else if($info && $info->status == 2 && $status == 2){
|
|
|
+ return message("您已取消收藏", false);
|
|
|
+ }else if(!$info && $status == 2){
|
|
|
+ return message("您未收藏过", false);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理
|
|
|
+ if($info){
|
|
|
+ $info->status = $status;
|
|
|
+ $info->create_time = time();
|
|
|
+ if($info->save()){
|
|
|
+ return message($status == 1? "收藏成功":"取消收藏成功", true);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $data = [
|
|
|
+ 'user_id'=> $userId,
|
|
|
+ 'source_id'=> $id,
|
|
|
+ 'create_time'=> time(),
|
|
|
+ 'status'=> 1,
|
|
|
+ ];
|
|
|
+ if($this->model::insertGetId($data)){
|
|
|
+ return message("收藏成功", true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return message('操作失败', false);
|
|
|
+ }
|
|
|
+}
|