فهرست منبع

从钱包操作方法限制用户消费权限

lizhen_gitee 1 سال پیش
والد
کامیت
534e40590b
1فایلهای تغییر یافته به همراه43 افزوده شده و 1 حذف شده
  1. 43 1
      application/common/model/Wallet.php

+ 43 - 1
application/common/model/Wallet.php

@@ -67,7 +67,7 @@ class Wallet extends Model
      * @return array[log_table]
      * @return array[log_id]
      */
-    public function lockChangeAccountRemain($user_id,$money,$mode,$before,$remark='',$logtype='',$accountType='money',$inviteId=0)
+    public function lockChangeAccountRemain($user_id,$money,$mode,$before = 0,$remark='',$logtype,$accountType='money',$inviteId=0)
     {
         //初始化
         $result = array(
@@ -78,6 +78,13 @@ class Wallet extends Model
             'log_id' => '',
         );
 
+        //限制权限
+        $power_rs = $this->power_limit_logtype($user_id,$logtype);
+        if($power_rs !== true){
+            $result['msg'] = $power_rs;
+            return $result;
+        }
+
         //获取小数点
         $point = $accountType == 'money' ? 2 : 0;
         bcscale($point);
@@ -171,6 +178,41 @@ class Wallet extends Model
 
     }
 
+    //user_power代表用户权限
+    //多个字段限制了用户的消费,当某个字段为1代表为禁止,结合logtype,报错到前台
+    public function power_limit_logtype($user_id,$logtype){
+        $power = Db::name('user_power')->where('user_id',$user_id)->find();
 
+        //没有权限表,直接报错
+        if(empty($power)){
+            return '不存在的用户';
+        }
+
+        $enum = [
+            0 => 'payorder',
+            1 => 'recharge',
+            3 => 'give_gift',
+            5 => 'noble',
+            6 => 'attire',
+            11 => 'transfer',
+            13 => 'raffle',
+            104 => 'withdraw',
+        ];
+
+        //不受限制
+        if(!isset($enum[$logtype])){
+            return true;
+        }
+
+        $field = $enum[$logtype];
+
+        //受限制
+        if($power[$field] == 1){
+            $logtype_name = $this->getlogtype($logtype);
+            return '您已被限制:'.$logtype_name.',请联系管理员';
+        }
+
+        return true;
+    }
 
 }