rabin 2 years ago
parent
commit
ee43322a9e
3 changed files with 30 additions and 15 deletions
  1. 1 1
      app/card/database/add.php
  2. 16 1
      app/card/lib/Code.php
  3. 13 13
      app/card/lib/Manage.php

+ 1 - 1
app/card/database/add.php

@@ -70,7 +70,7 @@ return array
         'content'       => array
         (
             'type'      => 'text-255',
-            'name'      => '填写卡号-多个换行隔开,如卡号重复将不会录入到库中',
+            'name'      => '填写卡号-多个换行隔开,如卡号重复将不会录入到库中,如需填写面值,请用半角逗号隔开',
             'default'   => '',
             'desc'      => '填写卡号',
             'match'     => 'is_string',

+ 16 - 1
app/card/lib/Code.php

@@ -92,17 +92,32 @@ class Code
         if (!$card) {
             return;
         }
+        $cash = 0;
+        if (strstr($card, ',')) {
+            $temp = explode(',', $card);
+            $card = $temp[0];
+            $cash = $temp[1];
+        }
         $where['clear'] = true;
         $where['card'] = $card;
         $state = Dever::db('card/code')->find($where);
 
         if (!$state) {
             $where['card_id'] = $info['id'];
+            if ($cash > 0) {
+                $where['total_cash'] = $cash;
+            }
             Dever::db('card/code')->insert($where);
 
             return $card;
         } else {
-            return false;
+            $where['where_id'] = $state['id'];
+            $where['card_id'] = $info['id'];
+            if ($cash > 0) {
+                $where['total_cash'] = $cash;
+            }
+            Dever::db('card/code')->update($where);
+            return $card;
         }
     }
 

+ 13 - 13
app/card/lib/Manage.php

@@ -108,21 +108,21 @@ class Manage
                     $table['兑换时间'] = date('Y-m-d H:i:s', $info['ddate']);
                 }
             }
+        }
 
-            if (!$info['total_cash']) {
-                $card_info = Dever::db('card/info')->find($info['card_id']);
-                $info['total_cash'] = $card_info['value'];
-            }
-            if (!$info['use_cash']) {
-                $info['use_cash'] = 0;
-            }
-            $table['总面值'] = $info['total_cash'];
-            $table['已用面值'] = $info['use_cash'];
-            $table['剩余面值'] = $info['total_cash'] - $info['use_cash'];
+        if (!$info['total_cash']) {
+            $card_info = Dever::db('card/info')->find($info['card_id']);
+            $info['total_cash'] = $card_info['value'];
+        }
+        if (!$info['use_cash']) {
+            $info['use_cash'] = 0;
+        }
+        $table['总面值'] = $info['total_cash'];
+        $table['已用面值'] = $info['use_cash'];
+        $table['剩余面值'] = $info['total_cash'] - $info['use_cash'];
 
-            if ($table) {
-                return Dever::table($table);
-            }
+        if ($table) {
+            return Dever::table($table);
         }
 
         return '暂无';