Kdbird.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\model\express;
  11. use app\model\system\Config as ConfigModel;
  12. use app\model\BaseModel;
  13. use extend\Kdbird as KdbirdExtend;
  14. /**
  15. * 快递鸟
  16. */
  17. class Kdbird extends BaseModel
  18. {
  19. /*********************************************************************** 快递100 start ***********************************************************************/
  20. /**
  21. * 快递鸟配置
  22. * @param $site_id
  23. * @return \multitype
  24. */
  25. public function getKdbirdConfig($site_id)
  26. {
  27. $config = new ConfigModel();
  28. $res = $config->getConfig([['app_module', '=', 'shop'], ['site_id', '=', $site_id], ['config_key', '=', 'EXPRESS_KDBIRD_CONFIG']]);
  29. if(empty($res['data']['value']['status'])){
  30. $res['data']['value']['status'] = 0;
  31. }
  32. return $res;
  33. }
  34. /**
  35. * 设置物流配送配置
  36. * @param $data
  37. * @return \multitype
  38. */
  39. public function setKdbirdConfig($data, $is_use, $site_id)
  40. {
  41. if ($is_use > 0) {
  42. event('CloseTrace', ['site_id' => $site_id]);
  43. }
  44. $config = new ConfigModel();
  45. $res = $config->setConfig($data, '快递鸟设置', $is_use, [['app_module', '=', 'shop'], ['site_id', '=', $site_id], ['config_key', '=', 'EXPRESS_KDBIRD_CONFIG']]);
  46. return $res;
  47. }
  48. /**
  49. * 开关状态
  50. * @param $is_use
  51. * @return array
  52. */
  53. public function modifyStatus($is_use, $site_id)
  54. {
  55. $config = new ConfigModel();
  56. $res = $config->modifyConfigIsUse($is_use, [['app_module', '=', 'shop'], ['site_id', '=', $site_id], ['config_key', '=', 'EXPRESS_KDBIRD_CONFIG']]);
  57. return $res;
  58. }
  59. /*********************************************************************** 快递100 end ***********************************************************************/
  60. /**
  61. * 查询物流轨迹 并且转化为兼容数据结构
  62. * @param $code
  63. * @param $express_no
  64. * @return array
  65. */
  66. public function trace($code, $express_no, $site_id, $mobile)
  67. {
  68. $config_result = $this->getKdbirdConfig($site_id);
  69. $config = $config_result['data'];
  70. if ($config['is_use'] == 0) return $this->error();
  71. $kd100_extend = new KdbirdExtend($config['value']);
  72. $result = $kd100_extend->orderTracesSubByJson($express_no, $code, $mobile);
  73. if (isset($result['success']) && $result['success']) {
  74. return $this->success($result);
  75. } else {
  76. return $this->error($result, $result['reason']);
  77. }
  78. }
  79. }