Pārlūkot izejas kodu

Merge branch 'fix_goods' into sess_0306

stanley-king 9 gadi atpakaļ
vecāks
revīzija
a2123ec358

+ 8 - 0
admin/control/cache.php

@@ -19,6 +19,7 @@ class cacheControl extends SystemControl
         'member_msg_tpl',   // 用户消息
         'consult_type',     // 咨询类型
         'circle_level',     // 圈子成员等级
+        'area',             // 省市区地址
     );
 
     public function __construct()
@@ -92,6 +93,13 @@ class cacheControl extends SystemControl
                 Model('web_config')->getWebHtml('index', 1);
                 delCacheFile('index');
             }
+
+            // 省市区地址
+            if (in_array('area', $todo)) {
+                dkcache('area');
+                dkcache('area_toplevelareas');  // 省级别缓存处理
+                dkcache('area_cityprovince');   // 市级别缓存处理
+            }
         }
 
         $this->log(L('cache_cls_operate'));

+ 1 - 0
admin/language/zh/cache.php

@@ -16,4 +16,5 @@ $lang['cache_cls_table']		= '表結構';
 $lang['cache_cls_express']		= '快遞公司';
 $lang['cache_cls_store_class']	= '店舖分類';
 $lang['cache_cls_store_grade']	= '店舖等級';
+$lang['cache_cls_address']		= '省市區地址缓存';
 $lang['cache_cls_ok']			= '更新成功';

+ 1 - 0
admin/language/zh_cn/cache.php

@@ -17,4 +17,5 @@ $lang['cache_cls_express']		= '快递公司';
 $lang['cache_cls_store_class']	= '店铺分类';
 $lang['cache_cls_store_grade']	= '店铺等级';
 $lang['cache_cls_circle_level']	= '圈子成员等级';
+$lang['cache_cls_address']		= '省市区地址缓存';
 $lang['cache_cls_ok']			= '更新成功';

+ 5 - 0
admin/templates/default/cache.clear.php

@@ -96,6 +96,11 @@
                           <input type="checkbox" name="cache[]" id="circle_level" value="circle_level" >
                           &nbsp;<?php echo $lang['cache_cls_circle_level']?></label>
                       </li>
+                      <li class="left w18pre">
+                        <label>
+                          <input type="checkbox" name="cache[]" id="area" value="area" >
+                          &nbsp;<?php echo $lang['cache_cls_address']?></label>
+                      </li>
                     </ul></td>
                 </tr>
               </tbody>

+ 6 - 1
core/framework/core/base.php

@@ -225,7 +225,12 @@ final class Base
 		//@ini_set("session.save_path", C('memcache.1.host').':'.C('memcache.1.port'));
 
 		//默认以文件形式存储session信息
-		session_save_path(BASE_DATA_PATH.'/session');
+		if (strcmp($config['session_type'], 'files') === 0) {
+			session_save_path(BASE_DATA_PATH.'/session');
+		} else if (strcmp($config['session_type'], 'redis') === 0) {
+			session_save_path($config['session_save_path']);
+		}
+		
 		session_start();
 	}
 

+ 21 - 0
crontab/control/hour.php

@@ -219,4 +219,25 @@ class hourControl extends BaseCronControl {
             $this->log($e->getMessage());
         }
     }
+
+    /**
+     * 定时推送异常订单(正常每半小时一次)
+     */
+    public function putExceptionOrderOp(){
+        $condition = array();
+        $condition['exception_state'] = 0;
+        // 查询异常订单(注意, 可能出现异常订单非常多的情况, 到时候用limit限制一下处理, 我写的时候就不做限制了)
+        $order_data = Model('order_exception_push')->where($condition)->select();
+
+        // 推送异常订单
+        $update_data['exception_state'] = 1;
+        foreach ($order_data as $value) {
+            $logic_delivery = Logic('delivery');
+            $ret = $logic_delivery->putOrder($value['pay_sn'], $value['pay_sn']);
+            if ($ret) {
+                // 更新订单状态
+                Model('order_exception_push')->where($condition)->update($update_data);
+            }
+        }
+    }
 }

+ 2 - 2
data/logic/buy.logic.php

@@ -589,6 +589,7 @@ class buyLogic {
      */
     private function _createOrderStep4() {
 
+        // extract() 函数从数组中将变量导入到当前的符号表。
         extract($this->_order_data);
 
         $member_id = $this->_member_info['member_id'];
@@ -648,7 +649,7 @@ class buyLogic {
             $order['store_name'] = $goods_list[0]['store_name'];
             $order['buyer_id'] = $member_id;
             $order['buyer_name'] = $member_name;
-            $order['buyer_email'] = $member_email;
+            $order['buyer_email'] = $member_email == NULL ? '' : $member_email;
             $order['add_time'] = time();
             $order['payment_code'] = $store_pay_type_list[$store_id];
             $order['order_state'] = $store_pay_type_list[$store_id] == 'online' ? ORDER_STATE_NEW : ORDER_STATE_PAY;
@@ -661,7 +662,6 @@ class buyLogic {
 			{
 				$order['payment_code']="offline";
 			}
-			//中山小修改货到付款bug<<<
             $order_id = $model_order->addOrder($order);
             if (!$order_id) {
                 throw new Exception('订单保存失败[未生成订单数据]');

+ 30 - 1
data/logic/delivery.logic.php

@@ -96,6 +96,12 @@ class deliveryLogic
                 array_push($delivery_order_list, $delivery_order);
             }
         }
+        // 订单状态不对
+        if (empty($delivery_order_list) || count($delivery_order_list) == 0) {
+            Log::record("putOrder: pay_sn={$pay_sn}, 错误原因: 订单状态不对");
+            return fasle;
+        }
+
         $data = array('type' => 'PUT_TRADE', 'data' => $delivery_order_list);
         $body = json_encode($data,JSON_UNESCAPED_UNICODE);
         $sign = $this->sign($body);
@@ -133,10 +139,18 @@ class deliveryLogic
      */
     private function check($pay_sn,$trade_no,$order_sn,$resp)
     {
+        $data = array();
+        $data_log = array();
+        $data['pay_sn'] = $pay_sn;
+        $data['order_sn'] = $order_sn;
+        $data_log['pay_sn'] = $pay_sn;
+        $data_log['order_sn']  = $order_sn;
+        $data_log['exception_time'] = time();
+        $data_log['exception_state'] = 0;
+
         //1:成功 0 :失败
         // 1:新订单 2:等待仓库处理 99:已拦截 90:库存不足 7:已发货
         // -99:发货失败 -2:订单关闭 -3:订单已存在(没有进行拦截的订单不予更新) -1:异常订单 -2:订单关闭
-
         $result = json_decode($resp, true);
         if (!empty($result) && is_array($result))
         {
@@ -144,6 +158,8 @@ class deliveryLogic
             {
                 if (!empty($result['data']) && is_array($result['data']) && count($result['data']) > 0)
                 {
+                    // 填充错误理由
+                    $data_log['exception_reason'] = $result['data'][0]['errorMessge'];
                     if (!empty($result['data'][0]['status']))
                     {
                         $status = intval($result['data'][0]['status']);
@@ -151,6 +167,8 @@ class deliveryLogic
                             return true;
                         } else {
                             Log::record("PUSHOMS ERR has status: order_sn = {$order_sn},pay_sn={$pay_sn},trade_no = {$trade_no}", Log::WAIT_HANDLE);
+                            Model('order_exception_push')->insert($data);
+                            Model('order_exception_log')->insert($data_log);
                             return false;
                         }
                     } else {
@@ -158,22 +176,33 @@ class deliveryLogic
                         if(strstr($msg,'订单已存在')) {
                             return true;
                         } else {
+                            // 技术债务, 未知问题, 不放入推送表, 确认后再放
+                            //Model('order_exception_push')->insert($data);
+                            Model('order_exception_log')->insert($data_log);
                             return false;
                         }
                     }
                 }
                 else
                 {
+                    // 填充错误理由
+                    $data_log['exception_reason'] = "$resp order_sn = {$order_sn},pay_sn={$pay_sn},trade_no = {$trade_no}";
                     Log::record("$resp order_sn = {$order_sn},pay_sn={$pay_sn},trade_no = {$trade_no}", Log::WAIT_HANDLE);
+                    Model('order_exception_push')->insert($data);
+                    Model('order_exception_log')->insert($data_log);
                     return false;
                 }
 
             } else {
                 Log::record("PUSHOMS ERR have not data: order_sn = {$order_sn},pay_sn={$pay_sn},trade_no = {$trade_no}", Log::WAIT_HANDLE);
+                Model('order_exception_push')->insert($data);
+                Model('order_exception_log')->insert($data_log);
                 return false;
             }
         } else {
             Log::record("PUSHOMS ERR empty result: order_sn = {$order_sn},pay_sn={$pay_sn},trade_no = {$trade_no}", Log::WAIT_HANDLE);
+            Model('order_exception_push')->insert($data);
+            Model('order_exception_log')->insert($data_log);
             return false;
         }
     }

+ 74 - 3
data/model/area.model.php

@@ -36,13 +36,25 @@ class areaModel extends Model {
      * @return array 键为id 值为名称字符串
      */
     public function getTopLevelAreas() {
-        $data = $this->getCache();
 
+        // 对象属性中有数据则返回
+        if ($this->cachedTopLevelAreas !== null)
+            return $this->cachedTopLevelAreas;
+
+        // 缓存中有数据则返回
         $arr = array();
+        if ($arr = rkcache('area_toplevelareas')) {
+            $this->cachedTopLevelAreas = $arr;
+            return $arr;
+        }
+
+        $data = $this->getCache();
         foreach ($data['children'][0] as $i) {
             $arr[$i] = $data['name'][$i];
         }
 
+        wkcache('area_toplevelareas', $arr);
+        $this->cachedTopLevelAreas = $arr;
         return $arr;
     }
 
@@ -52,15 +64,29 @@ class areaModel extends Model {
      * @return array 键为市级id 值为省级id
      */
     public function getCityProvince() {
-        $data = $this->getCache();
 
+        // 对象属性中有数据则返回
+        if ($this->cachedCityProvince !== null)
+            return $this->cachedCityProvince;
+
+        // 缓存中有数据则返回
         $arr = array();
+        if ($arr = rkcache('area_cityprovince')) {
+            $this->cachedCityProvince = $arr;
+            return $arr;
+        }
+
+        // 生成数据
+        $data = $this->getCache();
         foreach ($data['parent'] as $k => $v) {
             if ($v && $data['parent'][$v] == 0) {
                 $arr[$k] = $v;
             }
         }
 
+        wkcache('area_cityprovince', $arr);
+        $this->cachedCityProvince = $arr;
+
         return $arr;
     }
 
@@ -162,5 +188,50 @@ class areaModel extends Model {
         return $data;
     }
 
-    protected $cachedData;
+    /**
+     * 格式化地址, 返回格式化字符串, 省\t市\t区
+     * @return string
+     */
+    public function formatAddress($address) {
+       $topLevelAreas = $this->getTopLevelAreas();
+       $cityProvince = $this->getCityProvince();
+       $areaNames = $this->getAreaNames();
+
+        // 过滤空格等各种不可见字符
+        $address = trim($address);// 首先去掉头尾空格
+        $address = preg_replace('/\s(?=\s)/', '', $address);// 接着去掉两个空格以上的
+        $address = preg_replace('/[\n\r\t]/', '', $address);// 最后将非空格替换为没空格
+
+       // 省
+       foreach ($topLevelAreas as $key => $topValue) {
+            $topLevelLen = strlen($topValue);
+
+            // 匹配不到省, 跳过
+            $ret = strncmp($address, $topValue, $topLevelLen);
+            if ($ret != 0) continue;
+
+            $topLevelLen = mb_strlen($topValue);
+            // 市
+            foreach ($cityProvince as $cityValue => $parent) {
+                if ($parent != $key) continue;
+
+                $cityValue = $areaNames[$cityValue];
+                $cityLen = mb_strlen($cityValue);
+
+                $tmp = mb_substr($address, $topLevelLen, $cityLen);
+                // 匹配不到省, 跳过
+                if (strcmp($tmp, $cityValue) != 0) continue;
+
+                // 地区
+                $tmp = mb_substr($address, $topLevelLen+$cityLen, NULL);
+                return "{$topValue}\t{$cityValue}\t{$tmp}";
+            }
+       }
+
+       return null;
+    }
+
+    protected $cachedData;  // 地区表缓存
+    protected $cachedTopLevelAreas;   // 省名字缓存
+    protected $cachedCityProvince;    // 市id缓存
 }

+ 12 - 0
helper/area_check.php

@@ -0,0 +1,12 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 16/3/10
+ * Time: 下午2:33
+ */
+class area_check
+{
+
+}

+ 3 - 0
mobile/control/member_address.php

@@ -86,6 +86,9 @@ class member_addressControl extends mbMemberControl
             return self::outerr(errcode::ErrAddress, '地址数量已达上限');
         }
 
+        // 格式化区域信息
+        $model_area = Model('area');
+        $address_info['area_info'] = $model_area->formatAddress($address_info['area_info']);
         $result = $model_address->addAddress($address_info);
         if ($result) {
             $addr_acount = $model_address->getAddressCount(array('member_id' => $_SESSION['member_id']));

+ 140 - 0
mobile/control/member_refund.php

@@ -0,0 +1,140 @@
+<?php
+/**
+ * 会员退款退货
+ *
+ *
+ *
+ *
+
+ */
+
+//use Shopnc\Tpl;
+
+defined('InShopNC') or exit('Access Invalid!');
+
+class member_refundControl extends mbMemberControl
+{
+
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * 
+     * 退款接口(全退, 商品,全款全退, 不能指定)
+     */
+    public function refundOp()
+    {
+    	// 登录验证
+    	// $token = trim($_GET['key']);
+     //    if (false == $this->checkToken($token)) {
+     //        return joutput_error($this->err_code);
+     //    }
+
+        $order_info = Model('order')->getOrderInfo(array('order_sn' => $_GET['order_sn']));
+        if (empty($order_info)) {
+            joutput_error(array("errorMessage" => "订单为空"));
+            return;
+        }
+
+        $model_refund = Model('refund_return');
+        $condition = array();
+        $reason_list = $model_refund->getReasonList($condition);//退款退货原因
+        $order_id = intval($order_info['order_id']);
+        $goods_id = intval($_GET['goods_id']);//订单商品表编号(不传参数为全退, 传的话,为退 为指定退商品)
+        if (strstr($_GET['goods_id'], ',')) {
+            $goods_id = explode(',', $_GET['goods_id']);
+        }
+        $condition = array();
+        $condition['buyer_id'] = $order_info['buyer_id'];
+        $condition['order_id'] = $order_info['order_id'];
+        $order = $model_refund->getRightOrderList($condition, 0);
+        $order_id = $order['order_id'];
+        $order_amount = $order['order_amount'];//订单金额
+        $order_refund_amount = $order['refund_amount'];//订单退款金额
+        $goods_list = $order['goods_list'];
+        
+        $goods = $goods_list[0];
+        //$goods_pay_price = $goods['goods_pay_price'];//商品实际成交价
+        $goods_pay_price = $order_amount;   // 默认全退款
+        $goods_num = 1; // 数量,  默认为1
+        if (is_array($goods_id)) {// 计算物品数量
+            $goods_pay_price = 0.0;
+            $goods_num = count($goods_id);
+            foreach ($goods_list as $value) {
+                $tmp_goods_id = $value['goods_id'];
+                foreach ($goods_id as $goods_id_value) {
+                    if (intval($goods_id_value) == intval($tmp_goods_id)) {
+                        $goods_pay_price += floatval($value['goods_pay_price']);
+                    }
+                }
+            }
+        }
+            
+        $refund_amount = $goods_pay_price;
+        $goods_id = $goods['rec_id'];
+        $condition = array();
+        $condition['buyer_id'] = $order['buyer_id'];
+        $condition['order_id'] = $order['order_id'];
+        $condition['order_goods_id'] = $goods_id;
+        $condition['seller_state'] = array('lt','3');
+        $refund_list = $model_refund->getRefundReturnList($condition);
+        $refund = array();
+        if (!empty($refund_list) && is_array($refund_list)) {
+            $refund = $refund_list[0];
+        }
+        $refund_state = $model_refund->getRefundState($order);//根据订单状态判断是否可以退款退货
+        if ($refund['refund_id'] > 0 || $refund_state != 1) {//检查订单状态,防止页面刷新不及时造成数据错误
+            joutput_error(array("errorMessage" => "订单状态不正确"));
+        }
+        
+        $refund_array = array();
+        $refund_array['reason_info'] = '';
+        $reason_id = intval($_GET['reason_id']);//退货退款原因
+        $refund_array['reason_id'] = $reason_id;
+        $reason_array = array();
+        $reason_array['reason_info'] = '其他';
+        $reason_list[0] = $reason_array;
+        if (!empty($reason_list[$reason_id])) {
+            $reason_array = $reason_list[$reason_id];
+            $refund_array['reason_info'] = $reason_array['reason_info'];
+        }
+
+        $pic_array = array();
+        $pic_array['buyer'] = '';//$this->upload_pic();//上传凭证
+        $info = serialize($pic_array);
+        $refund_array['pic_info'] = $info;
+
+        $model_trade = Model('trade');
+        $order_shipped = $model_trade->getOrderState('order_shipped');//订单状态30:已发货
+        if ($order['order_state'] == $order_shipped) {
+            $refund_array['order_lock'] = '2';//锁定类型:1为不用锁定,2为需要锁定
+        }
+        $refund_array['refund_type'] = $_GET['refund_type'];//类型:1为退款,2为退货
+        $show_url = 'index.php?act=member_return&op=index';
+        $refund_array['return_type'] = $_GET['return_type'];//退货类型:1为不用退货,2为需要退货
+        if ($refund_array['refund_type'] != '2') {
+            $refund_array['refund_type'] = '1';
+            $refund_array['return_type'] = '1';
+            $show_url = 'index.php?act=member_refund&op=index';
+        }
+        $refund_array['seller_state'] = '1';//状态:1为待审核,2为同意,3为不同意
+        $refund_array['refund_amount'] = ncPriceFormat($refund_amount);
+        $refund_array['goods_num'] = $goods_num;
+        $refund_array['buyer_message'] = $_GET['buyer_message'];
+        $refund_array['add_time'] = time();
+        $state = $model_refund->addRefundReturn($refund_array,$order,$goods);
+
+        if ($state) {
+            if ($order['order_state'] == $order_shipped) {
+                $model_refund->editOrderLock($order_id);
+            }
+
+            joutput_data(array("errorMessage" => ""));
+        } else {
+            joutput_error(array("errorMessage" => "更新退款退货记录失败"));
+            
+        }
+    }
+}

+ 2 - 0
mobile/control/putorder.php

@@ -7,6 +7,8 @@
  * Time: 下午6:19
  */
 
+require_once (BASE_MOBILE_PATH . '/control/app_pay.php');
+
 class putorderControl extends mobileHomeControl
 {
     public function __construct()

+ 90 - 5
mobile/control/test.php

@@ -70,7 +70,7 @@ class testControl extends mobileHomeControl
     }
 
     /**
-     * �������
+     * 首页
      */
     public function indexOp(){
 
@@ -81,11 +81,31 @@ class testControl extends mobileHomeControl
 //        $payment = 500;
 //        $payment = $payment = $this->getAndUpdateBonus(36218,$payment);
 //        joutput_data(array('$payment'=>$payment));
+
+        // 修改地址
+        $order_id = "order_id in (297, 401, 923, 928,1097,1145,1150,1154,1244,1248,1281)";
+        $model = Model('order_common')->where($order_id)->select();
+        $model_address = Model('area');
+        $recv_info_array = array();
+        if ($model != null) {
+
+            foreach ($model as $val) {
+                $recv_info = unserialize($val['reciver_info']);
+
+                $recv_info['area'] = $model_address->formatAddress($recv_info['area']);
+                Model()->table('recv_info')->insert(array('order_id' => $val['order_id'], 'reciver_info' => serialize($recv_info)));
+
+                Model('order_common')->where(array('order_id'=>$val['order_id']))->update(array('reciver_info' => serialize($recv_info)));
+
+                array_push($recv_info_array, $recv_info);
+            }
+        }
+
+        joutput_data($recv_info_array);
     }
 
     public function getAndUpdateBonus($user_id,$pay_amount){
 
-        // ��ȡ���к�� �������Ϊ 1 ��user_id = member_id,��ǰʱ��С�ڽ���ʱ��(��ʱδ��Ϊ����)
         $condition['user_id'] = $user_id;
         $condition['bonus_type_id'] = 1;
         $bonus_list = Model()->table("user_bonus")->where($condition)->select();
@@ -94,12 +114,11 @@ class testControl extends mobileHomeControl
         if (!empty($bonus_list)) {
 
             foreach ($bonus_list as $value) {
-                $bonus_value = doubleval($value['bonus_value']);  // �����
+                $bonus_value = doubleval($value['bonus_value']);
 
-                // ֧�������ں����-��Ҫ����ѡ����
                 if (($pay_amount - $bonus_value) > 0.0000001) {
 
-                    $data['bonus_value'] = 0;  // ����Ϊ0
+                    $data['bonus_value'] = 0;
                     $ret = Model()->table('user_bonus')->where(array('bonus_id' => $value['bonus_id']))->update($data);
 
                     if($ret){
@@ -120,4 +139,70 @@ class testControl extends mobileHomeControl
 
         return $pay_amount;
     }
+
+    /**
+     * order_sn
+     * member_id
+     * 
+     * 手动退款接口
+     */
+    public function refundOp(){
+        $model_order = Model('order');
+        $model_trade = Model('trade');
+
+        $order_info = Model('order')->getOrderInfo(array('order_sn' => $_GET['order_sn']));
+        if (empty($order_info)) return;
+
+        $model_refund = Model('refund_return');        
+        $order_id = intval($order_info['order_id']);
+        $condition = array();
+        $condition['buyer_id'] = $order_info['buyer_id'];
+        $condition['order_id'] = $order_id;
+        $order = $model_refund->getRightOrderList($condition);
+        $order_amount = $order['order_amount'];//订单金额
+        $condition = array();
+        $condition['buyer_id'] = $order['buyer_id'];
+        $condition['order_id'] = $order['order_id'];
+        $condition['goods_id'] = '0';
+        $condition['seller_state'] = array('lt','3');
+        $refund_list = $model_refund->getRefundReturnList($condition);
+        $refund = array();
+        if (!empty($refund_list) && is_array($refund_list)) {
+            $refund = $refund_list[0];
+        }
+        $order_paid = $model_trade->getOrderState('order_paid');//订单状态20:已付款
+        $payment_code = $order['payment_code'];//支付方式
+        if ($refund['refund_id'] > 0 || $order['order_state'] != $order_paid || $payment_code == 'offline') {//检查订单状态,防止页面刷新不及时造成数据错误
+            joutput_error(array("result" => false));
+            return false;
+        }
+
+        $refund_array = array();
+        $refund_array['refund_type'] = '1';//类型:1为退款,2为退货
+        $refund_array['seller_state'] = '1';//状态:1为待审核,2为同意,3为不同意
+        $refund_array['order_lock'] = '2';//锁定类型:1为不用锁定,2为需要锁定
+        $refund_array['goods_id'] = '0';
+        $refund_array['order_goods_id'] = '0';
+        $refund_array['reason_id'] = '0';
+        $refund_array['reason_info'] = '取消订单,全部退款';
+        $refund_array['goods_name'] = '订单商品全部退款';
+        $refund_array['refund_amount'] = ncPriceFormat($order_amount);
+        $refund_array['buyer_message'] = $_POST['buyer_message'];
+        $refund_array['add_time'] = time();
+
+        $pic_array = array();
+        $pic_array['buyer'] = '';//$this->upload_pic();//上传凭证
+        $info = serialize($pic_array);
+        $refund_array['pic_info'] = $info;
+        $state = $model_refund->addRefundReturn($refund_array,$order);
+
+        if ($state) {
+            $model_refund->editOrderLock($order_id);
+            joutput_data(array("result" => true));
+            return true;
+        } else {
+            joutput_error(array("result" => false));
+            return false;
+        }
+    }
 }

+ 76 - 0
mobile/dispatch_notify.php

@@ -9,6 +9,78 @@
 //tid-订单号,status-1,consign_time-发货时间,logistics_no-快递流水,logistics_company-快递公司
 fcgi_header("Content-Type: text/plain; charset=UTF-8");
 
+/**
+ * Json方式  快递鸟物流信息订阅
+ * @param int $code: 快递类型
+ * @param array $no_list: 物流单号列表
+ */
+function getOrderTracesSubByJson($shipperCode, $logisticCode, $order_sn){
+     $requestData = "{\"OrderCode\":\"\",\"ShipperCode\":\"" . $shipperCode . "\",\"LogisticCode\":\"" . $logisticCode . "\" Bk\":\"" . $order_sn . "\"}";
+        $datas = array(
+            'EBusinessID' => '1256051',
+            'RequestType' => '1005',
+            'RequestData' => urlencode($requestData),
+            'DataType' => '2',
+        );
+    $datas['DataSign'] = $this->encrypt($requestData, '6718d260-e2b6-4329-ad78-daff173309ac');
+    $result = sendPost('http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx', $datas);
+    return $result;
+}
+
+/**
+ *  post提交数据 
+ * @param  string $url 请求Url
+ * @param  array $datas 提交的数据 
+ * @return url响应返回的html
+ */
+function sendPost($url, $datas) {
+    $temps = array();   
+    foreach ($datas as $key => $value) {
+        $temps[] = sprintf('%s=%s', $key, $value);      
+    }   
+    $post_data = implode('&', $temps);
+    $url_info = parse_url($url);
+    $httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";
+    $httpheader.= "Host:" . $url_info['host'] . "\r\n";
+    $httpheader.= "Content-Type:application/x-www-form-urlencoded\r\n";
+    $httpheader.= "Content-Length:" . strlen($post_data) . "\r\n";
+    $httpheader.= "Connection:close\r\n\r\n";
+    $httpheader.= $post_data;
+    $fd = fsockopen($url_info['host'], 80);
+    fwrite($fd, $httpheader);
+    $gets = ""; 
+    $headerFlag = true;
+    while (!feof($fd)) {
+        if (($header = @fgets($fd)) && ($header == "\r\n" || $header == "\n")) {
+            break;
+        }
+    }
+    while (!feof($fd)) {
+        $gets.= fread($fd, 128);
+    }
+    fclose($fd);  
+    
+    return $gets;
+}
+
+/**
+ *  通知快递鸟订阅回调 
+ * @param  string $url 请求Url
+ * @param  array $datas 提交的数据 
+ * @return url响应返回的html
+ */
+function notify_kdniao($order_sn) {
+
+    $model_order = Model('order');
+    $condition['order_sn'] = $order_sn;
+    $order_info = $model_order->getOrderInfo($condition, array('order_common', 'order_goods'));
+    // 发送快递鸟订阅回调
+    $express = rkcache('express', true);
+    $e_code = $express[$order_info['extend_order_common']['shipping_express_id']]['e_kdn_code'];
+    // 通知订阅, 快递鸟定时回调
+    getOrderTracesSubByJson($e_code, $order_info['shipping_code'], $order_sn);
+}
+
 try
 {
     $order_sn = trim($_POST['tid']);
@@ -37,12 +109,16 @@ try
             $order = Model('order');
             $ret = $order->setOrderDelivery($order_sn,$shipping_express_id,$logistics_no,$ship_time);
             if($ret) {
+                // 通知快递鸟回调
+                notify_kdniao($order_sn);
                 echo 'SUCCESS';
             } else {
                 echo 'AGAIN';
             }
         }
         else{
+            // 通知快递鸟回调
+            notify_kdniao($order_sn);
             echo 'SUCCESS';
         }
     }

+ 53 - 0
mobile/kdniao_notify.php

@@ -0,0 +1,53 @@
+<?php
+
+require_once(BASE_MOBILE_PATH . '/control/app_pay.php');
+require_once (BASE_DATA_PATH . '/logic/delivery.logic.php');
+
+$requestData = $_POST['RequestData'];  // 快递鸟数据
+$deliver_info = json_decode($requestData);
+
+Log::record("kdniao_notify: post data {$requestData}",Log::ERR);
+
+//数据不正确, 记录并退出
+if ($deliver_info === false || empty($deliver_info))
+{
+    Log::record("kdniao_notify:cannot query delivery info from kuaidn.",Log::ERR);
+    exit(0);
+}
+
+// 订单sn号
+$order_sn = $deliver_info['Data']['CallBack'];
+
+// 数据解析
+switch ($deliver_info['Data']['State'])
+{
+    case '2':	// 在途中, 不处理
+        $msg = '在途中';
+        Log::record('订单: {$order_sn} 在途中'); return;
+        break;
+    case '3':	// 已签收, 设置为已收货
+	    {
+	    	$msg = '已签收';
+	        $model_order = Model('order');
+	        $condition = array();
+	        $condition['order_state'] = ORDER_STATE_SEND;
+	        $condition['order_sn'] = $order_sn;
+	        $update = array();
+	        $update['order_state'] = ORDER_STATE_SUCCESS;	// 收货成功状态
+	        $update = $model_order->editOrder($update, $condition);
+	        if (!$update) {
+	            Log::record('更新订单状态为已收货状态时写入失败'); return;
+	        }
+	    }
+        break;
+    case '4':	// 问题件
+        $msg = '问题件';
+        break;
+    default: {
+        Log::record('query_status false');
+        return;
+    }
+}
+
+
+?>

+ 1 - 0
start-fcgi.sh

@@ -1,2 +1,3 @@
 #! /bin/sh
 spawn-fcgi -a 127.0.0.1 -p 9100 -F 1 -f "/usr/local/bin/php fcgi_run.php"
+