xiaoyu пре 2 година
родитељ
комит
0b788f7336
3 измењених фајлова са 48 додато и 1 уклоњено
  1. 13 1
      data/model/thrid_refill.model.php
  2. 3 0
      mobile/control/refill.php
  3. 32 0
      test/TestThirdRefill.php

+ 13 - 1
data/model/thrid_refill.model.php

@@ -39,6 +39,18 @@ class thrid_refillModel extends Model
         }
     }
 
+    public function getMerchantPcode($mchid)
+    {
+        $item = $this->table('merchant_price')
+            ->field('pcode')
+            ->where(['mchid' => $mchid, 'pcode' => ['neq','']])
+            ->select();
+        if(empty($item)) {
+            return [];
+        }
+        return array_column($item, 'pcode');
+    }
+
     public function addExt($data)
     {
         return $this->table('refill_third')->insert($data);
@@ -53,4 +65,4 @@ class thrid_refillModel extends Model
     {
         return $this->table('refill_third')->where(['order_id' => $order_id])->find();
     }
-}
+}

+ 3 - 0
mobile/control/refill.php

@@ -43,6 +43,9 @@ class refillControl extends merchantControl
                 $result[$key] = $value;
             }
         }
+        $thrid_refill = Model('thrid_refill');
+        $pcode = $thrid_refill->getMerchantPcode($mchid);
+        $result['third'] = $pcode;
 
         return self::outsuccess($result);
     }

+ 32 - 0
test/TestThirdRefill.php

@@ -44,5 +44,37 @@ class TestThirdRefill extends TestCase
         refill\RefillFactory::instance()->notify('sctongqian', $params);
     }
 
+    public function testMerchantGoods()
+    {
+        $goods_list = refill\RefillFactory::instance()->goods();
+
+        $sorter = function (array $items) {
+            $ret = [];
+            foreach ($items as $key => $val) {
+                sort($val);
+                $ret[$key] = $val;
+            }
+            return $ret;
+        };
+
+        $goods_list = $sorter($goods_list);
+
+        $result = [];
+        $mchid = 10254;
+        $merchant_goods = rcache('merchant_goods', 'refill-', $mchid);
+        $goods = $merchant_goods[$mchid] ?? serialize([]);
+        $goods = unserialize($goods);
+        foreach ($goods_list as $card_type => $value) {
+            $key = mtopcard\scard_type($card_type);
+            if (array_key_exists($key, $goods)) {
+                $result[$key] = $goods[$key];
+            } else {
+                $result[$key] = $value;
+            }
+        }
+        $thrid_refill = Model('thrid_refill');
+        $pcode = $thrid_refill->getMerchantPcode($mchid);
+        $result['third'] = $pcode;
+    }
 
 }