Sfoglia il codice sorgente

wesmiler 报恩寺项目提交

wesmiler 4 anni fa
parent
commit
ff1b695578

+ 18 - 0
app/Http/Controllers/Api/v1/EnshrineController.php

@@ -7,6 +7,7 @@ use App\Http\Validator\EnshrineNoticeValidator;
 use App\Http\Validator\EnshrineValidator;
 use App\Services\EnshrineNoticeService;
 use App\Services\EnshrineService;
+use App\Services\MontionService;
 use Illuminate\Http\Request;
 
 /**
@@ -30,6 +31,7 @@ class EnshrineController extends BaseController
 
         $this->service = new EnshrineService();
         $this->noticeService = new EnshrineNoticeService();
+        $this->motionService = new MontionService();
     }
 
 
@@ -145,4 +147,20 @@ class EnshrineController extends BaseController
     public function noticeDel(){
         return $this->noticeService->del($this->userId);
     }
+
+    /**
+     * 念佛记录
+     * @return array
+     */
+    public function motion(){
+        return $this->motionService->save($this->userId);
+    }
+
+    /**
+     * 念佛统计
+     * @return array
+     */
+    public function motionCount(){
+        return $this->motionService->counts($this->userId);
+    }
 }

+ 41 - 0
app/Models/MontionModel.php

@@ -0,0 +1,41 @@
+<?php
+// +----------------------------------------------------------------------
+// | Laravel框架 [ Laravel ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 Laravel研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: wesmiler <12345678@qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Models;
+
+/**
+ * 念佛记录管理-模型
+ * @author wesmiler
+ * @since 2020/11/11
+ * Class MontionModel
+ * @package App\Models
+ */
+class MontionModel extends BaseModel
+{
+    // 设置数据表
+    protected $table = 'montions';
+
+    /**
+     * 获取记录信息
+     * @param int $id 记录ID
+     * @return array|string
+     * @author wesmiler
+     * @since 2020/11/11
+     */
+    public function getInfo($id)
+    {
+        $info = parent::getInfo($id); // TODO: Change the autogenerated stub
+        if ($info) {
+
+        }
+        return $info;
+    }
+}

+ 170 - 0
app/Services/MontionService.php

@@ -0,0 +1,170 @@
+<?php
+// +----------------------------------------------------------------------
+// | Laravel框架 [ Laravel ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 Laravel研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: wesmiler <12345678@qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Services;
+
+use App\Models\MemberModel;
+use App\Models\MontionModel;
+use App\Models\TradeModel;
+
+/**
+ * 念佛记录-服务类
+ * @author wesmiler
+ * @since 2020/11/11
+ * Class MontionService
+ * @package App\Services
+ */
+class MontionService extends BaseService
+{
+    /**
+     * 构造函数
+     * @author wesmiler
+     * @since 2020/11/11
+     * MontionService constructor.
+     */
+    public function __construct()
+    {
+        $this->model = new MontionModel();
+    }
+
+    /**
+     * 保存记录
+     * @param $userId
+     * @return array
+     */
+    public function save($userId){
+        $params = request()->all();
+        $foId = isset($params['fo_id'])? intval($params['fo_id']) : 0;
+        if(empty($foId)){
+            return message('佛像参数错误', false);
+        }
+
+        $memberInfo = MemberModel::where(['id' => $userId, 'mark' => 1, 'status' => 1])
+            ->select(['id', 'nickname', 'merits_num', 'coupon'])
+            ->first();
+        if (!$memberInfo) {
+            return message('您的账号不可操作或已冻结,请联系客服', false);
+        }
+
+        $days = 1;
+        $checkInfo = $this->model::where(['user_id'=> $userId,'status'=> 1,'mark'=> 1])
+            ->select(['id','user_id','fo_id','days'])
+            ->where('create_time','>=', strtotime(date('Y-m-d'))-86400)
+            ->orderBy('create_time','desc')
+            ->orderBy('days','desc')
+            ->first();
+        if($checkInfo){
+            $dateTime = strtotime(date('Y-m-d', $checkInfo->create_time));
+            if($dateTime < strtotime(date('Y-m-d'))){
+                $days = $checkInfo->days+1;
+            }else{
+                $days = $checkInfo->days;
+            }
+        }
+
+        \DB::beginTransaction();
+        $data = [
+            'user_id' => $userId,
+            'fo_id' => $foId,
+            'days' => $days,
+            'remark' => isset($params['remark']) ? $params['remark'] : '',
+            'create_time' => time(),
+            'update_time' => time(),
+            'status' => 1
+        ];
+        if (!$this->model::insertGetId($data)) {
+            \DB::rollBack();
+            return message('念佛处理失败', false);
+        }
+
+        // 奖励
+        $giveGd = ConfigService::make()->getConfigByCode('nf_give_gd');
+        $giveGd = $giveGd ? $giveGd : 0;
+        if ($giveGd > 0) {
+            if (!MemberModel::where(['id' => $userId, 'mark' => 1])->increment('merits_num', $giveGd)) {
+                \DB::rollBack();
+                return message("更新功德账户失败", false);
+            }
+
+            $data = [
+                'user_id' => $userId,
+                'source_uid' => 0,
+                'type' => 3,
+                'coin_type' => 4,
+                'pay_type' => 4,
+                'money' => $giveGd,
+                'change_type' => 1,
+                'balance' => $memberInfo->merits_num,
+                'create_time' => time(),
+                'remark' => "祈福念佛",
+                'status' => 1,
+            ];
+            if (!TradeModel::insertGetId($data)) {
+                \DB::rollBack();
+                return message("处理功德奖励失败", false);
+            }
+
+            return message("功德+{$giveGd}", true);
+        }
+
+        \DB::commit();
+        return message("祈福念佛", true);
+    }
+
+    /**
+     * 统计
+     * @param $userId
+     * @return array
+     *
+     */
+    public function counts($userId){
+        $today = $this->model::where(['user_id'=> $userId,'mark'=> 1,'status'=> 1])
+            ->where('create_time','>=', strtotime(date('Y-m-d')))
+            ->count('id');
+
+        $total = $this->model::where(['user_id'=> $userId,'mark'=> 1,'status'=> 1])
+            ->count('id');
+
+        $days = $this->model::where(['user_id'=> $userId,'mark'=> 1,'status'=> 1])
+            ->where('create_time','>=', strtotime(date('Y-m-d')))
+            ->orderBy('create_time','desc')
+            ->value('days');
+
+        $counts = [
+            'today'=> intval($today),
+            'total'=> intval($total),
+            'days'=> intval($days),
+            'ranks'=> ['rank'=> 0],
+        ];
+
+        if($total>0){
+            $model = $this->model::from(\DB::raw(env('DB_PREFIX').'motions as m,(select (@rank:=0)) as rank'))
+                ->where(['mark'=> 1,'status'=> 1])
+                ->groupBy(\DB::raw('count(id) as total'))
+                ->orderBy('create_time', 'asc')
+                ->select([\DB::raw('count(id) as total'),'days','id',\DB::raw('(@rank:=@rank+1) as rank')]);
+            $binds = $model->getBindings();
+            $sql = str_replace('?', '%s', $model->toSql());
+            $sql = sprintf($sql, ...$binds);
+
+            $ranks = $this->model::from(\DB::raw("({$sql}) as a"))
+                ->where(['id'=> $userId])
+                ->select([\DB::raw('count(id) as total'),'id','rank'])
+                ->first();
+            if($ranks){
+                $counts['ranks'] = $ranks;
+            }
+        }
+
+
+        return message(MESSAGE_OK, true, $counts);
+    }
+}

+ 2 - 0
routes/api.php

@@ -177,6 +177,8 @@ Route::post('/enshrine/notice', [\App\Http\Controllers\Api\v1\EnshrineController
 Route::post('/enshrine/noticeDel', [\App\Http\Controllers\Api\v1\EnshrineController::class, 'noticeDel']);
 Route::post('/enshrine/chaodu', [\App\Http\Controllers\Api\v1\EnshrineController::class, 'chaodu']);
 Route::post('/enshrine/order', [\App\Http\Controllers\Api\v1\EnshrineController::class, 'orderList']);
+Route::post('/enshrine/motion', [\App\Http\Controllers\Api\v1\EnshrineController::class, 'motion']);
+Route::post('/enshrine/motionCount', [\App\Http\Controllers\Api\v1\EnshrineController::class, 'motionCount']);
 
 // 修行项目
 Route::post('/practices/list', [\App\Http\Controllers\Api\v1\PracticesController::class, 'index']);