stanley-king 3 years ago
parent
commit
cfa036e63f
2 changed files with 41 additions and 12 deletions
  1. 36 7
      admin/control/provider.php
  2. 5 5
      admin/templates/default/provider.price.set.php

+ 36 - 7
admin/control/provider.php

@@ -347,12 +347,14 @@ class providerControl extends SystemControl
         $provider_id = $_GET['provider_id'];
         $mod_provider = Model('refill_provider');
         $mod_price = Model('provider_price');
+
         $provider = $mod_provider->getProviderInfo(['provider_id' => $provider_id]);
         $provider_name = $provider['name'];
         $type = $provider['type'];
 
         $price = $mod_price->getPirce(['provider_name' => $provider_name,'product_type' => $type]);
         $cfg = $this->price_cfg($price);
+
         if(empty($provider)) {
             showMessage('通道不存在');
         }
@@ -363,6 +365,7 @@ class providerControl extends SystemControl
             if($effect_time > 0) {
                 $effect_time = strtotime($effect_time);
             }
+
             $chprice_helper = new refill\chprice_helper();
             $ret = $chprice_helper->update($price['price_id'], $new_cfg, $effect_time, $admininfo['name']);
             if($ret) {
@@ -373,10 +376,13 @@ class providerControl extends SystemControl
         }
         else
         {
-            $cfg_map = $this->map_cfg($cfg);
-            $all_specs = $this->all_specs($provider['qualitys'], $type);
-            Tpl::output('provider', $provider);
-            Tpl::output('cfg_map', $cfg_map);
+            $all_specs = $this->all_specs($cfg['qualitys'], $type);
+            $amounts   = $this->map_cfg($cfg,$all_specs);
+
+            Tpl::output('provider_name', $cfg['name']);
+            Tpl::output('product_type', $price['product_type']);
+
+            Tpl::output('amounts', $amounts);
             Tpl::output('all_specs', $all_specs);
             Tpl::showpage('provider.price.set');
         }
@@ -404,20 +410,43 @@ class providerControl extends SystemControl
         return $result;
     }
 
-    private function map_cfg($cfg)
+    private function map_cfg($cfg,$all_specs)
     {
-        $result = [];
         $amounts = $cfg['amount'] ?? [];
+
+        $amount_list = [];
         foreach ($amounts as $spec => $goods)
         {
             foreach ($goods as $gitem)
             {
                 $types = $this->card_types($gitem['card_type']);
                 foreach ($types as $type) {
-                    $result[$type][$spec] = $gitem['price'] ?? 0;
+                    $amount_list[$type][$spec] = $gitem['price'] ?? 0;
+                }
+            }
+        }
+
+        $result = [];
+        foreach ($all_specs as $card_type => $val)
+        {
+            $specs = $val['specs'];
+            foreach ($specs as $spec)
+            {
+                $result[$card_type][$spec] = ['price' => 0,'opened' => 0];
+            }
+        }
+
+        foreach ($amount_list as $card_type => $prices)
+        {
+            foreach ($prices as $spec => $price)
+            {
+                if (array_key_exists($card_type, $result) && array_key_exists($spec, $result[$card_type])) {
+                    $result[$card_type][$spec]['price'] = $price;
+                    $result[$card_type][$spec]['opened'] = 1;
                 }
             }
         }
+
         return $result;
     }
 

+ 5 - 5
admin/templates/default/provider.price.set.php

@@ -94,7 +94,7 @@
             </tr>
             <tr class="noborder">
                 <td class="vatop rowform">
-                    <?php echo $output['provider']['name']; ?>
+                    <?php echo $output['provider_name']; ?>
                 </td>
                 <td class="vatop tips"></td>
             </tr>
@@ -112,7 +112,7 @@
                 <td colspan="2" class="required"><label class="validation" for="password">费率:</label></td>
             </tr>
             <tr class="noborder" style="border-bottom: 1px solid #CBE9F3;">
-                <?php foreach ($output['all_specs'] as $card_type => $data){?>
+                <?php foreach ($output['amounts'] as $card_type => $datas){?>
                 <td>
                     <table class="spec_table tb-type2 setTable">
                         <tr class="w500">
@@ -133,10 +133,10 @@
                         </tr>
 
                         <tbody class="tbody">
-                        <?php foreach ($data['specs'] as $spec){ ?>
+                        <?php foreach ($datas as $spec => $val){ ?>
                         <tr class="w500">
                             <td class="w150 align-center">
-                                <?php echo $data['goods_name']; ?>
+                                <?php echo $output['all_specs'][$card_type]['goods_name']; ?>
                                 <input type="hidden" name="card_types[]" value="<?php echo $card_type; ?>">
                             </td>
                             <td class="w150 align-center">
@@ -145,7 +145,7 @@
                             </td>
                             <td class="w150 align-center tdVal">
                                 <input type="text" name="prices[]" class="txt price"
-                                       value="<?php echo $output['cfg_map'][$card_type][$spec] ?? 0; ?>">
+                                       value="<?php echo $val['price']; ?>">
                             </td>
                         </tr>
                         <?php }?>