|
|
@@ -0,0 +1,194 @@
|
|
|
+<?php
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | Laravel框架 [ Laravel ]
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | 版权所有 2017~2021 Laravel研发中心
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | 官方网站: http://www.laravel.cn
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | Author: wesmiler <12345678@qq.com>
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+
|
|
|
+namespace App\Services;
|
|
|
+
|
|
|
+use App\Models\EnshrineRecordModel;
|
|
|
+use App\Models\MemberModel;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 供奉管理-服务类
|
|
|
+ * @author wesmiler
|
|
|
+ * @since 2020/11/11
|
|
|
+ * Class EnshrineService
|
|
|
+ * @package App\Services
|
|
|
+ */
|
|
|
+class EnshrineService extends BaseService
|
|
|
+{
|
|
|
+
|
|
|
+ protected static $instance = null;
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ * @author wesmiler
|
|
|
+ * @since 2020/11/11
|
|
|
+ * EnshrineOrdersService constructor.
|
|
|
+ */
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ $this->model = new EnshrineRecordModel();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 静态入口
|
|
|
+ * @return EnshrineOrdersService|null
|
|
|
+ */
|
|
|
+ public static function make(){
|
|
|
+ if(!self::$instance){
|
|
|
+ self::$instance = new EnshrineOrdersService();
|
|
|
+ }
|
|
|
+ return self::$instance;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 供奉记录
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getDataList($userId){
|
|
|
+ $params = request()->all();
|
|
|
+ $page = isset($params['pageSize']) ? intval($params['pageSize']) : PAGE;
|
|
|
+ $pageSize = isset($params['pageSize']) ? intval($params['pageSize']) : PERPAGE;
|
|
|
+ $size = ConfigService::make()->getConfigByCode('qifu_limit');
|
|
|
+ $pageSize = $size? $size : $pageSize;
|
|
|
+
|
|
|
+ $dataList = $this->model::from('enshrine_records as a')
|
|
|
+ ->leftJoin('foxiang as f', 'f.id', '=', 'a.fo_id')
|
|
|
+ ->leftJoin('foxiang_cates as c', 'c.id', '=', 'f.cate_id')
|
|
|
+ ->where(['a.user_id'=> $userId])
|
|
|
+ ->where(function ($query) use ($params) {
|
|
|
+ $query->where(['a.mark'=>1,'a.status'=> 1]);
|
|
|
+
|
|
|
+ })
|
|
|
+ ->select(['a.*', 'f.name','f.thumb','f.image', 'f.file_url','c.name as cate_name'])
|
|
|
+ ->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['image'] = $item['image'] ? get_image_url($item['image']) : '';
|
|
|
+ $item['file_url'] = $item['file_url'] ? get_image_url($item['file_url']) : '';
|
|
|
+ $item['create_time'] = $item['create_time'] ? datetime($item['create_time'],'Y-m-d H:i:s') : '';
|
|
|
+ $item['time_close'] = 0;
|
|
|
+ if($item['create_time'] <= date('Y-m-d H:i:s', time()-24*3600)){
|
|
|
+ $item['time_close'] = 1;
|
|
|
+ }
|
|
|
+ $item['guibai'] = 0;
|
|
|
+ $item['wash'] = 0;
|
|
|
+ }
|
|
|
+ unset($item);
|
|
|
+ }
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'code' => 0,
|
|
|
+ 'success'=> true,
|
|
|
+ 'msg' => '操作成功',
|
|
|
+ 'count' => isset($dataList['total']) ? $dataList['total'] : 0,
|
|
|
+ 'data' => isset($dataList['data']) ? $dataList['data'] : 0,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 请佛
|
|
|
+ * @param $userId
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function select($userId){
|
|
|
+ $id = request()->get('id', 0);
|
|
|
+ if($id <=0){
|
|
|
+ return message('参数错误', false);
|
|
|
+ }
|
|
|
+
|
|
|
+ $foInfo = $this->model::where(['id'=> $id,'mark'=> 1,'status'=> 1])
|
|
|
+ ->select(['id','name'])
|
|
|
+ ->first();
|
|
|
+ if(!$foInfo){
|
|
|
+ return message('佛像不存在,请选择其他佛像', false);
|
|
|
+ }
|
|
|
+
|
|
|
+ $memberInfo = MemberModel::where(['id'=> $userId,'mark'=> 1,'status'=> 1])
|
|
|
+ ->select(['id','nickname'])
|
|
|
+ ->first();
|
|
|
+ if(!$memberInfo){
|
|
|
+ return message('您的账号不可操作或已冻结,请联系客服', false);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证是否正在供奉该佛像
|
|
|
+ $type = request()->get('type', 1);
|
|
|
+ $params = request()->all();
|
|
|
+ switch($type){
|
|
|
+ case 1: // 祈福
|
|
|
+ $record = $this->model::where(['fo_id'=> $id,'user_id'=> $userId,'mark'=> 1,'status'=> 1])
|
|
|
+ ->select(['id','fo_id','user_id'])
|
|
|
+ ->first();
|
|
|
+ if($record){
|
|
|
+ return message('抱歉该佛像您正在供奉中,请24小时后再继续供奉或选择其他佛像', false);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 2: // 超度
|
|
|
+ break;
|
|
|
+ case 3: // 放生
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'fo_id'=> $id,
|
|
|
+ 'type'=> $type,
|
|
|
+ 'user_id'=> $userId,
|
|
|
+ 'used_name'=> isset($params['used_name'])? trim($params['used_name']) : '',
|
|
|
+ 'user_name'=> isset($params['user_name'])? trim($params['user_name']) : '',
|
|
|
+ 'relation'=> isset($params['relation'])? trim($params['relation']) : '',
|
|
|
+ 'description'=> isset($params['description'])? trim($params['description']) : '',
|
|
|
+ 'image'=> isset($params['image'])? trim($params['image']) : '',
|
|
|
+ 'create_time'=> time(),
|
|
|
+ 'update_time'=> time(),
|
|
|
+ 'mark'=> 1,
|
|
|
+ 'status'=> 1,
|
|
|
+ ];
|
|
|
+
|
|
|
+ if($this->model::insertGetId($data)){
|
|
|
+ return message('请佛成功',true);
|
|
|
+ }else{
|
|
|
+ return message('请佛失败',true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 送圣
|
|
|
+ * @param $userId
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function packoff($userId){
|
|
|
+ $id = request()->get('id', 0);
|
|
|
+ $type = request()->get('type', 0);
|
|
|
+
|
|
|
+ if(!$id || !$type){
|
|
|
+ return message('参数错误', false);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $enshrine = $this->model::where(['fo_id'=> $id, 'user_id'=> $userId,'type'=> $type,'mark'=> 1,'status'=> 1])
|
|
|
+ ->select(['id','fo_id','user_id','status'])
|
|
|
+ ->first();
|
|
|
+ if(!$enshrine){
|
|
|
+ return message('佛像信息不存在', false);
|
|
|
+ }
|
|
|
+
|
|
|
+ $enshrine->status = 2;
|
|
|
+ if($enshrine->save()){
|
|
|
+ return message('送圣成功', true);
|
|
|
+ }else{
|
|
|
+ return message('送圣失败', false);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|