Express.php 5.4 KB

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