|
|
@@ -1,35 +1,73 @@
|
|
|
<?php namespace Seller\Api;
|
|
|
use Dever;
|
|
|
use Dever\Helper\Str;
|
|
|
-class Test
|
|
|
-{
|
|
|
- # 测试商户回调
|
|
|
- public function callback()
|
|
|
- {
|
|
|
- $input = Dever::input();
|
|
|
- Dever::log($input, 'callback');
|
|
|
- return 'ok';
|
|
|
- }
|
|
|
-
|
|
|
- public function run()
|
|
|
- {
|
|
|
- $order = Dever::input('order');
|
|
|
- $info = Dever::db('seller/order')->find($order);
|
|
|
- Dever::load(\Seller\Lib\Order::class)->handle($info);
|
|
|
+class Test
|
|
|
+{
|
|
|
+ protected static $sellerCache = [];
|
|
|
+ protected static $skuCache = [];
|
|
|
+ protected static $goodsCache = [];
|
|
|
+
|
|
|
+ # 测试商户回调
|
|
|
+ public function callback()
|
|
|
+ {
|
|
|
+ $input = Dever::input();
|
|
|
+ Dever::log($input, 'callback');
|
|
|
+ return 'ok';
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function seller($id)
|
|
|
+ {
|
|
|
+ if (!isset(self::$sellerCache[$id])) {
|
|
|
+ self::$sellerCache[$id] = Dever::db('seller/info')->find($id);
|
|
|
+ }
|
|
|
+ return self::$sellerCache[$id];
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function skuByCode($code)
|
|
|
+ {
|
|
|
+ if (!isset(self::$skuCache[$code])) {
|
|
|
+ self::$skuCache[$code] = Dever::db('goods/info_sku')->find(array('code' => $code));
|
|
|
+ }
|
|
|
+ return self::$skuCache[$code];
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function goods($id)
|
|
|
+ {
|
|
|
+ if (!isset(self::$goodsCache[$id])) {
|
|
|
+ self::$goodsCache[$id] = Dever::db('goods/info')->find($id);
|
|
|
+ }
|
|
|
+ return self::$goodsCache[$id];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function run()
|
|
|
+ {
|
|
|
+ $order = Dever::input('order');
|
|
|
+ $info = Dever::db('seller/order')->find($order);
|
|
|
+ Dever::load(\Seller\Lib\Order::class)->handle($info);
|
|
|
}
|
|
|
|
|
|
# 压力测试
|
|
|
public function test()
|
|
|
{
|
|
|
- $code = 'lt10';
|
|
|
- $info = Dever::db('seller/info')->find(1);
|
|
|
- $sku = Dever::db('goods/info_sku')->find(array('code' => $code));
|
|
|
- $goods = Dever::db('goods/info')->find($sku['info_id']);
|
|
|
- $account = '1' . Str::rand(10, 0);
|
|
|
- $order = Str::order('T');
|
|
|
- $num = 1;
|
|
|
- return Dever::load(\Seller\Lib\Order::class)->add($info, $goods, $sku, $account, $order, $num);
|
|
|
- }
|
|
|
+ $code = Dever::input('code', 'lt10');
|
|
|
+ $sellerId = Dever::input('seller_id', 1);
|
|
|
+ $info = $this->seller($sellerId);
|
|
|
+ if (!$info) {
|
|
|
+ Dever::error('商户不存在');
|
|
|
+ }
|
|
|
+ $sku = $this->skuByCode($code);
|
|
|
+ if (!$sku) {
|
|
|
+ Dever::error('规格不存在');
|
|
|
+ }
|
|
|
+ $goods = $this->goods($sku['info_id']);
|
|
|
+ if (!$goods) {
|
|
|
+ Dever::error('商品不存在');
|
|
|
+ }
|
|
|
+ $account = '1' . Str::rand(10, 0);
|
|
|
+ $order = Str::order('T');
|
|
|
+ $num = 1;
|
|
|
+ return Dever::load(\Seller\Lib\Order::class)->add($info, $goods, $sku, $account, $order, $num);
|
|
|
+ }
|
|
|
|
|
|
# 将当前订单置为失败
|
|
|
public function test_no()
|
|
|
@@ -45,4 +83,4 @@ class Test
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
-}
|
|
|
+}
|