Quellcode durchsuchen

wesmiler 更新第5期更新代码合并

wesmiler vor 4 Jahren
Ursprung
Commit
d334f631d2

+ 19 - 12
app/api/controller/MarketController.php

@@ -196,10 +196,12 @@ class MarketController extends MarketBaseController
 
             // 验证信息
             $where = ['openid' => $openid, 'user_type'=> 2];
-            $info = Member::where($where)->field('id,agent_type,agent_status')->find();
+            $info = Member::where($where)->field('id,agent_type,sex,avatar,agent_status')->find();
             $agentId = isset($info['id'])? $info['id'] : 0;
             $agentType = isset($info['agent_type'])? $info['agent_type'] : 0;
             $agentStatus = isset($info['agent_status'])? $info['agent_status'] : 0;
+            $hasAvatar = isset($info['avatar'])? $info['avatar'] : '';
+            $hasSex = isset($info['sex'])? $info['sex'] : 0;
             if($info && $agentType==1){
                 // 已审核
                 if($agentStatus == 1){
@@ -212,17 +214,21 @@ class MarketController extends MarketBaseController
             }
 
             // 头像
-            $avatar = isset($wxInfo['headimgurl']) ? trim($wxInfo['headimgurl']) : '';
-            $file = request()->file('image');
-            if (!empty($file) && $file != null) {
-                $fileData = Storage::uploadImg($file, 'avatar');
-                $avatar = isset($fileData['file']) ? $fileData['file'] : '';
-            }
+            $avatar = '';
+            if(empty($hasAvatar)){
+                $avatar = isset($wxInfo['headimgurl']) ? trim($wxInfo['headimgurl']) : '';
+                $file = request()->file('image');
+                if (!empty($file) && $file != null) {
+                    $fileData = Storage::uploadImg($file, 'avatar');
+                    $avatar = isset($fileData['file']) ? $fileData['file'] : '';
+                }
 
-            if (empty($avatar)) {
-                showJson(1004, 3004);
+                if (empty($avatar)) {
+                    showJson(1004, 3004);
+                }
             }
 
+
             Db::startTrans();
             $userPass = cmf_password('123456');
             $memberData = [
@@ -239,7 +245,6 @@ class MarketController extends MarketBaseController
                 'last_login_ip' => get_client_ip(),
                 'wechat_account' => isset($params['wechat_code']) ? trim($params['wechat_code']) : '',
                 'is_follow' => isset($wxInfo['subscribe']) ? intval($wxInfo['subscribe']) : 0,
-                'sex' => isset($wxInfo['sex']) ? intval($wxInfo['sex']) : 0,
                 'last_login_time' => time(),
                 'agent_create_time' => time(),
                 'agent_type' => 1,
@@ -247,7 +252,9 @@ class MarketController extends MarketBaseController
             if ($avatar) {
                 $memberData['avatar'] = $avatar;
             }
-           
+            if(!$hasSex){
+                $memberData['sex'] = isset($wxInfo['sex']) ? intval($wxInfo['sex']) : 0;
+            }
             if (!$agentId) {
                 $res = $agentId = Member::insertGetId($memberData);
             } else {
@@ -380,7 +387,7 @@ class MarketController extends MarketBaseController
             showJson(1004, 4010);
         }
 
-        $accountConfig = $siteInfo = cmf_get_option('account_config');
+        $accountConfig = cmf_get_option('account_config');
         $minWithdraw = isset($accountConfig['min_withdraw']) ? intval($accountConfig['min_withdraw']) : 1;
         $withdrawCost = isset($accountConfig['withdraw_cost']) ? floatval($accountConfig['withdraw_cost']) : 0;
         if ($minWithdraw && $money < $minWithdraw) {

+ 16 - 1
app/api/controller/MemberController.php

@@ -55,6 +55,12 @@ class MemberController extends BaseController
         $type = input('type', 0);
         $id = input('id', 0); // 当前浏览的用户ID
         $userId = $this->userId;
+
+        // 清除签到爱心
+        if($this->userId){
+            \app\weixin\service\Member::clearSignRedHeart($this->userId);
+        }
+
         $memberInfo = Member::getInfo(['id' => $userId]);
         if ($type == 1) {
             Member::visitCount($this->userId, 'center');
@@ -117,11 +123,20 @@ class MemberController extends BaseController
             }
 
             if ($type == 3) {
-                $accountConfig = $siteInfo = cmf_get_option('account_config');
+                $accountConfig = cmf_get_option('account_config');
                 $chargeRate = isset($accountConfig['charge_rate']) ? floatval($accountConfig['charge_rate']) : 0;
                 $minRecharge = isset($accountConfig['min_recharge']) ? intval($accountConfig['min_recharge']) : 1;
                 $memberInfo['charge_rate'] = $chargeRate > 0 ? $chargeRate : 1;
                 $memberInfo['min_recharge'] = $minRecharge ? $minRecharge : 1;
+
+                $clearData = Member::getSignReadheart($userId);
+                $signClear = isset($clearData['sign_clear'])? $clearData['sign_clear'] : 0;
+                $signTotal = isset($clearData['sign_total'])? $clearData['sign_total'] : 0;
+                $memberInfo['redheart_temp'] = $memberInfo['redheart'];
+//                $memberInfo['redheart'] = $memberInfo['redheart']>$signClear? $memberInfo['redheart'] - $signClear : 0;
+                $memberInfo['redheart_forever'] = $memberInfo['redheart']>$signTotal? $memberInfo['redheart'] - $signTotal : 0;
+                $memberInfo['clearData'] = $clearData;
+
             }
 
             // 是否已经认证

+ 36 - 0
app/api/controller/TaskController.php

@@ -3,6 +3,7 @@
 namespace app\api\controller;
 
 use app\portal\model\UserModel;
+use app\weixin\model\AccountLog;
 use app\weixin\model\Books;
 use app\weixin\model\Devices;
 use app\weixin\model\Member;
@@ -140,6 +141,41 @@ class TaskController extends Controller
     }
 
     /**
+     * 清除过期签到爱心
+     */
+    public function clearSignHeart(){
+        set_time_limit(0);
+        $key = input('key', '');
+        $checkKey = config('task.clearHeartKey');
+        if ($key != $checkKey) {
+            showJson(1004, 2009, '', "\n");
+        }
+        try {
+            $month = date('Y-m-01', time() - 2 * 86400);
+            $users = AccountLog::where(['type'=> 12,'status'=> 2])
+                ->where('created_at','>=', $month)
+                ->order('created_at','asc')
+                ->column('user_id');
+
+            $userIds = [];
+            \app\weixin\service\Member::clearSignRedHeart('1000077');
+            /*if($users){
+                foreach($users as $userId){
+                    // 清除签到爱心
+                    if($userId && \app\weixin\service\Member::clearSignRedHeart($userId)){
+                        $userIds[] = $userId;
+                    }
+                }
+            }*/
+
+            $msg = "清除签到爱心数据结果,共{".count($users)."}个,累计处理" . count($userIds) . "个会员数据更新";
+            return showJson(1005, $msg, "\n");
+        } catch (\Exception $exception) {
+            return showJson(1004, $exception->getMessage(), '', "\n");
+        }
+    }
+
+    /**
      * 处理怦然心动
      */
     public function catchUserHeart()

+ 1 - 2
app/weixin/controller/MemberController.php

@@ -6,9 +6,8 @@
 
 namespace app\weixin\controller;
 
-use app\weixin\model\Member;
 use app\weixin\model\Wechat;
-use app\weixin\validate\MemberValidate;
+use app\weixin\model\Member;
 use think\Request;
 
 class MemberController extends BaseController

+ 62 - 0
app/weixin/model/Member.php

@@ -2507,4 +2507,66 @@ class Member extends Model
 
         return true;
     }
+
+    /**
+     * 统计清除爱心
+     * @param $userId
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public static function getSignReadheart($userId){
+        $siteInfo = cmf_get_option('site_info');
+        $signClearDay = isset($siteInfo['sign_clear_day'])? intval($siteInfo['sign_clear_day']) : 0;
+        $signClearDay = $signClearDay? min($signClearDay, 28) : 1;
+        $signClearDay = $signClearDay<10? '0'.$signClearDay : $signClearDay;
+        $datas = [
+            'clear_day'=> date('m月'.$signClearDay.'号'),
+            'clear_month'=>date('m月', strtotime(date('Y-m-01')) - 86400),
+            'sign_total'=> 0,
+            'sign_clear'=> 0,
+            'show_clear'=> 1,
+        ];
+
+        // 最早
+        $month = date('Y-m-01', strtotime(date('Y-m-01')) - 86400);
+        $firstSign = AccountLog::where(['user_id'=> $userId,'type'=> 12,'status'=> 2])
+            ->where('created_at','>=', $month)
+            ->order('created_at','asc')
+            ->find();
+
+        $time = isset($firstSign['created_at'])? $firstSign['created_at'] : '';
+        if($firstSign && $time) {
+
+            // 签到后清除月份总消费
+            $totalCost = AccountLog::where(['user_id' => $userId, 'status' => 2, 'account_type' => 1, 'change_type' => 2])
+                ->where('created_at', '>=', $time)
+                ->where('created_at', '<', date('Y-m-01'))
+                ->sum('money');
+
+            $totalClearSign = AccountLog::where(['user_id' => $userId, 'type' => 12, 'status' => 2])
+                ->where('created_at', '>=', $time)
+                ->where('created_at', '<', date('Y-m-01'))
+                ->sum('money');
+
+            $clearRedheart = ($totalClearSign - $totalCost);
+            $datas['sign_clear'] = $clearRedheart;
+
+        }
+
+        $totalSign = AccountLog::where(['user_id' => $userId, 'type' => 12, 'status' => 2])
+            ->where('created_at', '>=', $time)
+            ->sum('money');
+        $cost = AccountLog::where(['user_id' => $userId, 'account_type' => 1, 'change_type' => 2, 'status' => 2])
+            ->where('created_at', '>=', $time)
+            ->sum('money');
+
+        $datas['sign_total'] = $totalSign>$cost? $totalSign-$cost : 0;
+        if($datas['sign_total'] <= 0){
+            $datas['sign_clear'] = 0;
+        }
+
+        return $datas;
+    }
 }

+ 1 - 1
app/weixin/model/SignMeal.php

@@ -79,7 +79,7 @@ class SignMeal extends Model
             return 2143;
         }
 
-        if($curSignDay != $signDay-1){
+        if($curSignDay != $signDay-1 && $curSignDay<7){
             return 2142;
         }
 

+ 94 - 0
app/weixin/service/Member.php

@@ -355,4 +355,98 @@ class Member
             });
     }
 
+    /**
+     * 到期清除
+     * @param $userId
+     * @return bool
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public static function clearSignRedHeart($userId){
+        $cacheKey = "cache:signs:clear:{$userId}_".date('Ym');
+        if(PRedis::get($cacheKey)){
+            return false;
+        }
+
+        $siteInfo = cmf_get_option('site_info');
+        $signClearDay = isset($siteInfo['sign_clear_day'])? intval($siteInfo['sign_clear_day']) : 0;
+        $signClearDay = $signClearDay? min($signClearDay, 28) : 1;
+        $signClearDay = $signClearDay<10? '0'.$signClearDay : $signClearDay;
+        if(date('Y-m-d') < date('Y-m-'.$signClearDay)){
+            PRedis::set($cacheKey, ['error' =>'未到清除时间','date'=> date('Y-m-d H:i:s'),'day'=> $signClearDay], rand(10, 30));
+            return false;
+        }
+
+        $month = date('Y-m-01', strtotime(date('Y-m-01')) - 86400);
+        $check = AccountLog::where(['user_id' => $userId, 'type'=> 13, 'status' => 2])
+            ->where('created_at', '>=', $month)
+            ->find();
+        if($check){
+            PRedis::set($cacheKey, ['error' =>'已清除过','info'=>$check,'date'=> date('Y-m-d H:i:s'),'day'=> $signClearDay], 86400);
+            return false;
+        }
+
+        $info = MemberModel::where(['id'=> $userId])->field('id,openid,user_nickname,redheart')->find();
+        if(empty($info)){
+            return false;
+        }
+
+        // 最早
+        $firstSign = AccountLog::where(['user_id'=> $userId,'type'=> 12,'status'=> 2])
+            ->where('created_at','>=', $month)
+            ->where('created_at','<', date('Y-m-01'))
+            ->order('created_at','asc')
+            ->find();
+        $time = isset($firstSign['created_at'])? $firstSign['created_at'] : '';
+        if(empty($firstSign) || empty($time)){
+            PRedis::set($cacheKey, ['first' => $firstSign,'user'=> $info], rand(10, 30));
+            return false;
+        }
+
+        // 签到后总消费
+        $totalCost = AccountLog::where(['user_id'=> $userId,'status'=> 2,'account_type'=> 1,'change_type'=>2])
+            ->where('created_at','>=', $time)
+            ->where('created_at','<', date('Y-m-01'))
+            ->sum('money');
+
+
+        $totalSign = AccountLog::where(['user_id'=> $userId,'type'=> 12,'status'=> 2])
+            ->where('created_at','>=', $time)
+            ->where('created_at','<', date('Y-m-01'))
+            ->sum('money');
+
+        // 清除还有未消费爱心
+        $redheart = isset($info['redheart'])? $info['redheart'] : 0;
+        $clearRedheart = ($totalSign-$totalCost);
+        PRedis::set($cacheKey, ['first' => $firstSign,'cost'=> $totalCost,'sign'=> $totalSign,'user'=> $info], 120);
+        if($clearRedheart>0 && $clearRedheart <= $redheart){
+            db()->startTrans();
+            if(!db()->name('user')->where(['id' => $userId])->setDec('redheart',$clearRedheart)){
+                db()->rollback();
+                return 2145;
+            }
+
+            $accountData = [
+                'type' => 13,
+                'account_type' => 1,
+                'change_type' => 2,
+                'user_id' => $userId,
+                'money' => $clearRedheart,
+                'balance' => $redheart,
+                'created_at' => date('Y-m-d H:i:s'),
+                'remark' => "签到爱心过期扣除",
+            ];
+            PRedis::set("cache:signs:clearLog:{$userId}", ['log' => $accountData,'user'=> $info], 86400);
+            db('account_log')->insertGetId($accountData);
+
+            db()->commit();
+            PRedis::set($cacheKey, ['log' => $accountData,'first' => $firstSign,'cost'=> $totalCost,'sign'=> $totalSign,'user'=> $info], 7*24*3600);
+            return true;
+        }
+
+        return false;
+    }
+
+
 }

+ 1 - 0
public/themes/admin_simpleboot3/admin/love/index.html

@@ -84,6 +84,7 @@
 							<case value="10">赠送</case>
 							<case value="11">置顶报名</case>
 							<case value="12">签到奖励</case>
+							<case value="13">扣除</case>
 						</switch>
 					</td>
 					<td>

+ 9 - 0
public/themes/admin_simpleboot3/admin/setting/site.html

@@ -445,6 +445,7 @@
                     </div>
 
                     <div class="tab-pane" id="H">
+
                         <div class="form-group">
                             <label for="input-book_time" class="col-sm-2 control-label">活动截止报名/小时</label>
                             <div class="col-md-4 col-sm-10">
@@ -532,6 +533,14 @@
 
                     <div class="tab-pane" id="I">
                         <div class="form-group">
+                            <label for="input-sign_clear_day" class="col-sm-2 control-label">签到积分每月几号清除</label>
+                            <div class="col-md-4 col-sm-10">
+                                <input type="text" class="form-control" id="input-sign_clear_day"
+                                       name="options[sign_clear_day]" value="{$site_info.sign_clear_day|default='7'}" max="28" min="1">
+                                <span class="help-block">签到积分每月几号清除,1-28号</span>
+                            </div>
+                        </div>
+                        <div class="form-group">
                             <label for="input-invite_award_redheart" class="col-sm-2 control-label">邀请注册奖励爱心数</label>
                             <div class="col-md-4 col-sm-10">
                                 <input type="text" class="form-control" id="input-invite_award_redheart"

+ 4 - 0
public/themes/default/weixin/account/recharge.html

@@ -11,9 +11,13 @@
     </div>
     <div class="main" v-if="memberInfo.id">
         <div class="chiz_box">
+            <div class="notice" v-if="showClear>0 && memberInfo.clearData.show_clear>0">
+                <div v-if="memberInfo.clearData.clear_day">{{memberInfo.clearData.clear_day}}将清空{{memberInfo.clearData.clear_month}}获得未使用的爱心,预计{{memberInfo.clearData.sign_clear}}个 <span @click="hideClear()">x</span></div>
+            </div>
             <div class="aix_cz">
                 <div class="tips"><a href="/weixin/page/rechargeAgree"><span>充值须知</span><img src="__TMPL__/weixin/public/assets/img/help.png" alt=""></a></div>
                 <div class="money"><span>剩余爱心:</span><span class="heart" v-text="memberInfo.redheart"></span></div>
+                <div class="text"><span>限时爱心:</span><span class="heart" v-text="memberInfo.clearData.sign_total"></span><span>永久爱心:</span><span class="heart" v-text="memberInfo.redheart_forever"></span></div>
             </div>
             <div class="chuz_sl">
                 <div @click="selectMeal($event, v)" :class="'list-item'+(mealInfo.id==v.id||(mealInfo.id==0&&k==0)? ' active': '')" v-for="(v,k) in mealList">

+ 37 - 1
public/themes/default/weixin/public/assets/css/recharge.css

@@ -25,10 +25,46 @@ body {
     margin: 0 15px;
     padding: 15px 0;
     /*text-align: center;*/
-    padding-top: 30px;
+    padding-top: 10px;
     margin-bottom: 20px;
 }
 
+.notice {
+    position: relative;
+    padding: 5px;
+    background: #f2447d;
+    color: #fff;
+    word-break: break-all;
+    text-overflow: ellipsis;
+    display: -webkit-box;
+    -webkit-box-orient: vertical;
+    -webkit-line-clamp: 1;
+    overflow: hidden;
+    width: 90%;
+    margin: 5px auto;
+    font-size: 14px;
+    border-radius: 2px;
+}
+.notice span {
+    position: absolute;
+    color: #fff;
+    text-align: center;
+    width: 20px;
+    height: 20px;
+    line-height: 20px;
+    right: 5px;
+    font-size: 16px;
+    border-radius: 10px;
+}
+.aix_cz .text {
+    font-size: 14px;
+    color: #666;
+    margin: 5px 0;
+}
+.aix_cz .text .heart {
+    font-size: 14px;
+    margin-right: 10px;
+}
 .aix_cz .tips {
     color: #ffd132;
 }

+ 11 - 0
public/themes/default/weixin/public/assets/js/recharge.js

@@ -6,6 +6,7 @@ var app = new Vue({
         // 用户信息
         memberInfo: {},
         mealList: [],
+        showClear: 1,
         mealInfo: {
             id: 0,
         },
@@ -17,10 +18,19 @@ var app = new Vue({
         },
     },
     created: function(){
+        var showClear = sessionStorage.getItem('showClear');
+        this.showClear = typeof(showClear) != 'undefined' && showClear !== null? showClear : 1;
+
+        console.log(this.showClear)
         this.getMeal();
         this.getMemberInfo();
+
     },
     methods: {
+        hideClear: function(){
+            this.showClear = 0;
+            sessionStorage.setItem('showClear', 0);
+        },
         // 选择套餐
         selectMeal: function(ele, data){
             if(data.heart<=0 || data.price<=0){
@@ -59,6 +69,7 @@ var app = new Vue({
                 $.hideLoading();
                 if (res.code == 'success'){
                     _this.memberInfo = res.data
+
                     _this.params.num =  _this.memberInfo.min_recharge? _this.memberInfo.min_recharge : 1;
                     _this.countMoney();
                 }else if(res.code == 'exception'){