Express.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 数据层模型
  15. */
  16. class Express extends BaseModel {
  17. public $page_info;
  18. /**
  19. * 查询快递列表
  20. * @access public
  21. * @author csdeshang
  22. * @return array
  23. */
  24. public function getExpressList() {
  25. return rkcache('express', true);
  26. }
  27. /**
  28. * 根据编号查询快递列表
  29. * @access public
  30. * @author csdeshang
  31. * @param int $id 快递编号
  32. * @return array
  33. */
  34. public function getExpressListByID($id = null) {
  35. $express_list = rkcache('express', true);
  36. if (!empty($id)) {
  37. $id_array = explode(',', $id);
  38. foreach ($express_list as $key => $value) {
  39. if (!in_array($key, $id_array)) {
  40. unset($express_list[$key]);
  41. }
  42. }
  43. return $express_list;
  44. } else {
  45. return array();
  46. }
  47. }
  48. /**
  49. * 查询详细信息(通过缓存获取)
  50. * @access public
  51. * @author csdeshang
  52. * @param int $id 快递编号
  53. * @return array
  54. */
  55. public function getExpressInfo($id) {
  56. $express_list = $this->getExpressList();
  57. return $express_list[$id];
  58. }
  59. /**
  60. * 获取单个信息
  61. * @param type $condition
  62. * @return type
  63. */
  64. public function getOneExpress($condition) {
  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. $ecode = trim($ecode);
  76. if (!$ecode) {
  77. return array('state' => false, 'msg' => '参数错误');
  78. }
  79. $express_list = $this->getExpressList();
  80. $express_info = array();
  81. if ($express_list) {
  82. foreach ($express_list as $v) {
  83. if ($v['express_code'] == $ecode) {
  84. $express_info = $v;
  85. }
  86. }
  87. }
  88. if (!$express_info) {
  89. return array('state' => false, 'msg' => '快递公司信息错误');
  90. } else {
  91. return array('state' => true, 'data' => array('express_info' => $express_info));
  92. }
  93. }
  94. /**
  95. * 获取快递列表
  96. * @param type $condition 条件
  97. * @param type $pagesize 分页
  98. * @param type $order 排序
  99. * @return type
  100. */
  101. public function getAllExpresslist($condition,$pagesize,$order='express_order,express_state desc,express_id'){
  102. if($pagesize){
  103. $res = Db::name('express')->where($condition)->order($order)->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  104. $this->page_info = $res;
  105. return $res->items();
  106. }else{
  107. return Db::name('express')->where($condition)->order($order)->select()->toArray();
  108. }
  109. }
  110. /**
  111. * 删除物流方式
  112. * @access public
  113. * @author csdeshang
  114. * @param array $condition 检索条件
  115. * @return boolean
  116. */
  117. public function delExpress($condition) {
  118. dkcache('express');
  119. return Db::name('express')->where($condition)->delete();
  120. }
  121. /**
  122. * 添加物流方式
  123. * @access public
  124. * @author csdeshang
  125. * @param array $data 参数内容
  126. * @return boolean
  127. */
  128. public function addExpress($data) {
  129. dkcache('express');
  130. return Db::name('express')->insertGetId($data);
  131. }
  132. /**
  133. * 编辑物流方式
  134. * @access public
  135. * @author csdeshang
  136. * @param array $condition 检索条件
  137. * @param array $update 更新数据
  138. * @return boolean
  139. */
  140. public function editExpress($condition, $update) {
  141. dkcache('express');
  142. return Db::name('express')->where($condition)->update($update);
  143. }
  144. /**
  145. * 快递查询
  146. */
  147. public function queryExpress($express_code,$shipping_code,$phone = ''){
  148. if ($express_code == 'SF'){
  149. $phone = ds_substing($phone,7,4);
  150. }
  151. $requestData= "{'OrderCode':'','ShipperCode':'".$express_code."','LogisticCode':'".$shipping_code."','CustomerName':'".$phone."'}";
  152. $datas = array(
  153. 'EBusinessID' => config('ds_config.expresscf_kdn_id'),
  154. 'RequestType' => config('ds_config.expresscf_kdn_type'),//1002即时查询 8002快递查询
  155. 'RequestData' => urlencode($requestData) ,
  156. 'DataType' => '2',
  157. 'DataSign' => urlencode(base64_encode(md5($requestData.config('ds_config.expresscf_kdn_key'))))
  158. );
  159. $result = http_request('http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx','post',$datas);
  160. return json_decode($result, true);
  161. }
  162. }
  163. ?>