Express.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 数据层模型
  10. */
  11. class Express extends BaseModel
  12. {
  13. public $page_info;
  14. /**
  15. * 查询快递列表
  16. * @access public
  17. * @author csdeshang
  18. * @return array
  19. */
  20. public function getExpressList()
  21. {
  22. return rkcache('express', true);
  23. }
  24. /**
  25. * 根据编号查询快递列表
  26. * @access public
  27. * @author csdeshang
  28. * @param int $id 快递编号
  29. * @return array
  30. */
  31. public function getExpressListByID($id = null)
  32. {
  33. $express_list = rkcache('express', true);
  34. if (!empty($id)) {
  35. $id_array = explode(',', $id);
  36. foreach ($express_list as $key => $value) {
  37. if (!in_array($key, $id_array)) {
  38. unset($express_list[$key]);
  39. }
  40. }
  41. return $express_list;
  42. } else {
  43. return array();
  44. }
  45. }
  46. /**
  47. * 查询详细信息(通过缓存获取)
  48. * @access public
  49. * @author csdeshang
  50. * @param int $id 快递编号
  51. * @return array
  52. */
  53. public function getExpressInfo($id)
  54. {
  55. $express_list = $this->getExpressList();
  56. return $express_list[$id];
  57. }
  58. /**
  59. * 获取单个信息
  60. * @param type $condition
  61. * @return type
  62. */
  63. public function getOneExpress($condition)
  64. {
  65. return Db::name('express')->where($condition)->find();
  66. }
  67. /**
  68. * 根据快递公司ecode获得快递公司信息
  69. * @access public
  70. * @author csdeshang
  71. * @param $ecode string 快递公司编号
  72. * @return array 快递公司详情
  73. */
  74. public function getExpressInfoByECode($ecode)
  75. {
  76. $ecode = trim($ecode);
  77. if (!$ecode) {
  78. return array('state' => false, 'msg' => '参数错误');
  79. }
  80. $express_list = $this->getExpressList();
  81. $express_info = array();
  82. if ($express_list) {
  83. foreach ($express_list as $v) {
  84. if ($v['express_code'] == $ecode) {
  85. $express_info = $v;
  86. }
  87. }
  88. }
  89. if (!$express_info) {
  90. return array('state' => false, 'msg' => '快递公司信息错误');
  91. } else {
  92. return array('state' => true, 'data' => array('express_info' => $express_info));
  93. }
  94. }
  95. /**
  96. * 获取快递列表
  97. * @param type $condition 条件
  98. * @param type $pagesize 分页
  99. * @param type $order 排序
  100. * @return type
  101. */
  102. public function getAllExpresslist($condition, $pagesize, $order = 'express_order,express_state desc,express_id')
  103. {
  104. if ($pagesize) {
  105. $res = Db::name('express')->where($condition)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  106. $this->page_info = $res;
  107. return $res->items();
  108. } else {
  109. return Db::name('express')->where($condition)->order($order)->select()->toArray();
  110. }
  111. }
  112. /**
  113. * 删除物流方式
  114. * @access public
  115. * @author csdeshang
  116. * @param array $condition 检索条件
  117. * @return boolean
  118. */
  119. public function delExpress($condition)
  120. {
  121. dkcache('express');
  122. return Db::name('express')->where($condition)->delete();
  123. }
  124. /**
  125. * 添加物流方式
  126. * @access public
  127. * @author csdeshang
  128. * @param array $data 参数内容
  129. * @return boolean
  130. */
  131. public function addExpress($data)
  132. {
  133. dkcache('express');
  134. return Db::name('express')->insertGetId($data);
  135. }
  136. /**
  137. * 编辑物流方式
  138. * @access public
  139. * @author csdeshang
  140. * @param array $condition 检索条件
  141. * @param array $update 更新数据
  142. * @return boolean
  143. */
  144. public function editExpress($condition, $update)
  145. {
  146. dkcache('express');
  147. return Db::name('express')->where($condition)->update($update);
  148. }
  149. /**
  150. * 快递查询
  151. */
  152. public function queryExpress($express_code, $shipping_code, $phone = '')
  153. {
  154. if ($express_code == 'SF') {
  155. $phone = ds_substing($phone, 7, 4);
  156. }
  157. $requestData = "{'OrderCode':'','ShipperCode':'" . $express_code . "','LogisticCode':'" . $shipping_code . "','CustomerName':'" . $phone . "'}";
  158. $datas = array(
  159. 'EBusinessID' => config('ds_config.expresscf_kdn_id'),
  160. 'RequestType' => config('ds_config.expresscf_kdn_type'), //1002即时查询 8002快递查询
  161. 'RequestData' => urlencode($requestData),
  162. 'DataType' => '2',
  163. 'DataSign' => urlencode(base64_encode(md5($requestData . config('ds_config.expresscf_kdn_key'))))
  164. );
  165. $result = http_request('http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx', 'post', $datas);
  166. return json_decode($result, true);
  167. }
  168. }