/**
  * 添加活动订单
  * @param $au_id
  * @param $user_id
  * @param array $pay_items
  * @return bool|array 成功返回 array($order_id, $order_no, $total_fee)
  *                    失败返回 false
  */
 public static function addActivityOrder($au_id, $user_id, array $pay_items)
 {
     $connection = self::_getConnection();
     $connection->begin();
     $goods_number_map = array();
     $goods_price_map = array();
     foreach ($pay_items as $pay_item) {
         $goods_number_map[$pay_item['id']] = $pay_item['number'];
     }
     $goods = Goods::getGoodsByIds(array_keys($goods_number_map));
     $total_fee = 0;
     foreach ($goods as $one_goods) {
         $goods_price_map[$one_goods['id']] = $one_goods['price'];
         $total_fee += $one_goods['price'] * $goods_number_map[$one_goods['id']];
     }
     $add_order_sql = "insert into PayList (orderNo, orderName, money, userId, orderType, relId) values (:order_no, '活动收费', :total_fee, :user_id, 'activity', :au_id)";
     $add_order_bind = array('total_fee' => $total_fee, 'user_id' => $user_id, 'au_id' => $au_id);
     do {
         $order_no = self::_genOrderNo();
         $add_order_bind['order_no'] = $order_no;
         $add_order_success = $connection->execute($add_order_sql, $add_order_bind);
         $err_info = $connection->getInternalHandler()->errorInfo();
     } while ($err_info[1] == '2627');
     if (!$add_order_success) {
         $connection->rollback();
         return false;
     }
     $new_order_id = $connection->lastInsertId();
     $order_detail_values_str = '';
     foreach ($goods_price_map as $goods_id => $goods_price) {
         $goods_number = $goods_number_map[$goods_id];
         $order_detail_values_str .= "({$goods_id}, {$new_order_id}, {$goods_number}, {$goods_price}), ";
     }
     $order_detail_values_str = rtrim($order_detail_values_str, ', ');
     $add_order_detail_sql = "insert into OrderToGoods (goods_id, order_id, number, price) values {$order_detail_values_str}";
     $add_order_detail_success = $connection->execute($add_order_detail_sql);
     if (!$add_order_detail_success) {
         $connection->rollback();
         return false;
     }
     $success = $connection->commit();
     if (!$success) {
         return false;
     }
     return array($new_order_id, $order_no, $total_fee);
 }
 public function setOrderInfo($orderNo, $conf)
 {
     $ret = Order::getOrderWithDetailByNo($orderNo);
     if (isset($ret['status']) && $ret['status'] == 1) {
         $order = $ret['data'];
     } else {
         $ret = array('status' => 0, 'msg' => $ret['msg']);
         return $ret;
     }
     $user_inst = new UserInstance();
     $ret = $user_inst->getUser($order['user_id']);
     if (isset($ret['status']) && $ret['status'] == 1) {
         $user = $ret['data'];
         $this->jkfGoodsPurchaser['id'] = $order['user_id'];
         $this->jkfGoodsPurchaser['name'] = $user['name'] ? $user['name'] : '';
         $this->jkfGoodsPurchaser['telNumber'] = $user['mobile'] ? $user['mobile'] : '';
     } else {
         $ret = array('status' => 0, 'msg' => $ret['msg']);
         return $ret;
     }
     $payNumber = $conf['payNumber'] ? $conf['payNumber'] : '';
     //$country = $order['country']?$order['country']:'日本';
     //$country = '日本';
     $countryNo = '116';
     // '日本'
     if (isset($order) && $order != NULL) {
         $this->jkfSign['businessNo'] = $orderNo;
         //    'payNumber'
         $this->jkfOrderImportHead['payNumber'] = $payNumber;
         // 订单号
         // TODO 下面这项可能在这重新计算
         $this->jkfOrderImportHead['orderTotalAmount'] = $order['payable_amount'] ? $order['payable_amount'] : '';
         // 订单总金额 order_amount payable_amount
         $this->jkfOrderImportHead['orderNo'] = $order['order_no'] ? $order['order_no'] : '';
         //   'orderNo'  订单编号
         $this->jkfOrderImportHead['orderTaxAmount'] = $order['taxes'] ? $order['taxes'] : '';
         //  订单税款
         $this->jkfOrderImportHead['orderGoodsAmount'] = $order['real_amount'] ? $order['real_amount'] : '';
         //订单货款 $order['payable_amount']
         // 固定规则 超过168 免运费    否则 30元运费
         if ($order['real_amount'] > 168) {
             $this->jkfOrderImportHead['feeAmount'] = 0;
         } else {
             $this->jkfOrderImportHead['feeAmount'] = 30;
         }
         // $this->jkfOrderImportHead['feeAmount'] = $order['real_freight']?$order['real_freight']:'';     // ? real_freight 总金额    运费   选填   单个商品金额 - 海关申报金额
         $this->jkfOrderImportHead['tradeTime'] = isset($order['create_time']) ? $order['create_time'] : '';
         // 成交时间  $order['create_time'] $order['pay_time'] 这个值好点
         //$this->jkfOrderImportHead['currCode'] = $order['currCode']?$order['currCode']:'';         // 成交币制
         $this->jkfOrderImportHead['totalAmount'] = isset($order['real_amount']) ? $order['real_amount'] : '';
         //
         $this->jkfOrderImportHead['consigneeEmail'] = "";
         //收件人邮箱     选填   $order['consigneeEmail']
         $this->jkfOrderImportHead['consigneeTel'] = isset($order['mobile']) ? $order['mobile'] : '';
         //收件人电话
         $this->jkfOrderImportHead['consignee'] = isset($order['accept_name']) ? $order['accept_name'] : '';
         //收件人
         $this->jkfOrderImportHead['consigneeAddress'] = isset($order['addr']) ? $order['addr'] : '';
         //
         // $this->jkfOrderImportHead['totalCount'] = 1;    // 总件数 默认给1
         // $this->jkfOrderImportHead['postMode'] = '';      //发货方式(物流方式) 选填
         $this->jkfOrderImportHead['senderCountry'] = $countryNo;
         //发件人国别 TODO  编码ID
         $this->jkfOrderImportHead['senderName'] = isset($user['name']) ? $user['name'] : '';
         //发件人名称
         $this->jkfOrderImportHead['purchaserId'] = isset($order['user_id']) ? $order['user_id'] : '';
         //购买人ID
         $this->jkfOrderImportHead['zipCode'] = isset($order['zip']) ? $order['zip'] : '';
         // 选填
         $this->jkfOrderImportHead['note'] = '';
         //  备注信息  选填
         $this->jkfOrderImportHead['wayBills'] = '';
         //运单号列表,单号之间分号隔开  选填
         $this->jkfOrderImportHead['rate'] = 1;
         // 汇率  结算时 用人民币  此项为1 选填
         $num = 0;
         foreach ($order['OrderGoods'] as $key => $detailItem) {
             if (isset($detailItem['prom_type']) && $detailItem['prom_type'] == 'bundling') {
                 $goods_ids = $detailItem['goods_ids'];
                 $goods_inst = new Goods();
                 $ret = $goods_inst->getGoodsByIds($goods_ids);
                 if (isset($ret['status']) && $ret['status'] == 1) {
                     $goods_list = $ret['data'];
                     foreach ($goods_list as $key => $item) {
                         $num++;
                         $jkfOrderDetail = array('goodsOrder' => $num, 'goodsName' => isset($item['name']) ? $item['name'] : '', 'goodsModel' => '', 'codeTs' => isset($item['tax_code']) ? $item['tax_code'] : '', 'grossWeight' => '', 'unitPrice' => isset($item['sell_price']) ? $item['sell_price'] : '', 'goodsUnit' => '件', 'goodsCount' => isset($detailItem['goods_nums']) ? $detailItem['goods_nums'] : '', 'originCountry' => isset($detailItem['origin_country']) ? $detailItem['origin_country'] : $countryNo);
                         $this->jkfOrderDetailList[] = $jkfOrderDetail;
                     }
                 }
             } else {
                 $num++;
                 $jkfOrderDetail = array('goodsOrder' => $num, 'goodsName' => isset($detailItem['goods_name']) ? $detailItem['goods_name'] : '', 'goodsModel' => '', 'codeTs' => isset($detailItem['tax_code']) ? $detailItem['tax_code'] : '', 'grossWeight' => '', 'unitPrice' => isset($detailItem['goods_price']) ? $detailItem['goods_price'] : '', 'goodsUnit' => '件', 'goodsCount' => isset($detailItem['goods_nums']) ? $detailItem['goods_nums'] : '', 'originCountry' => isset($detailItem['origin_country']) ? $detailItem['origin_country'] : $countryNo);
                 $this->jkfOrderDetailList[] = $jkfOrderDetail;
             }
         }
         $this->jkfOrderImportHead['totalCount'] = $num;
         // 总件数 默认给1  OK
         $ret = array('status' => 1, 'msg' => 'success!');
         return $ret;
     } else {
         $ret = array('status' => 0, 'msg' => '该订单号不存在--' . $orderNo);
         return $ret;
     }
 }