Przeglądaj źródła

Merge remote-tracking branch 'origin/master'

Panda 1 miesiąc temu
rodzic
commit
9c17347fcc

+ 1 - 1
application/api/controller/Notify.php

@@ -99,7 +99,7 @@ class Notify extends Api
         exit;
     }
 
-    //充值金币 逻辑
+    //充值VIP 逻辑
     private function vip_notify_do($out_trade_no)
     {
 

+ 1 - 1
application/api/controller/Pay.php

@@ -216,7 +216,7 @@ class Pay extends Api
         if ($money <= 0) {
             $this->error('支付金额必须大于0');
         }
-        if ($money > 10000) {
+        if ($money > 100000) {
             $this->error('支付金额太大');
         }
 

+ 181 - 0
application/api/controller/Task.php

@@ -0,0 +1,181 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+
+/**
+ * 任务接口
+ */
+class Task extends Api
+{
+    protected $noNeedLogin = [''];
+    protected $noNeedRight = '*';
+
+    public function _initialize()
+    {
+        parent::_initialize();
+        $this->taskModel = new \app\common\model\Task();
+        $this->tasklogModel = new \app\common\model\TaskLog();
+    }
+
+    /**
+     * 获取任务列表
+     */
+    public function getTaskList() {
+        $type_id = $this->request->request("type_id",1); // 任务类型:1=实时任务,2=每日任务
+        $plat = $this->request->request("plat",1); // 平台:1=安卓,2=ios
+
+        $urlArr = ["1"=>"android_url","2"=>"ios_url"];
+        $jump_url = $urlArr[$plat];
+
+        if($type_id == 2) {
+
+            // 获取所有基础任务
+            $where = [];
+            $where["type_id"] = 2;
+            $where["is_show"] = 1;
+
+            $taskList = Db::name('task')
+                ->field("id,type_id,image,name,title,exp,number,".$jump_url." as jump_url,url_type")
+                ->where($where)
+                ->autopage()
+                ->select();
+            $taskList = list_domain_image($taskList,['image']);
+
+            $today = strtotime(date("Y-m-d 00:00:00"));
+
+            //今日开始的任务
+            $where = [];
+            $where["user_id"] = $this->auth->id;
+            $where["createtime"] = ["gt",$today];
+            $finishInfo = \app\common\model\TaskLog::where($where)->select();
+
+            $finishIds = [];
+            if($finishInfo) foreach($finishInfo as $k => $v) {
+                $finishIds[$v["task_id"]] = $v;
+            }
+
+            if($taskList) {
+                foreach($taskList as $k => $v) {
+                    $finishInfo = isset($finishIds[$v["id"]])?$finishIds[$v["id"]]:[];
+                    if($finishInfo) {
+                        $taskList[$k]["pace"] = $finishInfo->pace;
+                        $taskList[$k]["is_finish"] = $finishInfo->is_finish;
+                        $taskList[$k]["finish_number"] = $finishInfo->finish_number;
+                        $taskList[$k]["is_reward"] = $finishInfo->is_reward;
+                        if($finishInfo->is_finish != 1 && $finishInfo->pace != 0) {
+                            $taskList[$k]["pace_txt"] = $finishInfo->finish_number."/".$v["number"];
+                        }
+                    } else {
+                        $taskList[$k]["pace"] = 0;
+                        $taskList[$k]["is_finish"] = 0;
+                        $taskList[$k]["finish_number"] = 0;
+                        $taskList[$k]["is_reward"] = 0;
+                        $taskList[$k]["pace_txt"] = "0/".$v["number"];
+                    }
+                }
+            }
+        } else {
+            // 获取基本信息
+            $where = [];
+            $where["a.type_id"] = 1;
+            $where["a.is_show"] = 1;
+            $taskList = Db::name('task')->alias("a")
+                ->field("a.id,a.type_id,a.image,a.name,a.title,a.exp,a.number,a.".$jump_url." as jump_url,a.url_type,l.pace,l.is_reward,l.is_finish,l.finish_number")
+                ->join("task_log l", "l.task_id = a.id and l.user_id = ".$this->auth->id, "left")
+                ->where($where)
+                ->autopage()
+                ->order("a.id","asc")
+                ->select();
+            $taskList = list_domain_image($taskList,['image']);
+
+            if($taskList) {
+                foreach($taskList as $k => $v) {
+                    $v["pace"] || $taskList[$k]["pace"] = 0;
+                    $v["is_finish"] || $taskList[$k]["is_finish"] = 0;
+                    $v["finish_number"] || $taskList[$k]["finish_number"] = 0;
+                    $v["is_reward"] || $taskList[$k]["is_reward"] = 0;
+                    if($v["is_finish"] != 1 && $v["pace"] != 0) {
+                        $taskList[$k]["pace_txt"] = $v["finish_number"]."/".$v["number"];
+                    }
+                }
+            }
+        }
+
+        $this->success("获取成功!",$taskList);
+    }
+
+    /**
+     * 领取奖励
+     */
+    public function getReward() {
+        $task_id = $this->request->request("task_id"); // 任务ID
+        if (!$task_id) {
+            $this->error(__('Invalid parameters'));
+        }
+        // 查询任务信息
+        $taskInfo = $this->taskModel->where(["id"=>$task_id])->find();
+        if(!$taskInfo) {
+            $this->error("任务信息未找到!");
+        }
+        // 查询用户完成情况
+        $where = [];
+        $where["user_id"] = $this->auth->id;
+        $where["task_id"] = $task_id;
+        $where["is_finish"] = 1;
+        if($taskInfo["type_id"] == 2){
+            $where["finish_date"] = date("Ymd");
+        }
+        $tasklogInfo = $this->tasklogModel->where($where)->find();
+        if(!$tasklogInfo) {
+            $this->error("任务还未完成哦!");
+        }
+        if($tasklogInfo["is_reward"] == 1) {
+            $this->error("任务奖励已领取,请勿重复领取!");
+        }
+        Db::startTrans();
+        try{
+            // 增加用户金币
+            $res1 = model('wallet')->lockChangeAccountRemain($this->auth->id,'bean',$taskInfo["exp"],102,$taskInfo['name'],'task_log',$tasklogInfo['id']);
+            if($res1['status'] === false){
+                Db::rollback();
+                $this->error($res1['msg']);
+            }
+            // 更新奖励领取状态
+            $res2 = $this->tasklogModel->update(["is_reward"=>1],["task_id"=>$task_id,"user_id"=>$this->auth->id]);
+            if($res1['status'] === true && $res2) {
+                Db::commit();
+                $this->success("领取成功!");
+            } else {
+                Db::rollback();
+                $this->error("领取失败!");
+            }
+        }catch (ValidateException $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        } catch (PDOException $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        } catch (Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+    }
+
+    /**
+     * 完成任务
+     */
+    public function finishTask() {
+        $task_id = $this->request->request("task_id"); // 任务编码
+        $number = $this->request->request("number",1); // 完成次数
+        if (!$task_id) {
+            $this->error(__('Invalid parameters'));
+        }
+        \app\common\model\TaskLog::tofinish($this->auth->id,$task_id,$number);
+        $this->success("成功!");
+
+    }
+
+}

+ 164 - 0
application/api/controller/Usersign.php

@@ -0,0 +1,164 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+
+/**
+ * 签到
+ */
+class Usersign extends Api
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = ['*'];
+
+    /**
+     * 配置
+     */
+    public function config()
+    {
+        $list = Db::name('signin')->order('id asc')->select();
+        //连续签到次数
+        $user_sign = Db::name('user_sign')->where(['uid' => $this->auth->id])->order('id desc')->find();
+        $yesterday_time = strtotime('yesterday'); //昨天0点时间戳
+        $today_time = $yesterday_time + 86400; //今日0点时间戳
+        if ($user_sign) {
+            if ($user_sign['createtime'] >= $yesterday_time) {
+                $data['sign_times'] = $user_sign['times']; //连续签到天数
+            } else {
+                $data['sign_times'] = 0;//昨天没签到,归零
+            }
+            if ($user_sign['createtime'] >= $today_time) {
+                $data['is_sign'] = 1; //今日是否签到: 1已签到 0未签到
+            } else {
+                $data['is_sign'] = 0; //今日是否签到: 1已签到 0未签到
+            }
+
+        } else {
+            $data['sign_times'] = 0; //连续签到天数
+            $data['is_sign'] = 0; //今日是否签到: 1已签到 0未签到
+        }
+
+        $data['sign_round_times'] = $data['sign_times'] % 7;
+
+        $data['list'] = $list;
+
+        $this->success('success',$data);
+    }
+
+    //签到
+    public function signin(){
+        $uid = $this->auth->id;
+
+        //记录日志
+        $data = [
+            'uid' => $uid,
+            'times' => 1,
+            'goldnum' => 0,
+            'createtime' => time(),
+        ];
+
+        $yesterday_time = strtotime('yesterday'); //昨天0点时间戳
+        $today_time = $yesterday_time + 86400; //今日0点时间戳
+
+        //修正当前次数
+        $check = Db::name('user_sign')->where('uid',$uid)->order('id desc')->find();
+        if($check){
+            //今天只能签一次
+            if($check['createtime'] > $today_time){
+                $this->error('今天已经签过了');
+            }
+            if ($check['createtime'] >= $yesterday_time) {
+                $data['times'] = $check['times'] + 1; //连续签到次数
+            }else{
+                //没有连起来,默认1
+            }
+
+        }
+
+        if($data['times'] > 7){
+            $data['times'] = 1;
+        }
+
+        //匹配对应金币数
+        $list = Db::name('signin')->order('id asc')->column('id,goldnum');
+        $data['goldnum'] = isset($list[$data['times']]) ? $list[$data['times']] : 0 ;
+
+        Db::startTrans();
+        //记录日志
+        $log_id = Db::name('user_sign')->insertGetId($data);
+        if(!$log_id){
+            Db::rollback();
+            $this->error('签到失败');
+        }
+
+        //加钱
+        $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'bean',$data['goldnum'],101,'签到奖励','user_sign',$log_id);
+        if($rs['status'] === false){
+            Db::rollback();
+            $this->error($rs['msg']);
+        }
+
+        //第七天赠送vip
+        $vip_rs = false;
+        $user_sign_gift_vipdays = intval(config('site.user_sign_gift_vipdays'));
+        if($data['times'] == 7 && $user_sign_gift_vipdays > 0){
+
+            //$vip_rs = $this->gift_vip($user_sign_gift_vipdays);
+        }
+
+        Db::commit();
+        $remark = '获得善豆'.$data['goldnum'];
+        if($vip_rs){
+            $remark .= ',vip'.$user_sign_gift_vipdays.'天';
+        }
+        $this->success('签到成功',$remark);
+    }
+
+    //第七天赠送vip
+    //找出最近七天的次数
+    private function gift_vip($user_sign_gift_vipdays){
+        $start = strtotime(date('Y-m-d')) - 518400;
+        $map = [
+            'uid' => $this->auth->id,
+            'createtime' => ['gt',$start],
+        ];
+        $count = Db::name('user_sign')->where($map)->count();
+
+        if($count >= 7){  //七天内签到次数 >= 7
+            //赠送vip三天
+            $add_time = 86400 * $user_sign_gift_vipdays;
+
+            //有vip的续费,没有的从现在开始
+            $vip_endtime = model('wallet')->getWallet($this->auth->id,'vip_endtime');
+            if($vip_endtime <= time()){
+                $new_vip_endtime = time() + $add_time;
+                $vip_type = 1;
+            }else{
+                $new_vip_endtime = $vip_endtime + $add_time;
+                $vip_type = 2;
+            }
+            $rs = Db::name('user_wallet')->where('user_id',$this->auth->id)->update(['vip_endtime'=>$new_vip_endtime]);
+
+            //记录日志
+            $log_data = [
+                'user_id' => $this->auth->id,
+                'before'  => $vip_endtime,
+                'change_value'  => $add_time,
+                'remain'  => $new_vip_endtime,
+                'remark'  => '签到送vip',
+                'createtime'  => time(),
+                'vip_type'  => $vip_type,
+            ];
+            Db::name('user_vip_log')->insertGetId($log_data);
+
+            if($rs === false){
+                Db::rollback();
+                $this->error('连续签到赠送vip失败');
+            }
+            return true;
+        }
+        return false;
+    }
+}

+ 16 - 13
application/api/controller/Userwallet.php

@@ -25,28 +25,29 @@ class Userwallet extends Api
     {
         $tab = $this->request->param('type', 'all');
 
-        $user = auth_user();
 
         $where = [
-            'user_id' => $user->id,
-            'type'    => 'money',
+            'user_id' => $this->auth->id,
         ];
 
         if($tab == 1){
-            $where['amount'] = ['>', 0];
+            $where['change_value'] = ['>', 0];
         }
         if($tab == 2){
-            $where['amount'] = ['<', 0];
+            $where['change_value'] = ['<', 0];
         }
 
-        $logs = UserWalletLogModel::where($where)
-            ->order('id', 'desc')
+        $logs = Db::name('user_money_log')
+            ->field('id,log_type,before,change_value,remain,remark,createtime')
+            ->where($where)
+            ->order('id desc')
             ->autopage()->select();
 
         $this->success(1, $logs);
     }
 
-    /*public function my_money_log(){
+    //善豆明细
+    public function my_bean_log(){
         $type = input('type',0);
 
         $map = [
@@ -56,13 +57,15 @@ class Userwallet extends Api
             $map['log_type'] = $type;
         }
 
-        $list = Db::name('user_money_log')
+        $list = Db::name('user_bean_log')
             ->field('id,log_type,before,change_value,remain,remark,createtime')
-            ->where($map)->order('id desc')->autopage()->select();
-        $list = $this->list_appen_logtext($list);
+            ->where($map)
+            ->order('id desc')
+            ->autopage()->select();
+//        $list = $this->list_appen_logtext($list);
 
-        $this->success('success',$list);
-    }*/
+        $this->success(1,$list);
+    }
 
 
 

+ 17 - 0
application/common/model/Task.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace app\common\model;
+
+use think\Model;
+
+/**
+ * 模型
+ */
+class Task extends Model
+{
+
+    // 开启自动写入时间戳字段
+    protected $autoWriteTimestamp = 'int';
+    // 定义时间戳字段名
+    protected $createTime = 'createtime';
+}

+ 81 - 0
application/common/model/TaskLog.php

@@ -0,0 +1,81 @@
+<?php
+
+namespace app\common\model;
+
+use think\Model;
+
+/**
+ * 模型
+ */
+class TaskLog extends Model
+{
+
+    // 开启自动写入时间戳字段
+    protected $autoWriteTimestamp = 'int';
+    // 定义时间戳字段名
+    protected $createTime = 'createtime';
+    protected $updateTime = 'updatetime';
+
+    /**
+     * 增加任务完成进度
+     */
+    public static function tofinish($user_id,$task_id,$number = 1) {
+        if(!$user_id || !$task_id || !$number) {
+            return false;
+        }
+        // 查询任务明细
+        $taskModel = new \app\common\model\Task();
+        $tasklogModel = new \app\common\model\TaskLog();
+
+        $where = [];
+        $where["id"] = $task_id;
+        $taskInfo = $taskModel->where($where)->find();
+        if(!$taskInfo) {
+            return false;
+        }
+        if($taskInfo['is_show'] != 1){
+            return true;
+        }
+        // 添加/修改任务日志
+        $where = [];
+        $where["user_id"] = $user_id;
+        $where["task_id"] = $taskInfo["id"];
+
+        if($taskInfo["type_id"] == 2){
+            $where["finish_date"] = date("Ymd");
+        };
+
+        $tasklogInfo = $tasklogModel->where($where)->lock(true)->find();
+        if($tasklogInfo) {
+            if($tasklogInfo["finish_number"] >= $taskInfo["number"] || $tasklogInfo["is_finish"] == 1) {
+                return true;
+            }
+            $finish_number = $tasklogInfo["finish_number"]+$number;
+            $where = [];
+            $where["id"] = $tasklogInfo["id"];
+            $data = [];
+            $data["finish_number"] = $finish_number;
+            $data["pace"] = round($finish_number/$taskInfo["number"],2)*100;
+            $data["finish_date"] = date("Ymd");
+            if($finish_number >= $taskInfo["number"]) {
+                $data["is_finish"] = 1;
+                $data["finish_time"] = time();
+            }
+            $res = $tasklogModel->update($data,$where);
+        } else {
+            $data = [];
+            $data["user_id"] = $user_id;
+            $data["task_id"] = $taskInfo["id"];
+            $data["finish_number"] = $number;
+            $data["pace"] = round($number/$taskInfo["number"],2)*100;
+            $data["finish_date"] = date("Ymd");
+            if($number >= $taskInfo["number"]) {
+                $data["is_finish"] = 1;
+                $data["finish_time"] = time();
+            }
+            $data["createtime"] = time();
+            $res = $tasklogModel->insertGetId($data);
+        }
+        return $res;
+    }
+}

+ 16 - 3
application/common/model/Wallet.php

@@ -13,12 +13,19 @@ class Wallet extends BaseModel
     // 日志变动类型
     const log_type = [
         1  => '系统调节',//money + -
-        10  => '用户充值',//money + -
+        10  => '用户充值',//money +
         20 => '老年大学活动报名',//money + -
+        31 => '商城订单支付', //money -
+        32 => '商城订单退款', //money +
+
+        //善豆
+        101 => '签到', //bean +
+        102 => '完成任务', //bean +
     ];
     // 操作钱包余额类型
     const money_type = [
         'money' => '余额',
+        'bean' => '善豆',
     ];
 
     protected $message = '';
@@ -100,7 +107,10 @@ class Wallet extends BaseModel
         );
 
         //获取小数点
-        $point = $accountType == 'money' ? 2 : 0;
+        $point = 0;
+        if(in_array($accountType,['money','bean'])){
+            $point = 2;
+        }
         bcscale($point);
 
         //钱包名称
@@ -191,7 +201,10 @@ class Wallet extends BaseModel
     public function change(int $user_id, float $number, string $accountType = 'money', int $log_type = 0, string $remark = '', string $table = '', int $table_id = 0)
     {
         //获取小数点
-        $point = $accountType == 'money' ? 2 : 0;
+        $point = 0;
+        if(in_array($accountType,['money','bean'])){
+            $point = 2;
+        }
         bcscale($point);
 
         //钱包名称

+ 1 - 1
application/database.php

@@ -16,7 +16,7 @@ return [
     // 数据库类型
     'type'            => Env::get('database.type', 'mysql'),
     // 服务器地址
-    'hostname'        => Env::get('database.hostname', '106.54.206.212'),
+    'hostname'        => Env::get('database.hostname', '122.51.218.69'),
     // 数据库名
     'database'        => Env::get('database.database', 'xiaoshan'),
     // 用户名