浏览代码

Merge branch 'master' of http://git.huxiukeji.com/lizhen/xiaoshan

# Conflicts:
#	application/extra/redis.php
lizhen_gitee 4 月之前
父节点
当前提交
1ed36079de

+ 38 - 0
application/admin/controller/News.php

@@ -0,0 +1,38 @@
+<?php
+
+namespace app\admin\controller;
+
+use app\common\controller\Backend;
+
+/**
+ * 新闻资讯
+ *
+ * @icon fa fa-circle-o
+ */
+class News extends Backend
+{
+
+    /**
+     * News模型对象
+     * @var \app\admin\model\News
+     */
+    protected $model = null;
+
+    public function _initialize()
+    {
+        parent::_initialize();
+        $this->model = new \app\admin\model\News;
+        $this->view->assign("statusList", $this->model->getStatusList());
+        $this->view->assign("isHotList", $this->model->getIsHotList());
+    }
+
+
+
+    /**
+     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
+     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
+     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
+     */
+
+
+}

+ 23 - 0
application/admin/lang/zh-cn/news.php

@@ -0,0 +1,23 @@
+<?php
+
+return [
+    'Id'          => 'ID',
+    'Title'       => '新闻标题',
+    'Image'       => '列表封面图',
+    'Content'     => '内容',
+    'Weigh'       => '排序',
+    'Status'      => '状态',
+    'Status 0'    => '未发布',
+    'Set status to 0'=> '设为未发布',
+    'Status 1'    => '已发布',
+    'Set status to 1'=> '设为已发布',
+    'Status 3'    => '回收站',
+    'Set status to 3'=> '设为回收站',
+    'Is_hot'      => '热门',
+    'Is_hot 0'    => '否',
+    'Set is_hot to 0'=> '取消热门',
+    'Is_hot 1'    => '是',
+    'Set is_hot to 1'=> '设为热门',
+    'Create_time' => '创建时间',
+    'Update_time' => '更新时间'
+];

+ 86 - 0
application/admin/model/News.php

@@ -0,0 +1,86 @@
+<?php
+
+namespace app\admin\model;
+
+use think\Model;
+
+
+class News extends Model
+{
+
+    
+
+    
+
+    // 表名
+    protected $table = 'news';
+    
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = false;
+
+    // 定义时间戳字段名
+    protected $createTime = false;
+    protected $updateTime = false;
+    protected $deleteTime = false;
+
+    // 追加属性
+    protected $append = [
+        'status_text',
+        'create_time_text',
+        'update_time_text'
+    ];
+    
+
+    protected static function init()
+    {
+        self::afterInsert(function ($row) {
+            $pk = $row->getPk();
+            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
+        });
+    }
+
+    
+    public function getIsHotList()
+    {
+        return ['0' => __('Is_hot 0'), '1' => __('Is_hot 1')];
+    }
+
+    public function getStatusList()
+    {
+        return ['0' => __('Status 0'), '1' => __('Status 1')];
+    }
+
+
+    public function getStatusTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
+        $list = $this->getStatusList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+
+    public function getCreateTimeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
+        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
+    }
+
+
+    public function getUpdateTimeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
+        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
+    }
+
+    protected function setCreateTimeAttr($value)
+    {
+        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
+    }
+
+    protected function setUpdateTimeAttr($value)
+    {
+        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
+    }
+
+
+}

+ 27 - 0
application/admin/validate/News.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace app\admin\validate;
+
+use think\Validate;
+
+class News extends Validate
+{
+    /**
+     * 验证规则
+     */
+    protected $rule = [
+    ];
+    /**
+     * 提示消息
+     */
+    protected $message = [
+    ];
+    /**
+     * 验证场景
+     */
+    protected $scene = [
+        'add'  => [],
+        'edit' => [],
+    ];
+    
+}

+ 77 - 0
application/admin/view/news/add.html

@@ -0,0 +1,77 @@
+<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Title')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-title" data-rule="required" class="form-control" name="row[title]" type="text" value="">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <div class="input-group">
+                <input id="c-image" data-rule="required" class="form-control" size="50" name="row[image]" type="text" value="">
+                <div class="input-group-addon no-border no-padding">
+                    <span><button type="button" id="faupload-image" class="btn btn-danger faupload" data-input-id="c-image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp,image/webp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
+                    <span><button type="button" id="fachoose-image" class="btn btn-primary fachoose" data-input-id="c-image" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
+                </div>
+                <span class="msg-box n-right" for="c-image"></span>
+            </div>
+            <ul class="row list-inline faupload-preview" id="p-image"></ul>
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Content')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <textarea id="c-content" class="form-control editor" rows="5" name="row[content]" cols="50"></textarea>
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Weigh')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-weigh" data-rule="required" class="form-control" name="row[weigh]" type="number" value="0">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Is_hot')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            
+            <div class="radio">
+            {foreach name="isHotList" item="vo"}
+            <label for="row[is_hot]-{$key}"><input id="row[is_hot]-{$key}" name="row[is_hot]" type="radio" value="{$key}" {in name="key" value="0"}checked{/in} /> {$vo}</label>
+            {/foreach}
+            </div>
+
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
+        <div class="col-xs-12 col-sm-8">
+
+            <div class="radio">
+            {foreach name="statusList" item="vo"}
+            <label for="row[status]-{$key}"><input id="row[status]-{$key}" name="row[status]" type="radio" value="{$key}" {in name="key" value="0"}checked{/in} /> {$vo}</label>
+            {/foreach}
+            </div>
+
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Create_time')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-create_time" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[create_time]" type="text" value="{:date('Y-m-d H:i:s')}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Update_time')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-update_time" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[update_time]" type="text" value="{:date('Y-m-d H:i:s')}">
+        </div>
+    </div>
+    <div class="form-group layer-footer">
+        <label class="control-label col-xs-12 col-sm-2"></label>
+        <div class="col-xs-12 col-sm-8">
+            <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
+        </div>
+    </div>
+</form>

+ 77 - 0
application/admin/view/news/edit.html

@@ -0,0 +1,77 @@
+<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Title')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-title" data-rule="required" class="form-control" name="row[title]" type="text" value="{$row.title|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <div class="input-group">
+                <input id="c-image" data-rule="required" class="form-control" size="50" name="row[image]" type="text" value="{$row.image|htmlentities}">
+                <div class="input-group-addon no-border no-padding">
+                    <span><button type="button" id="faupload-image" class="btn btn-danger faupload" data-input-id="c-image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp,image/webp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
+                    <span><button type="button" id="fachoose-image" class="btn btn-primary fachoose" data-input-id="c-image" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
+                </div>
+                <span class="msg-box n-right" for="c-image"></span>
+            </div>
+            <ul class="row list-inline faupload-preview" id="p-image"></ul>
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Content')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <textarea id="c-content" class="form-control editor" rows="5" name="row[content]" cols="50">{$row.content|htmlentities}</textarea>
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Weigh')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-weigh" data-rule="required" class="form-control" name="row[weigh]" type="number" value="{$row.weigh|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Is_hot')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            
+            <div class="radio">
+            {foreach name="isHotList" item="vo"}
+            <label for="row[is_hot]-{$key}"><input id="row[is_hot]-{$key}" name="row[is_hot]" type="radio" value="{$key}" {in name="key" value="$row.is_hot"}checked{/in} /> {$vo}</label>
+            {/foreach}
+            </div>
+
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
+        <div class="col-xs-12 col-sm-8">
+
+            <div class="radio">
+            {foreach name="statusList" item="vo"}
+            <label for="row[status]-{$key}"><input id="row[status]-{$key}" name="row[status]" type="radio" value="{$key}" {in name="key" value="$row.status"}checked{/in} /> {$vo}</label>
+            {/foreach}
+            </div>
+
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Create_time')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-create_time" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[create_time]" type="text" value="{:$row.create_time?datetime($row.create_time):''}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Update_time')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-update_time" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[update_time]" type="text" value="{:$row.update_time?datetime($row.update_time):''}">
+        </div>
+    </div>
+    <div class="form-group layer-footer">
+        <label class="control-label col-xs-12 col-sm-2"></label>
+        <div class="col-xs-12 col-sm-8">
+            <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
+        </div>
+    </div>
+</form>

+ 46 - 0
application/admin/view/news/index.html

@@ -0,0 +1,46 @@
+<div class="panel panel-default panel-intro">
+    
+    <div class="panel-heading">
+        {:build_heading(null,FALSE)}
+        <ul class="nav nav-tabs" data-field="status">
+            <li class="{:$Think.get.status === null ? 'active' : ''}"><a href="#t-all" data-value="" data-toggle="tab">{:__('All')}</a></li>
+            {foreach name="statusList" item="vo"}
+            <li class="{:$Think.get.status === (string)$key ? 'active' : ''}"><a href="#t-{$key}" data-value="{$key}" data-toggle="tab">{$vo}</a></li>
+            {/foreach}
+        </ul>
+    </div>
+
+
+    <div class="panel-body">
+        <div id="myTabContent" class="tab-content">
+            <div class="tab-pane fade active in" id="one">
+                <div class="widget-body no-padding">
+                    <div id="toolbar" class="toolbar">
+                        <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
+                        <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('news/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
+<!--                        <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('news/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>-->
+<!--                        <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('news/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>-->
+                        
+
+                        <div class="dropdown btn-group {:$auth->check('news/multi')?'':'hide'}">
+                            <a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
+                            <ul class="dropdown-menu text-left" role="menu">
+                                {foreach name="statusList" item="vo"}
+                                <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:" data-params="status={$key}">{:__('Set status to ' . $key)}</a></li>
+                                {/foreach}
+                            </ul>
+                        </div>
+
+                        
+                    </div>
+                    <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
+                           data-operate-edit="{:$auth->check('news/edit')}"
+                           data-operate-del="{:$auth->check('news/del')}"
+                           width="100%">
+                    </table>
+                </div>
+            </div>
+
+        </div>
+    </div>
+</div>

+ 18 - 0
application/api/controller/Index.php

@@ -3,6 +3,7 @@
 namespace app\api\controller;
 
 use app\common\controller\Api;
+use think\Db;
 
 /**
  * 首页接口
@@ -20,4 +21,21 @@ class Index extends Api
     {
         $this->success('请求成功');
     }
+
+    // 新闻列表
+    public function news()
+    {
+        $is_hot = input('is_hot','');
+        $query = Db::name('news')->field('id,title,image,create_time');
+        if (in_array($is_hot,[0,1])){
+            $query->where('is_hot',$is_hot);
+        }
+        $list = $query->where('status',1)->order('weigh desc')->order('id desc')->autopage()->select();
+        foreach ($list as $k => $v) {
+            $list[$k]['image'] = cdnurl($v['image']);
+            $list[$k]['create_time_text'] = date('Y-m-d H:i',$v['create_time']);
+            $list[$k]['url'] = \app\utils\Common::getHttp('/index/index/news_detail/id/'.$v['id']);
+        }
+        return $this->success('success',$list);
+    }
 }

+ 62 - 161
application/api/controller/Notify.php

@@ -1,8 +1,10 @@
 <?php
+
 namespace app\api\controller;
 
 use app\common\controller\Api;
 use app\common\model\PayOrderModel;
+use app\common\model\Wallet;
 use app\utils\LogUtil;
 use think\Db;
 use addons\epay\library\Service;
@@ -26,124 +28,64 @@ class Notify extends Api
         LogUtil::getInstance('Api/'); //设置日志存入通道
     }
 
-    //人民币充值 异步回调对外方法
-    public function recharge_notify_base(){
-
+    // 余额充值 支付回调
+    public function recharge()
+    {
         //验签
-        $paytype = input('paytype','wechat');
-        $notify_file = $this->notify_log_start($paytype);
-        $pay = Service::checkNotify($paytype);
-        if (!$pay) {
-            echo '签名错误';
-            exit;
+        $pay_type = input('pay_type', 'wechat');
+        LogUtil::info("用户充值 {$pay_type}支付回调", self::LOG_MODULE, __FUNCTION__, $this->request->param());
+        if (!$pay = Service::checkNotify($pay_type)) {
+            LogUtil::info('签名错误', self::LOG_MODULE, __FUNCTION__);
+            return $this->error('签名错误 err01');
         }
 
         //验证,拿订单号等信息
-        $data = $pay->verify();
+        $data         = $pay->verify();
         $out_trade_no = $data['out_trade_no'];
-        //订单查询
-        $info = Db::name('pay_order')->where('out_trade_no',$out_trade_no)->find();
-
-        if(empty($info)){
-            echo $pay->success();
-            exit;
-        }
-
-        if($info['order_status'] != 0)
-        {
-            echo $pay->success();
-            exit;
-        }
-        //你可以在此编写订单逻辑
-        $rs = $this->recharge_notify_do($out_trade_no);
-        if($rs === false){
-            //不论结果都应返回success
-            echo $pay->success();
-            exit;
-        }else{
-            //不论结果都应返回success
-            echo $pay->success();
-            exit;
-        }
-
-        //默认
-        echo $pay->success();
-        exit;
-    }
-
-    //人民币充值 逻辑
-    private function recharge_notify_do($out_trade_no){
-
-        Db::startTrans();
-        $orderInfo = Db::name('pay_order')->where(['out_trade_no' => $out_trade_no])->lock(true)->find();
-        if (empty($orderInfo)) {
-            Db::rollback();
-            return false;
-        }
-
-        if($orderInfo['order_status'] != 0){
-            Db::rollback();
-            return false;
-        }
-
-        //逻辑开始
-        $order_amount = $orderInfo['order_amount'];
-        $result = model('Wallet')->lockChangeAccountRemain($orderInfo['user_id'],'money',$order_amount,10, '充值','pay_order',$orderInfo['id']);
-        if($result['status']===false)
-        {
-            Db::rollback();
-            return false;
-        }
-        //逻辑结束
-
-        //状态
-        $ros = Db::name('pay_order')->where(['out_trade_no' => $out_trade_no])->update(['order_status'=>1,'notifytime'=>time()]);
-        if($ros === false) {
-            Db::rollback();
-            return false;
+        [$res, $msg] = PayOrderModel::recharge($out_trade_no);
+        if (!$res) {
+            LogUtil::info($msg, self::LOG_MODULE, __FUNCTION__);
+            return $this->error('签名错误 err02');
         }
-
-        //默认提交
-        Db::commit();
-        return true;
+        LogUtil::info('处理成功', self::LOG_MODULE, __FUNCTION__);
+        return $pay->success();
     }
 
-
     //充值VIP 异步回调对外方法
-    public function vip_notify_base(){
+    public function vip_notify_base()
+    {
 
         //验签
-        $paytype = input('paytype','wechat');
+        $paytype     = input('paytype', 'wechat');
         $notify_file = $this->notify_log_start($paytype);
-        $pay = Service::checkNotify($paytype);
+        $pay         = Service::checkNotify($paytype);
         if (!$pay) {
             echo '签名错误';
             exit;
         }
 
         //验证,拿订单号等信息
-        $data = $pay->verify();
+        $data         = $pay->verify();
         $out_trade_no = $data['out_trade_no'];
         //订单查询
-        $info = Db::name('pay_order')->where('out_trade_no',$out_trade_no)->find();
+        $info = Db::name('pay_order')->where('out_trade_no', $out_trade_no)->find();
 
-        if(empty($info)){
+        if (empty($info)) {
             echo $pay->success();
             exit;
         }
 
-        if($info['order_status'] != 0)
-        {
+        if ($info['order_status'] != 0) {
             echo $pay->success();
             exit;
         }
         //你可以在此编写订单逻辑
         $rs = $this->vip_notify_do($out_trade_no);
-        if($rs === false){
+        if ($rs === false) {
             //不论结果都应返回success
             echo $pay->success();
             exit;
-        }else{
+        } else {
             //不论结果都应返回success
             echo $pay->success();
             exit;
@@ -155,7 +97,8 @@ class Notify extends Api
     }
 
     //充值金币 逻辑
-    private function vip_notify_do($out_trade_no){
+    private function vip_notify_do($out_trade_no)
+    {
 
         Db::startTrans();
         $orderInfo = Db::name('pay_order')->where(['out_trade_no' => $out_trade_no])->lock(true)->find();
@@ -164,43 +107,42 @@ class Notify extends Api
             return false;
         }
 
-        if($orderInfo['order_status'] != 0){
+        if ($orderInfo['order_status'] != 0) {
             Db::rollback();
             return false;
         }
 
         //逻辑开始
         //先充值
-        $args = json_decode($orderInfo['args'],true);
-        $user_info = Db::name('user_wallet')->where('user_id',$orderInfo['user_id'])->lock(true)->find();
-        if($user_info['vip_endtime'] < time()){
+        $args      = json_decode($orderInfo['args'], true);
+        $user_info = Db::name('user_wallet')->where('user_id', $orderInfo['user_id'])->lock(true)->find();
+        if ($user_info['vip_endtime'] < time()) {
             //过期了
             $vip_endtime = time() + (intval($args['days']) * 86400);
-            $vip_type = 1;
-        }else{
+            $vip_type    = 1;
+        } else {
             //追加vip
             $vip_endtime = $user_info['vip_endtime'] + (intval($args['days']) * 86400);
-            $vip_type = 2;
+            $vip_type    = 2;
         }
         $update_data = [
-            'vip_endtime'=>$vip_endtime,
+            'vip_endtime' => $vip_endtime,
         ];
-        $result = Db::name('user_wallet')->where('user_id',$orderInfo['user_id'])->update($update_data);
+        $result      = Db::name('user_wallet')->where('user_id', $orderInfo['user_id'])->update($update_data);
 
         //记录日志
         $log_data = [
-            'user_id' => $orderInfo['user_id'],
-            'before'  => $user_info['vip_endtime'],
-            'change_value'  => intval($args['days']) * 86400,
-            'remain'  => $vip_endtime,
-            'remark'  => '购买vip',
-            'createtime'  => time(),
-            'vip_type'  => $vip_type,
+            'user_id'      => $orderInfo['user_id'],
+            'before'       => $user_info['vip_endtime'],
+            'change_value' => intval($args['days']) * 86400,
+            'remain'       => $vip_endtime,
+            'remark'       => '购买vip',
+            'createtime'   => time(),
+            'vip_type'     => $vip_type,
         ];
         Db::name('user_vip_log')->insertGetId($log_data);
 
-        if($result === false)
-        {
+        if ($result === false) {
             Db::rollback();
             return false;
         }
@@ -209,8 +151,8 @@ class Notify extends Api
         //逻辑结束
 
         //状态
-        $ros = Db::name('pay_order')->where(['out_trade_no' => $out_trade_no])->update(['order_status'=>1,'notifytime'=>time()]);
-        if($ros === false) {
+        $ros = Db::name('pay_order')->where(['out_trade_no' => $out_trade_no])->update(['order_status' => 1, 'notifytime' => time()]);
+        if ($ros === false) {
             Db::rollback();
             return false;
         }
@@ -220,87 +162,46 @@ class Notify extends Api
         return true;
     }
 
-
     //异步日志
-    private function notify_log_start($paytype = 'wechat'){
+    private function notify_log_start($paytype = 'wechat')
+    {
         //记录支付回调数据
         ignore_user_abort(); // run script in background
         set_time_limit(30);
         // 日志文件 start
-        $log_base_dir = '../paylog/'.$paytype.'/';
-        if (!is_dir($log_base_dir))
-        {
+        $log_base_dir = '../paylog/' . $paytype . '/';
+        if (!is_dir($log_base_dir)) {
             mkdir($log_base_dir, 0770, true);
             @chmod($log_base_dir, 0770);
         }
-        $notify_file = $log_base_dir.'notify.txt';
-        if(!file_exists($notify_file)) {
+        $notify_file = $log_base_dir . 'notify.txt';
+        if (!file_exists($notify_file)) {
             @touch($notify_file);
             @chmod($notify_file, 0770);
         }
-        if(filesize($notify_file)>5242880)//大于5M自动切换
+        if (filesize($notify_file) > 5242880)//大于5M自动切换
         {
-            rename($notify_file, $log_base_dir.'notify_'.date('Y_m_d_H_i_s').'.txt');
+            rename($notify_file, $log_base_dir . 'notify_' . date('Y_m_d_H_i_s') . '.txt');
         }
-        if(!file_exists($notify_file)) {
+        if (!file_exists($notify_file)) {
             @touch($notify_file);
             @chmod($notify_file, 0770);
         }
         // 日志文件 end
         //开始写入
         $_REQUEST = isset($_REQUEST) ? $_REQUEST : array();
-        if($_REQUEST && $paytype == 'alipay') {
-            file_put_contents($notify_file, "\r\n\r\n".date('Y-m-d H:i:s')." [notify][入口接收request]".json_encode($_REQUEST), FILE_APPEND);
+        if ($_REQUEST && $paytype == 'alipay') {
+            file_put_contents($notify_file, "\r\n\r\n" . date('Y-m-d H:i:s') . " [notify][入口接收request]" . json_encode($_REQUEST), FILE_APPEND);
         } else {
             $xml = file_get_contents("php://input");
-            file_put_contents($notify_file, "\r\n\r\n".date('Y-m-d H:i:s')." [notify][入口接收php://input流原始数据] \n".$xml, FILE_APPEND);
+            file_put_contents($notify_file, "\r\n\r\n" . date('Y-m-d H:i:s') . " [notify][入口接收php://input流原始数据] \n" . $xml, FILE_APPEND);
             $xmlObj = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
-            file_put_contents($notify_file, "\r\n\r\n".date('Y-m-d H:i:s')." [notify][入口接收php://input流] ".json_encode($xmlObj), FILE_APPEND);
+            file_put_contents($notify_file, "\r\n\r\n" . date('Y-m-d H:i:s') . " [notify][入口接收php://input流] " . json_encode($xmlObj), FILE_APPEND);
         }
 
-        ini_set('display_errors','On');
+        ini_set('display_errors', 'On');
 
         return $notify_file;
 
     }
-
-    // 老年大学活动报名支付回调
-    public function university_event_wechat()
-    {
-        LogUtil::info('老年大学活动 微信支付回调', self::LOG_MODULE,__FUNCTION__, $this->request->param());
-        $pay = Service::checkNotify('wechat');
-        if (!$pay){
-            LogUtil::info('签名错误', self::LOG_MODULE,__FUNCTION__);
-            return $this->error('签名错误 err01');
-        }
-        $data = $pay->verify();
-        $out_trade_no = $data['out_trade_no'];
-        [$res,$msg] = PayOrderModel::university_event($out_trade_no);
-        if (!$res){
-            LogUtil::info($msg, self::LOG_MODULE,__FUNCTION__);
-            return $this->error('签名错误 err02');
-        }
-        LogUtil::info('处理成功', self::LOG_MODULE,__FUNCTION__);
-        return $pay->success();
-    }
-
-    // 老年大学活动报名支付回调
-    public function university_event_alipay()
-    {
-        LogUtil::info('老年大学活动 支付宝支付回调', self::LOG_MODULE,__FUNCTION__, $this->request->param());
-        $pay = Service::checkNotify('alipay');
-        if (!$pay){
-            LogUtil::info('签名错误', self::LOG_MODULE,__FUNCTION__);
-            return $this->error('签名错误 err01');
-        }
-        $data = $pay->verify();
-        $out_trade_no = $data['out_trade_no'];
-        [$res,$msg] = PayOrderModel::university_event($out_trade_no);
-        if (!$res){
-            LogUtil::info($msg, self::LOG_MODULE,__FUNCTION__);
-            return $this->error('签名错误 err02');
-        }
-        LogUtil::info('处理成功', self::LOG_MODULE,__FUNCTION__);
-        return $pay->success();
-    }
 }

+ 100 - 101
application/api/controller/Pay.php

@@ -3,8 +3,11 @@
 namespace app\api\controller;
 
 use app\common\controller\Api;
+use app\common\model\Wallet;
+use app\utils\CurlUtil;
 use think\Db;
 use addons\epay\library\Service;
+
 /**
  * 充值配置与充值订单
  */
@@ -14,167 +17,163 @@ class Pay extends Api
     protected $noNeedRight = ['*'];
 
     //vip用的
-    public function vip_config(){
-        $list = Db::name('payvip_config')->order('weigh asc,id asc')->select();
-        $data['vipconfig'] = $list;
-        $data['vip_endtime'] = model('wallet')->getWallet($this->auth->id,'vip_endtime');
-        $data['is_vip'] = $data['vip_endtime'] > time() ? 1 : 0;
-        $data['avatar'] = localpath_to_netpath($this->auth->avatar);
-        $this->success('success',$data);
+    public function vip_config()
+    {
+        $list                = Db::name('payvip_config')->order('weigh asc,id asc')->select();
+        $data['vipconfig']   = $list;
+        $data['vip_endtime'] = model('wallet')->getWallet($this->auth->id, 'vip_endtime');
+        $data['is_vip']      = $data['vip_endtime'] > time() ? 1 : 0;
+        $data['avatar']      = localpath_to_netpath($this->auth->avatar);
+        $this->success('success', $data);
     }
 
     //vip用的,创建订单
-    public function vip_recharge(){
+    public function vip_recharge()
+    {
 
-        $rc_id = input('rc_id',0);
-        $pay_type = input('pay_type','wechat');
+        $rc_id    = input('rc_id', 0);
+        $pay_type = input('pay_type', 'wechat');
         $platform = 'app';
-        $uid = $this->auth->id;
+        $uid      = $this->auth->id;
 
-        if(!$rc_id){
+        if (!$rc_id) {
             $this->error('请选择会员套餐');
         }
 
-        if(!$this->user_auth_limit()){
+        if (!$this->user_auth_limit()) {
             $this->error('请先完成实名认证');
         }
 
 
         //赋值money
-        $recharge_config = Db::name('payvip_config')->where('id',$rc_id)->find();
-        $money = $recharge_config['money'];
+        $recharge_config = Db::name('payvip_config')->where('id', $rc_id)->find();
+        $money           = $recharge_config['money'];
 
-        if($money<=0)
-        {
+        if ($money <= 0) {
             $this->error('支付金额必须大于0');
         }
-        if($money > 10000){
+        if ($money > 10000) {
             $this->error('支付金额太大');
         }
 
 
         //创建订单
-        $data = [];
-        $data['user_id'] = $uid;
-        $data['out_trade_no'] = createUniqueNo('P',$uid); // 数据库订单号加密
+        $data                 = [];
+        $data['user_id']      = $uid;
+        $data['out_trade_no'] = createUniqueNo('P', $uid); // 数据库订单号加密
         $data['order_amount'] = $money;
-        $data['createtime'] = time();
+        $data['createtime']   = time();
 
-        $data['pay_type'] = $pay_type;
-        $data['platform'] = $platform;
+        $data['pay_type']     = $pay_type;
+        $data['platform']     = $platform;
         $data['order_status'] = 0;
-        $data['table_name'] = 'vip_recharge';
-        $data['table_id'] = 0;
-        $data['args'] = json_encode(['days'=>$recharge_config['days']]);
+        $data['table_name']   = 'vip_recharge';
+        $data['table_id']     = 0;
+        $data['args']         = json_encode(['days' => $recharge_config['days']]);
 
         $orderid = Db::name('pay_order')->insertGetId($data);
 
 //        $openid = $this->auth->mini_openid;
         //下单
         $params = [
-            'type'         => $pay_type,
-            'orderid'      => $data['out_trade_no'],
-            'title'        => '支付订单',
-            'amount'       => $data['order_amount'],
-            'method'       => $platform,
+            'type'      => $pay_type,
+            'orderid'   => $data['out_trade_no'],
+            'title'     => '支付订单',
+            'amount'    => $data['order_amount'],
+            'method'    => $platform,
 //            'openid'       => $openid,
-            'notifyurl' => config('pay_notify_url').'/api/notify/vip_notify_base/paytype/'.$pay_type,
+            'notifyurl' => config('pay_notify_url') . '/api/notify/vip_notify_base/paytype/' . $pay_type,
             'returnurl' => '',
         ];
 
         $res = Service::submitOrder($params);
 
-        if($pay_type == 'wechat'){
-            $this->success('success',json_decode($res,true));
-        }else{
-            $this->success('success',$res);
+        if ($pay_type == 'wechat') {
+            $this->success('success', json_decode($res, true));
+        } else {
+            $this->success('success', $res);
         }
     }
 
-
-
     //人民币充值
-    public function money_config(){
-        $list = Db::name('paymoney_config')->order('weigh asc,id asc')->where('is_show',1)->select();
-        $data['config'] = $list;
-
-        $wallet = model('wallet')->getWallet($this->auth->id);
+    public function money_config()
+    {
+        $wallet         = (new Wallet())->getWallet($this->auth->id);
         $data['wallet'] = $wallet;
-        $this->success('success',$data);
+        $data['recharge_explain'] = config('site.recharge_explain');
+        $list           = Db::name('paymoney_config')->order('weigh asc,id asc')->where('is_show', 1)->select();
+        $data['config'] = $list;
+        $this->success('success', $data);
     }
 
     //人民币充值 创建订单
-    public function money_recharge(){
-
-        $rc_id     = input('rc_id',0);
-        $pay_type  = input('pay_type','wechat');
-        $platform  = 'app';
-        $freemoney = input('freemoney',0);
-        $uid = $this->auth->id;
-
-        if(!$rc_id && !$freemoney){
+    public function money_recharge()
+    {
+        $rc_id      = input('rc_id', 0);
+        $pay_type   = input('pay_type', 'wechat');
+        $platform   = input('platform', 'app');
+        $free_money = input('free_money', 0);
+        $user_id        = $this->auth->id;
+        if (!$rc_id && !$free_money) {
             $this->error('请选择或填写充值金额');
         }
 
-        //赋值money
-        if($rc_id){
-            $recharge_config = Db::name('paymoney_config')->where('id',$rc_id)->find();
-            $money = $recharge_config['money'] ?: 0;
-        }
-
-        //自由输入覆盖
-        if(!empty($freemoney)){
-            $rc_id = 0;
-            $money = floatval($freemoney);
+        if ($rc_id) {
+            //赋值money
+            $recharge_config = Db::name('paymoney_config')->where('id', $rc_id)->find();
+            $money           = $recharge_config['money'] ?: 0;
+        } else {
+            //自由输入覆盖
+            $money = floatval($free_money);
         }
 
-        //
-        if($money<=0)
-        {
+        if ($money <= 0) {
             $this->error('支付金额必须大于0');
         }
-        if($money > 10000){
+        if ($money > 10000) {
             $this->error('支付金额太大');
         }
 
-        //创建订单
-        $data = [];
-        $data['user_id'] = $uid;
-        $data['out_trade_no'] = createUniqueNo('M',$uid); // 数据库订单号加密
-        $data['order_amount'] = $money;
-        $data['createtime'] = time();
-
-        $data['pay_type'] = $pay_type;
-        $data['platform'] = $platform;
-        $data['order_status'] = 0;
-        $data['table_name'] = 'money_recharge';
-        $data['table_id'] = 0;
-        $data['args'] = '';
-
-        $orderid = Db::name('pay_order')->insertGetId($data);
+        // 创建支付订单
+        $remark    = '充值订单';
+        $orderData = [
+            'user_id'      => $user_id,
+            'out_trade_no' => createUniqueNo('M', $user_id),
+            'order_amount' => $money,
+            'pay_type'     => $pay_type,
+            'platform'     => $platform,
+            'table_name'   => 'money_recharge',
+            'table_id'     => 0,
+            'createtime'   => time(),
+            'args'         => json_encode([
+                'table_id' => 0,
+                'money'    => $money,
+                'remark'   => $remark
+            ], JSON_UNESCAPED_UNICODE),
+        ];
+        if (!Db::name('pay_order')->insert($orderData)) {
+            return $this->error('订单创建失败');
+        }
 
-//        $openid = $this->auth->mini_openid;
-        //下单
+        // 第三方支付下单
         $params = [
-            'type'         => $pay_type,
-            'orderid'      => $data['out_trade_no'],
-            'title'        => '充值订单',
-            'amount'       => $data['order_amount'],
-            'method'       => $platform,
-//            'openid'       => $openid,
-            'notifyurl' => config('pay_notify_url').'/api/notify/recharge_notify_base/paytype/'.$pay_type,
+            'type'      => $orderData['pay_type'],
+            'orderid'   => $orderData['out_trade_no'],
+            'title'     => $remark,
+            'amount'    => $orderData['order_amount'],
+            'method'    => $orderData['platform'],
+            'notifyurl' => CurlUtil::getHttp("/api/notify/recharge/pay_type/{$pay_type}"),
             'returnurl' => '',
         ];
-
+        // 如果是小程序则需要添加 openid
+        if ($pay_type == 'wechat' && $platform == 'miniapp') {
+            $params['openid'] = $this->auth->mini_openid;
+        }
         $res = Service::submitOrder($params);
-
-        if($pay_type == 'wechat'){
-            $this->success('success',json_decode($res,true));
-        }else{
-            $this->success('success',$res);
+        if ($pay_type == 'wechat') {
+            $this->success('success', json_decode($res, true));
+        } else {
+            $this->success('success', $res);
         }
     }
-
-
-
 }

+ 209 - 0
application/api/controller/UniversityCourse.php

@@ -0,0 +1,209 @@
+<?php
+
+namespace app\api\controller;
+
+use addons\epay\library\Service;
+use app\common\controller\Api;
+use app\common\model\PayOrderModel;
+use app\common\model\UniversityCourseModel;
+use app\common\model\UniversityEventModel;
+use app\common\model\Wallet;
+use app\utils\CurlUtil;
+use app\utils\Service\Tencent\TencentIm;
+use think\Db;
+
+/**
+ * 老年大学 活动板块
+ */
+class UniversityCourse extends Api
+{
+    protected $noNeedLogin = [''];
+    protected $noNeedRight = ['*'];
+
+    // 活动列表
+    public function list()
+    {
+        $user_id = $this->auth->id;
+        $list    = UniversityCourseModel::with([
+            'apply' => function ($query) use ($user_id) {
+                $query->field('id,event_id,user_id')->where('user_id', $user_id)->where('status', 1);
+            }
+        ])
+            ->field('id,name,price,image,start_apply_time,end_apply_time,start_time,address')
+            ->where('status', 1)
+            ->order('id desc')
+            ->autopage()
+            ->select();
+        foreach ($list as $k => $v) {
+            $list[$k]['start_apply_time'] = date('Y-m-d H:i', $v['start_apply_time']);
+            $list[$k]['end_apply_time']   = date('Y-m-d H:i', $v['end_apply_time']);
+            $list[$k]['start_time']       = date('Y-m-d H:i', $v['start_time']);
+            $list[$k]['apply']            = !empty($v['apply']) ? 1 : 0;
+        }
+        return $this->success('success', $list);
+    }
+
+    // 活动详情
+    public function info()
+    {
+        $params = $this->request->param();
+        if (empty($params['event_id'])) {
+            return $this->error('参数缺失');
+        }
+        $user_id = $this->auth->id;
+
+        $info                     = UniversityEventModel::with([
+            'apply' => function ($query) use ($user_id) {
+                $query->field('id,event_id,user_id')->where('user_id', $user_id)->where('status', 1);
+            }
+        ])
+            ->field('id,name,price,image,images,start_apply_time,end_apply_time,start_time,address,content')
+            ->where('id', $params['event_id'])
+            ->where('status', 1)
+            ->order('id desc')
+            ->find();
+        $info['start_apply_time'] = date('Y-m-d', $info['start_apply_time']);
+        $info['end_apply_time']   = date('Y-m-d', $info['end_apply_time']);
+        $info['start_time']       = date('Y-m-d', $info['start_time']);
+        $info['apply']            = !empty($info['apply']) ? 1 : 0;
+        return $this->success('success', $info);
+    }
+
+    public function apply()
+    {
+        $params = $this->request->param();
+        if (empty($params['event_id'])) {
+            return $this->error('参数缺失');
+        }
+        if (empty($params['pay_type']) || empty($params['platform'])) {
+            return $this->error('请选择支付方式');
+        }
+        if (empty($params['apply_list'])) {
+            return $this->error('请提交报名信息');
+        }
+        foreach ($params['apply_list'] as $k => $v) {
+            if (empty($v['name'])) {
+                return $this->error('报名信息姓名不能为空');
+            }
+            if (empty($v['phone'])) {
+                return $this->error('报名信息手机号不能为空');
+            }
+        }
+        $user_id = $this->auth->id;
+        $info    = UniversityEventModel::with([
+            'apply' => function ($query) use ($user_id) {
+                $query->field('id,event_id,user_id')->where('user_id', $user_id)->where('status', 1);
+            }
+        ])
+            ->field('id,name,price,image,images,start_apply_time,end_apply_time,start_time,address,content')
+            ->where('id', $params['event_id'])
+            ->where('status', 1)
+            ->order('id desc')
+            ->find();
+        if (!$info) {
+            return $this->error('活动不存在');
+        }
+        if (!empty($info['apply'])) {
+            return $this->error('您已报过名了');
+        }
+        $nowTime = time();
+        if ($info['start_apply_time'] > $nowTime) {
+            return $this->error('报名未开始');
+        }
+        if ($info['end_apply_time'] < $nowTime) {
+            return $this->error('报名已结束');
+        }
+        // 开始报名
+        $num  = count($params['apply_list']);
+        $data = [
+            'user_id'     => $user_id,
+            'event_id'    => $params['event_id'],
+            'order_no'    => createUniqueNo('E', $user_id),
+            'pay_amount'  => bcmul($info['price'], $num, 2),
+            'create_time' => $nowTime
+        ];
+        Db::startTrans();
+        $apply_id = Db::name('university_event_apply')->insertGetId($data);
+        if (!$apply_id) {
+            Db::rollback();
+            return $this->error('订单创建失败');
+        }
+        $apply_info = [];
+        foreach ($params['apply_list'] as $k => $v) {
+            $apply_info[] = [
+                'user_id'  => $user_id,
+                'event_id' => $params['event_id'],
+                'order_id' => $apply_id,
+                'order_no' => $data['order_no'],
+                'name'     => $v['name'],
+                'phone'    => $v['phone']
+            ];
+        }
+        if (!Db::name('university_event_info')->insertAll($apply_info)) {
+            Db::rollback();
+            return $this->error('订单创建失败');
+        }
+        Db::commit();
+
+        // 创建支付订单
+        $remark    = '老年大学活动报名';
+        $orderData = [
+            'user_id'      => $user_id,
+            'out_trade_no' => $data['order_no'],
+            'order_amount' => $data['pay_amount'],
+            'pay_type'     => $params['pay_type'],
+            'platform'     => $params['platform'],
+            'table_name'   => 'university_event_apply',
+            'table_id'     => $apply_id,
+            'createtime'   => time(),
+            'args'         => json_encode([
+                'table_id' => $apply_id,
+                'remark'   => $remark
+            ], JSON_UNESCAPED_UNICODE),
+        ];
+        if (!Db::name('pay_order')->insert($orderData)) {
+            return $this->error('订单创建失败');
+        }
+
+        // 拉起支付 余额支付
+        if ($params['pay_type'] == 'wallet') {
+            Db::startTrans();
+            //钱包更新
+            $walletService = new Wallet();
+            if (!$walletService->change($user_id, -$orderData['order_amount'], 'money', 20, $remark, $orderData['table_name'], $orderData['table_id'])) {
+                Db::rollback();
+                return $this->error($walletService->getMessage());
+            }
+            // 支付成功,更改支付金额
+            [$res,$msg] = PayOrderModel::university_event($orderData['out_trade_no']);
+            if (!$res){
+                Db::rollback();
+                return $this->error($msg);
+            }
+            Db::commit();
+            return $this->success('支付成功');
+        }
+
+        // 第三方支付下单
+        $params = [
+            'type'      => $orderData['pay_type'],
+            'orderid'   => $orderData['out_trade_no'],
+            'title'     => $remark,
+            'amount'    => $orderData['order_amount'],
+            'method'    => $orderData['platform'],
+            'notifyurl' => CurlUtil::getHttp("/api/notify/university_event_{$params['pay_type']}"),
+            'returnurl' => '',
+        ];
+        // 如果是小程序则需要添加 openid
+        if ($params['pay_type'] == 'wechat' && $params['platform'] == 'miniapp') {
+            $params['openid'] = $this->auth->mini_openid;
+        }
+        $res = Service::submitOrder($params);
+        if ($params['pay_type'] == 'wechat') {
+            $this->success('success', json_decode($res, true));
+        } else {
+            $this->success('success', $res);
+        }
+    }
+
+}

+ 9 - 1
application/api/controller/UniversityEvent.php

@@ -87,6 +87,12 @@ class UniversityEvent extends Api
             if (empty($v['phone'])) {
                 return $this->error('报名信息手机号不能为空');
             }
+            if (empty($v['sex'])) {
+                return $this->error('报名信息性别不能为空');
+            }
+            if (empty($v['age'])) {
+                return $this->error('报名信息年龄不能为空');
+            }
         }
         $user_id = $this->auth->id;
         $info    = UniversityEventModel::with([
@@ -135,7 +141,9 @@ class UniversityEvent extends Api
                 'order_id' => $apply_id,
                 'order_no' => $data['order_no'],
                 'name'     => $v['name'],
-                'phone'    => $v['phone']
+                'phone'    => $v['phone'],
+                'sex'      => $v['sex'],
+                'age'      => $v['age'],
             ];
         }
         if (!Db::name('university_event_info')->insertAll($apply_info)) {

+ 0 - 2
application/api/controller/User.php

@@ -347,8 +347,6 @@ class User extends Api
         $this->success();
     }
 
-
-
     /**
      * 修改手机号
      *

+ 3 - 1
application/common/library/Auth.php

@@ -4,6 +4,7 @@ namespace app\common\library;
 
 use app\common\model\User;
 use app\common\model\UserRule;
+use app\common\model\Wallet;
 use fast\Random;
 use think\Config;
 use think\Db;
@@ -26,7 +27,7 @@ class Auth
     //默认配置
     protected $config = [];
     protected $options = [];
-    protected $allowFields = ['id', 'username', 'nickname', 'mobile', 'avatar', 'group_id'];
+    protected $allowFields = ['id', 'username', 'nickname', 'mobile', 'avatar', 'group_id','idcard_status'];
 
     public function __construct($options = [])
     {
@@ -402,6 +403,7 @@ class Auth
 
         $userinfo['avatar'] = localpath_to_netpath($userinfo['avatar']);
         $userinfo['chat_id'] = im_prefix($userinfo['id']);
+        $userinfo['balance'] = (new Wallet())->getWallet($userinfo['id'],'money');
         return $userinfo;
     }
 

+ 42 - 3
application/common/model/PayOrderModel.php

@@ -19,6 +19,44 @@ class PayOrderModel extends Model
     protected $updateTime = false;
     protected $deleteTime = false;
 
+    /**
+     * 余额充值支付回调
+     * @param $out_trade_no
+     * @return array
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public static function recharge($out_trade_no)
+    {
+        Db::startTrans();
+        if (!$order = self::where('out_trade_no',$out_trade_no)->lock(true)->find()) {
+            Db::rollback();
+            return [false,'未找到订单'];
+        }
+
+        if ($order['order_status'] != 0) {
+            Db::rollback();
+            return [true,'订单已支付'];
+        }
+
+        //更新订单状态
+        if (!self::where(['out_trade_no' => $out_trade_no])->update(['order_status' => 1, 'notifytime' => time()])) {
+            Db::rollback();
+            return [false,'订单状态更新失败'];
+        }
+
+        //钱包更新
+        $walletService = new Wallet();
+        if (!$walletService->change($order['user_id'], $order['order_amount'], 'money', 10, '充值', 'pay_order', $order['table_id'])) {
+            Db::rollback();
+            return [false,'余额充值失败'];
+        }
+        Db::commit();
+        return [true,'操作成功'];
+    }
 
     /**
      * 老年大学活动支付回调
@@ -27,14 +65,15 @@ class PayOrderModel extends Model
      */
     public static function university_event($out_trade_no)
     {
-        if (!$info = self::where('out_trade_no',$out_trade_no)->find()){
+        Db::startTrans();
+        if (!$info = self::where('out_trade_no',$out_trade_no)->lock(true)->find()){
+            Db::rollback();
             return [false,'未找到订单'];
         }
         if ($info['order_status'] == 1){
+            Db::rollback();
             return [true,'订单已支付'];
         }
-
-        Db::startTrans();
         //更新订单状态
         if (!self::where(['id' => $info['id']])->update(['status' => 1])) {
             Db::rollback();

+ 27 - 0
application/common/model/UniversityCourseApplyModel.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace app\common\model;
+
+use think\Db;
+use think\Model;
+
+/**
+ * 群组
+ */
+class UniversityCourseApplyModel extends Model
+{
+    // 表名
+    protected $name = 'university_event_apply';
+    // 开启自动写入时间戳字段
+    protected $autoWriteTimestamp = false;
+    // 定义时间戳字段名
+    protected $createTime = false;
+    protected $updateTime = false;
+    protected $deleteTime = false;
+
+
+    public function user()
+    {
+        return $this->hasOne(UserModel::class, 'id', 'user_id');
+    }
+}

+ 40 - 0
application/common/model/UniversityCourseModel.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace app\common\model;
+
+use think\Db;
+use think\Model;
+
+/**
+ * 群组
+ */
+class UniversityCourseModel extends Model
+{
+    // 表名
+    protected $name = 'university_event';
+    // 开启自动写入时间戳字段
+    protected $autoWriteTimestamp = false;
+    // 定义时间戳字段名
+    protected $createTime = false;
+    protected $updateTime = false;
+    protected $deleteTime = false;
+
+    public function getImageAttr($value, $data)
+    {
+        return cdnurl($value);
+    }
+
+    public function getImagesAttr($value, $data)
+    {
+        $value = explode(',',$value);
+        foreach ($value as &$v){
+            $v = cdnurl($v);
+        }
+        return $value;
+    }
+
+    public function apply()
+    {
+        return $this->hasOne(UniversityEventApplyModel::class, 'event_id', 'id');
+    }
+}

+ 8 - 6
application/common/model/Wallet.php

@@ -13,6 +13,7 @@ class Wallet extends Model
     // 日志变动类型
     const log_type = [
         1  => '系统调节',//money + -
+        10  => '用户充值',//money + -
         20 => '老年大学活动报名',//money + -
     ];
     // 操作钱包余额类型
@@ -48,15 +49,14 @@ class Wallet extends Model
 
     /**
      * 获取钱包余额
-     * @param string $username 用户编号
+     * @param int $user_id 用户编号
      * @param string $wallet_name 指定钱包名
      * @return array|float
      */
-    public function getWallet($user_id = '', $wallet_name = '')
+    public function getWallet($user_id = 0, $wallet_name = '')
     {
         //所有钱包余额
-        $wallet = Db::name('user_wallet')->lock(true)->where(['user_id' => $user_id])->find();
-        if (!$wallet) {
+        if (!$wallet = Db::name('user_wallet')->where(['user_id' => $user_id])->find()) {
             abort(500, '钱包余额获取失败');
         }
 
@@ -250,8 +250,10 @@ class Wallet extends Model
         return $this->message;
     }
 
-    public function getData()
+    public function getData($name = null)
     {
-        return $this->data;
+        $data = $this->data;
+        !empty($name) && $data = $this->data[$name];
+        return $data;
     }
 }

+ 4 - 0
application/extra/site.php

@@ -30,6 +30,7 @@ return array (
     'website' => '全站基础配置',
     'userandroid' => '用户端安卓版本',
     'userios' => '用户端苹果版本',
+    'explain' => '说明配置',
   ),
   'mail_type' => '1',
   'mail_smtp_host' => 'smtp.qq.com',
@@ -60,4 +61,7 @@ return array (
   'user_ios_update_info' => '界是你没有挽过的船新版本',
   'user_ios_pay_sandbox' => '0',
   'user_default_avatar' => '/uploads/20241019/244017dc8c5a698037da7bab78da2d34.png',
+  'recharge_explain' => '1.充值金额只能在小善·潘多港湾中使用。
+2.充值金额无法提现,无法找零。
+3.充值金额永久有效',
 );

+ 12 - 0
application/index/controller/Index.php

@@ -16,6 +16,18 @@ class Index extends Controller
         return $this->view->fetch();
     }
 
+    // 新闻详情
+    public function news_detail()
+    {
+        $id = input('id',0,'intval');
+        $info = Db::name('news')->field('id,title,content,create_time')->where('id',$id)->where('status',1)->find();
+        if($info){
+            $info['create_time_text'] = date('Y-m-d H:i',$info['create_time']);
+        }
+        $this->view->assign('info', $info);
+        return $this->view->fetch();
+    }
+
     /**
      * app下载页
      * 判断是安卓还是ios

+ 1 - 1
application/index/view/index/appdownload.html

@@ -4,7 +4,7 @@
 <head>
     <meta charset="UTF-8">
     <meta http-equiv="X-UA-Compatible" content="IE=edge">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
     <title>APP下载</title>
     <script src="../../assets/js/fontSize.js"></script>
 </head>

+ 1 - 1
application/index/view/index/basedata.html

@@ -3,7 +3,7 @@
 <head>
     <meta charset="UTF-8">
     <meta http-equiv="X-UA-Compatible" content="IE=edge">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
     <title>Document</title>
     <style>
         html, body, div, span, applet, object, iframe,

+ 1 - 1
application/index/view/index/index.html

@@ -5,7 +5,7 @@
 
     <meta charset="utf-8">
     <meta http-equiv="X-UA-Compatible" content="IE=edge">
-    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
 
     <title>{$site.name|htmlentities}</title>
     <link rel="shortcut icon" href="__CDN__/assets/img/favicon.ico"/>

+ 77 - 0
application/index/view/index/news_detail.html

@@ -0,0 +1,77 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
+    <title>{$info['title'] ?? ''}</title>
+    <link rel="shortcut icon" href="__CDN__/assets/img/favicon.ico"/>
+    <style>
+        html, body, div, span, applet, object, iframe,
+        h1, h2, h3, h4, h5, h6, p, blockquote, pre,
+        a, abbr, acronym, address, big, cite, code,
+        del, dfn, em, img, ins, kbd, q, s, samp,
+        small, strike,  sub, sup, tt, var,
+        u, i, center,
+        dl, dt, dd, ol, ul, li,
+        fieldset, form, label, legend,
+        table, caption, tbody, tfoot, thead, tr, th, td,
+        article, aside, canvas, details, embed,
+        figure, figcaption, footer, header, hgroup,
+        menu, nav, output, ruby, section, summary,
+        time, mark, audio, video {
+            margin: 0;
+            padding: 0;
+            border: 0;
+            font-size: 100%;
+            font: inherit;
+            vertical-align: baseline;
+            box-sizing: border-box;
+            font-family: Source Han Sans CN;
+        }
+        .title{
+            font-weight: 600;
+            font-size: 18px;
+            color: #0a0a0a;
+            padding: 5px 10px;
+        }
+        .time{
+            font-size: 12px;
+            color: #999999;
+            font-weight: 400;
+            padding: 5px 10px;
+        }
+        .page{
+            padding: 10px;
+            font-size: 14px;
+            line-height: 25px;
+            color:#333;
+        }
+    </style>
+</head>
+<body>
+<div class="title">{$info['title'] ?? ''}</div>
+<div class="time">{$info['create_time_text'] ?? ''}</div>
+<div class="page">
+    {$info['content'] ?? ''}
+</div>
+<script src="/assets/js/jquery-3.1.1.min.js"></script>
+<script>
+    function replaceDetail(){
+        var details = $('.page').html();
+        //newContent仅是details替换后内容;
+        let newContent = details.replace(/<img[^>]*>/gi, function (match, capture) { //去除三标签
+            match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
+            match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
+            match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
+            return match;
+        });
+        newContent = newContent.replace(/<br[^>]*\/>/gi, '');
+        newContent = newContent.replace(/<img/gi, '<img style="max-width:100%;height:auto;display:block;margin:0 auto;"');
+        $('.page').html('');
+        $('.page').html(newContent);
+    }
+    replaceDetail();
+</script>
+</body>
+</html>

+ 60 - 0
public/assets/js/backend/news.js

@@ -0,0 +1,60 @@
+define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
+
+    var Controller = {
+        index: function () {
+            // 初始化表格参数配置
+            Table.api.init({
+                extend: {
+                    index_url: 'news/index' + location.search,
+                    add_url: 'news/add',
+                    edit_url: 'news/edit',
+                    del_url: 'news/del',
+                    multi_url: 'news/multi',
+                    import_url: 'news/import',
+                    table: 'news',
+                }
+            });
+
+            var table = $("#table");
+
+            // 初始化表格
+            table.bootstrapTable({
+                url: $.fn.bootstrapTable.defaults.extend.index_url,
+                pk: 'id',
+                sortName: 'weigh',
+                showToggle: false,// 禁用视图切换
+                search:false,// 禁用默认搜索框
+                showExport: false,// 禁用导出
+                columns: [
+                    [
+                        {checkbox: true},
+                        {field: 'id', title: __('Id')},
+                        {field: 'title', title: __('Title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
+                        {field: 'is_hot', title: __('Is_hot'), searchList: {"0":__('Is_hot 0'),"1":__('Is_hot 1')}, formatter: Table.api.formatter.status},
+                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
+                        {field: 'weigh', title: __('Weigh'), operate: false},
+                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
+                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
+                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
+                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
+                    ]
+                ]
+            });
+
+            // 为表格绑定事件
+            Table.api.bindevent(table);
+        },
+        add: function () {
+            Controller.api.bindevent();
+        },
+        edit: function () {
+            Controller.api.bindevent();
+        },
+        api: {
+            bindevent: function () {
+                Form.api.bindevent($("form[role=form]"));
+            }
+        }
+    };
+    return Controller;
+});

文件差异内容过多而无法显示
+ 1 - 0
public/assets/js/jquery-3.1.1.min.js


部分文件因为文件数量过多而无法显示