| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php namespace Seller\Api;
- use Dever;
- use Dever\Helper\Str;
- 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 = 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()
- {
- while(1) {
- $order = Dever::db('seller/order')->find(array('seller_id' => 1, 'status' => 2));
- if ($order) {
- $msg = 'error';
- $update = array();
- $update['official_msg'] = '';
- $update['official_order_num'] = '';
- Dever::load(\Seller\Lib\Order::class)->notify($order, $msg, $update);
- }
- };
- }
- }
|