ProductService.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: LZP
  5. * Date: 2022/4/15
  6. * Time: 11:23
  7. */
  8. namespace App\HttpController;
  9. use EasySwoole\Http\AbstractInterface\Controller;
  10. use App\Com\JdSdk;
  11. class ProductService extends Controller
  12. {
  13. private $JdSdk;
  14. public function __construct()
  15. {
  16. $this->JdSdk = new JdSdk();
  17. }
  18. /**
  19. * 3.5 商品上下架状态接口
  20. *
  21. * @param $skuArr
  22. *
  23. * @return array|bool
  24. */
  25. public function skuState()
  26. {
  27. // 获取 `POST` 或者 `GET` 提交的所有参数
  28. $data = $this->request()->getRequestParam();
  29. var_dump($data);
  30. // 返回给客户端
  31. $this->response()->write($data . PHP_EOL);
  32. $skuArr = $data['skuArr'];
  33. $sku = implode(',', $skuArr);
  34. $response = $this->JdSdk->api_product_sku_state($sku);
  35. //$response = json_decode($response, true);
  36. // =====$response=====
  37. // { "success": true, "resultMessage": "操作成功", "resultCode": "0000", "result": [ { "state": 0, "sku": 5729524 } ], "code": 200 }
  38. return $response;
  39. }
  40. /**
  41. * 6.2 批量获取库存接口(建议订单详情页、下单使用)
  42. *
  43. * @param $skuNums
  44. * @param $area
  45. * $skuNums商品和数量 此是个String 再重构吧 [{skuId: 569172,num:101}], $area格式:1_0_0 (分别代表1、2、3级地址)
  46. * @return mixed
  47. */
  48. public function getNewStockById()
  49. {
  50. // 获取 `POST` 或者 `GET` 提交的所有参数
  51. $data = $this->request()->getRequestParam();
  52. $skuNums = $data['skuArr'];
  53. $area = $data['area'];
  54. $response = $this->JdSdk->api_stock_get_new_stock_by_id($skuNums, $area);
  55. return $response;
  56. }
  57. /**
  58. * TODO 待测 5.2 批量查询协议价价格
  59. * HTTPS请求方式:POST
  60. *
  61. * @return string
  62. */
  63. function api_price_get_price()
  64. {
  65. // 获取 `POST` 或者 `GET` 提交的所有参数
  66. $data = $this->request()->getRequestParam();
  67. $sku = $data['sku'];
  68. $response = $this->JdSdk->api_price_get_price($sku);
  69. return $response;
  70. }
  71. /**
  72. * 当请求方法未找到时,自动调用该方法,可自行覆盖该方法实现自己的逻辑
  73. *
  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. /**
  85. * 此控制器抛异常时会执行此方法
  86. *
  87. * @param \Throwable $throwable
  88. * @throws \Throwable
  89. * CreateTime: 2020/8/19 12:48 上午
  90. */
  91. public function onException(\Throwable $throwable): void
  92. {
  93. parent::onException($throwable); // TODO: Change the autogenerated stub
  94. }
  95. }