|
@@ -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);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|