Express.php 5.3 KB

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