Index.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace App\HttpController;
  3. use EasySwoole\Http\AbstractInterface\Controller;
  4. use App\Com\JdSdk;
  5. class Index extends Controller
  6. {
  7. protected $JdSdk;
  8. public function index()
  9. {
  10. $file = EASYSWOOLE_ROOT.'/vendor/easyswoole/easyswoole/src/Resource/Http/welcome.html';
  11. if(!is_file($file)){
  12. $file = EASYSWOOLE_ROOT.'/src/Resource/Http/welcome.html';
  13. }
  14. $this->response()->write(file_get_contents($file));
  15. }
  16. /**
  17. * 3.5 商品上下架状态接口
  18. *
  19. * @param $skuArr
  20. *
  21. * @return array|bool
  22. */
  23. public function skuState()
  24. {
  25. // 获取 `POST` 或者 `GET` 提交的所有参数
  26. $data = $this->request()->getRequestParam();
  27. $skuArr = $data['skuArr'];
  28. $this->JdSdk = new JdSdk();
  29. $response = $this->JdSdk->api_product_sku_state($skuArr);
  30. $this->response()->write($response . PHP_EOL);
  31. //$response = json_decode($response, true);
  32. // =====$response=====
  33. // { "success": true, "resultMessage": "操作成功", "resultCode": "0000", "result": [ { "state": 0, "sku": 5729524 } ], "code": 200 }
  34. //return $response;
  35. }
  36. /**
  37. * 6.2 批量获取库存接口(建议订单详情页、下单使用)
  38. *
  39. * @param $skuNums
  40. * @param $area
  41. * $skuNums商品和数量 此是个String 再重构吧 [{skuId: 569172,num:101}], $area格式:1_0_0 (分别代表1、2、3级地址)
  42. * @return mixed
  43. */
  44. public function skuStock()
  45. {
  46. // 获取 `POST` 或者 `GET` 提交的所有参数
  47. $data = $this->request()->getRequestParam();
  48. $skuArr = $data['skuArr'];
  49. $area = $data['area'];
  50. $this->JdSdk = new JdSdk();
  51. $response = $this->JdSdk->api_stock_get_new_stock_by_id($skuArr, $area);
  52. $this->response()->write($response . PHP_EOL);
  53. //return $response;
  54. }
  55. /**
  56. * TODO 待测 5.2 批量查询协议价价格
  57. * HTTPS请求方式:POST
  58. *
  59. * @return string
  60. */
  61. function skuPrice()
  62. {
  63. // 获取 `POST` 或者 `GET` 提交的所有参数
  64. $data = $this->request()->getRequestParam();
  65. $skuArr = $data['skuArr'];
  66. $this->JdSdk = new JdSdk();
  67. $response = $this->JdSdk->api_price_get_price($skuArr);
  68. $this->response()->write($response . PHP_EOL);
  69. //return $response;
  70. }
  71. function test()
  72. {
  73. $this->response()->write('this is test');
  74. }
  75. protected function actionNotFound(?string $action)
  76. {
  77. $this->response()->withStatus(404);
  78. $file = EASYSWOOLE_ROOT.'/vendor/easyswoole/easyswoole/src/Resource/Http/404.html';
  79. if(!is_file($file)){
  80. $file = EASYSWOOLE_ROOT.'/src/Resource/Http/404.html';
  81. }
  82. $this->response()->write(file_get_contents($file));
  83. }
  84. }