Test.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php namespace Seller\Api;
  2. use Dever;
  3. use Dever\Helper\Str;
  4. class Test
  5. {
  6. protected static $sellerCache = [];
  7. protected static $skuCache = [];
  8. protected static $goodsCache = [];
  9. # 测试商户回调
  10. public function callback()
  11. {
  12. $input = Dever::input();
  13. Dever::log($input, 'callback');
  14. return 'ok';
  15. }
  16. protected function seller($id)
  17. {
  18. if (!isset(self::$sellerCache[$id])) {
  19. self::$sellerCache[$id] = Dever::db('seller/info')->find($id);
  20. }
  21. return self::$sellerCache[$id];
  22. }
  23. protected function skuByCode($code)
  24. {
  25. if (!isset(self::$skuCache[$code])) {
  26. self::$skuCache[$code] = Dever::db('goods/info_sku')->find(array('code' => $code));
  27. }
  28. return self::$skuCache[$code];
  29. }
  30. protected function goods($id)
  31. {
  32. if (!isset(self::$goodsCache[$id])) {
  33. self::$goodsCache[$id] = Dever::db('goods/info')->find($id);
  34. }
  35. return self::$goodsCache[$id];
  36. }
  37. public function run()
  38. {
  39. $order = Dever::input('order');
  40. $info = Dever::db('seller/order')->find($order);
  41. Dever::load(\Seller\Lib\Order::class)->handle($info);
  42. }
  43. # 压力测试
  44. public function test()
  45. {
  46. $code = Dever::input('code', 'lt10');
  47. $sellerId = Dever::input('seller_id', 1);
  48. $info = $this->seller($sellerId);
  49. if (!$info) {
  50. Dever::error('商户不存在');
  51. }
  52. $sku = $this->skuByCode($code);
  53. if (!$sku) {
  54. Dever::error('规格不存在');
  55. }
  56. $goods = $this->goods($sku['info_id']);
  57. if (!$goods) {
  58. Dever::error('商品不存在');
  59. }
  60. $account = '1' . Str::rand(10, 0);
  61. $order = Str::order('T');
  62. $num = 1;
  63. return Dever::load(\Seller\Lib\Order::class)->add($info, $goods, $sku, $account, $order, $num);
  64. }
  65. # 将当前订单置为失败
  66. public function test_no()
  67. {
  68. while(1) {
  69. $order = Dever::db('seller/order')->find(array('seller_id' => 1, 'status' => 2));
  70. if ($order) {
  71. $msg = 'error';
  72. $update = array();
  73. $update['official_msg'] = '';
  74. $update['official_order_num'] = '';
  75. Dever::load(\Seller\Lib\Order::class)->notify($order, $msg, $update);
  76. }
  77. };
  78. }
  79. }