public function deliver()
 {
     if (IS_POST) {
         $order_id = intval($_POST['order_id']);
         $order_data['shipping_express_id'] = intval($_POST['express']);
         $order_data['shipping_code'] = trim($_POST['express_sn']);
         M('Order')->where(array('order_id' => $order_id))->save($order_data);
         M('Serial')->where(array('order_id' => $order_id))->delete();
         foreach ($_POST['serial'] as $key => $val) {
             $sk = explode('_', $key);
             if (!empty($val)) {
                 $data['goods_id'] = $sk[1];
                 $data['serial_number'] = $val;
                 $data['status'] = 1;
                 $data['order_id'] = $order_id;
                 M('Serial')->add($data);
                 unset($sk);
             }
         }
         $where['order_id'] = $order_id;
         $where['order_state'] = 20;
         $res = $this->model->where($where)->setField('order_state', 30);
         if ($res) {
             $order_goods = M('OrderGoods')->where(array('order_id' => $order_id))->select();
             foreach ($order_goods as $key => $val) {
                 M('Goods')->where(array('goods_id' => $val['goods_id']))->setDec('goods_freez', $val['goods_num']);
             }
             $data['order_id'] = $order_id;
             $data['order_state'] = get_order_state_name(30);
             $data['change_state'] = get_order_state_name(40);
             $data['state_info'] = '平台已确认发货完成.等待客户收货.';
             $data['log_time'] = NOW_TIME;
             $data['operator'] = '管理员-' . AID;
             M('OrderLog')->add($data);
             $this->success('发货成功');
         } else {
             $this->success('修改序列号成功');
         }
     } elseif (IS_GET) {
         $order_sn = trim($_GET['sn']);
         $where['order_sn'] = $order_sn;
         $info = D('Order')->relation(true)->where($where)->find();
         foreach ($info['OrderGoods'] as $key => $val) {
             $goods_num = $val['goods_num'];
             $serial = M('Serial')->where(array('order_id' => $info['order_id'], 'goods_id' => $val['goods_id']))->select();
             for ($goods_num; $goods_num > 0; $goods_num--) {
                 $info['OrderGoods'][$key]['serial'][$goods_num] = $serial[$goods_num - 1]['serial_number'];
             }
             unset($goods_num);
             ksort($info['OrderGoods'][$key]['serial']);
         }
         $this->express = M('Express')->where(array('e_state' => 1))->order('e_order')->select();
         $this->info = $info;
         $this->display();
     }
 }
 /**
  * 百度支付异步通知
  */
 public function bdpayNotify()
 {
     $bdpay = new Bdpay();
     if ($bdpay->check_bfb_pay_result_notify()) {
         $order_sn = trim($_GET['order_no']);
         if ($_GET['type'] == 'repair') {
             $this->mod = M('Repair');
             $where = array('rp_sn' => $order_sn);
             $order = $this->mod->where($where)->find();
             if ($order['rp_status'] == 3) {
                 $res = $this->mod->where($where)->setField('rp_status', 4);
                 //订单日志
                 $log_data['rp_id'] = $order['rp_id'];
                 $log_data['log_content'] = '会员已支付维修订单.';
                 $log_data['log_time'] = NOW_TIME;
                 $log_data['is_view'] = 1;
                 M('RepairLog')->add($log_data);
             } else {
                 //订单日志
                 $log_data['rp_id'] = $order['rp_id'];
                 $log_data['log_content'] = '客户支付完成.但维修订单状态异常.';
                 $log_data['log_time'] = NOW_TIME;
                 $log_data['is_view'] = 1;
                 M('RepairLog')->add($log_data);
             }
         } else {
             $where = array('order_sn' => $order_sn);
             $order = $this->mod->where($where)->find();
             if ($order['order_state'] == 10) {
                 $res = $this->mod->where($where)->setField('order_state', 20);
                 //订单日志
                 $log_data['order_id'] = $order['order_id'];
                 $log_data['order_state'] = get_order_state_name(20);
                 $log_data['change_state'] = get_order_state_name(30);
                 $log_data['state_info'] = '会员已支付订单';
                 $log_data['log_time'] = NOW_TIME;
                 $log_data['operator'] = '会员';
                 M('OrderLog')->add($log_data);
             } else {
                 //订单日志
                 $log_data['order_id'] = $order['order_id'];
                 $log_data['order_state'] = get_order_state_name(0);
                 $log_data['change_state'] = get_order_state_name(0);
                 $log_data['state_info'] = '客户支付完成.但订单状态异常.异常状态为' . $order['order_state'] . ':' . get_order_state_name($order['order_state']);
                 $log_data['log_time'] = NOW_TIME;
                 $log_data['operator'] = '会员';
                 M('OrderLog')->add($log_data);
             }
         }
         if ($res) {
             $bdpay->notify_bfb();
         }
     }
 }
 /**
  * 取消订单
  */
 public function cancelOrder()
 {
     $order_sn = trim($_POST['sn']);
     $where['order_sn'] = $order_sn;
     $where['member_id'] = $this->mid;
     $where['order_state'] = 10;
     $res = M('Order')->where($where)->setField('order_state', 60);
     if ($res) {
         //解冻库存
         $order_id = M('Order')->where(array('order_sn' => $order_sn))->getField('order_id');
         $order_goods = M('OrderGoods')->where(array('order_id' => $order_id))->select();
         foreach ($order_goods as $key => $val) {
             M('Goods')->where(array('goods_id' => $val['goods_id']))->setInc('goods_storage', $val['goods_num']);
             M('Goods')->where(array('goods_id' => $val['goods_id']))->setDec('goods_freez', $val['goods_num']);
         }
         //订单日志
         $log_data['order_id'] = $order_id;
         $log_data['order_state'] = get_order_state_name(60);
         $log_data['change_state'] = '无';
         $log_data['state_info'] = '会员取消订单';
         $log_data['log_time'] = NOW_TIME;
         $log_data['operator'] = '会员';
         M('OrderLog')->add($log_data);
         $this->success('取消订单成功');
     } else {
         $this->error('取消订单失败');
     }
 }