MErp.Class.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * erp相关队列业务脚本
  4. */
  5. namespace Jobs\Model\MTopic;
  6. class MErp
  7. {
  8. /**
  9. * 锁定库存
  10. * @param string $callback_url 回调地址
  11. * @param string $callback_params 回调参数
  12. */
  13. public function lockStock($params)
  14. {
  15. if(!$params){
  16. echo '参数值有空值'.PHP_EOL;
  17. return false;
  18. }
  19. $callback_url = $params['callback_url'];
  20. $authorization = $params['token'];
  21. unset($params['callback_url']);
  22. unset($params['token']);
  23. $i = 1;
  24. do{
  25. $curl_option = [
  26. CURLOPT_HTTPHEADER => [
  27. 'Content-Type:text/plain',
  28. 'Authorization:'.$authorization,
  29. ],
  30. ];
  31. $result = request($callback_url, json_encode($params['data']), 10, $curl_option);
  32. if($result['httpcode'] == 200){
  33. echo '请求业务脚本成功'.PHP_EOL;
  34. return true;
  35. }
  36. $i ++;
  37. sleep(1);
  38. }while($result['httpcode'] != 200 && $i <= 3);
  39. echo '请求业务脚本失败'.PHP_EOL;
  40. return false;
  41. }
  42. }