ayHaru 4 yıl önce
ebeveyn
işleme
bf4aca9aa9
2 değiştirilmiş dosya ile 110 ekleme ve 3 silme
  1. 102 3
      admin/control/merchant.php
  2. 8 0
      data/model/merchant.model.php

+ 102 - 3
admin/control/merchant.php

@@ -99,14 +99,113 @@ class merchantControl extends SystemControl
     public function priceOp(){
         $lang = Language::getLangContent();
         if (chksubmit()) {
-
+            $mchid = $_POST['mchid'];
+            $card_types = $_POST['cardtype'];
+            $spec = $_POST['spec'];
+            $prices = $_POST['price'];
+            foreach ($card_types as $key => $card_type){
+                $data['card_type'] = $card_type;
+                $data['spec'] = $spec[$key];
+                $data['price'] = $prices[$key];
+                $params[] = $data;
+            }
+            foreach ($params as $key => $value){
+                $arr[$value['price']][] = $value;
+            }
+            foreach ($arr as $price => $value){
+                $item = [];
+                foreach ($value as $v){
+                    $item['mchid'] = $mchid;
+                    $item['spec'] = $v['spec'];
+                    $item['price'] = $v['price'];
+                    $item['card_types'][] = $v['card_type'];
+                }
+                $items[] = $item;
+            }
+            foreach ($items as $key => $value){
+                $items[$key]['card_types'] = implode(',',$value['card_types']);
+            }
+            $model_merchant = Model('merchant');
+            try {
+                $trans = new trans_wapper($model_merchant, __METHOD__);
+                //删除旧费率
+                $model_merchant->delPrices($mchid);
+                $model_merchant->insertPrices($items);
+                $trans->commit();
+                showMessage('操作成功', 'index.php?act=merchant&op=merchant');
+            } catch (Exception $e) {
+                $trans->rollback();
+                showMessage($e->getMessage(), 'index.php?act=merchant&op=merchant', 'html', 'error');
+            }
         }
-        $goods = refill\RefillFactory::instance()->goods();
-//        var_dump($goods);die;
+        $mchid = $_GET['mchid'] ?? 0;
+        $goods = $this->GoodsFormat($mchid);
         Tpl::output('goods', $goods);
         Tpl::showpage('merchant.price');
     }
 
+    private function GoodsFormat($mchid){
+        $goods = refill\RefillFactory::instance()->goods();
+        $goods = $this->GoodsKeyFormat($goods);
+        $model_merchant = Model('merchant');
+        $items = $model_merchant->table('merchant_price')->where(['mchid' => $mchid])->select();
+        $items = $this->PricesFormat($items);
+        foreach ($goods as $key => $value){
+            foreach ($value as $amount){
+                $goods_name = $this->scard_type($key);
+                $data['goods_name'] = $goods_name;
+                $data['card_type'] = $key;
+                $data['spec'] = $amount;
+                $data['price'] = 0;
+                foreach ($items as $item){
+                    if($amount == $item['spec'] && $key == $item['card_type']){
+                        $data['price'] = $item['price'];
+                    }
+                }
+                $result[] = $data;
+            }
+        }
+        return $result;
+    }
+
+    private function GoodsKeyFormat($goods){
+        $data = [];
+        foreach ($goods as $key => $value){
+            if ($key == 'petrochina') { //中石油
+                $key = 1;
+            } elseif ($key == 'sinopec') { //中石化
+                $key = 2;
+            } elseif ($key == 'chinamobile') { //中国移动
+                $key = 4;
+            } elseif ($key == 'chinaunicom') { //中国联通
+                $key = 5;
+            } elseif ($key == 'chinatelecom') { //中国电信
+                $key = 6;
+            }
+            $data[$key] = $value;
+        }
+        return $data;
+    }
+
+    private function PricesFormat($items){
+        $data = [];
+        foreach ($items as $key => $item){
+            if(strlen($item['card_types']) > 1){
+                $card_types = explode(',',$item['card_types']);
+                foreach ($card_types as $card_type){
+                    $item['card_type'] = $card_type;
+                    unset($item['card_types']);
+                    $data[] = $item;
+                }
+            }else{
+                $item['card_type'] = $item['card_types'];
+                unset($item['card_types']);
+                $data[] = $item;
+            }
+        }
+        return $data;
+    }
+
     public function check_merchantOp()
     {
         $mchid = trim($_GET['mchid']);

+ 8 - 0
data/model/merchant.model.php

@@ -30,6 +30,14 @@ class merchantModel extends Model
         return $this->table('merchant_price')->where(['mchid' => $mchid, 'spec' => $amount])->select();
     }
 
+    public function delPrices($mchid){
+        return $this->table('merchant_price')->where(['mchid' => $mchid])->delete();
+    }
+
+    public function insertPrices($params){
+        return $this->table('merchant_price')->insertAll($params);
+    }
+
     public function editMerchant($update, $condition)
     {
         return $this->table('merchant')->where($condition)->update($update);