Selaa lähdekoodia

还原支付有关的代码

shaoguo 7 kuukautta sitten
vanhempi
sitoutus
d4ab83f544

+ 6059 - 5794
Modules/Home/Controller/CarController.class.php

@@ -1,5795 +1,6060 @@
-<?php
-/**
- *
- */
-namespace Home\Controller;
-
-class CarController extends CommonController
-{
-
-	//--------begin
-
-
-	public function reduce_car_goods()
-	{
-		$_GPC = I('request.');
-
-		$data = array();
-		$data['goods_id'] = $_GPC['goods_id'];
-		$data['community_id'] = $_GPC['community_id'];
-		$data['quantity'] = $_GPC['quantity'];
-		$data['sku_str'] = $_GPC['sku_str'];
-		if ($_GPC['sku_str'] == 'undefined') {
-			$_GPC['sku_str'] = '';
-			$data['sku_str'] = '';
-		}
-
-
-		$data['buy_type'] = $_GPC['buy_type'];
-		$data['pin_id'] = $_GPC['pin_id'];
-		$data['is_just_addcar'] = $_GPC['is_just_addcar'];
-
-		$data['soli_id'] = isset($_GPC['soli_id']) ? intval($_GPC['soli_id']) : '';
-
-
-		if (!isset($data['buy_type']) || empty($data['buy_type'])) {
-			$data['buy_type'] = 'dan';
-		}
-		$token = $_GPC['token'];
-
-
-
-		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where(array('token' => $token))->find();
-
-		$member_id = $weprogram_token['member_id'];
-
-
-		$is_just_addcar = empty($data['is_just_addcar']) ? 0 : 1;
-
-		$goods_id = $data['goods_id'];
-		if (empty($member_id)) {
-			$result = array('code' => 4);
-			echo json_encode($result);
-			die();
-		}
-
-		if (isset($data['goods_id'])) {
-			$goods_id = $data['goods_id'];
-		} else {
-			$goods_id = 0;
-		}
-
-		$goods_param = array();
-
-		$product = M('lionfish_comshop_goods')->where(array('id' => $goods_id))->find();
-
-		if ($product['grounding'] != 1) {
-			$json['code'] = 6;
-			$json['msg'] = '商品已下架!';
-			echo json_encode($json);
-			die();
-		}
-
-		$is_community = D('Seller/Communityhead')->is_community($data['community_id']);
-		if (!$is_community) {
-			$json['code'] = 6;
-			$json['msg'] = '该小区已经不存在!';
-			echo json_encode($json);
-			die();
-		}
-
-		//6 
-		if ($is_just_addcar == 1) {
-			if ($product['pick_just'] > 0) {
-				$json['code'] = 6;
-				$json['msg'] = '自提商品,请立即购买';
-				echo json_encode($json);
-				die();
-			}
-		}
-
-		//商品存在
-		if ($product) {
-
-			$cart = D('Home/Car');
-
-			if (isset($data['quantity'])) {
-				$quantity = $data['quantity'];
-			} else {
-				$quantity = 1;
-			}
-
-			$option = array();
-
-			if (!empty($data['sku_str'])) {
-				$option = explode('_', $data['sku_str']);
-			}
-
-			$cart_goods_quantity = $cart->get_wecart_goods($goods_id, $data['sku_str'], $data['community_id'], $token, $data['soli_id']);
-
-
-			$key = (int) $goods_id . ':' . $data['community_id'] . ':';
-
-
-			if (!empty($data['soli_id'])) {
-				$key .= $data['soli_id'] . ':';
-			}
-
-			if ($data['sku_str']) {
-				$key .= base64_encode($data['sku_str']) . ':';
-			} else {
-				$key .= ':'; //xx
-			}
-
-			$car_prefix = 'cart.';
-
-			if (!empty($data['buy_type']) && $data['buy_type'] == 'soitaire') {
-				$key = 'soitairecart.' . $key;
-				$car_prefix = 'soitairecart.';
-			} else {
-				$key = 'cart.' . $key;
-			}
-
-
-
-
-			$json = array('code' => 0);
-
-
-			$car_info = M('lionfish_comshop_car')->where(array('carkey' => $key, 'community_id' => $data['community_id']))->find();
-
-			$tmp_format_data = unserialize($car_info['format_data']);
-
-			//$tmp_format_data['quantity']
-			if ($tmp_format_data['quantity'] == 1 || $tmp_format_data['quantity'] <= $quantity) {
-				$all_cart = M('lionfish_comshop_car')->where(array('carkey' => $key, 'community_id' => $data['community_id'], 'token' => $token))->delete();
-
-			} else {
-
-				$tmp_format_data['quantity'] = $tmp_format_data['quantity'] - $quantity;
-
-				M('lionfish_comshop_car')->where(array('id' => $car_info['id'], 'community_id' => $data['community_id']))->save(array('format_data' => serialize($tmp_format_data)));
-
-			}
-
-			$cart = D('Home/Car');
-			$total = $cart->count_goodscar($token, $data['community_id']);
-
-
-			$json['code'] = 1;
-			if ($data['buy_type'] != 'dan') {
-				$json['code'] = 2;
-			}
-
-
-			$cart_goods_quantity = $cart->get_wecart_goods($goods_id, $data['sku_str'], $data['community_id'], $token);
-
-
-			$json['success'] = '成功加入购物车!!';
-			$json['total'] = $total;
-			$json['cur_count'] = $cart_goods_quantity;
-
-
-			$is_limit_distance_buy = D('Home/Front')->get_config_by_name('shop_limit_buy_distance');
-
-			$json['is_limit_distance_buy'] = $is_limit_distance_buy;
-
-			$json['goods_total_count'] = 0;
-
-			if (!empty($data['buy_type']) && $data['buy_type'] == 'soitaire') {
-				$json['goods_total_count'] = $cart->get_wecart_goods_solicount($goods_id, $data['community_id'], $token, $data['soli_id']);
-
-				$json['cur_count'] = $cart->get_wecart_goods($goods_id, $data['sku_str'], $data['community_id'], $token, $car_prefix, $data['soli_id']);
-
-			}
-
-			echo json_encode($json);
-			die();
-		}
-
-	}
-
-	/**
-		   pintuan_newman_notice
-	   **/
-	public function add_newcar()
-	{
-		$_GPC = I('request.');
-
-		$data = array();
-		$data['goods_id'] = $_GPC['goods_id'];
-		$data['buy_type'] = 'pintuan';
-		$data['community_id'] = $_GPC['community_id'];
-
-		$community_id = $data['community_id'];
-
-		$data['quantity'] = 1;
-
-		$token = $_GPC['token'];
-
-		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where(array('token' => $token))->find();
-
-		$member_id = $weprogram_token['member_id'];
-
-
-		$goods_id = $data['goods_id'];
-		if (empty($member_id)) {
-			$result = array('code' => 4);
-			echo json_encode($result);
-			die();
-		}
-
-		$goods_param = array();
-
-		$product = M('lionfish_comshop_goods')->where(array('id' => $goods_id))->find();
-
-		if ($product['grounding'] != 1) {
-			$json['code'] = 6;
-			$json['msg'] = '商品已下架!';
-			echo json_encode($json);
-			die();
-		}
-
-
-		$goods_description = D('Home/Front')->get_goods_common_field($goods_id, 'total_limit_count,one_limit_count,is_new_buy');
-
-		$pin_model = D('Home/Pin');
-
-		$iszero_opentuan = $pin_model->check_goods_iszero_opentuan($goods_id);
-
-		if ($iszero_opentuan != 1) {
-			$json['code'] = 6;
-			$json['msg'] = '非邀请团商品!';
-			echo json_encode($json);
-			die();
-		}
-
-		$cart = D('Home/Car');
-
-
-
-		if ($product) {
-			if (!empty($data['buy_type']) && $data['buy_type'] == 'pintuan') {
-				$car_prefix = 'pintuancart.';
-			}
-
-			$cart_goods_quantity = $cart->get_wecart_goods($goods_id, $data['sku_str'], $data['community_id'], $token, $car_prefix);
-
-
-			$json = array('code' => 0);
-			//$goods_model = D('Home/Goods');
-			$goods_quantity = $cart->get_goods_quantity($goods_id);
-
-
-			//检测商品限购 6 one_limit_count
-			/**
-					 $can_buy_count = D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
-					 
-					 if(!empty($cart_goods_quantity) && $cart_goods_quantity > 0)
-					 {
-						 if($goods_description['one_limit_count'] > 0 && $cart_goods_quantity >= $goods_description['one_limit_count'] )
-						 {
-							 $json['code'] =6;
-							 //$json['msg']='已经不能再买了';
-							 
-							 $json['msg']='您本次只能购买'.$goods_description['one_limit_count'].'个';
-							 
-							 $json['max_quantity'] = $goods_description['one_limit_count'];
-							 
-							 echo json_encode($json);
-							 die();
-						 }
-						 
-						 $can_buy_count = $can_buy_count - $cart_goods_quantity;
-						 if($can_buy_count <= 0)
-						 {
-							 $can_buy_count = -1;
-						 }
-					 }
-					 if($can_buy_count == -1 && $goods_description['total_limit_count'] >0)
-					 {
-						 $json['code'] =6;
-						 //$json['msg']='已经不能再买了';
-						 
-						 $json['msg']='您本次只能购买'.$goods_description['total_limit_count'].'个';
-						 
-						 $json['max_quantity'] = $goods_description['total_limit_count'];
-					 
-						 echo json_encode($json);
-						 die();
-					 }else if($can_buy_count >0 && $quantity >$can_buy_count)
-					 {
-						 $json['code'] =6;
-						 $json['msg']='您还能购买'.$can_buy_count.'份';
-						 
-						 $json['max_quantity'] = $can_buy_count;
-						 echo json_encode($json);
-						 die();
-					 }
-				 
-					 //已加入购物车的总数
-					 
-					 if($goods_quantity<$quantity+$cart_goods_quantity){
-						 $json['code'] =3;
-						 if ($goods_quantity==0) {
-							 $json['msg']='已抢光';
-						 }else{
-							 // $json['msg']='商品数量不足,剩余'.$goods_quantity.'个!!';
-							 $json['msg']='商品数量不足';
-							 $json['max_quantity'] = $goods_quantity;
-						 }
-
-						 echo json_encode($json);
-						 die();
-					 }
-					 **/
-			//开始生产订单 TODO...
-
-			$payment = M('lionfish_comshop_member')->where(array('member_id' => $member_id))->find();
-
-			$data = array();
-
-			$data['member_id'] = $member_id;
-			$data['name'] = $payment['username'];
-			$data['use_score'] = 0; //是否使用积分抵扣
-
-			$data['telephone'] = '0000';
-			$data['shipping_name'] = '0000';
-			$data['shipping_tel'] = '0000';
-			$data['shipping_address'] = '';
-			$data['shipping_province_id'] = 0;
-			$data['shipping_city_id'] = 0;
-			$data['shipping_stree_id'] = 0;
-			$data['shipping_country_id'] = 0;
-
-
-			$data['shipping_method'] = 0;
-			$data['delivery'] = 'express';
-
-			$data['pick_up_id'] = $community_id;
-
-			$data['ziti_name'] = '';
-			$data['ziti_mobile'] = '';
-
-			$data['payment_method'] = 'yuer';
-
-			$data['address_id'] = 0;
-			$data['voucher_id'] = 0; //目前都是平台券
-
-
-			$data['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
-			$data['date_added'] = time();
-
-
-			$data['type'] = 'pintuan';
-			$data['shipping_fare'] = 0;
-
-			$goods_data = array();
-
-			$goods_data[] = array(
-				'goods_id' => $product['id'],
-				'store_id' => 0,
-				'name' => $product['goodsname'],
-				'model' => '',
-				'is_pin' => 1,
-				'pin_id' => 0,
-				'header_disc' => 0,
-				'member_disc' => 0,
-				'level_name' => '',
-				'option' => '',
-				'quantity' => 1,
-				'shipping_fare' => 0,
-				'price' => $product['price'],
-				'card_price' => 0,
-				'costprice' => 0,
-				'total' => 0,
-				'card_total' => 0,
-				'is_take_vipcard' => 0,
-				'fenbi_li' => 0,
-				'can_man_jian' => 0,
-				'comment' => ''
-			);
-
-			$data['is_free_shipping_fare'] = 0;
-			$data['store_id'] = 0;
-			$data['order_goods_total_money'] = 0;
-
-
-			$data['goodss'] = $goods_data;
-			$data['order_num_alias'] = build_order_no($member_id);
-			$data['voucher_credit'] = 0;
-			$data['score_for_money'] = 0;
-			$data['reduce_money'] = 0;
-			$data['man_total_free'] = 0;
-
-
-			$oid = D('Home/Frontorder')->addOrder($data); // D('Order')->addOrder($data);
-
-			$o = array();
-			$o['payment_code'] = 'yuer';
-			$o['order_status_id'] = 2;
-			$o['date_modified'] = time();
-			$o['pay_time'] = time();
-			$o['transaction_id'] = '余额支付';
-			$o['type'] = 'ignore';
-
-			//ims_ 
-			M('lionfish_comshop_order')->where(array('order_id' => $oid))->save($o);
-
-			//更新到0元开团订单类型
-
-			echo json_encode(array('code' => 0, 'order_id' => $oid));
-			die();
-		}
-
-	}
-	//end--
-
-	public function add()
-	{
-		$gpc = I('request.');
-
-
-		$data = array();
-		$data['goods_id'] = $gpc['goods_id'];
-		$data['community_id'] = $gpc['community_id'];
-		$data['quantity'] = $gpc['quantity'];
-		$data['sku_str'] = $gpc['sku_str'];
-		$data['is_just_addcar'] = $gpc['is_just_addcar'];
-		$data['soli_id'] = isset($gpc['soli_id']) ? intval($gpc['soli_id']) : '';
-
-
-		if ($gpc['sku_str'] == 'undefined') {
-			$gpc['sku_str'] = '';
-			$data['sku_str'] = '';
-		}
-
-		$pintuan_model_buy = D('Home/Front')->get_config_by_name('pintuan_model_buy');
-
-		if (empty($pintuan_model_buy) || $pintuan_model_buy == 0) {
-			$pintuan_model_buy = 0;
-		}
-
-		$data['buy_type'] = $gpc['buy_type'];
-		$data['pin_id'] = $gpc['pin_id'];
-		$data['is_just_addcar'] = $gpc['is_just_addcar'];
-
-		if (!isset($data['buy_type']) || empty($data['buy_type'])) {
-			$data['buy_type'] = 'dan';
-		} else if (!empty($data['buy_type']) && $data['buy_type'] == 'soitaire') {
-			$data['buy_type'] = 'soitaire';
-		} else if (!empty($data['buy_type']) && $data['buy_type'] == 'pindan') {
-			$data['buy_type'] = 'pindan';
-		} else if (!empty($data['buy_type']) && $data['buy_type'] == 'pintuan') {
-			$data['buy_type'] = 'pintuan';
-		} else if (!empty($data['buy_type']) && $data['buy_type'] == 'presale') {
-			$data['buy_type'] = 'presale';
-		} else if (!empty($data['buy_type']) && $data['buy_type'] == 'virtualcard') {
-			$data['buy_type'] = 'virtualcard';
-		} else if (!empty($data['buy_type']) && $data['buy_type'] == 'integral') {
-			$data['buy_type'] = 'integral';
-		}
-
-
-		$token = $gpc['token'];
-
-		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where(array('token' => $token))->find();
-
-		$member_id = $weprogram_token['member_id'];
-
-
-		$puis_not_buy = D('Home/Front')->get_config_by_name('puis_not_buy');
-
-		$member_info = M('lionfish_comshop_member')->where(array('member_id' => $member_id))->find();
-
-
-		if (!empty($puis_not_buy) && $puis_not_buy == 1) {
-
-			if ($member_info['level_id'] == 0) {
-				$json['code'] = 6;
-				$json['msg'] = '普通会员不能购买!';
-				echo json_encode($json);
-				die();
-			}
-		}
-
-		//1、判断是否开启审核,2、如果开启审核,判断会员状态是否审核
-		$is_user_shenhe = D('Home/Front')->get_config_by_name('is_user_shenhe');
-		//1
-		if (isset($is_user_shenhe) && $is_user_shenhe == 1) {
-			if ($member_info['is_apply_state'] != 1) {
-				$json['code'] = 6;
-				$json['msg'] = '会员未审核不能购买';
-				echo json_encode($json);
-				die();
-			}
-		}
-
-		//团长休息
-		$community_id = $gpc['community_id'];
-		$group_name = D('Home/Front')->get_config_by_name('group_name');
-		if (isset($community_id) && $community_id > 0) {
-			$is_can_buy = D('Seller/Communityhead')->check_goods_can_community($gpc['goods_id'], $community_id);
-
-			if (!$is_can_buy) {
-				$json['code'] = 6;
-				$json['msg'] = '此商品在您所属' . $group_name . '不可参与!';
-				echo json_encode($json);
-				die();
-			}
-			// is_all_sale
-		}
-
-		$is_just_addcar = empty($data['is_just_addcar']) ? 0 : 1;
-
-		$goods_id = $data['goods_id'];
-		if (empty($member_id)) {
-			$result = array('code' => 4);
-			echo json_encode($result);
-			die();
-		}
-
-		if (isset($data['goods_id'])) {
-			$goods_id = $data['goods_id'];
-		} else {
-			$goods_id = 0;
-		}
-
-
-		$product = M('lionfish_comshop_goods')->where(array('id' => $goods_id))->find();
-
-		if ($product['grounding'] != 1) {
-			$json['code'] = 6;
-			$json['msg'] = '商品已下架!';
-			echo json_encode($json);
-			die();
-		}
-
-
-		$goods_description = D('Home/Front')->get_goods_common_field($goods_id, 'total_limit_count,one_limit_count,oneday_limit_count,is_new_buy,is_limit_levelunbuy,is_limit_vipmember_buy,goods_start_count');
-
-		//is_limit_levelunbuy
-		//$is_default_levellimit_buy = D('Home/Front')->get_config_by_name('is_default_levellimit_buy');
-		//isset($is_default_levellimit_buy) && $is_default_levellimit_buy == 1 &&
-
-		if ($goods_description['is_limit_levelunbuy'] == 1) {
-			// member_id
-			$mb_info = M('lionfish_comshop_member')->field('level_id')->where(array('member_id' => $member_id))->find();
-
-			if ($mb_info['level_id'] == 0) {
-				$json['code'] = 6;
-				$json['msg'] = '默认等级不能购买,请联系客服';
-				echo json_encode($json);
-				die();
-			}
-		}
-
-		//is_limit_vipmember_buy 付费会员专享
-
-		//$is_default_vipmember_buy = D('Home/Front')->get_config_by_name('is_default_vipmember_buy');
-		//isset($is_default_vipmember_buy) && $is_default_vipmember_buy == 1 &&
-
-		if ($goods_description['is_limit_vipmember_buy'] == 1) {
-			$mb_vip = M('lionfish_comshop_member')->field('card_id,card_begin_time,card_end_time')->where(array('member_id' => $member_id))->find();
-
-			//当前时间
-			$present_time = time();
-
-			if ($mb_vip['card_id'] == 0 || ($present_time > $mb_vip['card_end_time'])) {
-
-				$is_pop_vipmember_buytip = D('Home/Front')->get_config_by_name('is_pop_vipmember_buytip');
-				$is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
-				$pop_vipmember_buyimage = D('Home/Front')->get_config_by_name('pop_vipmember_buyimage');
-
-				$json['has_image'] = 0;
-
-				$is_open_vipcard_buy = isset($is_open_vipcard_buy) ? $is_open_vipcard_buy : 0;
-
-				if (isset($is_pop_vipmember_buytip) && $is_pop_vipmember_buytip == 1) {
-					if (isset($pop_vipmember_buyimage) && !empty($pop_vipmember_buyimage)) {
-						$pop_vipmember_buyimage = tomedia($pop_vipmember_buyimage);
-
-						$json['has_image'] = 1;
-						$json['pop_vipmember_buyimage'] = $pop_vipmember_buyimage;
-					}
-				}
-				$json['code'] = 7;
-
-
-				$json['msg'] = '付费会员专享,普通会员不能购买';
-				echo json_encode($json);
-				die();
-			}
-
-		}
-
-		if (!empty($goods_description['is_new_buy']) && $goods_description['is_new_buy'] == 1) {
-
-			$ck_buy_order = M('lionfish_comshop_order')->field('order_id')->where("member_id={$member_id} and order_status_id in (1,4,6,7,10,11,12,14)")->find();
-
-			if (!empty($ck_buy_order)) {
-				$json['code'] = 6;
-				$json['msg'] = '新人专享!';
-				echo json_encode($json);
-				die();
-			}
-
-			$is_new_buy_limit = D('Home/Front')->get_config_by_name('is_new_buy_limit');
-			$new_buy_limit_num = D('Home/Front')->get_config_by_name('new_buy_limit_num');
-			if (!empty($is_new_buy_limit) && $is_new_buy_limit == 1) { //新人专享限制
-				$goods_cate_count = D('Home/Car')->get_new_goods_count($token, $goods_id, $data['sku_str']);
-				if ($goods_cate_count >= $new_buy_limit_num) {
-					$json['code'] = 6;
-					$json['msg'] = '超出新人专享限制!';
-					echo json_encode($json);
-					die();
-				}
-			}
-		}
-
-
-
-
-		//$data['community_id']
-		if ($data['buy_type'] == 'dan' || $data['buy_type'] == 'soitaire' || ($pintuan_model_buy == 1 && $data['buy_type'] != 'dan')) {
-			$is_community = D('Seller/Communityhead')->is_community($data['community_id']);
-			if (!$is_community) {
-				$json['code'] = 6;
-				$json['msg'] = '该小区已经不存在!';
-				echo json_encode($json);
-				die();
-			}
-		}
-
-		//判断是否积分兑换
-		if ($product['type'] == 'integral') {
-			//判断积分是否足够 member_id 暂时关闭以下代码
-
-			$integral_model = D('Home/Integral');
-			if (isset($data['quantity'])) {
-				$quantity = $data['quantity'];
-			} else {
-				$quantity = 1;
-			}
-			if (intval($quantity) < 1) {
-				$json['code'] = 6;
-				$json['msg'] = '数量不能小于1!';
-				echo json_encode($json);
-				die();
-			}
-			$check_result = $integral_model->check_user_score_quantity_can_pay($member_id, $data['sku_str'], $goods_id, $quantity);
-
-			if ($check_result['code'] == 1) {
-				$json['code'] = 6;
-				$json['msg'] = '剩余' . $check_result['cur_score'] . '积分,积分不足!';
-				echo json_encode($json);
-				die();
-			}
-			/****/
-		}
-
-		//6 
-		if ($is_just_addcar == 1) {
-			if ($product['pick_just'] > 0) {
-				$json['code'] = 6;
-				$json['msg'] = '自提商品,请立即购买';
-				echo json_encode($json);
-				die();
-			}
-		}
-
-		//商品存在
-		if ($product) {
-
-			$cart = D('Home/Car');
-
-			if (isset($data['quantity'])) {
-				$quantity = $data['quantity'];
-			} else {
-				$quantity = 1;
-			}
-
-			$option = array();
-
-			if (!empty($data['sku_str'])) {
-				$option = explode('_', $data['sku_str']);
-			}
-
-			$car_prefix = "cart.";
-
-			if (!empty($data['buy_type']) && $data['buy_type'] == 'pindan') {
-				$car_prefix = 'pindancart.'; //cart.
-			} else if (!empty($data['buy_type']) && $data['buy_type'] == 'soitaire') {
-				$car_prefix = 'soitairecart.';
-			} else if (!empty($data['buy_type']) && $data['buy_type'] == 'pintuan') {
-				$car_prefix = 'pintuancart.';
-			} else if (!empty($data['buy_type']) && $data['buy_type'] == 'presale') {
-				$car_prefix = 'presalecart.';
-			} else if (!empty($data['buy_type']) && $data['buy_type'] == 'virtualcard') {
-				$car_prefix = 'virtualcardcart.';
-			} else if (!empty($data['buy_type']) && $data['buy_type'] == 'integral') {
-				$car_prefix = 'integralcart.';
-			}
-
-			//$data['soli_id']
-			if ($data['is_just_addcar'] == 0) {
-				$cart_goods_quantity = 0;
-			} else {
-				$cart_goods_quantity = $cart->get_wecart_goods($goods_id, $data['sku_str'], $data['community_id'], $token, $car_prefix, $data['soli_id']);
-			}
-
-
-
-			$cart_goods_all_quantity = $cart->get_wecartall_goods($goods_id, $data['sku_str'], $data['community_id'], $token, $car_prefix);
-
-
-			$json = array('code' => 0);
-			//$goods_model = D('Home/Goods');
-			$goods_quantity = $cart->get_goods_quantity($goods_id);
-			if (!empty($data['sku_str'])) {
-				$goods_option_item_value = M('lionfish_comshop_goods_option_item_value')->field('stock')->where(array('goods_id' => $goods_id, 'option_item_ids' => $data['sku_str']))->find();
-				if (!empty($goods_option_item_value)) {
-					$goods_quantity = $goods_option_item_value['stock'];
-				}
-			}
-
-
-			//rela_goodsoption_valueid
-			if ($goods_quantity < $goods_description['goods_start_count']) {
-				$json['code'] = 6;
-				$json['msg'] = '起售数量' . $goods_description['goods_start_count'] . ',库存不足,剩余' . $goods_quantity . '个';
-				$json['max_quantity'] = $goods_description['goods_start_count'];
-				echo json_encode($json);
-				die();
-			}
-			//起售数量判断
-			if ($quantity + $cart_goods_quantity < $goods_description['goods_start_count']) {
-				$json['code'] = 6;
-				$json['msg'] = $goods_description['goods_start_count'] . '份起售';
-				$json['max_quantity'] = $goods_description['goods_start_count'];
-				echo json_encode($json);
-				die();
-			}
-			//$can_buy_count = D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
-			/**
-					 //单次限购
-					 if(!empty($cart_goods_all_quantity) && $cart_goods_all_quantity > 0 && $data['buy_type'] != 'pintuan' )
-					 {
-						 if($goods_description['one_limit_count'] > 0 && $cart_goods_all_quantity >= $goods_description['one_limit_count'] )
-						 {
-							 $json['code'] =6;
-							 //$json['msg']='已经不能再买了';
-
-							 $json['msg'] = '您本次只能购买'.$goods_description['one_limit_count'].'个';
-
-							 $json['max_quantity'] = $goods_description['one_limit_count'];
-
-							 echo json_encode($json);
-							 die();
-						 }
-
-						 $can_buy_count = $can_buy_count - $cart_goods_all_quantity;
-						 if($can_buy_count <= 0)
-						 {
-							 $can_buy_count = -1;
-						 }
-					 }
-					 //每单限购
-					 if($can_buy_count > 0 && $quantity > $can_buy_count)
-					 {
-						 $json['code'] =6;
-						 $json['msg']='您每次只能购买'.$can_buy_count.'份';
-
-						 $json['max_quantity'] = $can_buy_count;
-						 echo json_encode($json);
-						 die();
-					 }
-
-					 //每日限购 6
-					 $can_buy_day_count =  D('Home/Front')->check_goods_user_canbuy_day_count($member_id, $goods_id);
-
-					 if ($goods_description['oneday_limit_count'] >0){
-						 if($can_buy_day_count == -1 || ($can_buy_day_count > 0 && ($cart_goods_all_quantity+$quantity) > $can_buy_day_count))
-						 {
-							 $json['code'] =6;
-							 //$json['msg']='已经不能再买了';
-							 $json['msg']='您每天只能购买'.$goods_description['oneday_limit_count'].'个';
-
-							 $json['max_quantity'] = $goods_description['oneday_limit_count'];
-
-							 echo json_encode($json);
-							 die();
-						 }
-					 }
-
-					 //历史限购判断
-					 if($can_buy_count == -1 && $goods_description['total_limit_count'] >0)
-					 {
-						 $json['code'] =6;
-						 //$json['msg']='已经不能再买了';
-						 $json['msg']='您还能购买'.$goods_description['total_limit_count'].'个';
-						 
-						 $json['max_quantity'] = $goods_description['total_limit_count'];
-					 
-						 echo json_encode($json);
-						 die();
-					 }
-					 **/
-
-			$can_buy_one_count = D('Home/Front')->check_goods_user_canbuy_one_count($member_id, $goods_id);
-
-
-			/*$goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'total_limit_count,one_limit_count,oneday_limit_count,is_new_buy,is_limit_levelunbuy,is_limit_vipmember_buy,goods_start_count');
-					 if($quantity < $goods_description['goods_start_count']){
-						 $json['code'] = 6;
-						 //$json['msg'] = '您本次只能购买'.$goods_description['one_limit_count'].'份';
-						 $json['msg'] = $goods_description['goods_start_count'].'件起售';
-						 $json['max_quantity'] = $goods_description['goods_start_count'];
-						 echo json_encode($json);
-						 die();
-					 }*/
-
-			//单次限购判断
-			if ($goods_description['one_limit_count'] > 0 && $quantity + $cart_goods_quantity > $goods_description['one_limit_count']) {
-				$json['code'] = 6;
-				//$json['msg'] = '您本次只能购买'.$goods_description['one_limit_count'].'份';
-				$json['msg'] = '购物车总数已满或超出每次购买数量';
-				$json['max_quantity'] = $goods_description['one_limit_count'] - $cart_goods_all_quantity;
-				echo json_encode($json);
-				die();
-			}
-
-			$can_buy_day_count = D('Home/Front')->check_goods_user_canbuy_day_count($member_id, $goods_id);
-			if ($can_buy_day_count == -1 || ($can_buy_day_count > 0 && $quantity > $can_buy_day_count)) {
-				$json['code'] = 6;
-				//$json['msg'] = '您今天只能购买'.$goods_description['oneday_limit_count'].'份';
-				$json['msg'] = '购物车总数已满或超出每天购买数量';
-				$json['max_quantity'] = $can_buy_day_count - $cart_goods_all_quantity;
-				echo json_encode($json);
-				die();
-			} else if ($can_buy_day_count > 0 && ($quantity + $cart_goods_quantity) > $can_buy_day_count) {
-				$json['code'] = 6;
-				//$json['msg'] = '您今天还能购买'.$can_buy_day_count.'份';
-				$json['msg'] = '购物车总数已满或超出每天购买数量';
-				$json['max_quantity'] = $can_buy_day_count - $cart_goods_all_quantity;
-				echo json_encode($json);
-				die();
-			}
-
-			$can_buy_all_count = D('Home/Front')->check_goods_user_canbuy_all_count($member_id, $goods_id);
-			if ($data['buy_type'] == 'pintuan' || $data['buy_type'] == 'pindan' || $data['buy_type'] == 'presale') {
-				$cart_goods_all_quantity = 0;
-			}
-			//历史限购判断
-			if ($can_buy_all_count == -1 && $goods_description['total_limit_count'] > 0) {
-				$json['code'] = 6;
-				//$json['msg']='您最多只能购买'.$goods_description['total_limit_count'].'份';
-				$json['msg'] = '购物车总数已满或超出历史购买数量';
-				$json['max_quantity'] = 1;
-				echo json_encode($json);
-				die();
-			} else if ($can_buy_all_count > 0 && ($cart_goods_all_quantity + $quantity) > $can_buy_all_count) {
-				$json['code'] = 6;
-				$json['msg'] = '购物车总数已满或超出历史购买数量';
-				$json['max_quantity'] = $can_buy_all_count - $cart_goods_all_quantity;
-				echo json_encode($json);
-				die();
-			}
-
-			//已加入购物车的总数
-
-			if ($goods_quantity < $quantity + $cart_goods_quantity) {
-				$json['code'] = 3;
-				if ($goods_quantity == 0) {
-					$json['msg'] = '已抢光';
-				} else {
-					$json['msg'] = '商品数量不足';
-					$json['max_quantity'] = $goods_quantity;
-				}
-
-				echo json_encode($json);
-				die();
-			}
-
-			if (!empty($option)) {
-				$mul_opt_arr = array();
-
-				//ims_ 
-				//$goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->where( array('goods_id' => $goods_id,'option_item_ids' => $data['sku_str']) )->find();
-				$open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
-
-				if (!empty($open_redis_server) && $open_redis_server == 1) {
-					$goods_option_mult_value_stock = D('Seller/Redisorder')->get_goods_sku_quantity($goods_id, $data['sku_str']);
-				} else {
-					$goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->where(array('goods_id' => $goods_id, 'option_item_ids' => $data['sku_str']))->find();
-				}
-
-
-				if (!empty($goods_option_mult_value_stock)) {
-					if ($goods_option_mult_value_stock < $quantity + $cart_goods_quantity) {
-						$json['code'] = 3;
-						$json['msg'] = '商品数量不足,剩余' . $goods_option_mult_value_stock . '个!!';
-
-						$json['max_quantity'] = $goods_option_mult_value['stock'];
-						echo json_encode($json);
-						die();
-					}
-				}
-			}
-
-			//buy_type
-
-			// $this->clear_all_cart(); $data['community_id']
-
-			$format_data_array = array(
-				'quantity' => $quantity,
-				'community_id' => $data['community_id'],
-				'goods_id' => $goods_id,
-				'sku_str' => $data['sku_str'],
-				'buy_type' => $data['buy_type'],
-				'soli_id' => $data['soli_id']
-			);
-			//区分活动商品还是普通商品。做两个购物车,活动商品是需要直接购买的,单独购买商品加入正常的购物车TODO....
-			//is_just_addcar 0  1
-			if ($data['buy_type'] == 'dan' && $is_just_addcar == 0) {
-
-				//$cart->removedancar($token);
-				//清空一下购物车
-				//singledel
-				$format_data_array['is_just_addcar'] = 0;
-				$format_data_array['singledel'] = 1;
-
-				$cart->addwecar($token, $goods_id, $format_data_array, $data['sku_str'], $data['community_id']);
-				$total = $cart->count_goodscar($token, $data['community_id']);
-			} else if ($data['buy_type'] == 'dan' && $is_just_addcar == 1) {
-				//singledel
-				$format_data_array['is_just_addcar'] = 1;
-				$format_data_array['singledel'] = 1;
-				$cart->addwecar($token, $goods_id, $format_data_array, $data['sku_str'], $data['community_id']);
-				$total = $cart->count_goodscar($token, $data['community_id']);
-			} else if (!empty($data['buy_type']) && $data['buy_type'] == 'soitaire') {
-				//清理单独购买的商品
-				$format_data_array['is_just_addcar'] = 1;
-				$format_data_array['singledel'] = 1;
-
-				$cart->addwecar($token, $goods_id, $format_data_array, $data['sku_str'], $data['community_id'], $car_prefix, $data['soli_id']);
-				$total = 0;
-			} else if (!empty($data['buy_type']) && $data['buy_type'] == 'pindan') {
-				//清理单独购买的商品
-				$cart->removeActivityAllcar($token, 'pindancart.');
-				$format_data_array['is_just_addcar'] = 0;
-				$format_data_array['singledel'] = 1;
-
-				$cart->addwecar($token, $goods_id, $format_data_array, $data['sku_str'], $data['community_id'], $car_prefix);
-				$total = 0;
-			} else if (!empty($data['buy_type']) && $data['buy_type'] == 'pintuan') {
-				$pin_id = isset($data['pin_id']) ? $data['pin_id'] : 0;
-
-				if ($pin_id > 0) {
-					$pin_info_tmp = M('lionfish_comshop_pin')->where(array('pin_id' => $pin_id))->find();
-
-					if (!empty($pin_info_tmp) && $pin_info_tmp['is_newman_takein'] == 1) {
-						//检测是否新人
-						//检测是否购买过
-						$od_status = "1,2,4,6,7,8,9,10,11,12,14";
-
-						$od_buy_count = M('lionfish_comshop_order')->where("order_status_id in ({$od_status}) and member_id=" . $member_id)->count();
-
-						if (!empty($od_buy_count) && $od_buy_count > 0) {
-							$json['code'] = 3;
-							$json['msg'] = '新人专享';
-
-							echo json_encode($json);
-							die();
-						}
-					}
-
-				}
-
-				//清理拼团的商品
-				$cart->removeActivityAllcar($token, 'pintuancart.');
-				$format_data_array['is_just_addcar'] = 0;
-				$format_data_array['singledel'] = 1;
-				$format_data_array['pin_id'] = $pin_id;
-
-				$cart->addwecar($token, $goods_id, $format_data_array, $data['sku_str'], $data['community_id'], $car_prefix);
-				$total = 0;
-			} else if (!empty($data['buy_type']) && $data['buy_type'] == 'presale') {
-				//清理预售的商品
-				$cart->removeActivityAllcar($token, 'presalecart.');
-				$format_data_array['is_just_addcar'] = 0;
-				$format_data_array['singledel'] = 1;
-
-				$cart->addwecar($token, $goods_id, $format_data_array, $data['sku_str'], $data['community_id'], $car_prefix);
-				$total = 0;
-			} else if (!empty($data['buy_type']) && $data['buy_type'] == 'virtualcard') {
-				//清理预售的商品
-				$cart->removeActivityAllcar($token, 'virtualcardcart.');
-				$format_data_array['is_just_addcar'] = 0;
-				$format_data_array['singledel'] = 1;
-
-				$cart->addwecar($token, $goods_id, $format_data_array, $data['sku_str'], $data['community_id'], $car_prefix);
-				$total = 0;
-			} else if (!empty($data['buy_type']) && $data['buy_type'] == 'integral') {
-
-				//清理拼团的商品 $data['pin_id']
-				$cart->removeActivityAllcar($token, 'integralcart.');
-				$format_data_array['is_just_addcar'] = 0;
-				$format_data_array['singledel'] = 1;
-
-				$cart->addwecar($token, $goods_id, $format_data_array, $data['sku_str'], $data['community_id'], $car_prefix);
-				$total = 0;
-			} else {
-				//buy_type:pin  活动购物车。
-				$pin_id = isset($data['pin_id']) ? $data['pin_id'] : 0;
-
-				//lottery
-				if ($product['type'] == 'lottery' && $product['type'] == 'lottery') {
-					/**
-								   //等待把抽奖的活动打开
-								   $now_time = time();
-								   $lottery_goods_info =  M('lottery_goods')->where( array('goods_id' => $goods_id) )->find();
-								   
-								   if($lottery_goods_info['end_time'] < $now_time)
-								   {
-									   $json['code'] =6;
-									   $json['msg']='抽奖活动已结束';
-									   echo json_encode($json);
-									   die();
-								   }
-								   **/
-				}
-
-				//检测商品是否老带新,新人才能参团
-				if ($pin_id > 0) {
-					//等待把老带新的活动打开
-					/**
-								   if($product['type'] == 'newman')
-								   {
-									   $new_mamn_buy = $goods_model->check_goods_new_manbug($member_id);
-									   if($new_mamn_buy>0)
-									   {
-										   $json['code'] =5;
-										   $json['msg']='该商品只能新人参团';
-										   echo json_encode($json);
-										   die();
-									   }
-								   }
-								   **/
-				}
-
-				$format_data_array['pin_id'] = $pin_id;
-
-				$cart->add_activitycar($token, $goods_id, $format_data_array, $data['sku_str']);
-				$total = $cart->count_activitycar($token);
-			}
-
-
-			$carts = M('lionfish_comshop_car')->where(array('token' => $token, 'community_id' => $data['community_id'], 'carkey' => 'cart_total'))->find();
-
-			if (!empty($data['buy_type']) && $data['buy_type'] == 'dan') {
-				if (!empty($carts)) {
-					$car_data = array();
-					$car_data['format_data'] = serialize(array('quantity' => $total));
-					$car_data['modifytime'] = 1;
-
-					M('lionfish_comshop_car')->where(array('token' => $token, 'community_id' => $data['community_id'], 'carkey' => 'cart_total'))->save($car_data);
-
-				} else {
-
-					$car_data = array();
-					$car_data['token'] = $token;
-
-					$car_data['community_id'] = $data['community_id'];
-					$car_data['carkey'] = 'cart_total';
-					$car_data['format_data'] = serialize(array('quantity' => $total));
-
-					M('lionfish_comshop_car')->add($car_data);
-				}
-			}
-
-			//session('cart_total',$total);
-			$json['code'] = 1;
-			if ($data['buy_type'] != 'dan') {
-				$json['code'] = 2;
-			}
-			$json['success'] = '成功加入购物车!!';
-			$json['total'] = $total;
-
-			$cart_goods_quantity = $cart->get_wecart_goods($goods_id, $data['sku_str'], $data['community_id'], $token, $car_prefix);
-			$json['cur_count'] = $cart_goods_quantity;
-
-
-
-			//soitaire 
-			$is_limit_distance_buy = D('Home/Front')->get_config_by_name('shop_limit_buy_distance');
-
-			$json['is_limit_distance_buy'] = $is_limit_distance_buy;
-
-			$json['goods_total_count'] = 0;
-
-			if (!empty($data['buy_type']) && $data['buy_type'] == 'soitaire') {
-				$json['goods_total_count'] = $cart->get_wecart_goods_solicount($goods_id, $data['community_id'], $token, $data['soli_id']);
-
-				$cart_goods_quantity = $cart->get_wecart_goods($goods_id, $data['sku_str'], $data['community_id'], $token, $car_prefix, $data['soli_id']);
-				$json['cur_count'] = $cart_goods_quantity;
-			}
-
-
-			echo json_encode($json);
-			die();
-		}
-
-	}
-
-	//显示购物车中商品列表
-	function show_cart_goods()
-	{
-
-		$gpc = I('request.');
-
-		$token = $gpc['token'];
-		$community_id = $gpc['community_id'];
-		$soli_id = isset($gpc['soli_id']) ? intval($gpc['soli_id']) : '';
-
-		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where(array('token' => $token))->find();
-
-		$member_id = $weprogram_token['member_id'];
-
-		$is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
-		$is_open_vipcard_buy = !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 ? 1 : 0;
-		$modify_vipcard_name = D('Home/Front')->get_config_by_name('modify_vipcard_name');
-
-
-		$is_vip_card_member = 0;
-		$is_member_level_buy = 0;
-
-		if ($member_id > 0) {
-			$member_info = M('lionfish_comshop_member')->where(array('member_id' => $member_id))->find();
-
-			if (!empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1) {
-
-				$now_time = time();
-
-				if ($member_info['card_id'] > 0 && $member_info['card_end_time'] > $now_time) {
-					$is_vip_card_member = 1; //还是会员
-				} else if ($member_info['card_id'] > 0 && $member_info['card_end_time'] < $now_time) {
-					$is_vip_card_member = 2; //已过期
-				}
-			}
-
-			if ($is_vip_card_member != 1 && $member_info['level_id'] > 0) {
-				$is_member_level_buy = 1;
-			}
-		}
-
-		$buy_type = isset($gpc['buy_type']) ? $gpc['buy_type'] : 'dan';
-
-		if (empty($member_id)) {
-			//需要登录
-			echo json_encode(array('code' => 5));
-			die();
-		}
-
-		$cart = D('Home/Car');
-
-		$goods = $cart->get_all_goodswecar($buy_type, $token, 0, $community_id, $soli_id);
-
-
-		$seller_goodss = array();
-
-		$seller_goodss_mult = array();
-
-		//is_only_express
-		$tp_ar = array();
-
-		foreach ($goods as $key => $val) {
-			//$goods_store_field =  M('goods')->field('store_id')->where( array('goods_id' => $val['goods_id']) )->find();
-			//$seller_goodss[ $goods_store_field['store_id'] ]['goods'][$key] = $val;
-
-			$supply_id = D('Home/Front')->get_goods_supply_id($val['goods_id']);
-			if ($supply_id > 0) {
-				$supply_info = D('Home/Front')->get_supply_info($supply_id);
-
-				if ($supply_info['type'] == 0) {
-					$supply_id = 0;
-				}
-			}
-
-
-			$seller_goodss[$supply_id]['goods'][$key] = $val;
-
-			$tp_ar[] = $val['is_only_express'];
-			$seller_goodss_mult[$val['is_only_express']][$supply_id]['goods'][$key] = $val; //new 0719
-
-		}
-
-		$ck_goodstype_count = 0;
-		$vipcard_save_money = 0;
-
-		$level_save_money = 0;
-		//$max_can_orderbuy_money = 0 ;
-		foreach ($seller_goodss_mult as $key => $seller_goodss_tp) {
-
-			foreach ($seller_goodss_tp as $store_id => $val) {
-				//total
-				$seller_voucher_list = array();
-				$seller_total_fee = 0;
-				$total_trans_free = 0;
-
-				$tmp_goods = array();
-
-				$is_store_ck = false;
-
-				foreach ($val['goods'] as $kk => $d_goods) {
-					$seller_total_fee += $d_goods['total'];
-
-					$total_trans_free += $d_goods[$kk]['trans_free'];
-					$val['goods'][$kk] = $d_goods;
-
-					$tp_val = array();
-					$tp_val['id'] = $d_goods['goods_id'];
-					$tp_val['key'] = $d_goods['key'];
-					if ($d_goods['singledel'] == 1) {
-						$tp_val['isselect'] = true;
-						$is_store_ck = true;
-						$ck_goodstype_count++;
-						if ($d_goods['is_take_vipcard'] == 1) {
-							$vipcard_save_money = $d_goods['total'] - $d_goods['card_total'];
-						} else if ($d_goods['is_mb_level_buy'] == 1) {
-							$level_save_money = $d_goods['total'] - $d_goods['level_total'];
-						}
-					} else {
-						$tp_val['isselect'] = false;
-					}
-
-					$tp_val['imgurl'] = $d_goods['image'];
-					$tp_val['edit'] = 'inline';
-					$tp_val['title'] = htmlspecialchars_decode($d_goods['name']);
-					$tp_val['finish'] = 'none';
-					$tp_val['description'] = 'description';
-
-					$option_arr = array();
-					$option_str = "";
-					foreach ($d_goods['option'] as $option_val) {
-						//$option_arr[] = $option_val['name'].':'.$option_val['value'];
-						$option_arr[] = $option_val['value'];
-					}
-					if (!empty($option_arr)) {
-						$option_str = implode(';', $option_arr);
-					}
-
-
-					$tp_val['can_buy'] = D('Home/Pingoods')->get_goods_time_can_buy($d_goods['goods_id']);
-
-					$tp_val['option_can_buy'] = D('Home/Pingoods')->get_goods_option_can_buy($d_goods['goods_id'], $d_goods['sku_str']);
-
-
-					$tp_val['goodstype'] = $option_str;
-					$tp_val['goodstypeedit'] = $option_str;
-					$tp_val['goodsnum'] = $d_goods['quantity'];
-					$tp_val['can_man_jian'] = $d_goods['can_man_jian'];
-					$tp_val['max_quantity'] = $d_goods['max_quantity'];
-					$tp_val['cartype'] = 'inline';
-					$tp_val['currntprice'] = $d_goods['price'];
-					$tp_val['card_price'] = $d_goods['card_price'];
-
-					$tp_val['levelprice'] = $d_goods['levelprice']; // 会员等级价格
-					$tp_val['is_mb_level_buy'] = $d_goods['is_mb_level_buy']; //是否可以会员等级价格购买
-
-					$tp_val['is_take_vipcard'] = $d_goods['is_take_vipcard'];
-					$tp_val['price'] = $d_goods['shop_price'];
-					$tp_val['is_new_buy'] = $d_goods['is_new_buy'];
-					$tp_val['goods_start_count'] = $d_goods['goods_start_count'];
-					$tp_val['store_id'] = $store_id;
-					$tmp_goods[] = $tp_val;
-
-				}
-
-				//$store_info = M('seller')->field('s_id,s_true_name,s_logo')->where( array('s_id' => $store_id) )->find();
-				//$store_info['s_logo'] = C('SITE_URL').'Uploads/image/'.$store_info['s_logo'];
-
-				$store_info = array('s_true_name' => '', 's_id' => 1);
-				$s_logo = D('Home/Front')->get_config_by_name('shoplogo');
-
-				if (!empty($s_logo)) {
-					$s_logo = tomedia($s_logo);
-				}
-
-				$val['store_info'] = $store_info;
-
-				$store_data = array();
-				$store_data['id'] = $store_info['s_id'];
-				if ($is_store_ck) {
-					$store_data['isselect'] = true;
-				} else {
-					$store_data['isselect'] = false;
-				}
-
-				$store_data['shopname'] = $store_info['s_true_name'];
-				$store_data['caredit'] = 'inline';
-				$store_data['finish'] = 'none';
-				$store_data['count'] = '0.00';
-
-				$is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
-				$full_money = D('Home/Front')->get_config_by_name('full_money');
-				$full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
-
-				if (empty($full_reducemoney) || $full_reducemoney <= 0) {
-					$is_open_fullreduction = 0;
-				}
-
-				$store_data['is_open_fullreduction'] = $is_open_fullreduction;
-				$store_data['full_money'] = $full_money;
-				$store_data['full_reducemoney'] = $full_reducemoney;
-
-
-
-				$store_data['goodstype'] = 2;
-				$store_data['goodstypeselect'] = 0;
-				$store_data['shopcarts'] = $tmp_goods;
-
-				//起送价格
-				$localtown_moneytype_fixed_deliverymoney = 0;
-				//达到金额免配送费
-				$localtown_moneytype_fixed_freemoney = 0;
-
-
-				$localtown_fixed_list = array();
-				if ($key == 3) { //同城配送商品
-					$storename = "";
-					if ($store_id == 0) {
-						//配送费类型:0、固定金额,1、按距离收取
-						$localtown_delivery_moneytype = D('Home/Front')->get_config_by_name('localtown_delivery_moneytype');
-						if ($localtown_delivery_moneytype == 0) {
-							$localtown_moneytype_fixed_deliverymoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_deliverymoney');
-							$localtown_moneytype_fixed_freemoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_freemoney');
-						}
-						$storename = "平台";
-					} else {
-						$isopen_localtown_delivery = D('Home/Front')->get_supply_config_by_name('isopen_localtown_delivery', $store_id);
-						//配送费类型:0、固定金额,1、按距离收取
-						$localtown_delivery_moneytype = D('Home/Front')->get_supply_config_by_name('localtown_delivery_moneytype', $store_id);
-						if ($isopen_localtown_delivery == 1 && $localtown_delivery_moneytype == 0) {
-							$localtown_moneytype_fixed_deliverymoney = D('Home/Front')->get_supply_config_by_name('localtown_moneytype_fixed_deliverymoney', $store_id);
-							$localtown_moneytype_fixed_freemoney = D('Home/Front')->get_supply_config_by_name('localtown_moneytype_fixed_freemoney', $store_id);
-						}
-						$supply_info_data = M('lionfish_comshop_supply')->field('storename')->where(array('id' => $store_id))->find();
-						$storename = $supply_info_data['storename'];
-					}
-					$localtown_fixed_list['localtown_moneytype_fixed_deliverymoney'] = $localtown_moneytype_fixed_deliverymoney;
-					//if($localtown_moneytype_fixed_deliverymoney > $max_can_orderbuy_money){
-					//获取起送最大下单金额限制
-					//$max_can_orderbuy_money = $localtown_moneytype_fixed_deliverymoney;
-					//}
-					$localtown_fixed_list['localtown_moneytype_fixed_freemoney'] = $localtown_moneytype_fixed_freemoney;
-					$localtown_fixed_list['store_name'] = $storename;
-				} else if ($key == 2) {
-					if ($store_id == 0) {
-						$storename = "平台";
-					} else {
-						$supply_info_data = M('lionfish_comshop_supply')->field('storename')->where(array('id' => $store_id))->find();
-						$storename = $supply_info_data['storename'];
-					}
-					$localtown_fixed_list['store_name'] = $storename;
-				}
-				$store_data['localtown_fixed_list'] = $localtown_fixed_list;
-				$seller_goodss_tp[$store_id] = $store_data;
-				$i++;
-			}
-			$seller_goodss_mult[$key] = $seller_goodss_tp;
-
-		}
-
-
-
-
-		foreach ($seller_goodss as $store_id => $val) {
-			//total
-			$seller_voucher_list = array();
-			$seller_total_fee = 0;
-			$total_trans_free = 0;
-
-			$tmp_goods = array();
-
-			$is_store_ck = false;
-
-			foreach ($val['goods'] as $kk => $d_goods) {
-				$seller_total_fee += $d_goods['total'];
-
-				$total_trans_free += $d_goods[$kk]['trans_free'];
-				$val['goods'][$kk] = $d_goods;
-
-				$tp_val = array();
-				$tp_val['id'] = $d_goods['goods_id'];
-				$tp_val['key'] = $d_goods['key'];
-				if ($d_goods['singledel'] == 1) {
-					$tp_val['isselect'] = true;
-					$is_store_ck = true;
-					$ck_goodstype_count++;
-				} else {
-					$tp_val['isselect'] = false;
-				}
-
-				$tp_val['imgurl'] = $d_goods['image'];
-				$tp_val['edit'] = 'inline';
-				$tp_val['title'] = $d_goods['name'];
-				$tp_val['finish'] = 'none';
-				$tp_val['description'] = 'description';
-
-				$option_arr = array();
-				$option_str = "";
-				foreach ($d_goods['option'] as $option_val) {
-					//$option_arr[] = $option_val['name'].':'.$option_val['value'];
-					$option_arr[] = $option_val['value'];
-				}
-				if (!empty($option_arr)) {
-					$option_str = implode(';', $option_arr);
-				}
-
-
-				$tp_val['can_buy'] = D('Home/Pingoods')->get_goods_time_can_buy($d_goods['goods_id']);
-
-				$tp_val['goodstype'] = $option_str;
-				$tp_val['goodstypeedit'] = $option_str;
-				$tp_val['goodsnum'] = $d_goods['quantity'];
-				$tp_val['can_man_jian'] = $d_goods['can_man_jian'];
-				$tp_val['max_quantity'] = $d_goods['max_quantity'];
-				$tp_val['cartype'] = 'inline';
-				$tp_val['currntprice'] = $d_goods['price'];
-				$tp_val['price'] = $d_goods['shop_price'];
-				$tp_val['card_price'] = $d_goods['card_price'];
-				$tp_val['is_take_vipcard'] = $d_goods['is_take_vipcard'];
-				$tp_val['is_new_buy'] = $d_goods['is_new_buy'];
-
-				$tmp_goods[] = $tp_val;
-
-			}
-
-			//$store_info = M('seller')->field('s_id,s_true_name,s_logo')->where( array('s_id' => $store_id) )->find();
-			//$store_info['s_logo'] = C('SITE_URL').'Uploads/image/'.$store_info['s_logo'];
-
-			$store_info = array('s_true_name' => '', 's_id' => 1);
-			$s_logo = D('Home/Front')->get_config_by_name('shoplogo');
-
-			if (!empty($s_logo)) {
-				$s_logo = tomedia($s_logo);
-			}
-
-			$val['store_info'] = $store_info;
-
-			$store_data = array();
-			$store_data['id'] = $store_info['s_id'];
-			if ($is_store_ck) {
-				$store_data['isselect'] = true;
-			} else {
-				$store_data['isselect'] = false;
-			}
-
-			$store_data['shopname'] = $store_info['s_true_name'];
-			$store_data['caredit'] = 'inline';
-			$store_data['finish'] = 'none';
-			$store_data['count'] = '0.00';
-
-			$is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
-			$full_money = D('Home/Front')->get_config_by_name('full_money');
-			$full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
-
-			if (empty($full_reducemoney) || $full_reducemoney <= 0) {
-				$is_open_fullreduction = 0;
-			}
-
-			$store_data['is_open_fullreduction'] = $is_open_fullreduction;
-			$store_data['full_money'] = $full_money;
-			$store_data['full_reducemoney'] = $full_reducemoney;
-
-
-
-			$store_data['goodstype'] = 2;
-			$store_data['goodstypeselect'] = 0;
-			$store_data['shopcarts'] = $tmp_goods;
-
-
-			$seller_goodss[$store_id] = $store_data;
-			$i++;
-		}
-
-		// 商家是否休息
-		$is_comunity_rest = D('Seller/Communityhead')->is_community_rest($community_id);
-		$open_man_orderbuy = D('Home/Front')->get_config_by_name('open_man_orderbuy');
-		$man_orderbuy_money = D('Home/Front')->get_config_by_name('man_orderbuy_money');
-		//if($man_orderbuy_money > $max_can_orderbuy_money){
-		//$max_can_orderbuy_money = $man_orderbuy_money;
-		//}
-		$is_show_guess_like = D('Home/Front')->get_config_by_name('is_show_guess_like');
-
-
-		// 免配送 man_free_tuanzshipping>0开启
-		$delivery_type_ziti = D('Home/Front')->get_config_by_name('delivery_type_ziti');
-		$delivery_type_express = D('Home/Front')->get_config_by_name('delivery_type_express');
-		$delivery_type_tuanz = D('Home/Front')->get_config_by_name('delivery_type_tuanz');
-		$man_free_tuanzshipping = $delivery_tuanz_money = 0;
-
-		//暂时屏蔽,2020.02.13.14:57
-		/**
-			  if($delivery_type_ziti!=1 && $delivery_type_express!=1 && $delivery_type_tuanz==1) {
-				  $man_free_tuanzshipping = D('Home/Front')->get_config_by_name('man_free_tuanzshipping');
-				  if($man_free_tuanzshipping>1 && !empty($man_free_tuanzshipping)) {
-					  $delivery_tuanz_money = D('Home/Front')->get_config_by_name('delivery_tuanz_money');
-				  }
-			  }
-			  **/
-
-
-		if ($delivery_type_tuanz == 1) {
-			$man_free_tuanzshipping = D('Home/Front')->get_config_by_name('man_free_tuanzshipping');
-		} else {
-			$man_free_tuanzshipping = 0;
-		}
-
-		$open_tuan_ship = $delivery_type_tuanz;
-		//团长自定义配送开关
-		if ($community_id && $man_free_tuanzshipping > 1) {
-			$community_modify_shipping = M('lionfish_community_head')->field('is_modify_shipping_method')->where(array('id' => $community_id))->find();
-			$is_modify_shipping_method = $community_modify_shipping['is_modify_shipping_method'];
-			if ($is_modify_shipping_method == 1) {
-				$open_tuan_ship = 1;
-			} else if ($is_modify_shipping_method == 2) {
-				$open_tuan_ship = 0;
-			}
-		}
-
-		$delivery_tuanz_money = D('Home/Front')->get_config_by_name('delivery_tuanz_money');
-
-		$shopcar_tab_all_name = D('Home/Front')->get_config_by_name('shopcar_tab_all_name');
-		$shopcar_tab_express_name = D('Home/Front')->get_config_by_name('shopcar_tab_express_name');
-
-
-		$is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
-		if ($is_open_fullreduction) {
-			$full_list = D('Home/Front')->get_fullreduction();
-		} else {
-			$full_list[0]['full_money'] = 0;
-			$full_list[0]['full_reducemoney'] = 0;
-		}
-
-		//同城配送信息
-		//配送费类型:0、固定金额,1、按距离收取
-		$localtown_delivery_moneytype = D('Home/Front')->get_config_by_name('localtown_delivery_moneytype');
-		$localtown_moneytype_fixed_deliverymoney = 0;
-		$localtown_moneytype_fixed_freemoney = 0;
-		if ($localtown_delivery_moneytype == 0) {
-			//起送价格
-			$localtown_moneytype_fixed_deliverymoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_deliverymoney');
-			//达到金额免配送费
-			$localtown_moneytype_fixed_freemoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_freemoney');
-		}
-
-		$need_data = array();
-		$need_data['code'] = 0;
-		$need_data['carts'] = $seller_goodss;
-		$need_data['mult_carts'] = $seller_goodss_mult;
-		$need_data['is_comunity_rest'] = $is_comunity_rest;
-		$need_data['open_man_orderbuy'] = $open_man_orderbuy;
-		$need_data['man_orderbuy_money'] = $man_orderbuy_money;
-		//$need_data['max_can_orderbuy_money'] = $max_can_orderbuy_money;
-		$need_data['is_show_guess_like'] = $is_show_guess_like;
-		$need_data['man_free_tuanzshipping'] = $man_free_tuanzshipping;
-		$need_data['delivery_tuanz_money'] = $delivery_tuanz_money;
-
-		$need_data['is_member_level_buy'] = $is_member_level_buy; //当前会员折扣 购买,1是,0否
-		$need_data['level_save_money'] = $level_save_money; //会员折扣省的钱
-
-		$need_data['is_vip_card_member'] = $is_vip_card_member; //当前会员是否是 会员卡会员 0 不是,1是,2已过期
-		$need_data['vipcard_save_money'] = $vipcard_save_money; //vip能节约的金额
-		$need_data['is_open_vipcard_buy'] = $is_open_vipcard_buy; //vip能节约的金额
-		$need_data['modify_vipcard_name'] = $modify_vipcard_name;
-
-		$need_data['shopcar_tab_all_name'] = $shopcar_tab_all_name;
-		$need_data['shopcar_tab_express_name'] = $shopcar_tab_express_name;
-		$need_data['open_tuan_ship'] = $open_tuan_ship;
-
-		$need_data['is_open_fullreduction'] = $is_open_fullreduction;
-		$need_data['full_list'] = $full_list;
-
-		//平台和供应商 起送价格和免配送费价格
-		//$need_data['localtown_fixed_list'] = $localtown_fixed_list;
-
-		$need_data['localtown_moneytype_fixed_deliverymoney'] = $localtown_moneytype_fixed_deliverymoney; //起送价格
-		$need_data['localtown_moneytype_fixed_freemoney'] = $localtown_moneytype_fixed_freemoney; //达到金额免配送费
-
-		echo json_encode($need_data);
-		die();
-
-	}
-
-	public function checkout_flushall()
-	{
-		$gpc = I('request.');
-
-		$token = $gpc['token'];
-
-		$community_id = $gpc['community_id'];
-
-		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where(array('token' => $token))->find();
-		$member_id = $weprogram_token['member_id'];
-
-		//dan soitaire
-		$buy_type = isset($gpc['buy_type']) ? $gpc['buy_type'] : 'dan';
-
-		//$car_prefix = 'soitairecart.';
-
-		//buy_type和soli_id吗
-
-		$is_community = D('Seller/Communityhead')->is_community($community_id);
-		if (!$is_community) {
-			$json['code'] = 6;
-			$json['msg'] = '该小区已经不存在!';
-			echo json_encode($json);
-			die();
-		}
-
-
-		$data = array();
-		$data['car_key'] = $gpc['car_key'];
-		$data['all_keys_arr'] = $gpc['all_keys_arr'];
-		$data['cur_car_key'] = $gpc['cur_car_key'];
-		//car_key:cart.6:MTc0:,cart.13:MjcwXzI3Mw==:
-		//all_keys_arr:cart.6:MTc0:_1,cart.13:MjcwXzI3Mw==:_1
-
-		$car_key = explode(',', $data['car_key']);
-		$all_keys_arr = explode(',', $data['all_keys_arr']);
-
-		if (!empty($data['cur_car_key'])) {
-			$car_key = array($data['cur_car_key']);
-		}
-
-		$save_keys = array();
-		if (!empty($all_keys_arr)) {
-			foreach ($all_keys_arr as $val) {
-				$tmp_val = explode('_', $val);
-				$save_keys[$tmp_val[0]] = $tmp_val[1];
-			}
-		}
-
-
-
-		if ($buy_type == 'dan') {
-			$all_cart = M('lionfish_comshop_car')->where("community_id={$community_id} and token='{$token}' and carkey like 'cart.%'")->select();
-
-		} else if ($buy_type == 'soitaire') {
-			$all_cart = M('lionfish_comshop_car')->where("community_id={$community_id} and token='{$token}' and carkey like 'soitairecart.%'")->select();
-		}
-
-		if (!empty($all_cart)) {
-			foreach ($all_cart as $val) {
-				$tmp_format_data = unserialize($val['format_data']);
-				$tmp_format_data['singledel'] = 0;
-
-
-				$tmp_format_data['quantity'] = isset($save_keys[$val['carkey']]) ? $save_keys[$val['carkey']] : $tmp_format_data['quantity'];
-
-
-				M('lionfish_comshop_car')->where(array('id' => $val['id'], 'community_id' => $community_id))->save(array('format_data' => serialize($tmp_format_data)));
-			}
-		}
-
-		if (!empty($car_key)) {
-			foreach ($car_key as $key) {
-
-				$car_info = M('lionfish_comshop_car')->where(array('community_id' => $community_id, 'carkey' => $key, 'token' => $token))->find();
-				if (!empty($car_info)) {
-					$tmp_format_data = unserialize($car_info['format_data']);
-					$tmp_format_data['singledel'] = 1;
-					$quantity = $tmp_format_data['quantity'];
-					$sku_quantity_one = $tmp_format_data['quantity'];
-					$goods_id = $tmp_format_data['goods_id'];
-					$sku_str = $tmp_format_data['sku_str'];
-					//同一个商品不同规格 总数量合计
-					$sku_quantity = $this->_check_goods_sku_quantity($community_id, $key, $token);
-					if ($sku_quantity > $quantity) {
-						$quantity = $sku_quantity;
-					}
-					$goods_description = D('Home/Front')->get_goods_common_field($goods_id, 'goods_start_count');
-					//起售数量判断
-					if ($sku_quantity_one < $goods_description['goods_start_count']) {
-
-						$json['code'] = 6;
-						$json['msg'] = $goods_description['goods_start_count'] . '份起售';
-						$json['max_quantity'] = $goods_description['goods_start_count'];
-						echo json_encode($json);
-						die();
-					}
-					$check_json = $this->_check_can_buy($member_id, $goods_id, $quantity);
-
-
-
-					if ($check_json['code'] != 0) {
-						$tmp_format_data['quantity'] = $check_json['count'];
-
-
-						M('lionfish_comshop_car')->where(array('id' => $car_info['id'], 'community_id' => $community_id))->save(array('format_data' => serialize($tmp_format_data)));
-						echo json_encode(array('code' => 6, 'msg' => $check_json['msg']));
-						die();
-					}
-
-					//check sku is ok 
-
-					$check_json = $this->_check_goods_sku_canbuy($goods_id, $sku_str);
-
-					if ($check_json['code'] != 0) {
-						echo json_encode(array('code' => 6, 'msg' => $check_json['msg']));
-						die();
-					}
-
-
-					$check_json = $this->_check_goods_quantity($goods_id, $sku_quantity_one, $sku_str);
-
-					if ($check_json['code'] != 0) {
-						echo json_encode(array('code' => 6, 'msg' => $check_json['msg']));
-						die();
-					}
-
-					M('lionfish_comshop_car')->where(array('id' => $car_info['id'], 'community_id' => $community_id))->save(array('format_data' => serialize($tmp_format_data)));
-				}
-			}
-		}
-		$is_limit_distance_buy = D('Home/Front')->get_config_by_name('shop_limit_buy_distance');
-
-		echo json_encode(array('code' => 0, 'data' => $is_limit_distance_buy));
-		die();
-	}
-
-	public function _check_goods_sku_quantity($community_id, $key, $token)
-	{
-		$quantity = 0;
-		$key_array = explode(":", $key);
-		$key_result = "";
-		foreach ($key_array as $k => $v) {
-			if ($k < 2) {
-				if (empty($key_result)) {
-					$key_result = $v;
-				} else {
-					$key_result = $key_result . ":" . $v;
-				}
-			}
-		}
-		$sql = "SELECT format_data FROM " . C('DB_PREFIX') . "lionfish_comshop_car "
-			. " WHERE carkey LIKE  '" . $key_result . "%' and community_id = '" . $community_id . "' "
-			. " and token='" . $token . "'";
-		$cart_goods_list = M()->query($sql);
-
-		if (!empty($cart_goods_list)) {
-			foreach ($cart_goods_list as $val) {
-				$tmp_format_data = unserialize($val['format_data']);
-				$quantity = $quantity + $tmp_format_data['quantity'];
-			}
-		}
-		return $quantity;
-	}
-
-	public function _check_goods_sku_canbuy($goods_id, $sku_str)
-	{
-
-		$json = array('code' => 0);
-
-		$goods_info = M('lionfish_comshop_goods')->field('goodsname as name')->where(array('id' => $goods_id))->find();
-
-		if (!empty($sku_str)) {
-			$goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->field('stock as quantity')->where(array('option_item_ids' => $sku_str, 'goods_id' => $goods_id))->find();
-
-			if (empty($goods_option_mult_value)) {
-				$json['code'] = 3;
-				$json['msg'] = mb_substr($goods_info['name'], 0, 4, 'utf-8') . ',规格已失效,删除后再结算';
-			}
-		}
-
-		return $json;
-	}
-
-
-	public function del_car_goods()
-	{
-		$gpc = I('request.');
-
-
-		$token = $gpc['token'];
-		$community_id = $gpc['community_id'];
-
-		$carkey = $gpc['carkey'];
-
-
-		M('lionfish_comshop_car')->where("community_id={$community_id} and token='{$token}' and carkey='{$carkey}'")->delete();
-
-		echo json_encode(array('code' => 0));
-		die();
-
-	}
-
-	public function _check_goods_quantity($goods_id, $quantity, $sku_str)
-	{
-		$gpc = I('request.');
-
-
-		$goods_info = M('lionfish_comshop_goods')->field('goodsname as name')->where(array('id' => $goods_id))->find();
-
-		$goods_quantity = D('Home/Car')->get_goods_quantity($goods_id);
-
-
-
-		$json = array('code' => 0);
-
-		if ($goods_quantity < $quantity) {
-			$json['code'] = 3;
-			$json['msg'] = mb_substr($goods_info['name'], 0, 4, 'utf-8') . '...,商品数量不足,剩余' . $goods_quantity . '个!!';
-
-		} else if (!empty($sku_str)) {
-			$mul_opt_arr = array();
-
-			$goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->field('stock as quantity')->where(array('option_item_ids' => $sku_str, 'goods_id' => $goods_id))->find();
-
-			if (!empty($goods_option_mult_value)) {
-				if ($goods_option_mult_value['quantity'] < $quantity) {
-					$json['code'] = 3;
-					$json['msg'] = mb_substr($goods_info['name'], 0, 4, 'utf-8') . '...,商品数量不足,剩余' . $goods_option_mult_value['quantity'] . '个!!';
-				}
-			}
-		}
-		return $json;
-	}
-
-	private function _check_can_buy($member_id, $goods_id, $quantity)
-	{
-		$gpc = I('request.');
-
-		//$can_buy_count =  D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
-
-		$goods_description = D('Home/Front')->get_goods_common_field($goods_id, 'total_limit_count,one_limit_count,oneday_limit_count,is_new_buy,is_limit_levelunbuy,is_limit_vipmember_buy,goods_start_count');
-
-		//单次限购判断
-		if ($goods_description['one_limit_count'] > 0 && $quantity > $goods_description['one_limit_count']) {
-			$json['code'] = 6;
-			$json['msg'] = '您本次只能购买' . $goods_description['one_limit_count'] . '份';
-			$json['count'] = $goods_description['one_limit_count'];
-			return $json;
-		}
-
-		$can_buy_day_count = D('Home/Front')->check_goods_user_canbuy_day_count($member_id, $goods_id);
-		if ($can_buy_day_count == -1 || ($can_buy_day_count > 0 && $quantity > $can_buy_day_count)) {
-			$json['code'] = 6;
-			$json['msg'] = '您今天只能购买' . $goods_description['oneday_limit_count'] . '份';
-			$json['count'] = 1;
-			return $json;
-		} else if ($can_buy_day_count > 0 && $quantity > $can_buy_day_count) {
-			$json['code'] = 6;
-			$json['msg'] = '您今天还能购买' . $can_buy_day_count . '份';
-			$json['count'] = $can_buy_day_count;
-			return $json;
-		}
-
-		$can_buy_all_count = D('Home/Front')->check_goods_user_canbuy_all_count($member_id, $goods_id);
-		//历史限购判断
-		if ($can_buy_all_count == -1 && $goods_description['total_limit_count'] > 0) {
-			$json['code'] = 6;
-			$json['msg'] = '您最多只能购买' . $goods_description['total_limit_count'] . '个';
-			$json['count'] = 1;
-			return $json;
-		} else if ($can_buy_all_count > 0 && $quantity > $can_buy_all_count) {
-			$json['code'] = 6;
-			$json['msg'] = '您还能购买' . $can_buy_all_count . '份';
-			$json['count'] = $can_buy_all_count;
-			return $json;
-		}
-
-		$goods_info = M('lionfish_comshop_goods')->where(array('id' => $goods_id))->find();
-
-		$goods_description = D('Home/Front')->get_goods_common_field($goods_id, 'per_number');
-
-		$can_buy_count = D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
-		$json = array();
-		if ($can_buy_count == -1 || $can_buy_day_count == -1) {
-			$json['code'] = 6;
-			$json['msg'] = mb_substr($goods_info['name'], 0, 4, 'utf-8') . '...,您本次只能购买' . $goods_description['per_number'] . '个';
-		} else if ($can_buy_count > 0 && $quantity > $can_buy_count) {
-			$json['code'] = 6;
-			//$json['msg']=mb_substr($goods_info['name'],0,4,'utf-8').'...,您还能购买'.$can_buy_count.'份';
-			$json['msg'] = '本次最多购买' . $can_buy_count . '份';
-			$json['count'] = $can_buy_count;
-
-		} else {
-			$json['code'] = 0;
-		}
-		return $json;
-	}
-
-	private function _add_address($token, $userName, $telNumber, $provinceName, $cityName, $countyName, $detailInfo, $latitude = '', $longitude = '', $lou_meng_hao = '')
-	{
-		$_GPC = I('request.');
-
-		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where(array('token' => $token))->find();
-		$member_id = $weprogram_token['member_id'];
-
-
-		//  lionfish_comshop_area
-
-		$province_info = M('lionfish_comshop_area')->where("name like '%{$provinceName}%' ")->find();
-
-		if (!empty($province_info)) {
-			$province_id = $province_info['id'];
-		} else {
-
-
-			$area_data = array();
-			$area_data['name'] = $provinceName;
-			$area_data['pid'] = 0;
-			$area_data['code'] = $max_dp['code'] + 1;
-
-			$province_id = M('lionfish_comshop_area')->add($area_data);
-
-			$up_data = array();
-			$up_data['code'] = $province_id;
-
-			M('lionfish_comshop_area')->where(array('id' => $province_id))->save($up_data);
-
-		}
-
-		$guding_arr = ['鞍山市'];
-
-		if (in_array($cityName, $guding_arr)) {
-			$city_info = M('lionfish_comshop_area')->where("name = '{$cityName}'")->find();
-		} else {
-			$city_info = M('lionfish_comshop_area')->where("name like '%{$cityName}%'")->find();
-		}
-
-		//$city_info = M('lionfish_comshop_area')->where("name like '%{$cityName}%'")->find();
-
-		if (!empty($city_info)) {
-			$city_id = $city_info['id'];
-		} else {
-
-			$max_dp = M('lionfish_comshop_area')->order('code desc')->find();
-
-			$area_data = array();
-			$area_data['name'] = $cityName;
-			$area_data['pid'] = $province_id;
-			$area_data['code'] = $max_dp['code'] + 1;
-
-			$city_id = M('lionfish_comshop_area')->add($area_data);
-
-			$up_data = array();
-			$up_data['code'] = $city_id;
-
-			M('lionfish_comshop_area')->where(array('id' => $city_id))->save($up_data);
-
-		}
-
-		//city_name: 东莞市
-		if (empty($countyName)) {
-			if ($cityName == '东莞市') {
-				$countyName = '东莞';
-			}
-			if ($cityName == '中山市') {
-				$countyName = '中山';
-				//453
-			}
-		}
-
-		$country_info = M('lionfish_comshop_area')->where("name like '%{$countyName}%' ")->find();
-
-		if ($countyName == '中山') {
-
-			$country_info = M('lionfish_comshop_area')->where(array('id' => 453))->find();
-			//
-		}
-
-
-		if (!empty($country_info)) {
-			$country_id = $country_info['id'];
-		} else {
-
-			$max_dp = M('lionfish_comshop_area')->order('code desc')->find();
-
-			$area_data = array();
-			$area_data['name'] = $countyName;
-			$area_data['pid'] = $city_id;
-			$area_data['code'] = $max_dp['code'] + 1;
-
-			$country_id = M('lionfish_comshop_area')->add($area_data);
-
-			$up_data = array();
-			$up_data['code'] = $country_id;
-
-			M('lionfish_comshop_area')->where(array('id' => $country_id))->save($up_data);
-
-		}
-
-
-		$address_param = array();
-
-		$address_param['member_id'] = $member_id;
-		$address_param['province_id'] = $province_id;
-		$address_param['country_id'] = $country_id;
-		$address_param['city_id'] = $city_id;
-		$address_param['address'] = $detailInfo;
-		$address_param['name'] = $userName;
-		$address_param['telephone'] = $telNumber;
-
-		$address_param['lon_lat'] = '';
-		$address_param['lou_meng_hao'] = $lou_meng_hao;
-
-		if (!empty($latitude)) {
-			$address_param['lon_lat'] = $longitude . ',' . $latitude;
-		}
-
-
-
-		$has_addre = M('lionfish_comshop_address')->where($address_param)->find();
-
-		if (empty($has_addre)) {
-
-			$has_default_address = M('lionfish_comshop_address')->where(array('is_default' => 1, 'member_id' => $member_id))->find();
-
-
-			$address_data = array();
-			$address_data['member_id'] = $member_id;
-			$address_data['name'] = $userName;
-			$address_data['telephone'] = $telNumber;
-			$address_data['lou_meng_hao'] = $lou_meng_hao;
-			if (!empty($latitude)) {
-				$address_data['lon_lat'] = $longitude . ',' . $latitude;
-			} else {
-				$address_data['lon_lat'] = '';
-			}
-
-			$address_data['address'] = $detailInfo;
-			$address_data['address_name'] = empty($data['address_name']) ? 'HOME' : $data['address_name'];
-			if (!empty($has_default_address) && false) {
-				$address_data['is_default'] = 0;
-			} else {
-				$data = array();
-				$data['is_default'] = 0;
-
-				M('lionfish_comshop_address')->where(array('member_id' => $member_id))->save($data);
-
-				$address_data['is_default'] = 1;
-			}
-
-			$address_data['city_id'] = $city_id;
-			$address_data['country_id'] = $country_id;
-			$address_data['province_id'] = $province_id;
-
-			$res = M('lionfish_comshop_address')->add($address_data);
-		} else {
-			$res = $has_addre['address_id'];
-		}
-
-		return $res;
-	}
-
-	public function checkout()
-	{
-		$gpc = I('request.');
-
-
-		$buy_type = isset($gpc['buy_type']) ? $gpc['buy_type'] : 'dan';
-
-		$pintuan_model_buy = D('Home/Front')->get_config_by_name('pintuan_model_buy');
-
-		if (empty($pintuan_model_buy) || $pintuan_model_buy == 0) {
-			$pintuan_model_buy = 0;
-		}
-
-
-		$mb_city_name = isset($gpc['mb_city_name']) ? $gpc['mb_city_name'] : '';
-
-		if ($buy_type == 'undefined') {
-			$buy_type = 'dan';
-		}
-
-		$community_id = $gpc['community_id'];
-		$token = $gpc['token'];
-
-		$voucher_id = isset($gpc['voucher_id']) ? $gpc['voucher_id'] : 0;
-
-		$soli_id = isset($gpc['soli_id']) ? intval($gpc['soli_id']) : '';
-
-		$use_quan_str = isset($gpc['use_quan_str']) ? $gpc['use_quan_str'] : '';
-		$use_quan_arr = array();
-
-		if ($use_quan_str != '') {
-			$use_quan_arr_tmp = explode('@', $use_quan_str);
-			foreach ($use_quan_arr_tmp as $val) {
-				$tmp_arr = explode('_', $val);
-				$use_quan_arr[$tmp_arr[0]] = $tmp_arr[1];
-			}
-		}
-
-		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where(array('token' => $token))->find();
-		$member_id = $weprogram_token['member_id'];
-
-
-		$is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
-		$is_open_vipcard_buy = !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 ? 1 : 0;
-
-		$is_vip_card_member = 0;
-		$is_member_level_buy = 0;
-
-		if ($member_id > 0) {
-			$member_info = M('lionfish_comshop_member')->where(array('member_id' => $member_id))->find();
-
-			if (!empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1) {
-
-				$now_time = time();
-
-				if ($member_info['card_id'] > 0 && $member_info['card_end_time'] > $now_time) {
-					$is_vip_card_member = 1; //还是会员
-				} else if ($member_info['card_id'] > 0 && $member_info['card_end_time'] < $now_time) {
-					$is_vip_card_member = 2; //已过期
-				}
-			}
-
-			if ($is_vip_card_member != 1 && $member_info['level_id'] > 0) {
-				$is_member_level_buy = 1;
-			}
-		}
-		//预售不开启会员卡
-		if ($buy_type == 'pesale') {
-			$is_member_level_buy = 0;
-			$is_vip_card_member = 0;
-		}
-
-
-		if (empty($member_id)) {
-			//需要登录
-			echo json_encode(array('code' => 5));
-			die();
-		}
-
-		$cart = D('Home/Car');
-
-
-
-		if ((!$cart->has_goodswecar($buy_type, $token, $community_id))) {
-			//购物车中没有商品
-			echo json_encode(array('code' => 4));
-			die();
-		}
-
-
-		$member_info = M('lionfish_comshop_member')->where(array('member_id' => $member_id))->find();
-
-		//soitaire
-		$goods = $cart->get_all_goodswecar($buy_type, $token, 1, $community_id, $soli_id);
-
-
-		$address = M('lionfish_comshop_address')->where(array('member_id' => $member_id))->order('is_default desc,address_id desc')->find();
-
-		$add_old_order = M('lionfish_comshop_order')->field('address_id')->where(" (delivery ='localtown_delivery' or delivery = 'express') and member_id = {$member_id} ")->order('order_id desc')->find();
-
-		if (!empty($add_old_order) && $add_old_order['address_id'] > 0) {
-			$address = M('lionfish_comshop_address')->where(array('address_id' => $add_old_order['address_id'], 'member_id' => $member_id))->find();
-		}
-
-		$mb_city_id = 0;
-		if (!empty($mb_city_name)) {
-			$mb_city_info = M('lionfish_comshop_area')->where(" name='{$mb_city_name}' ")->find();
-
-			if (!empty($mb_city_info)) {
-				$mb_city_id = $mb_city_info['id'];
-			}
-
-		}
-
-		if ($address) {
-
-			//get_area_info($id)
-			$province_info = D('Home/Front')->get_area_info($address['province_id']); // M('area')->field('area_name')->where( array('area_id' => $address['province_id']) )->find();
-			$city_info = D('Home/Front')->get_area_info($address['city_id']); //M('area')->field('area_name')->where( array('area_id' => $address['city_id']) )->find();
-			$country_info = D('Home/Front')->get_area_info($address['country_id']); //M('area')->field('area_name')->where( array('area_id' => $address['country_id']) )->find();
-
-			$address['province_name'] = $province_info['name'];
-			$address['city_name'] = $city_info['name'];
-			$address['country_name'] = $country_info['name'];
-		} else {
-			$address = array();
-		}
-
-		$seller_goodss = array();
-		$show_voucher = 0;
-
-		//判断是否仅快递的配送方式  is_only_express
-
-		$is_open_only_express = D('Home/Front')->get_config_by_name('is_open_only_express');
-
-		$is_only_express = 0;
-
-		if (!empty($is_open_only_express) && $is_open_only_express == 1) {
-			$is_only_express = 1;
-		}
-		/**
-		   if($is_vip_card_member != 1 && $member_info['level_id'] >0 )
-		   {
-			   $is_member_level_buy = 1;
-		   }
-		   **/
-		foreach ($goods as $key => $val) {
-			//$goods_store_field =  M('goods')->field('store_id')->where( array('goods_id' => $val['goods_id']) )->find();
-			if ($is_only_express == 1 && $val['is_only_express'] != 1) {
-				$is_only_express = 0;
-			}
-			if ($is_only_express == 0 && $val['is_only_express'] == 3) {
-				$is_only_express = 3;
-			}
-			if ($is_only_express == 0 && $val['is_only_express'] == 2) {
-				$is_only_express = 2;
-			}
-
-			$supply_id = D('Home/Front')->get_goods_supply_id($val['goods_id']);
-			if ($supply_id > 0) {
-				$supply_info = D('Home/Front')->get_supply_info($supply_id);
-
-				if ($supply_info['type'] == 0) {
-					$supply_id = 0;
-				}
-			}
-			$val['name'] = htmlspecialchars_decode($val['name']);
-			$seller_goodss[$supply_id]['goods'][$key] = $val;
-		}
-
-		//begin 如果是同城配送 ,查一查有没有新提交的地址,如果有,按照新的来处理
-
-		$localtown_address = array();
-
-		if ($is_only_express == 3) {
-			$localtown_old_order = M('lionfish_comshop_order')->field('address_id')->where(array('delivery' => 'localtown_delivery', 'member_id' => $member_id))->order('order_id desc')->find();
-
-			$localtown_id = 0;
-
-
-			if (!empty($localtown_old_order) && $localtown_old_order['address_id'] > 0) {
-				$localtown_address = M('lionfish_comshop_address')->where(array('address_id' => $localtown_old_order['address_id'], 'member_id' => $member_id))->find();
-
-				if (!empty($localtown_address)) {
-					$province_info = D('Home/Front')->get_area_info($address['province_id']); // M('area')->field('area_name')->where( array('area_id' => $address['province_id']) )->find();
-					$city_info = D('Home/Front')->get_area_info($address['city_id']); //M('area')->field('area_name')->where( array('area_id' => $address['city_id']) )->find();
-					$country_info = D('Home/Front')->get_area_info($address['country_id']); //M('area')->field('area_name')->where( array('area_id' => $address['country_id']) )->find();
-
-					$localtown_address['province_name'] = $province_info['name'];
-					$localtown_address['city_name'] = $city_info['name'];
-					$localtown_address['country_name'] = $country_info['name'];
-
-				} else if (isset($gpc['longitude']) && isset($gpc['latitude'])) {
-					$localtown_address['lon_lat'] = $gpc['longitude'] . ',' . $gpc['latitude'];
-				}
-			} else {
-				$address = array();
-			}
-
-		}
-		//end同城配送
-
-		$quan_model = D('Home/Voucher');
-		$pin_model = D('Home/Pin');
-
-
-		$voucher_price = 0;
-		$reduce_money = 0;
-		$cha_reduce_money = 0;
-
-		$is_pin_over = 0;
-		$is_moban = false;
-
-
-
-		$is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
-		$full_money = D('Home/Front')->get_config_by_name('full_money');
-		$full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
-
-		if (empty($full_reducemoney) || $full_reducemoney <= 0) {
-			$is_open_fullreduction = 0;
-		}
-
-		$show_voucher = 0;
-
-		$voucher_can_use = 1; //目前都是平台券,
-		$man_total_free = 0;
-		$store_buy_total_money = 0;
-
-		$pin_id = 0;
-		$presale_goods_id = 0; //预售商品id
-		$presale_goods_total = 0; //预售商品价格
-
-		$is_zero_buy = 0;
-		$vipcard_save_money = 0;
-		$level_save_money = 0;
-
-		$today_time = time();
-		$arr = array('天', '一', '二', '三', '四', '五', '六');
-		//计算优惠券
-		foreach ($seller_goodss as $store_id => $val) {
-
-			$seller_voucher_list = array();
-			$seller_total_fee = 0;
-			$total_trans_free = 0;
-			$is_no_quan = false;
-
-
-			$total_weight = 0;
-			$total_quantity = 0;
-			$vch_goods_ids = array();
-
-
-			foreach ($val['goods'] as $kk => $d_goods) {
-				//预售不参与会员卡
-				if ($d_goods['is_take_vipcard'] == 1) {
-					$vipcard_save_money += $d_goods['total'] - $d_goods['card_total'];
-				} else if ($d_goods['is_mb_level_buy'] == 1 && $d_goods['is_mb_level_buy'] == 1 && $is_member_level_buy == 1) {
-					$level_save_money += $d_goods['total'] - $d_goods['level_total'];
-				}
-
-				if ($is_vip_card_member == 1 && $d_goods['is_take_vipcard'] == 1) {
-					$seller_total_fee += $d_goods['card_total'];
-					if ($store_id == 0) {
-						$store_buy_total_money += $d_goods['card_total'];
-					}
-					if ($d_goods['can_man_jian'] == 1) {
-						$man_total_free += $d_goods['card_total'];
-
-					}
-				} else if ($d_goods['is_mb_level_buy'] == 1 && $member_info['level_id'] > 0) {
-					$seller_total_fee += $d_goods['level_total'];
-					if ($store_id == 0) {
-						$store_buy_total_money += $d_goods['level_total'];
-					}
-					if ($d_goods['can_man_jian'] == 1) {
-						$man_total_free += $d_goods['level_total'];
-					}
-				} else {
-					$seller_total_fee += $d_goods['total'];
-					if ($store_id == 0) {
-						$store_buy_total_money += $d_goods['total'];
-					}
-					if ($d_goods['can_man_jian'] == 1) {
-						$man_total_free += $d_goods['total'];
-
-					}
-
-				}
-
-
-				if ($buy_type == 'pintuan' && $d_goods['pin_id'] > 0) {
-					$is_pin_over = $pin_model->getNowPinState($d_goods['pin_id']);
-					if ($is_pin_over == 2) {
-						$is_zero_buy = $pin_model->check_goods_iszero_opentuan($d_goods['goods_id']);
-					}
-				} else if ($buy_type == 'pintuan' && $d_goods['pin_id'] == 0) {
-					$is_zero_buy = $pin_model->check_goods_iszero_opentuan($d_goods['goods_id']);
-				}
-
-				if ($buy_type == 'presale') {
-					$presale_goods_id = $d_goods['goods_id'];
-					$presale_goods_total = $seller_total_fee;
-				}
-				$tp_goods_info = M('lionfish_comshop_goods')->field('type')->where(array('id' => $d_goods['goods_id']))->find();
-
-				$vch_goods_ids[$d_goods['goods_id']] = $vch_goods_ids[$d_goods['goods_id']] + $d_goods['total'];
-				//$is_no_quan = true;
-				//预售不开启优惠券 
-				if ($tp_goods_info['type'] == 'integral' || $tp_goods_info['type'] == 'presale') {
-					$is_no_quan = true;
-				}
-
-				if ($d_goods['shipping'] == 0) {
-					$is_moban = true;
-					$val['is_moban'] = true;
-					$total_weight += $d_goods['weight'] * $d_goods['quantity'];
-					$total_quantity += $d_goods['quantity'];
-				}
-
-				$d_goods[$kk]['trans_free'] = 0;
-				/**
-						 if($d_goods['shipping']==1)
-						 {
-							 //统一运费
-							 $d_goods[$kk]['trans_free'] = $d_goods['goods_freight'];
-						 }else {
-							 //运费模板
-							  if(!empty($address))
-							 {
-								 $trans_free = load_model_class('transport')->calc_transport($d_goods['transport_id'], $d_goods['quantity'],$d_goods['quantity']*$d_goods['weight'], $address['city_id'] );
-							 }else{
-								 $trans_free = 0;
-							 }
-							$d_goods[$kk]['trans_free'] = $trans_free;
-						 }
-						 **/
-
-				$total_trans_free += $d_goods[$kk]['trans_free'];
-				//自提时间
-				$goods_info = M('lionfish_comshop_good_common')->field('pick_up_type,pick_up_modify')->where(array('goods_id' => $d_goods['goods_id']))->find();
-				$pick_up_type = -1;
-				if ($pick_up_type == -1 || $goods_info['pick_up_type'] > $pick_up_type) {
-					$pick_up_type = $goods_info['pick_up_type'];
-
-					if ($pick_up_type == 0) {
-						$pick_up_time = date('m-d', $today_time);
-						$pick_up_weekday = '周' . $arr[date('w', $today_time)];
-					} else if ($pick_up_type == 1) {
-						$pick_up_time = date('m-d', $today_time + 86400);
-						$pick_up_weekday = '周' . $arr[date('w', $today_time + 86400)];
-					} else if ($pick_up_type == 2) {
-						$pick_up_time = date('m-d', $today_time + 86400 * 2);
-						$pick_up_weekday = '周' . $arr[date('w', $today_time + 86400 * 2)];
-					} else if ($pick_up_type == 3) {
-						$pick_up_time = $goods_info['pick_up_modify'];
-					}
-				}
-				$d_goods['pick_up_type'] = $pick_up_type;
-				$d_goods['pick_up_time'] = $pick_up_time;
-				$d_goods['pick_up_weekday'] = $pick_up_weekday;
-
-				$val['goods'][$kk] = $d_goods;
-
-			}
-
-			$val['reduce_money'] = 0;
-
-			//pindan (拼团商品单独购买)   pintuan (拼团)
-			//预售关闭满减 
-			if ($buy_type == 'pindan' || $buy_type == 'pintuan' || $buy_type == 'integral' || $buy_type == 'presale') {
-				$is_open_fullreduction = 0;
-			}
-
-			//原来满级计算man_total_free
-			/*if($is_open_fullreduction == 1 && $man_total_free >= $full_money )
-				   {
-				   $val['reduce_money'] = $full_reducemoney;
-				   $reduce_money = $full_reducemoney;
-				   }else if($is_open_fullreduction == 1 && $man_total_free < $full_money)
-				   {
-				   $cha_reduce_money = $full_money - $man_total_free;
-				   }*/
-			/**
-			 * 新满减计算
-			 */
-
-			if ($is_open_fullreduction == 1) {
-				$reduce_result = D('Home/Front')->get_reduce_money($man_total_free);
-
-				$val['reduce_money'] = $reduce_result['reduce_money'];
-				$reduce_money = $reduce_result['reduce_money'];
-				$cha_reduce_money = $reduce_result['cha_reduce_money'];
-			}
-
-			$chose_vouche = array();
-
-			if (!$is_no_quan) {
-
-				$vouche_list = $quan_model->get_user_canpay_voucher($member_id, $store_id, $seller_total_fee, '', $vch_goods_ids);
-
-				$vouche_list = $quan_model->get_voucher_amout_bygoods($vouche_list, $val['goods'], $reduce_money);
-				//var_dump(  $vouche_list );
-				//die();
-
-				if (!empty($vouche_list) && empty($use_quan_arr)) {
-					$ling_vouche_list = $vouche_list;
-					if ($voucher_can_use == 1) {
-						$voucher_can_use++;
-
-						$show_voucher = 1;
-						reset($ling_vouche_list);
-						$chose_vouche = current($ling_vouche_list);
-						//$voucher_price += $chose_vouche['credit'];
-						$voucher_price += $chose_vouche['can_vouche_amount'];
-
-						//$seller_total_fee = round( $seller_total_fee - $chose_vouche['credit'], 2);
-						$seller_total_fee = round($seller_total_fee - $chose_vouche['can_vouche_amount'], 2);
-					}
-
-				} else if (!empty($vouche_list) && !empty($use_quan_arr)) {
-
-					foreach ($vouche_list as $tmp_voucher) {
-						if ($tmp_voucher['id'] == $use_quan_arr[$store_id]) {
-							$show_voucher = 1;
-							$chose_vouche = $tmp_voucher;
-							//$seller_total_fee = round( $seller_total_fee - $chose_vouche['credit'], 2);
-							//$voucher_price += $chose_vouche['credit'];
-							$seller_total_fee = round($seller_total_fee - $chose_vouche['can_vouche_amount'], 2);
-							$voucher_price += $chose_vouche['can_vouche_amount'];
-
-							break;
-						}
-					}
-				}
-
-			}
-
-
-
-			$val['chose_vouche'] = $chose_vouche;
-			$val['show_voucher'] = $show_voucher;
-
-			$val['voucher_list'] = $vouche_list;
-			$val['total'] = $seller_total_fee;
-
-			if ($val['total'] < 0) {
-				$val['total'] = 0;
-			}
-
-			$val['trans_free'] = $total_trans_free;
-
-			$val['total_weight'] = $total_weight;
-			$val['total_quantity'] = $total_quantity;
-
-			$s_logo = D('Home/Front')->get_config_by_name('shoplogo');
-			$shoname = D('Home/Front')->get_config_by_name('shoname');
-			if (!empty($s_logo)) {
-				$s_logo = tomedia($s_logo);
-			}
-
-			$store_info = array('s_id' => $store_id, 's_true_name' => $shoname, 's_logo' => $s_logo);
-
-			if (!empty($store_id) && $store_id > 0) {
-				$supply_info = D('Home/Front')->get_supply_info($store_id);
-				//logo
-				if (!empty($supply_info)) {
-					$store_info['s_true_name'] = $supply_info['shopname'];
-					$store_info['s_logo'] = tomedia($supply_info['logo']);
-				}
-			}
-
-			$val['store_info'] = $store_info;
-
-			$seller_goodss[$store_id] = $val;
-		}
-
-		$trans_free_toal = 0; //运费
-
-		//delivery_type_ziti  delivery_type_express    delivery_type_tuanz  delivery_tuanz_money
-
-		$delivery_type_ziti = D('Home/Front')->get_config_by_name('delivery_type_ziti');
-		$delivery_type_express = D('Home/Front')->get_config_by_name('delivery_type_express');
-		$delivery_type_tuanz = D('Home/Front')->get_config_by_name('delivery_type_tuanz');
-		$delivery_tuanz_money = D('Home/Front')->get_config_by_name('delivery_tuanz_money');
-		//---
-		$man_free_tuanzshipping = D('Home/Front')->get_config_by_name('man_free_tuanzshipping');
-		$man_free_shipping = D('Home/Front')->get_config_by_name('man_free_shipping');
-
-		$delivery_express_name = D('Home/Front')->get_config_by_name('delivery_express_name');
-
-
-		if (empty($man_free_tuanzshipping) || $buy_type == 'integral') {
-			$man_free_tuanzshipping = 0;
-		}
-		//关闭团长配送费 免  预售 
-		if (empty($man_free_tuanzshipping) || $buy_type == 'presale') {
-			$man_free_tuanzshipping = 0;
-		}
-		if (empty($man_free_shipping) || $buy_type == 'integral') {
-			$man_free_shipping = 0;
-		}
-		//关闭快递配送费 免  预售 
-		if (empty($man_free_shipping) || $buy_type == 'presale') {
-			$man_free_shipping = 0;
-		}
-
-
-		//if( $buy_type == 'dan' )
-		if ($buy_type == 'dan' || $buy_type == 'soitaire' || ($pintuan_model_buy == 1 && $buy_type != 'dan' && $buy_type != 'integral')) {
-			//...判断团长是否开启自定义的情况 store_buy_total_money
-			$community_info_modify = M('lionfish_community_head')->field('is_modify_shipping_method,is_modify_shipping_fare,shipping_fare')->where(array('id' => $community_id))->find();
-
-
-			if (!empty($community_info_modify['is_modify_shipping_method']) && $community_info_modify['is_modify_shipping_method'] == 1 && $delivery_type_tuanz == 1) {
-				//开启配送
-				$delivery_type_tuanz = 1;
-
-				if (!empty($community_info_modify['is_modify_shipping_fare']) && $community_info_modify['is_modify_shipping_fare'] == 1 && $community_info_modify['shipping_fare'] > 0) {
-					$delivery_tuanz_money = $community_info_modify['shipping_fare'];
-				}
-
-
-			} else if (!empty($community_info_modify['is_modify_shipping_method']) && $community_info_modify['is_modify_shipping_method'] == 2) {
-				//关闭配送
-				$delivery_type_tuanz = 0;
-			}
-		} else if ($buy_type == 'pindan' || $buy_type == 'pintuan') {
-			if ($pintuan_model_buy == 0) {
-				$delivery_type_tuanz = 0;
-				$delivery_type_express = 1;
-				$delivery_type_ziti = 2;
-			}
-		} else if ($buy_type == 'integral') {
-			$delivery_type_tuanz = 0;
-			$delivery_type_express = 1;
-			$delivery_type_ziti = 2;
-		}
-
-		foreach ($val['goods'] as $kk => $d_goods) {
-			if ($d_goods['is_only_express'] == 1) {
-				$delivery_type_express = 1;
-			}
-		}
-
-		$is_man_delivery_tuanz_fare = 0; //是否达到满xx减团长配送费
-		$fare_man_delivery_tuanz_fare_money = 0; //达到满xx减团长配送费, 减了多少钱
-
-		if (($buy_type == 'dan' || $buy_type == 'soitaire') && !empty($man_free_tuanzshipping) && $man_free_tuanzshipping > 0 && $man_free_tuanzshipping <= $store_buy_total_money) {
-			//$delivery_tuanz_money = 0;
-			$is_man_delivery_tuanz_fare = 1;
-			$fare_man_delivery_tuanz_fare_money = $delivery_tuanz_money;
-		}
-
-		$is_man_shipping_fare = 0; //是否达到满xx减运费
-		$fare_man_shipping_fare_money = 0; //达到满xx减运费,司机减了多少运费
-
-		//----开始计算运费 //dispatchtype
-
-		if ($delivery_type_express == 1) {
-			//ims_ 
-			$store_trans_free_toal = 0;
-			if ($mb_city_id > 0) {
-
-				$shipping_default = M('lionfish_comshop_shipping')->where(array('enabled' => 1))->order('isdefault desc,id desc')->find();
-
-				foreach ($seller_goodss as $store_id => $val) {
-					//$val['is_moban'] = true;
-					$store_shipping_fare = 0;
-					if (isset($val['is_moban']) && $val['is_moban']) {
-						$store_shipping_fare = D('Home/Transport')->calc_transport($shipping_default['id'], $val['total_quantity'], $val['total_weight'], $mb_city_id);
-
-					}
-
-
-					$val['store_shipping_fare'] = $store_shipping_fare;
-
-					$trans_free_toal += $store_shipping_fare;
-					if ($store_id == 0) {
-						$store_trans_free_toal += $store_shipping_fare;
-					}
-
-					foreach ($val['goods'] as $kk => $d_goods) {
-						if ($d_goods['shipping'] == 1) {
-							//统一运费
-							$trans_free_toal += $d_goods['goods_freight'];
-							if ($store_id == 0) {
-								$store_trans_free_toal += $d_goods['goods_freight'];
-							}
-						}
-					}
-				}
-
-			} else if (!empty($address) && $mb_city_id == 0) {
-
-				$shipping_default = M('lionfish_comshop_shipping')->where(array('enabled' => 1))->order('isdefault desc,id desc')->find();
-
-				foreach ($seller_goodss as $store_id => $val) {
-					$store_shipping_fare = 0;
-					if (isset($val['is_moban']) && $val['is_moban']) {
-						$store_shipping_fare = D('Home/Transport')->calc_transport($shipping_default['id'], $val['total_quantity'], $val['total_weight'], $address['city_id']);
-
-					}
-					$val['store_shipping_fare'] = $store_shipping_fare;
-
-					$trans_free_toal += $store_shipping_fare;
-
-					if ($store_id == 0) {
-
-						$store_trans_free_toal += $store_shipping_fare;
-					}
-
-					foreach ($val['goods'] as $kk => $d_goods) {
-						if ($d_goods['shipping'] == 1) {
-							//统一运费
-							$trans_free_toal += $d_goods['goods_freight'];
-							$val['store_shipping_fare'] += $d_goods['goods_freight'];
-
-							if ($store_id == 0) {
-								$store_trans_free_toal += $d_goods['goods_freight'];
-							}
-						}
-					}
-				}
-
-			} else {
-				$trans_free_toal = 0;
-			}
-
-			//
-
-			if (!empty($man_free_shipping) && $man_free_shipping > 0 && $man_free_shipping <= $store_buy_total_money) {
-
-				$fare_man_shipping_fare_money = $store_trans_free_toal;
-				$is_man_shipping_fare = 1;
-				//$trans_free_toal = 0;
-			}
-		}
-		//礼品卡配送费0
-		if ($buy_type == 'virtualcard') {
-			$trans_free_toal = 0;
-		}
-		//---结束结算运费
-
-
-		if (empty($delivery_type_ziti)) {
-			$delivery_type_ziti = 1; //开启
-		}
-		if (empty($delivery_type_express)) {
-			$delivery_type_express = 2;
-		}
-		if (empty($delivery_type_tuanz)) {
-			$delivery_type_tuanz = 2;
-		}
-
-		//默认关闭同城配送
-		$delivery_type_localtown = 0;
-		//默认关闭核销商品
-		$delvery_type_hexiao = 0;
-		//is_only_express
-		if ($is_only_express == 1) {
-			$delivery_type_ziti = 2;
-			$delivery_type_express = 1;
-			$delivery_type_tuanz = 2;
-		} else if ($is_only_express == 3) {
-			//同城配送
-			$delivery_type_ziti = 0;
-			$delivery_type_express = 0;
-			$delivery_type_tuanz = 0;
-			$delivery_type_localtown = 1;
-		} else if ($is_only_express == 2) {
-			//核销商品
-			$delivery_type_ziti = 0;
-			$delivery_type_express = 0;
-			$delivery_type_tuanz = 0;
-			$delivery_type_localtown = 0;
-			$delvery_type_hexiao = 1;
-		}
-
-
-
-		$total_free = 0;
-		$is_ziti = 2;
-
-		$pick_up_time = "";
-		$pick_up_type = -1;
-		$pick_up_weekday = '';
-		$today_time = time();
-
-		$arr = array('天', '一', '二', '三', '四', '五', '六');
-
-		$pick_up_arr = array();
-		foreach ($goods as $key => $good) {
-			//暂时关闭
-			//ims_lionfish_comshop_goods
-			//ims_ lionfish_comshop_good_common
-
-			$goods_info = M('lionfish_comshop_good_common')->field('pick_up_type,pick_up_modify')->where(array('goods_id' => $good['goods_id']))->find();
-
-			if ($pick_up_type == -1 || $goods_info['pick_up_type'] > $pick_up_type) {
-				$pick_up_type = $goods_info['pick_up_type'];
-
-				if ($pick_up_type == 0) {
-					$pick_up_time = date('m-d', $today_time);
-					$pick_up_weekday = '周' . $arr[date('w', $today_time)];
-				} else if ($pick_up_type == 1) {
-					$pick_up_time = date('m-d', $today_time + 86400);
-					$pick_up_weekday = '周' . $arr[date('w', $today_time + 86400)];
-				} else if ($pick_up_type == 2) {
-					$pick_up_time = date('m-d', $today_time + 86400 * 2);
-					$pick_up_weekday = '周' . $arr[date('w', $today_time + 86400 * 2)];
-				} else if ($pick_up_type == 3) {
-					$pick_up_time = $goods_info['pick_up_modify'];
-				}
-			}
-
-			$goods[$key]['trans_free'] = $good['goods_freight'];
-
-			if ($is_vip_card_member == 1 && $good['is_take_vipcard'] == 1) {
-				$total_free += $good['card_total'];
-			} else if ($good['is_mb_level_buy'] == 1 && $member_info['level_id'] > 0) {
-				$total_free += $good['level_total'];
-			} else {
-				$total_free += $good['total'];
-			}
-
-		}
-
-		//同城配送费
-		$localtown_shipping_fare = 0;
-		//包装费
-		$picking_fare = 0;
-		$picking_fare_arr = array();
-		$localtown_shipping_fare_arr = array();
-		$localtown_dispatchtime = 0; //预计一共需要配送多少分钟
-		$localtown_expected_delivery = array(); //预计送达时间段
-		$localtown_modifypickingname = ""; //包装费标题
-		if ($is_only_express == 3) {
-			$picking_fare_arr = D('Home/LocaltownDelivery')->calc_packing_money($seller_goodss); // $seller_goodss;
-			$picking_fare = $picking_fare_arr['total_picking_fare'];
-
-			$localtown_dispatchtime = D('Home/LocaltownDelivery')->get_order_dispatchtime($seller_goodss);
-
-
-			if (isset($gpc['latitude']) && !empty($gpc['latitude']) && isset($gpc['longitude']) && !empty($gpc['longitude'])) {
-
-				$lon = $gpc['longitude'];
-
-				$lat = $gpc['latitude'];
-
-				$localtown_shipping_fare_arr = D('Home/LocaltownDelivery')->calc_shipping_fare($lon, $lat, $seller_goodss);
-
-				$localtown_shipping_fare = $localtown_shipping_fare_arr['total_shipping_fare'];
-
-				$trans_free_toal = $localtown_shipping_fare;
-
-
-			} else if (!empty($localtown_address)) {
-				list($lon, $lat) = explode(',', $localtown_address['lon_lat']);
-
-				$localtown_shipping_fare_arr = D('Home/LocaltownDelivery')->calc_shipping_fare($lon, $lat, $seller_goodss);
-
-				$localtown_shipping_fare = $localtown_shipping_fare_arr['total_shipping_fare'];
-
-				$trans_free_toal = $localtown_shipping_fare;
-			}
-
-			//配送时间段间隔
-			$localtown_expected_delivery = D('Home/LocaltownDelivery')->get_expected_delivery($localtown_dispatchtime);
-
-			$localtown_modifypickingname = D('Home/Front')->get_config_by_name('localtown_modifypickingname');
-			$localtown_modifypickingname = !empty($localtown_modifypickingname) ? $localtown_modifypickingname : '包装费';
-		}
-
-		//暂时关闭自提代码
-		/**
-		   if(!empty($pick_up))
-		   {
-			   $pick_up = unserialize($pick_up);
-			   $pick_up_ids = implode(',',$pick_up);
-			   $pick_up_arr = M('pick_up')->where( array('id'=>array('in',$pick_up_ids)) )->select();
-		   }
-		   **/
-
-
-		$pick_up_name = '';
-		$pick_up_mobile = '';
-		$tuan_send_address = '';
-		$order_note_content = '';
-
-		$tuan_send_address_info = array();
-
-		$shop_limit_buy_distance = D('Home/Front')->get_config_by_name('shop_limit_buy_distance');
-
-
-
-
-		if ($is_ziti >= 1) {
-			//寻找上一个订单的自提电话 自提姓名  
-
-			$last_order_info = M('lionfish_comshop_order')->where(array('member_id' => $member_id, 'delivery' => 'pickup'))->order('order_id desc')->find();
-			if (empty($last_order_info)) {
-				$last_order_info = M('lionfish_comshop_order')->where(array('member_id' => $member_id, 'delivery' => 'hexiao'))->order('order_id desc')->find();
-			}
-			if (!empty($last_order_info)) {
-				$pick_up_name = $last_order_info['shipping_name'];
-				$pick_up_mobile = $last_order_info['telephone'];
-				$order_note_content = $last_order_info['note_content'];
-			}
-
-			//order_note_content
-			$last_tuanz_send_order_info = M('lionfish_comshop_order')->field('tuan_send_address,address_id,note_content,order_id')->where(array('member_id' => $member_id, 'delivery' => 'tuanz_send'))->order('order_id desc')->find();
-
-			if (!empty($last_tuanz_send_order_info)) {
-				$tuan_send_address = $last_tuanz_send_order_info['tuan_send_address'];
-
-				if (!empty($last_tuanz_send_order_info['note_content']) && $last_tuanz_send_order_info['order_id'] > $last_order_info['order_id']) {
-					$order_note_content = $last_tuanz_send_order_info['note_content'];
-				}
-
-				if (!empty($last_tuanz_send_order_info['address_id'])) {
-
-					if ($shop_limit_buy_distance == 1) {
-						$tuan_send_address_info = M('lionfish_comshop_address')->where("address_id=" . $last_tuanz_send_order_info['address_id'] . " and lon_lat != '' ")->find();
-
-					} else {
-
-						$tuan_send_address_info = M('lionfish_comshop_address')->where("address_id=" . $last_tuanz_send_order_info['address_id'])->find();
-
-					}
-
-					if (!empty($tuan_send_address) && !empty($tuan_send_address_info['lon_lat'])) {
-						$province_info = D('Home/Front')->get_area_info($tuan_send_address_info['province_id']); // M('area')->field('area_name')->where( array('area_id' => $address['province_id']) )->find();
-						$city_info = D('Home/Front')->get_area_info($tuan_send_address_info['city_id']); //M('area')->field('area_name')->where( array('area_id' => $address['city_id']) )->find();
-						$country_info = D('Home/Front')->get_area_info($tuan_send_address_info['country_id']); //M('area')->field('area_name')->where( array('area_id' => $address['country_id']) )->find();
-
-						$tuan_send_address_info['province_name'] = $province_info['name'];
-						$tuan_send_address_info['city_name'] = $city_info['name'];
-						$tuan_send_address_info['country_name'] = $country_info['name'];
-
-						$tuan_send_address = $tuan_send_address_info['address'];
-					} else {
-						//todo...
-						$tuan_send_address = '';
-					}
-
-				} else {
-					$tuan_send_address = '';
-				}
-
-			}
-		}
-		/**
-		 **/
-		/**
-		   tuan_region
-		   store_buy_total_money
-		   
-		   **/
-
-		//open_score_buy_score $shop_limit_buy_distance = load_model_class('front')->get_config_by_name('shop_limit_buy_distance');
-
-
-		/**
-		   
-		   $delivery_ziti_name = D('Home/Front')->get_config_by_name('delivery_ziti_name');
-		   $delivery_tuanzshipping_name = D('Home/Front')->get_config_by_name('delivery_tuanzshipping_name');
-		   $delivery_diy_sort = D('Home/Front')->get_config_by_name('delivery_diy_sort');
-		   
-		   if(empty($delivery_diy_sort) || !isset($delivery_diy_sort)) $delivery_diy_sort = '0,1,2';
-		   
-		   
-		   if( empty($tuan_send_address_info) )
-		   {
-			   $tuan_send_address_info = array();
-		   }
-
-		   //判断是否预售,给出预售的信息 begin todo
-		   $presale_info = [];
-		   if( $buy_type == 'presale' )
-		   {
-			   // $presale_goods_id
-			   $presale_result = D('Home/PresaleGoods')->getCheckOutPresaleGoodsInfo( $presale_goods_id , $presale_goods_total );
-
-			   if( $presale_result['code'] == 0 )
-			   {
-				   $presale_info = $presale_result['data'];
-			   }
-		   }
-		   //end
-	   **/
-		$open_score_buy_score = D('Home/Front')->get_config_by_name('open_score_buy_score');
-
-		if (empty($open_score_buy_score) || $buy_type == 'integral') {
-			$open_score_buy_score = 0;
-		}
-
-		$score_forbuy_money_maxbi = D('Home/Front')->get_config_by_name('score_forbuy_money_maxbi');
-
-		if (empty($score_forbuy_money_maxbi)) {
-			$score_forbuy_money_maxbi = 100;
-		}
-
-		$score_for_money = 0;
-		$bue_use_score = 0;
-
-		if ($open_score_buy_score == 1) {
-			if ($member_info['score'] > 0) {
-
-				$score_can_max = $store_buy_total_money - $voucher_price - $reduce_money;
-
-				//计算能兑换多少钱
-				$score_forbuy_money = D('Home/Front')->get_config_by_name('score_forbuy_money');
-				//只有兑换比例大于0才能允许兑换
-				if (!empty($score_forbuy_money) && $score_forbuy_money > 0) {
-					$score_for_money = sprintf("%.2f", $member_info['score'] / $score_forbuy_money);
-					if ($score_can_max < $score_for_money) {
-						$score_for_money = $score_can_max;
-						$bue_use_score = floor($score_can_max * $score_forbuy_money);
-						$score_for_money = round($bue_use_score / $score_forbuy_money, 2);
-					}
-
-					$max_store_buy_total_money = sprintf("%.2f", ($score_forbuy_money_maxbi * $score_can_max) / 100);
-
-					if ($score_for_money > $max_store_buy_total_money) {
-						$score_for_money = $max_store_buy_total_money;
-
-						$bue_use_score = floor($max_store_buy_total_money * $score_forbuy_money);
-
-						$score_for_money = round($bue_use_score / $score_forbuy_money, 2);
-					} else if ($bue_use_score <= $max_store_buy_total_money) {
-
-						$bue_use_score = floor($score_for_money * $score_forbuy_money);
-
-						//$bue_use_score = $member_info['score'];
-
-						if ($bue_use_score > $member_info['score']) {
-							$bue_use_score = floor($member_info['score']);
-						}
-						$score_for_money = round($bue_use_score / $score_forbuy_money, 2);
-					}
-				}
-
-
-				//预售
-				//if($buy_type == 'presale'){
-				//	$sum_deduction_money =  $goods[0]["quantity"] * $presale_info['deduction_money'] ;
-				//}	
-			}
-		}
-		//score_forbuy_money score
-
-		$delivery_ziti_name = D('Home/Front')->get_config_by_name('delivery_ziti_name');
-		$delivery_tuanzshipping_name = D('Home/Front')->get_config_by_name('delivery_tuanzshipping_name');
-		$delivery_diy_sort = D('Home/Front')->get_config_by_name('delivery_diy_sort');
-
-		if (empty($delivery_diy_sort) || !isset($delivery_diy_sort))
-			$delivery_diy_sort = '0,1,2';
-
-
-		if (empty($tuan_send_address_info)) {
-			$tuan_send_address_info = array();
-		}
-
-		//判断是否预售,给出预售的信息 begin todo
-		$presale_info = [];
-		if ($buy_type == 'presale') {
-			// $presale_goods_id
-			$presale_result = D('Home/PresaleGoods')->getCheckOutPresaleGoodsInfo($presale_goods_id, $presale_goods_total);
-
-			if ($presale_result['code'] == 0) {
-				$presale_info = $presale_result['data'];
-			}
-		}
-		//end
-
-		$need_data = array();
-		$need_data['code'] = 1;
-
-		$need_data['open_score_buy_score'] = $open_score_buy_score; //1开启积分抵扣
-		$need_data['score'] = $member_info['score']; //会员持有的积分
-		$need_data['score_for_money'] = $score_for_money; //会员能抵扣的金额
-		$need_data['bue_use_score'] = $bue_use_score; //会员能抵扣的积分数
-
-
-		$need_data['delivery_type_ziti'] = $delivery_type_ziti;
-		$need_data['delivery_type_express'] = $delivery_type_express;
-		$need_data['delivery_type_tuanz'] = $delivery_type_tuanz;
-		$need_data['delivery_type_localtown'] = $delivery_type_localtown;
-		$need_data['delvery_type_hexiao'] = $delvery_type_hexiao;
-
-
-		$need_data['delivery_express_name'] = $delivery_express_name;
-		$need_data['delivery_ziti_name'] = $delivery_ziti_name;
-		$need_data['delivery_tuanzshipping_name'] = $delivery_tuanzshipping_name;
-		$need_data['delivery_diy_sort'] = $delivery_diy_sort;
-
-		$need_data['presale_info'] = $presale_info; //预售信息
-
-		$seller_goodss_keys = array_keys($seller_goodss);
-
-		$need_data['delivery_tuanz_money'] = round($delivery_tuanz_money * count($seller_goodss_keys), 2);
-
-		//$need_data['delivery_tuanz_money'] = $delivery_tuanz_money;
-		$need_data['man_free_tuanzshipping'] = empty($man_free_tuanzshipping) ? 0 : $man_free_tuanzshipping; //团长配送,满多少免配送费,0或者为空表示不减免
-		$need_data['man_free_shipping'] = empty($man_free_shipping) ? 0 : $man_free_shipping; //快递配送,满多少免配送费,0或者为空表示不减免
-
-		$need_data['address'] = $address;
-
-
-		$need_data['pick_up_time'] = $pick_up_time;
-		$need_data['pick_up_type'] = $pick_up_type;
-		$need_data['pick_up_weekday'] = $pick_up_weekday;
-
-		$need_data['is_pin_over'] = $is_pin_over;
-		$need_data['is_integer'] = 0; //$is_no_quan ? 1: 0;
-		$need_data['pick_up_arr'] = $pick_up_arr;
-		$need_data['is_ziti'] = 2;
-
-		$need_data['ziti_name'] = $pick_up_name;
-		$need_data['ziti_mobile'] = $pick_up_mobile;
-		$need_data['tuan_send_address'] = $tuan_send_address;
-		$need_data['tuan_send_address_info'] = $tuan_send_address_info;
-		$need_data['seller_goodss'] = $seller_goodss;
-		$need_data['show_voucher'] = $show_voucher;
-
-		$need_data['buy_type'] = $buy_type;
-		$need_data['address'] = $address;
-		$need_data['trans_free_toal'] = $trans_free_toal;
-
-		$need_data['is_limit_distance_buy'] = 0;
-		$need_data['limit_distance'] = 100; //km
-
-		$need_data['is_member_level_buy'] = $is_member_level_buy; //km
-		$need_data['level_save_money'] = $level_save_money; //km
-
-		//begin
-
-		$need_data['localtown_shipping_fare'] = $localtown_shipping_fare; //同城配送配送费
-		$need_data['pickingup_fare'] = $picking_fare; //包装费
-		$need_data['localtown_dispatchtime'] = $localtown_dispatchtime; //预计一共需要配送多少分钟
-		$need_data['picking_fare_arr'] = $picking_fare_arr;
-		$need_data['localtown_shipping_fare_arr'] = $localtown_shipping_fare_arr;
-		$need_data['localtown_expected_delivery'] = $localtown_expected_delivery;
-		//end
-
-
-		$need_data['is_vip_card_member'] = $is_vip_card_member; //km
-		$need_data['vipcard_save_money'] = $vipcard_save_money; //km
-		$need_data['is_open_vipcard_buy'] = $is_open_vipcard_buy; //km
-
-
-
-		if (!empty($shop_limit_buy_distance) && $shop_limit_buy_distance == 1) {
-			$latitude = 0;
-			$longitude = 0;
-
-			if (!empty($tuan_send_address_info) && !empty($tuan_send_address_info['lon_lat'])) {
-				//lon_lat
-				$lon_lat_arr = explode(',', $tuan_send_address_info['lon_lat']);
-				$longitude = $lon_lat_arr[0];
-				$latitude = $lon_lat_arr[1];
-			}
-
-
-			if (isset($gpc['latitude']) && !empty($gpc['latitude'])) {
-				$latitude = $gpc['latitude'];
-			}
-			if (isset($gpc['longitude']) && !empty($gpc['longitude'])) {
-				$longitude = $gpc['longitude'];
-			}
-
-			if (!empty($latitude) && !empty($longitude)) {
-				$shop_buy_distance = D('Home/Front')->get_config_by_name('shop_buy_distance');
-
-				$shop_buy_distance = $shop_buy_distance * 1000;
-
-				$community_info = M('lionfish_community_head')->field('lon,lat')->where(array('id' => $community_id))->find();
-
-				$distince = D('Seller/Communityhead')->GetDistance($longitude, $latitude, $community_info['lon'], $community_info['lat']);
-
-				$need_data['current_distance'] = $distince;
-				$need_data['shop_buy_distance'] = $shop_buy_distance;
-				if ($distince > $shop_buy_distance) {
-					$need_data['is_limit_distance_buy'] = 1;
-					$need_data['limit_distance'] = $distince / 1000;
-				}
-			}
-		}
-
-
-
-		$need_data['reduce_money'] = $reduce_money;
-		$need_data['is_open_fullreduction'] = $is_open_fullreduction;
-		$need_data['cha_reduce_money'] = $cha_reduce_money;
-
-
-		$need_data['is_man_delivery_tuanz_fare'] = $is_man_delivery_tuanz_fare; //是否达到满xx减团长配送费
-		$need_data['fare_man_delivery_tuanz_fare_money'] = $fare_man_delivery_tuanz_fare_money; //达到满xx减团长配送费, 减了多少钱
-		$need_data['is_man_shipping_fare'] = $is_man_shipping_fare; //是否达到满xx减运费
-		$need_data['fare_man_shipping_fare_money'] = $fare_man_shipping_fare_money; //达到满xx减运费,司机减了多少运费
-
-
-		$dispatching = isset($gpc['dispatching']) ? $gpc['dispatching'] : 'pickup';
-		//is_ziti == 2
-		if ($dispatching == 'express') {
-			$need_data['total_free'] = $total_free + $trans_free_toal - $voucher_price - $reduce_money;
-		} else if ($dispatching == 'localtown_delivery') {
-			$need_data['total_free'] = $total_free + $localtown_shipping_fare + $picking_fare - $voucher_price - $reduce_money;
-		} else {
-			$need_data['total_free'] = $total_free - $voucher_price - $reduce_money;
-		}
-		if ($is_ziti == 2) {
-			$need_data['total_free'] = $total_free - $voucher_price - $reduce_money;
-		}
-		//积分兑换 不算总金额,但是算总积分
-		if ($buy_type == 'integral') {
-			$need_data['total_free'] = $trans_free_toal;
-			$need_data['total_integral'] = $total_free;
-		}
-
-		if ($need_data['total_free'] < 0) {
-			$need_data['total_free'] = 0;
-		}
-
-		//判断是否可以余额支付
-
-		//暂时关闭 会员余额功能
-		/**
-		   $is_yue_open_info =	M('config')->where( array('name' => 'is_yue_open') )->find();
-		   $is_yue_open =  $is_yue_open_info['value'];
-		   **/
-
-		$is_yue_open = 0;
-
-		$is_yue_open = D('Home/Front')->get_config_by_name('is_open_yue_pay');
-		if (empty($is_yue_open)) {
-			$is_yue_open = 0;
-		}
-
-
-		$need_data['is_yue_open'] = $is_yue_open;
-
-		$need_data['can_yupay'] = 0;
-
-		//暂时关闭 会员余额功能
-
-		if ($is_yue_open == 1 && $need_data['total_free'] >= 0 && $member_info['account_money'] >= $need_data['total_free']) {
-			$need_data['can_yupay'] = 1;
-		}
-
-		//前端隐藏 团长信息
-		$index_hide_headdetail_address = D('Home/Front')->get_config_by_name('index_hide_headdetail_address');
-
-		if (empty($index_hide_headdetail_address)) {
-			$index_hide_headdetail_address = 0;
-		}
-		$need_data['index_hide_headdetail_address'] = $index_hide_headdetail_address;
-
-
-		//订单留言
-		$is_open_order_message = D('Home/Front')->get_config_by_name('is_open_order_message');
-
-		$need_data['yu_money'] = $member_info['account_money'];
-		$need_data['goods'] = $goods;
-		$need_data['is_open_order_message'] = $is_open_order_message;
-
-		$need_data['is_zero_opentuan'] = 0;
-		//拼团特殊情况0元开团
-		if ($buy_type == 'pintuan' && $is_zero_buy == 1) {
-			//$need_data['total_free'] = 0;
-			//$need_data['trans_free_toal'] = 0;
-			//$need_data['is_zero_opentuan'] = 1;
-		}
-
-
-		//订阅消息begin
-
-		$is_need_subscript = 0;
-		$need_subscript_template = array();
-
-
-		//'pay_order','send_order','hexiao_success','apply_community','open_tuan','take_tuan','pin_tuansuccess','apply_tixian'
-		//$member_id
-		if ($buy_type == 'pintuan') {
-			//pin_tuansuccess
-			//send_order  parameter[weprogram_subtemplate_pin_tuansuccess]
-			//hexiao_success
-
-			$pin_tuansuccess_info = M('lionfish_comshop_subscribe')->where(array('member_id' => $member_id, 'type' => 'pin_tuansuccess'))->find();
-
-			//if( empty($pin_tuansuccess_info) )
-			//{
-			$weprogram_subtemplate_pin_tuansuccess = D('Home/Front')->get_config_by_name('weprogram_subtemplate_pin_tuansuccess');
-
-			if (!empty($weprogram_subtemplate_pin_tuansuccess)) {
-				$need_subscript_template['pin_tuansuccess'] = $weprogram_subtemplate_pin_tuansuccess;
-			}
-			//}
-
-		} else {
-			//pay_order
-			$pay_order_info = M('lionfish_comshop_subscribe')->where(array('member_id' => $member_id, 'type' => 'pay_order'))->find();
-
-			//if( empty($pay_order_info) )
-			//{
-			$weprogram_subtemplate_pay_order = D('Home/Front')->get_config_by_name('weprogram_subtemplate_pay_order');
-
-			if (!empty($weprogram_subtemplate_pay_order)) {
-				$need_subscript_template['pay_order'] = $weprogram_subtemplate_pay_order;
-			}
-			//}
-		}
-		//send_order
-
-		$send_order_info = M('lionfish_comshop_subscribe')->where(array('member_id' => $member_id, 'type' => 'send_order'))->find();
-
-		//if( empty($send_order_info) )
-		//{
-		$weprogram_subtemplate_send_order = D('Home/Front')->get_config_by_name('weprogram_subtemplate_send_order');
-
-		if (!empty($weprogram_subtemplate_send_order)) {
-			$need_subscript_template['send_order'] = $weprogram_subtemplate_send_order;
-		}
-		//}
-		//hexiao_success
-		$hexiao_success_info = M('lionfish_comshop_subscribe')->where(array('member_id' => $member_id, 'type' => 'hexiao_success'))->find();
-
-
-		//if( empty($hexiao_success_info) )
-		//{
-		$weprogram_subtemplate_hexiao_success = D('Home/Front')->get_config_by_name('weprogram_subtemplate_hexiao_success');
-
-		if (!empty($weprogram_subtemplate_hexiao_success)) {
-			$need_subscript_template['hexiao_success'] = $weprogram_subtemplate_hexiao_success;
-		}
-		//}
-
-		if (!empty($need_subscript_template)) {
-			$is_need_subscript = 1;
-		}
-
-		//下单万能表单
-		$need_data['allform'] = D('Home/Allform')->getOrderForms();
-
-		//判断是否使用货到付款
-		$cashondelivery_data = D('Home/Front')->getCashonDeliveryAction($buy_type, $seller_goodss);
-		$need_data['cashondelivery_data'] = $cashondelivery_data;
-
-		//订阅消息end
-		$need_data['is_need_subscript'] = $is_need_subscript;
-		$need_data['need_subscript_template'] = $need_subscript_template;
-
-		//订单提交页面备注信息
-		$order_note_open = D('Home/Front')->get_config_by_name('order_note_open');
-
-		$order_note_open = isset($order_note_open) && $order_note_open == 1 ? 1 : 0;
-
-		$order_note_name = D('Home/Front')->get_config_by_name('order_note_name');
-
-		$order_note_name = !isset($order_note_name) || empty($order_note_name) ? '店名' : $order_note_name;
-
-		$need_data['order_note_open'] = $order_note_open; //开启下单页面备注,仅 自提跟 团长配送时需要
-		$need_data['order_note_name'] = $order_note_name; //备注名称,默认是店名
-		$need_data['order_note_content'] = $order_note_content; //备注名称,默认是店名
-
-		$need_data['localtown_modifypickingname'] = $localtown_modifypickingname; //备注名称,默认是店名
-
-		//配送费类型:0、固定金额,1、按距离收取
-		$localtown_delivery_moneytype = D('Home/Front')->get_config_by_name('localtown_delivery_moneytype');
-		//起送价格
-		$localtown_moneytype_fixed_deliverymoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_deliverymoney');
-		//达到金额免配送费
-		$localtown_moneytype_fixed_freemoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_freemoney');
-		//加价配送
-		$localtown_makeup_delivery_money = D('Home/Front')->get_config_by_name('localtown_makeup_delivery_money');
-		//1、固定金额,订单价格超过起送价格 无加价配送费,2、按距离收取 无加价配送费 3、固定金额,起送价格为0 无加价配送费
-		if (($localtown_delivery_moneytype == 0 && ($localtown_shipping_fare_arr[0]['is_can_qisong'] == 1 || $localtown_moneytype_fixed_deliverymoney == 0)) || $localtown_delivery_moneytype == 1) {
-			$localtown_makeup_delivery_money = 0;
-		} else {
-			$localtown_makeup_delivery_money = 0;
-		}
-
-		$need_data['localtown_delivery_moneytype'] = $localtown_delivery_moneytype;
-		$need_data['localtown_moneytype_fixed_deliverymoney'] = $localtown_moneytype_fixed_deliverymoney;
-		$need_data['localtown_moneytype_fixed_freemoney'] = $localtown_moneytype_fixed_freemoney;
-		$need_data['localtown_makeup_delivery_money'] = $localtown_makeup_delivery_money;
-
-		$need_data['order_lou_meng_hao'] = D('Home/Front')->get_config_by_name('order_lou_meng_hao');
-		$need_data['order_lou_meng_hao_placeholder'] = D('Home/Front')->get_config_by_name('order_lou_meng_hao_placeholder');
-
-		echo json_encode($need_data);
-		die();
-	}
-
-	public function sub_order()
-	{
-		$gpc = I('request.');
-
-		$buy_type = isset($gpc['buy_type']) ? $gpc['buy_type'] : 'dan';
-
-		$token = $gpc['token'];
-
-		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where(array('token' => $token))->find();
-		$member_id = $weprogram_token['member_id'];
-
-		$pintuan_model_buy = D('Home/Front')->get_config_by_name('pintuan_model_buy');
-
-		$allform_id = $gpc['allform_id'];
-		$allform_list = $gpc['allform_list'];
-
-		if (empty($pintuan_model_buy) || $pintuan_model_buy == 0) {
-			$pintuan_model_buy = 0;
-		}
-
-		$is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
-		$is_open_vipcard_buy = !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 ? 1 : 0;
-
-		$is_vip_card_member = 0;
-		$is_member_level_buy = 0;
-
-		if ($member_id > 0) {
-
-			$member_info = M('lionfish_comshop_member')->where(array('member_id' => $member_id))->find();
-
-			if (!empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1) {
-
-				$now_time = time();
-
-				if ($member_info['card_id'] > 0 && $member_info['card_end_time'] > $now_time) {
-					$is_vip_card_member = 1; //还是会员
-				} else if ($member_info['card_id'] > 0 && $member_info['card_end_time'] < $now_time) {
-					$is_vip_card_member = 2; //已过期
-				}
-			}
-
-			if ($is_vip_card_member != 1 && $member_info['level_id'] > 0) {
-				$is_member_level_buy = 1;
-			}
-		}
-
-		if ($buy_type == 'presale') {
-			$is_vip_card_member = 0;
-			$is_member_level_buy = 0;
-		}
-
-		//use_score = 1
-		$use_score = isset($gpc['use_score']) ? intval($gpc['use_score']) : 0;
-
-		$puis_not_buy = D('Home/Front')->get_config_by_name('puis_not_buy');
-
-		if (!empty($puis_not_buy) && $puis_not_buy == 1) {
-			$member_info = M('lionfish_comshop_member')->field('level_id')->where(array('member_id' => $member_id))->find();
-
-			if ($member_info['level_id'] == 0) {
-				echo json_encode(array('code' => 2, 'msg' => '普通会员不能购买'));
-				die();
-			}
-		}
-		//$buy_type == 'presale'
-		$data_s = array();
-		$data_s['pay_method'] = $gpc['wxpay'];
-		$data_s['buy_type'] = isset($gpc['buy_type']) ? $gpc['buy_type'] : 'dan';
-		$data_s['pick_up_id'] = $gpc['pick_up_id'];
-		$data_s['dispatching'] = $gpc['dispatching'];
-
-		$order_note_open = D('Home/Front')->get_config_by_name('order_note_open');
-		if ($order_note_open == 1) {
-			$data_s['note_content'] = $gpc['note_content'];
-		} else {
-			$data_s['note_content'] = '';
-		}
-
-
-		$data_s['soli_id'] = isset($gpc['soli_id']) ? intval($gpc['soli_id']) : 0;
-
-
-		if ($data_s['dispatching'] != 'express' && empty($data_s['pick_up_id'])) {
-			$last_community = M('lionfish_community_history')->where(array('member_id' => $member_id))->order('id desc')->find();
-
-			if (!empty($last_community)) {
-				$data_s['pick_up_id'] = $last_community['head_id'];
-			}
-
-			//$data_s['pick_up_id']
-		}
-		//礼品卡不用配送地址begin
-		if ($data_s['buy_type'] == 'virtualcard') {
-			$data_s['dispatching'] = 'express';
-			$data_s['address_id'] = 0;
-		}
-		//end
-
-		if ($data_s['buy_type'] == 'dan' || $data_s['buy_type'] == 'soitaire' || $data_s['buy_type'] == 'presale' || ($pintuan_model_buy == 1 && $data_s['buy_type'] != 'dan' && $data_s['buy_type'] != 'integral')) {
-			D('Seller/Community')->in_community_history($member_id, $data_s['pick_up_id']);
-		}
-
-		//'express'  快递, 'pickup'  自提, 'tuanz_send'  团长配送)   tuan_send_address 
-
-		$data_s['ziti_name'] = $gpc['ziti_name'];
-		$data_s['quan_arr'] = $gpc['quan_arr'];
-
-
-		$data_s['comment'] = $gpc['comment'];
-		$data_s['ziti_mobile'] = $gpc['ziti_mobile'];
-		$data_s['tuan_send_address'] = $gpc['tuan_send_address'];
-		$data_s['ck_yupay'] = $gpc['ck_yupay'];
-		//是否货到付款
-		$data_s['cashon_delivery'] = $gpc['cashon_delivery'];
-
-
-		$data_s['province_name'] = isset($gpc['province_name']) ? $gpc['province_name'] : '';
-		$data_s['city_name'] = isset($gpc['city_name']) ? $gpc['city_name'] : '';
-		$data_s['country_name'] = isset($gpc['country_name']) ? $gpc['country_name'] : '';
-		$data_s['address_name'] = isset($gpc['address_name']) ? $gpc['address_name'] : '';
-
-		$data_s['latitude'] = isset($gpc['latitude']) ? $gpc['latitude'] : '';
-		$data_s['longitude'] = isset($gpc['longitude']) ? $gpc['longitude'] : '';
-		$data_s['lou_meng_hao'] = isset($gpc['lou_meng_hao']) ? $gpc['lou_meng_hao'] : '';
-
-		$data_s['expected_delivery_time'] = isset($gpc['expected_delivery_time']) ? $gpc['expected_delivery_time'] : '';
-		//$data_s['tuan_send_address'] .= $data_s['lou_meng_hao'];
-		//$data_s['tuan_send_address'] .= $data_s['lou_meng_hao'];
-
-		//tuan_send_address
-
-		$province_name = isset($data_s['province_name']) ? $data_s['province_name'] : '';
-		$city_name = isset($data_s['city_name']) ? $data_s['city_name'] : '';
-		$country_name = isset($data_s['country_name']) ? $data_s['country_name'] : '';
-		$address_name = isset($data_s['address_name']) ? $data_s['address_name'] : '';
-
-		//判断配送距离
-		/*if($data_s['dispatching'] == 'localtown_delivery'){
-			   //服务距离
-			   $localtown_servvice_maxdistance =  D('Home/Front')->get_config_by_name('localtown_servvice_maxdistance');
-			   //商家经纬度
-			   $localtown_shop_lon =  D('Home/Front')->get_config_by_name('localtown_shop_lon');
-			   $localtown_shop_lat =  D('Home/Front')->get_config_by_name('localtown_shop_lat');
-
-			   $distince = D('Seller/Communityhead')->GetDistance($data_s['longitude'],$data_s['latitude'], $localtown_shop_lon, $localtown_shop_lat);
-			   $distince = round($distince/1000,2);
-			   if($distince > $localtown_servvice_maxdistance){
-				   //echo json_encode( array('code' => 2, 'msg' => '超出服务距离'.$localtown_servvice_maxdistance.'KM') );
-				   echo json_encode( array('code' => 2, 'msg' => '您与商家的距离过远,商家的配送范围是'.$localtown_servvice_maxdistance.'KM内') );
-				   die();
-			   }
-		   }*/
-
-
-		$json = array();
-
-		$pay_method = $data_s['pay_method']; //支付类型
-		$order_msg_str = $data_s['order_msg_str']; //商品订单留言
-		$comment = $data_s['comment']; //商品订单留言
-
-		$comment_arr = array();
-		if (!empty($data_s['comment'])) {
-			$comment_arr1 = explode('@EOF@', $data_s['comment']);
-			foreach ($comment_arr1 as $var) {
-				$count = substr_count($var, '_');
-				$a = explode('_', $var);
-
-				for ($i = 1; $i < $count; $i++) {
-					$comment_arr[$a[$i]] = $a[$count];
-				}
-
-			}
-		}
-
-		$pick_up_id = $data_s['pick_up_id'];
-		$dispatching = $data_s['dispatching'];
-		$ziti_name = $data_s['ziti_name'];
-		$ziti_mobile = $data_s['ziti_mobile'];
-
-
-		//新增快递
-		$province_name = isset($data_s['province_name']) ? $data_s['province_name'] : '';
-		$city_name = isset($data_s['city_name']) ? $data_s['city_name'] : '';
-		$country_name = isset($data_s['country_name']) ? $data_s['country_name'] : '';
-		$address_name = isset($data_s['address_name']) ? $data_s['address_name'] : '';
-
-
-		$ck_yupay = $data_s['ck_yupay'];
-		$cashon_delivery = $data_s['cashon_delivery'];
-		if ($dispatching == 'express') {
-			$data_s['address_id'] = $this->_add_address($token, $ziti_name, $ziti_mobile, $province_name, $city_name, $country_name, $address_name);
-		} else if ($dispatching == 'localtown_delivery') {
-			$data_s['address_id'] = $this->_add_address($token, $ziti_name, $ziti_mobile, $province_name, $city_name, $country_name, $address_name, $data_s['latitude'], $data_s['longitude'], $data_s['lou_meng_hao']);
-		} else if ($dispatching == 'tuanz_send') {
-			$data_s['address_id'] = $this->_add_address($token, $ziti_name, $ziti_mobile, $province_name, $city_name, $country_name, $data_s['tuan_send_address'], $data_s['latitude'], $data_s['longitude'], $data_s['lou_meng_hao']);
-
-			$data_s['tuan_send_address'] .= $data_s['lou_meng_hao'];
-		}
-
-		/**
-		   
-		   pick_up_id: that.data.pick_up_id,
-		   dispatching: that.data.dispatching, //express  pickup
-		   ziti_name: t_ziti_name,
-		   ziti_mobile: t_ziti_mobile
-		   **/
-		$order_msg_arr = explode('@,@', $order_msg_str);
-
-		$quan_arr = $data_s['quan_arr']; //商品订单留言
-
-		$order_quan_arr = array();
-
-
-		if (!empty($quan_arr)) {
-			if (!is_array($quan_arr)) {
-				$quan_arr = array($quan_arr);
-			}
-
-			foreach ($quan_arr as $q_val) {
-				$tmp_q = array();
-				$tmp_q = explode('_', $q_val);
-
-
-				$voucher_info = M('lionfish_comshop_coupon_list')->where("consume='N' and id=" . $tmp_q[1] . " and user_id=" . $member_id . " and end_time >" . time())->find();
-
-				if (!empty($voucher_info)) {
-					//$order_quan_arr[$tmp_q[0]] = $tmp_q[1];
-					$order_quan_arr[1] = $tmp_q[1];
-				}
-
-
-			}
-		}
-
-
-
-
-		$msg_arr = array();
-		foreach ($order_msg_arr as $val) {
-			$tmp_val = explode('@_@', $val);
-			$msg_arr[$tmp_val[0]] = $tmp_val[1];
-		}
-
-
-		$cart = D('Home/Car');
-
-		// 验证商品数量
-		//buy_type:buy_type
-		$buy_type = $data_s['buy_type']; //I('post.buy_type');
-
-
-		$is_pin = 0;
-		if ($buy_type == 'pintuan') {
-			$is_pin = 1;
-		}
-
-		$goodss = $cart->get_all_goodswecar($buy_type, $token, 1, $data_s['pick_up_id'], $data_s['soli_id']);
-		//付款人
-
-		$payment = M('lionfish_comshop_member')->where(array('member_id' => $member_id))->find();
-
-		//收货人
-		$addr_param = array();
-		$addr_param[':uniacid'] = $_W['uniacid'];
-		$addr_param[':member_id'] = $member_id;
-
-		//$addr_sql = "select * from ".tablename('lionfish_comshop_address')." where uniacid=:uniacid and member_id=:member_id order by  is_default desc,address_id desc limit 1";
-		//$address = pdo_fetch($addr_sql, $addr_param);
-
-		$seller_goodss = array();
-
-		/** 计算每个订单的优惠券占比begin */
-		$zanbi_total_money = 0;
-
-		//是否需要校验ticket 交易组件
-		$scene = $gpc['scene'];
-		$is_need_scene_check = 0;
-
-		if (!empty($scene)) {
-			$is_need_scene_check = D('Seller/MpModifyTradeComponts')->sceneCheck($scene);
-		}
-
-		foreach ($goodss as $key => $val) {
-			//单商户先屏蔽
-			//$goods_store_field =  M('goods')->field('store_id')->where( array('goods_id' => $val['goods_id']) )->find();
-
-			$supply_id = D('Home/Front')->get_goods_supply_id($val['goods_id']);
-			if ($supply_id > 0) {
-				$supply_info = D('Home/Front')->get_supply_info($supply_id);
-
-				if ($supply_info['type'] == 0) {
-					$supply_id = 0;
-				}
-			}
-
-			if ($data_s['dispatching'] == 'localtown_delivery') {
-				if ($supply_id > 0) {
-					$isopen_localtown_delivery = D('Home/Front')->get_supply_config_by_name('isopen_localtown_delivery', $supply_id);
-					if ($isopen_localtown_delivery == 1) {
-						//服务距离
-						$localtown_servvice_maxdistance = D('Home/Front')->get_supply_config_by_name('localtown_servvice_maxdistance', $supply_id);
-						//商家经纬度
-						$localtown_shop_lon = D('Home/Front')->get_supply_config_by_name('localtown_shop_lon', $supply_id);
-						$localtown_shop_lat = D('Home/Front')->get_supply_config_by_name('localtown_shop_lat', $supply_id);
-						$distince = D('Seller/Communityhead')->GetDistance($data_s['longitude'], $data_s['latitude'], $localtown_shop_lon, $localtown_shop_lat);
-						$distince = round($distince / 1000, 2);
-						if ($distince > $localtown_servvice_maxdistance) {
-							echo json_encode(array('code' => 2, 'msg' => '您与商家的距离过远,商家的配送范围是' . $localtown_servvice_maxdistance . 'KM内'));
-							die();
-						}
-					}
-				} else {
-					//服务距离
-					$localtown_servvice_maxdistance = D('Home/Front')->get_config_by_name('localtown_servvice_maxdistance');
-					//商家经纬度
-					$localtown_shop_lon = D('Home/Front')->get_config_by_name('localtown_shop_lon');
-					$localtown_shop_lat = D('Home/Front')->get_config_by_name('localtown_shop_lat');
-					$distince = D('Seller/Communityhead')->GetDistance($data_s['longitude'], $data_s['latitude'], $localtown_shop_lon, $localtown_shop_lat);
-					$distince = round($distince / 1000, 2);
-					if ($distince > $localtown_servvice_maxdistance) {
-						echo json_encode(array('code' => 2, 'msg' => '您与商家的距离过远,商家的配送范围是' . $localtown_servvice_maxdistance . 'KM内'));
-						die();
-					}
-				}
-
-			}
-
-			$seller_goodss[$supply_id][$key] = $val;
-
-			//$cart->removecar($val['key'],$token);
-
-
-			if ($is_vip_card_member == 1 && $val['is_take_vipcard'] == 1) {
-				$zanbi_total_money += $val['card_total'];
-			} else if ($val['is_mb_level_buy'] > 0 && $is_member_level_buy == 1) {
-				$zanbi_total_money += $val['level_total'];
-			} else if ($val['is_mb_level_buy'] == 1 && $member_info['level_id'] > 0) {
-				$zanbi_total_money += $val['level_total'];
-			} else {
-				$zanbi_total_money += $val['total'];
-			}
-
-			//检测是否场景符合begin
-			if ($is_need_scene_check == 1) {
-				if ($val['isTradeComponts'] == 0) {
-					echo json_encode(array('code' => 2, 'msg' => $val['name'] . ':未提交小程序交易组件'));
-					die();
-				}
-			}
-			//检测是否场景符合end
-		}
-
-		//判断是否可以货到付款
-		if ($cashon_delivery == 1) {
-			$cashondelivery_data = D('Home/Front')->getCashonDeliveryAction($buy_type, $seller_goodss);
-			if ($cashondelivery_data['isopen_cashondelivery'] == 1) {
-				if ($dispatching == 'express' && $cashondelivery_data['isopen_cashondelivery_express'] == 0) {
-					echo json_encode(array('code' => 3, 'msg' => '货到付款未开启'));
-					die();
-				} else if ($dispatching == 'tuanz_send' && $cashondelivery_data['isopen_cashondelivery_communityhead'] == 0) {
-					echo json_encode(array('code' => 3, 'msg' => '货到付款未开启'));
-					die();
-				} else if ($dispatching == 'localtown_delivery' && $cashondelivery_data['isopen_cashondelivery_localtown'] == 0) {
-					echo json_encode(array('code' => 3, 'msg' => '货到付款未开启'));
-					die();
-				} else if ($dispatching == 'hexiao' && $cashondelivery_data['isopen_cashondelivery_hexiao'] == 0) {
-					echo json_encode(array('code' => 3, 'msg' => '货到付款未开启'));
-					die();
-				} else if ($dispatching == 'pickup' && $cashondelivery_data['isopen_cashondelivery_ziti'] == 0) {
-					echo json_encode(array('code' => 3, 'msg' => '货到付款未开启'));
-					die();
-				}
-			} else {
-				echo json_encode(array('code' => 3, 'msg' => '货到付款未开启'));
-				die();
-			}
-		}
-
-		//....看看有没有满多少才能下单begin
-		$open_man_orderbuy = D('Home/Front')->get_config_by_name('open_man_orderbuy');
-		$man_orderbuy_money = D('Home/Front')->get_config_by_name('man_orderbuy_money');
-
-		//pindan (拼团商品单独购买)   pintuan (拼团)
-		if ($buy_type == 'pintuan' || $buy_type == 'pindan' || $buy_type == 'integral') {
-			$open_man_orderbuy = 0;
-		}
-
-		if (!empty($open_man_orderbuy) && $open_man_orderbuy == 1) {
-			if (!empty($man_orderbuy_money) && $man_orderbuy_money > 0) {
-				if ($man_orderbuy_money > $zanbi_total_money) {
-					echo json_encode(array('code' => 2, 'msg' => '满' . $man_orderbuy_money . '元才可以下单', 'is_forb' => 1));
-					die();
-				}
-			}
-		}
-		//....看看有没有满多少才能下单end
-		//清除购物车
-		foreach ($goodss as $key => $val) {
-			$cart->removecar($val['key'], $token);
-
-		}
-		/** 计算每个订单的优惠券占比end */
-
-		$pay_total = 0;
-		//M('order_all')
-
-
-		$order_all_data = array();
-		$order_all_data['member_id'] = $member_id;
-		$order_all_data['order_num_alias'] = build_order_no($member_id);
-		$order_all_data['transaction_id'] = '';
-		$order_all_data['order_status_id'] = 3;
-		$order_all_data['is_pin'] = $is_pin;
-		$order_all_data['paytime'] = 0;
-
-		$order_all_data['addtime'] = time();
-
-		$order_all_id = M('lionfish_comshop_order_all')->add($order_all_data);
-
-
-		//暂时屏蔽积分商城模块
-
-		$integral_model = D('Home/Integral');
-
-		$order_ids_arr = array();
-		$del_integral = 0;
-
-		if (($buy_type == 'pintuan' || $buy_type == 'pindan') && $pintuan_model_buy == 0) {
-			$community_info = array();
-			$community_detail_info = array();
-		} else if ($buy_type == 'integral') {
-			$community_info = array();
-			$community_detail_info = array();
-		} else if (($buy_type == 'pintuan' || $buy_type == 'pindan') && $pintuan_model_buy == 1) {
-			$community_info = M('lionfish_community_head')->where(array('id' => $data_s['pick_up_id']))->find();
-			$community_detail_info = D('Home/Front')->get_community_byid($data_s['pick_up_id']);
-		} else {
-			$community_info = M('lionfish_community_head')->where(array('id' => $data_s['pick_up_id']))->find();
-			$community_detail_info = D('Home/Front')->get_community_byid($data_s['pick_up_id']);
-		}
-
-
-
-		$address_info = M('lionfish_comshop_address')->where(array('address_id' => $data_s['address_id']))->find();
-
-
-		$is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
-		$full_money = D('Home/Front')->get_config_by_name('full_money');
-		$full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
-
-
-		$man_free_tuanzshipping = D('Home/Front')->get_config_by_name('man_free_tuanzshipping');
-		$man_free_shipping = D('Home/Front')->get_config_by_name('man_free_shipping');
-
-		if (empty($man_free_tuanzshipping)) {
-			$man_free_tuanzshipping = 0;
-		}
-
-		if (empty($man_free_shipping)) {
-			$man_free_shipping = 0;
-		}
-
-		if (empty($full_reducemoney) || $full_reducemoney <= 0) {
-			$is_open_fullreduction = 0;
-		}
-
-		if (($buy_type == 'pintuan' || $buy_type == 'pindan') && $pintuan_model_buy == 0) {
-			$man_free_tuanzshipping = 0;
-			$man_free_shipping = 0;
-			$is_open_fullreduction = 0;
-		} else if ($buy_type == 'integral') {
-			$man_free_tuanzshipping = 0;
-			$man_free_shipping = 0;
-			$is_open_fullreduction = 0;
-		} else if (($buy_type == 'pintuan' || $buy_type == 'pindan') && $pintuan_model_buy == 1) {
-			$man_free_shipping = 0;
-			$is_open_fullreduction = 0;
-		}
-		//预售不参与满减
-		if ($buy_type == 'presale') {
-			$man_free_tuanzshipping = 0;
-			$man_free_shipping = 0;
-			$is_open_fullreduction = 0;
-		}
-
-		$is_moban = false;
-
-
-		$cart = D('Home/Car');
-		$is_just_1 = 0;
-		$index_comment = 0;
-
-		$pay_goods_name = "";
-
-		$store_buy_total_money = 0;
-
-		$open_score_buy_score = D('Home/Front')->get_config_by_name('open_score_buy_score');
-
-		$score_for_money = 0; //use_score
-
-		if ($buy_type == 'integral') {
-			$open_score_buy_score = 0;
-		}
-
-		//预售不参与积分抵扣
-		if ($open_score_buy_score == 1 && $use_score == 1 && $payment['score'] > 0 && $buy_type != 'presale') {
-			//计算能兑换多少钱
-			$score_forbuy_money = D('Home/Front')->get_config_by_name('score_forbuy_money');
-			//只有兑换比例大于0才能允许兑换
-			if (!empty($score_forbuy_money) && $score_forbuy_money > 0) {
-				$score_for_money = sprintf('%.2f', $payment['score'] / $score_forbuy_money);
-			}
-		}
-
-
-
-		foreach ($seller_goodss as $kk => $vv) {
-			$is_just_1++;
-
-			$data = array();
-
-			$data['member_id'] = $member_id;
-			$data['name'] = $payment['username'];
-			$data['use_score'] = $use_score; //是否使用积分抵扣
-
-			$data['telephone'] = $data_s['ziti_mobile'];
-			$data['note_content'] = $data_s['note_content'];
-			$data['shipping_name'] = $data_s['ziti_name'];
-			$data['shipping_tel'] = $data_s['ziti_mobile'];
-
-
-			if ($dispatching == 'express' || $dispatching == 'tuanz_send' || $dispatching == 'localtown_delivery') {
-				$data['shipping_address'] = $address_info['address'];
-				$data['shipping_province_id'] = $address_info['province_id'];
-				$data['shipping_city_id'] = $address_info['city_id'];
-				$data['shipping_stree_id'] = 0;
-				$data['shipping_country_id'] = $address_info['country_id'];
-
-			} else {
-				$data['shipping_address'] = $community_detail_info['fullAddress'];
-				$data['shipping_province_id'] = $community_info['province_id'];
-				$data['shipping_city_id'] = $community_info['city_id'];
-				$data['shipping_stree_id'] = $community_info['country_id'];
-				$data['shipping_country_id'] = $community_info['area_id'];
-			}
-
-
-			$data['shipping_method'] = 0;
-			$data['delivery'] = $dispatching;
-			$data['pick_up_id'] = $pick_up_id;
-
-			$data['ziti_name'] = $community_info['head_name'];
-			$data['ziti_mobile'] = $community_info['head_mobile'];
-
-
-			$data['payment_method'] = $pay_method;
-
-			$data['address_id'] = $data_s['address_id'];
-			$data['voucher_id'] = isset($order_quan_arr[1]) ? $order_quan_arr[1] : 0; //目前都是平台券
-
-
-			$data['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
-			$data['date_added'] = time();
-
-			$subject = '';
-			$fare = 0;
-			$order_total = 0;
-
-
-			$trans_free_toal = 0; //运费
-
-			$is_localtown_free_shipping_fare = 0;
-			$localtown_shipping_fare_total = 0; //同城配送费
-			$localtown_free_shipping_fare = 0; //满减的同城配送费用
-
-			$reduce_money = 0;
-
-			$man_total_free = 0;
-			$score_buy_money = 0;
-
-			$is_lottery = 0;
-			$is_integral = 0;
-			$is_spike = 0;
-			$is_hexiao = 0;
-
-			$total_weight = 0;
-			$total_quantity = 0;
-
-			$redis_has_add_list = array();
-
-			$is_free_shipping_fare = 0; //是否免除运费
-
-			$order_goods_total_money = 0;
-			$goods_data = array();
-
-			$is_moban = false;
-			//comment_arr comment_arr
-
-
-			$packing_fare = 0;
-			$iscan_fu_packing = 1;
-
-			if ('localtown_delivery' == $dispatching) {
-
-				$tmp_sellergd = array($kk => array('goods' => $vv));
-
-				$town_address = M('lionfish_comshop_address')->where(array('address_id' => $data_s['address_id']))->find();
-
-				list($lon, $lat) = explode(",", $town_address['lon_lat']);
-
-				$localtown_shippingfare_arr = D('Home/LocaltownDelivery')->calc_shipping_fare($lon, $lat, $tmp_sellergd);
-
-				$trans_free_toal = $localtown_shippingfare_arr['total_shipping_fare'];
-
-				$localtown_shipping_fare_total = $trans_free_toal;
-
-				$packing_fare_arr = D('Home/LocaltownDelivery')->calc_packing_money(array($kk => array('goods' => $vv)));
-
-				$packing_fare = $packing_fare_arr['total_picking_fare'];
-
-				$localtown_shipping_fare = $localtown_shippingfare_arr['total_shipping_fare'];
-				$localtown_yl_shipping_fare = $localtown_shippingfare_arr['total_yl_shipping_fare'];
-				if ($localtown_shipping_fare != $localtown_yl_shipping_fare && $localtown_shipping_fare == 0) {
-					$is_localtown_free_shipping_fare = 1;
-					$localtown_free_shipping_fare = $localtown_shippingfare_arr['total_yl_shipping_fare'];
-				}
-
-				$data['localtown_add_shipping_fare'] = $localtown_shippingfare_arr[$kk]['localtown_add_shipping_fare'];
-			}
-
-			$data['expected_delivery_time'] = $data_s['expected_delivery_time'];
-			$data['packing_fare'] = floatval($packing_fare);
-
-			foreach ($vv as $key => $good) {
-
-				if ($kk == 0) {
-					if ($is_vip_card_member == 1 && $good['is_take_vipcard'] == 1) {
-						$store_buy_total_money += $good['card_total'];
-					} else if ($good['is_mb_level_buy'] == 1 && $member_info['level_id'] > 0) {
-						$store_buy_total_money += $good['level_total'];
-					} else {
-						$store_buy_total_money += $good['total'];
-					}
-
-				}
-				/**
-						 if($good['shipping']==1)
-						 {
-							 //统一运费
-							 $trans_free_toal += $good['goods_freight'];
-							 $trans_free = $good['goods_freight'];
-						 }else {
-							 //运费模板
-							 $trans_free = load_model_class('transport')->calc_transport($good['transport_id'], $good['quantity'], $good['quantity']*$good['weight'], $address['city_id'] );
-							 
-							 //$trans_free = D('Home/Transport')->calc_transport($good['transport_id'], $good['quantity']*$good['weight'], $address['city_id'] );
-							 $trans_free_toal +=$trans_free;
-						 }
-						 **/
-				$trans_free = 0;
-				//$trans_free_toal +=$trans_free;
-				//sku_str 
-
-				if ($is_vip_card_member == 1 && $good['is_take_vipcard'] == 1) {
-					$order_goods_total_money += $good['card_total'];
-					$order_total += $good['card_total'];
-				} else if ($good['is_mb_level_buy'] == 1 && $member_info['level_id'] > 0) {
-					$order_goods_total_money += $good['level_total'];
-					$order_total += $good['level_total'];
-				} else {
-					$order_goods_total_money += $good['total'];
-					$order_total += $good['total'];
-				}
-
-				$tp_goods_info = M('lionfish_comshop_goods')->field('type')->where(array('id' => $good['goods_id']))->find();
-
-				$tp_goods_info['store_id'] = 1;
-
-				if ($tp_goods_info['type'] == 'lottery') {
-					$is_lottery = 1;
-				}
-				if ($tp_goods_info['type'] == 'spike') {
-					$is_spike = 1;
-					$is_pin = 0;
-				}
-				//暂时屏蔽积分商城模块
-
-				if ($tp_goods_info['type'] == 'integral') {
-					$is_integral = 1;
-					$is_pin = 0;
-					$check_result = $integral_model->check_user_score_can_pay($member_id, $good['sku_str'], $good['goods_id']);
-					if ($check_result['code'] == 1) {
-						echo json_encode(array('code' => 2, 'msg' => '剩余' . $check_result['cur_score'] . '积分,积分不足!', 'is_forb' => 1));
-						die();
-					}
-
-				}
-
-				//is_hexiao is_only_express
-				if ($good['is_only_express'] == 2) {
-					$is_hexiao = 2;
-					$is_pin = 0;
-				}
-
-				if ($good['shipping'] == 0) {
-					$is_moban = true;
-					//统一运费
-					$total_weight += $good['weight'] * $good['quantity'];
-					$total_quantity += $good['quantity'];
-				}
-
-				$fenbi_li = 1;
-				if ($zanbi_total_money > 0) {
-					if ($is_vip_card_member == 1 && $good['is_take_vipcard'] == 1) {
-						$fenbi_li = round($good['card_total'] / $zanbi_total_money, 2);
-					} else if ($good['is_mb_level_buy'] == 1 && $member_info['level_id'] > 0) {
-						$fenbi_li = round($good['level_total'] / $zanbi_total_money, 2);
-					} else {
-						$fenbi_li = round($good['total'] / $zanbi_total_money, 2);
-					}
-				}
-
-				//if( isset($comment_arr[$index_comment]) )
-				//{
-				//	$comment = $comment_arr[$index_comment];
-
-				//}
-
-				//$good['goods_id']
-				if (isset($comment_arr)) {
-					foreach ($comment_arr as $key => $var) {
-						if ($good['goods_id'] == $key) {
-							$comment = $var;
-						}
-
-					}
-				}
-
-
-				//监测库存数量
-				$quantity_flag = D('Seller/Redisorder')->check_goods_can_buy($good['goods_id'], $good['sku_str'], $good['quantity']);
-				if ($quantity_flag <= 0) {
-					if (!empty($redis_has_add_list)) {
-						D('Seller/Redisorder')->bu_car_has_delquantity($redis_has_add_list);
-					}
-					echo json_encode(array('code' => 2, 'msg' => '已抢光', 'is_forb' => 1));
-					die();
-				}
-				//如果是下单减库存,那么用占坑法来避免超库存---begin
-				$kucun_method = D('Home/Front')->get_config_by_name('kucun_method');
-
-				if (empty($kucun_method)) {
-					$kucun_method = 0;
-				}
-
-				if ($kucun_method == 0) {
-					//$ret = $redis->rPush('city', 'guangzhou');
-					$check_redis_quantity = D('Seller/Redisorder')->add_goods_buy_user($good['goods_id'], $good['sku_str'], $good['quantity'], $member_id);
-					//注意要回滚
-
-					//$key = "user_goods_{$member_id}_{$goods_id}_{$sku_str}";
-
-					if ($check_redis_quantity == 0) {
-						//cancle_redis_user_list 
-						if (!empty($redis_has_add_list)) {
-							D('Seller/Redisorder')->bu_car_has_delquantity($redis_has_add_list);
-						}
-
-						echo json_encode(array('code' => 2, 'msg' => '已抢光', 'is_forb' => 1));
-						die();
-					}
-
-					$redis_has_add_list[] = array('member_id' => $member_id, 'goods_id' => $good['goods_id'], 'sku_str' => $good['sku_str'], 'quantity' => $good['quantity']);
-
-				}
-				//----------------redis   end
-				if ($good['can_man_jian'] == 1) {
-					//$man_total_free += $good['total'];
-
-					//begggg
-
-					if ($is_vip_card_member == 1 && $good['is_take_vipcard'] == 1) {
-
-						if ($good['can_man_jian'] == 1) {
-							$man_total_free += $good['card_total'];
-
-						}
-					} else if ($good['is_mb_level_buy'] == 1 && $member_info['level_id'] > 0) {
-						if ($good['can_man_jian'] == 1) {
-							$man_total_free += $good['level_total'];
-						}
-					} else {
-						if ($good['can_man_jian'] == 1) {
-							$man_total_free += $good['total'];
-
-						}
-					}
-
-					//eddddd
-
-				}
-
-				$pay_goods_name .= $good['name'];
-
-				if ($good['is_mb_level_buy'] == 1 && $is_vip_card_member == 0 && $member_info['level_id'] > 0) {
-					$good['is_mb_level_buy'] == 1;
-				} else {
-					$good['is_mb_level_buy'] == 0;
-				}
-
-				$localtown_superposition_pickingmoney = 0;
-				$localtown_superposition_pickingmoney = isset($localtown_superposition_pickingmoney) ? $localtown_superposition_pickingmoney : 0;
-
-				$gd_packing_fare = 0;
-
-				if ($localtown_superposition_pickingmoney == 0) {
-					$gd_packing_fare = $good['packing_free'];
-				} else {
-					if ($packing_fare == $good['packing_free'] && $iscan_fu_packing == 1) {
-						$iscan_fu_packing = 0;
-						$gd_packing_fare = $good['packing_free'];
-					}
-				}
-
-				$goods_data[] = array(
-					'goods_id' => $good['goods_id'],
-					'store_id' => $tp_goods_info['store_id'],
-					'name' => $good['name'],
-					'model' => $good['model'],
-					'is_pin' => $is_pin,
-					'pin_id' => $good['pin_id'],
-					'header_disc' => $good['header_disc'],
-					'member_disc' => $good['member_disc'],
-					'level_name' => $good['level_name'],
-					'option' => $good['sku_str'] == 'undefined' ? '' : $good['sku_str'],
-					'quantity' => $good['quantity'],
-					'shipping_fare' => $trans_free,
-					'price' => $good['price'],
-					'costprice' => $good['costprice'],
-					'card_price' => $good['card_price'],
-					'levelprice' => $good['levelprice'],
-					'total' => $good['total'],
-					'packing_fare' => $gd_packing_fare,
-					'card_total' => $good['card_total'],
-					'level_total' => $good['level_total'],
-					'is_mb_level_buy' => $good['is_mb_level_buy'],
-					'is_take_vipcard' => $good['is_take_vipcard'],
-					'fenbi_li' => $fenbi_li,
-					'can_man_jian' => $good['can_man_jian'],
-					'soli_id' => $good['soli_id'],
-					'comment' => htmlspecialchars($comment)
-				);
-
-			}
-
-			$index_comment++;
-			//$total_weight = 0;
-			//$total_quantity = 0;
-
-			if ($dispatching == 'express') {
-				//结算运费新模式
-				$trans_free_toal = 0; //运费
-
-				//----开始计算运费
-
-				//ims_ 
-
-				$shipping_default = M('lionfish_comshop_shipping')->where("enabled=1")->order('isdefault desc,id desc')->find();
-
-				$seller_goodss_re = $seller_goodss;
-
-
-
-				$store_shipping_fare = 0;
-				if ($is_moban) {
-					$store_shipping_fare = D('Home/Transport')->calc_transport($shipping_default['id'], $total_quantity, $total_weight, $address_info['city_id']);
-
-
-				}
-
-				$trans_free_toal += $store_shipping_fare;
-
-				foreach ($vv as $kkc => $d_goods) {
-					if ($d_goods['shipping'] == 1) {
-						//统一运费
-						$trans_free_toal += $d_goods['goods_freight'];
-
-					}
-				}
-
-
-				if ($kk == 0 && !empty($man_free_shipping) && $man_free_shipping > 0 && $order_goods_total_money >= $man_free_shipping) {
-
-					//$trans_free_toal = 0;
-					$is_free_shipping_fare = 1;
-				}
-
-				//---结束结算运费 address_id
-
-				$data_s['address_id'] = $this->_add_address($token, $ziti_name, $ziti_mobile, $province_name, $city_name, $country_name, $address_name);
-			} else if ('tuanz_send' == $dispatching) {
-				$trans_free_toal = 0;
-				$delivery_tuanz_money = D('Home/Front')->get_config_by_name('delivery_tuanz_money');
-
-
-				$community_info_modify = $community_info;
-
-				if (!empty($community_info_modify['is_modify_shipping_method']) && $community_info_modify['is_modify_shipping_method'] == 1) {
-					if (!empty($community_info_modify['is_modify_shipping_fare']) && $community_info_modify['is_modify_shipping_fare'] == 1 && $community_info_modify['shipping_fare'] > 0) {
-						$delivery_tuanz_money = $community_info_modify['shipping_fare'];
-					}
-				}
-
-
-				$trans_free_toal = $delivery_tuanz_money;
-
-				$data['tuan_send_address'] = $data_s['tuan_send_address'];
-
-				if ($kk == 0 && !empty($man_free_tuanzshipping) && $man_free_tuanzshipping > 0 && $order_goods_total_money >= $man_free_tuanzshipping) {
-					$is_free_shipping_fare = 1;
-					//$trans_free_toal = 0;
-				}
-			}
-
-
-
-
-			//$is_pin; is_lottery
-			//'pintuan', 'normal', 'lottery'
-			$data['type'] = 'normal';
-			if ($is_pin == 1) {
-				$data['type'] = 'pintuan';
-				if ($is_lottery == 1) {
-					$data['type'] = 'lottery';
-				}
-			}
-			if ($is_integral == 1) {
-				$data['type'] = 'integral';
-				$is_pin = 0;
-			}
-
-			if ($is_hexiao == 1) {
-				$data['type'] = 'virtual';
-				$is_pin = 0;
-			}
-
-
-			if ($is_spike == 1) {
-				$data['type'] = 'spike';
-				$is_pin = 0;
-			}
-
-			//礼品卡配送费0
-			if ($buy_type == 'virtualcard') {
-				$trans_free_toal = 0;
-			}
-
-			$data['shipping_fare'] = floatval($trans_free_toal);
-
-			if ($is_free_shipping_fare == 1) {
-				$trans_free_toal = 0;
-			}
-
-			//原先计算满减金额
-			/*if($is_open_fullreduction == 1 && $man_total_free >= $full_money )
-				  {
-					  $reduce_money = $full_reducemoney ;
-				  }*/
-			//多组满减金额计算
-			if ($is_open_fullreduction == 1) {
-				$reduce_result = D('Home/Front')->get_reduce_money($man_total_free);
-				$reduce_money = $reduce_result['reduce_money'];
-			}
-
-			$data['is_free_shipping_fare'] = $is_free_shipping_fare;
-			$data['store_id'] = $kk;
-			$data['order_goods_total_money'] = $order_goods_total_money;
-
-			$data['is_localtown_free_shipping_fare'] = $is_localtown_free_shipping_fare;
-			$data['localtown_free_shipping_fare'] = $localtown_free_shipping_fare;
-
-			$data['goodss'] = $goods_data;
-			$data['order_num_alias'] = build_order_no($member_id);
-
-			$data['totals'][0] = array(
-				'code' => 'sub_total',
-				'title' => '商品价格',
-				'text' => '¥' . $order_total,
-				'value' => $order_total
-			);
-			$data['totals'][1] = array(
-				'code' => 'shipping',
-				'title' => '运费',
-				'text' => '¥' . $trans_free_toal,
-				'value' => $trans_free_toal
-			);
-
-			$data['totals'][2] = array(
-				'code' => 'total',
-				'title' => '总价',
-				'text' => '¥' . ($order_total + $trans_free_toal - $reduce_money),
-				'value' => ($order_total + $trans_free_toal - $reduce_money)
-			);
-
-			$data['from_type'] = 'wepro';
-
-			//目前都是平台券
-			if ($data['voucher_id'] > 0) {
-
-				//暂时屏蔽优惠券,等待开启 
-				/**
-						 $voucher_info = pdo_fetch("select * from ".tablename('lionfish_comshop_coupon_list')." where uniacid=:uniacid and id=:id ", 
-												 array(':uniacid' => $_W['uniacid'],':id' => $data['voucher_id']));
-						 
-						 $data['voucher_credit'] = $voucher_info['credit'];
-						 
-						 pdo_update('lionfish_comshop_coupon_list', array('ordersn' => $data['order_num_alias'],'consume' => 'Y','usetime' => time()), array('id' => $data['voucher_id'] ));
-						 **/
-
-				$voucher_info = M('lionfish_comshop_coupon_list')->where(array('id' => $data['voucher_id']))->find();
-				//检查优惠券指定商品或指定商品分类 优惠金额 begin
-				$voucher_list[0] = $voucher_info;
-
-				$voucher_list = D('Home/Voucher')->get_voucher_amout_bygoods($voucher_list, $goods_data, 0);
-
-				$voucher_info = $voucher_list[0];
-				//检查优惠券指定商品或指定商品分类 优惠金额 end
-				$data['voucher_credit'] = $voucher_info['can_vouche_amount'];
-
-				$bili = 1;
-
-				if ($zanbi_total_money > 0) {
-					$bili = round(($order_goods_total_money / $zanbi_total_money), 2);
-				}
-				$data['voucher_credit'] = $data['voucher_credit'] * $bili;
-
-
-				//判断是否超出订单商品金额,不算运费
-				//if($data['voucher_credit'] > $order_total+$trans_free_toal - $reduce_money )
-				if ($data['voucher_credit'] > $order_total - $reduce_money) {
-					$data['voucher_credit'] = $order_total - $reduce_money;
-				}
-
-
-				M('lionfish_comshop_coupon_list')->where(array('id' => $data['voucher_id']))->save(array('ordersn' => $data['order_num_alias'], 'consume' => 'Y', 'usetime' => time()));
-
-			} else {
-				$data['voucher_credit'] = 0;
-			}
-
-			$use_score_total = 0; //用掉用户多少积分了.
-			$data['score_for_money'] = 0;
-
-			if ($kk == 0 && $score_for_money > 0) {
-
-
-
-				if ($order_total + $trans_free_toal - $reduce_money - $data['voucher_credit'] <= 0) {
-					//没必要扣积分了,单价已经是0
-				} else {
-					//只能抵扣扣除优惠券部分的金额
-					$del_money = $order_total - $data['voucher_credit'] - $reduce_money;
-
-					//var_dump($del_money, $score_for_money);die();
-
-					//score_for_money 会员能抵扣的最大金额
-
-
-
-					//计算多少积分了。
-
-					$score_forbuy_money_maxbi = D('Home/Front')->get_config_by_name('score_forbuy_money_maxbi');
-					$score_forbuy_money = D('Home/Front')->get_config_by_name('score_forbuy_money');
-
-					if (empty($score_forbuy_money_maxbi)) {
-						$score_forbuy_money_maxbi = 100;
-					}
-
-					//$max_dikou_money =  sprintf('%.2f', ($del_money * $score_forbuy_money_maxbi) /100);
-					$max_dikou_score = floor($del_money * $score_forbuy_money_maxbi * $score_forbuy_money / 100);
-					$max_dikou_money = sprintf('%.2f', ($max_dikou_score / $score_forbuy_money));
-					if ($max_dikou_money < $score_for_money) {
-						$score_for_money = $max_dikou_money;
-					}
-					//$score_buy_money = 0;
-					$data['score_for_money'] = $score_for_money;
-					//TODO...扣除会员积分,将积分分拆入每个商品订单,写入日志
-
-					//var_dump($data['score_for_money'], $max_dikou_money);die();
-				}
-			}
-
-
-			$data['comment'] = htmlspecialchars($comment);
-
-			$data['reduce_money'] = $reduce_money;
-
-			$data['man_total_free'] = $man_total_free;
-
-			//判断自提 dispatching:"pickup"
-			//dispatching, //express  pickup
-
-			if ($dispatching == 'express') {
-				$data['total'] = ($order_total); //+$fare - $data['voucher_credit']
-			} else if ('tuanz_send' == $dispatching) {
-				$data['total'] = ($order_total); // - $data['voucher_credit']);
-			} else {
-				$data['total'] = ($order_total); // - $data['voucher_credit']
-			}
-			//积分商城
-			//暂时屏蔽积分商城模块
-
-
-			if ($data['type'] == 'integral') {
-				$del_integral += $order_total; //扣除积分
-				$data['total'] = $order_total;
-
-			}
-			$data['buy_type'] = $buy_type; //判断预售使用
-			//万能表单数据
-			$data['allform_id'] = $allform_id;
-			$data['allform_list'] = $allform_list;
-
-			$oid = D('Home/Frontorder')->addOrder($data); // D('Order')->addOrder($data);
-
-
-
-			//暂时屏蔽自提模块
-			/**
-				  if($data['delivery'] == 'pickup')
-				  {
-					  $verify_bool = true;
-					  $verifycode = 0;
-					  while($verify_bool)
-					  {
-						  $code  = (ceil(time()/100)+rand(10000000,40000000)).rand(1000,9999);
-						  $verifycode = $code ? $code : rand(100000,999999);
-						  $verifycode = str_replace('1989','9819',$verifycode);
-						  $verifycode = str_replace('1259','9521',$verifycode);
-						  $verifycode = str_replace('12590','95210',$verifycode);
-						  $verifycode = str_replace('10086','68001',$verifycode);
-						  
-						  $pick_order = M('pick_order')->where( array('pick_sn' => $verifycode) )->find();
-						  if(empty($pick_order))
-						  {
-							  $verify_bool = false;
-						  }
-					  }
-					  $pick_data = array();
-					  $pick_data['pick_sn'] = $verifycode;
-					  $pick_data['pick_id'] = $pick_up_id;
-					  $pick_data['order_id'] = $oid;
-					  $pick_data['state'] = 0;
-					  
-					  $pick_data['ziti_name'] = $ziti_name;
-					  $pick_data['ziti_mobile'] = $ziti_mobile;
-					  
-				  
-					  $pick_data['addtime'] = time();
-					  M('pick_order')->add($pick_data);
-				  }
-				  **/
-
-			$order_ids_arr[] = $oid;
-			//$pay_total = $pay_total + $order_total+$trans_free_toal - $data['voucher_credit'];
-			if ($dispatching == 'express' && $data['type'] != 'integral') {
-				$pay_total = $pay_total + $order_total + $trans_free_toal - $data['voucher_credit'] - $reduce_money - $data['score_for_money'];
-			} else if ($dispatching == 'express' && $data['type'] == 'integral') {
-				$pay_total = $trans_free_toal;
-			} else if ('localtown_delivery' == $dispatching) {
-				$pay_total = $pay_total + $order_total + $packing_fare + $trans_free_toal - $data['voucher_credit'] - $reduce_money - $data['score_for_money'] + $data['localtown_add_shipping_fare'];
-			} else if ('tuanz_send' == $dispatching) {
-				$pay_total = $pay_total + $order_total + $trans_free_toal - $data['voucher_credit'] - $reduce_money - $data['score_for_money'];
-			} else {
-				$pay_total = $pay_total + $order_total - $data['voucher_credit'] - $reduce_money - $data['score_for_money'];
-			}
-
-
-			if ($buy_type == 'presale') {
-				//如果是预售,此处支付的就是定金
-				$presale_order_info = M('lionfish_comshop_order_presale')->where(['order_id' => $oid])->find();
-				if ($presale_order_info['presale_type'] == 1) {
-					M('lionfish_comshop_order_presale')->where(['id' => $presale_order_info['id']])->save(['presale_ding_money' => $pay_total]);
-				} else {
-					$pay_total = $presale_order_info['presale_ding_money'];
-				}
-			}
-
-			$pay_total = round($pay_total, 2);
-
-			$order_relate_data = array();
-
-			$order_relate_data['order_all_id'] = $order_all_id;
-			$order_relate_data['order_id'] = $oid;
-			$order_relate_data['addtime'] = time();
-
-			M('lionfish_comshop_order_relate')->add($order_relate_data);
-
-		}
-
-		$order_all_data = array();
-		$order_all_data['total_money'] = $pay_total;
-
-		M('lionfish_comshop_order_all')->where(array('id' => $order_all_id))->save($order_all_data);
-
-		if ($order_all_id) {
-
-			$order = M('lionfish_comshop_order')->where(array('order_id' => $oid))->find();
-
-			$member_info = M('lionfish_comshop_member')->field('we_openid,account_money')->where(array('member_id' => $member_id))->find();
-
-			$is_yue_open = 0;
-
-			$is_yue_open = D('Home/Front')->get_config_by_name('is_open_yue_pay');
-			if (empty($is_yue_open)) {
-				$is_yue_open = 0;
-			}
-
-			//检测是否需要扣除积分
-			if ($data['type'] == 'integral' && $del_integral > 0 && $is_integral == 1) {
-
-				$order_goods_tp = M('lionfish_comshop_order_goods')->field('order_goods_id')->where(array('order_id' => $oid))->find();
-
-				D('Admin/Member')->sendMemberPointChange($member_id, $del_integral, 1, '积分兑换商品', 'integral_exchange', $oid, $order_goods_tp['order_goods_id']);
-			}
-
-			$is_open_yinpay = D('Home/Front')->get_config_by_name('is_open_yinpay');
-			$shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
-			if ($order['type'] == 'ignore' || $pay_total <= 0 || ($is_yue_open == 1 && $ck_yupay == 1 && $member_info['account_money'] >= $pay_total)) {
-				//余额支付独立方法
-				D('Home/OrderV2')->carOrderYuerPay($order_all_id, $order, $pay_total, $ck_yupay, $buy_type, $is_integral, $is_spike, $is_just_1);
-			} else if ($buy_type == 'dan' && $cashon_delivery == 1) { //货到付款订单
-				//货到付款支付独立方法
-				D('Home/OrderV2')->carOrderCashonPay($order_all_id, $order, $pay_total, $cashon_delivery, $buy_type, $is_spike, $is_just_1);
-			} else if ($ck_yupay == 3) {
-				$lib_path = dirname(dirname(dirname(__FILE__))) . '/Lib/';
-				require_once $lib_path . "/Weixin/Wxfy.class.php";
-				$wxfy = new \Wxfy();
-				$appid = D('Home/Front')->get_config_by_name('wepro_appid');
-				$notify_url = $shop_domain . '/notify.php?type=fyfyfy';
-				$out_trade_no = $order_all_id . '-' . time();
-				$body = $pay_goods_name; //'商品购买';
-				if (empty($body) || mb_strlen($body)>30) {
-					$body = '购物车商品合并支付';
-				}
-				// $body=iconv('GB2312', 'UTF-8', $body);
-			
-				$nonce_str = nonce_str();
-				$fee = $pay_total;
-				$total_fee = $fee * 100;
-				$wxfydata=array();
-				$wxfydata['debug'] = false;
-				$wxfydata['filepath'] = $lib_path . 'Weixin/cert/';
-				$prefix = 1450;
-				$wxfydata['mchnt_order_no'] = $prefix . $out_trade_no; //商户订单号, 商户系统内部的订单号(5 到 30 个字符、 只能包含字母数字,区分大小写)
-				$wxfydata['random_str'] = $nonce_str;
-				$wxfydata['goods_des'] = $body;
-				$wxfydata['term_ip'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
-				$wxfydata['order_amt'] = $total_fee;
-				$wxfydata['notify_url'] = $notify_url;
-				$wxfydata['sub_openid'] = $payment['we_openid'];
-				$wxfydata['sub_appid'] = $appid;
-			//	$wxfydata['debug'] = true;
-
-				$resfult = $wxfy->createOrder($wxfydata);
-			//	$res = json_decode($resfult, 1);
-
-				M('lionfish_comshop_order_all')->where(array('id' => $order_all_id))->save(array('out_trade_no' => $out_trade_no));
-
-				
-					D('Home/Pin')->insertNotifyOrder($order['order_id']);
-					$time = time();
-
-//					$prepay_id = $res['session_id'];
-
-
-//					M('lionfish_comshop_order')->where(array('order_id' => array('in', $order_ids_arr)))->save(array('perpay_id' => $prepay_id));
-
-
-
-					$data = array();
-					$data['code'] = 0;
-//					$data['appid'] = $res['sdk_appid'];
-//					$data['timeStamp'] = $res['sdk_timestamp'];
-//					$data['nonceStr'] = $res['sdk_noncestr'];
-//					$data['signType'] = $res['sdk_signtype'];
-//					$data['package'] = 'prepay_id=' .$prepay_id;
-//					$data['paySign'] = $res['sdk_paysign'];
-					$data['out_trade_no'] = $out_trade_no;
-					//$data['total_fee']=
-					$data['is_go_orderlist'] = $is_just_1;
-                    $data['xml'] = $resfult;
-					$data['total_fee']=$total_fee;
-					//如果是微信小程序交易组件begin---新支付方法 wx.requestOrderPayment
-					$data['order_info'] = [];
-					$data['isRequestOrderPayment'] = $is_need_scene_check;
-
-
-
-					if ($is_pin == 1) {
-						$data['redirect_url'] = '../groups/group?id=' . $oid . '&is_show=1';
-					} else {
-						$data['redirect_url'] = '../orders/order_show_all?order_all_id=' + $order_all_id;
-					}
-
-				
-
-
-			} else if (isset($is_open_yinpay) && $is_open_yinpay == 3) {
-				//begin
-
-				$fee = $pay_total;
-				$appid = D('Home/Front')->get_config_by_name('wepro_appid');
-
-				$body = $pay_goods_name; //'商品购买';
-
-				$body = mb_substr($body, 0, 32, 'utf-8');
-
-				if (empty($body)) {
-					$body = '商品购买';
-				}
-
-				$mch_id = D('Home/Front')->get_config_by_name('wepro_partnerid');
-				$nonce_str = nonce_str();
-
-
-				$shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
-
-				$notify_url = $shop_domain . '/notify.php';
-
-
-				$openid = $payment['we_openid'];
-				$out_trade_no = $order_all_id . '-' . time();
-
-				//out_trade_no
-				M('lionfish_comshop_order_all')->where(array('id' => $order_all_id))->save(array('out_trade_no' => $out_trade_no));
-
-
-				$spbill_create_ip = $_SERVER['REMOTE_ADDR'];
-				$total_fee = $fee * 100;
-
-
-				//float(0.99999999999998)
-				$trade_type = 'JSAPI';
-				$pay_key = D('Home/Front')->get_config_by_name('wepro_key');
-
-				$post['appid'] = D('Home/Front')->get_config_by_name('wepro_fuwu_appid'); // 'wx7c38e2f177e0af59';
-				$post['body'] = $body;
-				$post['mch_id'] = D('Home/Front')->get_config_by_name('wepro_fuwu_partnerid'); //'1562705521';
-
-
-
-				$post['nonce_str'] = $nonce_str;
-				$post['notify_url'] = $notify_url;
-
-				//$post['openid'] = $openid;
-				$post['out_trade_no'] = $out_trade_no;
-				$post['spbill_create_ip'] = $spbill_create_ip;
-				$post['sub_appid'] = $appid;
-				$post['sub_mch_id'] = D('Home/Front')->get_config_by_name('wepro_sub_mch_id');
-				$post['sub_openid'] = $openid;
-
-				$post['total_fee'] = $total_fee;
-				$post['trade_type'] = $trade_type;
-				$sign = sign($post, $pay_key);
-
-				//var_dump( $notify_url );die();
-
-				$post_xml = '<xml>
-				   <appid>' . $post['appid'] . '</appid>
-				   <body>' . $body . '</body>
-				   <mch_id>' . $post['mch_id'] . '</mch_id>
-				   <nonce_str>' . $nonce_str . '</nonce_str>
-				   <notify_url>' . $notify_url . '</notify_url>
-				   
-				   <out_trade_no>' . $out_trade_no . '</out_trade_no>
-				   <spbill_create_ip>' . $spbill_create_ip . '</spbill_create_ip>
-				   <sub_appid>' . $post['sub_appid'] . '</sub_appid>
-				   <sub_mch_id>' . $post['sub_mch_id'] . '</sub_mch_id>
-				   <sub_openid>' . $openid . '</sub_openid>
-				   <total_fee>' . $total_fee . '</total_fee>
-				   <trade_type>' . $trade_type . '</trade_type>
-				   <sign>' . $sign . '</sign>
-				</xml> ';
-				$url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
-				$xml = http_request($url, $post_xml);
-				$array = xml($xml);
-
-				if ($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS') {
-
-					D('Home/Pin')->insertNotifyOrder($order['order_id']);
-
-					$time = time();
-					$tmp = array();
-					$tmp['appId'] = $appid;
-					$tmp['nonceStr'] = $nonce_str;
-					$tmp['package'] = 'prepay_id=' . $array['PREPAY_ID'];
-					$tmp['signType'] = 'MD5';
-					$tmp['timeStamp'] = "$time";
-
-					$prepay_id = (string) $array['PREPAY_ID'];
-
-
-					M('lionfish_comshop_order')->where(array('order_id' => array('in', $order_ids_arr)))->save(array('perpay_id' => $prepay_id));
-
-
-
-
-					//M('order')->where( array('order_id' => array('in',$order_ids_arr) ) )->save( array('perpay_id' => (string)$array['PREPAY_ID']) );
-					$data = array();
-					$data['code'] = 0;
-					$data['appid'] = $appid;
-					$data['timeStamp'] = "$time";
-					$data['nonceStr'] = $nonce_str;
-					$data['signType'] = 'MD5';
-					$data['package'] = 'prepay_id=' . $array['PREPAY_ID'];
-					$data['paySign'] = sign($tmp, $pay_key);
-					$data['out_trade_no'] = $out_trade_no;
-
-					$data['is_go_orderlist'] = $is_just_1;
-
-
-
-					if ($is_pin == 1) {
-						$data['redirect_url'] = '../groups/group?id=' . $oid . '&is_show=1';
-					} else {
-						$data['redirect_url'] = '../orders/order_show_all?order_all_id=' + $order_all_id;
-					}
-
-				} else {
-					$data = array();
-					$data['code'] = 1;
-					$data['text'] = "错误";
-					$data['RETURN_CODE'] = $array['RETURN_CODE'];
-					$data['RETURN_MSG'] = $array['RETURN_MSG'];
-				}
-				$data['has_yupay'] = 0;
-
-				//end
-			} else {
-
-				$fee = $pay_total;
-				$appid = D('Home/Front')->get_config_by_name('wepro_appid');
-
-				$body = $pay_goods_name; //'商品购买';
-
-				$body = mb_substr($body, 0, 32, 'utf-8');
-
-				if (empty($body)) {
-					$body = '商品购买';
-				}
-
-
-				$mch_id = D('Home/Front')->get_config_by_name('wepro_partnerid');
-
-			
-
-				$nonce_str = nonce_str();
-				$notify_url = $shop_domain . '/notify.php';
-
-
-				$openid = $payment['we_openid'];
-				$out_trade_no = $order_all_id . '-' . time();
-
-				//out_trade_no 
-				M('lionfish_comshop_order_all')->where(array('id' => $order_all_id))->save(array('out_trade_no' => $out_trade_no));
-
-
-				$spbill_create_ip = $_SERVER['REMOTE_ADDR'];
-				$total_fee = $fee * 100;
-				$trade_type = 'JSAPI';
-				$pay_key = D('Home/Front')->get_config_by_name('wepro_key');
-
-				$post['appid'] = $appid;
-				$post['body'] = $body;
-				$post['mch_id'] = $mch_id;
-				$post['nonce_str'] = $nonce_str;
-				$post['notify_url'] = $notify_url;
-
-				$post['openid'] = $openid;
-				$post['out_trade_no'] = $out_trade_no;
-				$post['spbill_create_ip'] = $spbill_create_ip;
-				$post['total_fee'] = $total_fee;
-				$post['trade_type'] = $trade_type;
-				$sign = sign($post, $pay_key);
-
-
-				$post_xml = '<xml>
-				   <appid>' . $appid . '</appid>
-				   <body>' . $body . '</body>
-				   <mch_id>' . $mch_id . '</mch_id>
-				   <nonce_str>' . $nonce_str . '</nonce_str>
-				   <notify_url>' . $notify_url . '</notify_url>
-				   <openid>' . $openid . '</openid>
-				   <out_trade_no>' . $out_trade_no . '</out_trade_no>
-				   <spbill_create_ip>' . $spbill_create_ip . '</spbill_create_ip>
-				   <total_fee>' . $total_fee . '</total_fee>
-				   <trade_type>' . $trade_type . '</trade_type>
-				   <sign>' . $sign . '</sign>
-				</xml> ';
-				$url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
-				$xml = http_request($url, $post_xml);
-				$array = xml($xml);
-
-				if ($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS') {
-					D('Home/Pin')->insertNotifyOrder($order['order_id']);
-					$time = time();
-					$tmp = array();
-					$tmp['appId'] = $appid;
-					$tmp['nonceStr'] = $nonce_str;
-					$tmp['package'] = 'prepay_id=' . $array['PREPAY_ID'];
-					$tmp['signType'] = 'MD5';
-					$tmp['timeStamp'] = "$time";
-
-					$prepay_id = (string) $array['PREPAY_ID'];
-
-
-					M('lionfish_comshop_order')->where(array('order_id' => array('in', $order_ids_arr)))->save(array('perpay_id' => $prepay_id));
-
-
-
-					//M('order')->where( array('order_id' => array('in',$order_ids_arr) ) )->save( array('perpay_id' => (string)$array['PREPAY_ID']) );
-					$data = array();
-					$data['code'] = 0;
-					$data['appid'] = $appid;
-					$data['timeStamp'] = "$time";
-					$data['nonceStr'] = $nonce_str;
-					$data['signType'] = 'MD5';
-					$data['package'] = 'prepay_id=' . $array['PREPAY_ID'];
-					$data['paySign'] = sign($tmp, $pay_key);
-					$data['out_trade_no'] = $out_trade_no;
-
-					$data['is_go_orderlist'] = $is_just_1;
-
-					//如果是微信小程序交易组件begin---新支付方法 wx.requestOrderPayment
-					$data['order_info'] = [];
-					$data['isRequestOrderPayment'] = $is_need_scene_check;
-					if ($is_need_scene_check == 1) {
-						$orderPamentResult = D('Seller/MpModifyTradeComponts')->getTradeOrderInfo($oid, $time, $pay_total);
-						//如果是微信小程序交易组件,提供订单信息 end
-						$data['order_info'] = $orderPamentResult['order_info'];
-					}
-
-
-					if ($is_pin == 1) {
-						$data['redirect_url'] = '../groups/group?id=' . $oid . '&is_show=1';
-					} else {
-						$data['redirect_url'] = '../orders/order_show_all?order_all_id=' + $order_all_id;
-					}
-
-				} else {
-					$data = array();
-					$data['code'] = 1;
-					$data['text'] = "错误";
-					$data['RETURN_CODE'] = $array['RETURN_CODE'];
-					$data['RETURN_MSG'] = $array['RETURN_MSG'];
-				}
-				$data['has_yupay'] = 0;
-			}
-
-			if ($is_pin == 1) {
-				$data['order_id'] = $oid;
-				$data['order_all_id'] = $order_all_id;
-			} else {
-				$data['order_id'] = $oid;
-				$data['order_all_id'] = $order_all_id;
-			}
-			$data['is_go_orderlist'] = $is_just_1;
-
-			$data['is_spike'] = $is_spike;
-			echo json_encode($data);
-			die();
-		} else {
-			echo json_encode(array('code' => 1, 'order_all_id' => $order_all_id));
-			die();
-		}
-
-	}
-
-	function requestAsHttpPOST($data, $service_url)
-	{
-		$HTTP_TIME_OUT = "20";
-		ksort(array_filter($data)); //删除数组中的空值并排序
-		$post_data = http_build_query($data);
-
-		$options = array(
-			'http' => array(
-				'method' => 'POST',
-				'header' => 'Content-type:application/x-www-form-urlencoded;charset=MD5',
-				'content' => $post_data,
-				'timeout' => $HTTP_TIME_OUT * 1000 //超时时间,*1000将毫秒变为秒(单位:s)
-			)
-		);
-		$context = stream_context_create($options);
-		$result = file_get_contents($service_url, false, $context);
-		return $result;
-	}
-
-
-	/**
-		   微信充值
-	   **/
-	public function wxcharge()
-	{
-		$_GPC = I('request.');
-
-		$token = $_GPC['token'];
-		$pay_method=$_GPC['pay_method']=='fypay'?$_GPC['pay_method']:"";
-
-		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where(array('token' => $token))->find();
-
-		$member_id = $weprogram_token['member_id'];
-
-		if (empty($member_id)) {
-			echo json_encode(array('code' => 1, 'msg' => '未登录'));
-			die();
-		}
-
-		$money = $_GPC['money'];
-
-		$rech_id = isset($_GPC['rech_id']) && $_GPC['rech_id'] > 0 ? $_GPC['rech_id'] : 0;
-
-		$member_info = M('lionfish_comshop_member')->field('we_openid')->where(array('member_id' => $member_id))->find();
-
-		$give_money = 0;
-
-		if ($rech_id > 0) {
-			$rech_info = M('lionfish_comshop_chargetype')->where(array('id' => $rech_id))->find();
-
-			if (!empty($rech_info)) {
-				$give_money = $rech_info['send_money'];
-			}
-
-			$money = $rech_info['money'];
-		} else {
-			$recharge_get_money = D('Home/Front')->get_config_by_name('recharge_get_money');
-
-			if (isset($recharge_get_money) && $recharge_get_money == 1) {
-				$rech_info = M('lionfish_comshop_chargetype')->where("money <= " . $money)->order('money desc')->limit(1)->find();
-
-				if (!empty($rech_info)) {
-					$give_money = $rech_info['send_money'];
-				}
-			}
-
-		}
-
-
-
-		$member_charge_flow_data = array();
-		$member_charge_flow_data['member_id'] = $member_id;
-		$member_charge_flow_data['money'] = $money;
-		$member_charge_flow_data['state'] = 0;
-		$member_charge_flow_data['give_money'] = $give_money;
-		$member_charge_flow_data['charge_time'] = 0;
-		$member_charge_flow_data['remark'] = '会员前台微信充值';
-		$member_charge_flow_data['add_time'] = time();
-
-		$order_id = M('lionfish_comshop_member_charge_flow')->add($member_charge_flow_data);
-
-
-		$shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
-
-
-
-
-
-		$fee = $money;
-		$appid = D('Home/Front')->get_config_by_name('wepro_appid');
-		$body = '会员充值';
-		$mch_id = D('Home/Front')->get_config_by_name('wepro_partnerid');
-		$nonce_str = nonce_str();
-		$notify_url = $shop_domain . '/notify.php';
-		$openid = $member_info['we_openid'];
-		$out_trade_no = $order_id . '-' . time() . '-charge-' . $member_id;
-		$spbill_create_ip = $_SERVER['REMOTE_ADDR'];
-		$total_fee = $fee * 100;
-
-		$is_open_yinpay = D('Home/Front')->get_config_by_name('is_open_yinpay');
-		if($pay_method=='fypay'){
-
-			$lib_path = dirname(dirname(dirname(__FILE__))) . '/Lib/';
-			require_once $lib_path . "/Weixin/Wxfy.class.php";
-			$wxfy = new \Wxfy();
-			
-			$notify_url = $shop_domain . '/notify.php?type=fyfyfy';
-	
-
-			$nonce_str = nonce_str();
-			$wxfydata=array();
-			$wxfydata['debug'] = false;
-			$wxfydata['filepath'] = $lib_path . 'Weixin/cert/';
-			$prefix = 1450;
-			$wxfydata['mchnt_order_no'] = $prefix . $out_trade_no; //商户订单号, 商户系统内部的订单号(5 到 30 个字符、 只能包含字母数字,区分大小写)
-			$wxfydata['random_str'] = $nonce_str;
-			$wxfydata['goods_des'] = base64_encode($body);
-			$wxfydata['term_ip'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
-			$wxfydata['order_amt'] = $total_fee;
-			$wxfydata['notify_url'] = $notify_url;
-			$wxfydata['sub_openid'] = $member_info['we_openid'];
-			$wxfydata['sub_appid'] = $appid;
-			
-			$resfult = $wxfy->createOrder($wxfydata);
-//			$fy_res = json_decode($resfult, 1);
-			
-		
-			if (false) {
-				$json = array();
-
-				$json['code'] = 2;
-				$json['msg'] = 'error:'.$fy_res['result_msg'];
-				echo json_encode($json);
-				die();
-			}
-
-		//	$prepay_id =(string)$fy_res['session_id'];
-
-			$data = array();
-			$data['code'] = 0;
-//			$data['appid'] = $fy_res['sdk_appid'];
-//			$data['timeStamp'] = $fy_res['sdk_timestamp'];
-//			$data['nonceStr'] = $fy_res['sdk_noncestr'];
-//			$data['signType'] = $fy_res['sdk_signtype'];
-//			$data['package'] = 'prepay_id=' .$prepay_id;
-//			$data['paySign'] = $fy_res['sdk_paysign'];
-			$data['out_trade_no'] = $out_trade_no;
-            $data['xml'] = $resfult;
-			$data['pay_method']='fypay';
-			$data['total_fee'] =$total_fee;
-//			M('lionfish_comshop_member_charge_flow')->where(array('id' => $order_id))->save(array('formid' => $prepay_id));
-			$data['redirect_url'] = '../dan/me';
-			echo json_encode($data);
-			die();
-
-		}else if (isset($is_open_yinpay) && $is_open_yinpay == 3) {
-
-			$trade_type = 'JSAPI';
-			$pay_key = D('Home/Front')->get_config_by_name('wepro_key');
-			$post = array();
-			$post['appid'] = D('Home/Front')->get_config_by_name('wepro_fuwu_appid'); // 'wx7c38e2f177e0af59';
-			$post['body'] = $body;
-			$post['mch_id'] = D('Home/Front')->get_config_by_name('wepro_fuwu_partnerid'); //'1562705521';
-			$post['nonce_str'] = $nonce_str;
-			$post['notify_url'] = $notify_url;
-			//$post['openid'] = $openid;
-			$post['out_trade_no'] = $out_trade_no;
-			$post['spbill_create_ip'] = $spbill_create_ip;
-			$post['sub_appid'] = $appid;
-			$post['sub_mch_id'] = D('Home/Front')->get_config_by_name('wepro_sub_mch_id');
-			$post['sub_openid'] = $openid;
-			$post['total_fee'] = $total_fee;
-			$post['trade_type'] = $trade_type;
-			$sign = sign($post, $pay_key);
-
-
-			$post_xml = '<xml>
-				   <appid>' . $post['appid'] . '</appid>
-				   <body>' . $body . '</body>
-				   <mch_id>' . $post['mch_id'] . '</mch_id>
-				   <nonce_str>' . $nonce_str . '</nonce_str>
-				   <notify_url>' . $notify_url . '</notify_url>
-				   
-				   <out_trade_no>' . $out_trade_no . '</out_trade_no>
-				   <spbill_create_ip>' . $spbill_create_ip . '</spbill_create_ip>
-				   <sub_appid>' . $post['sub_appid'] . '</sub_appid>
-				   <sub_mch_id>' . $post['sub_mch_id'] . '</sub_mch_id>
-				   <sub_openid>' . $openid . '</sub_openid>
-				   <total_fee>' . $total_fee . '</total_fee>
-				   <trade_type>' . $trade_type . '</trade_type>
-				   <sign>' . $sign . '</sign>
-				</xml> ';
-			$url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
-			$xml = http_request($url, $post_xml);
-			$array = xml($xml);
-
-			//end
-		} else {
-
-			$trade_type = 'JSAPI';
-			$pay_key = D('Home/Front')->get_config_by_name('wepro_key');
-
-			$post = array();
-
-			$post['appid'] = $appid;
-			$post['body'] = $body;
-			$post['mch_id'] = $mch_id;
-			$post['nonce_str'] = $nonce_str;
-			$post['notify_url'] = $notify_url;
-			$post['openid'] = $openid;
-			$post['out_trade_no'] = $out_trade_no;
-			$post['spbill_create_ip'] = $spbill_create_ip;
-			$post['total_fee'] = $total_fee;
-			$post['trade_type'] = $trade_type;
-
-			$sign = sign($post, $pay_key);
-
-			//sign()
-			$post_xml = '<xml>
-				   <appid>' . $appid . '</appid>
-				   <body>' . $body . '</body>
-				   <mch_id>' . $mch_id . '</mch_id>
-				   <nonce_str>' . $nonce_str . '</nonce_str>
-				   <notify_url>' . $notify_url . '</notify_url>
-				   <openid>' . $openid . '</openid>
-				   <out_trade_no>' . $out_trade_no . '</out_trade_no>
-				   <spbill_create_ip>' . $spbill_create_ip . '</spbill_create_ip>
-				   <total_fee>' . $total_fee . '</total_fee>
-				   <trade_type>' . $trade_type . '</trade_type>
-				   <sign>' . $sign . '</sign>
-				</xml> ';
-			$url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
-			$xml = http_request($url, $post_xml);
-			$array = xml($xml);
-		}
-
-
-
-
-		if ($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS') {
-			$time = time();
-			$tmp = array();
-			$tmp['appId'] = $appid;
-			$tmp['nonceStr'] = $nonce_str;
-			$tmp['package'] = 'prepay_id=' . $array['PREPAY_ID'];
-			$tmp['signType'] = 'MD5';
-			$tmp['timeStamp'] = "$time";
-
-			M('lionfish_comshop_member_charge_flow')->where(array('id' => $order_id))->save(array('formid' => $array['PREPAY_ID']));
-
-			$data['code'] = 0;
-			$data['timeStamp'] = "$time";
-			$data['nonceStr'] = $nonce_str;
-			$data['signType'] = 'MD5';
-			$data['package'] = 'prepay_id=' . $array['PREPAY_ID'];
-			$data['paySign'] = sign($tmp, $pay_key);
-			$data['out_trade_no'] = $out_trade_no;
-
-			$data['redirect_url'] = '../dan/me';
-
-		} else {
-			$data['code'] = 1;
-			$data['text'] = "错误";
-			$data['RETURN_CODE'] = $array['RETURN_CODE'];
-			$data['RETURN_MSG'] = $array['RETURN_MSG'];
-		}
-
-
-
-		echo json_encode($data);
-		die();
-
-	}
-
-
-	public function wxpay()
-	{
-		$gpc = I('request.');
-
-		$token = $gpc['token'];
-		$order_id = $gpc['order_id'];
-		$pay_method=$gpc['pay_method']=='fypay'?$gpc['pay_method']:"";
-		$scene = $gpc['scene'];
-		$is_need_scene_check = 0;
-
-		if (!empty($scene)) {
-			$is_need_scene_check = D('Seller/MpModifyTradeComponts')->sceneCheck($scene);
-		}
-
-		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where(array('token' => $token))->find();
-
-
-		$member_id = $weprogram_token['member_id'];
-
-
-		if (empty($member_id)) {
-			echo json_encode(array('code' => 1, 'msg' => '未登录'));
-			die();
-		}
-
-
-		$member_info = M('lionfish_comshop_member')->field('we_openid')->where(array('member_id' => $member_id))->find();
-
-
-		$order = M('lionfish_comshop_order')->where(array('order_id' => $order_id))->find();
-
-
-		//order_status_id
-
-		if ($order['order_status_id'] != 3 && $order['order_status_id'] != 15) {
-			$json = array();
-
-			$json['msg'] = '商品已下架!';
-			$json['code'] = 2;
-			if ($order['order_status_id'] == 1) {
-				$json['msg'] = '订单已付款,请勿重新付款!';
-			} else if ($order['order_status_id'] == 5) {
-				$json['msg'] = '订单已取消,请重新选择商品下单!';
-			}
-			echo json_encode($json);
-			die();
-		}
-
-
-
-		//检测商品是否下架 begin
-		$sql = "select name,quantity,rela_goodsoption_valueid,goods_id from " . C('DB_PREFIX') . "lionfish_comshop_order_goods  
-					where order_id={$order_id} ";
-
-		$order_goods_list = M()->query($sql);
-		$goodsname="";
-		foreach ($order_goods_list as $tp_val) {
-			$tp_gd_info = M('lionfish_comshop_goods')->field('grounding')->where(array('id' => $tp_val['goods_id']))->find();
-
-			if (empty($tp_gd_info) || $tp_gd_info['grounding'] != 1) {
-				$json['code'] = 2;
-
-				$json['msg'] = '商品已下架!';
-
-				echo json_encode($json);
-				die();
-			}
-			$goodsname.=$tp_val['name'];
-		}
-
-		//检测商品是否下架end   
-		//检测是否预售商品。预售商品不需要检测二次支付问题
-		$presale_info = [];
-		$presale_result = D('Home/PresaleGoods')->getOrderPresaleInfo($order_id);
-		if ($presale_result['code'] == 0) {
-			$presale_info = $presale_result['data'];
-		}
-		//检测是否已经支付过了begin
-
-		$order_relate_info = M('lionfish_comshop_order_relate')->where(array('order_id' => $order_id))->order('id desc')->find();
-
-		if (!empty($order_relate_info) && $order_relate_info['order_all_id'] > 0 && empty($presale_info)) {
-			
-			$order_all_info = M('lionfish_comshop_order_all')->where(array('id' => $order_relate_info['order_all_id']))->find();
-				
-			if (!empty($order_all_info) && !empty($order_all_info['out_trade_no'])) {
-					
-				$out_trade_no = $order_all_info['out_trade_no'];
-
-				$appid = D('Home/Front')->get_config_by_name('wepro_appid');
-				$mch_id = D('Home/Front')->get_config_by_name('wepro_partnerid');
-				$nonce_str = nonce_str();
-
-				$pay_key = D('Home/Front')->get_config_by_name('wepro_key');
-
-
-				$post = array();
-				
-				if($pay_method=='fypay'){
-				
-					//富友支付,写下去了
-
-
-				}else{
-					//主要是校验是否重复支付
-					$post['appid'] = $appid;
-					$post['mch_id'] = $mch_id;
-					$post['nonce_str'] = $nonce_str;
-					$post['out_trade_no'] = $out_trade_no;
-
-					$sign = sign($post, $pay_key);
-
-					$post_xml = '<xml>
-								<appid>' . $appid . '</appid>
-								<mch_id>' . $mch_id . '</mch_id>
-								<nonce_str>' . $nonce_str . '</nonce_str>
-								<out_trade_no>' . $out_trade_no . '</out_trade_no>
-								<sign>' . $sign . '</sign>
-								</xml>';
-
-					$url = "https://api.mch.weixin.qq.com/pay/orderquery";
-
-					$result = http_request($url, $post_xml);
-
-					$array = xml($result);
-
-					if ($array['RETURN_CODE'] == 'SUCCESS' && $array['RETURN_MSG'] == 'OK') {
-						if ($array['TRADE_STATE'] == 'SUCCESS') {
-							$json = array();
-
-							$json['msg'] = '商品已下架!';
-							$json['code'] = 2;
-							$json['msg'] = '订单已付款,请勿重新付款,请刷新页面!';
-							echo json_encode($json);
-							die();
-						}
-					}
-				}
-			}
-		}
-
-		//检测是否已经支付过了end  
-
-		//支付才减库存,才需要判断
-		$kucun_method = D('Home/Front')->get_config_by_name('kucun_method');
-
-		if (empty($kucun_method)) {
-			$kucun_method = 0;
-		}
-
-		if ($kucun_method == 1 && (empty($presale_info) || $presale_info['state'] != 1)) {
-			/*** 检测商品库存begin  **/
-
-			//goods_id
-			foreach ($order_goods_list as $val) {
-				$quantity = $val['quantity'];
-
-				$goods_id = $val['goods_id'];
-
-				$can_buy_count = D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
-
-				$goods_description = D('Home/Front')->get_goods_common_field($goods_id, 'total_limit_count');
-
-				if ($can_buy_count == -1) {
-					$json['code'] = 2;
-
-					$json['msg'] = '您还能购买' . $goods_description['total_limit_count'] . '个';
-
-					echo json_encode($json);
-					die();
-				} else if ($can_buy_count > 0 && $quantity > $can_buy_count) {
-					$json['code'] = 2;
-					$json['msg'] = '您还能购买' . $can_buy_count . '份';
-					echo json_encode($json);
-					die();
-				}
-				//rela_goodsoption_valueid
-				if (!empty($val['rela_goodsoption_valueid'])) {
-					$mul_opt_arr = array();
-
-					//ims_ 
-
-					$goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->where(array('goods_id' => $goods_id, 'option_item_ids' => $val['rela_goodsoption_valueid']))->find();
-
-
-					if (!empty($goods_option_mult_value)) {
-						if ($goods_option_mult_value['stock'] < $quantity) {
-							$json['code'] = 2;
-							$json['msg'] = '商品数量不足,剩余' . $goods_option_mult_value['stock'] . '个!!';
-							echo json_encode($json);
-							die();
-						}
-					}
-				}
-
-			}
-			/*** 检测商品库存end **/
-		}
-
-		$pin_order = array();
-		if (!empty($pin_order)) {
-			/**
-					 $pin_model =  load_model_class('pin');
-					 $is_pin_over = $pin_model->getNowPinState($pin_order['pin_id']);
-					 if($is_pin_over != 0)
-					 {
-						  pdo_query("delete from ".tablename('lionfish_comshop_pin_order')." where order_id = {$order_id} ");
-						  
-						  pdo_query("delete from ".tablename('lionfish_comshop_pin')." where pin_id = ".$pin_order['pin_id']." and order_id = ".$order_id);
-						  
-						 $order_goods_info = pdo_fetch("select goods_id from ".tablename('lionfish_comshop_order_goods')." where uniacid=:uniacid and order_id=:order_id ", array(':order_id' => $order_id,':uniacid' => $_W['uniacid']));
-						 
-						 //新开团
-						 
-						 $pin_id = $pin_model->openNewTuan($order_id,$order_goods_info['goods_id'],$member_id);
-						 //插入拼团订单
-						 $pin_model->insertTuanOrder($pin_id,$order_id);
-							
-					 }
-					 **/
-		}
-
-
-		//单独支付一个店铺的订单
-		//M('lionfish_comshop_order_relate')->where( array('order_id' => $order_id) )->delete();
-
-		$order_all_data = array();
-		$order_all_data['member_id'] = $member_id;
-		$order_all_data['order_num_alias'] = build_order_no($member_id);
-		$order_all_data['transaction_id'] = '';
-		$order_all_data['order_status_id'] = 3;
-		$order_all_data['is_pin'] = $order['is_pin'];
-		$order_all_data['paytime'] = 0;
-		$order_all_data['total_money'] = $order['total'] + $order['shipping_fare'] - $order['voucher_credit'] - $order['fullreduction_money'];
-		$order_all_data['addtime'] = time();
-
-		$order_all_id = M('lionfish_comshop_order_all')->add($order_all_data);
-
-		$order_relate_data = array();
-		$order_relate_data['order_all_id'] = $order_all_id;
-		$order_relate_data['order_id'] = $order_id;
-		$order_relate_data['addtime'] = time();
-
-		M('lionfish_comshop_order_relate')->add($order_relate_data);
-
-		if ($order['delivery'] == 'pickup') {
-			$fee = $order['total'] + $order['shipping_fare'] - $order['voucher_credit'] - $order['fullreduction_money'] - $order['score_for_money'] - $order['fare_shipping_free'];
-		} else if ($order['delivery'] == 'localtown_delivery') {
-			$fee = $order['total'] + $order['packing_fare'] + $order['shipping_fare'] - $order['voucher_credit'] - $order['fullreduction_money'] - $order['score_for_money'] + $order['localtown_add_shipping_fare'] - $order['fare_shipping_free'];
-		} else {
-			$fee = $order['total'] + $order['shipping_fare'] - $order['voucher_credit'] - $order['fullreduction_money'] - $order['score_for_money'] - $order['fare_shipping_free'];
-		}
-
-		//如果是预售 begin
-
-		if (!empty($presale_info)) {
-			if ($presale_info['state'] == 0) {
-				//首次支付,
-				$fee = $presale_info['presale_ding_money'];
-			} else if ($presale_info['state'] == 1) {
-				//第二次支付
-				if (!empty($presale_info['presale_deduction_money']) && false) {
-					$fee = $fee - $presale_info['presale_deduction_money'];
-				} else {
-					$fee = $fee - $presale_info['presale_ding_money'];
-				}
-			}
-		}
-		//end
-
-
-		$fee = round($fee, 2);
-
-
-		$appid = D('Home/Front')->get_config_by_name('wepro_appid');
-
-
-		$body = $pay_goods_name; //'商品购买';
-
-		$body = mb_substr($body, 0, 32, 'utf-8');
-
-		if (empty($body)) {
-			$body = '商品购买';
-		}
-
-
-		$mch_id = D('Home/Front')->get_config_by_name('wepro_partnerid');
-		$nonce_str = nonce_str();
-
-		$shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
-
-		$notify_url = $shop_domain . '/notify.php';
-
-		$openid = $member_info['we_openid'];
-		
-		$spbill_create_ip = $_SERVER['REMOTE_ADDR'];
-		$total_fee = $fee * 100;
-		$trade_type = 'JSAPI';
-		$pay_key = D('Home/Front')->get_config_by_name('wepro_key');
-		$out_trade_no = $order_all_id . '-' . time();
-
-		$is_open_yinpay = D('Home/Front')->get_config_by_name('is_open_yinpay');
-		
-		$appid = D('Home/Front')->get_config_by_name('wepro_appid');
-		//begin
-
-		if($pay_method=='fypay'){
-		//富友支付
-			$shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
-			$lib_path = dirname(dirname(dirname(__FILE__))) . '/Lib/';
-			require_once $lib_path . "/Weixin/Wxfy.class.php";
-			$wxfy = new \Wxfy();
-			
-			$notify_url = $shop_domain . '/notify.php?type=fyfyfy';
-			$body = $goodsname; //'商品购买';
-	
-			
-			if (empty($body) || mb_strlen($body)>30) {
-				$body = '购物车商品合并支付';
-			}
-		
-			// $body=iconv('GB2312', 'UTF-8', $body);
-
-			//富友一个订单号只能拉起一次支付,所以这里要改
-			M('lionfish_comshop_order_all')->where(array('id' => $order_all_id))->save(array('out_trade_no' => $out_trade_no));
-			$nonce_str = nonce_str();
-			$wxfydata=array();
-			$wxfydata['debug'] = false;
-			$wxfydata['filepath'] = $lib_path . 'Weixin/cert/';
-			$prefix = 1450;
-			$wxfydata['mchnt_order_no'] = $prefix . $out_trade_no; //商户订单号, 商户系统内部的订单号(5 到 30 个字符、 只能包含字母数字,区分大小写)
-			$wxfydata['random_str'] = $nonce_str;
-			$wxfydata['goods_des'] = $body;
-			$wxfydata['term_ip'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
-			$wxfydata['order_amt'] = $total_fee;
-			$wxfydata['notify_url'] = $notify_url;
-			$wxfydata['sub_openid'] = $member_info['we_openid'];
-			$wxfydata['sub_appid'] = $appid;
-			
-			$resfult = $wxfy->createOrder($wxfydata);
-		//	$fy_res = json_decode($resfult, 1);
-			
-		
-			if (false) {
-				$json = array();
-
-				$json['code'] = 2;
-				$json['msg'] = 'error:'.$fy_res['result_msg'];
-				echo json_encode($json);
-				die();
-			}
-
-			//$prepay_id =(string)$fy_res['session_id'];
-					
-
-			//M('lionfish_comshop_order')->where(array('order_id' => $order_id))->save(array('perpay_id' => $prepay_id));
-
-
-
-			$data = array();
-			$data['code'] = 0;
-		//	$data['appid'] = $fy_res['sdk_appid'];
-		//	$data['timeStamp'] = $fy_res['sdk_timestamp'];
-		//	$data['nonceStr'] = $fy_res['sdk_noncestr'];
-			//$data['signType'] = $fy_res['sdk_signtype'];
-		//	$data['package'] = 'prepay_id=' .$prepay_id;
-		//	$data['paySign'] = $fy_res['sdk_paysign'];
-			$data['out_trade_no'] = $out_trade_no;
-			$data['xml'] = $resfult;
-			$data['total_fee'] = $total_fee;
-			$data['pay_method'] = 'fypay';
-			if ($order['is_pin'] == 1) {
-				$data['redirect_url'] = '../groups/group?id=' . $order_id . '&is_show=1';
-			} else {
-				$data['redirect_url'] = '../orders/order?id=' + $order_id;
-			}
-			echo json_encode($data);
-			die();
-		}
-		elseif (isset($is_open_yinpay) && $is_open_yinpay == 3) {
-			
-			$pay_key = D('Home/Front')->get_config_by_name('wepro_key');
-
-			$body = '商品购买';
-
-			$post = array();
-
-			$post['appid'] =D('Home/Front')->get_config_by_name('wepro_fuwu_appid');
-			$post['body'] = $body;
-			$post['mch_id'] = D('Home/Front')->get_config_by_name('wepro_fuwu_partnerid');
-			$post['nonce_str'] = $nonce_str;
-			$post['notify_url'] = $notify_url;
-			//$post['openid'] = $openid;
-			$post['out_trade_no'] = $out_trade_no;
-			$post['spbill_create_ip'] = $spbill_create_ip;
-			$post['sub_appid'] = D('Home/Front')->get_config_by_name('wepro_appid');
-			$post['sub_mch_id'] = D('Home/Front')->get_config_by_name('wepro_sub_mch_id');
-			$post['sub_openid'] = $openid;
-
-			$post['total_fee'] = $total_fee;
-			$post['trade_type'] = $trade_type;
-			$sign = sign($post, $pay_key);
-
-			$post_xml = '<xml>
-				   <appid>' . $post['appid'] . '</appid>
-				   <body>' . $body . '</body>
-				   <mch_id>' . $post['mch_id'] . '</mch_id>
-				   <nonce_str>' . $nonce_str . '</nonce_str>
-				   <notify_url>' . $notify_url . '</notify_url>
-				   
-				   <out_trade_no>' . $out_trade_no . '</out_trade_no>
-				   <spbill_create_ip>' . $spbill_create_ip . '</spbill_create_ip>
-				   <sub_appid>' . $post['sub_appid'] . '</sub_appid>
-				   <sub_mch_id>' . $post['sub_mch_id'] . '</sub_mch_id>
-				   <sub_openid>' . $openid . '</sub_openid>
-				   <total_fee>' . $total_fee . '</total_fee>
-				   <trade_type>' . $trade_type . '</trade_type>
-				   <sign>' . $sign . '</sign>
-				</xml>';
-
-
-			$url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
-			$xml = http_request($url, $post_xml);
-			$array = xml($xml);
-
-			if ($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS') {
-				$time = time();
-				$tmp = array();
-				$tmp['appId'] = $appid;
-				$tmp['nonceStr'] = $nonce_str;
-				$tmp['package'] = 'prepay_id=' . $array['PREPAY_ID'];
-				$tmp['signType'] = 'MD5';
-				$tmp['timeStamp'] = "$time";
-
-				$prepay_id = (string) $array['PREPAY_ID'];
-
-				M('lionfish_comshop_order')->where(array('order_id' => $order_id))->save(array('perpay_id' => $prepay_id));
-
-
-				$data['code'] = 0;
-				$data['timeStamp'] = "$time";
-				$data['nonceStr'] = $nonce_str;
-				$data['signType'] = 'MD5';
-				$data['package'] = 'prepay_id=' . $array['PREPAY_ID'];
-				$data['paySign'] = sign($tmp, $pay_key);
-				$data['out_trade_no'] = $out_trade_no;
-				$data['is_pin'] = $order['is_pin'];
-
-				if ($order['is_pin'] == 1) {
-					$data['redirect_url'] = '../groups/group?id=' . $order_id . '&is_show=1';
-				} else {
-					$data['redirect_url'] = '../orders/order?id=' + $order_id;
-				}
-
-			} else {
-				$data['code'] = 1;
-				$data['text'] = "错误";
-				$data['RETURN_CODE'] = $array['RETURN_CODE'];
-				$data['RETURN_MSG'] = $array['RETURN_MSG'];
-			}
-
-
-			echo json_encode($data);
-			die();
-		}else{
-			$json = array();
-
-				$json['code'] = 2;
-				$json['msg'] = '没有支付方式';
-				echo json_encode($json);
-				die();
-		}
-
-		//end
-
-		$post = array();
-		$post['appid'] = $appid;
-		$post['body'] = $body;
-		$post['mch_id'] = $mch_id;
-		$post['nonce_str'] = $nonce_str;
-		$post['notify_url'] = $notify_url;
-		$post['openid'] = $openid;
-		$post['out_trade_no'] = $out_trade_no;
-		$post['spbill_create_ip'] = $spbill_create_ip;
-		$post['total_fee'] = $total_fee;
-		$post['trade_type'] = $trade_type;
-		$sign = sign($post, $pay_key);
-
-
-		$post_xml = '<xml>
-			   <appid>' . $appid . '</appid>
-			   <body>' . $body . '</body>
-			   <mch_id>' . $mch_id . '</mch_id>
-			   <nonce_str>' . $nonce_str . '</nonce_str>
-			   <notify_url>' . $notify_url . '</notify_url>
-			   <openid>' . $openid . '</openid>
-			   <out_trade_no>' . $out_trade_no . '</out_trade_no>
-			   <spbill_create_ip>' . $spbill_create_ip . '</spbill_create_ip>
-			   <total_fee>' . $total_fee . '</total_fee>
-			   <trade_type>' . $trade_type . '</trade_type>
-			   <sign>' . $sign . '</sign>
-			</xml> ';
-		$url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
-		$xml = http_request($url, $post_xml);
-		$array = xml($xml);
-		if ($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS') {
-			$time = time();
-			$tmp = array();
-			$tmp['appId'] = $appid;
-			$tmp['nonceStr'] = $nonce_str;
-			$tmp['package'] = 'prepay_id=' . $array['PREPAY_ID'];
-			$tmp['signType'] = 'MD5';
-			$tmp['timeStamp'] = "$time";
-
-			$prepay_id = (string) $array['PREPAY_ID'];
-
-			M('lionfish_comshop_order')->where(array('order_id' => $order_id))->save(array('perpay_id' => $prepay_id));
-
-
-			$data['code'] = 0;
-			$data['timeStamp'] = "$time";
-			$data['nonceStr'] = $nonce_str;
-			$data['signType'] = 'MD5';
-			$data['package'] = 'prepay_id=' . $array['PREPAY_ID'];
-			$data['paySign'] = sign($tmp, $pay_key);
-			$data['out_trade_no'] = $out_trade_no;
-			$data['is_pin'] = $order['is_pin'];
-
-			//如果是微信小程序交易组件begin---新支付方法 wx.requestOrderPayment
-			$data['order_info'] = [];
-			$data['isRequestOrderPayment'] = $is_need_scene_check;
-			if ($is_need_scene_check == 1) {
-				$orderPamentResult = D('Seller/MpModifyTradeComponts')->getTradeOrderInfo($order_id, $time, $fee);
-				//如果是微信小程序交易组件,提供订单信息 end
-				$data['order_info'] = $orderPamentResult['order_info'];
-			}
-
-			if ($order['is_pin'] == 1) {
-				$data['redirect_url'] = '../groups/group?id=' . $order_id . '&is_show=1';
-			} else {
-				$data['redirect_url'] = '../orders/order?id=' + $order_id;
-			}
-
-		} else {
-			$data['code'] = 1;
-			$data['text'] = "错误";
-			$data['RETURN_CODE'] = $array['RETURN_CODE'];
-			$data['RETURN_MSG'] = $array['RETURN_MSG'];
-		}
-
-
-		echo json_encode($data);
-		die();
-	}
-
-	/**
-	 * 获取购物车总数
-	 */
-	public function count()
-	{
-
-		$gpc = I('request.');
-
-		$data = array();
-		$token = $gpc['token'];
-		$community_id = $gpc['community_id'];
-
-		$cart = D('Home/Car');
-		$total = $cart->count_goodscar($token, $community_id);
-
-		$data['code'] = 0;
-		$data['data'] = $total;
-		echo json_encode($data);
-		die();
-
-	}
-
+<?php
+/**
+ * lionfish 商城系统
+ *
+ * ==========================================================================
+ * @link      http://www.liofis.com/
+ * @copyright Copyright (c) 2015 liofis.com. 
+ * @license   http://www.liofis.com/license.html License
+ * ==========================================================================
+ *
+ * @author    fish
+ *
+ */
+
+class CarController extends \Home\Controller\CommonController
+{
+	
+	//--------begin
+	
+	
+	public function reduce_car_goods()
+	{
+		$_GPC = I('request.');
+		
+		$data = array();
+		$data['goods_id'] = $_GPC['goods_id'];
+		$data['community_id'] = $_GPC['community_id'];
+		$data['quantity'] = $_GPC['quantity'];
+		$data['sku_str'] = $_GPC['sku_str'];
+		if($_GPC['sku_str'] == 'undefined')
+		{
+			$_GPC['sku_str'] = '';
+			$data['sku_str']  = '';
+		}
+		
+		
+		$data['buy_type'] = $_GPC['buy_type'];
+		$data['pin_id'] = $_GPC['pin_id'];
+		$data['is_just_addcar'] = $_GPC['is_just_addcar'];
+		
+		$data['soli_id'] = isset($_GPC['soli_id']) ? intval($_GPC['soli_id']) : '';
+		
+		
+		if( !isset($data['buy_type']) || empty($data['buy_type']) )
+		{
+		  $data['buy_type'] = 'dan';
+		}
+		$token = $_GPC['token'];
+		
+		
+		  
+		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
+		
+		$member_id = $weprogram_token['member_id'];
+		
+		
+		$is_just_addcar = empty($data['is_just_addcar']) ? 0: 1;
+		
+		$goods_id = $data['goods_id'];
+		if( empty($member_id))
+		{			
+		    $result = array('code' =>4);
+		    echo json_encode($result);
+		    die();
+		}
+		
+		if (isset($data['goods_id'])) {
+			$goods_id = $data['goods_id'];
+		} else {
+			$goods_id = 0;
+		}
+		
+		$goods_param = array();
+		
+		$product = M('lionfish_comshop_goods')->where( array('id' => $goods_id ) )->find();
+		
+		if( $product['grounding'] != 1)
+		{
+			$json['code'] =6;
+			$json['msg']='商品已下架!';
+			echo json_encode($json);
+			die();
+		}
+
+		$is_community = D('Seller/Communityhead')->is_community($data['community_id']);
+		if( !$is_community )
+		{
+			$json['code'] =6;
+			$json['msg']='该小区已经不存在!';
+			echo json_encode($json);
+			die();
+		}
+		
+		//6 
+		if($is_just_addcar == 1)
+		{
+			if($product['pick_just'] > 0)
+			{
+				$json['code'] =6;
+				$json['msg']='自提商品,请立即购买';
+				echo json_encode($json);
+				die();
+			}
+		}
+		
+		//商品存在
+		if($product){
+			
+			$cart= D('Home/Car');
+			
+			if (isset($data['quantity'])) {
+				$quantity = $data['quantity'];
+			} else {
+				$quantity = 1;
+			}
+					
+			$option = array();
+			
+			if( !empty($data['sku_str'])){
+			    $option = explode('_', $data['sku_str']);
+			}
+			
+            $cart_goods_quantity = $cart->get_wecart_goods($goods_id,$data['sku_str'],$data['community_id'] ,$token,$data['soli_id'] );
+			
+			
+			$key = (int)$goods_id . ':'.$data['community_id'].':';
+			
+			
+			if( !empty($data['soli_id']) )
+			{
+				$key .= $data['soli_id'].':';
+			}
+       
+			if ($data['sku_str']) {
+				$key.= base64_encode($data['sku_str']) . ':';
+			} else {
+			   $key.= ':';//xx
+			}
+			
+			$car_prefix = 'cart.';
+			
+			if( !empty($data['buy_type']) && $data['buy_type'] == 'soitaire' )
+			{
+				$key = 'soitairecart.' . $key;
+				$car_prefix = 'soitairecart.';
+			}else{
+				$key = 'cart.' . $key;
+			}
+			
+		
+			
+			
+			$json=array('code' =>0);
+			
+			
+			$car_info = M('lionfish_comshop_car')->where( array('carkey' => $key,'community_id' => $data['community_id'] ) )->find();
+			
+			$tmp_format_data = unserialize($car_info['format_data']);
+			
+			//$tmp_format_data['quantity']
+			if($tmp_format_data['quantity'] == 1 || $tmp_format_data['quantity'] <= $quantity)
+			{
+				$all_cart = M('lionfish_comshop_car')->where( array('carkey' => $key ,'community_id' =>$data['community_id'],'token' => $token  ) )->delete();
+				
+			}else{
+				
+				$tmp_format_data['quantity'] = $tmp_format_data['quantity'] - $quantity;
+				
+				M('lionfish_comshop_car')->where( array('id' => $car_info['id'], 'community_id' => $data['community_id'] ) )->save( array('format_data' => serialize($tmp_format_data) ) );
+					
+			}
+				
+			$cart= D('Home/Car');
+			$total=$cart->count_goodscar($token, $data['community_id']);
+		
+		
+			$json ['code']  = 1;
+			if( $data['buy_type'] != 'dan' )
+			{
+			    $json ['code']  = 2;
+			}
+			
+			
+			$cart_goods_quantity = $cart->get_wecart_goods($goods_id,$data['sku_str'],$data['community_id'] ,$token);
+			
+			
+			$json['success']='成功加入购物车!!';
+			$json['total']=$total;
+			$json['cur_count']=$cart_goods_quantity;
+			
+			
+			$is_limit_distance_buy = D('Home/Front')->get_config_by_name('shop_limit_buy_distance');	
+			
+			$json['is_limit_distance_buy']=$is_limit_distance_buy;
+			
+			$json['goods_total_count'] = 0;
+			
+			if( !empty($data['buy_type']) && $data['buy_type'] == 'soitaire' )
+			{
+				$json['goods_total_count'] = $cart->get_wecart_goods_solicount($goods_id, $data['community_id'],$token, $data['soli_id'] );
+				
+				$json['cur_count'] = $cart->get_wecart_goods($goods_id, $data['sku_str'], $data['community_id'],$token,$car_prefix,$data['soli_id'] );
+				
+			}
+			
+			echo json_encode($json);
+			die();
+		}
+		
+	}
+	
+	/**
+		pintuan_newman_notice
+	**/
+	public function add_newcar()
+	{
+		$_GPC = I('request.');
+		
+		$data = array();
+		$data['goods_id'] = $_GPC['goods_id'];
+		$data['buy_type'] = 'pintuan';
+		$data['community_id'] = $_GPC['community_id'];
+		
+		$community_id= $data['community_id'];
+		
+		$data['quantity'] = 1;
+		
+		$token = $_GPC['token'];
+		
+		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
+		
+		$member_id = $weprogram_token['member_id'];
+		
+		
+		$goods_id = $data['goods_id'];
+		if( empty($member_id))
+		{			
+		    $result = array('code' =>4);
+		    echo json_encode($result);
+		    die();
+		}
+		
+		$goods_param = array();
+		
+		$product = M('lionfish_comshop_goods')->where( array('id' => $goods_id ) )->find();
+		
+		if( $product['grounding'] != 1)
+		{
+			$json['code'] =6;
+			$json['msg']='商品已下架!';
+			echo json_encode($json);
+			die();
+		}
+		
+		
+		$goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'total_limit_count,one_limit_count,is_new_buy');
+		
+		$pin_model = D('Home/Pin');
+		
+		$iszero_opentuan = $pin_model->check_goods_iszero_opentuan( $goods_id );
+		
+		if($iszero_opentuan != 1)
+		{
+			$json['code'] =6;
+			$json['msg']='非邀请团商品!';
+			echo json_encode($json);
+			die();
+		}
+		
+		$cart= D('Home/Car');
+		
+		
+		
+		if($product){
+			if( !empty($data['buy_type']) && $data['buy_type'] == 'pintuan' )
+			{
+				$car_prefix = 'pintuancart.';
+			}
+			
+            $cart_goods_quantity = $cart->get_wecart_goods($goods_id,$data['sku_str'],$data['community_id'] ,$token,$car_prefix);
+			
+			
+			$json=array('code' =>0);
+			//$goods_model = D('Home/Goods');
+			$goods_quantity=$cart->get_goods_quantity($goods_id);
+			
+			
+			//检测商品限购 6 one_limit_count
+			/**
+			$can_buy_count = D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
+			
+			if(!empty($cart_goods_quantity) && $cart_goods_quantity > 0)
+			{
+				if($goods_description['one_limit_count'] > 0 && $cart_goods_quantity >= $goods_description['one_limit_count'] )
+				{
+					$json['code'] =6;
+					//$json['msg']='已经不能再买了';
+					
+					$json['msg']='您本次只能购买'.$goods_description['one_limit_count'].'个';
+					
+					$json['max_quantity'] = $goods_description['one_limit_count'];
+					
+					echo json_encode($json);
+					die();
+				}
+				
+				$can_buy_count = $can_buy_count - $cart_goods_quantity;
+				if($can_buy_count <= 0)
+				{
+					$can_buy_count = -1;
+				}
+			}
+			if($can_buy_count == -1 && $goods_description['total_limit_count'] >0)
+			{
+				$json['code'] =6;
+				//$json['msg']='已经不能再买了';
+				
+				$json['msg']='您本次只能购买'.$goods_description['total_limit_count'].'个';
+				
+				$json['max_quantity'] = $goods_description['total_limit_count'];
+			
+				echo json_encode($json);
+				die();
+			}else if($can_buy_count >0 && $quantity >$can_buy_count)
+			{
+				$json['code'] =6;
+				$json['msg']='您还能购买'.$can_buy_count.'份';
+				
+				$json['max_quantity'] = $can_buy_count;
+				echo json_encode($json);
+				die();
+			}
+		
+			//已加入购物车的总数
+			
+			if($goods_quantity<$quantity+$cart_goods_quantity){
+			    $json['code'] =3;
+			    if ($goods_quantity==0) {
+			    	$json['msg']='已抢光';
+			    }else{
+					// $json['msg']='商品数量不足,剩余'.$goods_quantity.'个!!';
+					$json['msg']='商品数量不足';
+					$json['max_quantity'] = $goods_quantity;
+			    }
+
+				echo json_encode($json);
+				die();
+			}
+			**/
+			//开始生产订单 TODO...
+			
+			$payment = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
+			
+			$data = array();
+
+			$data['member_id']=$member_id;
+			$data['name']= $payment['username'];
+			$data['use_score']= 0;//是否使用积分抵扣
+
+			$data['telephone']= '0000';
+			$data['shipping_name']= '0000';
+			$data['shipping_tel']= '0000';
+			$data['shipping_address'] = '';
+			$data['shipping_province_id']=0;
+			$data['shipping_city_id']=0;
+			$data['shipping_stree_id']=0;
+			$data['shipping_country_id']=0;
+						
+						
+			$data['shipping_method'] = 0;
+			$data['delivery']='express';
+			
+			$data['pick_up_id']=$community_id;
+
+			$data['ziti_name']='';
+			$data['ziti_mobile']='';
+
+			$data['payment_method']='yuer';
+
+			$data['address_id']= 0;
+			$data['voucher_id'] = 0;//目前都是平台券
+
+
+			$data['user_agent']=$_SERVER['HTTP_USER_AGENT'];
+			$data['date_added']=time();		
+
+
+			$data['type'] = 'pintuan';
+			$data['shipping_fare'] = 0;
+
+			$goods_data = array();
+			
+			$goods_data[] = array(
+				'goods_id'   => $product['id'],
+				'store_id' => 0,
+				'name'       => $product['goodsname'],
+				'model'      => '',
+				'is_pin' => 1,
+				'pin_id' => 0,
+				'header_disc' => 0,
+				'member_disc' => 0,
+				'level_name' => '',
+				'option'     => '',
+				'quantity'   => 1,
+				'shipping_fare' => 0,
+				'price'      => $product['price'],
+				'card_price' => 0,
+				'costprice' => 0,
+				'total'      => 0,
+				'card_total' => 0 ,
+				'is_take_vipcard' => 0,
+				'fenbi_li'      => 0,
+				'can_man_jian'  => 0,
+				'comment' => ''
+			);
+
+			$data['is_free_shipping_fare']= 0;
+			$data['store_id']= 0;
+			$data['order_goods_total_money']= 0;
+
+
+			$data['goodss'] = $goods_data;
+			$data['order_num_alias']=build_order_no($member_id);
+			$data['voucher_credit'] = 0;
+			$data['score_for_money'] = 0;
+			$data['reduce_money'] = 0;
+			$data['man_total_free'] = 0;
+					
+
+			$oid = D('Home/Frontorder')->addOrder($data);// D('Order')->addOrder($data);
+			
+			$o = array();
+			$o['payment_code'] = 'yuer';
+			$o['order_status_id'] =  2;
+			$o['date_modified']=time();
+			$o['pay_time']=time();
+			$o['transaction_id'] = '余额支付';
+			$o['type'] = 'ignore';
+			
+			//ims_ 
+			M('lionfish_comshop_order')->where( array('order_id' => $oid ) )->save( $o );
+			
+			//更新到0元开团订单类型
+			
+			echo json_encode( array('code' => 0, 'order_id' => $oid ) );
+			die();
+		}
+		
+	}
+	//end--
+	
+	public function add()
+	{
+		$gpc = I('request.');
+		
+		
+		$data = array();
+		$data['goods_id'] = $gpc['goods_id'];
+		$data['community_id'] = $gpc['community_id'];
+		$data['quantity'] = $gpc['quantity'];
+		$data['sku_str'] = $gpc['sku_str'];
+		$data['is_just_addcar'] = $gpc['is_just_addcar'];
+		$data['soli_id'] = isset($gpc['soli_id']) ? intval($gpc['soli_id']) :'';
+		
+		
+		if($gpc['sku_str'] == 'undefined')
+		{
+			$gpc['sku_str'] = '';
+			$data['sku_str']  = '';
+		}
+		
+		$pintuan_model_buy = D('Home/Front')->get_config_by_name('pintuan_model_buy');
+		
+		if( empty($pintuan_model_buy) || $pintuan_model_buy ==0 )
+		{
+			$pintuan_model_buy = 0;
+		}
+		
+		$data['buy_type'] = $gpc['buy_type'];
+		$data['pin_id'] = $gpc['pin_id'];
+		$data['is_just_addcar'] = $gpc['is_just_addcar'];
+		
+		if( !isset($data['buy_type']) || empty($data['buy_type']) )
+		{
+		  $data['buy_type'] = 'dan';
+		}
+		else if( !empty($data['buy_type']) && $data['buy_type'] == 'soitaire' )
+		{
+			$data['buy_type'] = 'soitaire';
+		}
+		else if( !empty($data['buy_type']) && $data['buy_type'] == 'pindan' )
+		{
+			$data['buy_type'] = 'pindan';
+		}else if( !empty($data['buy_type']) && $data['buy_type'] == 'pintuan' )
+		{
+			$data['buy_type'] = 'pintuan';
+		}
+		else if( !empty($data['buy_type']) && $data['buy_type'] == 'presale' )
+        {
+            $data['buy_type'] = 'presale';
+        }
+        else if( !empty($data['buy_type']) && $data['buy_type'] == 'virtualcard' )
+        {
+            $data['buy_type'] = 'virtualcard';
+        }
+		else if( !empty($data['buy_type']) &&  $data['buy_type'] == 'integral' )
+		{
+			$data['buy_type'] = 'integral';
+		}
+		
+		
+		$token = $gpc['token'];
+		
+		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
+		
+		$member_id = $weprogram_token['member_id'];
+		
+		
+		$puis_not_buy =  D('Home/Front')->get_config_by_name('puis_not_buy');
+
+        $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
+
+
+        if( !empty($puis_not_buy) && $puis_not_buy ==1 )
+		{
+
+			if($member_info['level_id'] == 0)
+			{
+				$json['code'] =6;
+				$json['msg']='普通会员不能购买!';
+				echo json_encode($json);
+				die();
+			}
+		}
+
+        //1、判断是否开启审核,2、如果开启审核,判断会员状态是否审核
+        $is_user_shenhe = D('Home/Front')->get_config_by_name('is_user_shenhe');
+        //1
+        if( isset($is_user_shenhe) && $is_user_shenhe == 1 )
+        {
+            if( $member_info['is_apply_state'] != 1 )
+            {
+                $json['code'] = 6;
+                $json['msg'] = '会员未审核不能购买';
+                echo json_encode( $json );
+                die();
+            }
+        }
+
+		//团长休息
+		$community_id = $gpc['community_id'];
+		$group_name = D('Home/Front')->get_config_by_name('group_name');
+		if( isset($community_id) && $community_id > 0 )
+		{
+			$is_can_buy = D('Seller/Communityhead')-> check_goods_can_community($gpc['goods_id'], $community_id);
+			
+			if( !$is_can_buy )
+			{
+				$json['code'] =6;
+				$json['msg']='此商品在您所属'.$group_name.'不可参与!';
+				echo json_encode($json);
+				die();
+			}
+			// is_all_sale
+		}
+
+        $is_just_addcar = empty($data['is_just_addcar']) ? 0: 1;
+		
+		$goods_id = $data['goods_id'];
+		if( empty($member_id))
+		{			
+		    $result = array('code' =>4);
+		    echo json_encode($result);
+		    die();
+		}
+		
+		if (isset($data['goods_id'])) {
+			$goods_id = $data['goods_id'];
+		} else {
+			$goods_id = 0;
+		}
+		
+		
+		$product = M('lionfish_comshop_goods')->where( array('id' => $goods_id ) )->find();
+		
+		if( $product['grounding'] != 1)
+		{
+			$json['code'] =6;
+			$json['msg']='商品已下架!';
+			echo json_encode($json);
+			die();
+		}
+		
+		
+		$goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'total_limit_count,one_limit_count,oneday_limit_count,is_new_buy,is_limit_levelunbuy,is_limit_vipmember_buy,goods_start_count');
+			
+		//is_limit_levelunbuy
+		//$is_default_levellimit_buy = D('Home/Front')->get_config_by_name('is_default_levellimit_buy');
+		//isset($is_default_levellimit_buy) && $is_default_levellimit_buy == 1 &&
+		
+		if(  $goods_description['is_limit_levelunbuy'] == 1 )
+		{
+			// member_id
+			$mb_info = M('lionfish_comshop_member')->field('level_id')->where( array('member_id' => $member_id ) )->find();
+			
+			if( $mb_info['level_id'] == 0 )
+			{
+				$json['code'] =6;
+				$json['msg']='默认等级不能购买,请联系客服';
+				echo json_encode($json);
+				die();
+			}
+		}	
+		
+		//is_limit_vipmember_buy 付费会员专享
+		
+		//$is_default_vipmember_buy = D('Home/Front')->get_config_by_name('is_default_vipmember_buy');
+		//isset($is_default_vipmember_buy) && $is_default_vipmember_buy == 1 &&
+		
+		if(  $goods_description['is_limit_vipmember_buy'] == 1 )
+		{
+			$mb_vip = M('lionfish_comshop_member')->field('card_id,card_begin_time,card_end_time')->where( array('member_id' => $member_id ) )->find();
+			
+			//当前时间
+			$present_time = time();
+			
+			if( $mb_vip['card_id'] == 0 || ( $present_time > $mb_vip['card_end_time'] ) )
+			{
+				
+				$is_pop_vipmember_buytip = D('Home/Front')->get_config_by_name('is_pop_vipmember_buytip');
+				$is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
+				$pop_vipmember_buyimage = D('Home/Front')->get_config_by_name('pop_vipmember_buyimage');
+				
+				$json['has_image'] = 0;
+				
+				$is_open_vipcard_buy = isset($is_open_vipcard_buy) ? $is_open_vipcard_buy : 0;
+				
+				if( isset($is_pop_vipmember_buytip) && $is_pop_vipmember_buytip ==1 )
+				{
+					if( isset($pop_vipmember_buyimage) && !empty($pop_vipmember_buyimage) )
+					{
+						$pop_vipmember_buyimage = tomedia($pop_vipmember_buyimage);
+						
+						$json['has_image'] = 1;
+						$json['pop_vipmember_buyimage'] = $pop_vipmember_buyimage;
+					}
+				}
+				$json['code'] =7;
+				
+				
+				$json['msg']='付费会员专享,普通会员不能购买';
+				echo json_encode($json);
+				die();
+			}			
+			
+		}
+		
+		if( !empty($goods_description['is_new_buy']) &&  $goods_description['is_new_buy'] == 1)
+		{
+			
+			$ck_buy_order = M('lionfish_comshop_order')->field('order_id')->where( "member_id={$member_id} and order_status_id in (1,4,6,7,10,11,12,14)"  )->find();
+			
+			if( !empty($ck_buy_order) )
+			{
+				$json['code'] =6;
+				$json['msg']='新人专享!';
+				echo json_encode($json);
+				die();
+			}
+
+			$is_new_buy_limit = D('Home/Front')->get_config_by_name('is_new_buy_limit');
+			$new_buy_limit_num = D('Home/Front')->get_config_by_name('new_buy_limit_num');
+			if(!empty($is_new_buy_limit) && $is_new_buy_limit == 1){//新人专享限制
+				$goods_cate_count = D('Home/Car')->get_new_goods_count($token,$goods_id,$data['sku_str']);
+				if($goods_cate_count >= $new_buy_limit_num){
+					$json['code'] = 6;
+					$json['msg']='超出新人专享限制!';
+					echo json_encode($json);
+					die();
+				}
+			}
+		}
+			
+		
+		
+	
+		//$data['community_id']
+		if( $data['buy_type'] == 'dan' || $data['buy_type'] =='soitaire'  || ($pintuan_model_buy ==1 && $data['buy_type'] != 'dan') )
+		{
+			$is_community = D('Seller/Communityhead')->is_community($data['community_id']);
+			if( !$is_community )
+			{
+				$json['code'] =6;
+				$json['msg']='该小区已经不存在!';
+				echo json_encode($json);
+				die();
+			}
+		}
+		
+		//判断是否积分兑换
+		if( $product['type'] == 'integral')
+		{
+			//判断积分是否足够 member_id 暂时关闭以下代码
+			
+			$integral_model = D('Home/Integral');
+			if (isset($data['quantity'])) {
+				$quantity = $data['quantity'];
+			} else {
+				$quantity = 1;
+			}
+			if(intval($quantity) < 1){
+				$json['code'] =6;
+				$json['msg']='数量不能小于1!';
+				echo json_encode($json);
+				die();
+			}
+			$check_result = $integral_model->check_user_score_quantity_can_pay($member_id, $data['sku_str'], $goods_id,$quantity);
+			
+			if( $check_result['code'] == 1 )
+			{
+				$json['code'] =6;
+				$json['msg']='剩余'.$check_result['cur_score'].'积分,积分不足!';
+				echo json_encode($json);
+				die();
+			}
+			/****/
+		}
+		
+		//6 
+		if($is_just_addcar == 1)
+		{
+			if($product['pick_just'] > 0)
+			{
+				$json['code'] =6;
+				$json['msg']='自提商品,请立即购买';
+				echo json_encode($json);
+				die();
+			}
+		}
+		
+		//商品存在
+		if($product){
+			
+			$cart= D('Home/Car');
+			
+			if (isset($data['quantity'])) {
+				$quantity = $data['quantity'];
+			} else {
+				$quantity = 1;
+			}
+					
+			$option = array();
+			
+			if( !empty($data['sku_str'])){
+			    $option = explode('_', $data['sku_str']);
+			}
+			
+			$car_prefix = "cart.";
+			
+			if( !empty($data['buy_type']) && $data['buy_type'] == 'pindan' )
+			{
+				$car_prefix = 'pindancart.';//cart.
+			}
+			else if( !empty($data['buy_type']) && $data['buy_type'] == 'soitaire' )
+			{
+				$car_prefix = 'soitairecart.';
+			}
+			else if( !empty($data['buy_type']) && $data['buy_type'] == 'pintuan' )
+			{
+				$car_prefix = 'pintuancart.';
+			}
+            else if( !empty($data['buy_type']) && $data['buy_type'] == 'presale' )
+            {
+                $car_prefix = 'presalecart.';
+            }
+            else if( !empty($data['buy_type']) && $data['buy_type'] == 'virtualcard' )
+            {
+                $car_prefix = 'virtualcardcart.';
+            }
+			else if( !empty($data['buy_type']) && $data['buy_type'] == 'integral' ){
+				$car_prefix = 'integralcart.';
+			}
+			
+			//$data['soli_id']
+            if($data['is_just_addcar'] == 0){
+                $cart_goods_quantity = 0;
+            }else{
+                $cart_goods_quantity = $cart->get_wecart_goods($goods_id,$data['sku_str'],$data['community_id'] ,$token,$car_prefix,$data['soli_id']);
+            }
+
+			
+			
+			$cart_goods_all_quantity = $cart->get_wecartall_goods($goods_id,$data['sku_str'],$data['community_id'] ,$token,$car_prefix);
+			
+			
+			$json=array('code' =>0);
+			//$goods_model = D('Home/Goods');
+			$goods_quantity=$cart->get_goods_quantity($goods_id);
+            if(!empty($data['sku_str'])){
+                $goods_option_item_value = M('lionfish_comshop_goods_option_item_value')->field('stock')->where(array('goods_id' =>$goods_id,'option_item_ids'=>$data['sku_str']))->find();
+                if(!empty($goods_option_item_value)){
+                    $goods_quantity = $goods_option_item_value['stock'];
+                }
+            }
+
+
+			//rela_goodsoption_valueid
+			if($goods_quantity < $goods_description['goods_start_count']){
+				$json['code'] =6;
+				$json['msg']='起售数量'.$goods_description['goods_start_count'].',库存不足,剩余'.$goods_quantity.'个';
+				$json['max_quantity'] = $goods_description['goods_start_count'];
+				echo json_encode($json);
+				die();
+			}
+			//起售数量判断
+			if($quantity+$cart_goods_quantity < $goods_description['goods_start_count'])
+			{
+				$json['code'] = 6;
+				$json['msg'] =  $goods_description['goods_start_count'].'份起售';
+				$json['max_quantity'] = $goods_description['goods_start_count'];
+				echo json_encode($json);
+				die();
+			}
+            //$can_buy_count = D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
+			/**
+            //单次限购
+            if(!empty($cart_goods_all_quantity) && $cart_goods_all_quantity > 0 && $data['buy_type'] != 'pintuan' )
+            {
+                if($goods_description['one_limit_count'] > 0 && $cart_goods_all_quantity >= $goods_description['one_limit_count'] )
+                {
+                    $json['code'] =6;
+                    //$json['msg']='已经不能再买了';
+
+                    $json['msg'] = '您本次只能购买'.$goods_description['one_limit_count'].'个';
+
+                    $json['max_quantity'] = $goods_description['one_limit_count'];
+
+                    echo json_encode($json);
+                    die();
+                }
+
+                $can_buy_count = $can_buy_count - $cart_goods_all_quantity;
+                if($can_buy_count <= 0)
+                {
+                    $can_buy_count = -1;
+                }
+            }
+            //每单限购
+            if($can_buy_count > 0 && $quantity > $can_buy_count)
+            {
+                $json['code'] =6;
+                $json['msg']='您每次只能购买'.$can_buy_count.'份';
+
+                $json['max_quantity'] = $can_buy_count;
+                echo json_encode($json);
+                die();
+            }
+
+            //每日限购 6
+            $can_buy_day_count =  D('Home/Front')->check_goods_user_canbuy_day_count($member_id, $goods_id);
+
+            if ($goods_description['oneday_limit_count'] >0){
+                if($can_buy_day_count == -1 || ($can_buy_day_count > 0 && ($cart_goods_all_quantity+$quantity) > $can_buy_day_count))
+                {
+                    $json['code'] =6;
+                    //$json['msg']='已经不能再买了';
+                    $json['msg']='您每天只能购买'.$goods_description['oneday_limit_count'].'个';
+
+                    $json['max_quantity'] = $goods_description['oneday_limit_count'];
+
+                    echo json_encode($json);
+                    die();
+                }
+            }
+
+			//历史限购判断
+			if($can_buy_count == -1 && $goods_description['total_limit_count'] >0)
+			{
+				$json['code'] =6;
+				//$json['msg']='已经不能再买了';
+				$json['msg']='您还能购买'.$goods_description['total_limit_count'].'个';
+				
+				$json['max_quantity'] = $goods_description['total_limit_count'];
+			
+				echo json_encode($json);
+				die();
+			}
+			**/
+
+			$can_buy_one_count = D('Home/Front')->check_goods_user_canbuy_one_count($member_id, $goods_id);
+
+
+			/*$goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'total_limit_count,one_limit_count,oneday_limit_count,is_new_buy,is_limit_levelunbuy,is_limit_vipmember_buy,goods_start_count');
+			if($quantity < $goods_description['goods_start_count']){
+				$json['code'] = 6;
+				//$json['msg'] = '您本次只能购买'.$goods_description['one_limit_count'].'份';
+				$json['msg'] = $goods_description['goods_start_count'].'件起售';
+				$json['max_quantity'] = $goods_description['goods_start_count'];
+				echo json_encode($json);
+				die();
+			}*/
+
+			//单次限购判断
+			if($goods_description['one_limit_count'] > 0 && $quantity+$cart_goods_quantity > $goods_description['one_limit_count'])
+			{
+				$json['code'] = 6;
+				//$json['msg'] = '您本次只能购买'.$goods_description['one_limit_count'].'份';
+				$json['msg'] = '购物车总数已满或超出每次购买数量';
+                $json['max_quantity'] = $goods_description['one_limit_count']-$cart_goods_all_quantity;
+				echo json_encode($json);
+				die();
+			}
+
+			$can_buy_day_count =  D('Home/Front')->check_goods_user_canbuy_day_count($member_id, $goods_id);
+			if($can_buy_day_count == -1 || ($can_buy_day_count > 0 && $quantity > $can_buy_day_count))
+			{
+				$json['code'] =6;
+				//$json['msg'] = '您今天只能购买'.$goods_description['oneday_limit_count'].'份';
+				$json['msg'] = '购物车总数已满或超出每天购买数量';
+				$json['max_quantity'] = $can_buy_day_count-$cart_goods_all_quantity;
+				echo json_encode($json);
+				die();
+			}else if($can_buy_day_count > 0 && ($quantity+$cart_goods_quantity) > $can_buy_day_count){
+				$json['code'] =6;
+				//$json['msg'] = '您今天还能购买'.$can_buy_day_count.'份';
+				$json['msg'] = '购物车总数已满或超出每天购买数量';
+				$json['max_quantity']=$can_buy_day_count-$cart_goods_all_quantity;
+				echo json_encode($json);
+				die();
+			}
+
+			$can_buy_all_count =  D('Home/Front')->check_goods_user_canbuy_all_count($member_id, $goods_id);
+            if($data['buy_type'] == 'pintuan' || $data['buy_type'] == 'pindan' || $data['buy_type'] == 'presale'){
+                $cart_goods_all_quantity = 0;
+            }
+			//历史限购判断
+			if($can_buy_all_count == -1 && $goods_description['total_limit_count'] >0)
+			{
+				$json['code'] =6;
+				//$json['msg']='您最多只能购买'.$goods_description['total_limit_count'].'份';
+				$json['msg'] = '购物车总数已满或超出历史购买数量';
+				$json['max_quantity'] = 1;
+				echo json_encode($json);
+				die();
+			}else if($can_buy_all_count > 0 && ($cart_goods_all_quantity+$quantity) > $can_buy_all_count){
+				$json['code'] =6;
+				$json['msg']='购物车总数已满或超出历史购买数量';
+				$json['max_quantity'] = $can_buy_all_count-$cart_goods_all_quantity;
+				echo json_encode($json);
+				die();
+			}
+
+			//已加入购物车的总数
+			
+			if($goods_quantity < $quantity+$cart_goods_quantity){
+			    $json['code'] =3;
+			    if ($goods_quantity==0) {
+			    	$json['msg']='已抢光';
+			    }else{
+					$json['msg']='商品数量不足';
+					$json['max_quantity'] = $goods_quantity;
+			    }
+
+				echo json_encode($json);
+				die();
+			}
+			
+			if(!empty($option))
+			{
+				$mul_opt_arr = array();
+				
+				//ims_ 
+				//$goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->where( array('goods_id' => $goods_id,'option_item_ids' => $data['sku_str']) )->find();
+				$open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
+		
+                if(!empty($open_redis_server) && $open_redis_server == 1)
+                {
+                    $goods_option_mult_value_stock = D('Seller/Redisorder')->get_goods_sku_quantity($goods_id, $data['sku_str']);
+                }else{
+                	$goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->where( array('goods_id' => $goods_id,'option_item_ids' => $data['sku_str']) )->find();
+                }
+				
+			
+				if( !empty($goods_option_mult_value_stock) )
+				{
+					if($goods_option_mult_value_stock<$quantity+$cart_goods_quantity){
+					    $json['code'] =3;
+						$json['msg']='商品数量不足,剩余'.$goods_option_mult_value_stock.'个!!';
+						
+						$json['max_quantity'] = $goods_option_mult_value['stock'];
+						echo json_encode($json);
+						die();
+					}
+				}
+			}
+			
+			//buy_type
+			
+		   // $this->clear_all_cart(); $data['community_id']
+		   
+			$format_data_array = array(
+									'quantity' => $quantity,
+									'community_id' => $data['community_id'],
+									'goods_id' => $goods_id,
+									'sku_str'=>$data['sku_str'],
+									'buy_type' =>$data['buy_type'],
+									'soli_id' => $data['soli_id']
+								);
+			//区分活动商品还是普通商品。做两个购物车,活动商品是需要直接购买的,单独购买商品加入正常的购物车TODO....
+		    //is_just_addcar 0  1
+			if($data['buy_type'] == 'dan' && $is_just_addcar == 0)
+		    {
+				
+				//$cart->removedancar($token);
+				//清空一下购物车
+				//singledel
+				$format_data_array['is_just_addcar'] = 0;
+				$format_data_array['singledel'] = 1;
+				
+		        $cart->addwecar($token,$goods_id,$format_data_array,$data['sku_str'],$data['community_id']);
+				$total=$cart->count_goodscar($token ,$data['community_id']);
+		    }
+			else if($data['buy_type'] == 'dan' && $is_just_addcar == 1)
+			{
+				//singledel
+				$format_data_array['is_just_addcar'] = 1;
+				$format_data_array['singledel'] = 1;
+				$cart->addwecar($token,$goods_id,$format_data_array,$data['sku_str'],$data['community_id']);
+				$total=$cart->count_goodscar($token, $data['community_id']);
+			}
+			else if( !empty($data['buy_type']) && $data['buy_type'] == 'soitaire' )
+			{
+				//清理单独购买的商品
+				$format_data_array['is_just_addcar'] = 1;
+				$format_data_array['singledel'] = 1;
+				
+		        $cart->addwecar($token,$goods_id,$format_data_array,$data['sku_str'],$data['community_id'],$car_prefix,$data['soli_id']);
+				$total=0;
+			}
+			else if( !empty($data['buy_type']) && $data['buy_type'] == 'pindan' )
+			{
+				//清理单独购买的商品
+				$cart->removeActivityAllcar($token, 'pindancart.');
+				$format_data_array['is_just_addcar'] = 0;
+				$format_data_array['singledel'] = 1;
+				
+		        $cart->addwecar($token,$goods_id,$format_data_array,$data['sku_str'],$data['community_id'],$car_prefix);
+				$total=0;
+			}
+			else if( !empty($data['buy_type']) && $data['buy_type'] == 'pintuan' )
+			{
+				$pin_id = isset($data['pin_id']) ? $data['pin_id'] : 0;
+				
+				if( $pin_id > 0 )
+				{
+					$pin_info_tmp = M('lionfish_comshop_pin')->where( array('pin_id' => $pin_id ) )->find();
+					
+					if( !empty($pin_info_tmp) && $pin_info_tmp['is_newman_takein'] == 1 )
+					{
+						//检测是否新人
+						//检测是否购买过
+						$od_status = "1,2,4,6,7,8,9,10,11,12,14";
+						
+						$od_buy_count = M('lionfish_comshop_order')->where("order_status_id in ({$od_status}) and member_id=".$member_id)->count();
+						
+						if( !empty($od_buy_count) && $od_buy_count >0 )
+						{
+							$json['code'] =3;
+							$json['msg']='新人专享';
+							
+							echo json_encode($json);
+							die();
+						}
+					}
+					
+				}
+				
+				//清理拼团的商品
+				$cart->removeActivityAllcar($token, 'pintuancart.');
+				$format_data_array['is_just_addcar'] = 0;
+				$format_data_array['singledel'] = 1;
+				$format_data_array['pin_id'] = $pin_id;
+				
+		        $cart->addwecar($token,$goods_id,$format_data_array,$data['sku_str'],$data['community_id'],$car_prefix);
+				$total=0;
+			}
+            else if( !empty($data['buy_type']) && $data['buy_type'] == 'presale' )
+            {
+                //清理预售的商品
+                $cart->removeActivityAllcar($token, 'presalecart.');
+                $format_data_array['is_just_addcar'] = 0;
+                $format_data_array['singledel'] = 1;
+
+                $cart->addwecar($token,$goods_id,$format_data_array,$data['sku_str'],$data['community_id'],$car_prefix);
+                $total=0;
+            }
+            else if( !empty($data['buy_type']) && $data['buy_type'] == 'virtualcard' )
+            {
+                //清理预售的商品
+                $cart->removeActivityAllcar($token, 'virtualcardcart.');
+                $format_data_array['is_just_addcar'] = 0;
+                $format_data_array['singledel'] = 1;
+
+                $cart->addwecar($token,$goods_id,$format_data_array,$data['sku_str'],$data['community_id'],$car_prefix);
+                $total=0;
+            }
+			else if( !empty($data['buy_type']) && $data['buy_type'] == 'integral' )
+			{
+				
+				//清理拼团的商品 $data['pin_id']
+				$cart->removeActivityAllcar($token, 'integralcart.');
+				$format_data_array['is_just_addcar'] = 0;
+				$format_data_array['singledel'] = 1;
+				
+		        $cart->addwecar($token,$goods_id,$format_data_array,$data['sku_str'],$data['community_id'],$car_prefix);
+				$total=0;
+			}
+			else {
+		        //buy_type:pin  活动购物车。
+		        $pin_id = isset($data['pin_id']) ? $data['pin_id'] : 0;
+				
+				//lottery
+				if( $product['type'] == 'lottery' && $product['type'] == 'lottery' )
+				{
+					/**
+					//等待把抽奖的活动打开
+					$now_time = time();
+					$lottery_goods_info =  M('lottery_goods')->where( array('goods_id' => $goods_id) )->find();
+					
+					if($lottery_goods_info['end_time'] < $now_time)
+					{
+						$json['code'] =6;
+						$json['msg']='抽奖活动已结束';
+						echo json_encode($json);
+						die();
+					}
+					**/
+				}
+				
+				//检测商品是否老带新,新人才能参团
+				if($pin_id > 0 )
+				{
+					//等待把老带新的活动打开
+					/**
+					if($product['type'] == 'newman')
+					{
+						$new_mamn_buy = $goods_model->check_goods_new_manbug($member_id);
+						if($new_mamn_buy>0)
+						{
+							$json['code'] =5;
+							$json['msg']='该商品只能新人参团';
+							echo json_encode($json);
+							die();
+						}
+					}
+					**/
+				}
+				
+		        $format_data_array['pin_id'] = $pin_id;
+
+		        $cart->add_activitycar($token, $goods_id,$format_data_array,$data['sku_str']);
+				$total=$cart->count_activitycar($token);
+		    }
+		    
+		    
+			$carts = M('lionfish_comshop_car')->where( array('token' => $token,'community_id' => $data['community_id'],'carkey' => 'cart_total') )->find();
+			
+			if( !empty($data['buy_type']) && $data['buy_type'] == 'dan' )
+			{
+				if( !empty($carts) )			
+				{
+					$car_data = array();
+					$car_data['format_data'] = serialize(array('quantity' => $total));
+					$car_data['modifytime'] = 1;
+					
+					M('lionfish_comshop_car')->where( array('token' => $token,'community_id' => $data['community_id'],'carkey' => 'cart_total') )->save($car_data);
+				
+				} else{				
+					
+					$car_data = array();
+					$car_data['token'] = $token;
+					
+					$car_data['community_id'] = $data['community_id'];
+					$car_data['carkey'] = 'cart_total';
+					$car_data['format_data'] = serialize(array('quantity' => $total));
+					
+					M('lionfish_comshop_car')->add($car_data);
+				}
+			}
+						
+			//session('cart_total',$total);
+			$json ['code']  = 1;
+			if( $data['buy_type'] != 'dan' )
+			{
+			    $json ['code']  = 2;
+			}
+			$json['success']='成功加入购物车!!';
+			$json['total']=$total;
+			
+			$cart_goods_quantity = $cart->get_wecart_goods($goods_id,$data['sku_str'],$data['community_id'] ,$token , $car_prefix);
+			$json['cur_count']=$cart_goods_quantity;
+			
+			
+			
+			//soitaire 
+			$is_limit_distance_buy = D('Home/Front')->get_config_by_name('shop_limit_buy_distance');	
+			
+			$json['is_limit_distance_buy']=$is_limit_distance_buy;
+			
+			$json['goods_total_count'] = 0;
+			
+			if( !empty($data['buy_type']) && $data['buy_type'] == 'soitaire' )
+			{
+				$json['goods_total_count'] = $cart->get_wecart_goods_solicount($goods_id, $data['community_id'],$token, $data['soli_id'] );
+				
+				$cart_goods_quantity = $cart->get_wecart_goods($goods_id,$data['sku_str'],$data['community_id'] ,$token , $car_prefix, $data['soli_id']);
+				$json['cur_count']=$cart_goods_quantity;
+			}
+			
+			
+			echo json_encode($json);
+			die();
+		}	
+		
+	}
+	
+	//显示购物车中商品列表
+	function show_cart_goods(){
+		
+		$gpc = I('request.');
+		
+		$token = $gpc['token'];
+		$community_id = $gpc['community_id'];
+		$soli_id = isset($gpc['soli_id']) ? intval($gpc['soli_id']) : '';
+		
+		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
+		
+		$member_id = $weprogram_token['member_id'];
+		
+		$is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
+		$is_open_vipcard_buy = !empty($is_open_vipcard_buy) && $is_open_vipcard_buy ==1 ? 1:0;
+		$modify_vipcard_name = D('Home/Front')->get_config_by_name('modify_vipcard_name');
+		
+		
+		$is_vip_card_member = 0;
+		$is_member_level_buy = 0;
+		
+		if( $member_id > 0 )
+		{
+			$member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
+			
+			if( !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 )
+			{
+				
+				$now_time = time();
+				
+				if( $member_info['card_id'] >0 && $member_info['card_end_time'] > $now_time )
+				{
+					$is_vip_card_member = 1;//还是会员
+				}else if( $member_info['card_id'] >0 && $member_info['card_end_time'] < $now_time ){
+					$is_vip_card_member = 2;//已过期
+				}
+			}
+			
+			if($is_vip_card_member != 1 && $member_info['level_id'] >0 )
+			{
+				$is_member_level_buy = 1;
+			}
+		}
+		
+		$buy_type = isset($gpc['buy_type']) ? $gpc['buy_type']: 'dan';
+		
+		if( empty($member_id) )
+		{
+			  //需要登录
+			  echo json_encode( array('code' =>5) );
+			  die();
+		}
+		  
+		$cart =  D('Home/Car');
+		
+		$goods = $cart->get_all_goodswecar($buy_type, $token, 0, $community_id,$soli_id);
+	
+
+		$seller_goodss = array();
+
+		$seller_goodss_mult = array();
+		
+		//is_only_express
+		$tp_ar = array();
+		
+		foreach($goods as $key => $val)
+		{
+			//$goods_store_field =  M('goods')->field('store_id')->where( array('goods_id' => $val['goods_id']) )->find();
+			//$seller_goodss[ $goods_store_field['store_id'] ]['goods'][$key] = $val;
+			
+			$supply_id = D('Home/Front')->get_goods_supply_id($val['goods_id']);
+			if($supply_id > 0)
+			{
+				$supply_info = D('Home/Front')->get_supply_info($supply_id);
+				
+				if($supply_info['type'] ==0)
+				{
+					$supply_id = 0;
+				}
+			}
+			
+			
+			$seller_goodss[ $supply_id ]['goods'][$key] = $val;
+			
+			$tp_ar[] = $val['is_only_express'];
+			$seller_goodss_mult[$val['is_only_express']][ $supply_id ]['goods'][$key] = $val;//new 0719
+			
+		}
+		
+		$ck_goodstype_count = 0;
+		$vipcard_save_money = 0;
+		
+		$level_save_money = 0;
+		//$max_can_orderbuy_money = 0 ;
+		foreach($seller_goodss_mult as $key => $seller_goodss_tp)
+		{
+			
+			foreach($seller_goodss_tp as $store_id => $val)
+			{
+				//total
+				$seller_voucher_list = array();
+				$seller_total_fee = 0;
+				$total_trans_free = 0;
+				
+				$tmp_goods = array();
+				
+				$is_store_ck = false;
+				
+				foreach($val['goods'] as $kk =>$d_goods)
+				{
+					$seller_total_fee += $d_goods['total'];
+					
+					$total_trans_free  += $d_goods[$kk]['trans_free'];
+					$val['goods'][$kk] = $d_goods;
+					
+					$tp_val = array();
+					$tp_val['id'] = $d_goods['goods_id'];
+					$tp_val['key'] = $d_goods['key'];
+					if($d_goods['singledel'] == 1)
+					{ 
+						$tp_val['isselect'] = true;
+						$is_store_ck = true;
+						$ck_goodstype_count++;
+						if($d_goods['is_take_vipcard'] == 1)
+						{	
+							$vipcard_save_money = $d_goods['total'] - $d_goods['card_total'];
+						}else if($d_goods['is_mb_level_buy']  == 1 ){
+							$level_save_money = $d_goods['total'] - $d_goods['level_total'];
+						}
+					} else {
+						$tp_val['isselect'] = false;
+					}
+					
+					$tp_val['imgurl'] = $d_goods['image'];
+					$tp_val['edit'] = 'inline';
+					$tp_val['title'] = htmlspecialchars_decode($d_goods['name']);
+					$tp_val['finish'] = 'none';
+					$tp_val['description'] = 'description';
+					
+					$option_arr  = array();
+					$option_str = "";
+					foreach($d_goods['option'] as $option_val)
+					{
+						//$option_arr[] = $option_val['name'].':'.$option_val['value'];
+						$option_arr[] = $option_val['value'];
+					}
+					if(!empty($option_arr))
+					{
+						$option_str = implode(';', $option_arr);
+					}
+					
+					
+					$tp_val['can_buy'] = D('Home/Pingoods')->get_goods_time_can_buy($d_goods['goods_id']);
+					
+					$tp_val['option_can_buy'] = D('Home/Pingoods')->get_goods_option_can_buy( $d_goods['goods_id'], $d_goods['sku_str']);
+					
+					
+					$tp_val['goodstype'] = $option_str;
+					$tp_val['goodstypeedit'] = $option_str;
+					$tp_val['goodsnum'] = $d_goods['quantity'];
+					$tp_val['can_man_jian'] = $d_goods['can_man_jian'];
+					$tp_val['max_quantity'] = $d_goods['max_quantity'];
+					$tp_val['cartype'] = 'inline';
+					$tp_val['currntprice'] = $d_goods['price'];
+					$tp_val['card_price'] = $d_goods['card_price'];
+					
+					$tp_val['levelprice'] = $d_goods['levelprice'];// 会员等级价格
+					$tp_val['is_mb_level_buy'] = $d_goods['is_mb_level_buy'];//是否可以会员等级价格购买
+					
+					$tp_val['is_take_vipcard'] = $d_goods['is_take_vipcard'];
+					$tp_val['price'] = $d_goods['shop_price'];
+					$tp_val['is_new_buy'] = $d_goods['is_new_buy'];
+					$tp_val['goods_start_count'] = $d_goods['goods_start_count'];
+					$tp_val['store_id'] = $store_id;
+					$tmp_goods[] = $tp_val;
+					
+				}
+				
+				//$store_info = M('seller')->field('s_id,s_true_name,s_logo')->where( array('s_id' => $store_id) )->find();
+				//$store_info['s_logo'] = C('SITE_URL').'Uploads/image/'.$store_info['s_logo'];
+				
+				$store_info = array('s_true_name' => '','s_id' => 1);
+				$s_logo = D('Home/Front')->get_config_by_name('shoplogo');
+				
+				if( !empty($s_logo) )
+				{
+					$s_logo = tomedia($s_logo);
+				}
+						
+				$val['store_info'] = $store_info;
+				
+				$store_data = array();
+				$store_data['id'] = $store_info['s_id'];
+				if($is_store_ck)
+				{
+					$store_data['isselect'] = true;
+				} else {
+					$store_data['isselect'] = false;
+				}
+				
+				$store_data['shopname'] = $store_info['s_true_name'];
+				$store_data['caredit'] = 'inline';
+				$store_data['finish'] = 'none';
+				$store_data['count'] = '0.00';
+				
+				$is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
+				$full_money = D('Home/Front')->get_config_by_name('full_money');
+				$full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
+				
+				if(empty($full_reducemoney) || $full_reducemoney <= 0)
+				{
+					$is_open_fullreduction = 0;
+				}
+				
+				$store_data['is_open_fullreduction'] = $is_open_fullreduction;
+				$store_data['full_money'] = $full_money;
+				$store_data['full_reducemoney'] = $full_reducemoney;
+				
+				
+				
+				$store_data['goodstype'] = 2;
+				$store_data['goodstypeselect'] = 0;
+				$store_data['shopcarts'] = $tmp_goods;
+
+				//起送价格
+				$localtown_moneytype_fixed_deliverymoney = 0;
+				//达到金额免配送费
+				$localtown_moneytype_fixed_freemoney = 0;
+				
+				
+				$localtown_fixed_list = array();
+				if($key == 3){//同城配送商品
+					$storename = "";
+					if($store_id == 0){
+						//配送费类型:0、固定金额,1、按距离收取
+						$localtown_delivery_moneytype = D('Home/Front')->get_config_by_name('localtown_delivery_moneytype');
+						if($localtown_delivery_moneytype == 0){
+							$localtown_moneytype_fixed_deliverymoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_deliverymoney');
+							$localtown_moneytype_fixed_freemoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_freemoney');
+						}
+						$storename = "平台";
+					}else{
+						$isopen_localtown_delivery = D('Home/Front')->get_supply_config_by_name('isopen_localtown_delivery',$store_id);
+						//配送费类型:0、固定金额,1、按距离收取
+						$localtown_delivery_moneytype = D('Home/Front')->get_supply_config_by_name('localtown_delivery_moneytype',$store_id);
+						if($isopen_localtown_delivery == 1 && $localtown_delivery_moneytype == 0){
+							$localtown_moneytype_fixed_deliverymoney = D('Home/Front')->get_supply_config_by_name('localtown_moneytype_fixed_deliverymoney',$store_id);
+							$localtown_moneytype_fixed_freemoney = D('Home/Front')->get_supply_config_by_name('localtown_moneytype_fixed_freemoney',$store_id);
+						}
+						$supply_info_data = M('lionfish_comshop_supply')->field('storename')->where( array('id' => $store_id) )->find();
+						$storename = $supply_info_data['storename'];
+					}
+					$localtown_fixed_list['localtown_moneytype_fixed_deliverymoney'] = $localtown_moneytype_fixed_deliverymoney;
+					//if($localtown_moneytype_fixed_deliverymoney > $max_can_orderbuy_money){
+						//获取起送最大下单金额限制
+						//$max_can_orderbuy_money = $localtown_moneytype_fixed_deliverymoney;
+					//}
+					$localtown_fixed_list['localtown_moneytype_fixed_freemoney'] = $localtown_moneytype_fixed_freemoney;
+					$localtown_fixed_list['store_name'] = $storename;
+				}else if($key == 2){
+					if($store_id == 0){
+						$storename = "平台";
+					}else{
+						$supply_info_data = M('lionfish_comshop_supply')->field('storename')->where( array('id' => $store_id) )->find();
+						$storename = $supply_info_data['storename'];
+					}
+					$localtown_fixed_list['store_name'] = $storename;
+				}
+				$store_data['localtown_fixed_list'] = $localtown_fixed_list;
+				$seller_goodss_tp[$store_id] = $store_data;
+				$i++;
+			}
+			$seller_goodss_mult[$key] = $seller_goodss_tp;
+			
+		}
+		
+		
+	
+	
+		foreach($seller_goodss as $store_id => $val)
+		{
+			//total
+			$seller_voucher_list = array();
+			$seller_total_fee = 0;
+			$total_trans_free = 0;
+			
+			$tmp_goods = array();
+			
+			$is_store_ck = false;
+			
+			foreach($val['goods'] as $kk =>$d_goods)
+			{
+				$seller_total_fee += $d_goods['total'];
+				
+				$total_trans_free  += $d_goods[$kk]['trans_free'];
+				$val['goods'][$kk] = $d_goods;
+				
+				$tp_val = array();
+				$tp_val['id'] = $d_goods['goods_id'];
+				$tp_val['key'] = $d_goods['key'];
+				if($d_goods['singledel'] == 1)
+				{ 
+					$tp_val['isselect'] = true;
+					$is_store_ck = true;
+					$ck_goodstype_count++;
+				} else {
+					$tp_val['isselect'] = false;
+				}
+				
+				$tp_val['imgurl'] = $d_goods['image'];
+				$tp_val['edit'] = 'inline';
+				$tp_val['title'] = $d_goods['name'];
+				$tp_val['finish'] = 'none';
+				$tp_val['description'] = 'description';
+				
+				$option_arr  = array();
+				$option_str = "";
+				foreach($d_goods['option'] as $option_val)
+				{
+					//$option_arr[] = $option_val['name'].':'.$option_val['value'];
+					$option_arr[] = $option_val['value'];
+				}
+				if(!empty($option_arr))
+				{
+					$option_str = implode(';', $option_arr);
+				}
+				
+				
+				$tp_val['can_buy'] = D('Home/Pingoods')->get_goods_time_can_buy($d_goods['goods_id']);
+				
+				$tp_val['goodstype'] = $option_str;
+				$tp_val['goodstypeedit'] = $option_str;
+				$tp_val['goodsnum'] = $d_goods['quantity'];
+				$tp_val['can_man_jian'] = $d_goods['can_man_jian'];
+				$tp_val['max_quantity'] = $d_goods['max_quantity'];
+				$tp_val['cartype'] = 'inline';
+				$tp_val['currntprice'] = $d_goods['price'];
+				$tp_val['price'] = $d_goods['shop_price'];
+				$tp_val['card_price'] = $d_goods['card_price'];
+				$tp_val['is_take_vipcard'] = $d_goods['is_take_vipcard'];
+				$tp_val['is_new_buy'] = $d_goods['is_new_buy'];
+				
+				$tmp_goods[] = $tp_val;
+				
+			}
+			
+			//$store_info = M('seller')->field('s_id,s_true_name,s_logo')->where( array('s_id' => $store_id) )->find();
+			//$store_info['s_logo'] = C('SITE_URL').'Uploads/image/'.$store_info['s_logo'];
+			
+			$store_info = array('s_true_name' => '','s_id' => 1);
+			$s_logo = D('Home/Front')->get_config_by_name('shoplogo');
+			
+			if( !empty($s_logo) )
+			{
+				$s_logo = tomedia($s_logo);
+			}
+					
+			$val['store_info'] = $store_info;
+			
+			$store_data = array();
+			$store_data['id'] = $store_info['s_id'];
+			if($is_store_ck)
+			{
+				$store_data['isselect'] = true;
+			} else {
+				$store_data['isselect'] = false;
+			}
+			
+			$store_data['shopname'] = $store_info['s_true_name'];
+			$store_data['caredit'] = 'inline';
+			$store_data['finish'] = 'none';
+			$store_data['count'] = '0.00';
+			
+			$is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
+			$full_money = D('Home/Front')->get_config_by_name('full_money');
+			$full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
+			
+			if(empty($full_reducemoney) || $full_reducemoney <= 0)
+			{
+				$is_open_fullreduction = 0;
+			}
+			
+			$store_data['is_open_fullreduction'] = $is_open_fullreduction;
+			$store_data['full_money'] = $full_money;
+			$store_data['full_reducemoney'] = $full_reducemoney;
+			
+			
+			
+			$store_data['goodstype'] = 2;
+			$store_data['goodstypeselect'] = 0;
+			$store_data['shopcarts'] = $tmp_goods;
+			
+			
+			$seller_goodss[$store_id] = $store_data;
+			$i++;
+		}
+		
+		// 商家是否休息
+		$is_comunity_rest = D('Seller/Communityhead')->is_community_rest($community_id);
+		$open_man_orderbuy = D('Home/Front')->get_config_by_name('open_man_orderbuy');
+		$man_orderbuy_money = D('Home/Front')->get_config_by_name('man_orderbuy_money');
+		//if($man_orderbuy_money > $max_can_orderbuy_money){
+			//$max_can_orderbuy_money = $man_orderbuy_money;
+		//}
+		$is_show_guess_like = D('Home/Front')->get_config_by_name('is_show_guess_like');
+		
+		
+		// 免配送 man_free_tuanzshipping>0开启
+		$delivery_type_ziti = D('Home/Front')->get_config_by_name('delivery_type_ziti');
+		$delivery_type_express = D('Home/Front')->get_config_by_name('delivery_type_express');
+		$delivery_type_tuanz = D('Home/Front')->get_config_by_name('delivery_type_tuanz');
+		$man_free_tuanzshipping = $delivery_tuanz_money = 0;
+		
+		//暂时屏蔽,2020.02.13.14:57
+		/**
+		if($delivery_type_ziti!=1 && $delivery_type_express!=1 && $delivery_type_tuanz==1) {
+			$man_free_tuanzshipping = D('Home/Front')->get_config_by_name('man_free_tuanzshipping');
+			if($man_free_tuanzshipping>1 && !empty($man_free_tuanzshipping)) {
+				$delivery_tuanz_money = D('Home/Front')->get_config_by_name('delivery_tuanz_money');
+			}
+		}
+		**/
+		
+		
+		if($delivery_type_tuanz==1) {
+			$man_free_tuanzshipping = D('Home/Front')->get_config_by_name('man_free_tuanzshipping');
+		}else{
+			$man_free_tuanzshipping =  0;
+		}
+
+		$open_tuan_ship = $delivery_type_tuanz;
+		//团长自定义配送开关
+		if($community_id&&$man_free_tuanzshipping>1) {
+			$community_modify_shipping = M('lionfish_community_head')->field('is_modify_shipping_method')->where( array('id' => $community_id) )->find();
+			$is_modify_shipping_method = $community_modify_shipping['is_modify_shipping_method'];
+			if($is_modify_shipping_method==1) {
+				$open_tuan_ship = 1;
+			} else if($is_modify_shipping_method==2){
+				$open_tuan_ship = 0;
+			}
+		}
+		
+		$delivery_tuanz_money = D('Home/Front')->get_config_by_name('delivery_tuanz_money');
+
+		$shopcar_tab_all_name = D('Home/Front')->get_config_by_name('shopcar_tab_all_name');
+		$shopcar_tab_express_name = D('Home/Front')->get_config_by_name('shopcar_tab_express_name');
+
+		
+		$is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
+        if($is_open_fullreduction){
+        	$full_list = D('Home/Front')->get_fullreduction();
+        }else{
+        	$full_list[0]['full_money']= 0 ;
+        	$full_list[0]['full_reducemoney']= 0 ;
+        }
+        
+        //同城配送信息
+        //配送费类型:0、固定金额,1、按距离收取
+        $localtown_delivery_moneytype = D('Home/Front')->get_config_by_name('localtown_delivery_moneytype');
+        $localtown_moneytype_fixed_deliverymoney = 0;
+        $localtown_moneytype_fixed_freemoney = 0;
+        if($localtown_delivery_moneytype == 0){
+            //起送价格
+            $localtown_moneytype_fixed_deliverymoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_deliverymoney');
+            //达到金额免配送费
+            $localtown_moneytype_fixed_freemoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_freemoney');
+        }
+		
+		$need_data = array();
+		$need_data['code'] = 0;
+		$need_data['carts'] = $seller_goodss;
+		$need_data['mult_carts'] = $seller_goodss_mult;
+		$need_data['is_comunity_rest'] = $is_comunity_rest;
+		$need_data['open_man_orderbuy'] = $open_man_orderbuy;
+		$need_data['man_orderbuy_money'] = $man_orderbuy_money;
+		//$need_data['max_can_orderbuy_money'] = $max_can_orderbuy_money;
+		$need_data['is_show_guess_like'] = $is_show_guess_like;
+		$need_data['man_free_tuanzshipping'] = $man_free_tuanzshipping;
+		$need_data['delivery_tuanz_money'] = $delivery_tuanz_money;
+		
+		$need_data['is_member_level_buy'] = $is_member_level_buy;//当前会员折扣 购买,1是,0否
+		$need_data['level_save_money'] = $level_save_money;//会员折扣省的钱
+				
+		$need_data['is_vip_card_member'] = $is_vip_card_member;//当前会员是否是 会员卡会员 0 不是,1是,2已过期
+		$need_data['vipcard_save_money'] = $vipcard_save_money;//vip能节约的金额
+		$need_data['is_open_vipcard_buy'] = $is_open_vipcard_buy;//vip能节约的金额
+		$need_data['modify_vipcard_name'] = $modify_vipcard_name;
+		
+		$need_data['shopcar_tab_all_name'] = $shopcar_tab_all_name;
+		$need_data['shopcar_tab_express_name'] = $shopcar_tab_express_name;
+		$need_data['open_tuan_ship'] = $open_tuan_ship;
+
+		$need_data['is_open_fullreduction'] = $is_open_fullreduction;
+        $need_data['full_list'] = $full_list;
+
+		//平台和供应商 起送价格和免配送费价格
+		//$need_data['localtown_fixed_list'] = $localtown_fixed_list;
+        
+        $need_data['localtown_moneytype_fixed_deliverymoney'] = $localtown_moneytype_fixed_deliverymoney;//起送价格
+        $need_data['localtown_moneytype_fixed_freemoney'] = $localtown_moneytype_fixed_freemoney;//达到金额免配送费
+		
+		echo json_encode( $need_data );
+		die();
+		
+	}
+	
+	public function checkout_flushall()
+	{
+		$gpc = I('request.');
+		
+		$token = $gpc['token'];
+		
+		$community_id = $gpc['community_id'];
+		
+		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
+		$member_id = $weprogram_token['member_id'];
+		
+		//dan soitaire
+		$buy_type  = isset($gpc['buy_type']) ? $gpc['buy_type'] : 'dan';
+		
+		//$car_prefix = 'soitairecart.';
+		
+		//buy_type和soli_id吗
+
+		$is_community = D('Seller/Communityhead')->is_community($community_id);
+		if( !$is_community )
+		{
+			$json['code'] =6;
+			$json['msg']='该小区已经不存在!';
+			echo json_encode($json);
+			die();
+		}
+
+		
+		$data = array();
+		$data['car_key'] = $gpc['car_key'];
+		$data['all_keys_arr'] = $gpc['all_keys_arr'];
+		$data['cur_car_key'] = $gpc['cur_car_key'];
+		//car_key:cart.6:MTc0:,cart.13:MjcwXzI3Mw==:
+		//all_keys_arr:cart.6:MTc0:_1,cart.13:MjcwXzI3Mw==:_1
+
+		$car_key = explode(',', $data['car_key']);
+		$all_keys_arr = explode(',', $data['all_keys_arr']) ;
+
+		if(!empty($data['cur_car_key'])){
+			$car_key = array($data['cur_car_key']);
+		}
+
+		$save_keys = array();
+		if(!empty($all_keys_arr)){
+			foreach($all_keys_arr as $val)
+			{
+				$tmp_val = explode('_', $val);
+				$save_keys[ $tmp_val[0] ] = $tmp_val[1];
+			}
+		}
+		
+		
+		
+		if( $buy_type == 'dan')
+		{
+			$all_cart = M('lionfish_comshop_car')->where("community_id={$community_id} and token='{$token}' and carkey like 'cart.%'")->select();
+		
+		}else if( $buy_type == 'soitaire' ){
+			$all_cart = M('lionfish_comshop_car')->where("community_id={$community_id} and token='{$token}' and carkey like 'soitairecart.%'")->select();	
+		}
+		
+		if(!empty($all_cart))
+		{
+			foreach($all_cart as $val)
+			{
+				$tmp_format_data = unserialize($val['format_data']);
+				$tmp_format_data['singledel'] = 0;
+				
+				
+				$tmp_format_data['quantity'] = isset( $save_keys[$val['carkey']] ) ? $save_keys[$val['carkey']] : $tmp_format_data['quantity'];
+				
+				
+				M('lionfish_comshop_car')->where( array('id' => $val['id'] ,'community_id' => $community_id) )->save( array('format_data' => serialize($tmp_format_data) ) );
+			}
+		}
+
+		if(!empty($car_key)){
+			foreach( $car_key as $key )
+			{
+				
+				$car_info = M('lionfish_comshop_car')->where( array('community_id' => $community_id,'carkey' => $key ,'token' => $token) )->find();
+				if( !empty($car_info) )
+				{
+					$tmp_format_data = unserialize($car_info['format_data']);
+					$tmp_format_data['singledel'] = 1;
+					$quantity = $tmp_format_data['quantity'];
+					$sku_quantity_one = $tmp_format_data['quantity'];
+					$goods_id = $tmp_format_data['goods_id'];
+					$sku_str = $tmp_format_data['sku_str'];
+					//同一个商品不同规格 总数量合计
+					$sku_quantity = $this->_check_goods_sku_quantity($community_id,$key,$token);
+					if($sku_quantity > $quantity) {
+						$quantity = $sku_quantity;
+					}
+					$goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'goods_start_count');
+					//起售数量判断
+					if($sku_quantity_one < $goods_description['goods_start_count'])
+					{
+
+						$json['code'] = 6;
+						$json['msg'] =  $goods_description['goods_start_count'].'份起售';
+						$json['max_quantity'] = $goods_description['goods_start_count'];
+						echo json_encode( $json );
+						die();
+					}
+					$check_json = $this->_check_can_buy($member_id, $goods_id,$quantity);
+					
+					
+					
+					if($check_json['code'] != 0)
+					{
+						$tmp_format_data['quantity'] = $check_json['count'];
+						
+						
+						M('lionfish_comshop_car')->where( array('id' =>  $car_info['id'], 'community_id' => $community_id) )->save( array('format_data' => serialize($tmp_format_data) ) );
+						echo json_encode( array('code' => 6,'msg' => $check_json['msg']) );
+						die();
+					}
+					
+					//check sku is ok 
+					
+					$check_json = $this->_check_goods_sku_canbuy($goods_id,$sku_str);
+					
+					if($check_json['code'] != 0)
+					{
+						echo json_encode( array('code' => 6,'msg' => $check_json['msg']) );
+						die();
+					}
+					
+					
+					$check_json = $this->_check_goods_quantity($goods_id,$sku_quantity_one,$sku_str);
+					
+					if($check_json['code'] != 0)
+					{
+						echo json_encode( array('code' => 6,'msg' => $check_json['msg']) );
+						die();
+					}
+				
+					M('lionfish_comshop_car')->where( array('id' => $car_info['id'], 'community_id' => $community_id) )->save( array('format_data' => serialize($tmp_format_data) ) );	
+				}		
+			}	
+		}
+		$is_limit_distance_buy = D('Home/Front')->get_config_by_name('shop_limit_buy_distance');
+
+		echo json_encode( array('code' => 0, 'data' => $is_limit_distance_buy) );
+		die();
+	}
+	
+	public function _check_goods_sku_quantity($community_id,$key,$token){
+		$quantity = 0;
+		$key_array = explode(":",$key);
+		$key_result = "";
+		foreach($key_array as $k=>$v){
+			if($k < 2){
+				if(empty($key_result)){
+					$key_result = $v;
+				}else{
+					$key_result = $key_result.":".$v;
+				}
+			}
+		}
+		$sql = "SELECT format_data FROM ".C('DB_PREFIX')."lionfish_comshop_car "
+			 . " WHERE carkey LIKE  '".$key_result."%' and community_id = '".$community_id."' "
+			 . " and token='".$token."'";
+		$cart_goods_list = M()->query($sql);
+		
+		if(!empty($cart_goods_list)){
+			foreach($cart_goods_list as $val)
+			{
+				$tmp_format_data = unserialize($val['format_data']);
+				$quantity = $quantity + $tmp_format_data['quantity'];
+			}
+		}
+		return $quantity;
+	}
+	
+	public function _check_goods_sku_canbuy($goods_id,$sku_str)
+	{
+		
+		$json = array('code' => 0);
+		
+		$goods_info = M('lionfish_comshop_goods')->field('goodsname as name')->where( array('id' => $goods_id ) )->find();
+		
+		if(!empty($sku_str))
+		{
+			$goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->field('stock as quantity')->where( array('option_item_ids' => $sku_str,'goods_id' => $goods_id) )->find();
+			
+			if( empty($goods_option_mult_value) )
+			{
+				$json['code'] =3;
+				$json['msg']=mb_substr($goods_info['name'],0,4,'utf-8').',规格已失效,删除后再结算';
+			}
+		}
+		
+		return $json;
+	}
+	
+	
+	public function del_car_goods()
+	{
+		$gpc = I('request.');
+		
+		
+		$token = $gpc['token'];
+		$community_id = $gpc['community_id'];
+		  
+		$carkey = $gpc['carkey'];
+		
+		
+		M('lionfish_comshop_car')->where( "community_id={$community_id} and token='{$token}' and carkey='{$carkey}'" )->delete();
+		
+		echo json_encode( array('code' => 0) );
+		die();
+		
+	}
+	
+	public function _check_goods_quantity($goods_id,$quantity,$sku_str)
+	{
+		$gpc = I('request.');
+		
+		
+		$goods_info = M('lionfish_comshop_goods')->field('goodsname as name')->where( array('id' => $goods_id) )->find();
+		
+		$goods_quantity= D('Home/Car')->get_goods_quantity($goods_id);
+
+
+		
+		$json = array('code' => 0);
+		
+		if($goods_quantity<$quantity){
+			$json['code'] =3;
+			$json['msg']= mb_substr($goods_info['name'],0,4,'utf-8').'...,商品数量不足,剩余'.$goods_quantity.'个!!';
+			
+		}else if(!empty($sku_str)){
+			$mul_opt_arr = array();
+			
+			$goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->field('stock as quantity')->where( array('option_item_ids' => $sku_str,'goods_id' => $goods_id) )->find();
+			
+			if( !empty($goods_option_mult_value) )
+			{
+				if($goods_option_mult_value['quantity']<$quantity){
+					$json['code'] =3;
+					$json['msg']=mb_substr($goods_info['name'],0,4,'utf-8').'...,商品数量不足,剩余'.$goods_option_mult_value['quantity'].'个!!';
+				}
+			}
+		}
+		return $json;
+	}
+	
+	private function _check_can_buy($member_id, $goods_id,$quantity)
+	{
+		$gpc = I('request.');
+		
+		//$can_buy_count =  D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
+
+		$goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'total_limit_count,one_limit_count,oneday_limit_count,is_new_buy,is_limit_levelunbuy,is_limit_vipmember_buy,goods_start_count');
+
+		//单次限购判断
+		if($goods_description['one_limit_count'] > 0 && $quantity > $goods_description['one_limit_count'])
+		{
+			$json['code'] = 6;
+			$json['msg'] = '您本次只能购买'.$goods_description['one_limit_count'].'份';
+			$json['count'] = $goods_description['one_limit_count'];
+			return $json;
+		}
+
+		$can_buy_day_count =  D('Home/Front')->check_goods_user_canbuy_day_count($member_id, $goods_id);
+		if($can_buy_day_count == -1 || ($can_buy_day_count > 0 && $quantity >$can_buy_day_count))
+		{
+			$json['code'] =6;
+			$json['msg'] = '您今天只能购买'.$goods_description['oneday_limit_count'].'份';
+			$json['count']=1;
+			return $json;
+		}else if($can_buy_day_count > 0 && $quantity > $can_buy_day_count){
+			$json['code'] =6;
+			$json['msg'] = '您今天还能购买'.$can_buy_day_count.'份';
+			$json['count']=$can_buy_day_count;
+			return $json;
+		}
+
+		$can_buy_all_count =  D('Home/Front')->check_goods_user_canbuy_all_count($member_id, $goods_id);
+		//历史限购判断
+		if($can_buy_all_count == -1 && $goods_description['total_limit_count'] >0)
+		{
+			$json['code'] =6;
+			$json['msg']='您最多只能购买'.$goods_description['total_limit_count'].'个';
+			$json['count'] = 1;
+			return $json;
+		}else if($can_buy_all_count > 0 && $quantity > $can_buy_all_count)
+		{
+			$json['code'] =6;
+			$json['msg']='您还能购买'.$can_buy_all_count.'份';
+			$json['count'] = $can_buy_all_count;
+			return $json;
+		}
+
+		$goods_info = M('lionfish_comshop_goods')->where( array('id' => $goods_id) )->find();
+		
+		$goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'per_number');
+
+		$can_buy_count =  D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
+		$json = array();
+		if($can_buy_count == -1 || $can_buy_day_count == -1)
+		{
+			$json['code'] =6;
+			$json['msg']=mb_substr($goods_info['name'],0,4,'utf-8').'...,您本次只能购买'.$goods_description['per_number'].'个';
+		}else if($can_buy_count >0 && $quantity >$can_buy_count)
+		{
+			$json['code'] =6;
+			//$json['msg']=mb_substr($goods_info['name'],0,4,'utf-8').'...,您还能购买'.$can_buy_count.'份';
+			$json['msg']='本次最多购买'.$can_buy_count.'份';
+			$json['count']=$can_buy_count;
+			
+		}else{
+			$json['code'] = 0;
+		}
+		return $json;
+	}
+	
+	private function _add_address($token,$userName,$telNumber,$provinceName,$cityName, $countyName,$detailInfo,$latitude='',$longitude='',$lou_meng_hao='')
+	{
+		$_GPC = I('request.');
+		
+		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
+		$member_id = $weprogram_token['member_id'];	
+		
+		
+		//  lionfish_comshop_area
+		
+		$province_info = M('lionfish_comshop_area')->where("name like '%{$provinceName}%' ")->find();
+		
+		if( !empty($province_info))
+		{
+			$province_id = $province_info['id'];
+		}else{
+			
+			
+			$area_data = array();
+			$area_data['name'] = $provinceName;
+			$area_data['pid'] = 0;
+			$area_data['code'] = $max_dp['code']+1;
+			
+			$province_id = M('lionfish_comshop_area')->add($area_data);
+			
+			$up_data = array();
+			$up_data['code'] = $province_id;
+			
+			M('lionfish_comshop_area')->where( array('id' => $province_id ) )->save($up_data);
+			
+		}
+
+        $guding_arr = ['鞍山市'];
+
+        if( in_array($cityName , $guding_arr) )
+        {
+            $city_info = M('lionfish_comshop_area')->where("name = '{$cityName}'")->find();
+        }else{
+            $city_info = M('lionfish_comshop_area')->where("name like '%{$cityName}%'")->find();
+        }
+
+		//$city_info = M('lionfish_comshop_area')->where("name like '%{$cityName}%'")->find();
+		
+		if( !empty($city_info))
+		{
+			$city_id = $city_info['id'];
+		}else{
+			
+			$max_dp = M('lionfish_comshop_area')->order('code desc')->find();
+			
+			$area_data = array();
+			$area_data['name'] = $cityName;
+			$area_data['pid'] = $province_id;
+			$area_data['code'] = $max_dp['code']+1;
+			
+			$city_id = M('lionfish_comshop_area')->add( $area_data);
+			
+			$up_data = array();
+			$up_data['code'] = $city_id;
+		
+			M('lionfish_comshop_area')->where( array('id' => $city_id ) )->save($up_data);
+			
+		}
+		
+		//city_name: 东莞市
+		if( empty($countyName)   )
+		{
+			if( $cityName == '东莞市' )
+			{
+				$countyName = '东莞';
+			}
+			if( $cityName == '中山市' )
+			{
+				$countyName = '中山';
+				//453
+			}
+		}
+		
+		$country_info = M('lionfish_comshop_area')->where( "name like '%{$countyName}%' " )->find();
+		
+		if( $countyName == '中山' )
+		{
+			
+			$country_info = M('lionfish_comshop_area')->where( array('id' => 453 ) )->find();
+			//
+		}
+		
+		
+		if( !empty($country_info))
+		{
+			$country_id = $country_info['id'];
+		}else{
+			
+			$max_dp = M('lionfish_comshop_area')->order('code desc')->find();
+			
+			$area_data = array();
+			$area_data['name'] = $countyName;
+			$area_data['pid'] = $city_id;
+			$area_data['code'] = $max_dp['code']+1;
+			
+			$country_id = M('lionfish_comshop_area')->add( $area_data );
+			
+			$up_data = array();
+			$up_data['code'] = $country_id;
+			
+			M('lionfish_comshop_area')->where( array('id' => $country_id ) )->save( $up_data );
+			
+		}
+		
+		
+		$address_param = array();
+		
+		$address_param['member_id'] = $member_id;
+		$address_param['province_id'] = $province_id;
+		$address_param['country_id'] = $country_id;
+		$address_param['city_id'] = $city_id;
+		$address_param['address'] = $detailInfo;
+		$address_param['name'] = $userName;
+		$address_param['telephone'] = $telNumber;
+		
+		$address_param['lon_lat'] = '';
+		$address_param['lou_meng_hao'] = $lou_meng_hao;
+	
+		if(!empty($latitude))
+		{
+			$address_param['lon_lat'] = $longitude.','.$latitude; 
+		}
+		
+		
+		
+		$has_addre = M('lionfish_comshop_address')->where($address_param)->find();
+		
+		if(empty($has_addre))
+		{
+			
+			$has_default_address = M('lionfish_comshop_address')->where( array('is_default' => 1,'member_id' => $member_id) )->find();
+			
+			
+			$address_data = array();
+			$address_data['member_id'] = $member_id;
+			$address_data['name'] = $userName;
+			$address_data['telephone'] = $telNumber;
+			$address_data['lou_meng_hao'] = $lou_meng_hao;
+			if(!empty($latitude))
+			{
+				$address_data['lon_lat'] = $longitude.','.$latitude; 
+			}else{
+				$address_data['lon_lat'] = ''; 
+			}
+			
+			$address_data['address'] = $detailInfo;
+			$address_data['address_name'] = empty($data['address_name']) ? 'HOME' : $data['address_name'];
+			if(!empty($has_default_address) && false)
+			{
+				$address_data['is_default'] = 0;
+			}else{
+				$data = array();
+				$data['is_default'] = 0;
+				
+				M('lionfish_comshop_address')->where( array('member_id' => $member_id ) )->save($data);
+				
+				$address_data['is_default'] = 1;
+			}
+			
+			$address_data['city_id'] = $city_id;
+			$address_data['country_id'] = $country_id;
+			$address_data['province_id'] = $province_id;
+			
+			$res = M('lionfish_comshop_address')->add($address_data);
+		}else{
+			$res = $has_addre['address_id'];
+		}
+		
+		return $res;
+	}
+	
+	public function checkout()
+	{
+		$gpc = I('request.');
+		
+		
+	  $buy_type = isset($gpc['buy_type']) ? $gpc['buy_type'] : 'dan';
+	  
+	  $pintuan_model_buy = D('Home/Front')->get_config_by_name('pintuan_model_buy');
+		
+	  if( empty($pintuan_model_buy) || $pintuan_model_buy ==0 )
+	  {
+		  $pintuan_model_buy = 0;
+	  }
+	  
+	   
+	  $mb_city_name = isset($gpc['mb_city_name']) ? $gpc['mb_city_name'] : '';
+	  
+	  if($buy_type == 'undefined')
+	  {
+		 $buy_type = 'dan'; 
+	  }
+	  
+	  $community_id = $gpc['community_id'];
+	  $token = $gpc['token'];
+	  
+	  $voucher_id = isset($gpc['voucher_id']) ? $gpc['voucher_id'] : 0;
+	  
+	  $soli_id = isset($gpc['soli_id']) ? intval($gpc['soli_id']) : '';
+	   
+	  $use_quan_str = isset($gpc['use_quan_str']) ? $gpc['use_quan_str'] : '';
+	  $use_quan_arr = array();
+	  
+	  if($use_quan_str != '')
+	  {
+		  $use_quan_arr_tmp = explode('@',$use_quan_str );
+		  foreach($use_quan_arr_tmp as $val)
+		  {
+			 $tmp_arr = explode('_', $val);
+			 $use_quan_arr[$tmp_arr[0]] = $tmp_arr[1];
+		  }
+	  }
+	  
+	  $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
+	  $member_id = $weprogram_token['member_id'];
+	
+	
+		$is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
+		$is_open_vipcard_buy = !empty($is_open_vipcard_buy) && $is_open_vipcard_buy ==1 ? 1:0; 
+
+		$is_vip_card_member = 0;
+		$is_member_level_buy = 0;
+
+		if( $member_id > 0 )
+		{
+			$member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
+			
+			if( !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 )
+			{
+				
+				$now_time = time();
+				
+				if( $member_info['card_id'] >0 && $member_info['card_end_time'] > $now_time )
+				{
+					$is_vip_card_member = 1;//还是会员
+				}else if( $member_info['card_id'] >0 && $member_info['card_end_time'] < $now_time ){
+					$is_vip_card_member = 2;//已过期
+				}
+			}
+			
+			if($is_vip_card_member != 1 && $member_info['level_id'] >0 )
+			{
+				$is_member_level_buy = 1;
+			}
+		}
+        //预售不开启会员卡
+		if($buy_type == 'pesale')
+        {
+           $is_member_level_buy = 0;
+          $is_vip_card_member = 0;
+        }
+			
+	
+	  if( empty($member_id) )
+	  {
+		  //需要登录
+		  echo json_encode( array('code' =>5) );
+		  die();
+	  }
+	
+	$cart = D('Home/Car');
+	
+	
+	
+	if ((!$cart->has_goodswecar($buy_type,$token,$community_id) ) ) {
+		//购物车中没有商品
+		echo json_encode( array('code' =>4) );
+		die();
+	}
+	
+	
+	$member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
+	
+	//soitaire
+	$goods=$cart->get_all_goodswecar($buy_type, $token,1,$community_id,$soli_id);
+
+	
+	$address = M('lionfish_comshop_address')->where( array('member_id' => $member_id) )->order('is_default desc,address_id desc')->find();
+	
+	$add_old_order = M('lionfish_comshop_order')->field('address_id')->where(  " (delivery ='localtown_delivery' or delivery = 'express') and member_id = {$member_id} " )->order('order_id desc')->find();
+	
+	if( !empty($add_old_order) && $add_old_order['address_id'] > 0)
+	{
+		$address = M('lionfish_comshop_address')->where( array('address_id' => $add_old_order['address_id'],'member_id' => $member_id) )->find();	
+	}
+	
+	$mb_city_id = 0;
+	if(!empty($mb_city_name))
+	{
+		$mb_city_info = M('lionfish_comshop_area')->where(" name='{$mb_city_name}' ")->find();
+		
+		if( !empty($mb_city_info) )
+		{
+			$mb_city_id = $mb_city_info['id'];
+		}			
+		
+	}
+
+	if($address){
+		
+		//get_area_info($id)
+		$province_info =  D('Home/Front')->get_area_info($address['province_id']);// M('area')->field('area_name')->where( array('area_id' => $address['province_id']) )->find();
+		$city_info = D('Home/Front')->get_area_info($address['city_id']);//M('area')->field('area_name')->where( array('area_id' => $address['city_id']) )->find();
+		$country_info = D('Home/Front')->get_area_info($address['country_id']);//M('area')->field('area_name')->where( array('area_id' => $address['country_id']) )->find();
+		
+		$address['province_name'] = $province_info['name'];
+		$address['city_name'] = $city_info['name'];
+		$address['country_name'] = $country_info['name'];
+	}else{
+		$address = array();
+	}
+	
+	$seller_goodss = array();
+	$show_voucher = 0;
+	
+	//判断是否仅快递的配送方式  is_only_express
+	
+	$is_open_only_express = D('Home/Front')->get_config_by_name('is_open_only_express');
+					
+	$is_only_express = 0;
+	
+	if( !empty($is_open_only_express) && $is_open_only_express == 1)
+	{
+		$is_only_express = 1;
+	}
+	/**
+	if($is_vip_card_member != 1 && $member_info['level_id'] >0 )
+	{
+	    $is_member_level_buy = 1;
+	}
+	**/
+	foreach($goods as $key => $val)
+	{
+		//$goods_store_field =  M('goods')->field('store_id')->where( array('goods_id' => $val['goods_id']) )->find();
+		if( $is_only_express == 1 && $val['is_only_express'] != 1 )
+		{
+			$is_only_express = 0;
+		}
+		if($is_only_express == 0 && $val['is_only_express'] == 3 )
+		{
+			$is_only_express = 3;
+		}
+		if($is_only_express == 0 && $val['is_only_express'] == 2 )
+		{
+			$is_only_express = 2;
+		}
+
+		$supply_id = D('Home/Front')->get_goods_supply_id($val['goods_id']);
+		if($supply_id > 0)
+		{
+			$supply_info = D('Home/Front')->get_supply_info($supply_id);
+			
+			if($supply_info['type'] ==0)
+			{
+				$supply_id = 0;
+			}
+		}
+		$val['name'] = htmlspecialchars_decode($val['name']);
+		$seller_goodss[ $supply_id ]['goods'][$key] = $val;
+	}
+
+	//begin 如果是同城配送 ,查一查有没有新提交的地址,如果有,按照新的来处理
+
+    $localtown_address = array();
+
+    if( $is_only_express  == 3 )
+    {
+        $localtown_old_order = M('lionfish_comshop_order')->field('address_id')->where(  array('delivery' => 'localtown_delivery','member_id' => $member_id) )->order('order_id desc')->find();
+
+        $localtown_id = 0;
+
+
+        if( !empty($localtown_old_order) && $localtown_old_order['address_id'] > 0)
+        {
+            $localtown_address = M('lionfish_comshop_address')->where( array('address_id' => $localtown_old_order['address_id'],'member_id' => $member_id) )->find();
+
+            if(!empty($localtown_address))
+            {
+                $province_info =  D('Home/Front')->get_area_info($address['province_id']);// M('area')->field('area_name')->where( array('area_id' => $address['province_id']) )->find();
+                $city_info = D('Home/Front')->get_area_info($address['city_id']);//M('area')->field('area_name')->where( array('area_id' => $address['city_id']) )->find();
+                $country_info = D('Home/Front')->get_area_info($address['country_id']);//M('area')->field('area_name')->where( array('area_id' => $address['country_id']) )->find();
+
+                $localtown_address['province_name'] = $province_info['name'];
+                $localtown_address['city_name'] = $city_info['name'];
+                $localtown_address['country_name'] = $country_info['name'];
+
+            }else if( isset($gpc['longitude']) && isset($gpc['latitude']) )
+            {
+                $localtown_address['lon_lat'] = $gpc['longitude'].','.$gpc['latitude'];
+            }
+        }else{
+            $address = array();
+        }
+
+    }
+    //end同城配送
+
+	$quan_model = D('Home/Voucher'); 
+	$pin_model = D('Home/Pin');
+	
+	
+	$voucher_price = 0;
+	$reduce_money = 0;
+	$cha_reduce_money = 0;
+	
+	$is_pin_over = 0;
+	$is_moban =  false;
+	
+	
+	
+	$is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
+	$full_money = D('Home/Front')->get_config_by_name('full_money');
+	$full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
+	
+	if(empty($full_reducemoney) || $full_reducemoney <= 0)
+	{
+		$is_open_fullreduction = 0;
+	}
+
+	$show_voucher = 0;
+		
+	$voucher_can_use =1;//目前都是平台券,
+	$man_total_free = 0;
+	$store_buy_total_money = 0;
+	
+	$pin_id = 0;
+	$presale_goods_id = 0;//预售商品id
+    $presale_goods_total = 0;//预售商品价格
+
+	$is_zero_buy = 0;
+	$vipcard_save_money = 0;
+	$level_save_money = 0;
+
+	$today_time = time();
+	$arr = array('天','一','二','三','四','五','六');
+	//计算优惠券
+	foreach($seller_goodss as $store_id => $val)
+	{
+		
+		$seller_voucher_list = array();
+		$seller_total_fee = 0;
+		$total_trans_free = 0;
+		$is_no_quan = false;
+		
+		
+		$total_weight = 0;
+		$total_quantity = 0;
+		$vch_goods_ids =  array();
+		
+		
+		foreach($val['goods'] as $kk =>$d_goods)
+		{
+		    //预售不参与会员卡
+			if($d_goods['is_take_vipcard'] == 1)
+			{	
+				$vipcard_save_money += $d_goods['total'] - $d_goods['card_total'];
+			}else if( $d_goods['is_mb_level_buy'] == 1 && $d_goods['is_mb_level_buy'] == 1 && $is_member_level_buy == 1)
+			{
+				$level_save_money += $d_goods['total'] - $d_goods['level_total'];
+			}
+			
+			if( $is_vip_card_member == 1 && $d_goods['is_take_vipcard'] == 1 )
+			{
+				$seller_total_fee += $d_goods['card_total'];
+				if( $store_id == 0 )
+				{
+					$store_buy_total_money += $d_goods['card_total'];
+				}
+				if( $d_goods['can_man_jian'] == 1)
+				{
+					$man_total_free += $d_goods['card_total'];
+					
+				}
+			}
+			else if( $d_goods['is_mb_level_buy'] == 1 && $member_info['level_id'] >0 )
+			{
+				$seller_total_fee += $d_goods['level_total'];
+				if( $store_id == 0 )
+				{
+					$store_buy_total_money += $d_goods['level_total'];
+				}
+				if( $d_goods['can_man_jian'] == 1)
+				{
+					$man_total_free += $d_goods['level_total'];
+				}
+			}
+			else
+			{
+				$seller_total_fee += $d_goods['total'];
+				if( $store_id == 0 )
+				{
+					$store_buy_total_money += $d_goods['total'];
+				}
+				if( $d_goods['can_man_jian'] == 1)
+				{
+					$man_total_free += $d_goods['total'];
+
+				}
+
+			}
+			
+			
+			if($buy_type == 'pintuan' && $d_goods['pin_id'] > 0)
+			{
+				$is_pin_over = $pin_model->getNowPinState($d_goods['pin_id']);
+				if( $is_pin_over == 2 )
+				{
+					$is_zero_buy = $pin_model->check_goods_iszero_opentuan( $d_goods['goods_id'] );
+				}
+			}else if($buy_type == 'pintuan' && $d_goods['pin_id'] == 0)
+			{
+				$is_zero_buy = $pin_model->check_goods_iszero_opentuan( $d_goods['goods_id'] );
+			}
+
+			if( $buy_type == 'presale' )
+            {
+                $presale_goods_id = $d_goods['goods_id'];
+                $presale_goods_total = $seller_total_fee;
+            }
+			$tp_goods_info = M('lionfish_comshop_goods')->field('type')->where( array('id' => $d_goods['goods_id']) )->find();	
+			
+			$vch_goods_ids[$d_goods['goods_id']] = $vch_goods_ids[$d_goods['goods_id']] + $d_goods['total'];
+			//$is_no_quan = true;
+			//预售不开启优惠券 
+			if($tp_goods_info['type'] == 'integral' || $tp_goods_info['type'] == 'presale' )
+			{
+				$is_no_quan = true;
+			}
+			
+			if($d_goods['shipping']==0)
+			{
+				$is_moban = true;
+				$val['is_moban'] = true;
+				$total_weight += $d_goods['weight']*$d_goods['quantity'];
+				$total_quantity += $d_goods['quantity'];
+			}
+			
+			$d_goods[$kk]['trans_free'] = 0;
+			/**
+			if($d_goods['shipping']==1)
+			{
+				//统一运费
+				$d_goods[$kk]['trans_free'] = $d_goods['goods_freight'];
+			}else {
+				//运费模板
+				 if(!empty($address))
+				{
+					$trans_free = load_model_class('transport')->calc_transport($d_goods['transport_id'], $d_goods['quantity'],$d_goods['quantity']*$d_goods['weight'], $address['city_id'] );
+				}else{
+					$trans_free = 0;
+				}
+			   $d_goods[$kk]['trans_free'] = $trans_free;
+			}
+			**/
+			
+			$total_trans_free  += $d_goods[$kk]['trans_free'];
+			//自提时间
+			$goods_info = M('lionfish_comshop_good_common')->field('pick_up_type,pick_up_modify')->where( array('goods_id' => $d_goods['goods_id']) )->find();
+			$pick_up_type = -1;
+			if($pick_up_type == -1 || $goods_info['pick_up_type'] > $pick_up_type)
+			{
+				$pick_up_type = $goods_info['pick_up_type'];
+
+				if($pick_up_type == 0)
+				{
+					$pick_up_time = date('m-d', $today_time);
+					$pick_up_weekday = '周'.$arr[date('w',$today_time)];
+				}else if( $pick_up_type == 1 ){
+					$pick_up_time = date('m-d', $today_time+86400);
+					$pick_up_weekday = '周'.$arr[date('w',$today_time+86400)];
+				}else if( $pick_up_type == 2 )
+				{
+					$pick_up_time = date('m-d', $today_time+86400*2);
+					$pick_up_weekday = '周'.$arr[date('w',$today_time+86400*2)];
+				}else if($pick_up_type == 3)
+				{
+					$pick_up_time = $goods_info['pick_up_modify'];
+				}
+			}
+			$d_goods['pick_up_type'] = $pick_up_type;
+			$d_goods['pick_up_time'] = $pick_up_time;
+			$d_goods['pick_up_weekday'] = $pick_up_weekday;
+
+			$val['goods'][$kk] = $d_goods;
+			
+		}
+		
+		$val['reduce_money'] = 0;
+		
+		//pindan (拼团商品单独购买)   pintuan (拼团)
+		//预售关闭满减 
+		if($buy_type == 'pindan' || $buy_type == 'pintuan' || $buy_type == 'integral' || $buy_type == 'presale')
+		{
+		    $is_open_fullreduction = 0;
+		}
+		
+		//原来满级计算man_total_free
+		/*if($is_open_fullreduction == 1 && $man_total_free >= $full_money )
+		 {
+		 $val['reduce_money'] = $full_reducemoney;
+		 $reduce_money = $full_reducemoney;
+		 }else if($is_open_fullreduction == 1 && $man_total_free < $full_money)
+		 {
+		 $cha_reduce_money = $full_money - $man_total_free;
+		 }*/
+		/**
+		 * 新满减计算
+		 */
+		
+		if($is_open_fullreduction == 1)
+		{
+		    $reduce_result = D('Home/Front')->get_reduce_money($man_total_free);
+
+		    $val['reduce_money'] = $reduce_result['reduce_money'];
+		    $reduce_money = $reduce_result['reduce_money'];
+		    $cha_reduce_money = $reduce_result['cha_reduce_money'];
+		}
+		
+		$chose_vouche = array();
+		
+		if(!$is_no_quan)
+		{
+
+			$vouche_list = $quan_model->get_user_canpay_voucher($member_id,$store_id,$seller_total_fee,'',$vch_goods_ids);
+			
+			$vouche_list = $quan_model->get_voucher_amout_bygoods($vouche_list,$val['goods'],$reduce_money);
+			//var_dump(  $vouche_list );
+			//die();
+			
+			if(!empty($vouche_list) && empty($use_quan_arr) ) {
+				$ling_vouche_list = $vouche_list;
+				if($voucher_can_use == 1)
+				{
+					$voucher_can_use++;
+					
+					$show_voucher = 1;
+					reset($ling_vouche_list);
+					$chose_vouche = current($ling_vouche_list);
+					//$voucher_price += $chose_vouche['credit'];
+					$voucher_price += $chose_vouche['can_vouche_amount'];
+					
+					//$seller_total_fee = round( $seller_total_fee - $chose_vouche['credit'], 2);
+					$seller_total_fee = round( $seller_total_fee - $chose_vouche['can_vouche_amount'], 2);
+				}
+				
+			}else if( !empty($vouche_list) &&  !empty($use_quan_arr) )
+			{
+				
+				foreach($vouche_list as $tmp_voucher)
+				{
+					if($tmp_voucher['id'] == $use_quan_arr[$store_id]) 
+					{
+						$show_voucher = 1;
+						$chose_vouche = $tmp_voucher;
+						//$seller_total_fee = round( $seller_total_fee - $chose_vouche['credit'], 2);
+						//$voucher_price += $chose_vouche['credit'];
+						$seller_total_fee = round( $seller_total_fee - $chose_vouche['can_vouche_amount'], 2);
+						$voucher_price += $chose_vouche['can_vouche_amount'];
+
+						break;
+					}
+				}
+			}
+			
+		}
+		
+		
+		
+		$val['chose_vouche'] = $chose_vouche;
+		$val['show_voucher'] = $show_voucher;
+		
+		$val['voucher_list'] = $vouche_list;
+		$val['total'] = $seller_total_fee;
+		
+		if($val['total'] < 0)
+		{
+			$val['total'] = 0;
+		}
+		
+		$val['trans_free'] = $total_trans_free;
+
+		$val['total_weight'] = $total_weight;
+		$val['total_quantity'] = $total_quantity;
+		
+		$s_logo = D('Home/Front')->get_config_by_name('shoplogo');
+		$shoname = D('Home/Front')->get_config_by_name('shoname');
+		if( !empty($s_logo) )
+		{
+			$s_logo = tomedia( $s_logo );
+		}
+		
+		$store_info = array('s_id' => $store_id,'s_true_name' => $shoname,'s_logo' => $s_logo );
+		
+		if( !empty($store_id) && $store_id > 0 )
+		{
+			 $supply_info = D('Home/Front')->get_supply_info($store_id);
+			 //logo
+			 if( !empty($supply_info) )
+			 {
+				 $store_info['s_true_name'] = $supply_info['shopname'];
+				 $store_info['s_logo'] = tomedia( $supply_info['logo'] );
+			 }
+		}
+		
+		$val['store_info'] = $store_info;
+		
+		$seller_goodss[$store_id] = $val;
+	}
+	
+	$trans_free_toal = 0;//运费
+   
+	//delivery_type_ziti  delivery_type_express    delivery_type_tuanz  delivery_tuanz_money
+	
+	$delivery_type_ziti = D('Home/Front')->get_config_by_name('delivery_type_ziti');
+	$delivery_type_express = D('Home/Front')->get_config_by_name('delivery_type_express');
+	$delivery_type_tuanz = D('Home/Front')->get_config_by_name('delivery_type_tuanz');
+	$delivery_tuanz_money = D('Home/Front')->get_config_by_name('delivery_tuanz_money');
+	//---
+	$man_free_tuanzshipping = D('Home/Front')->get_config_by_name('man_free_tuanzshipping');
+	$man_free_shipping = D('Home/Front')->get_config_by_name('man_free_shipping');
+	
+	$delivery_express_name = D('Home/Front')->get_config_by_name('delivery_express_name');
+	
+	
+	if( empty($man_free_tuanzshipping) || $buy_type == 'integral')
+    {
+        $man_free_tuanzshipping = 0;
+    }
+    //关闭团长配送费 免  预售 
+    if( empty($man_free_tuanzshipping) || $buy_type == 'presale' )
+    {
+        $man_free_tuanzshipping = 0;
+    }
+	if( empty($man_free_shipping) || $buy_type == 'integral' )
+	{
+		$man_free_shipping = 0;
+	}
+        //关闭快递配送费 免  预售 
+	if( empty($man_free_shipping) || $buy_type == 'presale' )
+	{
+		$man_free_shipping = 0;
+	}
+
+	
+	//if( $buy_type == 'dan' )
+	if( $buy_type == 'dan'  || $buy_type == 'soitaire' || ($pintuan_model_buy == 1 && $buy_type != 'dan' && $buy_type != 'integral'  ) )			
+	{
+		//...判断团长是否开启自定义的情况 store_buy_total_money
+		$community_info_modify = M('lionfish_community_head')->field('is_modify_shipping_method,is_modify_shipping_fare,shipping_fare')->where( array('id' => $community_id) )->find();				
+								
+		
+		if( !empty($community_info_modify['is_modify_shipping_method']) && $community_info_modify['is_modify_shipping_method'] == 1 && $delivery_type_tuanz == 1)
+		{
+			//开启配送
+			$delivery_type_tuanz = 1;
+			
+			if( !empty($community_info_modify['is_modify_shipping_fare']) && $community_info_modify['is_modify_shipping_fare'] == 1 && $community_info_modify['shipping_fare'] > 0 )
+			{
+				$delivery_tuanz_money = $community_info_modify['shipping_fare'];
+			}
+			
+			
+		}else if( !empty($community_info_modify['is_modify_shipping_method']) && $community_info_modify['is_modify_shipping_method'] == 2 )
+		{
+			//关闭配送
+			$delivery_type_tuanz = 0;
+		}
+	}else if( $buy_type == 'pindan' || $buy_type == 'pintuan' ){
+		if($pintuan_model_buy == 0)
+		{
+			$delivery_type_tuanz = 0;
+			$delivery_type_express = 1;
+			$delivery_type_ziti = 2;
+		}
+	}else if( $buy_type == 'integral' )
+	{
+		$delivery_type_tuanz = 0;
+		$delivery_type_express = 1;
+		$delivery_type_ziti = 2;
+	}
+
+	foreach($val['goods'] as $kk =>$d_goods)
+	{
+		if($d_goods['is_only_express'] == 1){
+			$delivery_type_express = 1;
+		}
+	}
+	
+	$is_man_delivery_tuanz_fare = 0;//是否达到满xx减团长配送费
+	$fare_man_delivery_tuanz_fare_money = 0;//达到满xx减团长配送费, 减了多少钱
+	
+	if( ( $buy_type == 'dan' || $buy_type == 'soitaire' ) && !empty($man_free_tuanzshipping) && $man_free_tuanzshipping > 0 && $man_free_tuanzshipping <= $store_buy_total_money )
+	{
+		//$delivery_tuanz_money = 0;
+		$is_man_delivery_tuanz_fare = 1;
+		$fare_man_delivery_tuanz_fare_money = $delivery_tuanz_money;
+	}
+	
+	$is_man_shipping_fare = 0;//是否达到满xx减运费
+	$fare_man_shipping_fare_money = 0;//达到满xx减运费,司机减了多少运费
+	
+	//----开始计算运费 //dispatchtype
+	
+	if($delivery_type_express == 1)
+	{
+		//ims_ 
+		$store_trans_free_toal = 0;
+		 if($mb_city_id > 0){
+			
+			$shipping_default = M('lionfish_comshop_shipping')->where(array('enabled' => 1))->order('isdefault desc,id desc')->find();
+			
+			foreach($seller_goodss as $store_id => $val)
+			{
+				//$val['is_moban'] = true;
+				$store_shipping_fare = 0;
+				if(  isset($val['is_moban']) && $val['is_moban'] )
+				{
+					$store_shipping_fare = D('Home/Transport')->calc_transport($shipping_default['id'], $val['total_quantity'],$val['total_weight'], $mb_city_id );
+					
+				}
+				
+				
+				$val['store_shipping_fare'] = $store_shipping_fare;
+				
+				$trans_free_toal += $store_shipping_fare;
+				if( $store_id == 0 )
+				{
+					$store_trans_free_toal += $store_shipping_fare;
+				}
+				
+				foreach($val['goods'] as $kk =>$d_goods)
+				{
+					if($d_goods['shipping']==1)
+					{
+						//统一运费
+						$trans_free_toal += $d_goods['goods_freight'];
+						if( $store_id == 0 )
+						{
+							$store_trans_free_toal += $d_goods['goods_freight'];
+						}
+					}
+				}
+			}
+			
+		}else if(!empty($address) && $mb_city_id == 0)
+		{
+			
+			$shipping_default = M('lionfish_comshop_shipping')->where( array('enabled' => 1) )->order('isdefault desc,id desc')->find();
+			
+			foreach($seller_goodss as $store_id => $val)
+			{
+				$store_shipping_fare = 0;
+				if(isset($val['is_moban']) && $val['is_moban'])
+				{
+					$store_shipping_fare = D('Home/Transport')->calc_transport($shipping_default['id'], $val['total_quantity'],$val['total_weight'], $address['city_id'] );
+				
+				}
+				$val['store_shipping_fare'] = $store_shipping_fare;
+				
+				$trans_free_toal += $store_shipping_fare;
+				
+				if( $store_id == 0 )
+				{
+					
+					$store_trans_free_toal += $store_shipping_fare;
+				}
+				
+				foreach($val['goods'] as $kk =>$d_goods)
+				{
+					if($d_goods['shipping']==1)
+					{
+						//统一运费
+						$trans_free_toal += $d_goods['goods_freight'];
+						$val['store_shipping_fare'] += $d_goods['goods_freight'];
+						
+						if( $store_id == 0 )
+						{
+							$store_trans_free_toal += $d_goods['goods_freight'];
+						}
+					}
+				}
+			}
+			
+		}else{
+			$trans_free_toal = 0;
+		}
+		
+		//
+		
+		if( !empty($man_free_shipping) && $man_free_shipping > 0 && $man_free_shipping <= $store_buy_total_money )
+		{
+			
+			$fare_man_shipping_fare_money = $store_trans_free_toal;
+			$is_man_shipping_fare = 1;
+			//$trans_free_toal = 0;
+		}
+	}
+	//礼品卡配送费0
+	if( $buy_type == 'virtualcard' )
+    {
+        $trans_free_toal = 0;
+    }
+	//---结束结算运费
+
+
+	if( empty($delivery_type_ziti) )
+	{
+		$delivery_type_ziti = 1;//开启
+	}
+	if( empty($delivery_type_express) )
+	{
+		$delivery_type_express = 2;
+	}
+	if( empty($delivery_type_tuanz) )
+	{
+		$delivery_type_tuanz = 2;
+	}
+
+	//默认关闭同城配送
+    $delivery_type_localtown = 0;
+	//默认关闭核销商品
+	$delvery_type_hexiao = 0;
+	//is_only_express
+	if( $is_only_express == 1 )
+	{
+		$delivery_type_ziti = 2;
+		$delivery_type_express = 1;
+		$delivery_type_tuanz = 2;
+	}else if( $is_only_express == 3 )
+	{
+		//同城配送
+		$delivery_type_ziti = 0;
+		$delivery_type_express = 0;
+		$delivery_type_tuanz = 0;
+        $delivery_type_localtown = 1;
+	}else if( $is_only_express == 2 )
+	{
+		//核销商品
+		$delivery_type_ziti = 0;
+		$delivery_type_express = 0;
+		$delivery_type_tuanz = 0;
+		$delivery_type_localtown = 0;
+		$delvery_type_hexiao = 1;
+	}
+	
+	
+	
+	$total_free = 0;
+	$is_ziti = 2;
+	
+	$pick_up_time = "";
+	$pick_up_type = -1;
+	$pick_up_weekday = '';
+	$today_time = time();
+	
+	$arr = array('天','一','二','三','四','五','六');
+	
+	$pick_up_arr = array();
+	foreach($goods as $key => $good)
+	{
+		//暂时关闭
+		//ims_lionfish_comshop_goods
+		//ims_ lionfish_comshop_good_common
+		
+		$goods_info = M('lionfish_comshop_good_common')->field('pick_up_type,pick_up_modify')->where( array('goods_id' => $good['goods_id']) )->find();				
+						
+		if($pick_up_type == -1 || $goods_info['pick_up_type'] > $pick_up_type)
+		{
+			$pick_up_type = $goods_info['pick_up_type'];
+			
+			if($pick_up_type == 0)
+			{
+				$pick_up_time = date('m-d', $today_time);
+				$pick_up_weekday = '周'.$arr[date('w',$today_time)];
+			}else if( $pick_up_type == 1 ){
+				$pick_up_time = date('m-d', $today_time+86400);
+				$pick_up_weekday = '周'.$arr[date('w',$today_time+86400)];
+			}else if( $pick_up_type == 2 )
+			{
+				$pick_up_time = date('m-d', $today_time+86400*2);
+				$pick_up_weekday = '周'.$arr[date('w',$today_time+86400*2)];
+			}else if($pick_up_type == 3)
+			{
+				$pick_up_time = $goods_info['pick_up_modify'];
+			}
+		}
+
+		$goods[$key]['trans_free'] = $good['goods_freight'];
+
+		if( $is_vip_card_member == 1 && $good['is_take_vipcard'] == 1 )
+		{
+			$total_free += $good['card_total'];
+		}
+		else if( $good['is_mb_level_buy'] == 1  && $member_info['level_id'] >0 )
+		{
+			$total_free += $good['level_total'];
+		}
+		else
+		{
+			$total_free += $good['total'];
+		}
+		
+	}
+
+    //同城配送费
+    $localtown_shipping_fare = 0;
+    //包装费
+    $picking_fare = 0;
+    $picking_fare_arr = array();
+    $localtown_shipping_fare_arr = array();
+    $localtown_dispatchtime = 0;//预计一共需要配送多少分钟
+	$localtown_expected_delivery = array();//预计送达时间段
+	$localtown_modifypickingname = "";//包装费标题
+    if( $is_only_express == 3 )
+    {
+        $picking_fare_arr =  D('Home/LocaltownDelivery')->calc_packing_money( $seller_goodss );// $seller_goodss;
+        $picking_fare = $picking_fare_arr['total_picking_fare'];
+
+        $localtown_dispatchtime = D('Home/LocaltownDelivery')->get_order_dispatchtime($seller_goodss);
+
+
+        if(  isset($gpc['latitude']) && !empty($gpc['latitude'])  &&  isset($gpc['longitude']) && !empty($gpc['longitude']) )
+        {
+
+            $lon = $gpc['longitude'];
+
+            $lat = $gpc['latitude'];
+
+            $localtown_shipping_fare_arr = D('Home/LocaltownDelivery')->calc_shipping_fare( $lon, $lat , $seller_goodss );
+
+            $localtown_shipping_fare = $localtown_shipping_fare_arr['total_shipping_fare'];
+
+            $trans_free_toal = $localtown_shipping_fare;
+
+
+        }else if( !empty($localtown_address) )
+        {
+            list($lon,$lat) = explode(',', $localtown_address['lon_lat'] );
+
+            $localtown_shipping_fare_arr = D('Home/LocaltownDelivery')->calc_shipping_fare( $lon, $lat , $seller_goodss );
+
+            $localtown_shipping_fare = $localtown_shipping_fare_arr['total_shipping_fare'];
+
+            $trans_free_toal = $localtown_shipping_fare;
+        }
+
+		//配送时间段间隔
+		$localtown_expected_delivery = D('Home/LocaltownDelivery')->get_expected_delivery($localtown_dispatchtime);
+
+		$localtown_modifypickingname = D('Home/Front')->get_config_by_name('localtown_modifypickingname');
+		$localtown_modifypickingname = !empty($localtown_modifypickingname) ? $localtown_modifypickingname: '包装费';
+    }
+	
+	//暂时关闭自提代码
+	/**
+	if(!empty($pick_up))
+	{
+		$pick_up = unserialize($pick_up);
+		$pick_up_ids = implode(',',$pick_up);
+		$pick_up_arr = M('pick_up')->where( array('id'=>array('in',$pick_up_ids)) )->select();
+	}
+	**/		
+	
+   
+	$pick_up_name = '';
+	$pick_up_mobile = '';
+	$tuan_send_address = '';
+	$order_note_content = '';
+	
+	$tuan_send_address_info = array();
+	
+	$shop_limit_buy_distance = D('Home/Front')->get_config_by_name('shop_limit_buy_distance');
+	
+	
+	
+	
+	if($is_ziti >= 1)
+	{
+		//寻找上一个订单的自提电话 自提姓名  
+		
+		$last_order_info = M('lionfish_comshop_order')->where( array('member_id' => $member_id,'delivery' => 'pickup') )->order('order_id desc')->find();
+		if(empty($last_order_info)){
+			$last_order_info = M('lionfish_comshop_order')->where( array('member_id' => $member_id,'delivery' => 'hexiao') )->order('order_id desc')->find();
+		}
+		if(!empty($last_order_info))
+		{
+			$pick_up_name = $last_order_info['shipping_name'];
+			$pick_up_mobile = $last_order_info['telephone'];
+			$order_note_content = $last_order_info['note_content'];
+		}
+		
+		//order_note_content
+		$last_tuanz_send_order_info = M('lionfish_comshop_order')->field('tuan_send_address,address_id,note_content,order_id')->where( array('member_id' =>$member_id,'delivery' => 'tuanz_send' ) )->order('order_id desc')->find();					
+		
+		if(!empty($last_tuanz_send_order_info))
+		{
+			$tuan_send_address = $last_tuanz_send_order_info['tuan_send_address'];
+			
+			if( !empty($last_tuanz_send_order_info['note_content']) && $last_tuanz_send_order_info['order_id'] > $last_order_info['order_id'] )
+			{
+				$order_note_content = $last_tuanz_send_order_info['note_content'];
+			}
+			
+			if( !empty($last_tuanz_send_order_info['address_id']) )
+			{
+				
+				if($shop_limit_buy_distance == 1)
+				{
+					$tuan_send_address_info = M('lionfish_comshop_address')->where( "address_id=".$last_tuanz_send_order_info['address_id']." and lon_lat != '' " )->find();
+					
+				}else{
+					
+					$tuan_send_address_info = M('lionfish_comshop_address')->where( "address_id=".$last_tuanz_send_order_info['address_id'] )->find();
+					
+				}
+				
+				if( !empty($tuan_send_address) && !empty($tuan_send_address_info['lon_lat']) )
+				{
+					$province_info =  D('Home/Front')->get_area_info($tuan_send_address_info['province_id']);// M('area')->field('area_name')->where( array('area_id' => $address['province_id']) )->find();
+					$city_info = D('Home/Front')->get_area_info($tuan_send_address_info['city_id']);//M('area')->field('area_name')->where( array('area_id' => $address['city_id']) )->find();
+					$country_info = D('Home/Front')->get_area_info($tuan_send_address_info['country_id']);//M('area')->field('area_name')->where( array('area_id' => $address['country_id']) )->find();
+					
+					$tuan_send_address_info['province_name'] = $province_info['name'];
+					$tuan_send_address_info['city_name'] = $city_info['name'];
+					$tuan_send_address_info['country_name'] = $country_info['name'];
+					
+					$tuan_send_address = $tuan_send_address_info['address'];
+				}else{
+					//todo...
+					$tuan_send_address = '';
+				}
+				
+			}else{
+				$tuan_send_address = '';
+			}
+			
+		}
+	}
+	/**
+	**/
+	/**
+	tuan_region
+	store_buy_total_money
+	
+	**/
+	
+	//open_score_buy_score $shop_limit_buy_distance = load_model_class('front')->get_config_by_name('shop_limit_buy_distance');
+	
+
+	/**
+	
+	$delivery_ziti_name = D('Home/Front')->get_config_by_name('delivery_ziti_name');
+	$delivery_tuanzshipping_name = D('Home/Front')->get_config_by_name('delivery_tuanzshipping_name');
+	$delivery_diy_sort = D('Home/Front')->get_config_by_name('delivery_diy_sort');
+	
+	if(empty($delivery_diy_sort) || !isset($delivery_diy_sort)) $delivery_diy_sort = '0,1,2';
+	
+	
+	if( empty($tuan_send_address_info) )
+	{
+		$tuan_send_address_info = array();
+	}
+
+	//判断是否预售,给出预售的信息 begin todo
+    $presale_info = [];
+    if( $buy_type == 'presale' )
+    {
+        // $presale_goods_id
+        $presale_result = D('Home/PresaleGoods')->getCheckOutPresaleGoodsInfo( $presale_goods_id , $presale_goods_total );
+
+        if( $presale_result['code'] == 0 )
+        {
+            $presale_info = $presale_result['data'];
+        }
+    }
+	//end
+**/	
+	$open_score_buy_score =  D('Home/Front')->get_config_by_name('open_score_buy_score');
+	
+	if( empty($open_score_buy_score) || $buy_type == 'integral' )
+	{
+		$open_score_buy_score = 0;
+	}
+	
+	$score_forbuy_money_maxbi = D('Home/Front')->get_config_by_name('score_forbuy_money_maxbi');
+	
+	if( empty($score_forbuy_money_maxbi) )
+	{
+		$score_forbuy_money_maxbi = 100;
+	}
+	
+	$score_for_money = 0;
+	$bue_use_score = 0;
+	
+	if( $open_score_buy_score == 1 )
+	{
+		if( $member_info['score'] > 0 )
+		{
+			
+			$score_can_max = $store_buy_total_money - $voucher_price - $reduce_money;
+
+			//计算能兑换多少钱
+			$score_forbuy_money = D('Home/Front')->get_config_by_name('score_forbuy_money');
+			//只有兑换比例大于0才能允许兑换
+			if( !empty($score_forbuy_money) && $score_forbuy_money >0 )
+			{
+				$score_for_money = sprintf("%.2f",$member_info['score'] / $score_forbuy_money);
+				if( $score_can_max < $score_for_money )
+				{
+					$score_for_money = $score_can_max;
+					$bue_use_score = floor($score_can_max * $score_forbuy_money);
+					$score_for_money = round($bue_use_score/$score_forbuy_money,2);
+				}
+				
+				$max_store_buy_total_money = sprintf("%.2f",($score_forbuy_money_maxbi * $score_can_max) /100);
+
+				if($score_for_money > $max_store_buy_total_money)
+				{
+					$score_for_money = $max_store_buy_total_money;
+					
+					$bue_use_score = floor($max_store_buy_total_money * $score_forbuy_money);
+					
+					$score_for_money = round($bue_use_score/$score_forbuy_money,2);
+				}else if($bue_use_score <= $max_store_buy_total_money){
+					
+				    $bue_use_score = floor($score_for_money * $score_forbuy_money);
+					
+					//$bue_use_score = $member_info['score'];
+					
+					if($bue_use_score > $member_info['score'] )
+					{
+					    $bue_use_score = floor($member_info['score']);
+					}
+					$score_for_money = round($bue_use_score/$score_forbuy_money,2);
+				}
+			}
+			
+			
+			//预售
+			//if($buy_type == 'presale'){
+			//	$sum_deduction_money =  $goods[0]["quantity"] * $presale_info['deduction_money'] ;
+			//}	
+		}
+	}
+	//score_forbuy_money score
+	
+	$delivery_ziti_name = D('Home/Front')->get_config_by_name('delivery_ziti_name');
+	$delivery_tuanzshipping_name = D('Home/Front')->get_config_by_name('delivery_tuanzshipping_name');
+	$delivery_diy_sort = D('Home/Front')->get_config_by_name('delivery_diy_sort');
+	
+	if(empty($delivery_diy_sort) || !isset($delivery_diy_sort)) $delivery_diy_sort = '0,1,2';
+	
+	
+	if( empty($tuan_send_address_info) )
+	{
+		$tuan_send_address_info = array();
+	}
+
+	//判断是否预售,给出预售的信息 begin todo
+    $presale_info = [];
+    if( $buy_type == 'presale' )
+    {
+        // $presale_goods_id
+        $presale_result = D('Home/PresaleGoods')->getCheckOutPresaleGoodsInfo( $presale_goods_id , $presale_goods_total );
+
+        if( $presale_result['code'] == 0 )
+        {
+            $presale_info = $presale_result['data'];
+        }
+    }
+	//end
+	
+	$need_data = array();
+	$need_data['code'] = 1;
+	
+	$need_data['open_score_buy_score'] = $open_score_buy_score;//1开启积分抵扣
+	$need_data['score'] = $member_info['score'];//会员持有的积分
+	$need_data['score_for_money'] = $score_for_money;//会员能抵扣的金额
+	$need_data['bue_use_score'] = $bue_use_score;//会员能抵扣的积分数
+	
+	
+	$need_data['delivery_type_ziti'] = $delivery_type_ziti;
+	$need_data['delivery_type_express'] = $delivery_type_express;
+	$need_data['delivery_type_tuanz'] = $delivery_type_tuanz;
+	$need_data['delivery_type_localtown'] = $delivery_type_localtown;
+	$need_data['delvery_type_hexiao'] = $delvery_type_hexiao;
+
+
+	$need_data['delivery_express_name'] = $delivery_express_name;
+	$need_data['delivery_ziti_name'] = $delivery_ziti_name;
+	$need_data['delivery_tuanzshipping_name'] = $delivery_tuanzshipping_name;
+	$need_data['delivery_diy_sort'] = $delivery_diy_sort;
+
+	$need_data['presale_info'] = $presale_info;//预售信息
+
+	$seller_goodss_keys = array_keys($seller_goodss);
+	
+	$need_data['delivery_tuanz_money'] = round($delivery_tuanz_money * count($seller_goodss_keys) , 2);
+	
+	//$need_data['delivery_tuanz_money'] = $delivery_tuanz_money;
+	$need_data['man_free_tuanzshipping'] = empty($man_free_tuanzshipping) ? 0 : $man_free_tuanzshipping;//团长配送,满多少免配送费,0或者为空表示不减免
+	$need_data['man_free_shipping'] = empty($man_free_shipping) ? 0 : $man_free_shipping;//快递配送,满多少免配送费,0或者为空表示不减免
+	
+	$need_data['address'] = $address;
+	
+	
+	$need_data['pick_up_time'] = $pick_up_time;
+	$need_data['pick_up_type'] = $pick_up_type;
+	$need_data['pick_up_weekday'] = $pick_up_weekday;
+	
+	$need_data['is_pin_over'] = $is_pin_over;
+	$need_data['is_integer'] = 0;//$is_no_quan ? 1: 0;
+	$need_data['pick_up_arr'] = $pick_up_arr;
+	$need_data['is_ziti'] = 2;
+	
+	$need_data['ziti_name'] = $pick_up_name;
+	$need_data['ziti_mobile'] = $pick_up_mobile;
+	$need_data['tuan_send_address'] = $tuan_send_address;
+	$need_data['tuan_send_address_info'] = $tuan_send_address_info;
+	$need_data['seller_goodss'] = $seller_goodss;
+	$need_data['show_voucher'] = $show_voucher;
+	
+	$need_data['buy_type'] = $buy_type;
+	$need_data['address'] = $address;
+	$need_data['trans_free_toal'] = $trans_free_toal;
+	
+	$need_data['is_limit_distance_buy'] = 0;
+	$need_data['limit_distance'] = 100;//km
+	
+	$need_data['is_member_level_buy'] = $is_member_level_buy;//km
+	$need_data['level_save_money'] = $level_save_money;//km
+
+    //begin
+
+    $need_data['localtown_shipping_fare'] = $localtown_shipping_fare;//同城配送配送费
+    $need_data['pickingup_fare'] = $picking_fare;//包装费
+    $need_data['localtown_dispatchtime'] = $localtown_dispatchtime;//预计一共需要配送多少分钟
+    $need_data['picking_fare_arr'] = $picking_fare_arr;
+    $need_data['localtown_shipping_fare_arr'] = $localtown_shipping_fare_arr;
+	$need_data['localtown_expected_delivery'] = $localtown_expected_delivery;
+    //end
+
+
+	$need_data['is_vip_card_member'] = $is_vip_card_member;//km
+	$need_data['vipcard_save_money'] = $vipcard_save_money;//km
+	$need_data['is_open_vipcard_buy'] = $is_open_vipcard_buy;//km
+	
+	
+	
+	if( !empty($shop_limit_buy_distance) && $shop_limit_buy_distance ==1 )
+	{
+		$latitude = 0;
+		$longitude = 0;
+		
+		if( !empty($tuan_send_address_info) && !empty($tuan_send_address_info['lon_lat']) )
+		{
+			//lon_lat
+			$lon_lat_arr = explode(',', $tuan_send_address_info['lon_lat']);
+			$longitude = $lon_lat_arr[0];
+			$latitude = $lon_lat_arr[1];
+		}
+		
+		
+		if( isset($gpc['latitude']) && !empty($gpc['latitude']) )
+		{
+			$latitude = $gpc['latitude'];
+		}
+		if( isset($gpc['longitude']) && !empty($gpc['longitude']) )
+		{
+			$longitude = $gpc['longitude'];
+		}
+		
+		if( !empty($latitude) && !empty($longitude) )
+		{
+			$shop_buy_distance = D('Home/Front')->get_config_by_name('shop_buy_distance');
+		
+			$shop_buy_distance = $shop_buy_distance * 1000;
+
+			$community_info = M('lionfish_community_head')->field('lon,lat')->where( array('id' => $community_id ) )->find();
+
+			$distince = D('Seller/Communityhead')->GetDistance($longitude,$latitude,$community_info['lon'],$community_info['lat']);
+			
+			$need_data['current_distance'] = $distince;
+			$need_data['shop_buy_distance'] = $shop_buy_distance;
+			if($distince > $shop_buy_distance )
+			{
+				$need_data['is_limit_distance_buy'] = 1;
+				$need_data['limit_distance'] = $distince/1000;
+			}
+		}
+	}
+	
+	
+	
+	$need_data['reduce_money'] = $reduce_money;
+	$need_data['is_open_fullreduction'] = $is_open_fullreduction;
+	$need_data['cha_reduce_money'] = $cha_reduce_money;
+	
+	
+	$need_data['is_man_delivery_tuanz_fare'] = $is_man_delivery_tuanz_fare; //是否达到满xx减团长配送费
+	$need_data['fare_man_delivery_tuanz_fare_money'] = $fare_man_delivery_tuanz_fare_money;	//达到满xx减团长配送费, 减了多少钱
+	$need_data['is_man_shipping_fare'] = $is_man_shipping_fare; //是否达到满xx减运费
+	$need_data['fare_man_shipping_fare_money'] = $fare_man_shipping_fare_money;	//达到满xx减运费,司机减了多少运费
+	
+	
+	$dispatching = isset($gpc['dispatching']) ? $gpc['dispatching']:'pickup';
+	//is_ziti == 2
+	if($dispatching == 'express')
+	{
+		$need_data['total_free'] = $total_free + $trans_free_toal - $voucher_price -$reduce_money;
+	}
+	else if( $dispatching == 'localtown_delivery' )
+    {
+        $need_data['total_free'] = $total_free + $localtown_shipping_fare + $picking_fare - $voucher_price - $reduce_money;
+    }
+	else{
+		$need_data['total_free'] = $total_free  - $voucher_price -$reduce_money;
+	}
+	if($is_ziti == 2)
+	{
+		$need_data['total_free'] = $total_free  - $voucher_price -$reduce_money;
+	}
+	//积分兑换 不算总金额,但是算总积分
+	if( $buy_type == 'integral' )
+	{
+		$need_data['total_free'] = $trans_free_toal;
+		$need_data['total_integral'] = $total_free;
+	}
+	
+	if($need_data['total_free'] < 0)
+	{
+		$need_data['total_free'] = 0;
+	}
+	
+	//判断是否可以余额支付
+	
+	//暂时关闭 会员余额功能
+	/**
+	$is_yue_open_info =	M('config')->where( array('name' => 'is_yue_open') )->find();
+	$is_yue_open =  $is_yue_open_info['value'];
+	**/
+	
+	$is_yue_open = 0;
+	
+	$is_yue_open = D('Home/Front')->get_config_by_name('is_open_yue_pay');
+	if( empty($is_yue_open) )
+	{
+		$is_yue_open = 0;
+	}
+		
+	
+	$need_data['is_yue_open'] = $is_yue_open;
+	
+	$need_data['can_yupay'] = 0;
+	
+	//暂时关闭 会员余额功能
+	
+	if($is_yue_open == 1 && $need_data['total_free'] >=0 && $member_info['account_money'] >= $need_data['total_free'])
+	{
+		$need_data['can_yupay'] = 1;
+	}
+	
+	//前端隐藏 团长信息
+	$index_hide_headdetail_address = D('Home/Front')->get_config_by_name('index_hide_headdetail_address');
+	
+	if( empty($index_hide_headdetail_address) )
+	{
+		$index_hide_headdetail_address = 0;
+	}
+	$need_data['index_hide_headdetail_address'] = $index_hide_headdetail_address;
+	
+	
+	//订单留言
+	$is_open_order_message = D('Home/Front')->get_config_by_name('is_open_order_message');
+	
+	$need_data['yu_money'] = $member_info['account_money'];
+	$need_data['goods'] = $goods;
+	$need_data['is_open_order_message'] = $is_open_order_message;
+	
+	$need_data['is_zero_opentuan'] = 0;
+	//拼团特殊情况0元开团
+	if( $buy_type == 'pintuan' && $is_zero_buy == 1 )
+	{
+		//$need_data['total_free'] = 0;
+		//$need_data['trans_free_toal'] = 0;
+		//$need_data['is_zero_opentuan'] = 1;
+	}
+	
+	
+	//订阅消息begin
+	
+	$is_need_subscript = 0;
+	$need_subscript_template = array();
+	
+	
+		//'pay_order','send_order','hexiao_success','apply_community','open_tuan','take_tuan','pin_tuansuccess','apply_tixian'
+		//$member_id
+		if( $buy_type == 'pintuan' )
+		{
+			//pin_tuansuccess
+			//send_order  parameter[weprogram_subtemplate_pin_tuansuccess]
+			//hexiao_success
+			
+			$pin_tuansuccess_info = M('lionfish_comshop_subscribe')->where( array('member_id' => $member_id, 'type' => 'pin_tuansuccess' ) )->find();
+			
+			//if( empty($pin_tuansuccess_info) )
+			//{
+				$weprogram_subtemplate_pin_tuansuccess = D('Home/Front')->get_config_by_name('weprogram_subtemplate_pin_tuansuccess');
+				
+				if( !empty($weprogram_subtemplate_pin_tuansuccess) )
+				{
+					$need_subscript_template['pin_tuansuccess'] = $weprogram_subtemplate_pin_tuansuccess;
+				}
+			//}
+			
+		}else{
+			//pay_order
+			$pay_order_info = M('lionfish_comshop_subscribe')->where( array('member_id' => $member_id , 'type' => 'pay_order') )->find();
+			
+			//if( empty($pay_order_info) )
+			//{
+				$weprogram_subtemplate_pay_order = D('Home/Front')->get_config_by_name('weprogram_subtemplate_pay_order');
+				
+				if( !empty($weprogram_subtemplate_pay_order) )
+				{
+					$need_subscript_template['pay_order'] = $weprogram_subtemplate_pay_order;
+				}
+			//}
+		}
+		//send_order
+		
+		$send_order_info = M('lionfish_comshop_subscribe')->where( array('member_id' => $member_id, 'type' => 'send_order' ) )->find();
+		
+		//if( empty($send_order_info) )
+		//{
+			$weprogram_subtemplate_send_order = D('Home/Front')->get_config_by_name('weprogram_subtemplate_send_order');
+			
+			if( !empty($weprogram_subtemplate_send_order) )
+			{
+				$need_subscript_template['send_order'] = $weprogram_subtemplate_send_order;
+			}
+		//}
+		//hexiao_success
+		$hexiao_success_info = M('lionfish_comshop_subscribe')->where( array('member_id' => $member_id, 'type' => 'hexiao_success' ) )->find();
+		
+		
+		//if( empty($hexiao_success_info) )
+		//{
+			$weprogram_subtemplate_hexiao_success = D('Home/Front')->get_config_by_name('weprogram_subtemplate_hexiao_success');
+			
+			if( !empty($weprogram_subtemplate_hexiao_success) )
+			{
+				$need_subscript_template['hexiao_success'] = $weprogram_subtemplate_hexiao_success;
+			}
+		//}
+		
+		if( !empty($need_subscript_template) )
+		{
+			$is_need_subscript = 1;
+		}
+
+	//下单万能表单
+	$need_data['allform'] = D('Home/Allform')->getOrderForms();
+
+	//判断是否使用货到付款
+	$cashondelivery_data = D('Home/Front')->getCashonDeliveryAction($buy_type, $seller_goodss);
+	$need_data['cashondelivery_data'] = $cashondelivery_data;
+
+	//订阅消息end
+	$need_data['is_need_subscript'] = $is_need_subscript;
+	$need_data['need_subscript_template'] = $need_subscript_template;
+	
+	//订单提交页面备注信息
+	$order_note_open = D('Home/Front')->get_config_by_name('order_note_open');
+	
+	$order_note_open = isset($order_note_open) && $order_note_open == 1 ? 1: 0;
+	
+	$order_note_name = D('Home/Front')->get_config_by_name('order_note_name');
+	
+	$order_note_name =  !isset($order_note_name) || empty($order_note_name) ?  '店名' : $order_note_name;
+	
+	$need_data['order_note_open'] = $order_note_open;//开启下单页面备注,仅 自提跟 团长配送时需要
+	$need_data['order_note_name'] = $order_note_name;//备注名称,默认是店名
+	$need_data['order_note_content'] = $order_note_content;//备注名称,默认是店名
+
+	$need_data['localtown_modifypickingname'] = $localtown_modifypickingname;//备注名称,默认是店名
+
+	//配送费类型:0、固定金额,1、按距离收取
+	$localtown_delivery_moneytype = D('Home/Front')->get_config_by_name('localtown_delivery_moneytype');
+	//起送价格
+	$localtown_moneytype_fixed_deliverymoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_deliverymoney');
+	//达到金额免配送费
+	$localtown_moneytype_fixed_freemoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_freemoney');
+	//加价配送
+	$localtown_makeup_delivery_money = D('Home/Front')->get_config_by_name('localtown_makeup_delivery_money');
+	//1、固定金额,订单价格超过起送价格 无加价配送费,2、按距离收取 无加价配送费 3、固定金额,起送价格为0 无加价配送费
+	if(($localtown_delivery_moneytype == 0 && ($localtown_shipping_fare_arr[0]['is_can_qisong'] == 1 || $localtown_moneytype_fixed_deliverymoney == 0)) || $localtown_delivery_moneytype == 1){
+	    $localtown_makeup_delivery_money = 0;
+	}else{
+		$localtown_makeup_delivery_money = 0;
+	}
+
+	$need_data['localtown_delivery_moneytype'] = $localtown_delivery_moneytype;
+	$need_data['localtown_moneytype_fixed_deliverymoney'] = $localtown_moneytype_fixed_deliverymoney;
+	$need_data['localtown_moneytype_fixed_freemoney'] = $localtown_moneytype_fixed_freemoney;
+	$need_data['localtown_makeup_delivery_money'] = $localtown_makeup_delivery_money;
+
+	$need_data['order_lou_meng_hao'] = D('Home/Front')->get_config_by_name('order_lou_meng_hao');
+	$need_data['order_lou_meng_hao_placeholder'] = D('Home/Front')->get_config_by_name('order_lou_meng_hao_placeholder');
+
+	echo json_encode($need_data);
+	die();
+}
+
+public function sub_order()
+{
+	$gpc = I('request.');
+
+    $buy_type = isset($gpc['buy_type']) ? $gpc['buy_type'] : 'dan';
+
+	$token = $gpc['token'];
+	
+	$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
+	$member_id = $weprogram_token['member_id'];
+
+	$pintuan_model_buy = D('Home/Front')->get_config_by_name('pintuan_model_buy');
+
+	$allform_id = $gpc['allform_id'];
+	$allform_list = $gpc['allform_list'];
+
+	if( empty($pintuan_model_buy) || $pintuan_model_buy ==0 )
+	{
+		$pintuan_model_buy = 0;
+	}
+	
+	$is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
+	$is_open_vipcard_buy = !empty($is_open_vipcard_buy) && $is_open_vipcard_buy ==1 ? 1:0; 
+
+	$is_vip_card_member = 0;
+	$is_member_level_buy = 0;
+
+	if( $member_id > 0 )
+	{
+		
+		$member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
+		
+		if( !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 )
+		{
+			
+			$now_time = time();
+			
+			if( $member_info['card_id'] >0 && $member_info['card_end_time'] > $now_time )
+			{
+				$is_vip_card_member = 1;//还是会员
+			}else if( $member_info['card_id'] >0 && $member_info['card_end_time'] < $now_time ){
+				$is_vip_card_member = 2;//已过期
+			}
+		}
+		
+		if($is_vip_card_member != 1 && $member_info['level_id'] >0 )
+		{
+			$is_member_level_buy = 1;
+		}
+	}
+
+	if($buy_type == 'presale')
+    {
+        $is_vip_card_member = 0;
+        $is_member_level_buy = 0;
+    }
+	
+	//use_score = 1
+	$use_score = isset($gpc['use_score']) ? intval($gpc['use_score']) : 0;
+	
+	$puis_not_buy =  D('Home/Front')->get_config_by_name('puis_not_buy');
+				
+	if( !empty($puis_not_buy) && $puis_not_buy ==1 )
+	{
+		$member_info = M('lionfish_comshop_member')->field('level_id')->where( array('member_id' => $member_id) )->find();
+		
+		if($member_info['level_id'] == 0)
+		{
+			echo json_encode( array('code' => 2, 'msg' => '普通会员不能购买') );
+			die();
+		}
+	}
+		//$buy_type == 'presale'
+	$data_s  = array();
+	$data_s['pay_method'] = $gpc['wxpay'];
+	$data_s['buy_type'] = isset($gpc['buy_type']) ? $gpc['buy_type'] : 'dan';
+	$data_s['pick_up_id'] = $gpc['pick_up_id'];
+	$data_s['dispatching'] = $gpc['dispatching'];
+	
+	$order_note_open = D('Home/Front')->get_config_by_name('order_note_open');
+	if($order_note_open == 1){
+		$data_s['note_content'] = $gpc['note_content'];
+	}else{
+		$data_s['note_content'] = '';
+	}
+	
+	
+	$data_s['soli_id'] = isset($gpc['soli_id']) ? intval($gpc['soli_id']) : 0 ;
+	
+	
+	if($data_s['dispatching'] != 'express' && empty($data_s['pick_up_id']))
+	{
+		$last_community = M('lionfish_community_history')->where( array('member_id' => $member_id) )->order('id desc')->find();
+		
+		if( !empty($last_community) )
+		{
+			$data_s['pick_up_id'] = $last_community['head_id'];
+		}
+
+		//$data_s['pick_up_id']
+	}
+	//礼品卡不用配送地址begin
+	if( $data_s['buy_type'] == 'virtualcard' )
+    {
+        $data_s['dispatching'] = 'express';
+        $data_s['address_id'] = 0;
+    }
+    //end
+	
+	if( $data_s['buy_type'] == 'dan' || $data_s['buy_type'] == 'soitaire' || $data_s['buy_type'] == 'presale' || ($pintuan_model_buy == 1 && $data_s['buy_type'] != 'dan' && $data_s['buy_type'] != 'integral'  ) )
+	{
+		D('Seller/Community')->in_community_history($member_id,$data_s['pick_up_id']);
+	}
+	
+	//'express'  快递, 'pickup'  自提, 'tuanz_send'  团长配送)   tuan_send_address 
+	
+	$data_s['ziti_name'] = $gpc['ziti_name'];
+	$data_s['quan_arr'] = $gpc['quan_arr'];
+	
+	
+	$data_s['comment'] = $gpc['comment'];
+	$data_s['ziti_mobile'] = $gpc['ziti_mobile'];
+	$data_s['tuan_send_address'] = $gpc['tuan_send_address'];
+	$data_s['ck_yupay'] = $gpc['ck_yupay'];
+	//是否货到付款
+	$data_s['cashon_delivery'] = $gpc['cashon_delivery'];
+
+	
+	$data_s['province_name'] = isset($gpc['province_name']) ? $gpc['province_name']:'' ;
+	$data_s['city_name'] = isset($gpc['city_name']) ? $gpc['city_name']: '';
+	$data_s['country_name'] = isset($gpc['country_name']) ? $gpc['country_name']: '';
+	$data_s['address_name'] = isset($gpc['address_name']) ? $gpc['address_name']:'' ;
+	
+	$data_s['latitude'] = isset($gpc['latitude']) ? $gpc['latitude']:'' ;
+	$data_s['longitude'] = isset($gpc['longitude']) ? $gpc['longitude']:'' ;
+	$data_s['lou_meng_hao'] = isset($gpc['lou_meng_hao']) ? $gpc['lou_meng_hao']:'' ;
+
+	$data_s['expected_delivery_time'] = isset($gpc['expected_delivery_time']) ? $gpc['expected_delivery_time']:'' ;
+	//$data_s['tuan_send_address'] .= $data_s['lou_meng_hao'];
+	//$data_s['tuan_send_address'] .= $data_s['lou_meng_hao'];
+	
+	//tuan_send_address
+	
+	$province_name = isset($data_s['province_name']) ? $data_s['province_name'] : '';
+	$city_name = isset($data_s['city_name']) ? $data_s['city_name'] : '';
+	$country_name = isset($data_s['country_name']) ? $data_s['country_name'] : '';
+	$address_name = isset($data_s['address_name']) ? $data_s['address_name'] : '';
+	
+	//判断配送距离
+	/*if($data_s['dispatching'] == 'localtown_delivery'){
+		//服务距离
+		$localtown_servvice_maxdistance =  D('Home/Front')->get_config_by_name('localtown_servvice_maxdistance');
+		//商家经纬度
+		$localtown_shop_lon =  D('Home/Front')->get_config_by_name('localtown_shop_lon');
+		$localtown_shop_lat =  D('Home/Front')->get_config_by_name('localtown_shop_lat');
+
+		$distince = D('Seller/Communityhead')->GetDistance($data_s['longitude'],$data_s['latitude'], $localtown_shop_lon, $localtown_shop_lat);
+		$distince = round($distince/1000,2);
+		if($distince > $localtown_servvice_maxdistance){
+			//echo json_encode( array('code' => 2, 'msg' => '超出服务距离'.$localtown_servvice_maxdistance.'KM') );
+		    echo json_encode( array('code' => 2, 'msg' => '您与商家的距离过远,商家的配送范围是'.$localtown_servvice_maxdistance.'KM内') );
+			die();
+		}
+	}*/
+	
+	
+	$json=array();
+
+	$pay_method = $data_s['pay_method'];//支付类型
+	$order_msg_str = $data_s['order_msg_str'];//商品订单留言
+	$comment = $data_s['comment'];//商品订单留言
+	
+	$comment_arr = array();
+	if( !empty($data_s['comment']) )
+	{
+		$comment_arr1 = explode('@EOF@', $data_s['comment']);
+		foreach($comment_arr1  as  $var){
+			$count = substr_count($var, '_');
+			$a = explode('_', $var);
+
+			for($i=1 ; $i<$count ; $i++ ){
+				$comment_arr[$a[$i]] =  $a[$count];
+			}
+			
+		}
+	}
+	
+	$pick_up_id = $data_s['pick_up_id'];
+	$dispatching = $data_s['dispatching'];
+	$ziti_name = $data_s['ziti_name'];
+	$ziti_mobile = $data_s['ziti_mobile'];
+	
+	
+	//新增快递
+	$province_name = isset($data_s['province_name']) ? $data_s['province_name'] : '';
+	$city_name = isset($data_s['city_name']) ? $data_s['city_name'] : '';
+	$country_name = isset($data_s['country_name']) ? $data_s['country_name'] : '';
+	$address_name = isset($data_s['address_name']) ? $data_s['address_name'] : '';
+	
+	
+	$ck_yupay = $data_s['ck_yupay'];
+	$cashon_delivery = $data_s['cashon_delivery'];
+	if($dispatching == 'express')
+	{
+		$data_s['address_id'] = $this->_add_address($token,$ziti_name,$ziti_mobile,$province_name,$city_name, $country_name,$address_name);
+	}
+	else if( $dispatching == 'localtown_delivery' )
+    {
+        $data_s['address_id'] = $this->_add_address($token,$ziti_name,$ziti_mobile,$province_name,$city_name, $country_name,$address_name,$data_s['latitude'],$data_s['longitude'],$data_s['lou_meng_hao'] );
+    }
+	else if($dispatching == 'tuanz_send'){
+		$data_s['address_id'] = $this->_add_address($token,$ziti_name,$ziti_mobile,$province_name,$city_name, $country_name,$data_s['tuan_send_address'],$data_s['latitude'],$data_s['longitude'],$data_s['lou_meng_hao'] );
+		
+		$data_s['tuan_send_address'] .= $data_s['lou_meng_hao'];
+	}
+	
+	/**
+	
+	pick_up_id: that.data.pick_up_id,
+	dispatching: that.data.dispatching, //express  pickup
+	ziti_name: t_ziti_name,
+	ziti_mobile: t_ziti_mobile
+	**/
+	$order_msg_arr = explode('@,@', $order_msg_str);
+	
+	$quan_arr = $data_s['quan_arr'];//商品订单留言
+
+	$order_quan_arr = array();
+	
+	
+	if( !empty($quan_arr) )
+	{
+		if( !is_array($quan_arr) )
+		{
+			$quan_arr = array($quan_arr);
+		}
+		
+		foreach($quan_arr as $q_val)
+		{
+			$tmp_q = array();
+			$tmp_q = explode('_',$q_val);
+			
+			
+			$voucher_info = M('lionfish_comshop_coupon_list')->where("consume='N' and id=".$tmp_q[1]." and user_id=".$member_id." and end_time >".time())->find();
+			
+			if( !empty($voucher_info) )
+			{
+				//$order_quan_arr[$tmp_q[0]] = $tmp_q[1];
+				$order_quan_arr[1] = $tmp_q[1];
+			}
+			
+			
+		}
+	}
+	
+	
+	
+	
+	$msg_arr = array();
+	foreach($order_msg_arr as $val)
+	{
+		$tmp_val = explode('@_@', $val);
+		$msg_arr[ $tmp_val[0] ] = $tmp_val[1];
+	}
+	
+
+	$cart= D('Home/Car');
+
+	// 验证商品数量
+	//buy_type:buy_type
+	$buy_type = $data_s['buy_type'];//I('post.buy_type');
+
+
+	$is_pin = 0;
+	if($buy_type == 'pintuan')
+	{
+		$is_pin = 1;
+	}
+	
+	$goodss = $cart->get_all_goodswecar($buy_type,$token,1,$data_s['pick_up_id'], $data_s['soli_id']);
+	//付款人
+	
+	$payment = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
+
+	//收货人
+	$addr_param = array();
+	$addr_param[':uniacid'] = $_W['uniacid'];
+	$addr_param[':member_id'] = $member_id;
+	
+	//$addr_sql = "select * from ".tablename('lionfish_comshop_address')." where uniacid=:uniacid and member_id=:member_id order by  is_default desc,address_id desc limit 1";
+	//$address = pdo_fetch($addr_sql, $addr_param);
+	
+	$seller_goodss = array();
+	
+	/** 计算每个订单的优惠券占比begin */
+	$zanbi_total_money = 0;
+
+	//是否需要校验ticket 交易组件
+    $scene = $gpc['scene'];
+    $is_need_scene_check = 0;
+
+    if(!empty($scene))
+    {
+        $is_need_scene_check = D('Seller/MpModifyTradeComponts')->sceneCheck( $scene );
+    }
+
+	foreach($goodss as $key => $val) {
+		//单商户先屏蔽
+		//$goods_store_field =  M('goods')->field('store_id')->where( array('goods_id' => $val['goods_id']) )->find();
+
+		$supply_id = D('Home/Front')->get_goods_supply_id($val['goods_id']);
+		if ($supply_id > 0) {
+			$supply_info = D('Home/Front')->get_supply_info($supply_id);
+
+			if ($supply_info['type'] == 0) {
+				$supply_id = 0;
+			}
+		}
+
+		if($data_s['dispatching'] == 'localtown_delivery'){
+			if($supply_id > 0){
+				$isopen_localtown_delivery =  D('Home/Front')->get_supply_config_by_name('isopen_localtown_delivery',$supply_id);
+				if($isopen_localtown_delivery == 1){
+					//服务距离
+					$localtown_servvice_maxdistance =  D('Home/Front')->get_supply_config_by_name('localtown_servvice_maxdistance',$supply_id);
+					//商家经纬度
+					$localtown_shop_lon =  D('Home/Front')->get_supply_config_by_name('localtown_shop_lon',$supply_id);
+					$localtown_shop_lat =  D('Home/Front')->get_supply_config_by_name('localtown_shop_lat',$supply_id);
+					$distince = D('Seller/Communityhead')->GetDistance($data_s['longitude'],$data_s['latitude'], $localtown_shop_lon, $localtown_shop_lat);
+					$distince = round($distince/1000,2);
+					if($distince > $localtown_servvice_maxdistance){
+						echo json_encode( array('code' => 2, 'msg' => '您与商家的距离过远,商家的配送范围是'.$localtown_servvice_maxdistance.'KM内') );
+						die();
+					}
+				}
+			}else{
+				//服务距离
+				$localtown_servvice_maxdistance =  D('Home/Front')->get_config_by_name('localtown_servvice_maxdistance');
+				//商家经纬度
+				$localtown_shop_lon =  D('Home/Front')->get_config_by_name('localtown_shop_lon');
+				$localtown_shop_lat =  D('Home/Front')->get_config_by_name('localtown_shop_lat');
+				$distince = D('Seller/Communityhead')->GetDistance($data_s['longitude'],$data_s['latitude'], $localtown_shop_lon, $localtown_shop_lat);
+				$distince = round($distince/1000,2);
+				if($distince > $localtown_servvice_maxdistance){
+					echo json_encode( array('code' => 2, 'msg' => '您与商家的距离过远,商家的配送范围是'.$localtown_servvice_maxdistance.'KM内') );
+					die();
+				}
+			}
+
+		}
+
+		$seller_goodss[$supply_id][$key] = $val;
+
+		//$cart->removecar($val['key'],$token);
+
+
+		if ($is_vip_card_member == 1 && $val['is_take_vipcard'] == 1) {
+			$zanbi_total_money += $val['card_total'];
+		} else if ($val['is_mb_level_buy'] > 0 && $is_member_level_buy == 1) {
+			$zanbi_total_money += $val['level_total'];
+		} else if ($val['is_mb_level_buy'] == 1 && $member_info['level_id'] > 0){
+			$zanbi_total_money += $val['level_total'];
+		}
+		else
+		{
+			$zanbi_total_money += $val['total'];
+		}
+		
+		//检测是否场景符合begin
+		if( $is_need_scene_check == 1 )
+        {
+            if( $val['isTradeComponts'] == 0 )
+            {
+                echo json_encode( array('code' => 2,'msg' => $val['name'].':未提交小程序交易组件' ) );
+                die();
+            }
+        }
+        //检测是否场景符合end
+	}
+
+	//判断是否可以货到付款
+	if($cashon_delivery == 1){
+		$cashondelivery_data = D('Home/Front')->getCashonDeliveryAction($buy_type, $seller_goodss);
+		if($cashondelivery_data['isopen_cashondelivery'] == 1){
+			if($dispatching == 'express' && $cashondelivery_data['isopen_cashondelivery_express'] == 0){
+				echo json_encode( array('code' => 3,'msg' => '货到付款未开启' ) );
+				die();
+			}else if($dispatching == 'tuanz_send' && $cashondelivery_data['isopen_cashondelivery_communityhead'] == 0){
+				echo json_encode( array('code' => 3,'msg' => '货到付款未开启' ) );
+				die();
+			}else if($dispatching == 'localtown_delivery' && $cashondelivery_data['isopen_cashondelivery_localtown'] == 0){
+				echo json_encode( array('code' => 3,'msg' => '货到付款未开启' ) );
+				die();
+			}else if($dispatching == 'hexiao' && $cashondelivery_data['isopen_cashondelivery_hexiao'] == 0){
+				echo json_encode( array('code' => 3,'msg' => '货到付款未开启' ) );
+				die();
+			}else if($dispatching == 'pickup' && $cashondelivery_data['isopen_cashondelivery_ziti'] == 0){
+				echo json_encode( array('code' => 3,'msg' => '货到付款未开启' ) );
+				die();
+			}
+		}else{
+			echo json_encode( array('code' => 3,'msg' => '货到付款未开启' ) );
+			die();
+		}
+	}
+
+	//....看看有没有满多少才能下单begin
+	$open_man_orderbuy = D('Home/Front')->get_config_by_name('open_man_orderbuy');
+	$man_orderbuy_money = D('Home/Front')->get_config_by_name('man_orderbuy_money');
+	
+	//pindan (拼团商品单独购买)   pintuan (拼团)
+	if($buy_type == 'pintuan' || $buy_type == 'pindan' || $buy_type == 'integral' )
+	{
+		$open_man_orderbuy = 0;
+	}
+	
+	if( !empty($open_man_orderbuy) &&  $open_man_orderbuy == 1 )
+	{
+		if( !empty($man_orderbuy_money) && $man_orderbuy_money >0 )
+		{
+			if($man_orderbuy_money > $zanbi_total_money)
+			{
+				echo json_encode( array('code' => 2,'msg' => '满'.$man_orderbuy_money.'元才可以下单' , 'is_forb' => 1) );
+				die();
+			}
+		}
+	}
+	//....看看有没有满多少才能下单end
+	//清除购物车
+	foreach($goodss as $key => $val)
+	{
+		$cart->removecar($val['key'],$token);
+		
+	}
+	/** 计算每个订单的优惠券占比end */
+	
+	$pay_total = 0;
+	//M('order_all')
+	
+	
+	$order_all_data = array();
+	$order_all_data['member_id'] = $member_id;
+	$order_all_data['order_num_alias'] = build_order_no($member_id);
+	$order_all_data['transaction_id'] = '';
+	$order_all_data['order_status_id'] = 3;
+	$order_all_data['is_pin'] = $is_pin;
+	$order_all_data['paytime'] = 0;
+	
+	$order_all_data['addtime'] = time();
+	
+	$order_all_id = M('lionfish_comshop_order_all')->add($order_all_data);
+	
+	
+	//暂时屏蔽积分商城模块
+	
+	$integral_model = D('Home/Integral');
+	
+	$order_ids_arr = array();
+	$del_integral = 0;
+	
+	if( ($buy_type == 'pintuan' || $buy_type == 'pindan') && $pintuan_model_buy == 0 )
+	{
+		$community_info = array();
+		$community_detail_info = array();
+	}
+	else if( $buy_type == 'integral' )
+	{
+		$community_info = array();
+		$community_detail_info = array();
+	}
+	else if( ($buy_type == 'pintuan' || $buy_type == 'pindan') && $pintuan_model_buy == 1 )
+	{
+		$community_info = M('lionfish_community_head')->where( array('id' => $data_s['pick_up_id'] ) )->find();	
+		$community_detail_info = D('Home/Front')->get_community_byid($data_s['pick_up_id']);
+	}else{			
+		$community_info = M('lionfish_community_head')->where( array('id' => $data_s['pick_up_id'] ) )->find();	
+		$community_detail_info = D('Home/Front')->get_community_byid($data_s['pick_up_id']);
+	}
+	
+	
+	
+	$address_info = M('lionfish_comshop_address')->where( array('address_id' => $data_s['address_id'] ) )->find();					
+						
+	
+	$is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
+	$full_money = D('Home/Front')->get_config_by_name('full_money');
+	$full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
+	
+	
+	$man_free_tuanzshipping = D('Home/Front')->get_config_by_name('man_free_tuanzshipping');
+	$man_free_shipping = D('Home/Front')->get_config_by_name('man_free_shipping');
+	
+	if( empty($man_free_tuanzshipping) )
+	{
+		$man_free_tuanzshipping = 0;
+	}
+	
+	if( empty($man_free_shipping) )
+	{
+		$man_free_shipping = 0;
+	}
+
+	if(empty($full_reducemoney) || $full_reducemoney <= 0)
+	{
+		$is_open_fullreduction = 0;
+	}
+			
+	if( ($buy_type == 'pintuan' || $buy_type == 'pindan') && $pintuan_model_buy == 0  )
+	{
+		$man_free_tuanzshipping = 0;
+		$man_free_shipping = 0;
+		$is_open_fullreduction = 0;
+	}
+	else if( $buy_type == 'integral' )
+	{
+		$man_free_tuanzshipping = 0;
+		$man_free_shipping = 0;
+		$is_open_fullreduction = 0;
+	}
+	else if( ($buy_type == 'pintuan' || $buy_type == 'pindan') && $pintuan_model_buy == 1 )
+	{
+		$man_free_shipping = 0;
+		$is_open_fullreduction = 0;
+	}
+	//预售不参与满减
+    if($buy_type == 'presale')
+    {
+        $man_free_tuanzshipping = 0;
+        $man_free_shipping = 0;
+        $is_open_fullreduction = 0;
+    }
+					
+	$is_moban = false;	
+	
+	
+	$cart = D('Home/Car');
+	$is_just_1 = 0;
+	$index_comment = 0;
+	
+	$pay_goods_name = "";
+	
+	$store_buy_total_money = 0;
+	
+	$open_score_buy_score = D('Home/Front')->get_config_by_name('open_score_buy_score');
+		
+	$score_for_money = 0;//use_score
+	
+	if( $buy_type == 'integral' )
+	{
+		$open_score_buy_score = 0;
+	}
+	
+	//预售不参与积分抵扣
+	if($open_score_buy_score == 1 && $use_score == 1 && $payment['score'] > 0 && $buy_type != 'presale')
+	{
+		//计算能兑换多少钱
+		$score_forbuy_money = D('Home/Front')->get_config_by_name('score_forbuy_money');
+		//只有兑换比例大于0才能允许兑换
+		if( !empty($score_forbuy_money) && $score_forbuy_money >0 )
+		{
+			$score_for_money =  sprintf('%.2f', $payment['score'] / $score_forbuy_money);
+		}
+	}
+	
+		
+	
+	foreach($seller_goodss as $kk => $vv)
+	{
+		$is_just_1++;
+		
+		$data = array();
+
+		$data['member_id']=$member_id;
+		$data['name']= $payment['username'];
+		$data['use_score']= $use_score;//是否使用积分抵扣
+	
+		$data['telephone']= $data_s['ziti_mobile'];
+		$data['note_content']= $data_s['note_content'];
+		$data['shipping_name']= $data_s['ziti_name'];
+		$data['shipping_tel']= $data_s['ziti_mobile'];
+	
+		
+		if($dispatching == 'express' || $dispatching == 'tuanz_send' || $dispatching == 'localtown_delivery')
+		{
+			$data['shipping_address'] = $address_info['address'];
+			$data['shipping_province_id']=$address_info['province_id'];
+			$data['shipping_city_id']=$address_info['city_id'];
+			$data['shipping_stree_id']= 0;
+			$data['shipping_country_id']=$address_info['country_id'];
+			
+		}else{
+			$data['shipping_address'] = $community_detail_info['fullAddress'];
+			$data['shipping_province_id']=$community_info['province_id'];
+			$data['shipping_city_id']=$community_info['city_id'];
+			$data['shipping_stree_id']=$community_info['country_id'];
+			$data['shipping_country_id']=$community_info['area_id'];
+		}
+		
+	
+		$data['shipping_method'] = 0;
+		$data['delivery']=$dispatching;
+		$data['pick_up_id']=$pick_up_id;
+		
+		$data['ziti_name']=$community_info['head_name'];
+		$data['ziti_mobile']=$community_info['head_mobile'];
+		
+	
+		$data['payment_method']=$pay_method;
+	
+		$data['address_id']= $data_s['address_id'];
+		$data['voucher_id'] = isset($order_quan_arr[1]) ? $order_quan_arr[1]:0;//目前都是平台券
+		
+	
+		$data['user_agent']=$_SERVER['HTTP_USER_AGENT'];
+		$data['date_added']=time();
+	
+		$subject='';
+		$fare = 0;
+		$order_total = 0;
+	
+
+		$trans_free_toal = 0;//运费
+
+		$is_localtown_free_shipping_fare = 0;
+        $localtown_shipping_fare_total = 0;//同城配送费
+		$localtown_free_shipping_fare = 0;//满减的同城配送费用
+		
+		$reduce_money = 0;
+		
+		$man_total_free = 0;
+		$score_buy_money = 0;
+		
+		$is_lottery = 0;
+		$is_integral = 0;
+		$is_spike = 0;
+		$is_hexiao = 0;
+		
+		$total_weight = 0;
+		$total_quantity = 0;
+		
+		$redis_has_add_list = array();
+		
+		$is_free_shipping_fare = 0;//是否免除运费
+		
+		$order_goods_total_money = 0;
+		$goods_data = array();
+		
+		$is_moban = false;
+		//comment_arr comment_arr
+
+
+        $packing_fare = 0;
+        $iscan_fu_packing = 1;
+
+        if('localtown_delivery' == $dispatching)
+        {
+
+            $tmp_sellergd = array($kk => array('goods'=>$vv) );
+
+            $town_address = M('lionfish_comshop_address')->where( array('address_id' => $data_s['address_id'] ) )->find();
+
+            list($lon, $lat ) = explode(",",$town_address['lon_lat'] );
+
+            $localtown_shippingfare_arr = D('Home/LocaltownDelivery')->calc_shipping_fare( $lon, $lat , $tmp_sellergd );
+
+            $trans_free_toal = $localtown_shippingfare_arr['total_shipping_fare'];
+
+            $localtown_shipping_fare_total = $trans_free_toal;
+
+            $packing_fare_arr = D('Home/LocaltownDelivery')->calc_packing_money( array( $kk => array('goods' => $vv ) ) );
+
+            $packing_fare = $packing_fare_arr['total_picking_fare'];
+
+			$localtown_shipping_fare = $localtown_shippingfare_arr['total_shipping_fare'];
+			$localtown_yl_shipping_fare = $localtown_shippingfare_arr['total_yl_shipping_fare'];
+			if($localtown_shipping_fare != $localtown_yl_shipping_fare && $localtown_shipping_fare == 0){
+				$is_localtown_free_shipping_fare = 1;
+				$localtown_free_shipping_fare = $localtown_shippingfare_arr['total_yl_shipping_fare'];
+			}
+
+			$data['localtown_add_shipping_fare'] = $localtown_shippingfare_arr[$kk]['localtown_add_shipping_fare'];
+        }
+
+		$data['expected_delivery_time'] = $data_s['expected_delivery_time'];
+        $data['packing_fare'] = floatval($packing_fare);
+
+		foreach($vv as $key => $good)
+		{
+			
+			if( $kk == 0 )
+			{
+				if( $is_vip_card_member == 1 && $good['is_take_vipcard'] == 1 )
+				{
+					$store_buy_total_money += $good['card_total'];
+				}
+				else if( $good['is_mb_level_buy'] == 1 && $member_info['level_id'] >0 )
+				{
+					$store_buy_total_money += $good['level_total'];
+				}
+				else
+				{
+					$store_buy_total_money += $good['total'];
+				}
+				
+			}
+			/**
+			if($good['shipping']==1)
+			{
+				//统一运费
+				$trans_free_toal += $good['goods_freight'];
+				$trans_free = $good['goods_freight'];
+			}else {
+				//运费模板
+				$trans_free = load_model_class('transport')->calc_transport($good['transport_id'], $good['quantity'], $good['quantity']*$good['weight'], $address['city_id'] );
+				
+				//$trans_free = D('Home/Transport')->calc_transport($good['transport_id'], $good['quantity']*$good['weight'], $address['city_id'] );
+				$trans_free_toal +=$trans_free;
+			}
+			**/
+			$trans_free = 0;
+			//$trans_free_toal +=$trans_free;
+		   //sku_str 
+			
+			if( $is_vip_card_member == 1 && $good['is_take_vipcard'] == 1 )
+			{
+				$order_goods_total_money += $good['card_total'];
+				$order_total += $good['card_total'];
+			}
+			else if( $good['is_mb_level_buy'] == 1 && $member_info['level_id'] >0 )
+			{
+				$order_goods_total_money += $good['level_total'];
+				$order_total += $good['level_total'];
+			}
+			else
+			{
+				$order_goods_total_money += $good['total'];
+				$order_total += $good['total'];
+			}
+			
+			$tp_goods_info = M('lionfish_comshop_goods')->field('type')->where( array('id' => $good['goods_id']) )->find();
+			
+			$tp_goods_info['store_id'] = 1;
+			
+			if($tp_goods_info['type'] == 'lottery')
+			{
+				$is_lottery = 1;
+			}
+			if($tp_goods_info['type'] == 'spike')
+			{
+				$is_spike = 1;
+				$is_pin = 0;
+			}
+			//暂时屏蔽积分商城模块
+			
+			if($tp_goods_info['type'] == 'integral')
+			{
+				$is_integral = 1;
+				$is_pin = 0;
+				$check_result = $integral_model->check_user_score_can_pay($member_id, $good['sku_str'], $good['goods_id'] );
+				if($check_result['code'] == 1)
+				{
+					echo json_encode( array('code' => 2, 'msg' => '剩余'.$check_result['cur_score'].'积分,积分不足!' , 'is_forb' => 1 ) );
+					die();
+				}
+				
+			}
+			
+			//is_hexiao is_only_express
+			if($good['is_only_express']==2)
+			{
+				$is_hexiao = 2;
+				$is_pin = 0;
+			}
+			
+			if($good['shipping']==0)
+			{
+				$is_moban = true;
+				//统一运费
+				$total_weight += $good['weight']*$good['quantity'];
+				$total_quantity += $good['quantity'];
+			}
+			
+			$fenbi_li = 1;
+			if(  $zanbi_total_money > 0 )
+			{
+				if( $is_vip_card_member == 1 && $good['is_take_vipcard'] == 1 )
+				{
+					$fenbi_li = round($good['card_total'] / $zanbi_total_money, 2);
+				}
+				else if( $good['is_mb_level_buy'] == 1 && $member_info['level_id'] >0 )
+				{
+					$fenbi_li = round($good['level_total'] / $zanbi_total_money, 2);
+				}
+				else
+				{
+					$fenbi_li = round($good['total'] / $zanbi_total_money, 2);
+				}
+			}
+			
+			//if( isset($comment_arr[$index_comment]) )
+			//{
+			//	$comment = $comment_arr[$index_comment];
+				
+			//}
+			
+			//$good['goods_id']
+			if( isset($comment_arr) )
+			{
+				foreach($comment_arr as $key => $var){
+				   if($good['goods_id'] == $key ){
+					   $comment = $var;
+				   }	
+				
+				}
+			}
+			
+			
+			//监测库存数量
+			$quantity_flag = D('Seller/Redisorder')->check_goods_can_buy($good['goods_id'], $good['sku_str'],$good['quantity']);
+			if( $quantity_flag <=0 )
+			{
+				if( !empty($redis_has_add_list) )
+				{
+					D('Seller/Redisorder')->bu_car_has_delquantity($redis_has_add_list);
+				}
+				echo json_encode(  array('code' => 2, 'msg' => '已抢光' , 'is_forb' => 1) );
+				die();
+			}
+			//如果是下单减库存,那么用占坑法来避免超库存---begin
+			$kucun_method = D('Home/Front')->get_config_by_name('kucun_method');
+						
+			if( empty($kucun_method) )
+			{
+				$kucun_method = 0;
+			}
+			
+			if($kucun_method == 0)
+			{
+				//$ret = $redis->rPush('city', 'guangzhou');
+				$check_redis_quantity = D('Seller/Redisorder')->add_goods_buy_user($good['goods_id'], $good['sku_str'],$good['quantity'],$member_id);
+				//注意要回滚
+				
+				//$key = "user_goods_{$member_id}_{$goods_id}_{$sku_str}";
+				
+				if($check_redis_quantity == 0)
+				{
+					//cancle_redis_user_list 
+					if( !empty($redis_has_add_list) )
+					{
+					    D('Seller/Redisorder')->bu_car_has_delquantity($redis_has_add_list);
+					}
+				
+					echo json_encode( array('code' => 2, 'msg' => '已抢光' , 'is_forb' => 1) );
+					die();
+				}
+				
+				$redis_has_add_list[]  = array('member_id' => $member_id, 'goods_id' => $good['goods_id'], 'sku_str' => $good['sku_str'],'quantity' => $good['quantity'] );
+				
+			}
+			//----------------redis   end
+			if( $good['can_man_jian'] == 1)
+			{
+				//$man_total_free += $good['total'];
+				
+				//begggg
+				
+				if( $is_vip_card_member == 1 && $good['is_take_vipcard'] == 1 )
+				{
+					
+					if( $good['can_man_jian'] == 1)
+					{
+						$man_total_free += $good['card_total'];
+						
+					}
+				}
+				else if( $good['is_mb_level_buy'] == 1 && $member_info['level_id'] >0 )
+				{
+					if( $good['can_man_jian'] == 1)
+					{
+						$man_total_free += $good['level_total'];
+					}
+				}
+				else
+				{
+					if( $good['can_man_jian'] == 1)
+					{
+						$man_total_free += $good['total'];
+						
+					}
+				}
+				
+				//eddddd
+				
+			}
+			
+			$pay_goods_name .= $good['name'];
+			
+			if( $good['is_mb_level_buy'] == 1 && $is_vip_card_member ==0 && $member_info['level_id'] >0 )
+			{
+				$good['is_mb_level_buy'] == 1;
+			}else{
+				$good['is_mb_level_buy'] == 0;
+			}
+
+            $localtown_superposition_pickingmoney = 0;
+            $localtown_superposition_pickingmoney = isset($localtown_superposition_pickingmoney) ? $localtown_superposition_pickingmoney : 0;
+
+            $gd_packing_fare = 0;
+
+            if( $localtown_superposition_pickingmoney == 0  )
+            {
+                $gd_packing_fare = $good['packing_free'];
+            } else
+            {
+                if( $packing_fare == $good['packing_free'] && $iscan_fu_packing == 1)
+                {
+                    $iscan_fu_packing = 0;
+                    $gd_packing_fare = $good['packing_free'];
+                }
+            }
+
+            $goods_data[] = array(
+				'goods_id'   => $good['goods_id'],
+				'store_id' => $tp_goods_info['store_id'],
+				'name'       => $good['name'],
+				'model'      => $good['model'],
+				'is_pin' => $is_pin,
+				'pin_id' => $good['pin_id'],
+				'header_disc' => $good['header_disc'],
+				'member_disc' => $good['member_disc'],
+				'level_name' => $good['level_name'],
+				'option'     => $good['sku_str']== 'undefined' ? '':$good['sku_str'],
+				'quantity'   => $good['quantity'],
+				'shipping_fare' => $trans_free,
+				'price'      => $good['price'],
+				'costprice'  => $good['costprice'],
+				'card_price' => $good['card_price'],
+				'levelprice' => $good['levelprice'],
+				'total'      => $good['total'],
+				'packing_fare' => $gd_packing_fare,
+				'card_total' => $good['card_total'] ,
+				'level_total' => $good['level_total'] ,
+				'is_mb_level_buy' => $good['is_mb_level_buy']  ,
+				'is_take_vipcard' => $good['is_take_vipcard'],
+				'fenbi_li'      => $fenbi_li,
+				'can_man_jian'      => $good['can_man_jian'],
+				'soli_id'      => $good['soli_id'],
+				'comment' => htmlspecialchars($comment)
+			);
+
+		}
+		
+		$index_comment++;
+		//$total_weight = 0;
+		//$total_quantity = 0;
+		
+		if($dispatching == 'express')
+		{
+			//结算运费新模式
+			$trans_free_toal = 0;//运费
+		   
+			//----开始计算运费
+			
+			//ims_ 
+			
+			$shipping_default = M('lionfish_comshop_shipping')->where("enabled=1")->order('isdefault desc,id desc')->find();
+			
+			$seller_goodss_re = $seller_goodss;
+			
+			
+			
+				$store_shipping_fare = 0;
+				if($is_moban)
+				{
+					$store_shipping_fare = D('Home/Transport')->calc_transport($shipping_default['id'], $total_quantity,$total_weight, $address_info['city_id'] );
+				
+				
+				}
+			
+				$trans_free_toal += $store_shipping_fare;
+				
+				foreach($vv as $kkc =>$d_goods)
+				{
+					if($d_goods['shipping']==1)
+					{
+						//统一运费
+						$trans_free_toal += $d_goods['goods_freight'];
+						
+					}
+				}
+			
+			
+			if( $kk == 0 && !empty($man_free_shipping) && $man_free_shipping > 0 && $order_goods_total_money >= $man_free_shipping )
+			{
+				
+				//$trans_free_toal = 0;
+				$is_free_shipping_fare = 1;
+			}
+			
+			//---结束结算运费 address_id
+			
+			$data_s['address_id'] = $this->_add_address($token,$ziti_name,$ziti_mobile,$province_name,$city_name, $country_name,$address_name);
+		}
+		else if('tuanz_send' == $dispatching)
+		{
+			$trans_free_toal = 0;
+			$delivery_tuanz_money = D('Home/Front')->get_config_by_name('delivery_tuanz_money');
+			
+			
+			$community_info_modify = $community_info;
+	
+			if( !empty($community_info_modify['is_modify_shipping_method']) && $community_info_modify['is_modify_shipping_method'] == 1 )
+			{
+				if( !empty($community_info_modify['is_modify_shipping_fare']) && $community_info_modify['is_modify_shipping_fare'] == 1 && $community_info_modify['shipping_fare'] > 0 )
+				{
+					$delivery_tuanz_money = $community_info_modify['shipping_fare'];
+				}
+			}
+			
+			
+			$trans_free_toal = $delivery_tuanz_money;
+			
+			$data['tuan_send_address'] = $data_s['tuan_send_address'];
+			
+			if( $kk == 0 && !empty($man_free_tuanzshipping) && $man_free_tuanzshipping > 0 && $order_goods_total_money >= $man_free_tuanzshipping )
+			{
+				$is_free_shipping_fare = 1;
+				//$trans_free_toal = 0;
+			}
+		}
+		
+		
+		
+		
+		//$is_pin; is_lottery
+		//'pintuan', 'normal', 'lottery'
+		$data['type'] = 'normal';
+		if($is_pin == 1)
+		{
+			$data['type'] = 'pintuan';
+			if($is_lottery == 1)
+			{
+				$data['type'] = 'lottery';
+			}
+		}
+		if($is_integral == 1)
+		{
+			$data['type'] = 'integral';
+			$is_pin = 0;
+		}
+		
+		if($is_hexiao == 1)
+		{
+			$data['type'] = 'virtual';
+			$is_pin = 0;
+		}
+		
+		
+		if($is_spike == 1)
+		{
+			$data['type'] = 'spike';
+			$is_pin = 0;
+		}
+
+        //礼品卡配送费0
+        if( $buy_type == 'virtualcard' )
+        {
+            $trans_free_toal = 0;
+        }
+
+		$data['shipping_fare'] = floatval($trans_free_toal);
+		
+		if($is_free_shipping_fare == 1)
+		{
+			$trans_free_toal = 0;
+		}
+
+		//原先计算满减金额
+		/*if($is_open_fullreduction == 1 && $man_total_free >= $full_money )
+		{
+			$reduce_money = $full_reducemoney ;
+		}*/
+        //多组满减金额计算
+        if($is_open_fullreduction == 1)
+        {
+            $reduce_result = D('Home/Front')->get_reduce_money($man_total_free);
+            $reduce_money = $reduce_result['reduce_money'];
+        }
+		
+		$data['is_free_shipping_fare']= $is_free_shipping_fare;
+		$data['store_id']= $kk;
+		$data['order_goods_total_money']= $order_goods_total_money;
+
+		$data['is_localtown_free_shipping_fare']= $is_localtown_free_shipping_fare;
+		$data['localtown_free_shipping_fare']= $localtown_free_shipping_fare;
+		
+		$data['goodss'] = $goods_data;
+		$data['order_num_alias']=build_order_no($member_id);
+			
+		$data['totals'][0]=array(
+			'code'=>'sub_total',
+			'title'=>'商品价格',
+			'text'=>'¥'.$order_total,
+			'value'=>$order_total
+		);
+		$data['totals'][1]=array(
+			'code'=>'shipping',
+			'title'=>'运费',
+			'text'=>'¥'.$trans_free_toal,
+			'value'=>$trans_free_toal
+		);
+			
+		$data['totals'][2]=array(
+			'code'=>'total',
+			'title'=>'总价',
+			'text'=>'¥'.($order_total+$trans_free_toal-$reduce_money),
+			'value'=>($order_total+$trans_free_toal-$reduce_money)
+		);
+	
+		$data['from_type'] = 'wepro';
+		
+		//目前都是平台券
+		if($data['voucher_id'] > 0) {
+			
+			//暂时屏蔽优惠券,等待开启 
+			/**
+			$voucher_info = pdo_fetch("select * from ".tablename('lionfish_comshop_coupon_list')." where uniacid=:uniacid and id=:id ", 
+									array(':uniacid' => $_W['uniacid'],':id' => $data['voucher_id']));
+			
+			$data['voucher_credit'] = $voucher_info['credit'];
+			
+			pdo_update('lionfish_comshop_coupon_list', array('ordersn' => $data['order_num_alias'],'consume' => 'Y','usetime' => time()), array('id' => $data['voucher_id'] ));
+			**/
+						
+			$voucher_info = M('lionfish_comshop_coupon_list')->where( array('id' => $data['voucher_id']) )->find();	
+			//检查优惠券指定商品或指定商品分类 优惠金额 begin
+			$voucher_list[0] = $voucher_info;
+			
+			$voucher_list = D('Home/Voucher')->get_voucher_amout_bygoods($voucher_list,$goods_data, 0);
+			
+			$voucher_info = $voucher_list[0];
+			//检查优惠券指定商品或指定商品分类 优惠金额 end
+			$data['voucher_credit'] = $voucher_info['can_vouche_amount'];
+			
+			$bili = 1;
+			
+			if( $zanbi_total_money > 0 )
+			{
+				$bili = round( ($order_goods_total_money / $zanbi_total_money), 2);
+			}
+			$data['voucher_credit'] = $data['voucher_credit'] * $bili;
+			
+			
+			//判断是否超出订单商品金额,不算运费
+			//if($data['voucher_credit'] > $order_total+$trans_free_toal - $reduce_money )
+			if($data['voucher_credit'] > $order_total - $reduce_money )
+			{
+				$data['voucher_credit'] = $order_total - $reduce_money;
+			}
+			
+			
+			M('lionfish_comshop_coupon_list')->where( array('id' => $data['voucher_id'] ) )->save( array('ordersn' => $data['order_num_alias'],'consume' => 'Y','usetime' => time() ) );
+			
+		} else {
+			$data['voucher_credit'] = 0;
+		}
+		
+		$use_score_total = 0;//用掉用户多少积分了.
+		$data['score_for_money'] = 0;
+		
+		if( $kk == 0 && $score_for_money  > 0)
+		{
+			
+			
+			
+			if( $order_total+$trans_free_toal - $reduce_money - $data['voucher_credit'] <= 0)
+			{
+				//没必要扣积分了,单价已经是0
+			}else{
+				//只能抵扣扣除优惠券部分的金额
+				$del_money = $order_total - $data['voucher_credit']  - $reduce_money;
+				
+				//var_dump($del_money, $score_for_money);die();
+				
+				//score_for_money 会员能抵扣的最大金额
+
+				
+				
+				//计算多少积分了。
+				
+				$score_forbuy_money_maxbi = D('Home/Front')->get_config_by_name('score_forbuy_money_maxbi');
+				$score_forbuy_money = D('Home/Front')->get_config_by_name('score_forbuy_money');
+	
+				if( empty($score_forbuy_money_maxbi) )
+				{
+					$score_forbuy_money_maxbi = 100;
+				}
+				
+				//$max_dikou_money =  sprintf('%.2f', ($del_money * $score_forbuy_money_maxbi) /100);
+				$max_dikou_score = floor($del_money * $score_forbuy_money_maxbi * $score_forbuy_money / 100 );
+				$max_dikou_money =  sprintf('%.2f', ($max_dikou_score / $score_forbuy_money));
+				if($max_dikou_money < $score_for_money)
+				{
+					$score_for_money = $max_dikou_money;
+				}
+				//$score_buy_money = 0;
+				$data['score_for_money'] = $score_for_money;
+				//TODO...扣除会员积分,将积分分拆入每个商品订单,写入日志
+				
+				//var_dump($data['score_for_money'], $max_dikou_money);die();
+			}
+		}
+		
+		
+		$data['comment'] = htmlspecialchars($comment);
+		
+		$data['reduce_money'] = $reduce_money;
+		
+		$data['man_total_free'] = $man_total_free;
+		
+		//判断自提 dispatching:"pickup"
+		//dispatching, //express  pickup
+		
+		if($dispatching == 'express')
+		{
+			$data['total']=($order_total);//+$fare - $data['voucher_credit']
+		}else if('tuanz_send' == $dispatching){
+			$data['total']=($order_total);// - $data['voucher_credit']);
+		}
+		else{
+			$data['total'] = ($order_total );// - $data['voucher_credit']
+		}
+		//积分商城
+		//暂时屏蔽积分商城模块
+
+
+		if($data['type'] == 'integral')
+		{
+			$del_integral += $order_total;//扣除积分
+			$data['total'] = $order_total;
+
+		}
+        $data['buy_type'] = $buy_type;//判断预售使用
+		//万能表单数据
+		$data['allform_id'] = $allform_id;
+		$data['allform_list'] = $allform_list;
+
+		$oid=  D('Home/Frontorder')->addOrder($data);// D('Order')->addOrder($data);
+
+
+
+		//暂时屏蔽自提模块
+		/**
+		if($data['delivery'] == 'pickup')
+		{
+			$verify_bool = true;
+			$verifycode = 0;
+			while($verify_bool)
+			{
+				$code  = (ceil(time()/100)+rand(10000000,40000000)).rand(1000,9999);
+				$verifycode = $code ? $code : rand(100000,999999);
+				$verifycode = str_replace('1989','9819',$verifycode);
+				$verifycode = str_replace('1259','9521',$verifycode);
+				$verifycode = str_replace('12590','95210',$verifycode);
+				$verifycode = str_replace('10086','68001',$verifycode);
+				
+				$pick_order = M('pick_order')->where( array('pick_sn' => $verifycode) )->find();
+				if(empty($pick_order))
+				{
+					$verify_bool = false;
+				}
+			}
+			$pick_data = array();
+			$pick_data['pick_sn'] = $verifycode;
+			$pick_data['pick_id'] = $pick_up_id;
+			$pick_data['order_id'] = $oid;
+			$pick_data['state'] = 0;
+			
+			$pick_data['ziti_name'] = $ziti_name;
+			$pick_data['ziti_mobile'] = $ziti_mobile;
+			
+		
+			$pick_data['addtime'] = time();
+			M('pick_order')->add($pick_data);
+		}
+		**/
+		
+		$order_ids_arr[] = $oid;
+		//$pay_total = $pay_total + $order_total+$trans_free_toal - $data['voucher_credit'];
+		if($dispatching == 'express' && $data['type'] != 'integral')
+		{
+			$pay_total = $pay_total + $order_total+$trans_free_toal - $data['voucher_credit']- $reduce_money - $data['score_for_money'];
+		}
+		else if( $dispatching == 'express' && $data['type'] == 'integral' )
+		{
+			$pay_total = $trans_free_toal;
+		}
+		else if('localtown_delivery' == $dispatching)
+        {
+            $pay_total = $pay_total + $order_total+ $packing_fare + $trans_free_toal - $data['voucher_credit'] -$reduce_money - $data['score_for_money'] + $data['localtown_add_shipping_fare'];
+        }
+		else if('tuanz_send' == $dispatching){
+			$pay_total = $pay_total + $order_total+$trans_free_toal - $data['voucher_credit'] -$reduce_money - $data['score_for_money'];
+		}
+		else{
+			$pay_total = $pay_total + $order_total - $data['voucher_credit'] -$reduce_money - $data['score_for_money'];
+		}
+
+
+        if( $buy_type == 'presale' )
+        {
+            //如果是预售,此处支付的就是定金
+            $presale_order_info =  M('lionfish_comshop_order_presale')->where(['order_id' => $oid ])->find();
+            if( $presale_order_info['presale_type'] == 1 )
+            {
+                M('lionfish_comshop_order_presale')->where( ['id' => $presale_order_info['id'] ] )->save( ['presale_ding_money' => $pay_total ] );
+            }else{
+                $pay_total = $presale_order_info['presale_ding_money'];
+            }
+        }
+
+            $pay_total = round($pay_total, 2);
+		
+		$order_relate_data = array();
+		
+		$order_relate_data['order_all_id'] = $order_all_id;
+		$order_relate_data['order_id'] = $oid;
+		$order_relate_data['addtime'] = time();
+		
+		M('lionfish_comshop_order_relate')->add($order_relate_data);
+		
+	}
+	
+	$order_all_data = array();
+	$order_all_data['total_money'] = $pay_total;
+		
+	M('lionfish_comshop_order_all')->where(  array('id' => $order_all_id) )->save($order_all_data);	
+	
+	if($order_all_id){
+			
+		$order = M('lionfish_comshop_order')->where( array('order_id' => $oid) )->find();	
+					
+		$member_info = M('lionfish_comshop_member')->field('we_openid,account_money')->where( array('member_id' => $member_id ) )->find();				
+		
+		$is_yue_open = 0;
+	
+		$is_yue_open = D('Home/Front')->get_config_by_name('is_open_yue_pay');
+		if( empty($is_yue_open) )
+		{
+			$is_yue_open = 0;
+		}
+	
+	    //检测是否需要扣除积分
+		if($data['type'] == 'integral' && $del_integral> 0 && $is_integral == 1)
+		{
+			
+			$order_goods_tp = M('lionfish_comshop_order_goods')->field('order_goods_id')->where( array('order_id' => $oid ) )->find();
+			
+			D('Admin/Member')->sendMemberPointChange($member_id,$del_integral, 1 ,'积分兑换商品', 'integral_exchange', $oid ,$order_goods_tp['order_goods_id']);
+		}
+		
+		$is_open_yinpay = D('Home/Front')->get_config_by_name('is_open_yinpay');
+		
+		if( $order['type'] == 'ignore' || $pay_total<=0 || ($is_yue_open == 1 && $ck_yupay == 1 && $member_info['account_money'] >= $pay_total) )
+		{
+			//余额支付独立方法
+			D('Home/OrderV2')->carOrderYuerPay( $order_all_id, $order ,$pay_total , $ck_yupay ,$buy_type, $is_integral, $is_spike , $is_just_1 );
+		}else if($buy_type == 'dan' && $cashon_delivery == 1){//货到付款订单
+			//货到付款支付独立方法
+			D('Home/OrderV2')->carOrderCashonPay( $order_all_id, $order ,$pay_total , $cashon_delivery , $buy_type , $is_spike , $is_just_1);
+		}
+		else if( isset($is_open_yinpay) && $is_open_yinpay == 3 )
+		{
+		    //begin
+		    
+		    $fee = $pay_total;
+		    $appid = D('Home/Front')->get_config_by_name('wepro_appid');
+		    
+		    $body =  $pay_goods_name;//'商品购买';
+		     
+		    $body = mb_substr($body,0,32,'utf-8');
+		     
+		    if( empty($body) )
+		    {
+		        $body = '商品购买';
+		    }
+		     
+		    $mch_id =       D('Home/Front')->get_config_by_name('wepro_partnerid');
+		    $nonce_str =    nonce_str();
+		    
+		    
+		    $shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
+		    	
+		    $notify_url =   $shop_domain.'/notify.php';
+		     
+		     
+		    $openid =       $payment['we_openid'];
+		    $out_trade_no = $order_all_id.'-'.time();
+		     
+		    //out_trade_no
+		    M('lionfish_comshop_order_all')->where( array('id' => $order_all_id ) )->save( array('out_trade_no' => $out_trade_no ) );
+		    	
+		    
+		    $spbill_create_ip = $_SERVER['REMOTE_ADDR'];
+		    $total_fee = $fee*100;
+		     
+		     
+		    //float(0.99999999999998)
+		    $trade_type = 'JSAPI';
+		    $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
+		     
+		    $post['appid'] =  D('Home/Front')->get_config_by_name('wepro_fuwu_appid');// 'wx7c38e2f177e0af59';
+		    $post['body'] = $body;
+		    $post['mch_id'] = D('Home/Front')->get_config_by_name('wepro_fuwu_partnerid');//'1562705521';
+		     
+		     
+		     
+		    $post['nonce_str'] = $nonce_str;
+		    $post['notify_url'] = $notify_url;
+		     
+		    //$post['openid'] = $openid;
+		    $post['out_trade_no'] = $out_trade_no;
+		    $post['spbill_create_ip'] = $spbill_create_ip;
+		    $post['sub_appid'] = $appid;
+		    $post['sub_mch_id'] = D('Home/Front')->get_config_by_name('wepro_sub_mch_id');
+		    $post['sub_openid'] = $openid;
+			
+		    $post['total_fee'] = $total_fee;
+		    $post['trade_type'] = $trade_type;
+		    $sign = sign($post,$pay_key);
+		     
+		    //var_dump( $notify_url );die();
+		     
+		    $post_xml = '<xml>
+				   <appid>'.$post['appid'].'</appid>
+				   <body>'.$body.'</body>
+				   <mch_id>'.$post['mch_id'].'</mch_id>
+				   <nonce_str>'.$nonce_str.'</nonce_str>
+				   <notify_url>'.$notify_url.'</notify_url>
+				   
+				   <out_trade_no>'.$out_trade_no.'</out_trade_no>
+				   <spbill_create_ip>'.$spbill_create_ip.'</spbill_create_ip>
+				   <sub_appid>'.$post['sub_appid'].'</sub_appid>
+				   <sub_mch_id>'.$post['sub_mch_id'].'</sub_mch_id>
+				   <sub_openid>'.$openid.'</sub_openid>
+				   <total_fee>'.$total_fee.'</total_fee>
+				   <trade_type>'.$trade_type.'</trade_type>
+				   <sign>'.$sign.'</sign>
+				</xml> ';
+		    $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
+		    $xml = http_request($url,$post_xml);
+		    $array = xml($xml);
+		     
+		    if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS'){
+		        
+				D('Home/Pin')->insertNotifyOrder($order['order_id']);
+				
+				$time = time();
+				$tmp=array();
+				$tmp['appId'] = $appid;
+				$tmp['nonceStr'] = $nonce_str;
+				$tmp['package'] = 'prepay_id='.$array['PREPAY_ID'];
+				$tmp['signType'] = 'MD5';
+				$tmp['timeStamp'] = "$time";
+				
+				$prepay_id = (string)$array['PREPAY_ID'];
+				
+				
+				M('lionfish_comshop_order')->where( array('order_id' => array('in', $order_ids_arr)) )->save( array('perpay_id' => $prepay_id) );
+
+
+
+
+				//M('order')->where( array('order_id' => array('in',$order_ids_arr) ) )->save( array('perpay_id' => (string)$array['PREPAY_ID']) );
+				$data = array();
+				$data['code'] = 0;
+				$data['appid'] = $appid;
+				$data['timeStamp'] = "$time";
+				$data['nonceStr'] = $nonce_str;
+				$data['signType'] = 'MD5';
+				$data['package'] = 'prepay_id='.$array['PREPAY_ID'];
+				$data['paySign'] = sign($tmp,$pay_key);
+				$data['out_trade_no'] = $out_trade_no;
+				
+				$data['is_go_orderlist'] = $is_just_1;
+
+
+
+				if($is_pin == 1)
+				{
+					$data['redirect_url'] = '../groups/group?id='.$oid.'&is_show=1';
+				} else {
+					$data['redirect_url'] = '../orders/order_show_all?order_all_id=' + $order_all_id;
+				}
+				
+			}else{
+		        $data = array();
+		        $data['code'] = 1;
+		        $data['text'] = "错误";
+		        $data['RETURN_CODE'] = $array['RETURN_CODE'];
+		        $data['RETURN_MSG'] = $array['RETURN_MSG'];
+		    }
+		    $data['has_yupay'] = 0;
+		    
+		    //end
+		}
+		else{
+			
+			$fee = $pay_total;
+			$appid = D('Home/Front')->get_config_by_name('wepro_appid');
+			
+			$body =  $pay_goods_name;//'商品购买';
+			
+			$body = mb_substr($body,0,32,'utf-8');
+			
+			if( empty($body) )
+			{
+				$body = '商品购买';
+			}
+			
+			
+			$mch_id =       D('Home/Front')->get_config_by_name('wepro_partnerid');
+			
+			$shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
+			
+			$nonce_str =    nonce_str();
+			$notify_url =   $shop_domain.'/notify.php';
+			
+			
+			$openid =       $payment['we_openid'];
+			$out_trade_no = $order_all_id.'-'.time();
+			
+			//out_trade_no 
+			M('lionfish_comshop_order_all')->where( array('id' => $order_all_id ) )->save( array('out_trade_no' => $out_trade_no ) );
+			
+			
+			$spbill_create_ip = $_SERVER['REMOTE_ADDR'];
+			$total_fee =    $fee*100;
+			$trade_type = 'JSAPI';
+			$pay_key = D('Home/Front')->get_config_by_name('wepro_key');
+
+			$post['appid'] = $appid;
+			$post['body'] = $body;
+			$post['mch_id'] = $mch_id;
+			$post['nonce_str'] = $nonce_str;
+			$post['notify_url'] = $notify_url;
+			
+			$post['openid'] = $openid;
+			$post['out_trade_no'] = $out_trade_no;
+			$post['spbill_create_ip'] = $spbill_create_ip;
+			$post['total_fee'] = $total_fee;
+			$post['trade_type'] = $trade_type;
+			$sign = sign($post,$pay_key);
+			
+			
+			$post_xml = '<xml>
+				   <appid>'.$appid.'</appid>
+				   <body>'.$body.'</body>
+				   <mch_id>'.$mch_id.'</mch_id>
+				   <nonce_str>'.$nonce_str.'</nonce_str>
+				   <notify_url>'.$notify_url.'</notify_url>
+				   <openid>'.$openid.'</openid>
+				   <out_trade_no>'.$out_trade_no.'</out_trade_no>
+				   <spbill_create_ip>'.$spbill_create_ip.'</spbill_create_ip>
+				   <total_fee>'.$total_fee.'</total_fee>
+				   <trade_type>'.$trade_type.'</trade_type>
+				   <sign>'.$sign.'</sign>
+				</xml> ';
+			$url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
+			$xml = http_request($url,$post_xml);
+			$array = xml($xml);
+			
+			if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS'){
+				D('Home/Pin')->insertNotifyOrder($order['order_id']);
+				$time = time();
+				$tmp=array();
+				$tmp['appId'] = $appid;
+				$tmp['nonceStr'] = $nonce_str;
+				$tmp['package'] = 'prepay_id='.$array['PREPAY_ID'];
+				$tmp['signType'] = 'MD5';
+				$tmp['timeStamp'] = "$time";
+				
+				$prepay_id = (string)$array['PREPAY_ID'];
+				
+				
+				M('lionfish_comshop_order')->where( array('order_id' => array('in', $order_ids_arr)) )->save( array('perpay_id' => $prepay_id) );
+				
+				
+				
+				//M('order')->where( array('order_id' => array('in',$order_ids_arr) ) )->save( array('perpay_id' => (string)$array['PREPAY_ID']) );
+				$data = array();
+				$data['code'] = 0;
+				$data['appid'] = $appid;
+				$data['timeStamp'] = "$time";
+				$data['nonceStr'] = $nonce_str;
+				$data['signType'] = 'MD5';
+				$data['package'] = 'prepay_id='.$array['PREPAY_ID'];
+				$data['paySign'] = sign($tmp,$pay_key);
+				$data['out_trade_no'] = $out_trade_no;
+				
+				$data['is_go_orderlist'] = $is_just_1;
+
+                //如果是微信小程序交易组件begin---新支付方法 wx.requestOrderPayment
+                $data['order_info'] = [];
+                $data['isRequestOrderPayment'] = $is_need_scene_check;
+                if($is_need_scene_check == 1)
+                {
+                    $orderPamentResult = D('Seller/MpModifyTradeComponts')->getTradeOrderInfo( $oid , $time , $pay_total );
+                    //如果是微信小程序交易组件,提供订单信息 end
+                    $data['order_info'] = $orderPamentResult['order_info'];
+                }
+
+
+                if($is_pin == 1)
+				{
+					$data['redirect_url'] = '../groups/group?id='.$oid.'&is_show=1';
+				} else {
+					$data['redirect_url'] = '../orders/order_show_all?order_all_id=' + $order_all_id;
+				}
+				
+			}else{
+				$data = array();
+				$data['code'] = 1;
+				$data['text'] = "错误";
+				$data['RETURN_CODE'] = $array['RETURN_CODE'];
+				$data['RETURN_MSG'] = $array['RETURN_MSG'];
+				}
+				$data['has_yupay'] = 0;
+			}
+			
+			if($is_pin == 1)
+			{
+				$data['order_id'] = $oid;
+				$data['order_all_id'] = $order_all_id;
+			}else{
+				$data['order_id'] = $oid;
+				$data['order_all_id'] = $order_all_id;
+			}
+			$data['is_go_orderlist'] = $is_just_1;
+			
+			$data['is_spike'] = $is_spike;
+			echo json_encode($data);
+			die();	
+		}else{
+			echo json_encode( array('code' =>1,'order_all_id' =>$order_all_id) );
+			die();
+		}
+			
+	}
+	
+	function requestAsHttpPOST($data, $service_url){
+        $HTTP_TIME_OUT= "20";
+        ksort(array_filter($data)); //删除数组中的空值并排序
+        $post_data = http_build_query($data);
+	
+        $options = array(
+            'http' => array(
+                'method'  => 'POST',
+                'header'  => 'Content-type:application/x-www-form-urlencoded;charset=MD5',
+                'content' => $post_data,
+                'timeout' => $HTTP_TIME_OUT * 1000 //超时时间,*1000将毫秒变为秒(单位:s)
+            )
+        );
+        $context = stream_context_create($options);
+        $result = file_get_contents($service_url, false, $context);
+        return $result;
+    }
+	
+	
+	/**
+		微信充值
+	**/
+	public function wxcharge()
+	{
+		$_GPC = I('request.');
+		
+		$token = $_GPC['token'];
+	
+		
+		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
+		
+		$member_id = $weprogram_token['member_id'];
+		
+		if( empty($member_id) )
+		{
+			echo json_encode( array('code' =>1,'msg' =>'未登录') );
+			die();
+		}
+		
+		$money = $_GPC['money'];
+		
+		$rech_id = isset($_GPC['rech_id']) && $_GPC['rech_id'] > 0 ? $_GPC['rech_id'] : 0;
+
+		$member_info = M('lionfish_comshop_member')->field('we_openid')->where( array('member_id' => $member_id) )->find();
+		
+		$give_money = 0;
+		
+		if( $rech_id > 0 )
+		{
+			$rech_info = M('lionfish_comshop_chargetype')->where( array('id' => $rech_id ) )->find();
+			
+			if( !empty($rech_info) )
+			{
+				$give_money = $rech_info['send_money'];
+			}
+
+			$money = $rech_info['money'];
+		}else{
+			$recharge_get_money = D('Home/Front')->get_config_by_name('recharge_get_money');
+
+			if(isset($recharge_get_money) && $recharge_get_money == 1){
+				$rech_info = M('lionfish_comshop_chargetype')->where( "money <= ".$money )->order('money desc')->limit(1)->find();
+
+				if( !empty($rech_info) )
+				{
+					$give_money = $rech_info['send_money'];
+				}
+			}
+
+		}
+		
+		
+		
+		$member_charge_flow_data = array();
+		$member_charge_flow_data['member_id'] = $member_id;
+		$member_charge_flow_data['money'] = $money;
+		$member_charge_flow_data['state'] = 0;
+		$member_charge_flow_data['give_money'] = $give_money;
+		$member_charge_flow_data['charge_time'] = 0;
+		$member_charge_flow_data['remark'] = '会员前台微信充值';
+		$member_charge_flow_data['add_time'] = time();
+		
+		$order_id = M('lionfish_comshop_member_charge_flow')->add( $member_charge_flow_data );
+		
+		
+		$shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
+		
+	
+		
+			
+		
+		$fee = $money;
+		$appid = D('Home/Front')->get_config_by_name('wepro_appid');
+		$body =         '会员充值';
+		$mch_id =      D('Home/Front')->get_config_by_name('wepro_partnerid');
+		$nonce_str =    nonce_str();
+		$notify_url =   $shop_domain.'/notify.php';
+		$openid =       $member_info['we_openid'];
+		$out_trade_no = $order_id.'-'.time().'-charge-'.$id;
+		$spbill_create_ip = $_SERVER['REMOTE_ADDR'];
+		$total_fee =    $fee*100;
+		
+		
+		$is_open_yinpay = D('Home/Front')->get_config_by_name('is_open_yinpay');
+		if( isset($is_open_yinpay) && $is_open_yinpay == 3 )
+		{
+
+		    $trade_type = 'JSAPI';
+		    $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
+		    $post = array();
+			$post['appid'] =  D('Home/Front')->get_config_by_name('wepro_fuwu_appid');// 'wx7c38e2f177e0af59';
+		    $post['body'] = $body;
+		    $post['mch_id'] = D('Home/Front')->get_config_by_name('wepro_fuwu_partnerid');//'1562705521';
+		    $post['nonce_str'] = $nonce_str;
+		    $post['notify_url'] = $notify_url;
+		    //$post['openid'] = $openid;
+		    $post['out_trade_no'] = $out_trade_no;
+		    $post['spbill_create_ip'] = $spbill_create_ip;
+		    $post['sub_appid'] = $appid;
+		    $post['sub_mch_id'] = D('Home/Front')->get_config_by_name('wepro_sub_mch_id');
+		    $post['sub_openid'] = $openid;
+		    $post['total_fee'] = $total_fee;
+		    $post['trade_type'] = $trade_type;
+		    $sign = sign($post,$pay_key);
+			
+
+		    $post_xml = '<xml>
+				   <appid>'.$post['appid'].'</appid>
+				   <body>'.$body.'</body>
+				   <mch_id>'.$post['mch_id'].'</mch_id>
+				   <nonce_str>'.$nonce_str.'</nonce_str>
+				   <notify_url>'.$notify_url.'</notify_url>
+				   
+				   <out_trade_no>'.$out_trade_no.'</out_trade_no>
+				   <spbill_create_ip>'.$spbill_create_ip.'</spbill_create_ip>
+				   <sub_appid>'.$post['sub_appid'].'</sub_appid>
+				   <sub_mch_id>'.$post['sub_mch_id'].'</sub_mch_id>
+				   <sub_openid>'.$openid.'</sub_openid>
+				   <total_fee>'.$total_fee.'</total_fee>
+				   <trade_type>'.$trade_type.'</trade_type>
+				   <sign>'.$sign.'</sign>
+				</xml> ';
+		    $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
+		    $xml = http_request($url,$post_xml);
+		    $array = xml($xml);
+		    
+		    //end
+		}else{
+			
+			$trade_type = 'JSAPI';
+			$pay_key = D('Home/Front')->get_config_by_name('wepro_key');
+			
+			$post = array();
+			
+			$post['appid'] = $appid;
+			$post['body'] = $body;
+			$post['mch_id'] = $mch_id;
+			$post['nonce_str'] = $nonce_str;
+			$post['notify_url'] = $notify_url;
+			$post['openid'] = $openid;
+			$post['out_trade_no'] = $out_trade_no;
+			$post['spbill_create_ip'] = $spbill_create_ip;
+			$post['total_fee'] = $total_fee;
+			$post['trade_type'] = $trade_type;
+			
+			$sign = sign($post,$pay_key);
+			
+			//sign()
+			$post_xml = '<xml>
+				   <appid>'.$appid.'</appid>
+				   <body>'.$body.'</body>
+				   <mch_id>'.$mch_id.'</mch_id>
+				   <nonce_str>'.$nonce_str.'</nonce_str>
+				   <notify_url>'.$notify_url.'</notify_url>
+				   <openid>'.$openid.'</openid>
+				   <out_trade_no>'.$out_trade_no.'</out_trade_no>
+				   <spbill_create_ip>'.$spbill_create_ip.'</spbill_create_ip>
+				   <total_fee>'.$total_fee.'</total_fee>
+				   <trade_type>'.$trade_type.'</trade_type>
+				   <sign>'.$sign.'</sign>
+				</xml> ';
+			$url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
+			$xml = http_request($url,$post_xml);
+			$array = xml($xml);
+		}
+		
+		
+		
+		
+		if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS'){
+			$time = time();
+			$tmp= array();
+			$tmp['appId'] = $appid;
+			$tmp['nonceStr'] = $nonce_str;
+			$tmp['package'] = 'prepay_id='.$array['PREPAY_ID'];
+			$tmp['signType'] = 'MD5';
+			$tmp['timeStamp'] = "$time";
+			
+			M('lionfish_comshop_member_charge_flow')->where( array('id' => $order_id) )->save( array('formid' => $array['PREPAY_ID'] ) );
+			
+			$data['code'] = 0;
+			$data['timeStamp'] = "$time";
+			$data['nonceStr'] = $nonce_str;
+			$data['signType'] = 'MD5';
+			$data['package'] = 'prepay_id='.$array['PREPAY_ID'];
+			$data['paySign'] =   sign($tmp, $pay_key);
+			$data['out_trade_no'] = $out_trade_no;
+			
+			$data['redirect_url'] = '../dan/me';
+			
+		}else{
+			$data['code'] = 1;
+			$data['text'] = "错误";
+			$data['RETURN_CODE'] = $array['RETURN_CODE'];
+			$data['RETURN_MSG'] = $array['RETURN_MSG'];
+		}
+		
+		
+		
+		echo json_encode($data);
+		die();
+		
+	}
+
+
+	public function wxpay()
+	{
+		$gpc = I('request.');
+		
+		$token = $gpc['token'];
+		$order_id = $gpc['order_id'];
+
+        $scene = $gpc['scene'];
+        $is_need_scene_check = 0;
+
+        if(!empty($scene))
+        {
+            $is_need_scene_check = D('Seller/MpModifyTradeComponts')->sceneCheck( $scene );
+        }
+		
+		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
+		
+		
+		$member_id = $weprogram_token['member_id'];
+		
+		
+		if( empty($member_id) )
+		{
+			echo json_encode( array('code' =>1,'msg' =>'未登录') );
+			die();
+		}
+		
+		
+		$member_info = M('lionfish_comshop_member')->field('we_openid')->where( array('member_id' => $member_id) )->find();
+		
+		
+		$order = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
+		
+		
+		//order_status_id
+		
+		if( $order['order_status_id'] != 3 && $order['order_status_id'] != 15 )
+		{
+			$json = array();
+			
+			$json['msg']='商品已下架!';
+			$json['code'] = 2;
+			if($order['order_status_id'] == 1)
+			{
+				$json['msg']='订单已付款,请勿重新付款!';
+			}
+			else if( $order['order_status_id'] == 5){
+				$json['msg']='订单已取消,请重新选择商品下单!';
+			}
+			echo json_encode($json);
+			die();
+		}
+		
+		
+		
+		//检测商品是否下架 begin
+		$sql = "select name,quantity,rela_goodsoption_valueid,goods_id from ".C('DB_PREFIX')."lionfish_comshop_order_goods  
+					where order_id={$order_id} ";
+			
+		$order_goods_list = M()->query($sql);
+		
+		foreach($order_goods_list as $tp_val)
+		{
+			$tp_gd_info = M('lionfish_comshop_goods')->field('grounding')->where( array('id' => $tp_val['goods_id'] ) )->find();
+			
+			if( empty($tp_gd_info) || $tp_gd_info['grounding'] != 1 )
+			{
+				$json['code'] = 2;
+					
+				$json['msg']='商品已下架!';
+			
+				echo json_encode($json);
+				die();
+			}
+		}
+		
+		//检测商品是否下架end   
+		//检测是否预售商品。预售商品不需要检测二次支付问题
+        $presale_info = [];
+        $presale_result = D('Home/PresaleGoods')->getOrderPresaleInfo( $order_id );
+        if( $presale_result['code'] == 0 )
+        {
+            $presale_info = $presale_result['data'];
+        }
+		//检测是否已经支付过了begin
+		
+		$order_relate_info = M('lionfish_comshop_order_relate')->where( array('order_id' => $order_id ) )->order('id desc')->find();
+		
+		if( !empty($order_relate_info) && $order_relate_info['order_all_id'] > 0  && empty($presale_info) )
+		{
+			$order_all_info = M('lionfish_comshop_order_all')->where( array('id' => $order_relate_info['order_all_id'] ) )->find();
+			
+			if( !empty($order_all_info) && !empty($order_all_info['out_trade_no']) )
+			{
+				
+				$out_trade_no = $order_all_info['out_trade_no'];
+		
+				$appid =  D('Home/Front')->get_config_by_name('wepro_appid');
+				$mch_id =      D('Home/Front')->get_config_by_name('wepro_partnerid');
+				$nonce_str =    nonce_str();
+				
+				$pay_key = D('Home/Front')->get_config_by_name('wepro_key');
+				
+				
+				$post = array();
+				$post['appid'] = $appid;
+				$post['mch_id'] = $mch_id;
+				$post['nonce_str'] = $nonce_str;
+				$post['out_trade_no'] = $out_trade_no;
+			
+				$sign = sign($post,$pay_key);
+				
+				$post_xml = '<xml>
+							   <appid>'.$appid.'</appid>
+							   <mch_id>'.$mch_id.'</mch_id>
+							   <nonce_str>'.$nonce_str.'</nonce_str>
+							   <out_trade_no>'.$out_trade_no.'</out_trade_no>
+							   <sign>'.$sign.'</sign>
+							</xml>';
+					
+				$url = "https://api.mch.weixin.qq.com/pay/orderquery";
+				
+				$result = http_request($url,$post_xml);
+				
+				$array = xml($result);
+				
+				if( $array['RETURN_CODE'] == 'SUCCESS' && $array['RETURN_MSG'] == 'OK' )
+				{
+					if( $array['TRADE_STATE'] == 'SUCCESS' )
+					{
+						$json = array();
+			
+						$json['msg']='商品已下架!';
+						$json['code'] = 2;
+						$json['msg']='订单已付款,请勿重新付款,请刷新页面!';
+						echo json_encode($json);
+						die();
+					}
+				}
+				
+			}
+		}
+		
+		//检测是否已经支付过了end  
+		
+		//支付才减库存,才需要判断
+		$kucun_method = D('Home/Front')->get_config_by_name('kucun_method');
+						
+		if( empty($kucun_method) )
+		{
+			$kucun_method = 0;
+		}
+		
+		if($kucun_method == 1 && ( empty($presale_info) || $presale_info['state'] != 1 ) )
+		{
+			/*** 检测商品库存begin  **/
+
+			//goods_id
+			foreach($order_goods_list as $val)
+			{
+				$quantity = $val['quantity'];
+				
+				$goods_id = $val['goods_id'];
+				
+				$can_buy_count = D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
+				
+				$goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'total_limit_count');
+				
+				if($can_buy_count == -1)
+				{
+					$json['code'] = 2;
+					
+					$json['msg']='您还能购买'.$goods_description['total_limit_count'].'个';
+				
+					echo json_encode($json);
+					die();
+				}else if($can_buy_count >0 && $quantity >$can_buy_count)
+				{
+					$json['code'] = 2;
+					$json['msg']='您还能购买'.$can_buy_count.'份';
+					echo json_encode($json);
+					die();
+				}
+				//rela_goodsoption_valueid
+				if(!empty($val['rela_goodsoption_valueid']))
+				{
+					$mul_opt_arr = array();
+					
+					//ims_ 
+					
+					$goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->where( array('goods_id' => $goods_id,'option_item_ids' => $val['rela_goodsoption_valueid']) )->find();				
+									
+					
+					if( !empty($goods_option_mult_value) )
+					{
+						if($goods_option_mult_value['stock']<$quantity){
+							$json['code'] =2;
+							$json['msg']='商品数量不足,剩余'.$goods_option_mult_value['stock'].'个!!';
+							echo json_encode($json);
+							die();
+						}
+					}
+				}
+				
+			}
+			/*** 检测商品库存end **/
+		}
+	
+		$pin_order = array();
+		if( !empty($pin_order) )
+		{
+			/**
+			$pin_model =  load_model_class('pin');
+			$is_pin_over = $pin_model->getNowPinState($pin_order['pin_id']);
+			if($is_pin_over != 0)
+			{
+				 pdo_query("delete from ".tablename('lionfish_comshop_pin_order')." where order_id = {$order_id} ");
+				 
+				 pdo_query("delete from ".tablename('lionfish_comshop_pin')." where pin_id = ".$pin_order['pin_id']." and order_id = ".$order_id);
+				 
+				$order_goods_info = pdo_fetch("select goods_id from ".tablename('lionfish_comshop_order_goods')." where uniacid=:uniacid and order_id=:order_id ", array(':order_id' => $order_id,':uniacid' => $_W['uniacid']));
+				
+				//新开团
+				
+				$pin_id = $pin_model->openNewTuan($order_id,$order_goods_info['goods_id'],$member_id);
+				//插入拼团订单
+	            $pin_model->insertTuanOrder($pin_id,$order_id);
+	               
+			}
+			**/
+		}
+		
+		
+		//单独支付一个店铺的订单
+		//M('lionfish_comshop_order_relate')->where( array('order_id' => $order_id) )->delete();
+		
+		$order_all_data = array();
+		$order_all_data['member_id'] = $member_id;
+		$order_all_data['order_num_alias'] = build_order_no($member_id);
+		$order_all_data['transaction_id'] = '';
+		$order_all_data['order_status_id'] = 3;
+		$order_all_data['is_pin'] = $order['is_pin'];
+		$order_all_data['paytime'] = 0;
+		$order_all_data['total_money'] = $order['total']+ $order['shipping_fare']-$order['voucher_credit']-$order['fullreduction_money'];
+		$order_all_data['addtime'] = time();
+		
+		$order_all_id = M('lionfish_comshop_order_all')->add($order_all_data);
+			
+		$order_relate_data = array();
+		$order_relate_data['order_all_id'] = $order_all_id;
+		$order_relate_data['order_id'] = $order_id;
+		$order_relate_data['addtime'] = time();
+		
+		M('lionfish_comshop_order_relate')->add($order_relate_data);
+		
+		if( $order['delivery'] == 'pickup' )
+		{
+			$fee = $order['total']+ $order['shipping_fare']-$order['voucher_credit']-$order['fullreduction_money'] - $order['score_for_money'] - $order['fare_shipping_free'];
+		}else if($order['delivery'] == 'localtown_delivery'){
+			$fee = $order['total'] + $order['packing_fare'] + $order['shipping_fare']-$order['voucher_credit'] - $order['fullreduction_money'] - $order['score_for_money'] + $order['localtown_add_shipping_fare'] - $order['fare_shipping_free'];
+		}else {
+			$fee = $order['total']+ $order['shipping_fare']-$order['voucher_credit']-$order['fullreduction_money'] - $order['score_for_money'] - $order['fare_shipping_free'];
+		}
+
+		//如果是预售 begin
+
+        if( !empty($presale_info) )
+        {
+            if( $presale_info['state'] == 0 )
+            {
+                //首次支付,
+                $fee = $presale_info['presale_ding_money'];
+            }else if( $presale_info['state'] == 1 )
+            {
+                //第二次支付
+                if( !empty($presale_info['presale_deduction_money']) && false )
+                {
+                    $fee = $fee - $presale_info['presale_deduction_money'];
+                }else{
+                    $fee = $fee - $presale_info['presale_ding_money'];
+                }
+            }
+        }
+        //end
+
+
+		$fee = round($fee , 2);
+			
+		
+		$appid = D('Home/Front')->get_config_by_name('wepro_appid');
+		
+		
+		$body =  $pay_goods_name;//'商品购买';
+		
+		$body = mb_substr($body,0,32,'utf-8');
+		
+		if( empty($body) )
+		{
+		    $body =         '商品购买';
+		}
+			
+		
+		$mch_id =       D('Home/Front')->get_config_by_name('wepro_partnerid');
+		$nonce_str =    nonce_str();
+		
+		$shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
+		
+		$notify_url =    $shop_domain.'/notify.php';
+		
+		$openid =       $member_info['we_openid'];
+		$out_trade_no = $order_all_id.'-'.time();
+		$spbill_create_ip = $_SERVER['REMOTE_ADDR'];
+		$total_fee =    $fee*100;
+		$trade_type = 'JSAPI';
+		$pay_key = D('Home/Front')->get_config_by_name('wepro_key');
+		
+		
+		$is_open_yinpay = D('Home/Front')->get_config_by_name('is_open_yinpay');
+		
+		//begin
+		
+		if( isset($is_open_yinpay) && $is_open_yinpay == 3 )
+		{
+		    $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
+		    	
+		    $body = '商品购买';
+		    	
+		    $post = array();
+		    	
+		    $post['appid'] = D('Home/Front')->get_config_by_name('wepro_fuwu_appid');
+		    $post['body'] = $body;
+		    $post['mch_id'] =  D('Home/Front')->get_config_by_name('wepro_fuwu_partnerid');
+		    $post['nonce_str'] = $nonce_str;
+		    $post['notify_url'] = $notify_url;
+		    //$post['openid'] = $openid;
+		    $post['out_trade_no'] = $out_trade_no;
+		    $post['spbill_create_ip'] = $spbill_create_ip;
+		    $post['sub_appid'] = D('Home/Front')->get_config_by_name('wepro_appid');
+		    $post['sub_mch_id'] = D('Home/Front')->get_config_by_name('wepro_sub_mch_id');
+			$post['sub_openid'] = $openid;
+		    	
+		    $post['total_fee'] = $total_fee;
+		    $post['trade_type'] = $trade_type;
+		    $sign = sign($post,$pay_key);
+		    	
+		    $post_xml = '<xml>
+				   <appid>'.$post['appid'].'</appid>
+				   <body>'.$body.'</body>
+				   <mch_id>'.$post['mch_id'].'</mch_id>
+				   <nonce_str>'.$nonce_str.'</nonce_str>
+				   <notify_url>'.$notify_url.'</notify_url>
+				   
+				   <out_trade_no>'.$out_trade_no.'</out_trade_no>
+				   <spbill_create_ip>'.$spbill_create_ip.'</spbill_create_ip>
+				   <sub_appid>'.$post['sub_appid'].'</sub_appid>
+				   <sub_mch_id>'.$post['sub_mch_id'].'</sub_mch_id>
+				   <sub_openid>'.$openid.'</sub_openid>
+				   <total_fee>'.$total_fee.'</total_fee>
+				   <trade_type>'.$trade_type.'</trade_type>
+				   <sign>'.$sign.'</sign>
+				</xml>';
+		
+		    	
+		    $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
+		    $xml = http_request($url,$post_xml);
+		    $array = xml($xml);
+		    	
+    		if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS'){
+    			$time = time();
+    			$tmp= array();
+    			$tmp['appId'] = $appid;
+    			$tmp['nonceStr'] = $nonce_str;
+    			$tmp['package'] = 'prepay_id='.$array['PREPAY_ID'];
+    			$tmp['signType'] = 'MD5';
+    			$tmp['timeStamp'] = "$time";
+    			
+    			$prepay_id = (string)$array['PREPAY_ID'];
+    			
+    			M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('perpay_id' => $prepay_id) );
+    				
+    			
+    			$data['code'] = 0;
+    			$data['timeStamp'] = "$time";
+    			$data['nonceStr'] = $nonce_str;
+    			$data['signType'] = 'MD5';
+    			$data['package'] = 'prepay_id='.$array['PREPAY_ID'];
+    			$data['paySign'] = sign($tmp, $pay_key);
+    			$data['out_trade_no'] = $out_trade_no;
+    			$data['is_pin'] = $order['is_pin'];
+    			
+    			if($order['is_pin'] == 1)
+    			{
+    				$data['redirect_url'] = '../groups/group?id='.$order_id.'&is_show=1';
+    			} else {
+    				$data['redirect_url'] = '../orders/order?id=' + $order_id;
+    			}
+    			
+    		}else{
+    		        $data['code'] = 1;
+    		        $data['text'] = "错误";
+    		        $data['RETURN_CODE'] = $array['RETURN_CODE'];
+    		        $data['RETURN_MSG'] = $array['RETURN_MSG'];
+		    }
+		    	
+		    	
+		    echo json_encode($data);
+		    die();
+		}
+		
+		//end
+		
+		$post = array();
+		$post['appid'] = $appid;
+		$post['body'] = $body;
+		$post['mch_id'] = $mch_id;
+		$post['nonce_str'] = $nonce_str;
+		$post['notify_url'] = $notify_url;
+		$post['openid'] = $openid;
+		$post['out_trade_no'] = $out_trade_no;
+		$post['spbill_create_ip'] = $spbill_create_ip;
+		$post['total_fee'] = $total_fee;
+		$post['trade_type'] = $trade_type;
+		$sign = sign($post,$pay_key);
+		
+		
+		$post_xml = '<xml>
+			   <appid>'.$appid.'</appid>
+			   <body>'.$body.'</body>
+			   <mch_id>'.$mch_id.'</mch_id>
+			   <nonce_str>'.$nonce_str.'</nonce_str>
+			   <notify_url>'.$notify_url.'</notify_url>
+			   <openid>'.$openid.'</openid>
+			   <out_trade_no>'.$out_trade_no.'</out_trade_no>
+			   <spbill_create_ip>'.$spbill_create_ip.'</spbill_create_ip>
+			   <total_fee>'.$total_fee.'</total_fee>
+			   <trade_type>'.$trade_type.'</trade_type>
+			   <sign>'.$sign.'</sign>
+			</xml> ';
+		$url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
+		$xml = http_request($url,$post_xml);
+		$array = xml($xml);
+		if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS'){
+			$time = time();
+			$tmp= array();
+			$tmp['appId'] = $appid;
+			$tmp['nonceStr'] = $nonce_str;
+			$tmp['package'] = 'prepay_id='.$array['PREPAY_ID'];
+			$tmp['signType'] = 'MD5';
+			$tmp['timeStamp'] = "$time";
+			
+			$prepay_id = (string)$array['PREPAY_ID'];
+			
+			M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('perpay_id' => $prepay_id) );
+
+
+			$data['code'] = 0;
+			$data['timeStamp'] = "$time";
+			$data['nonceStr'] = $nonce_str;
+			$data['signType'] = 'MD5';
+			$data['package'] = 'prepay_id='.$array['PREPAY_ID'];
+			$data['paySign'] = sign($tmp, $pay_key);
+			$data['out_trade_no'] = $out_trade_no;
+			$data['is_pin'] = $order['is_pin'];
+
+            //如果是微信小程序交易组件begin---新支付方法 wx.requestOrderPayment
+            $data['order_info'] = [];
+            $data['isRequestOrderPayment'] = $is_need_scene_check;
+            if($is_need_scene_check == 1)
+            {
+                $orderPamentResult = D('Seller/MpModifyTradeComponts')->getTradeOrderInfo( $order_id , $time , $fee );
+                //如果是微信小程序交易组件,提供订单信息 end
+                $data['order_info'] = $orderPamentResult['order_info'];
+            }
+			
+			if($order['is_pin'] == 1)
+			{
+				$data['redirect_url'] = '../groups/group?id='.$order_id.'&is_show=1';
+			} else {
+				$data['redirect_url'] = '../orders/order?id=' + $order_id;
+			}
+			
+		}else{
+			$data['code'] = 1;
+			$data['text'] = "错误";
+			$data['RETURN_CODE'] = $array['RETURN_CODE'];
+			$data['RETURN_MSG'] = $array['RETURN_MSG'];
+		}
+		
+		
+		echo json_encode($data);
+		die();
+	}
+
+	/**
+	 * 获取购物车总数
+	 */
+	public function count() {
+		
+		$gpc = I('request.');
+		
+		$data = array();
+		$token = $gpc['token'];
+		$community_id = $gpc['community_id'];
+
+		$cart= D('Home/Car');
+		$total=$cart->count_goodscar($token, $community_id);
+
+		$data['code'] = 0;
+		$data['data'] = $total;
+		echo json_encode($data);
+		die();
+
+	}
+    
 }

+ 5795 - 0
Modules/Home/Controller/CarController.class.php.back

@@ -0,0 +1,5795 @@
+<?php
+/**
+ *
+ */
+namespace Home\Controller;
+
+class CarController extends CommonController
+{
+
+	//--------begin
+
+
+	public function reduce_car_goods()
+	{
+		$_GPC = I('request.');
+
+		$data = array();
+		$data['goods_id'] = $_GPC['goods_id'];
+		$data['community_id'] = $_GPC['community_id'];
+		$data['quantity'] = $_GPC['quantity'];
+		$data['sku_str'] = $_GPC['sku_str'];
+		if ($_GPC['sku_str'] == 'undefined') {
+			$_GPC['sku_str'] = '';
+			$data['sku_str'] = '';
+		}
+
+
+		$data['buy_type'] = $_GPC['buy_type'];
+		$data['pin_id'] = $_GPC['pin_id'];
+		$data['is_just_addcar'] = $_GPC['is_just_addcar'];
+
+		$data['soli_id'] = isset($_GPC['soli_id']) ? intval($_GPC['soli_id']) : '';
+
+
+		if (!isset($data['buy_type']) || empty($data['buy_type'])) {
+			$data['buy_type'] = 'dan';
+		}
+		$token = $_GPC['token'];
+
+
+
+		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where(array('token' => $token))->find();
+
+		$member_id = $weprogram_token['member_id'];
+
+
+		$is_just_addcar = empty($data['is_just_addcar']) ? 0 : 1;
+
+		$goods_id = $data['goods_id'];
+		if (empty($member_id)) {
+			$result = array('code' => 4);
+			echo json_encode($result);
+			die();
+		}
+
+		if (isset($data['goods_id'])) {
+			$goods_id = $data['goods_id'];
+		} else {
+			$goods_id = 0;
+		}
+
+		$goods_param = array();
+
+		$product = M('lionfish_comshop_goods')->where(array('id' => $goods_id))->find();
+
+		if ($product['grounding'] != 1) {
+			$json['code'] = 6;
+			$json['msg'] = '商品已下架!';
+			echo json_encode($json);
+			die();
+		}
+
+		$is_community = D('Seller/Communityhead')->is_community($data['community_id']);
+		if (!$is_community) {
+			$json['code'] = 6;
+			$json['msg'] = '该小区已经不存在!';
+			echo json_encode($json);
+			die();
+		}
+
+		//6 
+		if ($is_just_addcar == 1) {
+			if ($product['pick_just'] > 0) {
+				$json['code'] = 6;
+				$json['msg'] = '自提商品,请立即购买';
+				echo json_encode($json);
+				die();
+			}
+		}
+
+		//商品存在
+		if ($product) {
+
+			$cart = D('Home/Car');
+
+			if (isset($data['quantity'])) {
+				$quantity = $data['quantity'];
+			} else {
+				$quantity = 1;
+			}
+
+			$option = array();
+
+			if (!empty($data['sku_str'])) {
+				$option = explode('_', $data['sku_str']);
+			}
+
+			$cart_goods_quantity = $cart->get_wecart_goods($goods_id, $data['sku_str'], $data['community_id'], $token, $data['soli_id']);
+
+
+			$key = (int) $goods_id . ':' . $data['community_id'] . ':';
+
+
+			if (!empty($data['soli_id'])) {
+				$key .= $data['soli_id'] . ':';
+			}
+
+			if ($data['sku_str']) {
+				$key .= base64_encode($data['sku_str']) . ':';
+			} else {
+				$key .= ':'; //xx
+			}
+
+			$car_prefix = 'cart.';
+
+			if (!empty($data['buy_type']) && $data['buy_type'] == 'soitaire') {
+				$key = 'soitairecart.' . $key;
+				$car_prefix = 'soitairecart.';
+			} else {
+				$key = 'cart.' . $key;
+			}
+
+
+
+
+			$json = array('code' => 0);
+
+
+			$car_info = M('lionfish_comshop_car')->where(array('carkey' => $key, 'community_id' => $data['community_id']))->find();
+
+			$tmp_format_data = unserialize($car_info['format_data']);
+
+			//$tmp_format_data['quantity']
+			if ($tmp_format_data['quantity'] == 1 || $tmp_format_data['quantity'] <= $quantity) {
+				$all_cart = M('lionfish_comshop_car')->where(array('carkey' => $key, 'community_id' => $data['community_id'], 'token' => $token))->delete();
+
+			} else {
+
+				$tmp_format_data['quantity'] = $tmp_format_data['quantity'] - $quantity;
+
+				M('lionfish_comshop_car')->where(array('id' => $car_info['id'], 'community_id' => $data['community_id']))->save(array('format_data' => serialize($tmp_format_data)));
+
+			}
+
+			$cart = D('Home/Car');
+			$total = $cart->count_goodscar($token, $data['community_id']);
+
+
+			$json['code'] = 1;
+			if ($data['buy_type'] != 'dan') {
+				$json['code'] = 2;
+			}
+
+
+			$cart_goods_quantity = $cart->get_wecart_goods($goods_id, $data['sku_str'], $data['community_id'], $token);
+
+
+			$json['success'] = '成功加入购物车!!';
+			$json['total'] = $total;
+			$json['cur_count'] = $cart_goods_quantity;
+
+
+			$is_limit_distance_buy = D('Home/Front')->get_config_by_name('shop_limit_buy_distance');
+
+			$json['is_limit_distance_buy'] = $is_limit_distance_buy;
+
+			$json['goods_total_count'] = 0;
+
+			if (!empty($data['buy_type']) && $data['buy_type'] == 'soitaire') {
+				$json['goods_total_count'] = $cart->get_wecart_goods_solicount($goods_id, $data['community_id'], $token, $data['soli_id']);
+
+				$json['cur_count'] = $cart->get_wecart_goods($goods_id, $data['sku_str'], $data['community_id'], $token, $car_prefix, $data['soli_id']);
+
+			}
+
+			echo json_encode($json);
+			die();
+		}
+
+	}
+
+	/**
+		   pintuan_newman_notice
+	   **/
+	public function add_newcar()
+	{
+		$_GPC = I('request.');
+
+		$data = array();
+		$data['goods_id'] = $_GPC['goods_id'];
+		$data['buy_type'] = 'pintuan';
+		$data['community_id'] = $_GPC['community_id'];
+
+		$community_id = $data['community_id'];
+
+		$data['quantity'] = 1;
+
+		$token = $_GPC['token'];
+
+		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where(array('token' => $token))->find();
+
+		$member_id = $weprogram_token['member_id'];
+
+
+		$goods_id = $data['goods_id'];
+		if (empty($member_id)) {
+			$result = array('code' => 4);
+			echo json_encode($result);
+			die();
+		}
+
+		$goods_param = array();
+
+		$product = M('lionfish_comshop_goods')->where(array('id' => $goods_id))->find();
+
+		if ($product['grounding'] != 1) {
+			$json['code'] = 6;
+			$json['msg'] = '商品已下架!';
+			echo json_encode($json);
+			die();
+		}
+
+
+		$goods_description = D('Home/Front')->get_goods_common_field($goods_id, 'total_limit_count,one_limit_count,is_new_buy');
+
+		$pin_model = D('Home/Pin');
+
+		$iszero_opentuan = $pin_model->check_goods_iszero_opentuan($goods_id);
+
+		if ($iszero_opentuan != 1) {
+			$json['code'] = 6;
+			$json['msg'] = '非邀请团商品!';
+			echo json_encode($json);
+			die();
+		}
+
+		$cart = D('Home/Car');
+
+
+
+		if ($product) {
+			if (!empty($data['buy_type']) && $data['buy_type'] == 'pintuan') {
+				$car_prefix = 'pintuancart.';
+			}
+
+			$cart_goods_quantity = $cart->get_wecart_goods($goods_id, $data['sku_str'], $data['community_id'], $token, $car_prefix);
+
+
+			$json = array('code' => 0);
+			//$goods_model = D('Home/Goods');
+			$goods_quantity = $cart->get_goods_quantity($goods_id);
+
+
+			//检测商品限购 6 one_limit_count
+			/**
+					 $can_buy_count = D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
+					 
+					 if(!empty($cart_goods_quantity) && $cart_goods_quantity > 0)
+					 {
+						 if($goods_description['one_limit_count'] > 0 && $cart_goods_quantity >= $goods_description['one_limit_count'] )
+						 {
+							 $json['code'] =6;
+							 //$json['msg']='已经不能再买了';
+							 
+							 $json['msg']='您本次只能购买'.$goods_description['one_limit_count'].'个';
+							 
+							 $json['max_quantity'] = $goods_description['one_limit_count'];
+							 
+							 echo json_encode($json);
+							 die();
+						 }
+						 
+						 $can_buy_count = $can_buy_count - $cart_goods_quantity;
+						 if($can_buy_count <= 0)
+						 {
+							 $can_buy_count = -1;
+						 }
+					 }
+					 if($can_buy_count == -1 && $goods_description['total_limit_count'] >0)
+					 {
+						 $json['code'] =6;
+						 //$json['msg']='已经不能再买了';
+						 
+						 $json['msg']='您本次只能购买'.$goods_description['total_limit_count'].'个';
+						 
+						 $json['max_quantity'] = $goods_description['total_limit_count'];
+					 
+						 echo json_encode($json);
+						 die();
+					 }else if($can_buy_count >0 && $quantity >$can_buy_count)
+					 {
+						 $json['code'] =6;
+						 $json['msg']='您还能购买'.$can_buy_count.'份';
+						 
+						 $json['max_quantity'] = $can_buy_count;
+						 echo json_encode($json);
+						 die();
+					 }
+				 
+					 //已加入购物车的总数
+					 
+					 if($goods_quantity<$quantity+$cart_goods_quantity){
+						 $json['code'] =3;
+						 if ($goods_quantity==0) {
+							 $json['msg']='已抢光';
+						 }else{
+							 // $json['msg']='商品数量不足,剩余'.$goods_quantity.'个!!';
+							 $json['msg']='商品数量不足';
+							 $json['max_quantity'] = $goods_quantity;
+						 }
+
+						 echo json_encode($json);
+						 die();
+					 }
+					 **/
+			//开始生产订单 TODO...
+
+			$payment = M('lionfish_comshop_member')->where(array('member_id' => $member_id))->find();
+
+			$data = array();
+
+			$data['member_id'] = $member_id;
+			$data['name'] = $payment['username'];
+			$data['use_score'] = 0; //是否使用积分抵扣
+
+			$data['telephone'] = '0000';
+			$data['shipping_name'] = '0000';
+			$data['shipping_tel'] = '0000';
+			$data['shipping_address'] = '';
+			$data['shipping_province_id'] = 0;
+			$data['shipping_city_id'] = 0;
+			$data['shipping_stree_id'] = 0;
+			$data['shipping_country_id'] = 0;
+
+
+			$data['shipping_method'] = 0;
+			$data['delivery'] = 'express';
+
+			$data['pick_up_id'] = $community_id;
+
+			$data['ziti_name'] = '';
+			$data['ziti_mobile'] = '';
+
+			$data['payment_method'] = 'yuer';
+
+			$data['address_id'] = 0;
+			$data['voucher_id'] = 0; //目前都是平台券
+
+
+			$data['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
+			$data['date_added'] = time();
+
+
+			$data['type'] = 'pintuan';
+			$data['shipping_fare'] = 0;
+
+			$goods_data = array();
+
+			$goods_data[] = array(
+				'goods_id' => $product['id'],
+				'store_id' => 0,
+				'name' => $product['goodsname'],
+				'model' => '',
+				'is_pin' => 1,
+				'pin_id' => 0,
+				'header_disc' => 0,
+				'member_disc' => 0,
+				'level_name' => '',
+				'option' => '',
+				'quantity' => 1,
+				'shipping_fare' => 0,
+				'price' => $product['price'],
+				'card_price' => 0,
+				'costprice' => 0,
+				'total' => 0,
+				'card_total' => 0,
+				'is_take_vipcard' => 0,
+				'fenbi_li' => 0,
+				'can_man_jian' => 0,
+				'comment' => ''
+			);
+
+			$data['is_free_shipping_fare'] = 0;
+			$data['store_id'] = 0;
+			$data['order_goods_total_money'] = 0;
+
+
+			$data['goodss'] = $goods_data;
+			$data['order_num_alias'] = build_order_no($member_id);
+			$data['voucher_credit'] = 0;
+			$data['score_for_money'] = 0;
+			$data['reduce_money'] = 0;
+			$data['man_total_free'] = 0;
+
+
+			$oid = D('Home/Frontorder')->addOrder($data); // D('Order')->addOrder($data);
+
+			$o = array();
+			$o['payment_code'] = 'yuer';
+			$o['order_status_id'] = 2;
+			$o['date_modified'] = time();
+			$o['pay_time'] = time();
+			$o['transaction_id'] = '余额支付';
+			$o['type'] = 'ignore';
+
+			//ims_ 
+			M('lionfish_comshop_order')->where(array('order_id' => $oid))->save($o);
+
+			//更新到0元开团订单类型
+
+			echo json_encode(array('code' => 0, 'order_id' => $oid));
+			die();
+		}
+
+	}
+	//end--
+
+	public function add()
+	{
+		$gpc = I('request.');
+
+
+		$data = array();
+		$data['goods_id'] = $gpc['goods_id'];
+		$data['community_id'] = $gpc['community_id'];
+		$data['quantity'] = $gpc['quantity'];
+		$data['sku_str'] = $gpc['sku_str'];
+		$data['is_just_addcar'] = $gpc['is_just_addcar'];
+		$data['soli_id'] = isset($gpc['soli_id']) ? intval($gpc['soli_id']) : '';
+
+
+		if ($gpc['sku_str'] == 'undefined') {
+			$gpc['sku_str'] = '';
+			$data['sku_str'] = '';
+		}
+
+		$pintuan_model_buy = D('Home/Front')->get_config_by_name('pintuan_model_buy');
+
+		if (empty($pintuan_model_buy) || $pintuan_model_buy == 0) {
+			$pintuan_model_buy = 0;
+		}
+
+		$data['buy_type'] = $gpc['buy_type'];
+		$data['pin_id'] = $gpc['pin_id'];
+		$data['is_just_addcar'] = $gpc['is_just_addcar'];
+
+		if (!isset($data['buy_type']) || empty($data['buy_type'])) {
+			$data['buy_type'] = 'dan';
+		} else if (!empty($data['buy_type']) && $data['buy_type'] == 'soitaire') {
+			$data['buy_type'] = 'soitaire';
+		} else if (!empty($data['buy_type']) && $data['buy_type'] == 'pindan') {
+			$data['buy_type'] = 'pindan';
+		} else if (!empty($data['buy_type']) && $data['buy_type'] == 'pintuan') {
+			$data['buy_type'] = 'pintuan';
+		} else if (!empty($data['buy_type']) && $data['buy_type'] == 'presale') {
+			$data['buy_type'] = 'presale';
+		} else if (!empty($data['buy_type']) && $data['buy_type'] == 'virtualcard') {
+			$data['buy_type'] = 'virtualcard';
+		} else if (!empty($data['buy_type']) && $data['buy_type'] == 'integral') {
+			$data['buy_type'] = 'integral';
+		}
+
+
+		$token = $gpc['token'];
+
+		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where(array('token' => $token))->find();
+
+		$member_id = $weprogram_token['member_id'];
+
+
+		$puis_not_buy = D('Home/Front')->get_config_by_name('puis_not_buy');
+
+		$member_info = M('lionfish_comshop_member')->where(array('member_id' => $member_id))->find();
+
+
+		if (!empty($puis_not_buy) && $puis_not_buy == 1) {
+
+			if ($member_info['level_id'] == 0) {
+				$json['code'] = 6;
+				$json['msg'] = '普通会员不能购买!';
+				echo json_encode($json);
+				die();
+			}
+		}
+
+		//1、判断是否开启审核,2、如果开启审核,判断会员状态是否审核
+		$is_user_shenhe = D('Home/Front')->get_config_by_name('is_user_shenhe');
+		//1
+		if (isset($is_user_shenhe) && $is_user_shenhe == 1) {
+			if ($member_info['is_apply_state'] != 1) {
+				$json['code'] = 6;
+				$json['msg'] = '会员未审核不能购买';
+				echo json_encode($json);
+				die();
+			}
+		}
+
+		//团长休息
+		$community_id = $gpc['community_id'];
+		$group_name = D('Home/Front')->get_config_by_name('group_name');
+		if (isset($community_id) && $community_id > 0) {
+			$is_can_buy = D('Seller/Communityhead')->check_goods_can_community($gpc['goods_id'], $community_id);
+
+			if (!$is_can_buy) {
+				$json['code'] = 6;
+				$json['msg'] = '此商品在您所属' . $group_name . '不可参与!';
+				echo json_encode($json);
+				die();
+			}
+			// is_all_sale
+		}
+
+		$is_just_addcar = empty($data['is_just_addcar']) ? 0 : 1;
+
+		$goods_id = $data['goods_id'];
+		if (empty($member_id)) {
+			$result = array('code' => 4);
+			echo json_encode($result);
+			die();
+		}
+
+		if (isset($data['goods_id'])) {
+			$goods_id = $data['goods_id'];
+		} else {
+			$goods_id = 0;
+		}
+
+
+		$product = M('lionfish_comshop_goods')->where(array('id' => $goods_id))->find();
+
+		if ($product['grounding'] != 1) {
+			$json['code'] = 6;
+			$json['msg'] = '商品已下架!';
+			echo json_encode($json);
+			die();
+		}
+
+
+		$goods_description = D('Home/Front')->get_goods_common_field($goods_id, 'total_limit_count,one_limit_count,oneday_limit_count,is_new_buy,is_limit_levelunbuy,is_limit_vipmember_buy,goods_start_count');
+
+		//is_limit_levelunbuy
+		//$is_default_levellimit_buy = D('Home/Front')->get_config_by_name('is_default_levellimit_buy');
+		//isset($is_default_levellimit_buy) && $is_default_levellimit_buy == 1 &&
+
+		if ($goods_description['is_limit_levelunbuy'] == 1) {
+			// member_id
+			$mb_info = M('lionfish_comshop_member')->field('level_id')->where(array('member_id' => $member_id))->find();
+
+			if ($mb_info['level_id'] == 0) {
+				$json['code'] = 6;
+				$json['msg'] = '默认等级不能购买,请联系客服';
+				echo json_encode($json);
+				die();
+			}
+		}
+
+		//is_limit_vipmember_buy 付费会员专享
+
+		//$is_default_vipmember_buy = D('Home/Front')->get_config_by_name('is_default_vipmember_buy');
+		//isset($is_default_vipmember_buy) && $is_default_vipmember_buy == 1 &&
+
+		if ($goods_description['is_limit_vipmember_buy'] == 1) {
+			$mb_vip = M('lionfish_comshop_member')->field('card_id,card_begin_time,card_end_time')->where(array('member_id' => $member_id))->find();
+
+			//当前时间
+			$present_time = time();
+
+			if ($mb_vip['card_id'] == 0 || ($present_time > $mb_vip['card_end_time'])) {
+
+				$is_pop_vipmember_buytip = D('Home/Front')->get_config_by_name('is_pop_vipmember_buytip');
+				$is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
+				$pop_vipmember_buyimage = D('Home/Front')->get_config_by_name('pop_vipmember_buyimage');
+
+				$json['has_image'] = 0;
+
+				$is_open_vipcard_buy = isset($is_open_vipcard_buy) ? $is_open_vipcard_buy : 0;
+
+				if (isset($is_pop_vipmember_buytip) && $is_pop_vipmember_buytip == 1) {
+					if (isset($pop_vipmember_buyimage) && !empty($pop_vipmember_buyimage)) {
+						$pop_vipmember_buyimage = tomedia($pop_vipmember_buyimage);
+
+						$json['has_image'] = 1;
+						$json['pop_vipmember_buyimage'] = $pop_vipmember_buyimage;
+					}
+				}
+				$json['code'] = 7;
+
+
+				$json['msg'] = '付费会员专享,普通会员不能购买';
+				echo json_encode($json);
+				die();
+			}
+
+		}
+
+		if (!empty($goods_description['is_new_buy']) && $goods_description['is_new_buy'] == 1) {
+
+			$ck_buy_order = M('lionfish_comshop_order')->field('order_id')->where("member_id={$member_id} and order_status_id in (1,4,6,7,10,11,12,14)")->find();
+
+			if (!empty($ck_buy_order)) {
+				$json['code'] = 6;
+				$json['msg'] = '新人专享!';
+				echo json_encode($json);
+				die();
+			}
+
+			$is_new_buy_limit = D('Home/Front')->get_config_by_name('is_new_buy_limit');
+			$new_buy_limit_num = D('Home/Front')->get_config_by_name('new_buy_limit_num');
+			if (!empty($is_new_buy_limit) && $is_new_buy_limit == 1) { //新人专享限制
+				$goods_cate_count = D('Home/Car')->get_new_goods_count($token, $goods_id, $data['sku_str']);
+				if ($goods_cate_count >= $new_buy_limit_num) {
+					$json['code'] = 6;
+					$json['msg'] = '超出新人专享限制!';
+					echo json_encode($json);
+					die();
+				}
+			}
+		}
+
+
+
+
+		//$data['community_id']
+		if ($data['buy_type'] == 'dan' || $data['buy_type'] == 'soitaire' || ($pintuan_model_buy == 1 && $data['buy_type'] != 'dan')) {
+			$is_community = D('Seller/Communityhead')->is_community($data['community_id']);
+			if (!$is_community) {
+				$json['code'] = 6;
+				$json['msg'] = '该小区已经不存在!';
+				echo json_encode($json);
+				die();
+			}
+		}
+
+		//判断是否积分兑换
+		if ($product['type'] == 'integral') {
+			//判断积分是否足够 member_id 暂时关闭以下代码
+
+			$integral_model = D('Home/Integral');
+			if (isset($data['quantity'])) {
+				$quantity = $data['quantity'];
+			} else {
+				$quantity = 1;
+			}
+			if (intval($quantity) < 1) {
+				$json['code'] = 6;
+				$json['msg'] = '数量不能小于1!';
+				echo json_encode($json);
+				die();
+			}
+			$check_result = $integral_model->check_user_score_quantity_can_pay($member_id, $data['sku_str'], $goods_id, $quantity);
+
+			if ($check_result['code'] == 1) {
+				$json['code'] = 6;
+				$json['msg'] = '剩余' . $check_result['cur_score'] . '积分,积分不足!';
+				echo json_encode($json);
+				die();
+			}
+			/****/
+		}
+
+		//6 
+		if ($is_just_addcar == 1) {
+			if ($product['pick_just'] > 0) {
+				$json['code'] = 6;
+				$json['msg'] = '自提商品,请立即购买';
+				echo json_encode($json);
+				die();
+			}
+		}
+
+		//商品存在
+		if ($product) {
+
+			$cart = D('Home/Car');
+
+			if (isset($data['quantity'])) {
+				$quantity = $data['quantity'];
+			} else {
+				$quantity = 1;
+			}
+
+			$option = array();
+
+			if (!empty($data['sku_str'])) {
+				$option = explode('_', $data['sku_str']);
+			}
+
+			$car_prefix = "cart.";
+
+			if (!empty($data['buy_type']) && $data['buy_type'] == 'pindan') {
+				$car_prefix = 'pindancart.'; //cart.
+			} else if (!empty($data['buy_type']) && $data['buy_type'] == 'soitaire') {
+				$car_prefix = 'soitairecart.';
+			} else if (!empty($data['buy_type']) && $data['buy_type'] == 'pintuan') {
+				$car_prefix = 'pintuancart.';
+			} else if (!empty($data['buy_type']) && $data['buy_type'] == 'presale') {
+				$car_prefix = 'presalecart.';
+			} else if (!empty($data['buy_type']) && $data['buy_type'] == 'virtualcard') {
+				$car_prefix = 'virtualcardcart.';
+			} else if (!empty($data['buy_type']) && $data['buy_type'] == 'integral') {
+				$car_prefix = 'integralcart.';
+			}
+
+			//$data['soli_id']
+			if ($data['is_just_addcar'] == 0) {
+				$cart_goods_quantity = 0;
+			} else {
+				$cart_goods_quantity = $cart->get_wecart_goods($goods_id, $data['sku_str'], $data['community_id'], $token, $car_prefix, $data['soli_id']);
+			}
+
+
+
+			$cart_goods_all_quantity = $cart->get_wecartall_goods($goods_id, $data['sku_str'], $data['community_id'], $token, $car_prefix);
+
+
+			$json = array('code' => 0);
+			//$goods_model = D('Home/Goods');
+			$goods_quantity = $cart->get_goods_quantity($goods_id);
+			if (!empty($data['sku_str'])) {
+				$goods_option_item_value = M('lionfish_comshop_goods_option_item_value')->field('stock')->where(array('goods_id' => $goods_id, 'option_item_ids' => $data['sku_str']))->find();
+				if (!empty($goods_option_item_value)) {
+					$goods_quantity = $goods_option_item_value['stock'];
+				}
+			}
+
+
+			//rela_goodsoption_valueid
+			if ($goods_quantity < $goods_description['goods_start_count']) {
+				$json['code'] = 6;
+				$json['msg'] = '起售数量' . $goods_description['goods_start_count'] . ',库存不足,剩余' . $goods_quantity . '个';
+				$json['max_quantity'] = $goods_description['goods_start_count'];
+				echo json_encode($json);
+				die();
+			}
+			//起售数量判断
+			if ($quantity + $cart_goods_quantity < $goods_description['goods_start_count']) {
+				$json['code'] = 6;
+				$json['msg'] = $goods_description['goods_start_count'] . '份起售';
+				$json['max_quantity'] = $goods_description['goods_start_count'];
+				echo json_encode($json);
+				die();
+			}
+			//$can_buy_count = D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
+			/**
+					 //单次限购
+					 if(!empty($cart_goods_all_quantity) && $cart_goods_all_quantity > 0 && $data['buy_type'] != 'pintuan' )
+					 {
+						 if($goods_description['one_limit_count'] > 0 && $cart_goods_all_quantity >= $goods_description['one_limit_count'] )
+						 {
+							 $json['code'] =6;
+							 //$json['msg']='已经不能再买了';
+
+							 $json['msg'] = '您本次只能购买'.$goods_description['one_limit_count'].'个';
+
+							 $json['max_quantity'] = $goods_description['one_limit_count'];
+
+							 echo json_encode($json);
+							 die();
+						 }
+
+						 $can_buy_count = $can_buy_count - $cart_goods_all_quantity;
+						 if($can_buy_count <= 0)
+						 {
+							 $can_buy_count = -1;
+						 }
+					 }
+					 //每单限购
+					 if($can_buy_count > 0 && $quantity > $can_buy_count)
+					 {
+						 $json['code'] =6;
+						 $json['msg']='您每次只能购买'.$can_buy_count.'份';
+
+						 $json['max_quantity'] = $can_buy_count;
+						 echo json_encode($json);
+						 die();
+					 }
+
+					 //每日限购 6
+					 $can_buy_day_count =  D('Home/Front')->check_goods_user_canbuy_day_count($member_id, $goods_id);
+
+					 if ($goods_description['oneday_limit_count'] >0){
+						 if($can_buy_day_count == -1 || ($can_buy_day_count > 0 && ($cart_goods_all_quantity+$quantity) > $can_buy_day_count))
+						 {
+							 $json['code'] =6;
+							 //$json['msg']='已经不能再买了';
+							 $json['msg']='您每天只能购买'.$goods_description['oneday_limit_count'].'个';
+
+							 $json['max_quantity'] = $goods_description['oneday_limit_count'];
+
+							 echo json_encode($json);
+							 die();
+						 }
+					 }
+
+					 //历史限购判断
+					 if($can_buy_count == -1 && $goods_description['total_limit_count'] >0)
+					 {
+						 $json['code'] =6;
+						 //$json['msg']='已经不能再买了';
+						 $json['msg']='您还能购买'.$goods_description['total_limit_count'].'个';
+						 
+						 $json['max_quantity'] = $goods_description['total_limit_count'];
+					 
+						 echo json_encode($json);
+						 die();
+					 }
+					 **/
+
+			$can_buy_one_count = D('Home/Front')->check_goods_user_canbuy_one_count($member_id, $goods_id);
+
+
+			/*$goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'total_limit_count,one_limit_count,oneday_limit_count,is_new_buy,is_limit_levelunbuy,is_limit_vipmember_buy,goods_start_count');
+					 if($quantity < $goods_description['goods_start_count']){
+						 $json['code'] = 6;
+						 //$json['msg'] = '您本次只能购买'.$goods_description['one_limit_count'].'份';
+						 $json['msg'] = $goods_description['goods_start_count'].'件起售';
+						 $json['max_quantity'] = $goods_description['goods_start_count'];
+						 echo json_encode($json);
+						 die();
+					 }*/
+
+			//单次限购判断
+			if ($goods_description['one_limit_count'] > 0 && $quantity + $cart_goods_quantity > $goods_description['one_limit_count']) {
+				$json['code'] = 6;
+				//$json['msg'] = '您本次只能购买'.$goods_description['one_limit_count'].'份';
+				$json['msg'] = '购物车总数已满或超出每次购买数量';
+				$json['max_quantity'] = $goods_description['one_limit_count'] - $cart_goods_all_quantity;
+				echo json_encode($json);
+				die();
+			}
+
+			$can_buy_day_count = D('Home/Front')->check_goods_user_canbuy_day_count($member_id, $goods_id);
+			if ($can_buy_day_count == -1 || ($can_buy_day_count > 0 && $quantity > $can_buy_day_count)) {
+				$json['code'] = 6;
+				//$json['msg'] = '您今天只能购买'.$goods_description['oneday_limit_count'].'份';
+				$json['msg'] = '购物车总数已满或超出每天购买数量';
+				$json['max_quantity'] = $can_buy_day_count - $cart_goods_all_quantity;
+				echo json_encode($json);
+				die();
+			} else if ($can_buy_day_count > 0 && ($quantity + $cart_goods_quantity) > $can_buy_day_count) {
+				$json['code'] = 6;
+				//$json['msg'] = '您今天还能购买'.$can_buy_day_count.'份';
+				$json['msg'] = '购物车总数已满或超出每天购买数量';
+				$json['max_quantity'] = $can_buy_day_count - $cart_goods_all_quantity;
+				echo json_encode($json);
+				die();
+			}
+
+			$can_buy_all_count = D('Home/Front')->check_goods_user_canbuy_all_count($member_id, $goods_id);
+			if ($data['buy_type'] == 'pintuan' || $data['buy_type'] == 'pindan' || $data['buy_type'] == 'presale') {
+				$cart_goods_all_quantity = 0;
+			}
+			//历史限购判断
+			if ($can_buy_all_count == -1 && $goods_description['total_limit_count'] > 0) {
+				$json['code'] = 6;
+				//$json['msg']='您最多只能购买'.$goods_description['total_limit_count'].'份';
+				$json['msg'] = '购物车总数已满或超出历史购买数量';
+				$json['max_quantity'] = 1;
+				echo json_encode($json);
+				die();
+			} else if ($can_buy_all_count > 0 && ($cart_goods_all_quantity + $quantity) > $can_buy_all_count) {
+				$json['code'] = 6;
+				$json['msg'] = '购物车总数已满或超出历史购买数量';
+				$json['max_quantity'] = $can_buy_all_count - $cart_goods_all_quantity;
+				echo json_encode($json);
+				die();
+			}
+
+			//已加入购物车的总数
+
+			if ($goods_quantity < $quantity + $cart_goods_quantity) {
+				$json['code'] = 3;
+				if ($goods_quantity == 0) {
+					$json['msg'] = '已抢光';
+				} else {
+					$json['msg'] = '商品数量不足';
+					$json['max_quantity'] = $goods_quantity;
+				}
+
+				echo json_encode($json);
+				die();
+			}
+
+			if (!empty($option)) {
+				$mul_opt_arr = array();
+
+				//ims_ 
+				//$goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->where( array('goods_id' => $goods_id,'option_item_ids' => $data['sku_str']) )->find();
+				$open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
+
+				if (!empty($open_redis_server) && $open_redis_server == 1) {
+					$goods_option_mult_value_stock = D('Seller/Redisorder')->get_goods_sku_quantity($goods_id, $data['sku_str']);
+				} else {
+					$goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->where(array('goods_id' => $goods_id, 'option_item_ids' => $data['sku_str']))->find();
+				}
+
+
+				if (!empty($goods_option_mult_value_stock)) {
+					if ($goods_option_mult_value_stock < $quantity + $cart_goods_quantity) {
+						$json['code'] = 3;
+						$json['msg'] = '商品数量不足,剩余' . $goods_option_mult_value_stock . '个!!';
+
+						$json['max_quantity'] = $goods_option_mult_value['stock'];
+						echo json_encode($json);
+						die();
+					}
+				}
+			}
+
+			//buy_type
+
+			// $this->clear_all_cart(); $data['community_id']
+
+			$format_data_array = array(
+				'quantity' => $quantity,
+				'community_id' => $data['community_id'],
+				'goods_id' => $goods_id,
+				'sku_str' => $data['sku_str'],
+				'buy_type' => $data['buy_type'],
+				'soli_id' => $data['soli_id']
+			);
+			//区分活动商品还是普通商品。做两个购物车,活动商品是需要直接购买的,单独购买商品加入正常的购物车TODO....
+			//is_just_addcar 0  1
+			if ($data['buy_type'] == 'dan' && $is_just_addcar == 0) {
+
+				//$cart->removedancar($token);
+				//清空一下购物车
+				//singledel
+				$format_data_array['is_just_addcar'] = 0;
+				$format_data_array['singledel'] = 1;
+
+				$cart->addwecar($token, $goods_id, $format_data_array, $data['sku_str'], $data['community_id']);
+				$total = $cart->count_goodscar($token, $data['community_id']);
+			} else if ($data['buy_type'] == 'dan' && $is_just_addcar == 1) {
+				//singledel
+				$format_data_array['is_just_addcar'] = 1;
+				$format_data_array['singledel'] = 1;
+				$cart->addwecar($token, $goods_id, $format_data_array, $data['sku_str'], $data['community_id']);
+				$total = $cart->count_goodscar($token, $data['community_id']);
+			} else if (!empty($data['buy_type']) && $data['buy_type'] == 'soitaire') {
+				//清理单独购买的商品
+				$format_data_array['is_just_addcar'] = 1;
+				$format_data_array['singledel'] = 1;
+
+				$cart->addwecar($token, $goods_id, $format_data_array, $data['sku_str'], $data['community_id'], $car_prefix, $data['soli_id']);
+				$total = 0;
+			} else if (!empty($data['buy_type']) && $data['buy_type'] == 'pindan') {
+				//清理单独购买的商品
+				$cart->removeActivityAllcar($token, 'pindancart.');
+				$format_data_array['is_just_addcar'] = 0;
+				$format_data_array['singledel'] = 1;
+
+				$cart->addwecar($token, $goods_id, $format_data_array, $data['sku_str'], $data['community_id'], $car_prefix);
+				$total = 0;
+			} else if (!empty($data['buy_type']) && $data['buy_type'] == 'pintuan') {
+				$pin_id = isset($data['pin_id']) ? $data['pin_id'] : 0;
+
+				if ($pin_id > 0) {
+					$pin_info_tmp = M('lionfish_comshop_pin')->where(array('pin_id' => $pin_id))->find();
+
+					if (!empty($pin_info_tmp) && $pin_info_tmp['is_newman_takein'] == 1) {
+						//检测是否新人
+						//检测是否购买过
+						$od_status = "1,2,4,6,7,8,9,10,11,12,14";
+
+						$od_buy_count = M('lionfish_comshop_order')->where("order_status_id in ({$od_status}) and member_id=" . $member_id)->count();
+
+						if (!empty($od_buy_count) && $od_buy_count > 0) {
+							$json['code'] = 3;
+							$json['msg'] = '新人专享';
+
+							echo json_encode($json);
+							die();
+						}
+					}
+
+				}
+
+				//清理拼团的商品
+				$cart->removeActivityAllcar($token, 'pintuancart.');
+				$format_data_array['is_just_addcar'] = 0;
+				$format_data_array['singledel'] = 1;
+				$format_data_array['pin_id'] = $pin_id;
+
+				$cart->addwecar($token, $goods_id, $format_data_array, $data['sku_str'], $data['community_id'], $car_prefix);
+				$total = 0;
+			} else if (!empty($data['buy_type']) && $data['buy_type'] == 'presale') {
+				//清理预售的商品
+				$cart->removeActivityAllcar($token, 'presalecart.');
+				$format_data_array['is_just_addcar'] = 0;
+				$format_data_array['singledel'] = 1;
+
+				$cart->addwecar($token, $goods_id, $format_data_array, $data['sku_str'], $data['community_id'], $car_prefix);
+				$total = 0;
+			} else if (!empty($data['buy_type']) && $data['buy_type'] == 'virtualcard') {
+				//清理预售的商品
+				$cart->removeActivityAllcar($token, 'virtualcardcart.');
+				$format_data_array['is_just_addcar'] = 0;
+				$format_data_array['singledel'] = 1;
+
+				$cart->addwecar($token, $goods_id, $format_data_array, $data['sku_str'], $data['community_id'], $car_prefix);
+				$total = 0;
+			} else if (!empty($data['buy_type']) && $data['buy_type'] == 'integral') {
+
+				//清理拼团的商品 $data['pin_id']
+				$cart->removeActivityAllcar($token, 'integralcart.');
+				$format_data_array['is_just_addcar'] = 0;
+				$format_data_array['singledel'] = 1;
+
+				$cart->addwecar($token, $goods_id, $format_data_array, $data['sku_str'], $data['community_id'], $car_prefix);
+				$total = 0;
+			} else {
+				//buy_type:pin  活动购物车。
+				$pin_id = isset($data['pin_id']) ? $data['pin_id'] : 0;
+
+				//lottery
+				if ($product['type'] == 'lottery' && $product['type'] == 'lottery') {
+					/**
+								   //等待把抽奖的活动打开
+								   $now_time = time();
+								   $lottery_goods_info =  M('lottery_goods')->where( array('goods_id' => $goods_id) )->find();
+								   
+								   if($lottery_goods_info['end_time'] < $now_time)
+								   {
+									   $json['code'] =6;
+									   $json['msg']='抽奖活动已结束';
+									   echo json_encode($json);
+									   die();
+								   }
+								   **/
+				}
+
+				//检测商品是否老带新,新人才能参团
+				if ($pin_id > 0) {
+					//等待把老带新的活动打开
+					/**
+								   if($product['type'] == 'newman')
+								   {
+									   $new_mamn_buy = $goods_model->check_goods_new_manbug($member_id);
+									   if($new_mamn_buy>0)
+									   {
+										   $json['code'] =5;
+										   $json['msg']='该商品只能新人参团';
+										   echo json_encode($json);
+										   die();
+									   }
+								   }
+								   **/
+				}
+
+				$format_data_array['pin_id'] = $pin_id;
+
+				$cart->add_activitycar($token, $goods_id, $format_data_array, $data['sku_str']);
+				$total = $cart->count_activitycar($token);
+			}
+
+
+			$carts = M('lionfish_comshop_car')->where(array('token' => $token, 'community_id' => $data['community_id'], 'carkey' => 'cart_total'))->find();
+
+			if (!empty($data['buy_type']) && $data['buy_type'] == 'dan') {
+				if (!empty($carts)) {
+					$car_data = array();
+					$car_data['format_data'] = serialize(array('quantity' => $total));
+					$car_data['modifytime'] = 1;
+
+					M('lionfish_comshop_car')->where(array('token' => $token, 'community_id' => $data['community_id'], 'carkey' => 'cart_total'))->save($car_data);
+
+				} else {
+
+					$car_data = array();
+					$car_data['token'] = $token;
+
+					$car_data['community_id'] = $data['community_id'];
+					$car_data['carkey'] = 'cart_total';
+					$car_data['format_data'] = serialize(array('quantity' => $total));
+
+					M('lionfish_comshop_car')->add($car_data);
+				}
+			}
+
+			//session('cart_total',$total);
+			$json['code'] = 1;
+			if ($data['buy_type'] != 'dan') {
+				$json['code'] = 2;
+			}
+			$json['success'] = '成功加入购物车!!';
+			$json['total'] = $total;
+
+			$cart_goods_quantity = $cart->get_wecart_goods($goods_id, $data['sku_str'], $data['community_id'], $token, $car_prefix);
+			$json['cur_count'] = $cart_goods_quantity;
+
+
+
+			//soitaire 
+			$is_limit_distance_buy = D('Home/Front')->get_config_by_name('shop_limit_buy_distance');
+
+			$json['is_limit_distance_buy'] = $is_limit_distance_buy;
+
+			$json['goods_total_count'] = 0;
+
+			if (!empty($data['buy_type']) && $data['buy_type'] == 'soitaire') {
+				$json['goods_total_count'] = $cart->get_wecart_goods_solicount($goods_id, $data['community_id'], $token, $data['soli_id']);
+
+				$cart_goods_quantity = $cart->get_wecart_goods($goods_id, $data['sku_str'], $data['community_id'], $token, $car_prefix, $data['soli_id']);
+				$json['cur_count'] = $cart_goods_quantity;
+			}
+
+
+			echo json_encode($json);
+			die();
+		}
+
+	}
+
+	//显示购物车中商品列表
+	function show_cart_goods()
+	{
+
+		$gpc = I('request.');
+
+		$token = $gpc['token'];
+		$community_id = $gpc['community_id'];
+		$soli_id = isset($gpc['soli_id']) ? intval($gpc['soli_id']) : '';
+
+		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where(array('token' => $token))->find();
+
+		$member_id = $weprogram_token['member_id'];
+
+		$is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
+		$is_open_vipcard_buy = !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 ? 1 : 0;
+		$modify_vipcard_name = D('Home/Front')->get_config_by_name('modify_vipcard_name');
+
+
+		$is_vip_card_member = 0;
+		$is_member_level_buy = 0;
+
+		if ($member_id > 0) {
+			$member_info = M('lionfish_comshop_member')->where(array('member_id' => $member_id))->find();
+
+			if (!empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1) {
+
+				$now_time = time();
+
+				if ($member_info['card_id'] > 0 && $member_info['card_end_time'] > $now_time) {
+					$is_vip_card_member = 1; //还是会员
+				} else if ($member_info['card_id'] > 0 && $member_info['card_end_time'] < $now_time) {
+					$is_vip_card_member = 2; //已过期
+				}
+			}
+
+			if ($is_vip_card_member != 1 && $member_info['level_id'] > 0) {
+				$is_member_level_buy = 1;
+			}
+		}
+
+		$buy_type = isset($gpc['buy_type']) ? $gpc['buy_type'] : 'dan';
+
+		if (empty($member_id)) {
+			//需要登录
+			echo json_encode(array('code' => 5));
+			die();
+		}
+
+		$cart = D('Home/Car');
+
+		$goods = $cart->get_all_goodswecar($buy_type, $token, 0, $community_id, $soli_id);
+
+
+		$seller_goodss = array();
+
+		$seller_goodss_mult = array();
+
+		//is_only_express
+		$tp_ar = array();
+
+		foreach ($goods as $key => $val) {
+			//$goods_store_field =  M('goods')->field('store_id')->where( array('goods_id' => $val['goods_id']) )->find();
+			//$seller_goodss[ $goods_store_field['store_id'] ]['goods'][$key] = $val;
+
+			$supply_id = D('Home/Front')->get_goods_supply_id($val['goods_id']);
+			if ($supply_id > 0) {
+				$supply_info = D('Home/Front')->get_supply_info($supply_id);
+
+				if ($supply_info['type'] == 0) {
+					$supply_id = 0;
+				}
+			}
+
+
+			$seller_goodss[$supply_id]['goods'][$key] = $val;
+
+			$tp_ar[] = $val['is_only_express'];
+			$seller_goodss_mult[$val['is_only_express']][$supply_id]['goods'][$key] = $val; //new 0719
+
+		}
+
+		$ck_goodstype_count = 0;
+		$vipcard_save_money = 0;
+
+		$level_save_money = 0;
+		//$max_can_orderbuy_money = 0 ;
+		foreach ($seller_goodss_mult as $key => $seller_goodss_tp) {
+
+			foreach ($seller_goodss_tp as $store_id => $val) {
+				//total
+				$seller_voucher_list = array();
+				$seller_total_fee = 0;
+				$total_trans_free = 0;
+
+				$tmp_goods = array();
+
+				$is_store_ck = false;
+
+				foreach ($val['goods'] as $kk => $d_goods) {
+					$seller_total_fee += $d_goods['total'];
+
+					$total_trans_free += $d_goods[$kk]['trans_free'];
+					$val['goods'][$kk] = $d_goods;
+
+					$tp_val = array();
+					$tp_val['id'] = $d_goods['goods_id'];
+					$tp_val['key'] = $d_goods['key'];
+					if ($d_goods['singledel'] == 1) {
+						$tp_val['isselect'] = true;
+						$is_store_ck = true;
+						$ck_goodstype_count++;
+						if ($d_goods['is_take_vipcard'] == 1) {
+							$vipcard_save_money = $d_goods['total'] - $d_goods['card_total'];
+						} else if ($d_goods['is_mb_level_buy'] == 1) {
+							$level_save_money = $d_goods['total'] - $d_goods['level_total'];
+						}
+					} else {
+						$tp_val['isselect'] = false;
+					}
+
+					$tp_val['imgurl'] = $d_goods['image'];
+					$tp_val['edit'] = 'inline';
+					$tp_val['title'] = htmlspecialchars_decode($d_goods['name']);
+					$tp_val['finish'] = 'none';
+					$tp_val['description'] = 'description';
+
+					$option_arr = array();
+					$option_str = "";
+					foreach ($d_goods['option'] as $option_val) {
+						//$option_arr[] = $option_val['name'].':'.$option_val['value'];
+						$option_arr[] = $option_val['value'];
+					}
+					if (!empty($option_arr)) {
+						$option_str = implode(';', $option_arr);
+					}
+
+
+					$tp_val['can_buy'] = D('Home/Pingoods')->get_goods_time_can_buy($d_goods['goods_id']);
+
+					$tp_val['option_can_buy'] = D('Home/Pingoods')->get_goods_option_can_buy($d_goods['goods_id'], $d_goods['sku_str']);
+
+
+					$tp_val['goodstype'] = $option_str;
+					$tp_val['goodstypeedit'] = $option_str;
+					$tp_val['goodsnum'] = $d_goods['quantity'];
+					$tp_val['can_man_jian'] = $d_goods['can_man_jian'];
+					$tp_val['max_quantity'] = $d_goods['max_quantity'];
+					$tp_val['cartype'] = 'inline';
+					$tp_val['currntprice'] = $d_goods['price'];
+					$tp_val['card_price'] = $d_goods['card_price'];
+
+					$tp_val['levelprice'] = $d_goods['levelprice']; // 会员等级价格
+					$tp_val['is_mb_level_buy'] = $d_goods['is_mb_level_buy']; //是否可以会员等级价格购买
+
+					$tp_val['is_take_vipcard'] = $d_goods['is_take_vipcard'];
+					$tp_val['price'] = $d_goods['shop_price'];
+					$tp_val['is_new_buy'] = $d_goods['is_new_buy'];
+					$tp_val['goods_start_count'] = $d_goods['goods_start_count'];
+					$tp_val['store_id'] = $store_id;
+					$tmp_goods[] = $tp_val;
+
+				}
+
+				//$store_info = M('seller')->field('s_id,s_true_name,s_logo')->where( array('s_id' => $store_id) )->find();
+				//$store_info['s_logo'] = C('SITE_URL').'Uploads/image/'.$store_info['s_logo'];
+
+				$store_info = array('s_true_name' => '', 's_id' => 1);
+				$s_logo = D('Home/Front')->get_config_by_name('shoplogo');
+
+				if (!empty($s_logo)) {
+					$s_logo = tomedia($s_logo);
+				}
+
+				$val['store_info'] = $store_info;
+
+				$store_data = array();
+				$store_data['id'] = $store_info['s_id'];
+				if ($is_store_ck) {
+					$store_data['isselect'] = true;
+				} else {
+					$store_data['isselect'] = false;
+				}
+
+				$store_data['shopname'] = $store_info['s_true_name'];
+				$store_data['caredit'] = 'inline';
+				$store_data['finish'] = 'none';
+				$store_data['count'] = '0.00';
+
+				$is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
+				$full_money = D('Home/Front')->get_config_by_name('full_money');
+				$full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
+
+				if (empty($full_reducemoney) || $full_reducemoney <= 0) {
+					$is_open_fullreduction = 0;
+				}
+
+				$store_data['is_open_fullreduction'] = $is_open_fullreduction;
+				$store_data['full_money'] = $full_money;
+				$store_data['full_reducemoney'] = $full_reducemoney;
+
+
+
+				$store_data['goodstype'] = 2;
+				$store_data['goodstypeselect'] = 0;
+				$store_data['shopcarts'] = $tmp_goods;
+
+				//起送价格
+				$localtown_moneytype_fixed_deliverymoney = 0;
+				//达到金额免配送费
+				$localtown_moneytype_fixed_freemoney = 0;
+
+
+				$localtown_fixed_list = array();
+				if ($key == 3) { //同城配送商品
+					$storename = "";
+					if ($store_id == 0) {
+						//配送费类型:0、固定金额,1、按距离收取
+						$localtown_delivery_moneytype = D('Home/Front')->get_config_by_name('localtown_delivery_moneytype');
+						if ($localtown_delivery_moneytype == 0) {
+							$localtown_moneytype_fixed_deliverymoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_deliverymoney');
+							$localtown_moneytype_fixed_freemoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_freemoney');
+						}
+						$storename = "平台";
+					} else {
+						$isopen_localtown_delivery = D('Home/Front')->get_supply_config_by_name('isopen_localtown_delivery', $store_id);
+						//配送费类型:0、固定金额,1、按距离收取
+						$localtown_delivery_moneytype = D('Home/Front')->get_supply_config_by_name('localtown_delivery_moneytype', $store_id);
+						if ($isopen_localtown_delivery == 1 && $localtown_delivery_moneytype == 0) {
+							$localtown_moneytype_fixed_deliverymoney = D('Home/Front')->get_supply_config_by_name('localtown_moneytype_fixed_deliverymoney', $store_id);
+							$localtown_moneytype_fixed_freemoney = D('Home/Front')->get_supply_config_by_name('localtown_moneytype_fixed_freemoney', $store_id);
+						}
+						$supply_info_data = M('lionfish_comshop_supply')->field('storename')->where(array('id' => $store_id))->find();
+						$storename = $supply_info_data['storename'];
+					}
+					$localtown_fixed_list['localtown_moneytype_fixed_deliverymoney'] = $localtown_moneytype_fixed_deliverymoney;
+					//if($localtown_moneytype_fixed_deliverymoney > $max_can_orderbuy_money){
+					//获取起送最大下单金额限制
+					//$max_can_orderbuy_money = $localtown_moneytype_fixed_deliverymoney;
+					//}
+					$localtown_fixed_list['localtown_moneytype_fixed_freemoney'] = $localtown_moneytype_fixed_freemoney;
+					$localtown_fixed_list['store_name'] = $storename;
+				} else if ($key == 2) {
+					if ($store_id == 0) {
+						$storename = "平台";
+					} else {
+						$supply_info_data = M('lionfish_comshop_supply')->field('storename')->where(array('id' => $store_id))->find();
+						$storename = $supply_info_data['storename'];
+					}
+					$localtown_fixed_list['store_name'] = $storename;
+				}
+				$store_data['localtown_fixed_list'] = $localtown_fixed_list;
+				$seller_goodss_tp[$store_id] = $store_data;
+				$i++;
+			}
+			$seller_goodss_mult[$key] = $seller_goodss_tp;
+
+		}
+
+
+
+
+		foreach ($seller_goodss as $store_id => $val) {
+			//total
+			$seller_voucher_list = array();
+			$seller_total_fee = 0;
+			$total_trans_free = 0;
+
+			$tmp_goods = array();
+
+			$is_store_ck = false;
+
+			foreach ($val['goods'] as $kk => $d_goods) {
+				$seller_total_fee += $d_goods['total'];
+
+				$total_trans_free += $d_goods[$kk]['trans_free'];
+				$val['goods'][$kk] = $d_goods;
+
+				$tp_val = array();
+				$tp_val['id'] = $d_goods['goods_id'];
+				$tp_val['key'] = $d_goods['key'];
+				if ($d_goods['singledel'] == 1) {
+					$tp_val['isselect'] = true;
+					$is_store_ck = true;
+					$ck_goodstype_count++;
+				} else {
+					$tp_val['isselect'] = false;
+				}
+
+				$tp_val['imgurl'] = $d_goods['image'];
+				$tp_val['edit'] = 'inline';
+				$tp_val['title'] = $d_goods['name'];
+				$tp_val['finish'] = 'none';
+				$tp_val['description'] = 'description';
+
+				$option_arr = array();
+				$option_str = "";
+				foreach ($d_goods['option'] as $option_val) {
+					//$option_arr[] = $option_val['name'].':'.$option_val['value'];
+					$option_arr[] = $option_val['value'];
+				}
+				if (!empty($option_arr)) {
+					$option_str = implode(';', $option_arr);
+				}
+
+
+				$tp_val['can_buy'] = D('Home/Pingoods')->get_goods_time_can_buy($d_goods['goods_id']);
+
+				$tp_val['goodstype'] = $option_str;
+				$tp_val['goodstypeedit'] = $option_str;
+				$tp_val['goodsnum'] = $d_goods['quantity'];
+				$tp_val['can_man_jian'] = $d_goods['can_man_jian'];
+				$tp_val['max_quantity'] = $d_goods['max_quantity'];
+				$tp_val['cartype'] = 'inline';
+				$tp_val['currntprice'] = $d_goods['price'];
+				$tp_val['price'] = $d_goods['shop_price'];
+				$tp_val['card_price'] = $d_goods['card_price'];
+				$tp_val['is_take_vipcard'] = $d_goods['is_take_vipcard'];
+				$tp_val['is_new_buy'] = $d_goods['is_new_buy'];
+
+				$tmp_goods[] = $tp_val;
+
+			}
+
+			//$store_info = M('seller')->field('s_id,s_true_name,s_logo')->where( array('s_id' => $store_id) )->find();
+			//$store_info['s_logo'] = C('SITE_URL').'Uploads/image/'.$store_info['s_logo'];
+
+			$store_info = array('s_true_name' => '', 's_id' => 1);
+			$s_logo = D('Home/Front')->get_config_by_name('shoplogo');
+
+			if (!empty($s_logo)) {
+				$s_logo = tomedia($s_logo);
+			}
+
+			$val['store_info'] = $store_info;
+
+			$store_data = array();
+			$store_data['id'] = $store_info['s_id'];
+			if ($is_store_ck) {
+				$store_data['isselect'] = true;
+			} else {
+				$store_data['isselect'] = false;
+			}
+
+			$store_data['shopname'] = $store_info['s_true_name'];
+			$store_data['caredit'] = 'inline';
+			$store_data['finish'] = 'none';
+			$store_data['count'] = '0.00';
+
+			$is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
+			$full_money = D('Home/Front')->get_config_by_name('full_money');
+			$full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
+
+			if (empty($full_reducemoney) || $full_reducemoney <= 0) {
+				$is_open_fullreduction = 0;
+			}
+
+			$store_data['is_open_fullreduction'] = $is_open_fullreduction;
+			$store_data['full_money'] = $full_money;
+			$store_data['full_reducemoney'] = $full_reducemoney;
+
+
+
+			$store_data['goodstype'] = 2;
+			$store_data['goodstypeselect'] = 0;
+			$store_data['shopcarts'] = $tmp_goods;
+
+
+			$seller_goodss[$store_id] = $store_data;
+			$i++;
+		}
+
+		// 商家是否休息
+		$is_comunity_rest = D('Seller/Communityhead')->is_community_rest($community_id);
+		$open_man_orderbuy = D('Home/Front')->get_config_by_name('open_man_orderbuy');
+		$man_orderbuy_money = D('Home/Front')->get_config_by_name('man_orderbuy_money');
+		//if($man_orderbuy_money > $max_can_orderbuy_money){
+		//$max_can_orderbuy_money = $man_orderbuy_money;
+		//}
+		$is_show_guess_like = D('Home/Front')->get_config_by_name('is_show_guess_like');
+
+
+		// 免配送 man_free_tuanzshipping>0开启
+		$delivery_type_ziti = D('Home/Front')->get_config_by_name('delivery_type_ziti');
+		$delivery_type_express = D('Home/Front')->get_config_by_name('delivery_type_express');
+		$delivery_type_tuanz = D('Home/Front')->get_config_by_name('delivery_type_tuanz');
+		$man_free_tuanzshipping = $delivery_tuanz_money = 0;
+
+		//暂时屏蔽,2020.02.13.14:57
+		/**
+			  if($delivery_type_ziti!=1 && $delivery_type_express!=1 && $delivery_type_tuanz==1) {
+				  $man_free_tuanzshipping = D('Home/Front')->get_config_by_name('man_free_tuanzshipping');
+				  if($man_free_tuanzshipping>1 && !empty($man_free_tuanzshipping)) {
+					  $delivery_tuanz_money = D('Home/Front')->get_config_by_name('delivery_tuanz_money');
+				  }
+			  }
+			  **/
+
+
+		if ($delivery_type_tuanz == 1) {
+			$man_free_tuanzshipping = D('Home/Front')->get_config_by_name('man_free_tuanzshipping');
+		} else {
+			$man_free_tuanzshipping = 0;
+		}
+
+		$open_tuan_ship = $delivery_type_tuanz;
+		//团长自定义配送开关
+		if ($community_id && $man_free_tuanzshipping > 1) {
+			$community_modify_shipping = M('lionfish_community_head')->field('is_modify_shipping_method')->where(array('id' => $community_id))->find();
+			$is_modify_shipping_method = $community_modify_shipping['is_modify_shipping_method'];
+			if ($is_modify_shipping_method == 1) {
+				$open_tuan_ship = 1;
+			} else if ($is_modify_shipping_method == 2) {
+				$open_tuan_ship = 0;
+			}
+		}
+
+		$delivery_tuanz_money = D('Home/Front')->get_config_by_name('delivery_tuanz_money');
+
+		$shopcar_tab_all_name = D('Home/Front')->get_config_by_name('shopcar_tab_all_name');
+		$shopcar_tab_express_name = D('Home/Front')->get_config_by_name('shopcar_tab_express_name');
+
+
+		$is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
+		if ($is_open_fullreduction) {
+			$full_list = D('Home/Front')->get_fullreduction();
+		} else {
+			$full_list[0]['full_money'] = 0;
+			$full_list[0]['full_reducemoney'] = 0;
+		}
+
+		//同城配送信息
+		//配送费类型:0、固定金额,1、按距离收取
+		$localtown_delivery_moneytype = D('Home/Front')->get_config_by_name('localtown_delivery_moneytype');
+		$localtown_moneytype_fixed_deliverymoney = 0;
+		$localtown_moneytype_fixed_freemoney = 0;
+		if ($localtown_delivery_moneytype == 0) {
+			//起送价格
+			$localtown_moneytype_fixed_deliverymoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_deliverymoney');
+			//达到金额免配送费
+			$localtown_moneytype_fixed_freemoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_freemoney');
+		}
+
+		$need_data = array();
+		$need_data['code'] = 0;
+		$need_data['carts'] = $seller_goodss;
+		$need_data['mult_carts'] = $seller_goodss_mult;
+		$need_data['is_comunity_rest'] = $is_comunity_rest;
+		$need_data['open_man_orderbuy'] = $open_man_orderbuy;
+		$need_data['man_orderbuy_money'] = $man_orderbuy_money;
+		//$need_data['max_can_orderbuy_money'] = $max_can_orderbuy_money;
+		$need_data['is_show_guess_like'] = $is_show_guess_like;
+		$need_data['man_free_tuanzshipping'] = $man_free_tuanzshipping;
+		$need_data['delivery_tuanz_money'] = $delivery_tuanz_money;
+
+		$need_data['is_member_level_buy'] = $is_member_level_buy; //当前会员折扣 购买,1是,0否
+		$need_data['level_save_money'] = $level_save_money; //会员折扣省的钱
+
+		$need_data['is_vip_card_member'] = $is_vip_card_member; //当前会员是否是 会员卡会员 0 不是,1是,2已过期
+		$need_data['vipcard_save_money'] = $vipcard_save_money; //vip能节约的金额
+		$need_data['is_open_vipcard_buy'] = $is_open_vipcard_buy; //vip能节约的金额
+		$need_data['modify_vipcard_name'] = $modify_vipcard_name;
+
+		$need_data['shopcar_tab_all_name'] = $shopcar_tab_all_name;
+		$need_data['shopcar_tab_express_name'] = $shopcar_tab_express_name;
+		$need_data['open_tuan_ship'] = $open_tuan_ship;
+
+		$need_data['is_open_fullreduction'] = $is_open_fullreduction;
+		$need_data['full_list'] = $full_list;
+
+		//平台和供应商 起送价格和免配送费价格
+		//$need_data['localtown_fixed_list'] = $localtown_fixed_list;
+
+		$need_data['localtown_moneytype_fixed_deliverymoney'] = $localtown_moneytype_fixed_deliverymoney; //起送价格
+		$need_data['localtown_moneytype_fixed_freemoney'] = $localtown_moneytype_fixed_freemoney; //达到金额免配送费
+
+		echo json_encode($need_data);
+		die();
+
+	}
+
+	public function checkout_flushall()
+	{
+		$gpc = I('request.');
+
+		$token = $gpc['token'];
+
+		$community_id = $gpc['community_id'];
+
+		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where(array('token' => $token))->find();
+		$member_id = $weprogram_token['member_id'];
+
+		//dan soitaire
+		$buy_type = isset($gpc['buy_type']) ? $gpc['buy_type'] : 'dan';
+
+		//$car_prefix = 'soitairecart.';
+
+		//buy_type和soli_id吗
+
+		$is_community = D('Seller/Communityhead')->is_community($community_id);
+		if (!$is_community) {
+			$json['code'] = 6;
+			$json['msg'] = '该小区已经不存在!';
+			echo json_encode($json);
+			die();
+		}
+
+
+		$data = array();
+		$data['car_key'] = $gpc['car_key'];
+		$data['all_keys_arr'] = $gpc['all_keys_arr'];
+		$data['cur_car_key'] = $gpc['cur_car_key'];
+		//car_key:cart.6:MTc0:,cart.13:MjcwXzI3Mw==:
+		//all_keys_arr:cart.6:MTc0:_1,cart.13:MjcwXzI3Mw==:_1
+
+		$car_key = explode(',', $data['car_key']);
+		$all_keys_arr = explode(',', $data['all_keys_arr']);
+
+		if (!empty($data['cur_car_key'])) {
+			$car_key = array($data['cur_car_key']);
+		}
+
+		$save_keys = array();
+		if (!empty($all_keys_arr)) {
+			foreach ($all_keys_arr as $val) {
+				$tmp_val = explode('_', $val);
+				$save_keys[$tmp_val[0]] = $tmp_val[1];
+			}
+		}
+
+
+
+		if ($buy_type == 'dan') {
+			$all_cart = M('lionfish_comshop_car')->where("community_id={$community_id} and token='{$token}' and carkey like 'cart.%'")->select();
+
+		} else if ($buy_type == 'soitaire') {
+			$all_cart = M('lionfish_comshop_car')->where("community_id={$community_id} and token='{$token}' and carkey like 'soitairecart.%'")->select();
+		}
+
+		if (!empty($all_cart)) {
+			foreach ($all_cart as $val) {
+				$tmp_format_data = unserialize($val['format_data']);
+				$tmp_format_data['singledel'] = 0;
+
+
+				$tmp_format_data['quantity'] = isset($save_keys[$val['carkey']]) ? $save_keys[$val['carkey']] : $tmp_format_data['quantity'];
+
+
+				M('lionfish_comshop_car')->where(array('id' => $val['id'], 'community_id' => $community_id))->save(array('format_data' => serialize($tmp_format_data)));
+			}
+		}
+
+		if (!empty($car_key)) {
+			foreach ($car_key as $key) {
+
+				$car_info = M('lionfish_comshop_car')->where(array('community_id' => $community_id, 'carkey' => $key, 'token' => $token))->find();
+				if (!empty($car_info)) {
+					$tmp_format_data = unserialize($car_info['format_data']);
+					$tmp_format_data['singledel'] = 1;
+					$quantity = $tmp_format_data['quantity'];
+					$sku_quantity_one = $tmp_format_data['quantity'];
+					$goods_id = $tmp_format_data['goods_id'];
+					$sku_str = $tmp_format_data['sku_str'];
+					//同一个商品不同规格 总数量合计
+					$sku_quantity = $this->_check_goods_sku_quantity($community_id, $key, $token);
+					if ($sku_quantity > $quantity) {
+						$quantity = $sku_quantity;
+					}
+					$goods_description = D('Home/Front')->get_goods_common_field($goods_id, 'goods_start_count');
+					//起售数量判断
+					if ($sku_quantity_one < $goods_description['goods_start_count']) {
+
+						$json['code'] = 6;
+						$json['msg'] = $goods_description['goods_start_count'] . '份起售';
+						$json['max_quantity'] = $goods_description['goods_start_count'];
+						echo json_encode($json);
+						die();
+					}
+					$check_json = $this->_check_can_buy($member_id, $goods_id, $quantity);
+
+
+
+					if ($check_json['code'] != 0) {
+						$tmp_format_data['quantity'] = $check_json['count'];
+
+
+						M('lionfish_comshop_car')->where(array('id' => $car_info['id'], 'community_id' => $community_id))->save(array('format_data' => serialize($tmp_format_data)));
+						echo json_encode(array('code' => 6, 'msg' => $check_json['msg']));
+						die();
+					}
+
+					//check sku is ok 
+
+					$check_json = $this->_check_goods_sku_canbuy($goods_id, $sku_str);
+
+					if ($check_json['code'] != 0) {
+						echo json_encode(array('code' => 6, 'msg' => $check_json['msg']));
+						die();
+					}
+
+
+					$check_json = $this->_check_goods_quantity($goods_id, $sku_quantity_one, $sku_str);
+
+					if ($check_json['code'] != 0) {
+						echo json_encode(array('code' => 6, 'msg' => $check_json['msg']));
+						die();
+					}
+
+					M('lionfish_comshop_car')->where(array('id' => $car_info['id'], 'community_id' => $community_id))->save(array('format_data' => serialize($tmp_format_data)));
+				}
+			}
+		}
+		$is_limit_distance_buy = D('Home/Front')->get_config_by_name('shop_limit_buy_distance');
+
+		echo json_encode(array('code' => 0, 'data' => $is_limit_distance_buy));
+		die();
+	}
+
+	public function _check_goods_sku_quantity($community_id, $key, $token)
+	{
+		$quantity = 0;
+		$key_array = explode(":", $key);
+		$key_result = "";
+		foreach ($key_array as $k => $v) {
+			if ($k < 2) {
+				if (empty($key_result)) {
+					$key_result = $v;
+				} else {
+					$key_result = $key_result . ":" . $v;
+				}
+			}
+		}
+		$sql = "SELECT format_data FROM " . C('DB_PREFIX') . "lionfish_comshop_car "
+			. " WHERE carkey LIKE  '" . $key_result . "%' and community_id = '" . $community_id . "' "
+			. " and token='" . $token . "'";
+		$cart_goods_list = M()->query($sql);
+
+		if (!empty($cart_goods_list)) {
+			foreach ($cart_goods_list as $val) {
+				$tmp_format_data = unserialize($val['format_data']);
+				$quantity = $quantity + $tmp_format_data['quantity'];
+			}
+		}
+		return $quantity;
+	}
+
+	public function _check_goods_sku_canbuy($goods_id, $sku_str)
+	{
+
+		$json = array('code' => 0);
+
+		$goods_info = M('lionfish_comshop_goods')->field('goodsname as name')->where(array('id' => $goods_id))->find();
+
+		if (!empty($sku_str)) {
+			$goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->field('stock as quantity')->where(array('option_item_ids' => $sku_str, 'goods_id' => $goods_id))->find();
+
+			if (empty($goods_option_mult_value)) {
+				$json['code'] = 3;
+				$json['msg'] = mb_substr($goods_info['name'], 0, 4, 'utf-8') . ',规格已失效,删除后再结算';
+			}
+		}
+
+		return $json;
+	}
+
+
+	public function del_car_goods()
+	{
+		$gpc = I('request.');
+
+
+		$token = $gpc['token'];
+		$community_id = $gpc['community_id'];
+
+		$carkey = $gpc['carkey'];
+
+
+		M('lionfish_comshop_car')->where("community_id={$community_id} and token='{$token}' and carkey='{$carkey}'")->delete();
+
+		echo json_encode(array('code' => 0));
+		die();
+
+	}
+
+	public function _check_goods_quantity($goods_id, $quantity, $sku_str)
+	{
+		$gpc = I('request.');
+
+
+		$goods_info = M('lionfish_comshop_goods')->field('goodsname as name')->where(array('id' => $goods_id))->find();
+
+		$goods_quantity = D('Home/Car')->get_goods_quantity($goods_id);
+
+
+
+		$json = array('code' => 0);
+
+		if ($goods_quantity < $quantity) {
+			$json['code'] = 3;
+			$json['msg'] = mb_substr($goods_info['name'], 0, 4, 'utf-8') . '...,商品数量不足,剩余' . $goods_quantity . '个!!';
+
+		} else if (!empty($sku_str)) {
+			$mul_opt_arr = array();
+
+			$goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->field('stock as quantity')->where(array('option_item_ids' => $sku_str, 'goods_id' => $goods_id))->find();
+
+			if (!empty($goods_option_mult_value)) {
+				if ($goods_option_mult_value['quantity'] < $quantity) {
+					$json['code'] = 3;
+					$json['msg'] = mb_substr($goods_info['name'], 0, 4, 'utf-8') . '...,商品数量不足,剩余' . $goods_option_mult_value['quantity'] . '个!!';
+				}
+			}
+		}
+		return $json;
+	}
+
+	private function _check_can_buy($member_id, $goods_id, $quantity)
+	{
+		$gpc = I('request.');
+
+		//$can_buy_count =  D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
+
+		$goods_description = D('Home/Front')->get_goods_common_field($goods_id, 'total_limit_count,one_limit_count,oneday_limit_count,is_new_buy,is_limit_levelunbuy,is_limit_vipmember_buy,goods_start_count');
+
+		//单次限购判断
+		if ($goods_description['one_limit_count'] > 0 && $quantity > $goods_description['one_limit_count']) {
+			$json['code'] = 6;
+			$json['msg'] = '您本次只能购买' . $goods_description['one_limit_count'] . '份';
+			$json['count'] = $goods_description['one_limit_count'];
+			return $json;
+		}
+
+		$can_buy_day_count = D('Home/Front')->check_goods_user_canbuy_day_count($member_id, $goods_id);
+		if ($can_buy_day_count == -1 || ($can_buy_day_count > 0 && $quantity > $can_buy_day_count)) {
+			$json['code'] = 6;
+			$json['msg'] = '您今天只能购买' . $goods_description['oneday_limit_count'] . '份';
+			$json['count'] = 1;
+			return $json;
+		} else if ($can_buy_day_count > 0 && $quantity > $can_buy_day_count) {
+			$json['code'] = 6;
+			$json['msg'] = '您今天还能购买' . $can_buy_day_count . '份';
+			$json['count'] = $can_buy_day_count;
+			return $json;
+		}
+
+		$can_buy_all_count = D('Home/Front')->check_goods_user_canbuy_all_count($member_id, $goods_id);
+		//历史限购判断
+		if ($can_buy_all_count == -1 && $goods_description['total_limit_count'] > 0) {
+			$json['code'] = 6;
+			$json['msg'] = '您最多只能购买' . $goods_description['total_limit_count'] . '个';
+			$json['count'] = 1;
+			return $json;
+		} else if ($can_buy_all_count > 0 && $quantity > $can_buy_all_count) {
+			$json['code'] = 6;
+			$json['msg'] = '您还能购买' . $can_buy_all_count . '份';
+			$json['count'] = $can_buy_all_count;
+			return $json;
+		}
+
+		$goods_info = M('lionfish_comshop_goods')->where(array('id' => $goods_id))->find();
+
+		$goods_description = D('Home/Front')->get_goods_common_field($goods_id, 'per_number');
+
+		$can_buy_count = D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
+		$json = array();
+		if ($can_buy_count == -1 || $can_buy_day_count == -1) {
+			$json['code'] = 6;
+			$json['msg'] = mb_substr($goods_info['name'], 0, 4, 'utf-8') . '...,您本次只能购买' . $goods_description['per_number'] . '个';
+		} else if ($can_buy_count > 0 && $quantity > $can_buy_count) {
+			$json['code'] = 6;
+			//$json['msg']=mb_substr($goods_info['name'],0,4,'utf-8').'...,您还能购买'.$can_buy_count.'份';
+			$json['msg'] = '本次最多购买' . $can_buy_count . '份';
+			$json['count'] = $can_buy_count;
+
+		} else {
+			$json['code'] = 0;
+		}
+		return $json;
+	}
+
+	private function _add_address($token, $userName, $telNumber, $provinceName, $cityName, $countyName, $detailInfo, $latitude = '', $longitude = '', $lou_meng_hao = '')
+	{
+		$_GPC = I('request.');
+
+		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where(array('token' => $token))->find();
+		$member_id = $weprogram_token['member_id'];
+
+
+		//  lionfish_comshop_area
+
+		$province_info = M('lionfish_comshop_area')->where("name like '%{$provinceName}%' ")->find();
+
+		if (!empty($province_info)) {
+			$province_id = $province_info['id'];
+		} else {
+
+
+			$area_data = array();
+			$area_data['name'] = $provinceName;
+			$area_data['pid'] = 0;
+			$area_data['code'] = $max_dp['code'] + 1;
+
+			$province_id = M('lionfish_comshop_area')->add($area_data);
+
+			$up_data = array();
+			$up_data['code'] = $province_id;
+
+			M('lionfish_comshop_area')->where(array('id' => $province_id))->save($up_data);
+
+		}
+
+		$guding_arr = ['鞍山市'];
+
+		if (in_array($cityName, $guding_arr)) {
+			$city_info = M('lionfish_comshop_area')->where("name = '{$cityName}'")->find();
+		} else {
+			$city_info = M('lionfish_comshop_area')->where("name like '%{$cityName}%'")->find();
+		}
+
+		//$city_info = M('lionfish_comshop_area')->where("name like '%{$cityName}%'")->find();
+
+		if (!empty($city_info)) {
+			$city_id = $city_info['id'];
+		} else {
+
+			$max_dp = M('lionfish_comshop_area')->order('code desc')->find();
+
+			$area_data = array();
+			$area_data['name'] = $cityName;
+			$area_data['pid'] = $province_id;
+			$area_data['code'] = $max_dp['code'] + 1;
+
+			$city_id = M('lionfish_comshop_area')->add($area_data);
+
+			$up_data = array();
+			$up_data['code'] = $city_id;
+
+			M('lionfish_comshop_area')->where(array('id' => $city_id))->save($up_data);
+
+		}
+
+		//city_name: 东莞市
+		if (empty($countyName)) {
+			if ($cityName == '东莞市') {
+				$countyName = '东莞';
+			}
+			if ($cityName == '中山市') {
+				$countyName = '中山';
+				//453
+			}
+		}
+
+		$country_info = M('lionfish_comshop_area')->where("name like '%{$countyName}%' ")->find();
+
+		if ($countyName == '中山') {
+
+			$country_info = M('lionfish_comshop_area')->where(array('id' => 453))->find();
+			//
+		}
+
+
+		if (!empty($country_info)) {
+			$country_id = $country_info['id'];
+		} else {
+
+			$max_dp = M('lionfish_comshop_area')->order('code desc')->find();
+
+			$area_data = array();
+			$area_data['name'] = $countyName;
+			$area_data['pid'] = $city_id;
+			$area_data['code'] = $max_dp['code'] + 1;
+
+			$country_id = M('lionfish_comshop_area')->add($area_data);
+
+			$up_data = array();
+			$up_data['code'] = $country_id;
+
+			M('lionfish_comshop_area')->where(array('id' => $country_id))->save($up_data);
+
+		}
+
+
+		$address_param = array();
+
+		$address_param['member_id'] = $member_id;
+		$address_param['province_id'] = $province_id;
+		$address_param['country_id'] = $country_id;
+		$address_param['city_id'] = $city_id;
+		$address_param['address'] = $detailInfo;
+		$address_param['name'] = $userName;
+		$address_param['telephone'] = $telNumber;
+
+		$address_param['lon_lat'] = '';
+		$address_param['lou_meng_hao'] = $lou_meng_hao;
+
+		if (!empty($latitude)) {
+			$address_param['lon_lat'] = $longitude . ',' . $latitude;
+		}
+
+
+
+		$has_addre = M('lionfish_comshop_address')->where($address_param)->find();
+
+		if (empty($has_addre)) {
+
+			$has_default_address = M('lionfish_comshop_address')->where(array('is_default' => 1, 'member_id' => $member_id))->find();
+
+
+			$address_data = array();
+			$address_data['member_id'] = $member_id;
+			$address_data['name'] = $userName;
+			$address_data['telephone'] = $telNumber;
+			$address_data['lou_meng_hao'] = $lou_meng_hao;
+			if (!empty($latitude)) {
+				$address_data['lon_lat'] = $longitude . ',' . $latitude;
+			} else {
+				$address_data['lon_lat'] = '';
+			}
+
+			$address_data['address'] = $detailInfo;
+			$address_data['address_name'] = empty($data['address_name']) ? 'HOME' : $data['address_name'];
+			if (!empty($has_default_address) && false) {
+				$address_data['is_default'] = 0;
+			} else {
+				$data = array();
+				$data['is_default'] = 0;
+
+				M('lionfish_comshop_address')->where(array('member_id' => $member_id))->save($data);
+
+				$address_data['is_default'] = 1;
+			}
+
+			$address_data['city_id'] = $city_id;
+			$address_data['country_id'] = $country_id;
+			$address_data['province_id'] = $province_id;
+
+			$res = M('lionfish_comshop_address')->add($address_data);
+		} else {
+			$res = $has_addre['address_id'];
+		}
+
+		return $res;
+	}
+
+	public function checkout()
+	{
+		$gpc = I('request.');
+
+
+		$buy_type = isset($gpc['buy_type']) ? $gpc['buy_type'] : 'dan';
+
+		$pintuan_model_buy = D('Home/Front')->get_config_by_name('pintuan_model_buy');
+
+		if (empty($pintuan_model_buy) || $pintuan_model_buy == 0) {
+			$pintuan_model_buy = 0;
+		}
+
+
+		$mb_city_name = isset($gpc['mb_city_name']) ? $gpc['mb_city_name'] : '';
+
+		if ($buy_type == 'undefined') {
+			$buy_type = 'dan';
+		}
+
+		$community_id = $gpc['community_id'];
+		$token = $gpc['token'];
+
+		$voucher_id = isset($gpc['voucher_id']) ? $gpc['voucher_id'] : 0;
+
+		$soli_id = isset($gpc['soli_id']) ? intval($gpc['soli_id']) : '';
+
+		$use_quan_str = isset($gpc['use_quan_str']) ? $gpc['use_quan_str'] : '';
+		$use_quan_arr = array();
+
+		if ($use_quan_str != '') {
+			$use_quan_arr_tmp = explode('@', $use_quan_str);
+			foreach ($use_quan_arr_tmp as $val) {
+				$tmp_arr = explode('_', $val);
+				$use_quan_arr[$tmp_arr[0]] = $tmp_arr[1];
+			}
+		}
+
+		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where(array('token' => $token))->find();
+		$member_id = $weprogram_token['member_id'];
+
+
+		$is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
+		$is_open_vipcard_buy = !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 ? 1 : 0;
+
+		$is_vip_card_member = 0;
+		$is_member_level_buy = 0;
+
+		if ($member_id > 0) {
+			$member_info = M('lionfish_comshop_member')->where(array('member_id' => $member_id))->find();
+
+			if (!empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1) {
+
+				$now_time = time();
+
+				if ($member_info['card_id'] > 0 && $member_info['card_end_time'] > $now_time) {
+					$is_vip_card_member = 1; //还是会员
+				} else if ($member_info['card_id'] > 0 && $member_info['card_end_time'] < $now_time) {
+					$is_vip_card_member = 2; //已过期
+				}
+			}
+
+			if ($is_vip_card_member != 1 && $member_info['level_id'] > 0) {
+				$is_member_level_buy = 1;
+			}
+		}
+		//预售不开启会员卡
+		if ($buy_type == 'pesale') {
+			$is_member_level_buy = 0;
+			$is_vip_card_member = 0;
+		}
+
+
+		if (empty($member_id)) {
+			//需要登录
+			echo json_encode(array('code' => 5));
+			die();
+		}
+
+		$cart = D('Home/Car');
+
+
+
+		if ((!$cart->has_goodswecar($buy_type, $token, $community_id))) {
+			//购物车中没有商品
+			echo json_encode(array('code' => 4));
+			die();
+		}
+
+
+		$member_info = M('lionfish_comshop_member')->where(array('member_id' => $member_id))->find();
+
+		//soitaire
+		$goods = $cart->get_all_goodswecar($buy_type, $token, 1, $community_id, $soli_id);
+
+
+		$address = M('lionfish_comshop_address')->where(array('member_id' => $member_id))->order('is_default desc,address_id desc')->find();
+
+		$add_old_order = M('lionfish_comshop_order')->field('address_id')->where(" (delivery ='localtown_delivery' or delivery = 'express') and member_id = {$member_id} ")->order('order_id desc')->find();
+
+		if (!empty($add_old_order) && $add_old_order['address_id'] > 0) {
+			$address = M('lionfish_comshop_address')->where(array('address_id' => $add_old_order['address_id'], 'member_id' => $member_id))->find();
+		}
+
+		$mb_city_id = 0;
+		if (!empty($mb_city_name)) {
+			$mb_city_info = M('lionfish_comshop_area')->where(" name='{$mb_city_name}' ")->find();
+
+			if (!empty($mb_city_info)) {
+				$mb_city_id = $mb_city_info['id'];
+			}
+
+		}
+
+		if ($address) {
+
+			//get_area_info($id)
+			$province_info = D('Home/Front')->get_area_info($address['province_id']); // M('area')->field('area_name')->where( array('area_id' => $address['province_id']) )->find();
+			$city_info = D('Home/Front')->get_area_info($address['city_id']); //M('area')->field('area_name')->where( array('area_id' => $address['city_id']) )->find();
+			$country_info = D('Home/Front')->get_area_info($address['country_id']); //M('area')->field('area_name')->where( array('area_id' => $address['country_id']) )->find();
+
+			$address['province_name'] = $province_info['name'];
+			$address['city_name'] = $city_info['name'];
+			$address['country_name'] = $country_info['name'];
+		} else {
+			$address = array();
+		}
+
+		$seller_goodss = array();
+		$show_voucher = 0;
+
+		//判断是否仅快递的配送方式  is_only_express
+
+		$is_open_only_express = D('Home/Front')->get_config_by_name('is_open_only_express');
+
+		$is_only_express = 0;
+
+		if (!empty($is_open_only_express) && $is_open_only_express == 1) {
+			$is_only_express = 1;
+		}
+		/**
+		   if($is_vip_card_member != 1 && $member_info['level_id'] >0 )
+		   {
+			   $is_member_level_buy = 1;
+		   }
+		   **/
+		foreach ($goods as $key => $val) {
+			//$goods_store_field =  M('goods')->field('store_id')->where( array('goods_id' => $val['goods_id']) )->find();
+			if ($is_only_express == 1 && $val['is_only_express'] != 1) {
+				$is_only_express = 0;
+			}
+			if ($is_only_express == 0 && $val['is_only_express'] == 3) {
+				$is_only_express = 3;
+			}
+			if ($is_only_express == 0 && $val['is_only_express'] == 2) {
+				$is_only_express = 2;
+			}
+
+			$supply_id = D('Home/Front')->get_goods_supply_id($val['goods_id']);
+			if ($supply_id > 0) {
+				$supply_info = D('Home/Front')->get_supply_info($supply_id);
+
+				if ($supply_info['type'] == 0) {
+					$supply_id = 0;
+				}
+			}
+			$val['name'] = htmlspecialchars_decode($val['name']);
+			$seller_goodss[$supply_id]['goods'][$key] = $val;
+		}
+
+		//begin 如果是同城配送 ,查一查有没有新提交的地址,如果有,按照新的来处理
+
+		$localtown_address = array();
+
+		if ($is_only_express == 3) {
+			$localtown_old_order = M('lionfish_comshop_order')->field('address_id')->where(array('delivery' => 'localtown_delivery', 'member_id' => $member_id))->order('order_id desc')->find();
+
+			$localtown_id = 0;
+
+
+			if (!empty($localtown_old_order) && $localtown_old_order['address_id'] > 0) {
+				$localtown_address = M('lionfish_comshop_address')->where(array('address_id' => $localtown_old_order['address_id'], 'member_id' => $member_id))->find();
+
+				if (!empty($localtown_address)) {
+					$province_info = D('Home/Front')->get_area_info($address['province_id']); // M('area')->field('area_name')->where( array('area_id' => $address['province_id']) )->find();
+					$city_info = D('Home/Front')->get_area_info($address['city_id']); //M('area')->field('area_name')->where( array('area_id' => $address['city_id']) )->find();
+					$country_info = D('Home/Front')->get_area_info($address['country_id']); //M('area')->field('area_name')->where( array('area_id' => $address['country_id']) )->find();
+
+					$localtown_address['province_name'] = $province_info['name'];
+					$localtown_address['city_name'] = $city_info['name'];
+					$localtown_address['country_name'] = $country_info['name'];
+
+				} else if (isset($gpc['longitude']) && isset($gpc['latitude'])) {
+					$localtown_address['lon_lat'] = $gpc['longitude'] . ',' . $gpc['latitude'];
+				}
+			} else {
+				$address = array();
+			}
+
+		}
+		//end同城配送
+
+		$quan_model = D('Home/Voucher');
+		$pin_model = D('Home/Pin');
+
+
+		$voucher_price = 0;
+		$reduce_money = 0;
+		$cha_reduce_money = 0;
+
+		$is_pin_over = 0;
+		$is_moban = false;
+
+
+
+		$is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
+		$full_money = D('Home/Front')->get_config_by_name('full_money');
+		$full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
+
+		if (empty($full_reducemoney) || $full_reducemoney <= 0) {
+			$is_open_fullreduction = 0;
+		}
+
+		$show_voucher = 0;
+
+		$voucher_can_use = 1; //目前都是平台券,
+		$man_total_free = 0;
+		$store_buy_total_money = 0;
+
+		$pin_id = 0;
+		$presale_goods_id = 0; //预售商品id
+		$presale_goods_total = 0; //预售商品价格
+
+		$is_zero_buy = 0;
+		$vipcard_save_money = 0;
+		$level_save_money = 0;
+
+		$today_time = time();
+		$arr = array('天', '一', '二', '三', '四', '五', '六');
+		//计算优惠券
+		foreach ($seller_goodss as $store_id => $val) {
+
+			$seller_voucher_list = array();
+			$seller_total_fee = 0;
+			$total_trans_free = 0;
+			$is_no_quan = false;
+
+
+			$total_weight = 0;
+			$total_quantity = 0;
+			$vch_goods_ids = array();
+
+
+			foreach ($val['goods'] as $kk => $d_goods) {
+				//预售不参与会员卡
+				if ($d_goods['is_take_vipcard'] == 1) {
+					$vipcard_save_money += $d_goods['total'] - $d_goods['card_total'];
+				} else if ($d_goods['is_mb_level_buy'] == 1 && $d_goods['is_mb_level_buy'] == 1 && $is_member_level_buy == 1) {
+					$level_save_money += $d_goods['total'] - $d_goods['level_total'];
+				}
+
+				if ($is_vip_card_member == 1 && $d_goods['is_take_vipcard'] == 1) {
+					$seller_total_fee += $d_goods['card_total'];
+					if ($store_id == 0) {
+						$store_buy_total_money += $d_goods['card_total'];
+					}
+					if ($d_goods['can_man_jian'] == 1) {
+						$man_total_free += $d_goods['card_total'];
+
+					}
+				} else if ($d_goods['is_mb_level_buy'] == 1 && $member_info['level_id'] > 0) {
+					$seller_total_fee += $d_goods['level_total'];
+					if ($store_id == 0) {
+						$store_buy_total_money += $d_goods['level_total'];
+					}
+					if ($d_goods['can_man_jian'] == 1) {
+						$man_total_free += $d_goods['level_total'];
+					}
+				} else {
+					$seller_total_fee += $d_goods['total'];
+					if ($store_id == 0) {
+						$store_buy_total_money += $d_goods['total'];
+					}
+					if ($d_goods['can_man_jian'] == 1) {
+						$man_total_free += $d_goods['total'];
+
+					}
+
+				}
+
+
+				if ($buy_type == 'pintuan' && $d_goods['pin_id'] > 0) {
+					$is_pin_over = $pin_model->getNowPinState($d_goods['pin_id']);
+					if ($is_pin_over == 2) {
+						$is_zero_buy = $pin_model->check_goods_iszero_opentuan($d_goods['goods_id']);
+					}
+				} else if ($buy_type == 'pintuan' && $d_goods['pin_id'] == 0) {
+					$is_zero_buy = $pin_model->check_goods_iszero_opentuan($d_goods['goods_id']);
+				}
+
+				if ($buy_type == 'presale') {
+					$presale_goods_id = $d_goods['goods_id'];
+					$presale_goods_total = $seller_total_fee;
+				}
+				$tp_goods_info = M('lionfish_comshop_goods')->field('type')->where(array('id' => $d_goods['goods_id']))->find();
+
+				$vch_goods_ids[$d_goods['goods_id']] = $vch_goods_ids[$d_goods['goods_id']] + $d_goods['total'];
+				//$is_no_quan = true;
+				//预售不开启优惠券 
+				if ($tp_goods_info['type'] == 'integral' || $tp_goods_info['type'] == 'presale') {
+					$is_no_quan = true;
+				}
+
+				if ($d_goods['shipping'] == 0) {
+					$is_moban = true;
+					$val['is_moban'] = true;
+					$total_weight += $d_goods['weight'] * $d_goods['quantity'];
+					$total_quantity += $d_goods['quantity'];
+				}
+
+				$d_goods[$kk]['trans_free'] = 0;
+				/**
+						 if($d_goods['shipping']==1)
+						 {
+							 //统一运费
+							 $d_goods[$kk]['trans_free'] = $d_goods['goods_freight'];
+						 }else {
+							 //运费模板
+							  if(!empty($address))
+							 {
+								 $trans_free = load_model_class('transport')->calc_transport($d_goods['transport_id'], $d_goods['quantity'],$d_goods['quantity']*$d_goods['weight'], $address['city_id'] );
+							 }else{
+								 $trans_free = 0;
+							 }
+							$d_goods[$kk]['trans_free'] = $trans_free;
+						 }
+						 **/
+
+				$total_trans_free += $d_goods[$kk]['trans_free'];
+				//自提时间
+				$goods_info = M('lionfish_comshop_good_common')->field('pick_up_type,pick_up_modify')->where(array('goods_id' => $d_goods['goods_id']))->find();
+				$pick_up_type = -1;
+				if ($pick_up_type == -1 || $goods_info['pick_up_type'] > $pick_up_type) {
+					$pick_up_type = $goods_info['pick_up_type'];
+
+					if ($pick_up_type == 0) {
+						$pick_up_time = date('m-d', $today_time);
+						$pick_up_weekday = '周' . $arr[date('w', $today_time)];
+					} else if ($pick_up_type == 1) {
+						$pick_up_time = date('m-d', $today_time + 86400);
+						$pick_up_weekday = '周' . $arr[date('w', $today_time + 86400)];
+					} else if ($pick_up_type == 2) {
+						$pick_up_time = date('m-d', $today_time + 86400 * 2);
+						$pick_up_weekday = '周' . $arr[date('w', $today_time + 86400 * 2)];
+					} else if ($pick_up_type == 3) {
+						$pick_up_time = $goods_info['pick_up_modify'];
+					}
+				}
+				$d_goods['pick_up_type'] = $pick_up_type;
+				$d_goods['pick_up_time'] = $pick_up_time;
+				$d_goods['pick_up_weekday'] = $pick_up_weekday;
+
+				$val['goods'][$kk] = $d_goods;
+
+			}
+
+			$val['reduce_money'] = 0;
+
+			//pindan (拼团商品单独购买)   pintuan (拼团)
+			//预售关闭满减 
+			if ($buy_type == 'pindan' || $buy_type == 'pintuan' || $buy_type == 'integral' || $buy_type == 'presale') {
+				$is_open_fullreduction = 0;
+			}
+
+			//原来满级计算man_total_free
+			/*if($is_open_fullreduction == 1 && $man_total_free >= $full_money )
+				   {
+				   $val['reduce_money'] = $full_reducemoney;
+				   $reduce_money = $full_reducemoney;
+				   }else if($is_open_fullreduction == 1 && $man_total_free < $full_money)
+				   {
+				   $cha_reduce_money = $full_money - $man_total_free;
+				   }*/
+			/**
+			 * 新满减计算
+			 */
+
+			if ($is_open_fullreduction == 1) {
+				$reduce_result = D('Home/Front')->get_reduce_money($man_total_free);
+
+				$val['reduce_money'] = $reduce_result['reduce_money'];
+				$reduce_money = $reduce_result['reduce_money'];
+				$cha_reduce_money = $reduce_result['cha_reduce_money'];
+			}
+
+			$chose_vouche = array();
+
+			if (!$is_no_quan) {
+
+				$vouche_list = $quan_model->get_user_canpay_voucher($member_id, $store_id, $seller_total_fee, '', $vch_goods_ids);
+
+				$vouche_list = $quan_model->get_voucher_amout_bygoods($vouche_list, $val['goods'], $reduce_money);
+				//var_dump(  $vouche_list );
+				//die();
+
+				if (!empty($vouche_list) && empty($use_quan_arr)) {
+					$ling_vouche_list = $vouche_list;
+					if ($voucher_can_use == 1) {
+						$voucher_can_use++;
+
+						$show_voucher = 1;
+						reset($ling_vouche_list);
+						$chose_vouche = current($ling_vouche_list);
+						//$voucher_price += $chose_vouche['credit'];
+						$voucher_price += $chose_vouche['can_vouche_amount'];
+
+						//$seller_total_fee = round( $seller_total_fee - $chose_vouche['credit'], 2);
+						$seller_total_fee = round($seller_total_fee - $chose_vouche['can_vouche_amount'], 2);
+					}
+
+				} else if (!empty($vouche_list) && !empty($use_quan_arr)) {
+
+					foreach ($vouche_list as $tmp_voucher) {
+						if ($tmp_voucher['id'] == $use_quan_arr[$store_id]) {
+							$show_voucher = 1;
+							$chose_vouche = $tmp_voucher;
+							//$seller_total_fee = round( $seller_total_fee - $chose_vouche['credit'], 2);
+							//$voucher_price += $chose_vouche['credit'];
+							$seller_total_fee = round($seller_total_fee - $chose_vouche['can_vouche_amount'], 2);
+							$voucher_price += $chose_vouche['can_vouche_amount'];
+
+							break;
+						}
+					}
+				}
+
+			}
+
+
+
+			$val['chose_vouche'] = $chose_vouche;
+			$val['show_voucher'] = $show_voucher;
+
+			$val['voucher_list'] = $vouche_list;
+			$val['total'] = $seller_total_fee;
+
+			if ($val['total'] < 0) {
+				$val['total'] = 0;
+			}
+
+			$val['trans_free'] = $total_trans_free;
+
+			$val['total_weight'] = $total_weight;
+			$val['total_quantity'] = $total_quantity;
+
+			$s_logo = D('Home/Front')->get_config_by_name('shoplogo');
+			$shoname = D('Home/Front')->get_config_by_name('shoname');
+			if (!empty($s_logo)) {
+				$s_logo = tomedia($s_logo);
+			}
+
+			$store_info = array('s_id' => $store_id, 's_true_name' => $shoname, 's_logo' => $s_logo);
+
+			if (!empty($store_id) && $store_id > 0) {
+				$supply_info = D('Home/Front')->get_supply_info($store_id);
+				//logo
+				if (!empty($supply_info)) {
+					$store_info['s_true_name'] = $supply_info['shopname'];
+					$store_info['s_logo'] = tomedia($supply_info['logo']);
+				}
+			}
+
+			$val['store_info'] = $store_info;
+
+			$seller_goodss[$store_id] = $val;
+		}
+
+		$trans_free_toal = 0; //运费
+
+		//delivery_type_ziti  delivery_type_express    delivery_type_tuanz  delivery_tuanz_money
+
+		$delivery_type_ziti = D('Home/Front')->get_config_by_name('delivery_type_ziti');
+		$delivery_type_express = D('Home/Front')->get_config_by_name('delivery_type_express');
+		$delivery_type_tuanz = D('Home/Front')->get_config_by_name('delivery_type_tuanz');
+		$delivery_tuanz_money = D('Home/Front')->get_config_by_name('delivery_tuanz_money');
+		//---
+		$man_free_tuanzshipping = D('Home/Front')->get_config_by_name('man_free_tuanzshipping');
+		$man_free_shipping = D('Home/Front')->get_config_by_name('man_free_shipping');
+
+		$delivery_express_name = D('Home/Front')->get_config_by_name('delivery_express_name');
+
+
+		if (empty($man_free_tuanzshipping) || $buy_type == 'integral') {
+			$man_free_tuanzshipping = 0;
+		}
+		//关闭团长配送费 免  预售 
+		if (empty($man_free_tuanzshipping) || $buy_type == 'presale') {
+			$man_free_tuanzshipping = 0;
+		}
+		if (empty($man_free_shipping) || $buy_type == 'integral') {
+			$man_free_shipping = 0;
+		}
+		//关闭快递配送费 免  预售 
+		if (empty($man_free_shipping) || $buy_type == 'presale') {
+			$man_free_shipping = 0;
+		}
+
+
+		//if( $buy_type == 'dan' )
+		if ($buy_type == 'dan' || $buy_type == 'soitaire' || ($pintuan_model_buy == 1 && $buy_type != 'dan' && $buy_type != 'integral')) {
+			//...判断团长是否开启自定义的情况 store_buy_total_money
+			$community_info_modify = M('lionfish_community_head')->field('is_modify_shipping_method,is_modify_shipping_fare,shipping_fare')->where(array('id' => $community_id))->find();
+
+
+			if (!empty($community_info_modify['is_modify_shipping_method']) && $community_info_modify['is_modify_shipping_method'] == 1 && $delivery_type_tuanz == 1) {
+				//开启配送
+				$delivery_type_tuanz = 1;
+
+				if (!empty($community_info_modify['is_modify_shipping_fare']) && $community_info_modify['is_modify_shipping_fare'] == 1 && $community_info_modify['shipping_fare'] > 0) {
+					$delivery_tuanz_money = $community_info_modify['shipping_fare'];
+				}
+
+
+			} else if (!empty($community_info_modify['is_modify_shipping_method']) && $community_info_modify['is_modify_shipping_method'] == 2) {
+				//关闭配送
+				$delivery_type_tuanz = 0;
+			}
+		} else if ($buy_type == 'pindan' || $buy_type == 'pintuan') {
+			if ($pintuan_model_buy == 0) {
+				$delivery_type_tuanz = 0;
+				$delivery_type_express = 1;
+				$delivery_type_ziti = 2;
+			}
+		} else if ($buy_type == 'integral') {
+			$delivery_type_tuanz = 0;
+			$delivery_type_express = 1;
+			$delivery_type_ziti = 2;
+		}
+
+		foreach ($val['goods'] as $kk => $d_goods) {
+			if ($d_goods['is_only_express'] == 1) {
+				$delivery_type_express = 1;
+			}
+		}
+
+		$is_man_delivery_tuanz_fare = 0; //是否达到满xx减团长配送费
+		$fare_man_delivery_tuanz_fare_money = 0; //达到满xx减团长配送费, 减了多少钱
+
+		if (($buy_type == 'dan' || $buy_type == 'soitaire') && !empty($man_free_tuanzshipping) && $man_free_tuanzshipping > 0 && $man_free_tuanzshipping <= $store_buy_total_money) {
+			//$delivery_tuanz_money = 0;
+			$is_man_delivery_tuanz_fare = 1;
+			$fare_man_delivery_tuanz_fare_money = $delivery_tuanz_money;
+		}
+
+		$is_man_shipping_fare = 0; //是否达到满xx减运费
+		$fare_man_shipping_fare_money = 0; //达到满xx减运费,司机减了多少运费
+
+		//----开始计算运费 //dispatchtype
+
+		if ($delivery_type_express == 1) {
+			//ims_ 
+			$store_trans_free_toal = 0;
+			if ($mb_city_id > 0) {
+
+				$shipping_default = M('lionfish_comshop_shipping')->where(array('enabled' => 1))->order('isdefault desc,id desc')->find();
+
+				foreach ($seller_goodss as $store_id => $val) {
+					//$val['is_moban'] = true;
+					$store_shipping_fare = 0;
+					if (isset($val['is_moban']) && $val['is_moban']) {
+						$store_shipping_fare = D('Home/Transport')->calc_transport($shipping_default['id'], $val['total_quantity'], $val['total_weight'], $mb_city_id);
+
+					}
+
+
+					$val['store_shipping_fare'] = $store_shipping_fare;
+
+					$trans_free_toal += $store_shipping_fare;
+					if ($store_id == 0) {
+						$store_trans_free_toal += $store_shipping_fare;
+					}
+
+					foreach ($val['goods'] as $kk => $d_goods) {
+						if ($d_goods['shipping'] == 1) {
+							//统一运费
+							$trans_free_toal += $d_goods['goods_freight'];
+							if ($store_id == 0) {
+								$store_trans_free_toal += $d_goods['goods_freight'];
+							}
+						}
+					}
+				}
+
+			} else if (!empty($address) && $mb_city_id == 0) {
+
+				$shipping_default = M('lionfish_comshop_shipping')->where(array('enabled' => 1))->order('isdefault desc,id desc')->find();
+
+				foreach ($seller_goodss as $store_id => $val) {
+					$store_shipping_fare = 0;
+					if (isset($val['is_moban']) && $val['is_moban']) {
+						$store_shipping_fare = D('Home/Transport')->calc_transport($shipping_default['id'], $val['total_quantity'], $val['total_weight'], $address['city_id']);
+
+					}
+					$val['store_shipping_fare'] = $store_shipping_fare;
+
+					$trans_free_toal += $store_shipping_fare;
+
+					if ($store_id == 0) {
+
+						$store_trans_free_toal += $store_shipping_fare;
+					}
+
+					foreach ($val['goods'] as $kk => $d_goods) {
+						if ($d_goods['shipping'] == 1) {
+							//统一运费
+							$trans_free_toal += $d_goods['goods_freight'];
+							$val['store_shipping_fare'] += $d_goods['goods_freight'];
+
+							if ($store_id == 0) {
+								$store_trans_free_toal += $d_goods['goods_freight'];
+							}
+						}
+					}
+				}
+
+			} else {
+				$trans_free_toal = 0;
+			}
+
+			//
+
+			if (!empty($man_free_shipping) && $man_free_shipping > 0 && $man_free_shipping <= $store_buy_total_money) {
+
+				$fare_man_shipping_fare_money = $store_trans_free_toal;
+				$is_man_shipping_fare = 1;
+				//$trans_free_toal = 0;
+			}
+		}
+		//礼品卡配送费0
+		if ($buy_type == 'virtualcard') {
+			$trans_free_toal = 0;
+		}
+		//---结束结算运费
+
+
+		if (empty($delivery_type_ziti)) {
+			$delivery_type_ziti = 1; //开启
+		}
+		if (empty($delivery_type_express)) {
+			$delivery_type_express = 2;
+		}
+		if (empty($delivery_type_tuanz)) {
+			$delivery_type_tuanz = 2;
+		}
+
+		//默认关闭同城配送
+		$delivery_type_localtown = 0;
+		//默认关闭核销商品
+		$delvery_type_hexiao = 0;
+		//is_only_express
+		if ($is_only_express == 1) {
+			$delivery_type_ziti = 2;
+			$delivery_type_express = 1;
+			$delivery_type_tuanz = 2;
+		} else if ($is_only_express == 3) {
+			//同城配送
+			$delivery_type_ziti = 0;
+			$delivery_type_express = 0;
+			$delivery_type_tuanz = 0;
+			$delivery_type_localtown = 1;
+		} else if ($is_only_express == 2) {
+			//核销商品
+			$delivery_type_ziti = 0;
+			$delivery_type_express = 0;
+			$delivery_type_tuanz = 0;
+			$delivery_type_localtown = 0;
+			$delvery_type_hexiao = 1;
+		}
+
+
+
+		$total_free = 0;
+		$is_ziti = 2;
+
+		$pick_up_time = "";
+		$pick_up_type = -1;
+		$pick_up_weekday = '';
+		$today_time = time();
+
+		$arr = array('天', '一', '二', '三', '四', '五', '六');
+
+		$pick_up_arr = array();
+		foreach ($goods as $key => $good) {
+			//暂时关闭
+			//ims_lionfish_comshop_goods
+			//ims_ lionfish_comshop_good_common
+
+			$goods_info = M('lionfish_comshop_good_common')->field('pick_up_type,pick_up_modify')->where(array('goods_id' => $good['goods_id']))->find();
+
+			if ($pick_up_type == -1 || $goods_info['pick_up_type'] > $pick_up_type) {
+				$pick_up_type = $goods_info['pick_up_type'];
+
+				if ($pick_up_type == 0) {
+					$pick_up_time = date('m-d', $today_time);
+					$pick_up_weekday = '周' . $arr[date('w', $today_time)];
+				} else if ($pick_up_type == 1) {
+					$pick_up_time = date('m-d', $today_time + 86400);
+					$pick_up_weekday = '周' . $arr[date('w', $today_time + 86400)];
+				} else if ($pick_up_type == 2) {
+					$pick_up_time = date('m-d', $today_time + 86400 * 2);
+					$pick_up_weekday = '周' . $arr[date('w', $today_time + 86400 * 2)];
+				} else if ($pick_up_type == 3) {
+					$pick_up_time = $goods_info['pick_up_modify'];
+				}
+			}
+
+			$goods[$key]['trans_free'] = $good['goods_freight'];
+
+			if ($is_vip_card_member == 1 && $good['is_take_vipcard'] == 1) {
+				$total_free += $good['card_total'];
+			} else if ($good['is_mb_level_buy'] == 1 && $member_info['level_id'] > 0) {
+				$total_free += $good['level_total'];
+			} else {
+				$total_free += $good['total'];
+			}
+
+		}
+
+		//同城配送费
+		$localtown_shipping_fare = 0;
+		//包装费
+		$picking_fare = 0;
+		$picking_fare_arr = array();
+		$localtown_shipping_fare_arr = array();
+		$localtown_dispatchtime = 0; //预计一共需要配送多少分钟
+		$localtown_expected_delivery = array(); //预计送达时间段
+		$localtown_modifypickingname = ""; //包装费标题
+		if ($is_only_express == 3) {
+			$picking_fare_arr = D('Home/LocaltownDelivery')->calc_packing_money($seller_goodss); // $seller_goodss;
+			$picking_fare = $picking_fare_arr['total_picking_fare'];
+
+			$localtown_dispatchtime = D('Home/LocaltownDelivery')->get_order_dispatchtime($seller_goodss);
+
+
+			if (isset($gpc['latitude']) && !empty($gpc['latitude']) && isset($gpc['longitude']) && !empty($gpc['longitude'])) {
+
+				$lon = $gpc['longitude'];
+
+				$lat = $gpc['latitude'];
+
+				$localtown_shipping_fare_arr = D('Home/LocaltownDelivery')->calc_shipping_fare($lon, $lat, $seller_goodss);
+
+				$localtown_shipping_fare = $localtown_shipping_fare_arr['total_shipping_fare'];
+
+				$trans_free_toal = $localtown_shipping_fare;
+
+
+			} else if (!empty($localtown_address)) {
+				list($lon, $lat) = explode(',', $localtown_address['lon_lat']);
+
+				$localtown_shipping_fare_arr = D('Home/LocaltownDelivery')->calc_shipping_fare($lon, $lat, $seller_goodss);
+
+				$localtown_shipping_fare = $localtown_shipping_fare_arr['total_shipping_fare'];
+
+				$trans_free_toal = $localtown_shipping_fare;
+			}
+
+			//配送时间段间隔
+			$localtown_expected_delivery = D('Home/LocaltownDelivery')->get_expected_delivery($localtown_dispatchtime);
+
+			$localtown_modifypickingname = D('Home/Front')->get_config_by_name('localtown_modifypickingname');
+			$localtown_modifypickingname = !empty($localtown_modifypickingname) ? $localtown_modifypickingname : '包装费';
+		}
+
+		//暂时关闭自提代码
+		/**
+		   if(!empty($pick_up))
+		   {
+			   $pick_up = unserialize($pick_up);
+			   $pick_up_ids = implode(',',$pick_up);
+			   $pick_up_arr = M('pick_up')->where( array('id'=>array('in',$pick_up_ids)) )->select();
+		   }
+		   **/
+
+
+		$pick_up_name = '';
+		$pick_up_mobile = '';
+		$tuan_send_address = '';
+		$order_note_content = '';
+
+		$tuan_send_address_info = array();
+
+		$shop_limit_buy_distance = D('Home/Front')->get_config_by_name('shop_limit_buy_distance');
+
+
+
+
+		if ($is_ziti >= 1) {
+			//寻找上一个订单的自提电话 自提姓名  
+
+			$last_order_info = M('lionfish_comshop_order')->where(array('member_id' => $member_id, 'delivery' => 'pickup'))->order('order_id desc')->find();
+			if (empty($last_order_info)) {
+				$last_order_info = M('lionfish_comshop_order')->where(array('member_id' => $member_id, 'delivery' => 'hexiao'))->order('order_id desc')->find();
+			}
+			if (!empty($last_order_info)) {
+				$pick_up_name = $last_order_info['shipping_name'];
+				$pick_up_mobile = $last_order_info['telephone'];
+				$order_note_content = $last_order_info['note_content'];
+			}
+
+			//order_note_content
+			$last_tuanz_send_order_info = M('lionfish_comshop_order')->field('tuan_send_address,address_id,note_content,order_id')->where(array('member_id' => $member_id, 'delivery' => 'tuanz_send'))->order('order_id desc')->find();
+
+			if (!empty($last_tuanz_send_order_info)) {
+				$tuan_send_address = $last_tuanz_send_order_info['tuan_send_address'];
+
+				if (!empty($last_tuanz_send_order_info['note_content']) && $last_tuanz_send_order_info['order_id'] > $last_order_info['order_id']) {
+					$order_note_content = $last_tuanz_send_order_info['note_content'];
+				}
+
+				if (!empty($last_tuanz_send_order_info['address_id'])) {
+
+					if ($shop_limit_buy_distance == 1) {
+						$tuan_send_address_info = M('lionfish_comshop_address')->where("address_id=" . $last_tuanz_send_order_info['address_id'] . " and lon_lat != '' ")->find();
+
+					} else {
+
+						$tuan_send_address_info = M('lionfish_comshop_address')->where("address_id=" . $last_tuanz_send_order_info['address_id'])->find();
+
+					}
+
+					if (!empty($tuan_send_address) && !empty($tuan_send_address_info['lon_lat'])) {
+						$province_info = D('Home/Front')->get_area_info($tuan_send_address_info['province_id']); // M('area')->field('area_name')->where( array('area_id' => $address['province_id']) )->find();
+						$city_info = D('Home/Front')->get_area_info($tuan_send_address_info['city_id']); //M('area')->field('area_name')->where( array('area_id' => $address['city_id']) )->find();
+						$country_info = D('Home/Front')->get_area_info($tuan_send_address_info['country_id']); //M('area')->field('area_name')->where( array('area_id' => $address['country_id']) )->find();
+
+						$tuan_send_address_info['province_name'] = $province_info['name'];
+						$tuan_send_address_info['city_name'] = $city_info['name'];
+						$tuan_send_address_info['country_name'] = $country_info['name'];
+
+						$tuan_send_address = $tuan_send_address_info['address'];
+					} else {
+						//todo...
+						$tuan_send_address = '';
+					}
+
+				} else {
+					$tuan_send_address = '';
+				}
+
+			}
+		}
+		/**
+		 **/
+		/**
+		   tuan_region
+		   store_buy_total_money
+		   
+		   **/
+
+		//open_score_buy_score $shop_limit_buy_distance = load_model_class('front')->get_config_by_name('shop_limit_buy_distance');
+
+
+		/**
+		   
+		   $delivery_ziti_name = D('Home/Front')->get_config_by_name('delivery_ziti_name');
+		   $delivery_tuanzshipping_name = D('Home/Front')->get_config_by_name('delivery_tuanzshipping_name');
+		   $delivery_diy_sort = D('Home/Front')->get_config_by_name('delivery_diy_sort');
+		   
+		   if(empty($delivery_diy_sort) || !isset($delivery_diy_sort)) $delivery_diy_sort = '0,1,2';
+		   
+		   
+		   if( empty($tuan_send_address_info) )
+		   {
+			   $tuan_send_address_info = array();
+		   }
+
+		   //判断是否预售,给出预售的信息 begin todo
+		   $presale_info = [];
+		   if( $buy_type == 'presale' )
+		   {
+			   // $presale_goods_id
+			   $presale_result = D('Home/PresaleGoods')->getCheckOutPresaleGoodsInfo( $presale_goods_id , $presale_goods_total );
+
+			   if( $presale_result['code'] == 0 )
+			   {
+				   $presale_info = $presale_result['data'];
+			   }
+		   }
+		   //end
+	   **/
+		$open_score_buy_score = D('Home/Front')->get_config_by_name('open_score_buy_score');
+
+		if (empty($open_score_buy_score) || $buy_type == 'integral') {
+			$open_score_buy_score = 0;
+		}
+
+		$score_forbuy_money_maxbi = D('Home/Front')->get_config_by_name('score_forbuy_money_maxbi');
+
+		if (empty($score_forbuy_money_maxbi)) {
+			$score_forbuy_money_maxbi = 100;
+		}
+
+		$score_for_money = 0;
+		$bue_use_score = 0;
+
+		if ($open_score_buy_score == 1) {
+			if ($member_info['score'] > 0) {
+
+				$score_can_max = $store_buy_total_money - $voucher_price - $reduce_money;
+
+				//计算能兑换多少钱
+				$score_forbuy_money = D('Home/Front')->get_config_by_name('score_forbuy_money');
+				//只有兑换比例大于0才能允许兑换
+				if (!empty($score_forbuy_money) && $score_forbuy_money > 0) {
+					$score_for_money = sprintf("%.2f", $member_info['score'] / $score_forbuy_money);
+					if ($score_can_max < $score_for_money) {
+						$score_for_money = $score_can_max;
+						$bue_use_score = floor($score_can_max * $score_forbuy_money);
+						$score_for_money = round($bue_use_score / $score_forbuy_money, 2);
+					}
+
+					$max_store_buy_total_money = sprintf("%.2f", ($score_forbuy_money_maxbi * $score_can_max) / 100);
+
+					if ($score_for_money > $max_store_buy_total_money) {
+						$score_for_money = $max_store_buy_total_money;
+
+						$bue_use_score = floor($max_store_buy_total_money * $score_forbuy_money);
+
+						$score_for_money = round($bue_use_score / $score_forbuy_money, 2);
+					} else if ($bue_use_score <= $max_store_buy_total_money) {
+
+						$bue_use_score = floor($score_for_money * $score_forbuy_money);
+
+						//$bue_use_score = $member_info['score'];
+
+						if ($bue_use_score > $member_info['score']) {
+							$bue_use_score = floor($member_info['score']);
+						}
+						$score_for_money = round($bue_use_score / $score_forbuy_money, 2);
+					}
+				}
+
+
+				//预售
+				//if($buy_type == 'presale'){
+				//	$sum_deduction_money =  $goods[0]["quantity"] * $presale_info['deduction_money'] ;
+				//}	
+			}
+		}
+		//score_forbuy_money score
+
+		$delivery_ziti_name = D('Home/Front')->get_config_by_name('delivery_ziti_name');
+		$delivery_tuanzshipping_name = D('Home/Front')->get_config_by_name('delivery_tuanzshipping_name');
+		$delivery_diy_sort = D('Home/Front')->get_config_by_name('delivery_diy_sort');
+
+		if (empty($delivery_diy_sort) || !isset($delivery_diy_sort))
+			$delivery_diy_sort = '0,1,2';
+
+
+		if (empty($tuan_send_address_info)) {
+			$tuan_send_address_info = array();
+		}
+
+		//判断是否预售,给出预售的信息 begin todo
+		$presale_info = [];
+		if ($buy_type == 'presale') {
+			// $presale_goods_id
+			$presale_result = D('Home/PresaleGoods')->getCheckOutPresaleGoodsInfo($presale_goods_id, $presale_goods_total);
+
+			if ($presale_result['code'] == 0) {
+				$presale_info = $presale_result['data'];
+			}
+		}
+		//end
+
+		$need_data = array();
+		$need_data['code'] = 1;
+
+		$need_data['open_score_buy_score'] = $open_score_buy_score; //1开启积分抵扣
+		$need_data['score'] = $member_info['score']; //会员持有的积分
+		$need_data['score_for_money'] = $score_for_money; //会员能抵扣的金额
+		$need_data['bue_use_score'] = $bue_use_score; //会员能抵扣的积分数
+
+
+		$need_data['delivery_type_ziti'] = $delivery_type_ziti;
+		$need_data['delivery_type_express'] = $delivery_type_express;
+		$need_data['delivery_type_tuanz'] = $delivery_type_tuanz;
+		$need_data['delivery_type_localtown'] = $delivery_type_localtown;
+		$need_data['delvery_type_hexiao'] = $delvery_type_hexiao;
+
+
+		$need_data['delivery_express_name'] = $delivery_express_name;
+		$need_data['delivery_ziti_name'] = $delivery_ziti_name;
+		$need_data['delivery_tuanzshipping_name'] = $delivery_tuanzshipping_name;
+		$need_data['delivery_diy_sort'] = $delivery_diy_sort;
+
+		$need_data['presale_info'] = $presale_info; //预售信息
+
+		$seller_goodss_keys = array_keys($seller_goodss);
+
+		$need_data['delivery_tuanz_money'] = round($delivery_tuanz_money * count($seller_goodss_keys), 2);
+
+		//$need_data['delivery_tuanz_money'] = $delivery_tuanz_money;
+		$need_data['man_free_tuanzshipping'] = empty($man_free_tuanzshipping) ? 0 : $man_free_tuanzshipping; //团长配送,满多少免配送费,0或者为空表示不减免
+		$need_data['man_free_shipping'] = empty($man_free_shipping) ? 0 : $man_free_shipping; //快递配送,满多少免配送费,0或者为空表示不减免
+
+		$need_data['address'] = $address;
+
+
+		$need_data['pick_up_time'] = $pick_up_time;
+		$need_data['pick_up_type'] = $pick_up_type;
+		$need_data['pick_up_weekday'] = $pick_up_weekday;
+
+		$need_data['is_pin_over'] = $is_pin_over;
+		$need_data['is_integer'] = 0; //$is_no_quan ? 1: 0;
+		$need_data['pick_up_arr'] = $pick_up_arr;
+		$need_data['is_ziti'] = 2;
+
+		$need_data['ziti_name'] = $pick_up_name;
+		$need_data['ziti_mobile'] = $pick_up_mobile;
+		$need_data['tuan_send_address'] = $tuan_send_address;
+		$need_data['tuan_send_address_info'] = $tuan_send_address_info;
+		$need_data['seller_goodss'] = $seller_goodss;
+		$need_data['show_voucher'] = $show_voucher;
+
+		$need_data['buy_type'] = $buy_type;
+		$need_data['address'] = $address;
+		$need_data['trans_free_toal'] = $trans_free_toal;
+
+		$need_data['is_limit_distance_buy'] = 0;
+		$need_data['limit_distance'] = 100; //km
+
+		$need_data['is_member_level_buy'] = $is_member_level_buy; //km
+		$need_data['level_save_money'] = $level_save_money; //km
+
+		//begin
+
+		$need_data['localtown_shipping_fare'] = $localtown_shipping_fare; //同城配送配送费
+		$need_data['pickingup_fare'] = $picking_fare; //包装费
+		$need_data['localtown_dispatchtime'] = $localtown_dispatchtime; //预计一共需要配送多少分钟
+		$need_data['picking_fare_arr'] = $picking_fare_arr;
+		$need_data['localtown_shipping_fare_arr'] = $localtown_shipping_fare_arr;
+		$need_data['localtown_expected_delivery'] = $localtown_expected_delivery;
+		//end
+
+
+		$need_data['is_vip_card_member'] = $is_vip_card_member; //km
+		$need_data['vipcard_save_money'] = $vipcard_save_money; //km
+		$need_data['is_open_vipcard_buy'] = $is_open_vipcard_buy; //km
+
+
+
+		if (!empty($shop_limit_buy_distance) && $shop_limit_buy_distance == 1) {
+			$latitude = 0;
+			$longitude = 0;
+
+			if (!empty($tuan_send_address_info) && !empty($tuan_send_address_info['lon_lat'])) {
+				//lon_lat
+				$lon_lat_arr = explode(',', $tuan_send_address_info['lon_lat']);
+				$longitude = $lon_lat_arr[0];
+				$latitude = $lon_lat_arr[1];
+			}
+
+
+			if (isset($gpc['latitude']) && !empty($gpc['latitude'])) {
+				$latitude = $gpc['latitude'];
+			}
+			if (isset($gpc['longitude']) && !empty($gpc['longitude'])) {
+				$longitude = $gpc['longitude'];
+			}
+
+			if (!empty($latitude) && !empty($longitude)) {
+				$shop_buy_distance = D('Home/Front')->get_config_by_name('shop_buy_distance');
+
+				$shop_buy_distance = $shop_buy_distance * 1000;
+
+				$community_info = M('lionfish_community_head')->field('lon,lat')->where(array('id' => $community_id))->find();
+
+				$distince = D('Seller/Communityhead')->GetDistance($longitude, $latitude, $community_info['lon'], $community_info['lat']);
+
+				$need_data['current_distance'] = $distince;
+				$need_data['shop_buy_distance'] = $shop_buy_distance;
+				if ($distince > $shop_buy_distance) {
+					$need_data['is_limit_distance_buy'] = 1;
+					$need_data['limit_distance'] = $distince / 1000;
+				}
+			}
+		}
+
+
+
+		$need_data['reduce_money'] = $reduce_money;
+		$need_data['is_open_fullreduction'] = $is_open_fullreduction;
+		$need_data['cha_reduce_money'] = $cha_reduce_money;
+
+
+		$need_data['is_man_delivery_tuanz_fare'] = $is_man_delivery_tuanz_fare; //是否达到满xx减团长配送费
+		$need_data['fare_man_delivery_tuanz_fare_money'] = $fare_man_delivery_tuanz_fare_money; //达到满xx减团长配送费, 减了多少钱
+		$need_data['is_man_shipping_fare'] = $is_man_shipping_fare; //是否达到满xx减运费
+		$need_data['fare_man_shipping_fare_money'] = $fare_man_shipping_fare_money; //达到满xx减运费,司机减了多少运费
+
+
+		$dispatching = isset($gpc['dispatching']) ? $gpc['dispatching'] : 'pickup';
+		//is_ziti == 2
+		if ($dispatching == 'express') {
+			$need_data['total_free'] = $total_free + $trans_free_toal - $voucher_price - $reduce_money;
+		} else if ($dispatching == 'localtown_delivery') {
+			$need_data['total_free'] = $total_free + $localtown_shipping_fare + $picking_fare - $voucher_price - $reduce_money;
+		} else {
+			$need_data['total_free'] = $total_free - $voucher_price - $reduce_money;
+		}
+		if ($is_ziti == 2) {
+			$need_data['total_free'] = $total_free - $voucher_price - $reduce_money;
+		}
+		//积分兑换 不算总金额,但是算总积分
+		if ($buy_type == 'integral') {
+			$need_data['total_free'] = $trans_free_toal;
+			$need_data['total_integral'] = $total_free;
+		}
+
+		if ($need_data['total_free'] < 0) {
+			$need_data['total_free'] = 0;
+		}
+
+		//判断是否可以余额支付
+
+		//暂时关闭 会员余额功能
+		/**
+		   $is_yue_open_info =	M('config')->where( array('name' => 'is_yue_open') )->find();
+		   $is_yue_open =  $is_yue_open_info['value'];
+		   **/
+
+		$is_yue_open = 0;
+
+		$is_yue_open = D('Home/Front')->get_config_by_name('is_open_yue_pay');
+		if (empty($is_yue_open)) {
+			$is_yue_open = 0;
+		}
+
+
+		$need_data['is_yue_open'] = $is_yue_open;
+
+		$need_data['can_yupay'] = 0;
+
+		//暂时关闭 会员余额功能
+
+		if ($is_yue_open == 1 && $need_data['total_free'] >= 0 && $member_info['account_money'] >= $need_data['total_free']) {
+			$need_data['can_yupay'] = 1;
+		}
+
+		//前端隐藏 团长信息
+		$index_hide_headdetail_address = D('Home/Front')->get_config_by_name('index_hide_headdetail_address');
+
+		if (empty($index_hide_headdetail_address)) {
+			$index_hide_headdetail_address = 0;
+		}
+		$need_data['index_hide_headdetail_address'] = $index_hide_headdetail_address;
+
+
+		//订单留言
+		$is_open_order_message = D('Home/Front')->get_config_by_name('is_open_order_message');
+
+		$need_data['yu_money'] = $member_info['account_money'];
+		$need_data['goods'] = $goods;
+		$need_data['is_open_order_message'] = $is_open_order_message;
+
+		$need_data['is_zero_opentuan'] = 0;
+		//拼团特殊情况0元开团
+		if ($buy_type == 'pintuan' && $is_zero_buy == 1) {
+			//$need_data['total_free'] = 0;
+			//$need_data['trans_free_toal'] = 0;
+			//$need_data['is_zero_opentuan'] = 1;
+		}
+
+
+		//订阅消息begin
+
+		$is_need_subscript = 0;
+		$need_subscript_template = array();
+
+
+		//'pay_order','send_order','hexiao_success','apply_community','open_tuan','take_tuan','pin_tuansuccess','apply_tixian'
+		//$member_id
+		if ($buy_type == 'pintuan') {
+			//pin_tuansuccess
+			//send_order  parameter[weprogram_subtemplate_pin_tuansuccess]
+			//hexiao_success
+
+			$pin_tuansuccess_info = M('lionfish_comshop_subscribe')->where(array('member_id' => $member_id, 'type' => 'pin_tuansuccess'))->find();
+
+			//if( empty($pin_tuansuccess_info) )
+			//{
+			$weprogram_subtemplate_pin_tuansuccess = D('Home/Front')->get_config_by_name('weprogram_subtemplate_pin_tuansuccess');
+
+			if (!empty($weprogram_subtemplate_pin_tuansuccess)) {
+				$need_subscript_template['pin_tuansuccess'] = $weprogram_subtemplate_pin_tuansuccess;
+			}
+			//}
+
+		} else {
+			//pay_order
+			$pay_order_info = M('lionfish_comshop_subscribe')->where(array('member_id' => $member_id, 'type' => 'pay_order'))->find();
+
+			//if( empty($pay_order_info) )
+			//{
+			$weprogram_subtemplate_pay_order = D('Home/Front')->get_config_by_name('weprogram_subtemplate_pay_order');
+
+			if (!empty($weprogram_subtemplate_pay_order)) {
+				$need_subscript_template['pay_order'] = $weprogram_subtemplate_pay_order;
+			}
+			//}
+		}
+		//send_order
+
+		$send_order_info = M('lionfish_comshop_subscribe')->where(array('member_id' => $member_id, 'type' => 'send_order'))->find();
+
+		//if( empty($send_order_info) )
+		//{
+		$weprogram_subtemplate_send_order = D('Home/Front')->get_config_by_name('weprogram_subtemplate_send_order');
+
+		if (!empty($weprogram_subtemplate_send_order)) {
+			$need_subscript_template['send_order'] = $weprogram_subtemplate_send_order;
+		}
+		//}
+		//hexiao_success
+		$hexiao_success_info = M('lionfish_comshop_subscribe')->where(array('member_id' => $member_id, 'type' => 'hexiao_success'))->find();
+
+
+		//if( empty($hexiao_success_info) )
+		//{
+		$weprogram_subtemplate_hexiao_success = D('Home/Front')->get_config_by_name('weprogram_subtemplate_hexiao_success');
+
+		if (!empty($weprogram_subtemplate_hexiao_success)) {
+			$need_subscript_template['hexiao_success'] = $weprogram_subtemplate_hexiao_success;
+		}
+		//}
+
+		if (!empty($need_subscript_template)) {
+			$is_need_subscript = 1;
+		}
+
+		//下单万能表单
+		$need_data['allform'] = D('Home/Allform')->getOrderForms();
+
+		//判断是否使用货到付款
+		$cashondelivery_data = D('Home/Front')->getCashonDeliveryAction($buy_type, $seller_goodss);
+		$need_data['cashondelivery_data'] = $cashondelivery_data;
+
+		//订阅消息end
+		$need_data['is_need_subscript'] = $is_need_subscript;
+		$need_data['need_subscript_template'] = $need_subscript_template;
+
+		//订单提交页面备注信息
+		$order_note_open = D('Home/Front')->get_config_by_name('order_note_open');
+
+		$order_note_open = isset($order_note_open) && $order_note_open == 1 ? 1 : 0;
+
+		$order_note_name = D('Home/Front')->get_config_by_name('order_note_name');
+
+		$order_note_name = !isset($order_note_name) || empty($order_note_name) ? '店名' : $order_note_name;
+
+		$need_data['order_note_open'] = $order_note_open; //开启下单页面备注,仅 自提跟 团长配送时需要
+		$need_data['order_note_name'] = $order_note_name; //备注名称,默认是店名
+		$need_data['order_note_content'] = $order_note_content; //备注名称,默认是店名
+
+		$need_data['localtown_modifypickingname'] = $localtown_modifypickingname; //备注名称,默认是店名
+
+		//配送费类型:0、固定金额,1、按距离收取
+		$localtown_delivery_moneytype = D('Home/Front')->get_config_by_name('localtown_delivery_moneytype');
+		//起送价格
+		$localtown_moneytype_fixed_deliverymoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_deliverymoney');
+		//达到金额免配送费
+		$localtown_moneytype_fixed_freemoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_freemoney');
+		//加价配送
+		$localtown_makeup_delivery_money = D('Home/Front')->get_config_by_name('localtown_makeup_delivery_money');
+		//1、固定金额,订单价格超过起送价格 无加价配送费,2、按距离收取 无加价配送费 3、固定金额,起送价格为0 无加价配送费
+		if (($localtown_delivery_moneytype == 0 && ($localtown_shipping_fare_arr[0]['is_can_qisong'] == 1 || $localtown_moneytype_fixed_deliverymoney == 0)) || $localtown_delivery_moneytype == 1) {
+			$localtown_makeup_delivery_money = 0;
+		} else {
+			$localtown_makeup_delivery_money = 0;
+		}
+
+		$need_data['localtown_delivery_moneytype'] = $localtown_delivery_moneytype;
+		$need_data['localtown_moneytype_fixed_deliverymoney'] = $localtown_moneytype_fixed_deliverymoney;
+		$need_data['localtown_moneytype_fixed_freemoney'] = $localtown_moneytype_fixed_freemoney;
+		$need_data['localtown_makeup_delivery_money'] = $localtown_makeup_delivery_money;
+
+		$need_data['order_lou_meng_hao'] = D('Home/Front')->get_config_by_name('order_lou_meng_hao');
+		$need_data['order_lou_meng_hao_placeholder'] = D('Home/Front')->get_config_by_name('order_lou_meng_hao_placeholder');
+
+		echo json_encode($need_data);
+		die();
+	}
+
+	public function sub_order()
+	{
+		$gpc = I('request.');
+
+		$buy_type = isset($gpc['buy_type']) ? $gpc['buy_type'] : 'dan';
+
+		$token = $gpc['token'];
+
+		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where(array('token' => $token))->find();
+		$member_id = $weprogram_token['member_id'];
+
+		$pintuan_model_buy = D('Home/Front')->get_config_by_name('pintuan_model_buy');
+
+		$allform_id = $gpc['allform_id'];
+		$allform_list = $gpc['allform_list'];
+
+		if (empty($pintuan_model_buy) || $pintuan_model_buy == 0) {
+			$pintuan_model_buy = 0;
+		}
+
+		$is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
+		$is_open_vipcard_buy = !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 ? 1 : 0;
+
+		$is_vip_card_member = 0;
+		$is_member_level_buy = 0;
+
+		if ($member_id > 0) {
+
+			$member_info = M('lionfish_comshop_member')->where(array('member_id' => $member_id))->find();
+
+			if (!empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1) {
+
+				$now_time = time();
+
+				if ($member_info['card_id'] > 0 && $member_info['card_end_time'] > $now_time) {
+					$is_vip_card_member = 1; //还是会员
+				} else if ($member_info['card_id'] > 0 && $member_info['card_end_time'] < $now_time) {
+					$is_vip_card_member = 2; //已过期
+				}
+			}
+
+			if ($is_vip_card_member != 1 && $member_info['level_id'] > 0) {
+				$is_member_level_buy = 1;
+			}
+		}
+
+		if ($buy_type == 'presale') {
+			$is_vip_card_member = 0;
+			$is_member_level_buy = 0;
+		}
+
+		//use_score = 1
+		$use_score = isset($gpc['use_score']) ? intval($gpc['use_score']) : 0;
+
+		$puis_not_buy = D('Home/Front')->get_config_by_name('puis_not_buy');
+
+		if (!empty($puis_not_buy) && $puis_not_buy == 1) {
+			$member_info = M('lionfish_comshop_member')->field('level_id')->where(array('member_id' => $member_id))->find();
+
+			if ($member_info['level_id'] == 0) {
+				echo json_encode(array('code' => 2, 'msg' => '普通会员不能购买'));
+				die();
+			}
+		}
+		//$buy_type == 'presale'
+		$data_s = array();
+		$data_s['pay_method'] = $gpc['wxpay'];
+		$data_s['buy_type'] = isset($gpc['buy_type']) ? $gpc['buy_type'] : 'dan';
+		$data_s['pick_up_id'] = $gpc['pick_up_id'];
+		$data_s['dispatching'] = $gpc['dispatching'];
+
+		$order_note_open = D('Home/Front')->get_config_by_name('order_note_open');
+		if ($order_note_open == 1) {
+			$data_s['note_content'] = $gpc['note_content'];
+		} else {
+			$data_s['note_content'] = '';
+		}
+
+
+		$data_s['soli_id'] = isset($gpc['soli_id']) ? intval($gpc['soli_id']) : 0;
+
+
+		if ($data_s['dispatching'] != 'express' && empty($data_s['pick_up_id'])) {
+			$last_community = M('lionfish_community_history')->where(array('member_id' => $member_id))->order('id desc')->find();
+
+			if (!empty($last_community)) {
+				$data_s['pick_up_id'] = $last_community['head_id'];
+			}
+
+			//$data_s['pick_up_id']
+		}
+		//礼品卡不用配送地址begin
+		if ($data_s['buy_type'] == 'virtualcard') {
+			$data_s['dispatching'] = 'express';
+			$data_s['address_id'] = 0;
+		}
+		//end
+
+		if ($data_s['buy_type'] == 'dan' || $data_s['buy_type'] == 'soitaire' || $data_s['buy_type'] == 'presale' || ($pintuan_model_buy == 1 && $data_s['buy_type'] != 'dan' && $data_s['buy_type'] != 'integral')) {
+			D('Seller/Community')->in_community_history($member_id, $data_s['pick_up_id']);
+		}
+
+		//'express'  快递, 'pickup'  自提, 'tuanz_send'  团长配送)   tuan_send_address 
+
+		$data_s['ziti_name'] = $gpc['ziti_name'];
+		$data_s['quan_arr'] = $gpc['quan_arr'];
+
+
+		$data_s['comment'] = $gpc['comment'];
+		$data_s['ziti_mobile'] = $gpc['ziti_mobile'];
+		$data_s['tuan_send_address'] = $gpc['tuan_send_address'];
+		$data_s['ck_yupay'] = $gpc['ck_yupay'];
+		//是否货到付款
+		$data_s['cashon_delivery'] = $gpc['cashon_delivery'];
+
+
+		$data_s['province_name'] = isset($gpc['province_name']) ? $gpc['province_name'] : '';
+		$data_s['city_name'] = isset($gpc['city_name']) ? $gpc['city_name'] : '';
+		$data_s['country_name'] = isset($gpc['country_name']) ? $gpc['country_name'] : '';
+		$data_s['address_name'] = isset($gpc['address_name']) ? $gpc['address_name'] : '';
+
+		$data_s['latitude'] = isset($gpc['latitude']) ? $gpc['latitude'] : '';
+		$data_s['longitude'] = isset($gpc['longitude']) ? $gpc['longitude'] : '';
+		$data_s['lou_meng_hao'] = isset($gpc['lou_meng_hao']) ? $gpc['lou_meng_hao'] : '';
+
+		$data_s['expected_delivery_time'] = isset($gpc['expected_delivery_time']) ? $gpc['expected_delivery_time'] : '';
+		//$data_s['tuan_send_address'] .= $data_s['lou_meng_hao'];
+		//$data_s['tuan_send_address'] .= $data_s['lou_meng_hao'];
+
+		//tuan_send_address
+
+		$province_name = isset($data_s['province_name']) ? $data_s['province_name'] : '';
+		$city_name = isset($data_s['city_name']) ? $data_s['city_name'] : '';
+		$country_name = isset($data_s['country_name']) ? $data_s['country_name'] : '';
+		$address_name = isset($data_s['address_name']) ? $data_s['address_name'] : '';
+
+		//判断配送距离
+		/*if($data_s['dispatching'] == 'localtown_delivery'){
+			   //服务距离
+			   $localtown_servvice_maxdistance =  D('Home/Front')->get_config_by_name('localtown_servvice_maxdistance');
+			   //商家经纬度
+			   $localtown_shop_lon =  D('Home/Front')->get_config_by_name('localtown_shop_lon');
+			   $localtown_shop_lat =  D('Home/Front')->get_config_by_name('localtown_shop_lat');
+
+			   $distince = D('Seller/Communityhead')->GetDistance($data_s['longitude'],$data_s['latitude'], $localtown_shop_lon, $localtown_shop_lat);
+			   $distince = round($distince/1000,2);
+			   if($distince > $localtown_servvice_maxdistance){
+				   //echo json_encode( array('code' => 2, 'msg' => '超出服务距离'.$localtown_servvice_maxdistance.'KM') );
+				   echo json_encode( array('code' => 2, 'msg' => '您与商家的距离过远,商家的配送范围是'.$localtown_servvice_maxdistance.'KM内') );
+				   die();
+			   }
+		   }*/
+
+
+		$json = array();
+
+		$pay_method = $data_s['pay_method']; //支付类型
+		$order_msg_str = $data_s['order_msg_str']; //商品订单留言
+		$comment = $data_s['comment']; //商品订单留言
+
+		$comment_arr = array();
+		if (!empty($data_s['comment'])) {
+			$comment_arr1 = explode('@EOF@', $data_s['comment']);
+			foreach ($comment_arr1 as $var) {
+				$count = substr_count($var, '_');
+				$a = explode('_', $var);
+
+				for ($i = 1; $i < $count; $i++) {
+					$comment_arr[$a[$i]] = $a[$count];
+				}
+
+			}
+		}
+
+		$pick_up_id = $data_s['pick_up_id'];
+		$dispatching = $data_s['dispatching'];
+		$ziti_name = $data_s['ziti_name'];
+		$ziti_mobile = $data_s['ziti_mobile'];
+
+
+		//新增快递
+		$province_name = isset($data_s['province_name']) ? $data_s['province_name'] : '';
+		$city_name = isset($data_s['city_name']) ? $data_s['city_name'] : '';
+		$country_name = isset($data_s['country_name']) ? $data_s['country_name'] : '';
+		$address_name = isset($data_s['address_name']) ? $data_s['address_name'] : '';
+
+
+		$ck_yupay = $data_s['ck_yupay'];
+		$cashon_delivery = $data_s['cashon_delivery'];
+		if ($dispatching == 'express') {
+			$data_s['address_id'] = $this->_add_address($token, $ziti_name, $ziti_mobile, $province_name, $city_name, $country_name, $address_name);
+		} else if ($dispatching == 'localtown_delivery') {
+			$data_s['address_id'] = $this->_add_address($token, $ziti_name, $ziti_mobile, $province_name, $city_name, $country_name, $address_name, $data_s['latitude'], $data_s['longitude'], $data_s['lou_meng_hao']);
+		} else if ($dispatching == 'tuanz_send') {
+			$data_s['address_id'] = $this->_add_address($token, $ziti_name, $ziti_mobile, $province_name, $city_name, $country_name, $data_s['tuan_send_address'], $data_s['latitude'], $data_s['longitude'], $data_s['lou_meng_hao']);
+
+			$data_s['tuan_send_address'] .= $data_s['lou_meng_hao'];
+		}
+
+		/**
+		   
+		   pick_up_id: that.data.pick_up_id,
+		   dispatching: that.data.dispatching, //express  pickup
+		   ziti_name: t_ziti_name,
+		   ziti_mobile: t_ziti_mobile
+		   **/
+		$order_msg_arr = explode('@,@', $order_msg_str);
+
+		$quan_arr = $data_s['quan_arr']; //商品订单留言
+
+		$order_quan_arr = array();
+
+
+		if (!empty($quan_arr)) {
+			if (!is_array($quan_arr)) {
+				$quan_arr = array($quan_arr);
+			}
+
+			foreach ($quan_arr as $q_val) {
+				$tmp_q = array();
+				$tmp_q = explode('_', $q_val);
+
+
+				$voucher_info = M('lionfish_comshop_coupon_list')->where("consume='N' and id=" . $tmp_q[1] . " and user_id=" . $member_id . " and end_time >" . time())->find();
+
+				if (!empty($voucher_info)) {
+					//$order_quan_arr[$tmp_q[0]] = $tmp_q[1];
+					$order_quan_arr[1] = $tmp_q[1];
+				}
+
+
+			}
+		}
+
+
+
+
+		$msg_arr = array();
+		foreach ($order_msg_arr as $val) {
+			$tmp_val = explode('@_@', $val);
+			$msg_arr[$tmp_val[0]] = $tmp_val[1];
+		}
+
+
+		$cart = D('Home/Car');
+
+		// 验证商品数量
+		//buy_type:buy_type
+		$buy_type = $data_s['buy_type']; //I('post.buy_type');
+
+
+		$is_pin = 0;
+		if ($buy_type == 'pintuan') {
+			$is_pin = 1;
+		}
+
+		$goodss = $cart->get_all_goodswecar($buy_type, $token, 1, $data_s['pick_up_id'], $data_s['soli_id']);
+		//付款人
+
+		$payment = M('lionfish_comshop_member')->where(array('member_id' => $member_id))->find();
+
+		//收货人
+		$addr_param = array();
+		$addr_param[':uniacid'] = $_W['uniacid'];
+		$addr_param[':member_id'] = $member_id;
+
+		//$addr_sql = "select * from ".tablename('lionfish_comshop_address')." where uniacid=:uniacid and member_id=:member_id order by  is_default desc,address_id desc limit 1";
+		//$address = pdo_fetch($addr_sql, $addr_param);
+
+		$seller_goodss = array();
+
+		/** 计算每个订单的优惠券占比begin */
+		$zanbi_total_money = 0;
+
+		//是否需要校验ticket 交易组件
+		$scene = $gpc['scene'];
+		$is_need_scene_check = 0;
+
+		if (!empty($scene)) {
+			$is_need_scene_check = D('Seller/MpModifyTradeComponts')->sceneCheck($scene);
+		}
+
+		foreach ($goodss as $key => $val) {
+			//单商户先屏蔽
+			//$goods_store_field =  M('goods')->field('store_id')->where( array('goods_id' => $val['goods_id']) )->find();
+
+			$supply_id = D('Home/Front')->get_goods_supply_id($val['goods_id']);
+			if ($supply_id > 0) {
+				$supply_info = D('Home/Front')->get_supply_info($supply_id);
+
+				if ($supply_info['type'] == 0) {
+					$supply_id = 0;
+				}
+			}
+
+			if ($data_s['dispatching'] == 'localtown_delivery') {
+				if ($supply_id > 0) {
+					$isopen_localtown_delivery = D('Home/Front')->get_supply_config_by_name('isopen_localtown_delivery', $supply_id);
+					if ($isopen_localtown_delivery == 1) {
+						//服务距离
+						$localtown_servvice_maxdistance = D('Home/Front')->get_supply_config_by_name('localtown_servvice_maxdistance', $supply_id);
+						//商家经纬度
+						$localtown_shop_lon = D('Home/Front')->get_supply_config_by_name('localtown_shop_lon', $supply_id);
+						$localtown_shop_lat = D('Home/Front')->get_supply_config_by_name('localtown_shop_lat', $supply_id);
+						$distince = D('Seller/Communityhead')->GetDistance($data_s['longitude'], $data_s['latitude'], $localtown_shop_lon, $localtown_shop_lat);
+						$distince = round($distince / 1000, 2);
+						if ($distince > $localtown_servvice_maxdistance) {
+							echo json_encode(array('code' => 2, 'msg' => '您与商家的距离过远,商家的配送范围是' . $localtown_servvice_maxdistance . 'KM内'));
+							die();
+						}
+					}
+				} else {
+					//服务距离
+					$localtown_servvice_maxdistance = D('Home/Front')->get_config_by_name('localtown_servvice_maxdistance');
+					//商家经纬度
+					$localtown_shop_lon = D('Home/Front')->get_config_by_name('localtown_shop_lon');
+					$localtown_shop_lat = D('Home/Front')->get_config_by_name('localtown_shop_lat');
+					$distince = D('Seller/Communityhead')->GetDistance($data_s['longitude'], $data_s['latitude'], $localtown_shop_lon, $localtown_shop_lat);
+					$distince = round($distince / 1000, 2);
+					if ($distince > $localtown_servvice_maxdistance) {
+						echo json_encode(array('code' => 2, 'msg' => '您与商家的距离过远,商家的配送范围是' . $localtown_servvice_maxdistance . 'KM内'));
+						die();
+					}
+				}
+
+			}
+
+			$seller_goodss[$supply_id][$key] = $val;
+
+			//$cart->removecar($val['key'],$token);
+
+
+			if ($is_vip_card_member == 1 && $val['is_take_vipcard'] == 1) {
+				$zanbi_total_money += $val['card_total'];
+			} else if ($val['is_mb_level_buy'] > 0 && $is_member_level_buy == 1) {
+				$zanbi_total_money += $val['level_total'];
+			} else if ($val['is_mb_level_buy'] == 1 && $member_info['level_id'] > 0) {
+				$zanbi_total_money += $val['level_total'];
+			} else {
+				$zanbi_total_money += $val['total'];
+			}
+
+			//检测是否场景符合begin
+			if ($is_need_scene_check == 1) {
+				if ($val['isTradeComponts'] == 0) {
+					echo json_encode(array('code' => 2, 'msg' => $val['name'] . ':未提交小程序交易组件'));
+					die();
+				}
+			}
+			//检测是否场景符合end
+		}
+
+		//判断是否可以货到付款
+		if ($cashon_delivery == 1) {
+			$cashondelivery_data = D('Home/Front')->getCashonDeliveryAction($buy_type, $seller_goodss);
+			if ($cashondelivery_data['isopen_cashondelivery'] == 1) {
+				if ($dispatching == 'express' && $cashondelivery_data['isopen_cashondelivery_express'] == 0) {
+					echo json_encode(array('code' => 3, 'msg' => '货到付款未开启'));
+					die();
+				} else if ($dispatching == 'tuanz_send' && $cashondelivery_data['isopen_cashondelivery_communityhead'] == 0) {
+					echo json_encode(array('code' => 3, 'msg' => '货到付款未开启'));
+					die();
+				} else if ($dispatching == 'localtown_delivery' && $cashondelivery_data['isopen_cashondelivery_localtown'] == 0) {
+					echo json_encode(array('code' => 3, 'msg' => '货到付款未开启'));
+					die();
+				} else if ($dispatching == 'hexiao' && $cashondelivery_data['isopen_cashondelivery_hexiao'] == 0) {
+					echo json_encode(array('code' => 3, 'msg' => '货到付款未开启'));
+					die();
+				} else if ($dispatching == 'pickup' && $cashondelivery_data['isopen_cashondelivery_ziti'] == 0) {
+					echo json_encode(array('code' => 3, 'msg' => '货到付款未开启'));
+					die();
+				}
+			} else {
+				echo json_encode(array('code' => 3, 'msg' => '货到付款未开启'));
+				die();
+			}
+		}
+
+		//....看看有没有满多少才能下单begin
+		$open_man_orderbuy = D('Home/Front')->get_config_by_name('open_man_orderbuy');
+		$man_orderbuy_money = D('Home/Front')->get_config_by_name('man_orderbuy_money');
+
+		//pindan (拼团商品单独购买)   pintuan (拼团)
+		if ($buy_type == 'pintuan' || $buy_type == 'pindan' || $buy_type == 'integral') {
+			$open_man_orderbuy = 0;
+		}
+
+		if (!empty($open_man_orderbuy) && $open_man_orderbuy == 1) {
+			if (!empty($man_orderbuy_money) && $man_orderbuy_money > 0) {
+				if ($man_orderbuy_money > $zanbi_total_money) {
+					echo json_encode(array('code' => 2, 'msg' => '满' . $man_orderbuy_money . '元才可以下单', 'is_forb' => 1));
+					die();
+				}
+			}
+		}
+		//....看看有没有满多少才能下单end
+		//清除购物车
+		foreach ($goodss as $key => $val) {
+			$cart->removecar($val['key'], $token);
+
+		}
+		/** 计算每个订单的优惠券占比end */
+
+		$pay_total = 0;
+		//M('order_all')
+
+
+		$order_all_data = array();
+		$order_all_data['member_id'] = $member_id;
+		$order_all_data['order_num_alias'] = build_order_no($member_id);
+		$order_all_data['transaction_id'] = '';
+		$order_all_data['order_status_id'] = 3;
+		$order_all_data['is_pin'] = $is_pin;
+		$order_all_data['paytime'] = 0;
+
+		$order_all_data['addtime'] = time();
+
+		$order_all_id = M('lionfish_comshop_order_all')->add($order_all_data);
+
+
+		//暂时屏蔽积分商城模块
+
+		$integral_model = D('Home/Integral');
+
+		$order_ids_arr = array();
+		$del_integral = 0;
+
+		if (($buy_type == 'pintuan' || $buy_type == 'pindan') && $pintuan_model_buy == 0) {
+			$community_info = array();
+			$community_detail_info = array();
+		} else if ($buy_type == 'integral') {
+			$community_info = array();
+			$community_detail_info = array();
+		} else if (($buy_type == 'pintuan' || $buy_type == 'pindan') && $pintuan_model_buy == 1) {
+			$community_info = M('lionfish_community_head')->where(array('id' => $data_s['pick_up_id']))->find();
+			$community_detail_info = D('Home/Front')->get_community_byid($data_s['pick_up_id']);
+		} else {
+			$community_info = M('lionfish_community_head')->where(array('id' => $data_s['pick_up_id']))->find();
+			$community_detail_info = D('Home/Front')->get_community_byid($data_s['pick_up_id']);
+		}
+
+
+
+		$address_info = M('lionfish_comshop_address')->where(array('address_id' => $data_s['address_id']))->find();
+
+
+		$is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
+		$full_money = D('Home/Front')->get_config_by_name('full_money');
+		$full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
+
+
+		$man_free_tuanzshipping = D('Home/Front')->get_config_by_name('man_free_tuanzshipping');
+		$man_free_shipping = D('Home/Front')->get_config_by_name('man_free_shipping');
+
+		if (empty($man_free_tuanzshipping)) {
+			$man_free_tuanzshipping = 0;
+		}
+
+		if (empty($man_free_shipping)) {
+			$man_free_shipping = 0;
+		}
+
+		if (empty($full_reducemoney) || $full_reducemoney <= 0) {
+			$is_open_fullreduction = 0;
+		}
+
+		if (($buy_type == 'pintuan' || $buy_type == 'pindan') && $pintuan_model_buy == 0) {
+			$man_free_tuanzshipping = 0;
+			$man_free_shipping = 0;
+			$is_open_fullreduction = 0;
+		} else if ($buy_type == 'integral') {
+			$man_free_tuanzshipping = 0;
+			$man_free_shipping = 0;
+			$is_open_fullreduction = 0;
+		} else if (($buy_type == 'pintuan' || $buy_type == 'pindan') && $pintuan_model_buy == 1) {
+			$man_free_shipping = 0;
+			$is_open_fullreduction = 0;
+		}
+		//预售不参与满减
+		if ($buy_type == 'presale') {
+			$man_free_tuanzshipping = 0;
+			$man_free_shipping = 0;
+			$is_open_fullreduction = 0;
+		}
+
+		$is_moban = false;
+
+
+		$cart = D('Home/Car');
+		$is_just_1 = 0;
+		$index_comment = 0;
+
+		$pay_goods_name = "";
+
+		$store_buy_total_money = 0;
+
+		$open_score_buy_score = D('Home/Front')->get_config_by_name('open_score_buy_score');
+
+		$score_for_money = 0; //use_score
+
+		if ($buy_type == 'integral') {
+			$open_score_buy_score = 0;
+		}
+
+		//预售不参与积分抵扣
+		if ($open_score_buy_score == 1 && $use_score == 1 && $payment['score'] > 0 && $buy_type != 'presale') {
+			//计算能兑换多少钱
+			$score_forbuy_money = D('Home/Front')->get_config_by_name('score_forbuy_money');
+			//只有兑换比例大于0才能允许兑换
+			if (!empty($score_forbuy_money) && $score_forbuy_money > 0) {
+				$score_for_money = sprintf('%.2f', $payment['score'] / $score_forbuy_money);
+			}
+		}
+
+
+
+		foreach ($seller_goodss as $kk => $vv) {
+			$is_just_1++;
+
+			$data = array();
+
+			$data['member_id'] = $member_id;
+			$data['name'] = $payment['username'];
+			$data['use_score'] = $use_score; //是否使用积分抵扣
+
+			$data['telephone'] = $data_s['ziti_mobile'];
+			$data['note_content'] = $data_s['note_content'];
+			$data['shipping_name'] = $data_s['ziti_name'];
+			$data['shipping_tel'] = $data_s['ziti_mobile'];
+
+
+			if ($dispatching == 'express' || $dispatching == 'tuanz_send' || $dispatching == 'localtown_delivery') {
+				$data['shipping_address'] = $address_info['address'];
+				$data['shipping_province_id'] = $address_info['province_id'];
+				$data['shipping_city_id'] = $address_info['city_id'];
+				$data['shipping_stree_id'] = 0;
+				$data['shipping_country_id'] = $address_info['country_id'];
+
+			} else {
+				$data['shipping_address'] = $community_detail_info['fullAddress'];
+				$data['shipping_province_id'] = $community_info['province_id'];
+				$data['shipping_city_id'] = $community_info['city_id'];
+				$data['shipping_stree_id'] = $community_info['country_id'];
+				$data['shipping_country_id'] = $community_info['area_id'];
+			}
+
+
+			$data['shipping_method'] = 0;
+			$data['delivery'] = $dispatching;
+			$data['pick_up_id'] = $pick_up_id;
+
+			$data['ziti_name'] = $community_info['head_name'];
+			$data['ziti_mobile'] = $community_info['head_mobile'];
+
+
+			$data['payment_method'] = $pay_method;
+
+			$data['address_id'] = $data_s['address_id'];
+			$data['voucher_id'] = isset($order_quan_arr[1]) ? $order_quan_arr[1] : 0; //目前都是平台券
+
+
+			$data['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
+			$data['date_added'] = time();
+
+			$subject = '';
+			$fare = 0;
+			$order_total = 0;
+
+
+			$trans_free_toal = 0; //运费
+
+			$is_localtown_free_shipping_fare = 0;
+			$localtown_shipping_fare_total = 0; //同城配送费
+			$localtown_free_shipping_fare = 0; //满减的同城配送费用
+
+			$reduce_money = 0;
+
+			$man_total_free = 0;
+			$score_buy_money = 0;
+
+			$is_lottery = 0;
+			$is_integral = 0;
+			$is_spike = 0;
+			$is_hexiao = 0;
+
+			$total_weight = 0;
+			$total_quantity = 0;
+
+			$redis_has_add_list = array();
+
+			$is_free_shipping_fare = 0; //是否免除运费
+
+			$order_goods_total_money = 0;
+			$goods_data = array();
+
+			$is_moban = false;
+			//comment_arr comment_arr
+
+
+			$packing_fare = 0;
+			$iscan_fu_packing = 1;
+
+			if ('localtown_delivery' == $dispatching) {
+
+				$tmp_sellergd = array($kk => array('goods' => $vv));
+
+				$town_address = M('lionfish_comshop_address')->where(array('address_id' => $data_s['address_id']))->find();
+
+				list($lon, $lat) = explode(",", $town_address['lon_lat']);
+
+				$localtown_shippingfare_arr = D('Home/LocaltownDelivery')->calc_shipping_fare($lon, $lat, $tmp_sellergd);
+
+				$trans_free_toal = $localtown_shippingfare_arr['total_shipping_fare'];
+
+				$localtown_shipping_fare_total = $trans_free_toal;
+
+				$packing_fare_arr = D('Home/LocaltownDelivery')->calc_packing_money(array($kk => array('goods' => $vv)));
+
+				$packing_fare = $packing_fare_arr['total_picking_fare'];
+
+				$localtown_shipping_fare = $localtown_shippingfare_arr['total_shipping_fare'];
+				$localtown_yl_shipping_fare = $localtown_shippingfare_arr['total_yl_shipping_fare'];
+				if ($localtown_shipping_fare != $localtown_yl_shipping_fare && $localtown_shipping_fare == 0) {
+					$is_localtown_free_shipping_fare = 1;
+					$localtown_free_shipping_fare = $localtown_shippingfare_arr['total_yl_shipping_fare'];
+				}
+
+				$data['localtown_add_shipping_fare'] = $localtown_shippingfare_arr[$kk]['localtown_add_shipping_fare'];
+			}
+
+			$data['expected_delivery_time'] = $data_s['expected_delivery_time'];
+			$data['packing_fare'] = floatval($packing_fare);
+
+			foreach ($vv as $key => $good) {
+
+				if ($kk == 0) {
+					if ($is_vip_card_member == 1 && $good['is_take_vipcard'] == 1) {
+						$store_buy_total_money += $good['card_total'];
+					} else if ($good['is_mb_level_buy'] == 1 && $member_info['level_id'] > 0) {
+						$store_buy_total_money += $good['level_total'];
+					} else {
+						$store_buy_total_money += $good['total'];
+					}
+
+				}
+				/**
+						 if($good['shipping']==1)
+						 {
+							 //统一运费
+							 $trans_free_toal += $good['goods_freight'];
+							 $trans_free = $good['goods_freight'];
+						 }else {
+							 //运费模板
+							 $trans_free = load_model_class('transport')->calc_transport($good['transport_id'], $good['quantity'], $good['quantity']*$good['weight'], $address['city_id'] );
+							 
+							 //$trans_free = D('Home/Transport')->calc_transport($good['transport_id'], $good['quantity']*$good['weight'], $address['city_id'] );
+							 $trans_free_toal +=$trans_free;
+						 }
+						 **/
+				$trans_free = 0;
+				//$trans_free_toal +=$trans_free;
+				//sku_str 
+
+				if ($is_vip_card_member == 1 && $good['is_take_vipcard'] == 1) {
+					$order_goods_total_money += $good['card_total'];
+					$order_total += $good['card_total'];
+				} else if ($good['is_mb_level_buy'] == 1 && $member_info['level_id'] > 0) {
+					$order_goods_total_money += $good['level_total'];
+					$order_total += $good['level_total'];
+				} else {
+					$order_goods_total_money += $good['total'];
+					$order_total += $good['total'];
+				}
+
+				$tp_goods_info = M('lionfish_comshop_goods')->field('type')->where(array('id' => $good['goods_id']))->find();
+
+				$tp_goods_info['store_id'] = 1;
+
+				if ($tp_goods_info['type'] == 'lottery') {
+					$is_lottery = 1;
+				}
+				if ($tp_goods_info['type'] == 'spike') {
+					$is_spike = 1;
+					$is_pin = 0;
+				}
+				//暂时屏蔽积分商城模块
+
+				if ($tp_goods_info['type'] == 'integral') {
+					$is_integral = 1;
+					$is_pin = 0;
+					$check_result = $integral_model->check_user_score_can_pay($member_id, $good['sku_str'], $good['goods_id']);
+					if ($check_result['code'] == 1) {
+						echo json_encode(array('code' => 2, 'msg' => '剩余' . $check_result['cur_score'] . '积分,积分不足!', 'is_forb' => 1));
+						die();
+					}
+
+				}
+
+				//is_hexiao is_only_express
+				if ($good['is_only_express'] == 2) {
+					$is_hexiao = 2;
+					$is_pin = 0;
+				}
+
+				if ($good['shipping'] == 0) {
+					$is_moban = true;
+					//统一运费
+					$total_weight += $good['weight'] * $good['quantity'];
+					$total_quantity += $good['quantity'];
+				}
+
+				$fenbi_li = 1;
+				if ($zanbi_total_money > 0) {
+					if ($is_vip_card_member == 1 && $good['is_take_vipcard'] == 1) {
+						$fenbi_li = round($good['card_total'] / $zanbi_total_money, 2);
+					} else if ($good['is_mb_level_buy'] == 1 && $member_info['level_id'] > 0) {
+						$fenbi_li = round($good['level_total'] / $zanbi_total_money, 2);
+					} else {
+						$fenbi_li = round($good['total'] / $zanbi_total_money, 2);
+					}
+				}
+
+				//if( isset($comment_arr[$index_comment]) )
+				//{
+				//	$comment = $comment_arr[$index_comment];
+
+				//}
+
+				//$good['goods_id']
+				if (isset($comment_arr)) {
+					foreach ($comment_arr as $key => $var) {
+						if ($good['goods_id'] == $key) {
+							$comment = $var;
+						}
+
+					}
+				}
+
+
+				//监测库存数量
+				$quantity_flag = D('Seller/Redisorder')->check_goods_can_buy($good['goods_id'], $good['sku_str'], $good['quantity']);
+				if ($quantity_flag <= 0) {
+					if (!empty($redis_has_add_list)) {
+						D('Seller/Redisorder')->bu_car_has_delquantity($redis_has_add_list);
+					}
+					echo json_encode(array('code' => 2, 'msg' => '已抢光', 'is_forb' => 1));
+					die();
+				}
+				//如果是下单减库存,那么用占坑法来避免超库存---begin
+				$kucun_method = D('Home/Front')->get_config_by_name('kucun_method');
+
+				if (empty($kucun_method)) {
+					$kucun_method = 0;
+				}
+
+				if ($kucun_method == 0) {
+					//$ret = $redis->rPush('city', 'guangzhou');
+					$check_redis_quantity = D('Seller/Redisorder')->add_goods_buy_user($good['goods_id'], $good['sku_str'], $good['quantity'], $member_id);
+					//注意要回滚
+
+					//$key = "user_goods_{$member_id}_{$goods_id}_{$sku_str}";
+
+					if ($check_redis_quantity == 0) {
+						//cancle_redis_user_list 
+						if (!empty($redis_has_add_list)) {
+							D('Seller/Redisorder')->bu_car_has_delquantity($redis_has_add_list);
+						}
+
+						echo json_encode(array('code' => 2, 'msg' => '已抢光', 'is_forb' => 1));
+						die();
+					}
+
+					$redis_has_add_list[] = array('member_id' => $member_id, 'goods_id' => $good['goods_id'], 'sku_str' => $good['sku_str'], 'quantity' => $good['quantity']);
+
+				}
+				//----------------redis   end
+				if ($good['can_man_jian'] == 1) {
+					//$man_total_free += $good['total'];
+
+					//begggg
+
+					if ($is_vip_card_member == 1 && $good['is_take_vipcard'] == 1) {
+
+						if ($good['can_man_jian'] == 1) {
+							$man_total_free += $good['card_total'];
+
+						}
+					} else if ($good['is_mb_level_buy'] == 1 && $member_info['level_id'] > 0) {
+						if ($good['can_man_jian'] == 1) {
+							$man_total_free += $good['level_total'];
+						}
+					} else {
+						if ($good['can_man_jian'] == 1) {
+							$man_total_free += $good['total'];
+
+						}
+					}
+
+					//eddddd
+
+				}
+
+				$pay_goods_name .= $good['name'];
+
+				if ($good['is_mb_level_buy'] == 1 && $is_vip_card_member == 0 && $member_info['level_id'] > 0) {
+					$good['is_mb_level_buy'] == 1;
+				} else {
+					$good['is_mb_level_buy'] == 0;
+				}
+
+				$localtown_superposition_pickingmoney = 0;
+				$localtown_superposition_pickingmoney = isset($localtown_superposition_pickingmoney) ? $localtown_superposition_pickingmoney : 0;
+
+				$gd_packing_fare = 0;
+
+				if ($localtown_superposition_pickingmoney == 0) {
+					$gd_packing_fare = $good['packing_free'];
+				} else {
+					if ($packing_fare == $good['packing_free'] && $iscan_fu_packing == 1) {
+						$iscan_fu_packing = 0;
+						$gd_packing_fare = $good['packing_free'];
+					}
+				}
+
+				$goods_data[] = array(
+					'goods_id' => $good['goods_id'],
+					'store_id' => $tp_goods_info['store_id'],
+					'name' => $good['name'],
+					'model' => $good['model'],
+					'is_pin' => $is_pin,
+					'pin_id' => $good['pin_id'],
+					'header_disc' => $good['header_disc'],
+					'member_disc' => $good['member_disc'],
+					'level_name' => $good['level_name'],
+					'option' => $good['sku_str'] == 'undefined' ? '' : $good['sku_str'],
+					'quantity' => $good['quantity'],
+					'shipping_fare' => $trans_free,
+					'price' => $good['price'],
+					'costprice' => $good['costprice'],
+					'card_price' => $good['card_price'],
+					'levelprice' => $good['levelprice'],
+					'total' => $good['total'],
+					'packing_fare' => $gd_packing_fare,
+					'card_total' => $good['card_total'],
+					'level_total' => $good['level_total'],
+					'is_mb_level_buy' => $good['is_mb_level_buy'],
+					'is_take_vipcard' => $good['is_take_vipcard'],
+					'fenbi_li' => $fenbi_li,
+					'can_man_jian' => $good['can_man_jian'],
+					'soli_id' => $good['soli_id'],
+					'comment' => htmlspecialchars($comment)
+				);
+
+			}
+
+			$index_comment++;
+			//$total_weight = 0;
+			//$total_quantity = 0;
+
+			if ($dispatching == 'express') {
+				//结算运费新模式
+				$trans_free_toal = 0; //运费
+
+				//----开始计算运费
+
+				//ims_ 
+
+				$shipping_default = M('lionfish_comshop_shipping')->where("enabled=1")->order('isdefault desc,id desc')->find();
+
+				$seller_goodss_re = $seller_goodss;
+
+
+
+				$store_shipping_fare = 0;
+				if ($is_moban) {
+					$store_shipping_fare = D('Home/Transport')->calc_transport($shipping_default['id'], $total_quantity, $total_weight, $address_info['city_id']);
+
+
+				}
+
+				$trans_free_toal += $store_shipping_fare;
+
+				foreach ($vv as $kkc => $d_goods) {
+					if ($d_goods['shipping'] == 1) {
+						//统一运费
+						$trans_free_toal += $d_goods['goods_freight'];
+
+					}
+				}
+
+
+				if ($kk == 0 && !empty($man_free_shipping) && $man_free_shipping > 0 && $order_goods_total_money >= $man_free_shipping) {
+
+					//$trans_free_toal = 0;
+					$is_free_shipping_fare = 1;
+				}
+
+				//---结束结算运费 address_id
+
+				$data_s['address_id'] = $this->_add_address($token, $ziti_name, $ziti_mobile, $province_name, $city_name, $country_name, $address_name);
+			} else if ('tuanz_send' == $dispatching) {
+				$trans_free_toal = 0;
+				$delivery_tuanz_money = D('Home/Front')->get_config_by_name('delivery_tuanz_money');
+
+
+				$community_info_modify = $community_info;
+
+				if (!empty($community_info_modify['is_modify_shipping_method']) && $community_info_modify['is_modify_shipping_method'] == 1) {
+					if (!empty($community_info_modify['is_modify_shipping_fare']) && $community_info_modify['is_modify_shipping_fare'] == 1 && $community_info_modify['shipping_fare'] > 0) {
+						$delivery_tuanz_money = $community_info_modify['shipping_fare'];
+					}
+				}
+
+
+				$trans_free_toal = $delivery_tuanz_money;
+
+				$data['tuan_send_address'] = $data_s['tuan_send_address'];
+
+				if ($kk == 0 && !empty($man_free_tuanzshipping) && $man_free_tuanzshipping > 0 && $order_goods_total_money >= $man_free_tuanzshipping) {
+					$is_free_shipping_fare = 1;
+					//$trans_free_toal = 0;
+				}
+			}
+
+
+
+
+			//$is_pin; is_lottery
+			//'pintuan', 'normal', 'lottery'
+			$data['type'] = 'normal';
+			if ($is_pin == 1) {
+				$data['type'] = 'pintuan';
+				if ($is_lottery == 1) {
+					$data['type'] = 'lottery';
+				}
+			}
+			if ($is_integral == 1) {
+				$data['type'] = 'integral';
+				$is_pin = 0;
+			}
+
+			if ($is_hexiao == 1) {
+				$data['type'] = 'virtual';
+				$is_pin = 0;
+			}
+
+
+			if ($is_spike == 1) {
+				$data['type'] = 'spike';
+				$is_pin = 0;
+			}
+
+			//礼品卡配送费0
+			if ($buy_type == 'virtualcard') {
+				$trans_free_toal = 0;
+			}
+
+			$data['shipping_fare'] = floatval($trans_free_toal);
+
+			if ($is_free_shipping_fare == 1) {
+				$trans_free_toal = 0;
+			}
+
+			//原先计算满减金额
+			/*if($is_open_fullreduction == 1 && $man_total_free >= $full_money )
+				  {
+					  $reduce_money = $full_reducemoney ;
+				  }*/
+			//多组满减金额计算
+			if ($is_open_fullreduction == 1) {
+				$reduce_result = D('Home/Front')->get_reduce_money($man_total_free);
+				$reduce_money = $reduce_result['reduce_money'];
+			}
+
+			$data['is_free_shipping_fare'] = $is_free_shipping_fare;
+			$data['store_id'] = $kk;
+			$data['order_goods_total_money'] = $order_goods_total_money;
+
+			$data['is_localtown_free_shipping_fare'] = $is_localtown_free_shipping_fare;
+			$data['localtown_free_shipping_fare'] = $localtown_free_shipping_fare;
+
+			$data['goodss'] = $goods_data;
+			$data['order_num_alias'] = build_order_no($member_id);
+
+			$data['totals'][0] = array(
+				'code' => 'sub_total',
+				'title' => '商品价格',
+				'text' => '¥' . $order_total,
+				'value' => $order_total
+			);
+			$data['totals'][1] = array(
+				'code' => 'shipping',
+				'title' => '运费',
+				'text' => '¥' . $trans_free_toal,
+				'value' => $trans_free_toal
+			);
+
+			$data['totals'][2] = array(
+				'code' => 'total',
+				'title' => '总价',
+				'text' => '¥' . ($order_total + $trans_free_toal - $reduce_money),
+				'value' => ($order_total + $trans_free_toal - $reduce_money)
+			);
+
+			$data['from_type'] = 'wepro';
+
+			//目前都是平台券
+			if ($data['voucher_id'] > 0) {
+
+				//暂时屏蔽优惠券,等待开启 
+				/**
+						 $voucher_info = pdo_fetch("select * from ".tablename('lionfish_comshop_coupon_list')." where uniacid=:uniacid and id=:id ", 
+												 array(':uniacid' => $_W['uniacid'],':id' => $data['voucher_id']));
+						 
+						 $data['voucher_credit'] = $voucher_info['credit'];
+						 
+						 pdo_update('lionfish_comshop_coupon_list', array('ordersn' => $data['order_num_alias'],'consume' => 'Y','usetime' => time()), array('id' => $data['voucher_id'] ));
+						 **/
+
+				$voucher_info = M('lionfish_comshop_coupon_list')->where(array('id' => $data['voucher_id']))->find();
+				//检查优惠券指定商品或指定商品分类 优惠金额 begin
+				$voucher_list[0] = $voucher_info;
+
+				$voucher_list = D('Home/Voucher')->get_voucher_amout_bygoods($voucher_list, $goods_data, 0);
+
+				$voucher_info = $voucher_list[0];
+				//检查优惠券指定商品或指定商品分类 优惠金额 end
+				$data['voucher_credit'] = $voucher_info['can_vouche_amount'];
+
+				$bili = 1;
+
+				if ($zanbi_total_money > 0) {
+					$bili = round(($order_goods_total_money / $zanbi_total_money), 2);
+				}
+				$data['voucher_credit'] = $data['voucher_credit'] * $bili;
+
+
+				//判断是否超出订单商品金额,不算运费
+				//if($data['voucher_credit'] > $order_total+$trans_free_toal - $reduce_money )
+				if ($data['voucher_credit'] > $order_total - $reduce_money) {
+					$data['voucher_credit'] = $order_total - $reduce_money;
+				}
+
+
+				M('lionfish_comshop_coupon_list')->where(array('id' => $data['voucher_id']))->save(array('ordersn' => $data['order_num_alias'], 'consume' => 'Y', 'usetime' => time()));
+
+			} else {
+				$data['voucher_credit'] = 0;
+			}
+
+			$use_score_total = 0; //用掉用户多少积分了.
+			$data['score_for_money'] = 0;
+
+			if ($kk == 0 && $score_for_money > 0) {
+
+
+
+				if ($order_total + $trans_free_toal - $reduce_money - $data['voucher_credit'] <= 0) {
+					//没必要扣积分了,单价已经是0
+				} else {
+					//只能抵扣扣除优惠券部分的金额
+					$del_money = $order_total - $data['voucher_credit'] - $reduce_money;
+
+					//var_dump($del_money, $score_for_money);die();
+
+					//score_for_money 会员能抵扣的最大金额
+
+
+
+					//计算多少积分了。
+
+					$score_forbuy_money_maxbi = D('Home/Front')->get_config_by_name('score_forbuy_money_maxbi');
+					$score_forbuy_money = D('Home/Front')->get_config_by_name('score_forbuy_money');
+
+					if (empty($score_forbuy_money_maxbi)) {
+						$score_forbuy_money_maxbi = 100;
+					}
+
+					//$max_dikou_money =  sprintf('%.2f', ($del_money * $score_forbuy_money_maxbi) /100);
+					$max_dikou_score = floor($del_money * $score_forbuy_money_maxbi * $score_forbuy_money / 100);
+					$max_dikou_money = sprintf('%.2f', ($max_dikou_score / $score_forbuy_money));
+					if ($max_dikou_money < $score_for_money) {
+						$score_for_money = $max_dikou_money;
+					}
+					//$score_buy_money = 0;
+					$data['score_for_money'] = $score_for_money;
+					//TODO...扣除会员积分,将积分分拆入每个商品订单,写入日志
+
+					//var_dump($data['score_for_money'], $max_dikou_money);die();
+				}
+			}
+
+
+			$data['comment'] = htmlspecialchars($comment);
+
+			$data['reduce_money'] = $reduce_money;
+
+			$data['man_total_free'] = $man_total_free;
+
+			//判断自提 dispatching:"pickup"
+			//dispatching, //express  pickup
+
+			if ($dispatching == 'express') {
+				$data['total'] = ($order_total); //+$fare - $data['voucher_credit']
+			} else if ('tuanz_send' == $dispatching) {
+				$data['total'] = ($order_total); // - $data['voucher_credit']);
+			} else {
+				$data['total'] = ($order_total); // - $data['voucher_credit']
+			}
+			//积分商城
+			//暂时屏蔽积分商城模块
+
+
+			if ($data['type'] == 'integral') {
+				$del_integral += $order_total; //扣除积分
+				$data['total'] = $order_total;
+
+			}
+			$data['buy_type'] = $buy_type; //判断预售使用
+			//万能表单数据
+			$data['allform_id'] = $allform_id;
+			$data['allform_list'] = $allform_list;
+
+			$oid = D('Home/Frontorder')->addOrder($data); // D('Order')->addOrder($data);
+
+
+
+			//暂时屏蔽自提模块
+			/**
+				  if($data['delivery'] == 'pickup')
+				  {
+					  $verify_bool = true;
+					  $verifycode = 0;
+					  while($verify_bool)
+					  {
+						  $code  = (ceil(time()/100)+rand(10000000,40000000)).rand(1000,9999);
+						  $verifycode = $code ? $code : rand(100000,999999);
+						  $verifycode = str_replace('1989','9819',$verifycode);
+						  $verifycode = str_replace('1259','9521',$verifycode);
+						  $verifycode = str_replace('12590','95210',$verifycode);
+						  $verifycode = str_replace('10086','68001',$verifycode);
+						  
+						  $pick_order = M('pick_order')->where( array('pick_sn' => $verifycode) )->find();
+						  if(empty($pick_order))
+						  {
+							  $verify_bool = false;
+						  }
+					  }
+					  $pick_data = array();
+					  $pick_data['pick_sn'] = $verifycode;
+					  $pick_data['pick_id'] = $pick_up_id;
+					  $pick_data['order_id'] = $oid;
+					  $pick_data['state'] = 0;
+					  
+					  $pick_data['ziti_name'] = $ziti_name;
+					  $pick_data['ziti_mobile'] = $ziti_mobile;
+					  
+				  
+					  $pick_data['addtime'] = time();
+					  M('pick_order')->add($pick_data);
+				  }
+				  **/
+
+			$order_ids_arr[] = $oid;
+			//$pay_total = $pay_total + $order_total+$trans_free_toal - $data['voucher_credit'];
+			if ($dispatching == 'express' && $data['type'] != 'integral') {
+				$pay_total = $pay_total + $order_total + $trans_free_toal - $data['voucher_credit'] - $reduce_money - $data['score_for_money'];
+			} else if ($dispatching == 'express' && $data['type'] == 'integral') {
+				$pay_total = $trans_free_toal;
+			} else if ('localtown_delivery' == $dispatching) {
+				$pay_total = $pay_total + $order_total + $packing_fare + $trans_free_toal - $data['voucher_credit'] - $reduce_money - $data['score_for_money'] + $data['localtown_add_shipping_fare'];
+			} else if ('tuanz_send' == $dispatching) {
+				$pay_total = $pay_total + $order_total + $trans_free_toal - $data['voucher_credit'] - $reduce_money - $data['score_for_money'];
+			} else {
+				$pay_total = $pay_total + $order_total - $data['voucher_credit'] - $reduce_money - $data['score_for_money'];
+			}
+
+
+			if ($buy_type == 'presale') {
+				//如果是预售,此处支付的就是定金
+				$presale_order_info = M('lionfish_comshop_order_presale')->where(['order_id' => $oid])->find();
+				if ($presale_order_info['presale_type'] == 1) {
+					M('lionfish_comshop_order_presale')->where(['id' => $presale_order_info['id']])->save(['presale_ding_money' => $pay_total]);
+				} else {
+					$pay_total = $presale_order_info['presale_ding_money'];
+				}
+			}
+
+			$pay_total = round($pay_total, 2);
+
+			$order_relate_data = array();
+
+			$order_relate_data['order_all_id'] = $order_all_id;
+			$order_relate_data['order_id'] = $oid;
+			$order_relate_data['addtime'] = time();
+
+			M('lionfish_comshop_order_relate')->add($order_relate_data);
+
+		}
+
+		$order_all_data = array();
+		$order_all_data['total_money'] = $pay_total;
+
+		M('lionfish_comshop_order_all')->where(array('id' => $order_all_id))->save($order_all_data);
+
+		if ($order_all_id) {
+
+			$order = M('lionfish_comshop_order')->where(array('order_id' => $oid))->find();
+
+			$member_info = M('lionfish_comshop_member')->field('we_openid,account_money')->where(array('member_id' => $member_id))->find();
+
+			$is_yue_open = 0;
+
+			$is_yue_open = D('Home/Front')->get_config_by_name('is_open_yue_pay');
+			if (empty($is_yue_open)) {
+				$is_yue_open = 0;
+			}
+
+			//检测是否需要扣除积分
+			if ($data['type'] == 'integral' && $del_integral > 0 && $is_integral == 1) {
+
+				$order_goods_tp = M('lionfish_comshop_order_goods')->field('order_goods_id')->where(array('order_id' => $oid))->find();
+
+				D('Admin/Member')->sendMemberPointChange($member_id, $del_integral, 1, '积分兑换商品', 'integral_exchange', $oid, $order_goods_tp['order_goods_id']);
+			}
+
+			$is_open_yinpay = D('Home/Front')->get_config_by_name('is_open_yinpay');
+			$shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
+			if ($order['type'] == 'ignore' || $pay_total <= 0 || ($is_yue_open == 1 && $ck_yupay == 1 && $member_info['account_money'] >= $pay_total)) {
+				//余额支付独立方法
+				D('Home/OrderV2')->carOrderYuerPay($order_all_id, $order, $pay_total, $ck_yupay, $buy_type, $is_integral, $is_spike, $is_just_1);
+			} else if ($buy_type == 'dan' && $cashon_delivery == 1) { //货到付款订单
+				//货到付款支付独立方法
+				D('Home/OrderV2')->carOrderCashonPay($order_all_id, $order, $pay_total, $cashon_delivery, $buy_type, $is_spike, $is_just_1);
+			} else if ($ck_yupay == 3) {
+				$lib_path = dirname(dirname(dirname(__FILE__))) . '/Lib/';
+				require_once $lib_path . "/Weixin/Wxfy.class.php";
+				$wxfy = new \Wxfy();
+				$appid = D('Home/Front')->get_config_by_name('wepro_appid');
+				$notify_url = $shop_domain . '/notify.php?type=fyfyfy';
+				$out_trade_no = $order_all_id . '-' . time();
+				$body = $pay_goods_name; //'商品购买';
+				if (empty($body) || mb_strlen($body)>30) {
+					$body = '购物车商品合并支付';
+				}
+				// $body=iconv('GB2312', 'UTF-8', $body);
+			
+				$nonce_str = nonce_str();
+				$fee = $pay_total;
+				$total_fee = $fee * 100;
+				$wxfydata=array();
+				$wxfydata['debug'] = false;
+				$wxfydata['filepath'] = $lib_path . 'Weixin/cert/';
+				$prefix = 1450;
+				$wxfydata['mchnt_order_no'] = $prefix . $out_trade_no; //商户订单号, 商户系统内部的订单号(5 到 30 个字符、 只能包含字母数字,区分大小写)
+				$wxfydata['random_str'] = $nonce_str;
+				$wxfydata['goods_des'] = $body;
+				$wxfydata['term_ip'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
+				$wxfydata['order_amt'] = $total_fee;
+				$wxfydata['notify_url'] = $notify_url;
+				$wxfydata['sub_openid'] = $payment['we_openid'];
+				$wxfydata['sub_appid'] = $appid;
+			//	$wxfydata['debug'] = true;
+
+				$resfult = $wxfy->createOrder($wxfydata);
+			//	$res = json_decode($resfult, 1);
+
+				M('lionfish_comshop_order_all')->where(array('id' => $order_all_id))->save(array('out_trade_no' => $out_trade_no));
+
+				
+					D('Home/Pin')->insertNotifyOrder($order['order_id']);
+					$time = time();
+
+//					$prepay_id = $res['session_id'];
+
+
+//					M('lionfish_comshop_order')->where(array('order_id' => array('in', $order_ids_arr)))->save(array('perpay_id' => $prepay_id));
+
+
+
+					$data = array();
+					$data['code'] = 0;
+//					$data['appid'] = $res['sdk_appid'];
+//					$data['timeStamp'] = $res['sdk_timestamp'];
+//					$data['nonceStr'] = $res['sdk_noncestr'];
+//					$data['signType'] = $res['sdk_signtype'];
+//					$data['package'] = 'prepay_id=' .$prepay_id;
+//					$data['paySign'] = $res['sdk_paysign'];
+					$data['out_trade_no'] = $out_trade_no;
+					//$data['total_fee']=
+					$data['is_go_orderlist'] = $is_just_1;
+                    $data['xml'] = $resfult;
+					$data['total_fee']=$total_fee;
+					//如果是微信小程序交易组件begin---新支付方法 wx.requestOrderPayment
+					$data['order_info'] = [];
+					$data['isRequestOrderPayment'] = $is_need_scene_check;
+
+
+
+					if ($is_pin == 1) {
+						$data['redirect_url'] = '../groups/group?id=' . $oid . '&is_show=1';
+					} else {
+						$data['redirect_url'] = '../orders/order_show_all?order_all_id=' + $order_all_id;
+					}
+
+				
+
+
+			} else if (isset($is_open_yinpay) && $is_open_yinpay == 3) {
+				//begin
+
+				$fee = $pay_total;
+				$appid = D('Home/Front')->get_config_by_name('wepro_appid');
+
+				$body = $pay_goods_name; //'商品购买';
+
+				$body = mb_substr($body, 0, 32, 'utf-8');
+
+				if (empty($body)) {
+					$body = '商品购买';
+				}
+
+				$mch_id = D('Home/Front')->get_config_by_name('wepro_partnerid');
+				$nonce_str = nonce_str();
+
+
+				$shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
+
+				$notify_url = $shop_domain . '/notify.php';
+
+
+				$openid = $payment['we_openid'];
+				$out_trade_no = $order_all_id . '-' . time();
+
+				//out_trade_no
+				M('lionfish_comshop_order_all')->where(array('id' => $order_all_id))->save(array('out_trade_no' => $out_trade_no));
+
+
+				$spbill_create_ip = $_SERVER['REMOTE_ADDR'];
+				$total_fee = $fee * 100;
+
+
+				//float(0.99999999999998)
+				$trade_type = 'JSAPI';
+				$pay_key = D('Home/Front')->get_config_by_name('wepro_key');
+
+				$post['appid'] = D('Home/Front')->get_config_by_name('wepro_fuwu_appid'); // 'wx7c38e2f177e0af59';
+				$post['body'] = $body;
+				$post['mch_id'] = D('Home/Front')->get_config_by_name('wepro_fuwu_partnerid'); //'1562705521';
+
+
+
+				$post['nonce_str'] = $nonce_str;
+				$post['notify_url'] = $notify_url;
+
+				//$post['openid'] = $openid;
+				$post['out_trade_no'] = $out_trade_no;
+				$post['spbill_create_ip'] = $spbill_create_ip;
+				$post['sub_appid'] = $appid;
+				$post['sub_mch_id'] = D('Home/Front')->get_config_by_name('wepro_sub_mch_id');
+				$post['sub_openid'] = $openid;
+
+				$post['total_fee'] = $total_fee;
+				$post['trade_type'] = $trade_type;
+				$sign = sign($post, $pay_key);
+
+				//var_dump( $notify_url );die();
+
+				$post_xml = '<xml>
+				   <appid>' . $post['appid'] . '</appid>
+				   <body>' . $body . '</body>
+				   <mch_id>' . $post['mch_id'] . '</mch_id>
+				   <nonce_str>' . $nonce_str . '</nonce_str>
+				   <notify_url>' . $notify_url . '</notify_url>
+				   
+				   <out_trade_no>' . $out_trade_no . '</out_trade_no>
+				   <spbill_create_ip>' . $spbill_create_ip . '</spbill_create_ip>
+				   <sub_appid>' . $post['sub_appid'] . '</sub_appid>
+				   <sub_mch_id>' . $post['sub_mch_id'] . '</sub_mch_id>
+				   <sub_openid>' . $openid . '</sub_openid>
+				   <total_fee>' . $total_fee . '</total_fee>
+				   <trade_type>' . $trade_type . '</trade_type>
+				   <sign>' . $sign . '</sign>
+				</xml> ';
+				$url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
+				$xml = http_request($url, $post_xml);
+				$array = xml($xml);
+
+				if ($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS') {
+
+					D('Home/Pin')->insertNotifyOrder($order['order_id']);
+
+					$time = time();
+					$tmp = array();
+					$tmp['appId'] = $appid;
+					$tmp['nonceStr'] = $nonce_str;
+					$tmp['package'] = 'prepay_id=' . $array['PREPAY_ID'];
+					$tmp['signType'] = 'MD5';
+					$tmp['timeStamp'] = "$time";
+
+					$prepay_id = (string) $array['PREPAY_ID'];
+
+
+					M('lionfish_comshop_order')->where(array('order_id' => array('in', $order_ids_arr)))->save(array('perpay_id' => $prepay_id));
+
+
+
+
+					//M('order')->where( array('order_id' => array('in',$order_ids_arr) ) )->save( array('perpay_id' => (string)$array['PREPAY_ID']) );
+					$data = array();
+					$data['code'] = 0;
+					$data['appid'] = $appid;
+					$data['timeStamp'] = "$time";
+					$data['nonceStr'] = $nonce_str;
+					$data['signType'] = 'MD5';
+					$data['package'] = 'prepay_id=' . $array['PREPAY_ID'];
+					$data['paySign'] = sign($tmp, $pay_key);
+					$data['out_trade_no'] = $out_trade_no;
+
+					$data['is_go_orderlist'] = $is_just_1;
+
+
+
+					if ($is_pin == 1) {
+						$data['redirect_url'] = '../groups/group?id=' . $oid . '&is_show=1';
+					} else {
+						$data['redirect_url'] = '../orders/order_show_all?order_all_id=' + $order_all_id;
+					}
+
+				} else {
+					$data = array();
+					$data['code'] = 1;
+					$data['text'] = "错误";
+					$data['RETURN_CODE'] = $array['RETURN_CODE'];
+					$data['RETURN_MSG'] = $array['RETURN_MSG'];
+				}
+				$data['has_yupay'] = 0;
+
+				//end
+			} else {
+
+				$fee = $pay_total;
+				$appid = D('Home/Front')->get_config_by_name('wepro_appid');
+
+				$body = $pay_goods_name; //'商品购买';
+
+				$body = mb_substr($body, 0, 32, 'utf-8');
+
+				if (empty($body)) {
+					$body = '商品购买';
+				}
+
+
+				$mch_id = D('Home/Front')->get_config_by_name('wepro_partnerid');
+
+			
+
+				$nonce_str = nonce_str();
+				$notify_url = $shop_domain . '/notify.php';
+
+
+				$openid = $payment['we_openid'];
+				$out_trade_no = $order_all_id . '-' . time();
+
+				//out_trade_no 
+				M('lionfish_comshop_order_all')->where(array('id' => $order_all_id))->save(array('out_trade_no' => $out_trade_no));
+
+
+				$spbill_create_ip = $_SERVER['REMOTE_ADDR'];
+				$total_fee = $fee * 100;
+				$trade_type = 'JSAPI';
+				$pay_key = D('Home/Front')->get_config_by_name('wepro_key');
+
+				$post['appid'] = $appid;
+				$post['body'] = $body;
+				$post['mch_id'] = $mch_id;
+				$post['nonce_str'] = $nonce_str;
+				$post['notify_url'] = $notify_url;
+
+				$post['openid'] = $openid;
+				$post['out_trade_no'] = $out_trade_no;
+				$post['spbill_create_ip'] = $spbill_create_ip;
+				$post['total_fee'] = $total_fee;
+				$post['trade_type'] = $trade_type;
+				$sign = sign($post, $pay_key);
+
+
+				$post_xml = '<xml>
+				   <appid>' . $appid . '</appid>
+				   <body>' . $body . '</body>
+				   <mch_id>' . $mch_id . '</mch_id>
+				   <nonce_str>' . $nonce_str . '</nonce_str>
+				   <notify_url>' . $notify_url . '</notify_url>
+				   <openid>' . $openid . '</openid>
+				   <out_trade_no>' . $out_trade_no . '</out_trade_no>
+				   <spbill_create_ip>' . $spbill_create_ip . '</spbill_create_ip>
+				   <total_fee>' . $total_fee . '</total_fee>
+				   <trade_type>' . $trade_type . '</trade_type>
+				   <sign>' . $sign . '</sign>
+				</xml> ';
+				$url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
+				$xml = http_request($url, $post_xml);
+				$array = xml($xml);
+
+				if ($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS') {
+					D('Home/Pin')->insertNotifyOrder($order['order_id']);
+					$time = time();
+					$tmp = array();
+					$tmp['appId'] = $appid;
+					$tmp['nonceStr'] = $nonce_str;
+					$tmp['package'] = 'prepay_id=' . $array['PREPAY_ID'];
+					$tmp['signType'] = 'MD5';
+					$tmp['timeStamp'] = "$time";
+
+					$prepay_id = (string) $array['PREPAY_ID'];
+
+
+					M('lionfish_comshop_order')->where(array('order_id' => array('in', $order_ids_arr)))->save(array('perpay_id' => $prepay_id));
+
+
+
+					//M('order')->where( array('order_id' => array('in',$order_ids_arr) ) )->save( array('perpay_id' => (string)$array['PREPAY_ID']) );
+					$data = array();
+					$data['code'] = 0;
+					$data['appid'] = $appid;
+					$data['timeStamp'] = "$time";
+					$data['nonceStr'] = $nonce_str;
+					$data['signType'] = 'MD5';
+					$data['package'] = 'prepay_id=' . $array['PREPAY_ID'];
+					$data['paySign'] = sign($tmp, $pay_key);
+					$data['out_trade_no'] = $out_trade_no;
+
+					$data['is_go_orderlist'] = $is_just_1;
+
+					//如果是微信小程序交易组件begin---新支付方法 wx.requestOrderPayment
+					$data['order_info'] = [];
+					$data['isRequestOrderPayment'] = $is_need_scene_check;
+					if ($is_need_scene_check == 1) {
+						$orderPamentResult = D('Seller/MpModifyTradeComponts')->getTradeOrderInfo($oid, $time, $pay_total);
+						//如果是微信小程序交易组件,提供订单信息 end
+						$data['order_info'] = $orderPamentResult['order_info'];
+					}
+
+
+					if ($is_pin == 1) {
+						$data['redirect_url'] = '../groups/group?id=' . $oid . '&is_show=1';
+					} else {
+						$data['redirect_url'] = '../orders/order_show_all?order_all_id=' + $order_all_id;
+					}
+
+				} else {
+					$data = array();
+					$data['code'] = 1;
+					$data['text'] = "错误";
+					$data['RETURN_CODE'] = $array['RETURN_CODE'];
+					$data['RETURN_MSG'] = $array['RETURN_MSG'];
+				}
+				$data['has_yupay'] = 0;
+			}
+
+			if ($is_pin == 1) {
+				$data['order_id'] = $oid;
+				$data['order_all_id'] = $order_all_id;
+			} else {
+				$data['order_id'] = $oid;
+				$data['order_all_id'] = $order_all_id;
+			}
+			$data['is_go_orderlist'] = $is_just_1;
+
+			$data['is_spike'] = $is_spike;
+			echo json_encode($data);
+			die();
+		} else {
+			echo json_encode(array('code' => 1, 'order_all_id' => $order_all_id));
+			die();
+		}
+
+	}
+
+	function requestAsHttpPOST($data, $service_url)
+	{
+		$HTTP_TIME_OUT = "20";
+		ksort(array_filter($data)); //删除数组中的空值并排序
+		$post_data = http_build_query($data);
+
+		$options = array(
+			'http' => array(
+				'method' => 'POST',
+				'header' => 'Content-type:application/x-www-form-urlencoded;charset=MD5',
+				'content' => $post_data,
+				'timeout' => $HTTP_TIME_OUT * 1000 //超时时间,*1000将毫秒变为秒(单位:s)
+			)
+		);
+		$context = stream_context_create($options);
+		$result = file_get_contents($service_url, false, $context);
+		return $result;
+	}
+
+
+	/**
+		   微信充值
+	   **/
+	public function wxcharge()
+	{
+		$_GPC = I('request.');
+
+		$token = $_GPC['token'];
+		$pay_method=$_GPC['pay_method']=='fypay'?$_GPC['pay_method']:"";
+
+		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where(array('token' => $token))->find();
+
+		$member_id = $weprogram_token['member_id'];
+
+		if (empty($member_id)) {
+			echo json_encode(array('code' => 1, 'msg' => '未登录'));
+			die();
+		}
+
+		$money = $_GPC['money'];
+
+		$rech_id = isset($_GPC['rech_id']) && $_GPC['rech_id'] > 0 ? $_GPC['rech_id'] : 0;
+
+		$member_info = M('lionfish_comshop_member')->field('we_openid')->where(array('member_id' => $member_id))->find();
+
+		$give_money = 0;
+
+		if ($rech_id > 0) {
+			$rech_info = M('lionfish_comshop_chargetype')->where(array('id' => $rech_id))->find();
+
+			if (!empty($rech_info)) {
+				$give_money = $rech_info['send_money'];
+			}
+
+			$money = $rech_info['money'];
+		} else {
+			$recharge_get_money = D('Home/Front')->get_config_by_name('recharge_get_money');
+
+			if (isset($recharge_get_money) && $recharge_get_money == 1) {
+				$rech_info = M('lionfish_comshop_chargetype')->where("money <= " . $money)->order('money desc')->limit(1)->find();
+
+				if (!empty($rech_info)) {
+					$give_money = $rech_info['send_money'];
+				}
+			}
+
+		}
+
+
+
+		$member_charge_flow_data = array();
+		$member_charge_flow_data['member_id'] = $member_id;
+		$member_charge_flow_data['money'] = $money;
+		$member_charge_flow_data['state'] = 0;
+		$member_charge_flow_data['give_money'] = $give_money;
+		$member_charge_flow_data['charge_time'] = 0;
+		$member_charge_flow_data['remark'] = '会员前台微信充值';
+		$member_charge_flow_data['add_time'] = time();
+
+		$order_id = M('lionfish_comshop_member_charge_flow')->add($member_charge_flow_data);
+
+
+		$shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
+
+
+
+
+
+		$fee = $money;
+		$appid = D('Home/Front')->get_config_by_name('wepro_appid');
+		$body = '会员充值';
+		$mch_id = D('Home/Front')->get_config_by_name('wepro_partnerid');
+		$nonce_str = nonce_str();
+		$notify_url = $shop_domain . '/notify.php';
+		$openid = $member_info['we_openid'];
+		$out_trade_no = $order_id . '-' . time() . '-charge-' . $member_id;
+		$spbill_create_ip = $_SERVER['REMOTE_ADDR'];
+		$total_fee = $fee * 100;
+
+		$is_open_yinpay = D('Home/Front')->get_config_by_name('is_open_yinpay');
+		if($pay_method=='fypay'){
+
+			$lib_path = dirname(dirname(dirname(__FILE__))) . '/Lib/';
+			require_once $lib_path . "/Weixin/Wxfy.class.php";
+			$wxfy = new \Wxfy();
+			
+			$notify_url = $shop_domain . '/notify.php?type=fyfyfy';
+	
+
+			$nonce_str = nonce_str();
+			$wxfydata=array();
+			$wxfydata['debug'] = false;
+			$wxfydata['filepath'] = $lib_path . 'Weixin/cert/';
+			$prefix = 1450;
+			$wxfydata['mchnt_order_no'] = $prefix . $out_trade_no; //商户订单号, 商户系统内部的订单号(5 到 30 个字符、 只能包含字母数字,区分大小写)
+			$wxfydata['random_str'] = $nonce_str;
+			$wxfydata['goods_des'] = base64_encode($body);
+			$wxfydata['term_ip'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
+			$wxfydata['order_amt'] = $total_fee;
+			$wxfydata['notify_url'] = $notify_url;
+			$wxfydata['sub_openid'] = $member_info['we_openid'];
+			$wxfydata['sub_appid'] = $appid;
+			
+			$resfult = $wxfy->createOrder($wxfydata);
+//			$fy_res = json_decode($resfult, 1);
+			
+		
+			if (false) {
+				$json = array();
+
+				$json['code'] = 2;
+				$json['msg'] = 'error:'.$fy_res['result_msg'];
+				echo json_encode($json);
+				die();
+			}
+
+		//	$prepay_id =(string)$fy_res['session_id'];
+
+			$data = array();
+			$data['code'] = 0;
+//			$data['appid'] = $fy_res['sdk_appid'];
+//			$data['timeStamp'] = $fy_res['sdk_timestamp'];
+//			$data['nonceStr'] = $fy_res['sdk_noncestr'];
+//			$data['signType'] = $fy_res['sdk_signtype'];
+//			$data['package'] = 'prepay_id=' .$prepay_id;
+//			$data['paySign'] = $fy_res['sdk_paysign'];
+			$data['out_trade_no'] = $out_trade_no;
+            $data['xml'] = $resfult;
+			$data['pay_method']='fypay';
+			$data['total_fee'] =$total_fee;
+//			M('lionfish_comshop_member_charge_flow')->where(array('id' => $order_id))->save(array('formid' => $prepay_id));
+			$data['redirect_url'] = '../dan/me';
+			echo json_encode($data);
+			die();
+
+		}else if (isset($is_open_yinpay) && $is_open_yinpay == 3) {
+
+			$trade_type = 'JSAPI';
+			$pay_key = D('Home/Front')->get_config_by_name('wepro_key');
+			$post = array();
+			$post['appid'] = D('Home/Front')->get_config_by_name('wepro_fuwu_appid'); // 'wx7c38e2f177e0af59';
+			$post['body'] = $body;
+			$post['mch_id'] = D('Home/Front')->get_config_by_name('wepro_fuwu_partnerid'); //'1562705521';
+			$post['nonce_str'] = $nonce_str;
+			$post['notify_url'] = $notify_url;
+			//$post['openid'] = $openid;
+			$post['out_trade_no'] = $out_trade_no;
+			$post['spbill_create_ip'] = $spbill_create_ip;
+			$post['sub_appid'] = $appid;
+			$post['sub_mch_id'] = D('Home/Front')->get_config_by_name('wepro_sub_mch_id');
+			$post['sub_openid'] = $openid;
+			$post['total_fee'] = $total_fee;
+			$post['trade_type'] = $trade_type;
+			$sign = sign($post, $pay_key);
+
+
+			$post_xml = '<xml>
+				   <appid>' . $post['appid'] . '</appid>
+				   <body>' . $body . '</body>
+				   <mch_id>' . $post['mch_id'] . '</mch_id>
+				   <nonce_str>' . $nonce_str . '</nonce_str>
+				   <notify_url>' . $notify_url . '</notify_url>
+				   
+				   <out_trade_no>' . $out_trade_no . '</out_trade_no>
+				   <spbill_create_ip>' . $spbill_create_ip . '</spbill_create_ip>
+				   <sub_appid>' . $post['sub_appid'] . '</sub_appid>
+				   <sub_mch_id>' . $post['sub_mch_id'] . '</sub_mch_id>
+				   <sub_openid>' . $openid . '</sub_openid>
+				   <total_fee>' . $total_fee . '</total_fee>
+				   <trade_type>' . $trade_type . '</trade_type>
+				   <sign>' . $sign . '</sign>
+				</xml> ';
+			$url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
+			$xml = http_request($url, $post_xml);
+			$array = xml($xml);
+
+			//end
+		} else {
+
+			$trade_type = 'JSAPI';
+			$pay_key = D('Home/Front')->get_config_by_name('wepro_key');
+
+			$post = array();
+
+			$post['appid'] = $appid;
+			$post['body'] = $body;
+			$post['mch_id'] = $mch_id;
+			$post['nonce_str'] = $nonce_str;
+			$post['notify_url'] = $notify_url;
+			$post['openid'] = $openid;
+			$post['out_trade_no'] = $out_trade_no;
+			$post['spbill_create_ip'] = $spbill_create_ip;
+			$post['total_fee'] = $total_fee;
+			$post['trade_type'] = $trade_type;
+
+			$sign = sign($post, $pay_key);
+
+			//sign()
+			$post_xml = '<xml>
+				   <appid>' . $appid . '</appid>
+				   <body>' . $body . '</body>
+				   <mch_id>' . $mch_id . '</mch_id>
+				   <nonce_str>' . $nonce_str . '</nonce_str>
+				   <notify_url>' . $notify_url . '</notify_url>
+				   <openid>' . $openid . '</openid>
+				   <out_trade_no>' . $out_trade_no . '</out_trade_no>
+				   <spbill_create_ip>' . $spbill_create_ip . '</spbill_create_ip>
+				   <total_fee>' . $total_fee . '</total_fee>
+				   <trade_type>' . $trade_type . '</trade_type>
+				   <sign>' . $sign . '</sign>
+				</xml> ';
+			$url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
+			$xml = http_request($url, $post_xml);
+			$array = xml($xml);
+		}
+
+
+
+
+		if ($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS') {
+			$time = time();
+			$tmp = array();
+			$tmp['appId'] = $appid;
+			$tmp['nonceStr'] = $nonce_str;
+			$tmp['package'] = 'prepay_id=' . $array['PREPAY_ID'];
+			$tmp['signType'] = 'MD5';
+			$tmp['timeStamp'] = "$time";
+
+			M('lionfish_comshop_member_charge_flow')->where(array('id' => $order_id))->save(array('formid' => $array['PREPAY_ID']));
+
+			$data['code'] = 0;
+			$data['timeStamp'] = "$time";
+			$data['nonceStr'] = $nonce_str;
+			$data['signType'] = 'MD5';
+			$data['package'] = 'prepay_id=' . $array['PREPAY_ID'];
+			$data['paySign'] = sign($tmp, $pay_key);
+			$data['out_trade_no'] = $out_trade_no;
+
+			$data['redirect_url'] = '../dan/me';
+
+		} else {
+			$data['code'] = 1;
+			$data['text'] = "错误";
+			$data['RETURN_CODE'] = $array['RETURN_CODE'];
+			$data['RETURN_MSG'] = $array['RETURN_MSG'];
+		}
+
+
+
+		echo json_encode($data);
+		die();
+
+	}
+
+
+	public function wxpay()
+	{
+		$gpc = I('request.');
+
+		$token = $gpc['token'];
+		$order_id = $gpc['order_id'];
+		$pay_method=$gpc['pay_method']=='fypay'?$gpc['pay_method']:"";
+		$scene = $gpc['scene'];
+		$is_need_scene_check = 0;
+
+		if (!empty($scene)) {
+			$is_need_scene_check = D('Seller/MpModifyTradeComponts')->sceneCheck($scene);
+		}
+
+		$weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where(array('token' => $token))->find();
+
+
+		$member_id = $weprogram_token['member_id'];
+
+
+		if (empty($member_id)) {
+			echo json_encode(array('code' => 1, 'msg' => '未登录'));
+			die();
+		}
+
+
+		$member_info = M('lionfish_comshop_member')->field('we_openid')->where(array('member_id' => $member_id))->find();
+
+
+		$order = M('lionfish_comshop_order')->where(array('order_id' => $order_id))->find();
+
+
+		//order_status_id
+
+		if ($order['order_status_id'] != 3 && $order['order_status_id'] != 15) {
+			$json = array();
+
+			$json['msg'] = '商品已下架!';
+			$json['code'] = 2;
+			if ($order['order_status_id'] == 1) {
+				$json['msg'] = '订单已付款,请勿重新付款!';
+			} else if ($order['order_status_id'] == 5) {
+				$json['msg'] = '订单已取消,请重新选择商品下单!';
+			}
+			echo json_encode($json);
+			die();
+		}
+
+
+
+		//检测商品是否下架 begin
+		$sql = "select name,quantity,rela_goodsoption_valueid,goods_id from " . C('DB_PREFIX') . "lionfish_comshop_order_goods  
+					where order_id={$order_id} ";
+
+		$order_goods_list = M()->query($sql);
+		$goodsname="";
+		foreach ($order_goods_list as $tp_val) {
+			$tp_gd_info = M('lionfish_comshop_goods')->field('grounding')->where(array('id' => $tp_val['goods_id']))->find();
+
+			if (empty($tp_gd_info) || $tp_gd_info['grounding'] != 1) {
+				$json['code'] = 2;
+
+				$json['msg'] = '商品已下架!';
+
+				echo json_encode($json);
+				die();
+			}
+			$goodsname.=$tp_val['name'];
+		}
+
+		//检测商品是否下架end   
+		//检测是否预售商品。预售商品不需要检测二次支付问题
+		$presale_info = [];
+		$presale_result = D('Home/PresaleGoods')->getOrderPresaleInfo($order_id);
+		if ($presale_result['code'] == 0) {
+			$presale_info = $presale_result['data'];
+		}
+		//检测是否已经支付过了begin
+
+		$order_relate_info = M('lionfish_comshop_order_relate')->where(array('order_id' => $order_id))->order('id desc')->find();
+
+		if (!empty($order_relate_info) && $order_relate_info['order_all_id'] > 0 && empty($presale_info)) {
+			
+			$order_all_info = M('lionfish_comshop_order_all')->where(array('id' => $order_relate_info['order_all_id']))->find();
+				
+			if (!empty($order_all_info) && !empty($order_all_info['out_trade_no'])) {
+					
+				$out_trade_no = $order_all_info['out_trade_no'];
+
+				$appid = D('Home/Front')->get_config_by_name('wepro_appid');
+				$mch_id = D('Home/Front')->get_config_by_name('wepro_partnerid');
+				$nonce_str = nonce_str();
+
+				$pay_key = D('Home/Front')->get_config_by_name('wepro_key');
+
+
+				$post = array();
+				
+				if($pay_method=='fypay'){
+				
+					//富友支付,写下去了
+
+
+				}else{
+					//主要是校验是否重复支付
+					$post['appid'] = $appid;
+					$post['mch_id'] = $mch_id;
+					$post['nonce_str'] = $nonce_str;
+					$post['out_trade_no'] = $out_trade_no;
+
+					$sign = sign($post, $pay_key);
+
+					$post_xml = '<xml>
+								<appid>' . $appid . '</appid>
+								<mch_id>' . $mch_id . '</mch_id>
+								<nonce_str>' . $nonce_str . '</nonce_str>
+								<out_trade_no>' . $out_trade_no . '</out_trade_no>
+								<sign>' . $sign . '</sign>
+								</xml>';
+
+					$url = "https://api.mch.weixin.qq.com/pay/orderquery";
+
+					$result = http_request($url, $post_xml);
+
+					$array = xml($result);
+
+					if ($array['RETURN_CODE'] == 'SUCCESS' && $array['RETURN_MSG'] == 'OK') {
+						if ($array['TRADE_STATE'] == 'SUCCESS') {
+							$json = array();
+
+							$json['msg'] = '商品已下架!';
+							$json['code'] = 2;
+							$json['msg'] = '订单已付款,请勿重新付款,请刷新页面!';
+							echo json_encode($json);
+							die();
+						}
+					}
+				}
+			}
+		}
+
+		//检测是否已经支付过了end  
+
+		//支付才减库存,才需要判断
+		$kucun_method = D('Home/Front')->get_config_by_name('kucun_method');
+
+		if (empty($kucun_method)) {
+			$kucun_method = 0;
+		}
+
+		if ($kucun_method == 1 && (empty($presale_info) || $presale_info['state'] != 1)) {
+			/*** 检测商品库存begin  **/
+
+			//goods_id
+			foreach ($order_goods_list as $val) {
+				$quantity = $val['quantity'];
+
+				$goods_id = $val['goods_id'];
+
+				$can_buy_count = D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
+
+				$goods_description = D('Home/Front')->get_goods_common_field($goods_id, 'total_limit_count');
+
+				if ($can_buy_count == -1) {
+					$json['code'] = 2;
+
+					$json['msg'] = '您还能购买' . $goods_description['total_limit_count'] . '个';
+
+					echo json_encode($json);
+					die();
+				} else if ($can_buy_count > 0 && $quantity > $can_buy_count) {
+					$json['code'] = 2;
+					$json['msg'] = '您还能购买' . $can_buy_count . '份';
+					echo json_encode($json);
+					die();
+				}
+				//rela_goodsoption_valueid
+				if (!empty($val['rela_goodsoption_valueid'])) {
+					$mul_opt_arr = array();
+
+					//ims_ 
+
+					$goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->where(array('goods_id' => $goods_id, 'option_item_ids' => $val['rela_goodsoption_valueid']))->find();
+
+
+					if (!empty($goods_option_mult_value)) {
+						if ($goods_option_mult_value['stock'] < $quantity) {
+							$json['code'] = 2;
+							$json['msg'] = '商品数量不足,剩余' . $goods_option_mult_value['stock'] . '个!!';
+							echo json_encode($json);
+							die();
+						}
+					}
+				}
+
+			}
+			/*** 检测商品库存end **/
+		}
+
+		$pin_order = array();
+		if (!empty($pin_order)) {
+			/**
+					 $pin_model =  load_model_class('pin');
+					 $is_pin_over = $pin_model->getNowPinState($pin_order['pin_id']);
+					 if($is_pin_over != 0)
+					 {
+						  pdo_query("delete from ".tablename('lionfish_comshop_pin_order')." where order_id = {$order_id} ");
+						  
+						  pdo_query("delete from ".tablename('lionfish_comshop_pin')." where pin_id = ".$pin_order['pin_id']." and order_id = ".$order_id);
+						  
+						 $order_goods_info = pdo_fetch("select goods_id from ".tablename('lionfish_comshop_order_goods')." where uniacid=:uniacid and order_id=:order_id ", array(':order_id' => $order_id,':uniacid' => $_W['uniacid']));
+						 
+						 //新开团
+						 
+						 $pin_id = $pin_model->openNewTuan($order_id,$order_goods_info['goods_id'],$member_id);
+						 //插入拼团订单
+						 $pin_model->insertTuanOrder($pin_id,$order_id);
+							
+					 }
+					 **/
+		}
+
+
+		//单独支付一个店铺的订单
+		//M('lionfish_comshop_order_relate')->where( array('order_id' => $order_id) )->delete();
+
+		$order_all_data = array();
+		$order_all_data['member_id'] = $member_id;
+		$order_all_data['order_num_alias'] = build_order_no($member_id);
+		$order_all_data['transaction_id'] = '';
+		$order_all_data['order_status_id'] = 3;
+		$order_all_data['is_pin'] = $order['is_pin'];
+		$order_all_data['paytime'] = 0;
+		$order_all_data['total_money'] = $order['total'] + $order['shipping_fare'] - $order['voucher_credit'] - $order['fullreduction_money'];
+		$order_all_data['addtime'] = time();
+
+		$order_all_id = M('lionfish_comshop_order_all')->add($order_all_data);
+
+		$order_relate_data = array();
+		$order_relate_data['order_all_id'] = $order_all_id;
+		$order_relate_data['order_id'] = $order_id;
+		$order_relate_data['addtime'] = time();
+
+		M('lionfish_comshop_order_relate')->add($order_relate_data);
+
+		if ($order['delivery'] == 'pickup') {
+			$fee = $order['total'] + $order['shipping_fare'] - $order['voucher_credit'] - $order['fullreduction_money'] - $order['score_for_money'] - $order['fare_shipping_free'];
+		} else if ($order['delivery'] == 'localtown_delivery') {
+			$fee = $order['total'] + $order['packing_fare'] + $order['shipping_fare'] - $order['voucher_credit'] - $order['fullreduction_money'] - $order['score_for_money'] + $order['localtown_add_shipping_fare'] - $order['fare_shipping_free'];
+		} else {
+			$fee = $order['total'] + $order['shipping_fare'] - $order['voucher_credit'] - $order['fullreduction_money'] - $order['score_for_money'] - $order['fare_shipping_free'];
+		}
+
+		//如果是预售 begin
+
+		if (!empty($presale_info)) {
+			if ($presale_info['state'] == 0) {
+				//首次支付,
+				$fee = $presale_info['presale_ding_money'];
+			} else if ($presale_info['state'] == 1) {
+				//第二次支付
+				if (!empty($presale_info['presale_deduction_money']) && false) {
+					$fee = $fee - $presale_info['presale_deduction_money'];
+				} else {
+					$fee = $fee - $presale_info['presale_ding_money'];
+				}
+			}
+		}
+		//end
+
+
+		$fee = round($fee, 2);
+
+
+		$appid = D('Home/Front')->get_config_by_name('wepro_appid');
+
+
+		$body = $pay_goods_name; //'商品购买';
+
+		$body = mb_substr($body, 0, 32, 'utf-8');
+
+		if (empty($body)) {
+			$body = '商品购买';
+		}
+
+
+		$mch_id = D('Home/Front')->get_config_by_name('wepro_partnerid');
+		$nonce_str = nonce_str();
+
+		$shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
+
+		$notify_url = $shop_domain . '/notify.php';
+
+		$openid = $member_info['we_openid'];
+		
+		$spbill_create_ip = $_SERVER['REMOTE_ADDR'];
+		$total_fee = $fee * 100;
+		$trade_type = 'JSAPI';
+		$pay_key = D('Home/Front')->get_config_by_name('wepro_key');
+		$out_trade_no = $order_all_id . '-' . time();
+
+		$is_open_yinpay = D('Home/Front')->get_config_by_name('is_open_yinpay');
+		
+		$appid = D('Home/Front')->get_config_by_name('wepro_appid');
+		//begin
+
+		if($pay_method=='fypay'){
+		//富友支付
+			$shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
+			$lib_path = dirname(dirname(dirname(__FILE__))) . '/Lib/';
+			require_once $lib_path . "/Weixin/Wxfy.class.php";
+			$wxfy = new \Wxfy();
+			
+			$notify_url = $shop_domain . '/notify.php?type=fyfyfy';
+			$body = $goodsname; //'商品购买';
+	
+			
+			if (empty($body) || mb_strlen($body)>30) {
+				$body = '购物车商品合并支付';
+			}
+		
+			// $body=iconv('GB2312', 'UTF-8', $body);
+
+			//富友一个订单号只能拉起一次支付,所以这里要改
+			M('lionfish_comshop_order_all')->where(array('id' => $order_all_id))->save(array('out_trade_no' => $out_trade_no));
+			$nonce_str = nonce_str();
+			$wxfydata=array();
+			$wxfydata['debug'] = false;
+			$wxfydata['filepath'] = $lib_path . 'Weixin/cert/';
+			$prefix = 1450;
+			$wxfydata['mchnt_order_no'] = $prefix . $out_trade_no; //商户订单号, 商户系统内部的订单号(5 到 30 个字符、 只能包含字母数字,区分大小写)
+			$wxfydata['random_str'] = $nonce_str;
+			$wxfydata['goods_des'] = $body;
+			$wxfydata['term_ip'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
+			$wxfydata['order_amt'] = $total_fee;
+			$wxfydata['notify_url'] = $notify_url;
+			$wxfydata['sub_openid'] = $member_info['we_openid'];
+			$wxfydata['sub_appid'] = $appid;
+			
+			$resfult = $wxfy->createOrder($wxfydata);
+		//	$fy_res = json_decode($resfult, 1);
+			
+		
+			if (false) {
+				$json = array();
+
+				$json['code'] = 2;
+				$json['msg'] = 'error:'.$fy_res['result_msg'];
+				echo json_encode($json);
+				die();
+			}
+
+			//$prepay_id =(string)$fy_res['session_id'];
+					
+
+			//M('lionfish_comshop_order')->where(array('order_id' => $order_id))->save(array('perpay_id' => $prepay_id));
+
+
+
+			$data = array();
+			$data['code'] = 0;
+		//	$data['appid'] = $fy_res['sdk_appid'];
+		//	$data['timeStamp'] = $fy_res['sdk_timestamp'];
+		//	$data['nonceStr'] = $fy_res['sdk_noncestr'];
+			//$data['signType'] = $fy_res['sdk_signtype'];
+		//	$data['package'] = 'prepay_id=' .$prepay_id;
+		//	$data['paySign'] = $fy_res['sdk_paysign'];
+			$data['out_trade_no'] = $out_trade_no;
+			$data['xml'] = $resfult;
+			$data['total_fee'] = $total_fee;
+			$data['pay_method'] = 'fypay';
+			if ($order['is_pin'] == 1) {
+				$data['redirect_url'] = '../groups/group?id=' . $order_id . '&is_show=1';
+			} else {
+				$data['redirect_url'] = '../orders/order?id=' + $order_id;
+			}
+			echo json_encode($data);
+			die();
+		}
+		elseif (isset($is_open_yinpay) && $is_open_yinpay == 3) {
+			
+			$pay_key = D('Home/Front')->get_config_by_name('wepro_key');
+
+			$body = '商品购买';
+
+			$post = array();
+
+			$post['appid'] =D('Home/Front')->get_config_by_name('wepro_fuwu_appid');
+			$post['body'] = $body;
+			$post['mch_id'] = D('Home/Front')->get_config_by_name('wepro_fuwu_partnerid');
+			$post['nonce_str'] = $nonce_str;
+			$post['notify_url'] = $notify_url;
+			//$post['openid'] = $openid;
+			$post['out_trade_no'] = $out_trade_no;
+			$post['spbill_create_ip'] = $spbill_create_ip;
+			$post['sub_appid'] = D('Home/Front')->get_config_by_name('wepro_appid');
+			$post['sub_mch_id'] = D('Home/Front')->get_config_by_name('wepro_sub_mch_id');
+			$post['sub_openid'] = $openid;
+
+			$post['total_fee'] = $total_fee;
+			$post['trade_type'] = $trade_type;
+			$sign = sign($post, $pay_key);
+
+			$post_xml = '<xml>
+				   <appid>' . $post['appid'] . '</appid>
+				   <body>' . $body . '</body>
+				   <mch_id>' . $post['mch_id'] . '</mch_id>
+				   <nonce_str>' . $nonce_str . '</nonce_str>
+				   <notify_url>' . $notify_url . '</notify_url>
+				   
+				   <out_trade_no>' . $out_trade_no . '</out_trade_no>
+				   <spbill_create_ip>' . $spbill_create_ip . '</spbill_create_ip>
+				   <sub_appid>' . $post['sub_appid'] . '</sub_appid>
+				   <sub_mch_id>' . $post['sub_mch_id'] . '</sub_mch_id>
+				   <sub_openid>' . $openid . '</sub_openid>
+				   <total_fee>' . $total_fee . '</total_fee>
+				   <trade_type>' . $trade_type . '</trade_type>
+				   <sign>' . $sign . '</sign>
+				</xml>';
+
+
+			$url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
+			$xml = http_request($url, $post_xml);
+			$array = xml($xml);
+
+			if ($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS') {
+				$time = time();
+				$tmp = array();
+				$tmp['appId'] = $appid;
+				$tmp['nonceStr'] = $nonce_str;
+				$tmp['package'] = 'prepay_id=' . $array['PREPAY_ID'];
+				$tmp['signType'] = 'MD5';
+				$tmp['timeStamp'] = "$time";
+
+				$prepay_id = (string) $array['PREPAY_ID'];
+
+				M('lionfish_comshop_order')->where(array('order_id' => $order_id))->save(array('perpay_id' => $prepay_id));
+
+
+				$data['code'] = 0;
+				$data['timeStamp'] = "$time";
+				$data['nonceStr'] = $nonce_str;
+				$data['signType'] = 'MD5';
+				$data['package'] = 'prepay_id=' . $array['PREPAY_ID'];
+				$data['paySign'] = sign($tmp, $pay_key);
+				$data['out_trade_no'] = $out_trade_no;
+				$data['is_pin'] = $order['is_pin'];
+
+				if ($order['is_pin'] == 1) {
+					$data['redirect_url'] = '../groups/group?id=' . $order_id . '&is_show=1';
+				} else {
+					$data['redirect_url'] = '../orders/order?id=' + $order_id;
+				}
+
+			} else {
+				$data['code'] = 1;
+				$data['text'] = "错误";
+				$data['RETURN_CODE'] = $array['RETURN_CODE'];
+				$data['RETURN_MSG'] = $array['RETURN_MSG'];
+			}
+
+
+			echo json_encode($data);
+			die();
+		}else{
+			$json = array();
+
+				$json['code'] = 2;
+				$json['msg'] = '没有支付方式';
+				echo json_encode($json);
+				die();
+		}
+
+		//end
+
+		$post = array();
+		$post['appid'] = $appid;
+		$post['body'] = $body;
+		$post['mch_id'] = $mch_id;
+		$post['nonce_str'] = $nonce_str;
+		$post['notify_url'] = $notify_url;
+		$post['openid'] = $openid;
+		$post['out_trade_no'] = $out_trade_no;
+		$post['spbill_create_ip'] = $spbill_create_ip;
+		$post['total_fee'] = $total_fee;
+		$post['trade_type'] = $trade_type;
+		$sign = sign($post, $pay_key);
+
+
+		$post_xml = '<xml>
+			   <appid>' . $appid . '</appid>
+			   <body>' . $body . '</body>
+			   <mch_id>' . $mch_id . '</mch_id>
+			   <nonce_str>' . $nonce_str . '</nonce_str>
+			   <notify_url>' . $notify_url . '</notify_url>
+			   <openid>' . $openid . '</openid>
+			   <out_trade_no>' . $out_trade_no . '</out_trade_no>
+			   <spbill_create_ip>' . $spbill_create_ip . '</spbill_create_ip>
+			   <total_fee>' . $total_fee . '</total_fee>
+			   <trade_type>' . $trade_type . '</trade_type>
+			   <sign>' . $sign . '</sign>
+			</xml> ';
+		$url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
+		$xml = http_request($url, $post_xml);
+		$array = xml($xml);
+		if ($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS') {
+			$time = time();
+			$tmp = array();
+			$tmp['appId'] = $appid;
+			$tmp['nonceStr'] = $nonce_str;
+			$tmp['package'] = 'prepay_id=' . $array['PREPAY_ID'];
+			$tmp['signType'] = 'MD5';
+			$tmp['timeStamp'] = "$time";
+
+			$prepay_id = (string) $array['PREPAY_ID'];
+
+			M('lionfish_comshop_order')->where(array('order_id' => $order_id))->save(array('perpay_id' => $prepay_id));
+
+
+			$data['code'] = 0;
+			$data['timeStamp'] = "$time";
+			$data['nonceStr'] = $nonce_str;
+			$data['signType'] = 'MD5';
+			$data['package'] = 'prepay_id=' . $array['PREPAY_ID'];
+			$data['paySign'] = sign($tmp, $pay_key);
+			$data['out_trade_no'] = $out_trade_no;
+			$data['is_pin'] = $order['is_pin'];
+
+			//如果是微信小程序交易组件begin---新支付方法 wx.requestOrderPayment
+			$data['order_info'] = [];
+			$data['isRequestOrderPayment'] = $is_need_scene_check;
+			if ($is_need_scene_check == 1) {
+				$orderPamentResult = D('Seller/MpModifyTradeComponts')->getTradeOrderInfo($order_id, $time, $fee);
+				//如果是微信小程序交易组件,提供订单信息 end
+				$data['order_info'] = $orderPamentResult['order_info'];
+			}
+
+			if ($order['is_pin'] == 1) {
+				$data['redirect_url'] = '../groups/group?id=' . $order_id . '&is_show=1';
+			} else {
+				$data['redirect_url'] = '../orders/order?id=' + $order_id;
+			}
+
+		} else {
+			$data['code'] = 1;
+			$data['text'] = "错误";
+			$data['RETURN_CODE'] = $array['RETURN_CODE'];
+			$data['RETURN_MSG'] = $array['RETURN_MSG'];
+		}
+
+
+		echo json_encode($data);
+		die();
+	}
+
+	/**
+	 * 获取购物车总数
+	 */
+	public function count()
+	{
+
+		$gpc = I('request.');
+
+		$data = array();
+		$token = $gpc['token'];
+		$community_id = $gpc['community_id'];
+
+		$cart = D('Home/Car');
+		$total = $cart->count_goodscar($token, $community_id);
+
+		$data['code'] = 0;
+		$data['data'] = $total;
+		echo json_encode($data);
+		die();
+
+	}
+
+}

+ 1143 - 1143
Modules/Home/Controller/PaymentController.class.php

@@ -1,1144 +1,1144 @@
-<?php
-/**
- * 播播资源
- *
- * ==========================================================================
- * @link      https://www.ttbobo.com/
- * @copyright Copyright (c) 2015 liofis.com. 
- * @license   https://www.ttbobo.com/license.html License
- * ==========================================================================
- *
- * @author    fish
- *
- */
-namespace Home\Controller;
-
-class PaymentController extends CommonController {
-	
-	protected function _initialize()
-    {
-    	parent::_initialize();
-	}
-	
-	//会员中心页面,去付款
-	function confirm_pay(){
-		if(I('token')!=md5(session('pay_token'))){
-			$url=U('/checkout');
-			@header("Location: ".$url);
-			die();
-		}
-		$order=M('order')->where(array('order_id'=>get_url_id('id')))->find();
-		
-		$data['notify_url']=C('SITE_URL').U('Payment/alipay_notify');
-		$data['return_url']=C('SITE_URL').U('Payment/alipay_return');
-		$data['order_type']='goods_buy';
-		$data['subject']='购买商品';
-		$data['name']=$order['shipping_name'];
-		$data['pay_order_no']=$order['order_num_alias'];
-		$data['pay_total']=(float)$order['total'];		
-		
-		storage_user_action(session('user_auth.uid'),session('user_auth.username'),C('FRONTEND_USER'),'点击了去支付订单 '.$order['order_num_alias']);
-		
-		$url=$this->pay_api($order['payment_code'], $data);			
-		
-		@header("Location: ".$url);
-	
-		die();		
-	}
-	
-	/**
-		接受快递鸟通知
-	**/
-	function kuaidiniao()
-	{
-		
-		echo json_encode(array('Success'=>true));
-		
-		$request_data = I('post.RequestData');
-		
-		$request_data = htmlspecialchars_decode($request_data);
-
-		$request_data_arr = json_decode($request_data,true);
-		
-		foreach($request_data_arr['Data'] as $data)
-		{
-			$LogisticCode = $data['LogisticCode'];
-			$trace = serialize($data['Traces']);
-			M('order')->where( array('shipping_no' => $LogisticCode) )->save( array('shipping_traces' => $trace) );
-		}
-		
-		
-	}
-	
-	/**
-	 * 提交订单支付
-	 * @param unknown $order_id
-	 */
-	
-	function order_pay()
-	{
-	   $order_id =  I('get.order_id',0);
-	   if($order_id > 0)
-	   {
-	       $order = M('order')->where( array('order_id' => $order_id) )->find();   
-		  
-		   
-	       if($order['order_status_id'] == 3)
-	       {
-			   if($order['total'] <= 0)
-			   {
-				   $this->yuer_payreturn($order['order_num_alias']);
-			   } else {
-				    $order['payment_code'] = empty($order['payment_code']) ? 'wxpay': $order['payment_code'];
-					 
-					//单独支付一个店铺的订单
-					M('order_relate')->where( array('order_id' => $order_id) )->delete();
-					
-					$order_all_data = array();
-					$order_all_data['member_id'] = session('user_auth.uid');
-					$order_all_data['order_num_alias'] = build_order_no(session('user_auth.uid'));;
-					$order_all_data['transaction_id'] = '';
-					$order_all_data['order_status_id'] = 3;
-					$order_all_data['is_pin'] = $order['is_pin'];
-					$order_all_data['paytime'] = 0;
-					$order_all_data['total_money'] = $order['total'];
-					$order_all_data['addtime'] = time();
-					
-					$order_all_id = M('order_all')->add($order_all_data);
-						
-					$order_relate_data = array();
-					$order_relate_data['order_all_id'] = $order_all_id;
-					$order_relate_data['order_id'] = $order_id;
-					$order_relate_data['addtime'] = time();
-					M('order_relate')->add($order_relate_data);
-					
-				
-					$wxpay_url = C('SITE_URL')."index.php?s=/Payment/wxpay_order/pay_order_no/{$order_all_data[order_num_alias]}";
-					header('Location: '.$wxpay_url);
-					die();
-			   }
-	           
-	       }
-	   }
-	}
-	
-	
-	/**
-	 * $pay_type 购买商品,还是预存款
-	 * $order 订单信息
-	 */
-	function pay_api($payment_method,$order_all_id){
-		
-		$order_all = M('order_all')->where( array('id' => $order_all_id) )->find();
-		
-		if($payment_method=='alipay'){			
-			
-			$alipay= new \Lib\Payment\Alipay(get_payment_config('alipay'),$order_all);
-			return $alipay->get_payurl();
-		}
-		//wxpay
-		if($payment_method == 'wxpay')
-		{
-			$wxpay_url = C('SITE_URL')."index.php?s=/Payment/wxpay_order/pay_order_no/{$order_all[order_num_alias]}";
-			echo json_encode( array('code' =>1 ,'url' => $wxpay_url) );
-			die();
-			//header('Location: '.$wxpay_url);
-			//$this->redirect( 'Payment/wxpay_order',array('pay_order_no' => $order['order_num_alias']) );	
-		}
-	}
-	
-	//微信支付通知
-	function weixin_notify()
-	{
-		$lib_path = dirname(dirname( dirname(__FILE__) )).'/Lib/';
-		$data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
-		
-		require_once $lib_path."/Weixin/PayNotifyCallBack.class.php";
-		$type=$_GET['type']=='fyfyfy'?$_GET['type']:false;
-		$notify = new \PayNotifyCallBack();
-		$notify->Handle(false,$type);
-		
-	}
-	
-	//开始微信支付订单
-	function wxpay_order()
-	{
-		$lib_path = dirname(dirname( dirname(__FILE__) )).'/Lib/';
-		$data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
-		
-		RecursiveMkdir($data_path);
-		
-		require_once $lib_path."/Weixin/JsApiPay.class.php";
-		
-		
-		$pay_order_no = I('get.pay_order_no',0);
-		
-		$order = M('order_all')->where(array('order_num_alias'=>$pay_order_no, 'member_id' => is_login() ))->find();
-		
-		if(empty($order)) {
-			$this->redirect( U('Index/index') );	
-		}
-		
-		//初始化日志
-		$logHandler= new \CLogFileHandler( $data_path .date('Y-m-d').'.log');
-		
-		$log = \Log::Init($logHandler, 15);
-		
-		$member_info = M('member')->where( array('member_id' => $order['member_id']) )->find();
-		
-		//①、获取用户openid
-		$tools = new  \JsApiPay();
-		//$order['total'] = 0.01;
-		//②、统一下单
-		$input = new \WxPayUnifiedOrder();
-		$input->SetBody(mb_substr('商品购买', 0, 30, 'utf-8'));
-		$input->SetAttach(mb_substr('商品购买', 0, 30, 'utf-8'));
-		$input->SetOut_trade_no($order['id'].'-'.time());
-		$input->SetTotal_fee( ( $order['total_money'] *100) );
-		$input->SetTime_start(date("YmdHis"));
-		$input->SetTime_expire(date("YmdHis", time() + 600));
-		$input->SetGoods_tag("");
-		
-		$notify_url = C('SITE_URL').'notify.php';
-		
-		$input->SetNotify_url($notify_url);
-		
-		$input->SetTrade_type("JSAPI");
-		$input->SetOpenid($member_info['openid']);
-		
-	
-		$order_str = \WxPayApi::unifiedOrder($input);
-		
-		$jsApiParameters = $tools->GetJsApiParameters($order_str);
-		//var_dump($jsApiParameters);die();
-		//获取共享收货地址js函数参数
-		$editAddress = $tools->GetEditAddressParameters();
-		
-		$hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
-		//$order_id = $hashids->encode($order['id']); 
-		
-		if($order['is_pin'] == 1)
-		{
-			$order_relate =  M('order_relate')->where( array('order_all_id' => $order['id']) )->find();
-			$order_id = $hashids->encode($order_relate['order_id']); 
-			
-			$refurl = C('SITE_URL')."index.php?s=/Group/info/group_order_id/{$order_id}/is_show/1";
-		} else {
-			$refurl = C('SITE_URL')."index.php?s=/order/order_all_info/id/{$order[id]}";
-		}
-		$backurl = C('SITE_URL')."index.php?s=/order/order_all_info/id/{$order[id]}";
-		
-		$this->order_id = $order['id'];
-		
-		
-		$this->refurl = $refurl;
-		$this->backurl = $backurl;
-		$this->jsApiParameters = $jsApiParameters;
-		$this->editAddress = $editAddress;
-		
-		$this->display();
-		
-	}
-	
-	//写入订单
-	function pay(){
-	    $json=array();
-	
-	//pickup express
-	    $pay_method = I('post.pay_method');//支付类型
-	    $order_msg_str = I('post.order_msg_str');//商品订单留言
-		$quan_arr = I('post.quan_arr');//使用优惠券
-		
-		//express_method:express_method,pick_mobile:pick_mobile,pick_id:pick_id,pick_name:pick_name
-		$pick_up_id = I('post.pick_id');//$data_s['pick_up_id'];
-		$dispatching = I('post.dispatching');//$data_s['dispatching'];
-		$ziti_name = I('post.pick_name');//$data_s['ziti_name'];
-		$ziti_mobile = I('post.pick_mobile');//$data_s['ziti_mobile'];
-	
-	    $order_msg_arr = explode('@,@', $order_msg_str);
-	
-	    $msg_arr = array();
-	    foreach($order_msg_arr as $val)
-	    {
-	        $tmp_val = explode('@_@', $val);
-	        $msg_arr[ $tmp_val[0] ] = $tmp_val[1];
-	    }
-		
-		$member_id = session('user_auth.uid');
-		$order_quan_arr = array();
-		
-		if( !empty($quan_arr) )
-		{
-			foreach($quan_arr as $q_val)
-			{
-				$tmp_q = array();
-				$tmp_q = explode('_',$q_val);
-				
-				$voucher_info =  M('voucher_list')->where( array('id' =>$tmp_q[1],
-				'store_id' =>$tmp_q[0], 'user_id' => session('user_auth.uid'),'consume' =>'N','end_time' => array('gt',time() ) ) )->find();
-			
-				if( !empty($voucher_info) )
-				{
-					$order_quan_arr[$tmp_q[0]] = $tmp_q[1];
-				}
-			}
-			
-		}
-		
-		
-	    
-	    $cart=new \Lib\Cart();
-	
-	    // 验证商品数量
-	  
-	    $buy_type = I('post.buy_type');
-	
-	    $is_pin = 0;
-	    if($buy_type == 'pin')
-	    {
-	        $is_pin = 1;
-	    }
-	    $goodss = $cart->get_all_goods($buy_type,1);
-		
-		$seller_goodss = array();
-		$del_integral = 0;
-		
-		foreach($goodss as $key => $val)
-		{
-			if($buy_type == 'dan')
-			{
-				$new_key = 'cart.'.$key;
-				$s = session($new_key);
-				
-			
-				if( isset($s['can_del']) && $s['can_del'] == 1)
-				{
-					$cart->remove($key);
-				}else if(isset($s['old_quantity'])){
-					
-					$s['quantity'] = $s['old_quantity'];
-					
-					session($new_key,$s);
-				}
-			}
-			$goods_store_field =  M('goods')->field('store_id')->where( array('goods_id' => $val['goods_id']) )->find();
-			$seller_goodss[ $goods_store_field['store_id'] ][$key] = $val;
-		}
-		
-		
-	    //付款人
-	    $payment=M('Member')->find(session('user_auth.uid'));
-	
-	    //收货人
-	    $add_where = array('member_id'=>session('user_auth.uid'));
-	    $address = M('address')->where( $add_where )->order('is_default desc,address_id desc')->find();
-		
-		$pay_total = 0;
-		//M('order_all')
-		$order_all_data = array();
-		$order_all_data['member_id'] = session('user_auth.uid');
-		$order_all_data['order_num_alias'] = build_order_no(session('user_auth.uid'));;
-		$order_all_data['transaction_id'] = '';
-		$order_all_data['order_status_id'] = 3;
-		$order_all_data['is_pin'] = $is_pin;
-		$order_all_data['paytime'] = 0;
-		
-		$order_all_data['addtime'] = time();
-		
-		$order_all_id = M('order_all')->add($order_all_data);
-		
-		 
-		$integral_model = D('Seller/Integral');
-		
-		foreach($seller_goodss as $kk => $vv)
-		{
-			$data = array();
-	
-			$data['member_id']=session('user_auth.uid');
-			$data['name']=session('user_auth.username');
-		
-			$data['telephone']=$address['telephone'];
-		
-			$data['shipping_name']=$address['name'];
-			$data['shipping_address']=$address['address'];
-			$data['shipping_tel']=$address['telephone'];
-		
-			$data['shipping_province_id']=$address['province_id'];
-			$data['shipping_city_id']=$address['city_id'];
-			$data['shipping_country_id']=$address['country_id'];
-		
-			$data['shipping_method'] = 0;
-			
-			$data['delivery']=$dispatching;
-			$data['pick_up_id']=$pick_up_id;
-			$data['ziti_name']=$ziti_name;
-			$data['ziti_mobile']=$ziti_mobile;
-		
-		
-			$data['payment_method']=$pay_method;
-		
-			$data['address_id']= $address['address_id'];
-			//quan_arr
-			$data['voucher_id'] = isset($order_quan_arr[$kk]) ? $order_quan_arr[$kk]:0;
-		
-			$data['user_agent']=$_SERVER['HTTP_USER_AGENT'];
-			$data['date_added']=time();
-		
-			$hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
-			$subject='';
-			$fare = 0;
-				
-			$goodss = $vv;
-
-			$trans_free_toal = 0;//运费
-
-			$goods_data = array();
-			$order_total = 0;
-			$is_lottery = 0;
-			$is_integral = 0;
-			
-			foreach($goodss as $key => $good)
-			{
-				if($good['shipping']==1)
-				{
-					//统一运费
-					$trans_free_toal += $good['goods_freight'];
-					$trans_free = $good['goods_freight'];
-				}else {
-					//运费模板
-					$trans_free = D('Home/Transport')->calc_transport($good['transport_id'], $good['quantity']*$good['weight'], $address['city_id'] );
-					$trans_free_toal +=$trans_free;
-				}
-				$goods_info = explode(':', $key);
-
-				$goods_id = $goods_info[0];
-
-				
-				
-				if (!empty($goods_info[1])) {
-					$options = base64_decode($goods_info[1]);
-				} else {
-					$options = '';
-				}
-				$order_total += $good['total'];
-
-
-				$tp_goods_info = M('goods')->field('store_id,type')->where( array('goods_id' =>$good['goods_id'] ) )->find();
-				
-				if($tp_goods_info['type'] == 'lottery')
-				{
-					$is_lottery = 1;
-				}
-				
-				if($tp_goods_info['type'] == 'integral')
-				{
-					$is_integral = 1;
-					$is_pin = 0;
-					$check_result = $integral_model->check_user_score_can_pay($member_id, $good['sku_str'], $good['goods_id'] );
-					if($check_result['code'] == 1)
-					{
-						die();
-					}
-				}
-				
-				$goods_data[] = array(
-					'goods_id'   => $good['goods_id'],
-					'store_id' => $tp_goods_info['store_id'],
-					'name'       => $good['name'],
-					'model'      => $good['model'],
-					'is_pin' => $is_pin,
-					'pin_id' => $good['pin_id'],
-					'header_disc' => $good['header_disc'],
-					'option'     => $options,
-					'quantity'   => $good['quantity'],
-					'shipping_fare' => $trans_free,
-					'price'      => $good['price'],
-					'total'      => $good['total'],
-					'comment' => htmlspecialchars($msg_arr[$key])
-				);
-
-			}
-			$data['type'] = 'normal';
-			if($is_pin == 1)
-			{
-				$data['type'] = 'pintuan';
-				if($is_lottery == 1)
-				{
-					$data['type'] = 'lottery';
-				}
-			}
-			if($is_integral == 1)
-			{
-				$data['type'] = 'integral';
-				$is_pin = 0;
-			}
-			
-			$data['shipping_fare'] = floatval($trans_free_toal);
-				
-			$data['store_id']= $kk;
-			
-		   // $tp_goods_info['store_id'],
-			
-			
-			
-			
-			$data['goodss'] = $goods_data;
-			$data['order_num_alias']=build_order_no($kk);
-				
-			$data['totals'][0]=array(
-				'code'=>'sub_total',
-				'title'=>'商品价格',
-				'text'=>'¥'.$order_total,
-				'value'=>$order_total
-			);
-			$data['totals'][1]=array(
-				'code'=>'shipping',
-				'title'=>'运费',
-				'text'=>'¥'.$trans_free_toal,
-				'value'=>$trans_free_toal
-			);
-				
-			$data['totals'][2]=array(
-				'code'=>'total',
-				'title'=>'总价',
-				'text'=>'¥'.($order_total+$trans_free_toal),
-				'value'=>($order_total+$trans_free_toal)
-			);
-			
-			
-			if($data['voucher_id'] > 0) {
-				$voucher_info = M('voucher_list')->where( array('id' => $data['voucher_id']) )->find();
-				$data['voucher_credit'] = $voucher_info['credit'];
-				M('voucher_list')->where( array('id' => $data['voucher_id']) )->save( array('consume' => 'Y') );
-			} else {
-				$data['voucher_credit'] = 0;
-			}
-					
-			$data['total']=($order_total+$trans_free_toal- $data['voucher_credit'] );
-
-			//积分商城
-			if($data['type'] == 'integral')
-			{
-				$del_integral += $order_total;//扣除积分
-				$data['total'] = 0;
-				$order_total = 0;
-			}			
-			$oid=D('Order')->addOrder($data);
-			
-			if($data['delivery'] == 'pickup')
-			{
-				$verify_bool = true;
-				$verifycode = 0;
-				while($verify_bool)
-				{
-					$code  = (ceil(time()/100)+rand(10000000,40000000)).rand(1000,9999);
-					$verifycode = $code ? $code : rand(100000,999999);
-					$verifycode = str_replace('1989','9819',$verifycode);
-					$verifycode = str_replace('1259','9521',$verifycode);
-					$verifycode = str_replace('12590','95210',$verifycode);
-					$verifycode = str_replace('10086','68001',$verifycode);
-					
-					$pick_order = M('pick_order')->where( array('pick_sn' => $verifycode) )->find();
-					if(empty($pick_order))
-					{
-						$verify_bool = false;
-					}
-				}
-				$pick_data = array();
-				$pick_data['pick_sn'] = $verifycode;
-				$pick_data['pick_id'] = $pick_up_id;
-				$pick_data['order_id'] = $oid;
-				$pick_data['state'] = 0;
-				
-				$pick_data['ziti_name'] = $ziti_name;
-				$pick_data['ziti_mobile'] = $ziti_mobile;
-				
-			
-				$pick_data['addtime'] = time();
-				M('pick_order')->add($pick_data);
-			}
-			$pay_total = $pay_total + $order_total+$trans_free_toal- $data['voucher_credit'];
-			
-			
-			$order_relate_data = array();
-			$order_relate_data['order_all_id'] = $order_all_id;
-			$order_relate_data['order_id'] = $oid;
-			$order_relate_data['addtime'] = time();
-			
-			M('order_relate')->add($order_relate_data);
-		}
-		M('order_all')->where( array('id' => $order_all_id) )->save( array('total_money' => $pay_total) );
-		
-	    
-	
-	        if($order_all_id){
-	            //session('cart_total',null);
-	            $order['notify_url']=C('SITE_URL').U('Payment/alipay_notify');
-	            $order['return_url']=C('SITE_URL').U('Payment/alipay_return');
-	            $order['order_type']='goods_buy';
-	            $order['subject']=$subject;
-	            $order['name']=session('shipping_name');
-	            $order['order_num_alias']=$data['order_num_alias'];
-	            $order['pay_total']=($order_total+$trans_free_toal);
-	            //free_tuan
-	            
-	            //session('back_cart_address_id',null);
-	            //session('cart',null);
-	            //session('total',null);
-	            //session('shipping_address_id',null);
-	            //session('back_order_id',$oid);
-	            	
-	            if($data['total']<=0 )
-	            {
-					//检测是否需要扣除积分
-					//var_dump($del_integral,$is_integral );die();
-					if($del_integral> 0 && $is_integral == 1)
-					{
-						//
-						$integral_model->charge_member_score( $member_id, $del_integral,'out', 'orderbuy', $oid);
-					}
-	                $this->yuer_payreturn($oid); //测试使用
-	            }else {
-	                $url=$this->pay_api('wxpay', $order_all_id);
-	            }
-	            	
-	            die();
-	        }else{
-	
-	            echo 9999;die();
-	            $url=U('/checkout');
-	            @header("Location: ".$url);
-	            	
-	            die();
-	        }
-	
-	  
-	    	
-	}
-	//写入订单
-	function pay2(){
-		$json=array();
-		if(I('token')!=md5(session('token'))){
-			$url=U('/checkout');
-			@header("Location: ".$url);
-			die();
-		}		
-
-		$cart=new \Lib\Cart();	
-		
-		// 验证商品数量		
-		$goodss = $cart->get_all_goods();
-		
-		//付款人
-		$payment=M('Member')->find(session('user_auth.uid'));
-		
-		//收货人 
-		$shipping=M('Address')->find(session('shipping_address_id'));
-		
-		$data['member_id']=session('user_auth.uid');
-		$data['name']=session('user_auth.username');
-		
-		$data['telephone']=$payment['telephone'];
-		
-		$data['shipping_name']=$shipping['name'];
-		$data['shipping_address']=$shipping['address'];
-		$data['shipping_tel']=$shipping['telephone'];
-		
-		$data['shipping_province_id']=$shipping['province_id'];
-		$data['shipping_city_id']=$shipping['city_id'];
-		$data['shipping_country_id']=$shipping['country_id'];		
-		
-		$data['shipping_method'] = session('express_id');
-		$data['delivery']=session('shipping_method');
-		
-		
-		$data['payment_method']=session('payment_method');
-		
-		$data['address_id']=session('shipping_address_id');
-		
-		$data['voucher_id']=session('payment_voucher_id');
-		//payment_voucher_id
-
-		$data['user_agent']=$_SERVER['HTTP_USER_AGENT'];
-		$data['date_added']=time();
-		$data['comment']=session('remark');
-		$hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
-		$subject='';
-		$fare = 0;
-		if($goodss){				
-		    
-				/**
-				$sm=D('Transport')->calc_transport(session('shipping_method'),
-				session('quantity'),
-				$shipping['city_id']
-				);	
-				**/
-				
-				$sm = D('Transport')->calc_transport(null,
-				session('quantity'),
-				$shipping['city_id']
-				);
-				
-				$t=0;		
-				foreach ($goodss as $goods) {
-					
-					$option_data = array();
-	
-					foreach ($goods['option'] as $option) {
-						
-						$value = $option['value'];						
-	
-						$option_data[] = array(
-							'goods_option_id'       => $option['goods_option_id'],
-							'goods_option_value_id' => $option['goods_option_value_id'],
-							'option_id'               => $option['option_id'],
-							'option_value_id'         => $option['option_value_id'],								   
-							'name'                    => $option['name'],
-							'value'                   => $value,
-							'type'                    => $option['type']
-						);					
-					}
-					
-					$tp_goods_info = M('goods')->field('store_id,express_list')->where( array('goods_id' =>$hashids->decode($goods['goods_id'])) )->find();
-					
-					$express_list_arr = unserialize($tp_goods_info['express_list']);
-					
-					if($data['delivery'] == 'express')
-					{
-						$fare = isset($express_list_arr[$data['shipping_method']]) ? $express_list_arr[$data['shipping_method']]['price'] : 0;
-					}
-					
-					$t+=$goods['total'];					
-					
-					$goods['total'] = $goods['total'];
-					
-					$goods_data[] = array(
-						'goods_id'   => $goods['goods_id'],
-						'name'       => $goods['name'],
-					    'is_header_disc' => $goods['is_header_disc'],
-					    'store_id'   => $tp_goods_info['store_id'],
-						'model'      => $goods['model'],		
-						'option'     => $option_data,						
-						'quantity'   => $goods['quantity'],
-						'pin_type'   => $goods['pin_type'],
-					    'pin_id'     => $goods['pin_id'],
-						'price'      => $goods['price'],
-						'total'      => $goods['total']				
-					); 		
-			
-					$subject.=$goods['name'].' ';					
-						
-					}
-					
-					if($data['voucher_id'] > 0) {
-						$voucher_info = M('voucher_list')->where( array('id' => $data['voucher_id']) )->find();
-						$data['voucher_credit'] = $voucher_info['credit'];
-						M('voucher_list')->where( array('id' => $data['voucher_id']) )->save( array('consume' => 'Y') );
-					} else {
-						$data['voucher_credit'] = 0;
-					}
-					
-					$data['shipping_fare'] = floatval($fare);
-					
-					$data['total']=($t+$fare - $data['voucher_credit']);
-					$data['goodss'] = $goods_data;
-					$data['order_num_alias']=build_order_no($data['member_id']);
-					
-					$data['totals'][0]=array(
-						'code'=>'sub_total',
-						'title'=>'商品价格',
-						'text'=>'¥'.$t,
-						'value'=>$t				
-					);
-					$data['totals'][1]=array(
-						'code'=>'shipping',
-						'title'=>'运费',
-						'text'=>'¥'.$fare,
-						'value'=>$fare				
-					);				
-					$data['totals'][2]=array(
-						'code'=>'voucher',
-						'title'=>'优惠券',
-						'text'=>'¥'.$data['voucher_credit'],
-						'value'=>$data['voucher_credit']				
-					);	
-					$data['totals'][3]=array(
-						'code'=>'total',
-						'title'=>'总价',
-						'text'=>'¥'.($t+$fare- $data['voucher_credit']),
-						'value'=>($t+$fare- $data['voucher_credit'])				
-					);
-				
-				
-				$oid=D('Order')->addOrder($data);
-				
-				//delivery  pickup pick_up_id
-				if($data['delivery'] == 'pickup')
-				{
-					$verify_bool = true;
-					$verifycode = 0;
-					while($verify_bool)
-					{
-						$code  = (ceil(time()/100)+rand(10000000,40000000)).rand(1000,9999);
-						$verifycode = $code ? $code : rand(100000,999999);
-						$verifycode = str_replace('1989','9819',$verifycode);
-						$verifycode = str_replace('1259','9521',$verifycode);
-						$verifycode = str_replace('12590','95210',$verifycode);
-						$verifycode = str_replace('10086','68001',$verifycode);
-						
-						$pick_order = M('pick_order')->where( array('pick_sn' => $verifycode) )->find();
-						if(empty($pick_order))
-						{
-							$verify_bool = false;
-						}
-					}
-					$pick_data = array();
-					$pick_data['pick_sn'] = $verifycode;
-					$pick_data['pick_id'] = session('pick_up_id');
-					$pick_data['order_id'] = $oid;
-					$pick_data['state'] = 0;
-					$pick_data['addtime'] = time();
-					M('pick_order')->add($pick_data);
-				}
-				if($oid){				
-					session('cart_total',null);
-					$order['notify_url']=C('SITE_URL').U('Payment/alipay_notify');
-					$order['return_url']=C('SITE_URL').U('Payment/alipay_return');
-					$order['order_type']='goods_buy';
-					$order['subject']=$subject;
-					$order['name']=session('shipping_name');
-					$order['order_num_alias']=$data['order_num_alias'];
-					$order['pay_total']=($t+$sm['price']);			
-					//free_tuan
-					$order_goods_info = M('order_goods')->where( array('order_id' => $oid) )->find();
-					
-					session('back_cart_address_id',null);
-					session('cart',null);
-					session('total',null);					
-					session('shipping_address_id',null);	
-					session('back_order_id',$oid);
-					
-					if($data['total']<=0 || $order_goods_info['free_tuan'] ==1)
-					{
-					    $this->yuer_payreturn($data['order_num_alias']); //测试使用
-					}else {
-					    $url=$this->pay_api('wxpay', $order);
-					}
-					
-					die();
-				}else{
-				    
-				    echo 9999;die();
-					$url=U('/checkout');
-					@header("Location: ".$url);
-					
-					die();
-				}
-				
-			}
-			
-	}
-
-	public function success()
-	{
-	    $order_id = I('get.order_id');
-	    //removeAll
-	    $cart=new \Lib\Cart();
-	    $cart->removeAll();
-	    session('total',null);
-	     
-	    $pin_order = M('pin_order')->field('pin_id')->where( array('order_id' =>$order_id) )->find();
-	     
-	    //Order/info/id/14
-	     
-	    $redir_url = U('Order/info', array('id' => $order_id));
-	    if(!empty($pin_order))
-	    {
-	        $hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
-	        $group_order_id = $hashids->encode($order_id);
-	         
-	        $redir_url = U('Group/info', array('group_order_id' => $group_order_id,'is_show' =>1));
-			redirect($redir_url,0);
-	    }
-	    $this->redir_url = $redir_url;
-	     
-	    $this->order_id = $order_id;
-	    $this->display();
-	}
-	
-	function de_bug($content){
-		$file = ROOT_PATH."/Tmp/wxpay_debug.php";
-		file_put_contents($file,$content);	
-	}
-
-	//数据以post方式返回
-	function alipay_notify(){
-		
-		$alipay= new \Lib\Payment\Alipay(get_payment_config('alipay'));
-		
-		$verify_result = $alipay->verifyNotify();
-		
-		if($verify_result) {
-			
-			//$this->de_bug('success');
-			
-			//商户订单号	
-			//$out_trade_no = $_POST['out_trade_no'];	
-			//支付宝交易号	
-			//$trade_no = $_POST['trade_no'];	
-			//交易状态
-			//$trade_status = $_POST['trade_status'];
-			
-			if($_POST['trade_status'] == 'TRADE_FINISHED') {
-				//$this->de_bug('TRADE_FINISHED');
-				
-		    }
-		    else if ($_POST['trade_status'] == 'TRADE_SUCCESS') {
-				//$this->de_bug('TRADE_SUCCESS');
-				
-				$order=M('Order')->getByOrderNumAlias($_POST['out_trade_no']);
-				
-				if($order&&($order['order_status_id']!=C('paid_order_status_id'))){
-						//支付完成						
-						$o['order_id']=$order['order_id'];
-						$o['order_status_id']=C('paid_order_status_id');
-						$o['date_modified']=time();
-						$o['pay_time']=time();
-						M('Order')->save($o);
-						
-						$oh['order_id']=$order['order_id'];
-						$oh['order_status_id']=C('paid_order_status_id');
-				
-						$oh['comment']='买家已付款';
-						$oh['date_added']=time();
-						$oh['notify']=1;
-						M('OrderHistory')->add($oh);
-						
-						$model=new \Admin\Model\OrderModel();	   
-					    $this->order=$model->order_info($order['order_id']);
-					    $html=$this->fetch('Mail:order');				   
-					    think_send_mail($order['email'],$order['name'],'下单成功-'.C('SITE_NAME'),$html);
-						
-						storage_user_action(session('user_auth.uid'),session('user_auth.username'),C('FRONTEND_USER'),'支付了订单 '.$order['order_num_alias']);
-						
-						//@header("Location: ".U('/pay_success'));	
-											
-				}
-				
-		        
-				echo "success";		
-		    }
-		
-			
-			
-		}else{
-			//$this->de_bug('fail');
-			echo "fail";
-		}
-		
-	}
-	
-	private function yuer_payreturn($order_id){
-	    // $order=M('Order')->getByOrderNumAlias($out_trade_no);
-	    $order=M('Order')->where( array('order_id' => $order_id) )->find();
-	    $out_trade_no = $order['order_num_alias'];
-	     
-	    if($order['order_status_id']==C('paid_order_status_id')){
-	        @header("Location: ".U('/pay_success'));
-	        die;
-	    }
-	     
-	    if($order&&($order['order_status_id']!=C('paid_order_status_id'))){
-	        //支付完成
-	        if(true){
-	             
-	            
-	
-	            $goods_model = D('Home/Goods');
-	
-	            $kucun_method = C('kucun_method');
-	            $kucun_method  = empty($kucun_method) ? 0 : intval($kucun_method);
-	            if($kucun_method == 1)
-	            {//支付完减库存,增加销量
-	                $order_goods_list = M('order_goods')->where( array('order_id' => $order['order_id']) )->select();
-	                foreach($order_goods_list as $order_goods)
-	                {
-	                    //销量增加 del_goods_mult_option_quantity($order_id,$option,$goods_id,$quantity,$type='1')
-	                    $goods_model->del_goods_mult_option_quantity($order['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity'],1);
-	                    //扣除库存
-	                }
-	            }
-	
-	            $oh['order_id']=$order['order_id'];
-	            $oh['order_status_id'] = 1;
-	            $oh['comment']='买家已付款';
-	            $oh['date_added']=time();
-	            $oh['notify']=0;
-	            M('OrderHistory')->add($oh);
-	             
-	            $pin_order = M('pin_order')->where( array('order_id' =>$order['order_id'] ) )->find();
-	           
-	            if(!empty($pin_order))
-	            {
-					$o = array();
-					$o['order_id']=$order['order_id'];
-					$o['order_status_id']= 2;
-					$o['date_modified']=time();
-					$o['pay_time']=time();
-					M('Order')->save($o);
-	                //group_order_id
-	                $pin_model = D('Home/Pin');
-	                $is_pin_success = $pin_model->checkPinSuccess($pin_order['pin_id']);
-	
-	                if($is_pin_success) {
-	                    //todo send pintuan success notify
-	                    $pin_model->updatePintuanSuccess($pin_order['pin_id']);
-						
-	                }else{
-						
-					}
-	            }else{
-					$o = array();
-					$o['order_id']=$order['order_id'];
-					$o['order_status_id']= 1;
-					$o['date_modified']=time();
-					$o['pay_time']=time();
-					M('Order')->save($o);
-					$share_model = D('Seller/Fissionsharing');
-					$share_model->send_order_commiss_money( $order['order_id'] );
-				}
-	             
-	            $result = array('code' => 1, 'url' => U('Payment/success',array('order_id' => $order['order_id'])));
-	             
-	            echo json_encode($result);
-	            die();
-	            
-	        }
-	    }
-	}
-	
-	
-	private function yuer_payreturn2($out_trade_no){
-	    $order=M('Order')->getByOrderNumAlias($out_trade_no);
-	   
-	    if($order['order_status_id']==C('paid_order_status_id')){
-	        @header("Location: ".U('/pay_success'));
-	        die;
-	    }
-	    
-	    if($order&&($order['order_status_id']!=C('paid_order_status_id'))){
-	        //支付完成
-	        if(true){
-	            	 
-	                
-	            $o['order_id']=$order['order_id'];
-	            $o['order_status_id']= $order['is_pin'] == 1 ? 2:1;
-	            $o['date_modified']=time();
-	            $o['pay_time']=time();
-	            M('Order')->save($o);
-				
-				$goods_model = D('Home/Goods');
-				
-				$kucun_method = C('kucun_method');
-				$kucun_method  = empty($kucun_method) ? 0 : intval($kucun_method);
-				if($kucun_method == 1)
-				{//支付完减库存,增加销量
-					$order_goods_list = M('order_goods')->where( array('order_id' => $order['order_id']) )->select();
-					foreach($order_goods_list as $order_goods)
-					{
-						//销量增加 rela_goodsoption_valueid
-						$goods_model->del_goods_mult_option_quantity($order['order_id'],$order_goods['quantity'],1);
-						//扣除库存
-					}
-				}
-	            	
-	            $oh['order_id']=$order['order_id'];
-	            $oh['order_status_id']= $order['is_pin'] == 1 ? 2:1;
-	            $oh['comment']='买家已付款';
-	            $oh['date_added']=time();
-	            $oh['notify']=1;
-	            M('OrderHistory')->add($oh);
-	            
-	            //发送购买通知
-	            $weixin_nofity = D('Home/Weixinnotify');
-	            $weixin_nofity->orderBuy($order);
-	            
-	            $model=new \Admin\Model\OrderModel();
-	            $this->order=$model->order_info($order['order_id']);
-	           
-	            $hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
-	            $order_id = $hashids->encode($order['order_id']);
-	            
-	            if($order['is_pin'] == 1)
-	            {
-	                $pin_model = D('Home/Pin');
-	                $is_pin_success = $pin_model->checkPinSuccess($order['pin_id']);
-	                
-	                if($is_pin_success) {
-	                    //todo send pintuan success notify
-	                    $pin_model->updatePintuanSuccess($order['pin_id']);
-	                }
-	                $refurl = C('SITE_URL')."index.php?s=/Group/info/group_order_id/{$order_id}/is_show/1";
-	                @header("Location: ".$refurl);
-	                die();
-	            } else {
-	                @header("Location: ".U('Order/info',array('id' =>$order['order_id'] )));
-	                die();
-	            }
-	           
-	        }
-	    }
-	}
-
-	function alipay_return(){
-		
-		$alipay= new \Lib\Payment\Alipay(get_payment_config('alipay'));
-		
-		//对进入的参数进行远程数据判断
-		$verify = $alipay->return_verify();
-	
-		if($verify){
-			$order=M('Order')->getByOrderNumAlias($_GET['out_trade_no']);
-			
-			if($order['order_status_id']==C('paid_order_status_id')){
-				@header("Location: ".U('/pay_success'));	
-				die;
-			}
-			
-			if($order&&($order['order_status_id']!=C('paid_order_status_id'))){
-				//支付完成
-				if($_GET['trade_status']=='TRADE_SUCCESS'){					
-					
-					$o['order_id']=$order['order_id'];
-					$o['order_status_id']=C('paid_order_status_id');
-					$o['date_modified']=time();
-					$o['pay_time']=time();
-					M('Order')->save($o);
-					
-					$oh['order_id']=$order['order_id'];
-					$oh['order_status_id']=C('paid_order_status_id');
-			
-					$oh['comment']='买家已付款';
-					$oh['date_added']=time();
-					$oh['notify']=1;
-					M('OrderHistory')->add($oh);
-					
-					$model=new \Admin\Model\OrderModel();	   
-				    $this->order=$model->order_info($order['order_id']);
-				    $html=$this->fetch('Mail:order');				   
-				    think_send_mail($order['email'],$order['name'],'下单成功-'.C('SITE_NAME'),$html);
-					
-					storage_user_action(session('user_auth.uid'),session('user_auth.username'),C('FRONTEND_USER'),'支付了订单 '.$order['order_num_alias']);
-					
-					@header("Location: ".U('/pay_success'));	
-				}						
-			}else{
-				die('订单不存在');
-			}
-			
-		}else{
-			die('支付失败');
-		}		
-		
-	}
+<?php
+/**
+ * 播播资源
+ *
+ * ==========================================================================
+ * @link      https://www.ttbobo.com/
+ * @copyright Copyright (c) 2015 liofis.com. 
+ * @license   https://www.ttbobo.com/license.html License
+ * ==========================================================================
+ *
+ * @author    fish
+ *
+ */
+
+class PaymentController extends \Home\Controller\CommonController
+{
+	
+	protected function _initialize()
+    {
+    	\Home\Controller\CommonController::_initialize();
+	}
+	
+	//会员中心页面,去付款
+	function confirm_pay(){
+		if(I('token')!=md5(session('pay_token'))){
+			$url=U('/checkout');
+			@header("Location: ".$url);
+			die();
+		}
+		$order=M('order')->where(array('order_id'=>get_url_id('id')))->find();
+		
+		$data['notify_url']=C('SITE_URL').U('Payment/alipay_notify');
+		$data['return_url']=C('SITE_URL').U('Payment/alipay_return');
+		$data['order_type']='goods_buy';
+		$data['subject']='购买商品';
+		$data['name']=$order['shipping_name'];
+		$data['pay_order_no']=$order['order_num_alias'];
+		$data['pay_total']=(float)$order['total'];		
+		
+		storage_user_action(session('user_auth.uid'),session('user_auth.username'),C('FRONTEND_USER'),'点击了去支付订单 '.$order['order_num_alias']);
+		
+		$url=$this->pay_api($order['payment_code'], $data);			
+		
+		@header("Location: ".$url);
+	
+		die();		
+	}
+	
+	/**
+		接受快递鸟通知
+	**/
+	function kuaidiniao()
+	{
+		
+		echo json_encode(array('Success'=>true));
+		
+		$request_data = I('post.RequestData');
+		
+		$request_data = htmlspecialchars_decode($request_data);
+
+		$request_data_arr = json_decode($request_data,true);
+		
+		foreach($request_data_arr['Data'] as $data)
+		{
+			$LogisticCode = $data['LogisticCode'];
+			$trace = serialize($data['Traces']);
+			M('order')->where( array('shipping_no' => $LogisticCode) )->save( array('shipping_traces' => $trace) );
+		}
+		
+		
+	}
+	
+	/**
+	 * 提交订单支付
+	 * @param \Home\Controller\unknown $order_id
+	 */
+	
+	function order_pay()
+	{
+	   $order_id =  I('get.order_id',0);
+	   if($order_id > 0)
+	   {
+	       $order = M('order')->where( array('order_id' => $order_id) )->find();   
+		  
+		   
+	       if($order['order_status_id'] == 3)
+	       {
+			   if($order['total'] <= 0)
+			   {
+				   $this->yuer_payreturn($order['order_num_alias']);
+			   } else {
+				    $order['payment_code'] = empty($order['payment_code']) ? 'wxpay': $order['payment_code'];
+					 
+					//单独支付一个店铺的订单
+					M('order_relate')->where( array('order_id' => $order_id) )->delete();
+					
+					$order_all_data = array();
+					$order_all_data['member_id'] = session('user_auth.uid');
+					$order_all_data['order_num_alias'] = build_order_no(session('user_auth.uid'));;
+					$order_all_data['transaction_id'] = '';
+					$order_all_data['order_status_id'] = 3;
+					$order_all_data['is_pin'] = $order['is_pin'];
+					$order_all_data['paytime'] = 0;
+					$order_all_data['total_money'] = $order['total'];
+					$order_all_data['addtime'] = time();
+					
+					$order_all_id = M('order_all')->add($order_all_data);
+						
+					$order_relate_data = array();
+					$order_relate_data['order_all_id'] = $order_all_id;
+					$order_relate_data['order_id'] = $order_id;
+					$order_relate_data['addtime'] = time();
+					M('order_relate')->add($order_relate_data);
+					
+				
+					$wxpay_url = C('SITE_URL')."index.php?s=/Payment/wxpay_order/pay_order_no/{$order_all_data[order_num_alias]}";
+					header('Location: '.$wxpay_url);
+					die();
+			   }
+	           
+	       }
+	   }
+	}
+	
+	
+	/**
+	 * $pay_type 购买商品,还是预存款
+	 * $order 订单信息
+	 */
+	function pay_api($payment_method,$order_all_id){
+		
+		$order_all = M('order_all')->where( array('id' => $order_all_id) )->find();
+		
+		if($payment_method=='alipay'){			
+			
+			$alipay= new \Lib\Payment\Alipay(get_payment_config('alipay'),$order_all);
+			return $alipay->get_payurl();
+		}
+		//wxpay
+		if($payment_method == 'wxpay')
+		{
+			$wxpay_url = C('SITE_URL')."index.php?s=/Payment/wxpay_order/pay_order_no/{$order_all[order_num_alias]}";
+			echo json_encode( array('code' =>1 ,'url' => $wxpay_url) );
+			die();
+			//header('Location: '.$wxpay_url);
+			//$this->redirect( 'Payment/wxpay_order',array('pay_order_no' => $order['order_num_alias']) );	
+		}
+	}
+	
+	//微信支付通知
+	function weixin_notify()
+	{
+		$lib_path = dirname(dirname( dirname(__FILE__) )).'/Lib/';
+		$data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
+		
+		require_once $lib_path."/Weixin/PayNotifyCallBack.class.php";
+		
+		$notify = new \PayNotifyCallBack();
+		$notify->Handle(false);
+		
+	}
+	
+	//开始微信支付订单
+	function wxpay_order()
+	{
+		$lib_path = dirname(dirname( dirname(__FILE__) )).'/Lib/';
+		$data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
+		
+		RecursiveMkdir($data_path);
+		
+		require_once $lib_path."/Weixin/JsApiPay.class.php";
+		
+		
+		$pay_order_no = I('get.pay_order_no',0);
+		
+		$order = M('order_all')->where(array('order_num_alias'=>$pay_order_no, 'member_id' => is_login() ))->find();
+		
+		if(empty($order)) {
+			$this->redirect( U('Index/index') );	
+		}
+		
+		//初始化日志
+		$logHandler= new \CLogFileHandler( $data_path .date('Y-m-d').'.log');
+		
+		$log = \Log::Init($logHandler, 15);
+		
+		$member_info = M('member')->where( array('member_id' => $order['member_id']) )->find();
+		
+		//①、获取用户openid
+		$tools = new  \JsApiPay();
+		//$order['total'] = 0.01;
+		//②、统一下单
+		$input = new \WxPayUnifiedOrder();
+		$input->SetBody(mb_substr('商品购买', 0, 30, 'utf-8'));
+		$input->SetAttach(mb_substr('商品购买', 0, 30, 'utf-8'));
+		$input->SetOut_trade_no($order['id'].'-'.time());
+		$input->SetTotal_fee( ( $order['total_money'] *100) );
+		$input->SetTime_start(date("YmdHis"));
+		$input->SetTime_expire(date("YmdHis", time() + 600));
+		$input->SetGoods_tag("");
+		
+		$notify_url = C('SITE_URL').'notify.php';
+		
+		$input->SetNotify_url($notify_url);
+		
+		$input->SetTrade_type("JSAPI");
+		$input->SetOpenid($member_info['openid']);
+		
+	
+		$order_str = \WxPayApi::unifiedOrder($input);
+		
+		$jsApiParameters = $tools->GetJsApiParameters($order_str);
+		//var_dump($jsApiParameters);die();
+		//获取共享收货地址js函数参数
+		$editAddress = $tools->GetEditAddressParameters();
+		
+		$hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
+		//$order_id = $hashids->encode($order['id']); 
+		
+		if($order['is_pin'] == 1)
+		{
+			$order_relate =  M('order_relate')->where( array('order_all_id' => $order['id']) )->find();
+			$order_id = $hashids->encode($order_relate['order_id']); 
+			
+			$refurl = C('SITE_URL')."index.php?s=/Group/info/group_order_id/{$order_id}/is_show/1";
+		} else {
+			$refurl = C('SITE_URL')."index.php?s=/order/order_all_info/id/{$order[id]}";
+		}
+		$backurl = C('SITE_URL')."index.php?s=/order/order_all_info/id/{$order[id]}";
+		
+		$this->order_id = $order['id'];
+		
+		
+		$this->refurl = $refurl;
+		$this->backurl = $backurl;
+		$this->jsApiParameters = $jsApiParameters;
+		$this->editAddress = $editAddress;
+		
+		$this->display();
+		
+	}
+	
+	//写入订单
+	function pay(){
+	    $json=array();
+	
+	//pickup express
+	    $pay_method = I('post.pay_method');//支付类型
+	    $order_msg_str = I('post.order_msg_str');//商品订单留言
+		$quan_arr = I('post.quan_arr');//使用优惠券
+		
+		//express_method:express_method,pick_mobile:pick_mobile,pick_id:pick_id,pick_name:pick_name
+		$pick_up_id = I('post.pick_id');//$data_s['pick_up_id'];
+		$dispatching = I('post.dispatching');//$data_s['dispatching'];
+		$ziti_name = I('post.pick_name');//$data_s['ziti_name'];
+		$ziti_mobile = I('post.pick_mobile');//$data_s['ziti_mobile'];
+	
+	    $order_msg_arr = explode('@,@', $order_msg_str);
+	
+	    $msg_arr = array();
+	    foreach($order_msg_arr as $val)
+	    {
+	        $tmp_val = explode('@_@', $val);
+	        $msg_arr[ $tmp_val[0] ] = $tmp_val[1];
+	    }
+		
+		$member_id = session('user_auth.uid');
+		$order_quan_arr = array();
+		
+		if( !empty($quan_arr) )
+		{
+			foreach($quan_arr as $q_val)
+			{
+				$tmp_q = array();
+				$tmp_q = explode('_',$q_val);
+				
+				$voucher_info =  M('voucher_list')->where( array('id' =>$tmp_q[1],
+				'store_id' =>$tmp_q[0], 'user_id' => session('user_auth.uid'),'consume' =>'N','end_time' => array('gt',time() ) ) )->find();
+			
+				if( !empty($voucher_info) )
+				{
+					$order_quan_arr[$tmp_q[0]] = $tmp_q[1];
+				}
+			}
+			
+		}
+		
+		
+	    
+	    $cart=new \Lib\Cart();
+	
+	    // 验证商品数量
+	  
+	    $buy_type = I('post.buy_type');
+	
+	    $is_pin = 0;
+	    if($buy_type == 'pin')
+	    {
+	        $is_pin = 1;
+	    }
+	    $goodss = $cart->get_all_goods($buy_type,1);
+		
+		$seller_goodss = array();
+		$del_integral = 0;
+		
+		foreach($goodss as $key => $val)
+		{
+			if($buy_type == 'dan')
+			{
+				$new_key = 'cart.'.$key;
+				$s = session($new_key);
+				
+			
+				if( isset($s['can_del']) && $s['can_del'] == 1)
+				{
+					$cart->remove($key);
+				}else if(isset($s['old_quantity'])){
+					
+					$s['quantity'] = $s['old_quantity'];
+					
+					session($new_key,$s);
+				}
+			}
+			$goods_store_field =  M('goods')->field('store_id')->where( array('goods_id' => $val['goods_id']) )->find();
+			$seller_goodss[ $goods_store_field['store_id'] ][$key] = $val;
+		}
+		
+		
+	    //付款人
+	    $payment=M('Member')->find(session('user_auth.uid'));
+	
+	    //收货人
+	    $add_where = array('member_id'=>session('user_auth.uid'));
+	    $address = M('address')->where( $add_where )->order('is_default desc,address_id desc')->find();
+		
+		$pay_total = 0;
+		//M('order_all')
+		$order_all_data = array();
+		$order_all_data['member_id'] = session('user_auth.uid');
+		$order_all_data['order_num_alias'] = build_order_no(session('user_auth.uid'));;
+		$order_all_data['transaction_id'] = '';
+		$order_all_data['order_status_id'] = 3;
+		$order_all_data['is_pin'] = $is_pin;
+		$order_all_data['paytime'] = 0;
+		
+		$order_all_data['addtime'] = time();
+		
+		$order_all_id = M('order_all')->add($order_all_data);
+		
+		 
+		$integral_model = D('Seller/Integral');
+		
+		foreach($seller_goodss as $kk => $vv)
+		{
+			$data = array();
+	
+			$data['member_id']=session('user_auth.uid');
+			$data['name']=session('user_auth.username');
+		
+			$data['telephone']=$address['telephone'];
+		
+			$data['shipping_name']=$address['name'];
+			$data['shipping_address']=$address['address'];
+			$data['shipping_tel']=$address['telephone'];
+		
+			$data['shipping_province_id']=$address['province_id'];
+			$data['shipping_city_id']=$address['city_id'];
+			$data['shipping_country_id']=$address['country_id'];
+		
+			$data['shipping_method'] = 0;
+			
+			$data['delivery']=$dispatching;
+			$data['pick_up_id']=$pick_up_id;
+			$data['ziti_name']=$ziti_name;
+			$data['ziti_mobile']=$ziti_mobile;
+		
+		
+			$data['payment_method']=$pay_method;
+		
+			$data['address_id']= $address['address_id'];
+			//quan_arr
+			$data['voucher_id'] = isset($order_quan_arr[$kk]) ? $order_quan_arr[$kk]:0;
+		
+			$data['user_agent']=$_SERVER['HTTP_USER_AGENT'];
+			$data['date_added']=time();
+		
+			$hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
+			$subject='';
+			$fare = 0;
+				
+			$goodss = $vv;
+
+			$trans_free_toal = 0;//运费
+
+			$goods_data = array();
+			$order_total = 0;
+			$is_lottery = 0;
+			$is_integral = 0;
+			
+			foreach($goodss as $key => $good)
+			{
+				if($good['shipping']==1)
+				{
+					//统一运费
+					$trans_free_toal += $good['goods_freight'];
+					$trans_free = $good['goods_freight'];
+				}else {
+					//运费模板
+					$trans_free = D('Home/Transport')->calc_transport($good['transport_id'], $good['quantity']*$good['weight'], $address['city_id'] );
+					$trans_free_toal +=$trans_free;
+				}
+				$goods_info = explode(':', $key);
+
+				$goods_id = $goods_info[0];
+
+				
+				
+				if (!empty($goods_info[1])) {
+					$options = base64_decode($goods_info[1]);
+				} else {
+					$options = '';
+				}
+				$order_total += $good['total'];
+
+
+				$tp_goods_info = M('goods')->field('store_id,type')->where( array('goods_id' =>$good['goods_id'] ) )->find();
+				
+				if($tp_goods_info['type'] == 'lottery')
+				{
+					$is_lottery = 1;
+				}
+				
+				if($tp_goods_info['type'] == 'integral')
+				{
+					$is_integral = 1;
+					$is_pin = 0;
+					$check_result = $integral_model->check_user_score_can_pay($member_id, $good['sku_str'], $good['goods_id'] );
+					if($check_result['code'] == 1)
+					{
+						die();
+					}
+				}
+				
+				$goods_data[] = array(
+					'goods_id'   => $good['goods_id'],
+					'store_id' => $tp_goods_info['store_id'],
+					'name'       => $good['name'],
+					'model'      => $good['model'],
+					'is_pin' => $is_pin,
+					'pin_id' => $good['pin_id'],
+					'header_disc' => $good['header_disc'],
+					'option'     => $options,
+					'quantity'   => $good['quantity'],
+					'shipping_fare' => $trans_free,
+					'price'      => $good['price'],
+					'total'      => $good['total'],
+					'comment' => htmlspecialchars($msg_arr[$key])
+				);
+
+			}
+			$data['type'] = 'normal';
+			if($is_pin == 1)
+			{
+				$data['type'] = 'pintuan';
+				if($is_lottery == 1)
+				{
+					$data['type'] = 'lottery';
+				}
+			}
+			if($is_integral == 1)
+			{
+				$data['type'] = 'integral';
+				$is_pin = 0;
+			}
+			
+			$data['shipping_fare'] = floatval($trans_free_toal);
+				
+			$data['store_id']= $kk;
+			
+		   // $tp_goods_info['store_id'],
+			
+			
+			
+			
+			$data['goodss'] = $goods_data;
+			$data['order_num_alias']=build_order_no($kk);
+				
+			$data['totals'][0]=array(
+				'code'=>'sub_total',
+				'title'=>'商品价格',
+				'text'=>'¥'.$order_total,
+				'value'=>$order_total
+			);
+			$data['totals'][1]=array(
+				'code'=>'shipping',
+				'title'=>'运费',
+				'text'=>'¥'.$trans_free_toal,
+				'value'=>$trans_free_toal
+			);
+				
+			$data['totals'][2]=array(
+				'code'=>'total',
+				'title'=>'总价',
+				'text'=>'¥'.($order_total+$trans_free_toal),
+				'value'=>($order_total+$trans_free_toal)
+			);
+			
+			
+			if($data['voucher_id'] > 0) {
+				$voucher_info = M('voucher_list')->where( array('id' => $data['voucher_id']) )->find();
+				$data['voucher_credit'] = $voucher_info['credit'];
+				M('voucher_list')->where( array('id' => $data['voucher_id']) )->save( array('consume' => 'Y') );
+			} else {
+				$data['voucher_credit'] = 0;
+			}
+					
+			$data['total']=($order_total+$trans_free_toal- $data['voucher_credit'] );
+
+			//积分商城
+			if($data['type'] == 'integral')
+			{
+				$del_integral += $order_total;//扣除积分
+				$data['total'] = 0;
+				$order_total = 0;
+			}			
+			$oid=D('Order')->addOrder($data);
+			
+			if($data['delivery'] == 'pickup')
+			{
+				$verify_bool = true;
+				$verifycode = 0;
+				while($verify_bool)
+				{
+					$code  = (ceil(time()/100)+rand(10000000,40000000)).rand(1000,9999);
+					$verifycode = $code ? $code : rand(100000,999999);
+					$verifycode = str_replace('1989','9819',$verifycode);
+					$verifycode = str_replace('1259','9521',$verifycode);
+					$verifycode = str_replace('12590','95210',$verifycode);
+					$verifycode = str_replace('10086','68001',$verifycode);
+					
+					$pick_order = M('pick_order')->where( array('pick_sn' => $verifycode) )->find();
+					if(empty($pick_order))
+					{
+						$verify_bool = false;
+					}
+				}
+				$pick_data = array();
+				$pick_data['pick_sn'] = $verifycode;
+				$pick_data['pick_id'] = $pick_up_id;
+				$pick_data['order_id'] = $oid;
+				$pick_data['state'] = 0;
+				
+				$pick_data['ziti_name'] = $ziti_name;
+				$pick_data['ziti_mobile'] = $ziti_mobile;
+				
+			
+				$pick_data['addtime'] = time();
+				M('pick_order')->add($pick_data);
+			}
+			$pay_total = $pay_total + $order_total+$trans_free_toal- $data['voucher_credit'];
+			
+			
+			$order_relate_data = array();
+			$order_relate_data['order_all_id'] = $order_all_id;
+			$order_relate_data['order_id'] = $oid;
+			$order_relate_data['addtime'] = time();
+			
+			M('order_relate')->add($order_relate_data);
+		}
+		M('order_all')->where( array('id' => $order_all_id) )->save( array('total_money' => $pay_total) );
+		
+	    
+	
+	        if($order_all_id){
+	            //session('cart_total',null);
+	            $order['notify_url']=C('SITE_URL').U('Payment/alipay_notify');
+	            $order['return_url']=C('SITE_URL').U('Payment/alipay_return');
+	            $order['order_type']='goods_buy';
+	            $order['subject']=$subject;
+	            $order['name']=session('shipping_name');
+	            $order['order_num_alias']=$data['order_num_alias'];
+	            $order['pay_total']=($order_total+$trans_free_toal);
+	            //free_tuan
+	            
+	            //session('back_cart_address_id',null);
+	            //session('cart',null);
+	            //session('total',null);
+	            //session('shipping_address_id',null);
+	            //session('back_order_id',$oid);
+	            	
+	            if($data['total']<=0 )
+	            {
+					//检测是否需要扣除积分
+					//var_dump($del_integral,$is_integral );die();
+					if($del_integral> 0 && $is_integral == 1)
+					{
+						//
+						$integral_model->charge_member_score( $member_id, $del_integral,'out', 'orderbuy', $oid);
+					}
+	                $this->yuer_payreturn($oid); //测试使用
+	            }else {
+	                $url=$this->pay_api('wxpay', $order_all_id);
+	            }
+	            	
+	            die();
+	        }else{
+	
+	            echo 9999;die();
+	            $url=U('/checkout');
+	            @header("Location: ".$url);
+	            	
+	            die();
+	        }
+	
+	  
+	    	
+	}
+	//写入订单
+	function pay2(){
+		$json=array();
+		if(I('token')!=md5(session('token'))){
+			$url=U('/checkout');
+			@header("Location: ".$url);
+			die();
+		}		
+
+		$cart=new \Lib\Cart();	
+		
+		// 验证商品数量		
+		$goodss = $cart->get_all_goods();
+		
+		//付款人
+		$payment=M('Member')->find(session('user_auth.uid'));
+		
+		//收货人 
+		$shipping=M('Address')->find(session('shipping_address_id'));
+		
+		$data['member_id']=session('user_auth.uid');
+		$data['name']=session('user_auth.username');
+		
+		$data['telephone']=$payment['telephone'];
+		
+		$data['shipping_name']=$shipping['name'];
+		$data['shipping_address']=$shipping['address'];
+		$data['shipping_tel']=$shipping['telephone'];
+		
+		$data['shipping_province_id']=$shipping['province_id'];
+		$data['shipping_city_id']=$shipping['city_id'];
+		$data['shipping_country_id']=$shipping['country_id'];		
+		
+		$data['shipping_method'] = session('express_id');
+		$data['delivery']=session('shipping_method');
+		
+		
+		$data['payment_method']=session('payment_method');
+		
+		$data['address_id']=session('shipping_address_id');
+		
+		$data['voucher_id']=session('payment_voucher_id');
+		//payment_voucher_id
+
+		$data['user_agent']=$_SERVER['HTTP_USER_AGENT'];
+		$data['date_added']=time();
+		$data['comment']=session('remark');
+		$hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
+		$subject='';
+		$fare = 0;
+		if($goodss){				
+		    
+				/**
+				$sm=D('Transport')->calc_transport(session('shipping_method'),
+				session('quantity'),
+				$shipping['city_id']
+				);	
+				**/
+				
+				$sm = D('Transport')->calc_transport(null,
+				session('quantity'),
+				$shipping['city_id']
+				);
+				
+				$t=0;		
+				foreach ($goodss as $goods) {
+					
+					$option_data = array();
+	
+					foreach ($goods['option'] as $option) {
+						
+						$value = $option['value'];						
+	
+						$option_data[] = array(
+							'goods_option_id'       => $option['goods_option_id'],
+							'goods_option_value_id' => $option['goods_option_value_id'],
+							'option_id'               => $option['option_id'],
+							'option_value_id'         => $option['option_value_id'],								   
+							'name'                    => $option['name'],
+							'value'                   => $value,
+							'type'                    => $option['type']
+						);					
+					}
+					
+					$tp_goods_info = M('goods')->field('store_id,express_list')->where( array('goods_id' =>$hashids->decode($goods['goods_id'])) )->find();
+					
+					$express_list_arr = unserialize($tp_goods_info['express_list']);
+					
+					if($data['delivery'] == 'express')
+					{
+						$fare = isset($express_list_arr[$data['shipping_method']]) ? $express_list_arr[$data['shipping_method']]['price'] : 0;
+					}
+					
+					$t+=$goods['total'];					
+					
+					$goods['total'] = $goods['total'];
+					
+					$goods_data[] = array(
+						'goods_id'   => $goods['goods_id'],
+						'name'       => $goods['name'],
+					    'is_header_disc' => $goods['is_header_disc'],
+					    'store_id'   => $tp_goods_info['store_id'],
+						'model'      => $goods['model'],		
+						'option'     => $option_data,						
+						'quantity'   => $goods['quantity'],
+						'pin_type'   => $goods['pin_type'],
+					    'pin_id'     => $goods['pin_id'],
+						'price'      => $goods['price'],
+						'total'      => $goods['total']				
+					); 		
+			
+					$subject.=$goods['name'].' ';					
+						
+					}
+					
+					if($data['voucher_id'] > 0) {
+						$voucher_info = M('voucher_list')->where( array('id' => $data['voucher_id']) )->find();
+						$data['voucher_credit'] = $voucher_info['credit'];
+						M('voucher_list')->where( array('id' => $data['voucher_id']) )->save( array('consume' => 'Y') );
+					} else {
+						$data['voucher_credit'] = 0;
+					}
+					
+					$data['shipping_fare'] = floatval($fare);
+					
+					$data['total']=($t+$fare - $data['voucher_credit']);
+					$data['goodss'] = $goods_data;
+					$data['order_num_alias']=build_order_no($data['member_id']);
+					
+					$data['totals'][0]=array(
+						'code'=>'sub_total',
+						'title'=>'商品价格',
+						'text'=>'¥'.$t,
+						'value'=>$t				
+					);
+					$data['totals'][1]=array(
+						'code'=>'shipping',
+						'title'=>'运费',
+						'text'=>'¥'.$fare,
+						'value'=>$fare				
+					);				
+					$data['totals'][2]=array(
+						'code'=>'voucher',
+						'title'=>'优惠券',
+						'text'=>'¥'.$data['voucher_credit'],
+						'value'=>$data['voucher_credit']				
+					);	
+					$data['totals'][3]=array(
+						'code'=>'total',
+						'title'=>'总价',
+						'text'=>'¥'.($t+$fare- $data['voucher_credit']),
+						'value'=>($t+$fare- $data['voucher_credit'])				
+					);
+				
+				
+				$oid=D('Order')->addOrder($data);
+				
+				//delivery  pickup pick_up_id
+				if($data['delivery'] == 'pickup')
+				{
+					$verify_bool = true;
+					$verifycode = 0;
+					while($verify_bool)
+					{
+						$code  = (ceil(time()/100)+rand(10000000,40000000)).rand(1000,9999);
+						$verifycode = $code ? $code : rand(100000,999999);
+						$verifycode = str_replace('1989','9819',$verifycode);
+						$verifycode = str_replace('1259','9521',$verifycode);
+						$verifycode = str_replace('12590','95210',$verifycode);
+						$verifycode = str_replace('10086','68001',$verifycode);
+						
+						$pick_order = M('pick_order')->where( array('pick_sn' => $verifycode) )->find();
+						if(empty($pick_order))
+						{
+							$verify_bool = false;
+						}
+					}
+					$pick_data = array();
+					$pick_data['pick_sn'] = $verifycode;
+					$pick_data['pick_id'] = session('pick_up_id');
+					$pick_data['order_id'] = $oid;
+					$pick_data['state'] = 0;
+					$pick_data['addtime'] = time();
+					M('pick_order')->add($pick_data);
+				}
+				if($oid){				
+					session('cart_total',null);
+					$order['notify_url']=C('SITE_URL').U('Payment/alipay_notify');
+					$order['return_url']=C('SITE_URL').U('Payment/alipay_return');
+					$order['order_type']='goods_buy';
+					$order['subject']=$subject;
+					$order['name']=session('shipping_name');
+					$order['order_num_alias']=$data['order_num_alias'];
+					$order['pay_total']=($t+$sm['price']);			
+					//free_tuan
+					$order_goods_info = M('order_goods')->where( array('order_id' => $oid) )->find();
+					
+					session('back_cart_address_id',null);
+					session('cart',null);
+					session('total',null);					
+					session('shipping_address_id',null);	
+					session('back_order_id',$oid);
+					
+					if($data['total']<=0 || $order_goods_info['free_tuan'] ==1)
+					{
+					    $this->yuer_payreturn($data['order_num_alias']); //测试使用
+					}else {
+					    $url=$this->pay_api('wxpay', $order);
+					}
+					
+					die();
+				}else{
+				    
+				    echo 9999;die();
+					$url=U('/checkout');
+					@header("Location: ".$url);
+					
+					die();
+				}
+				
+			}
+			
+	}
+
+	public function success()
+	{
+	    $order_id = I('get.order_id');
+	    //removeAll
+	    $cart=new \Lib\Cart();
+	    $cart->removeAll();
+	    session('total',null);
+	     
+	    $pin_order = M('pin_order')->field('pin_id')->where( array('order_id' =>$order_id) )->find();
+	     
+	    //Order/info/id/14
+	     
+	    $redir_url = U('Order/info', array('id' => $order_id));
+	    if(!empty($pin_order))
+	    {
+	        $hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
+	        $group_order_id = $hashids->encode($order_id);
+	         
+	        $redir_url = U('Group/info', array('group_order_id' => $group_order_id,'is_show' =>1));
+			redirect($redir_url,0);
+	    }
+	    $this->redir_url = $redir_url;
+	     
+	    $this->order_id = $order_id;
+	    $this->display();
+	}
+	
+	function de_bug($content){
+		$file = ROOT_PATH."/Tmp/wxpay_debug.php";
+		file_put_contents($file,$content);	
+	}
+
+	//数据以post方式返回
+	function alipay_notify(){
+		
+		$alipay= new \Lib\Payment\Alipay(get_payment_config('alipay'));
+		
+		$verify_result = $alipay->verifyNotify();
+		
+		if($verify_result) {
+			
+			//$this->de_bug('success');
+			
+			//商户订单号	
+			//$out_trade_no = $_POST['out_trade_no'];	
+			//支付宝交易号	
+			//$trade_no = $_POST['trade_no'];	
+			//交易状态
+			//$trade_status = $_POST['trade_status'];
+			
+			if($_POST['trade_status'] == 'TRADE_FINISHED') {
+				//$this->de_bug('TRADE_FINISHED');
+				
+		    }
+		    else if ($_POST['trade_status'] == 'TRADE_SUCCESS') {
+				//$this->de_bug('TRADE_SUCCESS');
+				
+				$order=M('Order')->getByOrderNumAlias($_POST['out_trade_no']);
+				
+				if($order&&($order['order_status_id']!=C('paid_order_status_id'))){
+						//支付完成						
+						$o['order_id']=$order['order_id'];
+						$o['order_status_id']=C('paid_order_status_id');
+						$o['date_modified']=time();
+						$o['pay_time']=time();
+						M('Order')->save($o);
+						
+						$oh['order_id']=$order['order_id'];
+						$oh['order_status_id']=C('paid_order_status_id');
+				
+						$oh['comment']='买家已付款';
+						$oh['date_added']=time();
+						$oh['notify']=1;
+						M('OrderHistory')->add($oh);
+						
+						$model=new \Admin\Model\OrderModel();	   
+					    $this->order=$model->order_info($order['order_id']);
+					    $html=$this->fetch('Mail:order');				   
+					    think_send_mail($order['email'],$order['name'],'下单成功-'.C('SITE_NAME'),$html);
+						
+						storage_user_action(session('user_auth.uid'),session('user_auth.username'),C('FRONTEND_USER'),'支付了订单 '.$order['order_num_alias']);
+						
+						//@header("Location: ".U('/pay_success'));	
+											
+				}
+				
+		        
+				echo "success";		
+		    }
+		
+			
+			
+		}else{
+			//$this->de_bug('fail');
+			echo "fail";
+		}
+		
+	}
+	
+	private function yuer_payreturn($order_id){
+	    // $order=M('Order')->getByOrderNumAlias($out_trade_no);
+	    $order=M('Order')->where( array('order_id' => $order_id) )->find();
+	    $out_trade_no = $order['order_num_alias'];
+	     
+	    if($order['order_status_id']==C('paid_order_status_id')){
+	        @header("Location: ".U('/pay_success'));
+	        die;
+	    }
+	     
+	    if($order&&($order['order_status_id']!=C('paid_order_status_id'))){
+	        //支付完成
+	        if(true){
+	             
+	            
+	
+	            $goods_model = D('Home/Goods');
+	
+	            $kucun_method = C('kucun_method');
+	            $kucun_method  = empty($kucun_method) ? 0 : intval($kucun_method);
+	            if($kucun_method == 1)
+	            {//支付完减库存,增加销量
+	                $order_goods_list = M('order_goods')->where( array('order_id' => $order['order_id']) )->select();
+	                foreach($order_goods_list as $order_goods)
+	                {
+	                    //销量增加 del_goods_mult_option_quantity($order_id,$option,$goods_id,$quantity,$type='1')
+	                    $goods_model->del_goods_mult_option_quantity($order['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity'],1);
+	                    //扣除库存
+	                }
+	            }
+	
+	            $oh['order_id']=$order['order_id'];
+	            $oh['order_status_id'] = 1;
+	            $oh['comment']='买家已付款';
+	            $oh['date_added']=time();
+	            $oh['notify']=0;
+	            M('OrderHistory')->add($oh);
+	             
+	            $pin_order = M('pin_order')->where( array('order_id' =>$order['order_id'] ) )->find();
+	           
+	            if(!empty($pin_order))
+	            {
+					$o = array();
+					$o['order_id']=$order['order_id'];
+					$o['order_status_id']= 2;
+					$o['date_modified']=time();
+					$o['pay_time']=time();
+					M('Order')->save($o);
+	                //group_order_id
+	                $pin_model = D('Home/Pin');
+	                $is_pin_success = $pin_model->checkPinSuccess($pin_order['pin_id']);
+	
+	                if($is_pin_success) {
+	                    //todo send pintuan success notify
+	                    $pin_model->updatePintuanSuccess($pin_order['pin_id']);
+						
+	                }else{
+						
+					}
+	            }else{
+					$o = array();
+					$o['order_id']=$order['order_id'];
+					$o['order_status_id']= 1;
+					$o['date_modified']=time();
+					$o['pay_time']=time();
+					M('Order')->save($o);
+					$share_model = D('Seller/Fissionsharing');
+					$share_model->send_order_commiss_money( $order['order_id'] );
+				}
+	             
+	            $result = array('code' => 1, 'url' => U('Payment/success',array('order_id' => $order['order_id'])));
+	             
+	            echo json_encode($result);
+	            die();
+	            
+	        }
+	    }
+	}
+	
+	
+	private function yuer_payreturn2($out_trade_no){
+	    $order=M('Order')->getByOrderNumAlias($out_trade_no);
+	   
+	    if($order['order_status_id']==C('paid_order_status_id')){
+	        @header("Location: ".U('/pay_success'));
+	        die;
+	    }
+	    
+	    if($order&&($order['order_status_id']!=C('paid_order_status_id'))){
+	        //支付完成
+	        if(true){
+	            	 
+	                
+	            $o['order_id']=$order['order_id'];
+	            $o['order_status_id']= $order['is_pin'] == 1 ? 2:1;
+	            $o['date_modified']=time();
+	            $o['pay_time']=time();
+	            M('Order')->save($o);
+				
+				$goods_model = D('Home/Goods');
+				
+				$kucun_method = C('kucun_method');
+				$kucun_method  = empty($kucun_method) ? 0 : intval($kucun_method);
+				if($kucun_method == 1)
+				{//支付完减库存,增加销量
+					$order_goods_list = M('order_goods')->where( array('order_id' => $order['order_id']) )->select();
+					foreach($order_goods_list as $order_goods)
+					{
+						//销量增加 rela_goodsoption_valueid
+						$goods_model->del_goods_mult_option_quantity($order['order_id'],$order_goods['quantity'],1);
+						//扣除库存
+					}
+				}
+	            	
+	            $oh['order_id']=$order['order_id'];
+	            $oh['order_status_id']= $order['is_pin'] == 1 ? 2:1;
+	            $oh['comment']='买家已付款';
+	            $oh['date_added']=time();
+	            $oh['notify']=1;
+	            M('OrderHistory')->add($oh);
+	            
+	            //发送购买通知
+	            $weixin_nofity = D('Home/Weixinnotify');
+	            $weixin_nofity->orderBuy($order);
+	            
+	            $model=new \Admin\Model\OrderModel();
+	            $this->order=$model->order_info($order['order_id']);
+	           
+	            $hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
+	            $order_id = $hashids->encode($order['order_id']);
+	            
+	            if($order['is_pin'] == 1)
+	            {
+	                $pin_model = D('Home/Pin');
+	                $is_pin_success = $pin_model->checkPinSuccess($order['pin_id']);
+	                
+	                if($is_pin_success) {
+	                    //todo send pintuan success notify
+	                    $pin_model->updatePintuanSuccess($order['pin_id']);
+	                }
+	                $refurl = C('SITE_URL')."index.php?s=/Group/info/group_order_id/{$order_id}/is_show/1";
+	                @header("Location: ".$refurl);
+	                die();
+	            } else {
+	                @header("Location: ".U('Order/info',array('id' =>$order['order_id'] )));
+	                die();
+	            }
+	           
+	        }
+	    }
+	}
+
+	function alipay_return(){
+		
+		$alipay= new \Lib\Payment\Alipay(get_payment_config('alipay'));
+		
+		//对进入的参数进行远程数据判断
+		$verify = $alipay->return_verify();
+	
+		if($verify){
+			$order=M('Order')->getByOrderNumAlias($_GET['out_trade_no']);
+			
+			if($order['order_status_id']==C('paid_order_status_id')){
+				@header("Location: ".U('/pay_success'));	
+				die;
+			}
+			
+			if($order&&($order['order_status_id']!=C('paid_order_status_id'))){
+				//支付完成
+				if($_GET['trade_status']=='TRADE_SUCCESS'){					
+					
+					$o['order_id']=$order['order_id'];
+					$o['order_status_id']=C('paid_order_status_id');
+					$o['date_modified']=time();
+					$o['pay_time']=time();
+					M('Order')->save($o);
+					
+					$oh['order_id']=$order['order_id'];
+					$oh['order_status_id']=C('paid_order_status_id');
+			
+					$oh['comment']='买家已付款';
+					$oh['date_added']=time();
+					$oh['notify']=1;
+					M('OrderHistory')->add($oh);
+					
+					$model=new \Admin\Model\OrderModel();	   
+				    $this->order=$model->order_info($order['order_id']);
+				    $html=$this->fetch('Mail:order');				   
+				    think_send_mail($order['email'],$order['name'],'下单成功-'.C('SITE_NAME'),$html);
+					
+					storage_user_action(session('user_auth.uid'),session('user_auth.username'),C('FRONTEND_USER'),'支付了订单 '.$order['order_num_alias']);
+					
+					@header("Location: ".U('/pay_success'));	
+				}						
+			}else{
+				die('订单不存在');
+			}
+			
+		}else{
+			die('支付失败');
+		}		
+		
+	}
 }

+ 1144 - 0
Modules/Home/Controller/PaymentController.class.php.back

@@ -0,0 +1,1144 @@
+<?php
+/**
+ * 播播资源
+ *
+ * ==========================================================================
+ * @link      https://www.ttbobo.com/
+ * @copyright Copyright (c) 2015 liofis.com. 
+ * @license   https://www.ttbobo.com/license.html License
+ * ==========================================================================
+ *
+ * @author    fish
+ *
+ */
+namespace Home\Controller;
+
+class PaymentController extends CommonController {
+	
+	protected function _initialize()
+    {
+    	parent::_initialize();
+	}
+	
+	//会员中心页面,去付款
+	function confirm_pay(){
+		if(I('token')!=md5(session('pay_token'))){
+			$url=U('/checkout');
+			@header("Location: ".$url);
+			die();
+		}
+		$order=M('order')->where(array('order_id'=>get_url_id('id')))->find();
+		
+		$data['notify_url']=C('SITE_URL').U('Payment/alipay_notify');
+		$data['return_url']=C('SITE_URL').U('Payment/alipay_return');
+		$data['order_type']='goods_buy';
+		$data['subject']='购买商品';
+		$data['name']=$order['shipping_name'];
+		$data['pay_order_no']=$order['order_num_alias'];
+		$data['pay_total']=(float)$order['total'];		
+		
+		storage_user_action(session('user_auth.uid'),session('user_auth.username'),C('FRONTEND_USER'),'点击了去支付订单 '.$order['order_num_alias']);
+		
+		$url=$this->pay_api($order['payment_code'], $data);			
+		
+		@header("Location: ".$url);
+	
+		die();		
+	}
+	
+	/**
+		接受快递鸟通知
+	**/
+	function kuaidiniao()
+	{
+		
+		echo json_encode(array('Success'=>true));
+		
+		$request_data = I('post.RequestData');
+		
+		$request_data = htmlspecialchars_decode($request_data);
+
+		$request_data_arr = json_decode($request_data,true);
+		
+		foreach($request_data_arr['Data'] as $data)
+		{
+			$LogisticCode = $data['LogisticCode'];
+			$trace = serialize($data['Traces']);
+			M('order')->where( array('shipping_no' => $LogisticCode) )->save( array('shipping_traces' => $trace) );
+		}
+		
+		
+	}
+	
+	/**
+	 * 提交订单支付
+	 * @param unknown $order_id
+	 */
+	
+	function order_pay()
+	{
+	   $order_id =  I('get.order_id',0);
+	   if($order_id > 0)
+	   {
+	       $order = M('order')->where( array('order_id' => $order_id) )->find();   
+		  
+		   
+	       if($order['order_status_id'] == 3)
+	       {
+			   if($order['total'] <= 0)
+			   {
+				   $this->yuer_payreturn($order['order_num_alias']);
+			   } else {
+				    $order['payment_code'] = empty($order['payment_code']) ? 'wxpay': $order['payment_code'];
+					 
+					//单独支付一个店铺的订单
+					M('order_relate')->where( array('order_id' => $order_id) )->delete();
+					
+					$order_all_data = array();
+					$order_all_data['member_id'] = session('user_auth.uid');
+					$order_all_data['order_num_alias'] = build_order_no(session('user_auth.uid'));;
+					$order_all_data['transaction_id'] = '';
+					$order_all_data['order_status_id'] = 3;
+					$order_all_data['is_pin'] = $order['is_pin'];
+					$order_all_data['paytime'] = 0;
+					$order_all_data['total_money'] = $order['total'];
+					$order_all_data['addtime'] = time();
+					
+					$order_all_id = M('order_all')->add($order_all_data);
+						
+					$order_relate_data = array();
+					$order_relate_data['order_all_id'] = $order_all_id;
+					$order_relate_data['order_id'] = $order_id;
+					$order_relate_data['addtime'] = time();
+					M('order_relate')->add($order_relate_data);
+					
+				
+					$wxpay_url = C('SITE_URL')."index.php?s=/Payment/wxpay_order/pay_order_no/{$order_all_data[order_num_alias]}";
+					header('Location: '.$wxpay_url);
+					die();
+			   }
+	           
+	       }
+	   }
+	}
+	
+	
+	/**
+	 * $pay_type 购买商品,还是预存款
+	 * $order 订单信息
+	 */
+	function pay_api($payment_method,$order_all_id){
+		
+		$order_all = M('order_all')->where( array('id' => $order_all_id) )->find();
+		
+		if($payment_method=='alipay'){			
+			
+			$alipay= new \Lib\Payment\Alipay(get_payment_config('alipay'),$order_all);
+			return $alipay->get_payurl();
+		}
+		//wxpay
+		if($payment_method == 'wxpay')
+		{
+			$wxpay_url = C('SITE_URL')."index.php?s=/Payment/wxpay_order/pay_order_no/{$order_all[order_num_alias]}";
+			echo json_encode( array('code' =>1 ,'url' => $wxpay_url) );
+			die();
+			//header('Location: '.$wxpay_url);
+			//$this->redirect( 'Payment/wxpay_order',array('pay_order_no' => $order['order_num_alias']) );	
+		}
+	}
+	
+	//微信支付通知
+	function weixin_notify()
+	{
+		$lib_path = dirname(dirname( dirname(__FILE__) )).'/Lib/';
+		$data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
+		
+		require_once $lib_path."/Weixin/PayNotifyCallBack.class.php";
+		$type=$_GET['type']=='fyfyfy'?$_GET['type']:false;
+		$notify = new \PayNotifyCallBack();
+		$notify->Handle(false,$type);
+		
+	}
+	
+	//开始微信支付订单
+	function wxpay_order()
+	{
+		$lib_path = dirname(dirname( dirname(__FILE__) )).'/Lib/';
+		$data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
+		
+		RecursiveMkdir($data_path);
+		
+		require_once $lib_path."/Weixin/JsApiPay.class.php";
+		
+		
+		$pay_order_no = I('get.pay_order_no',0);
+		
+		$order = M('order_all')->where(array('order_num_alias'=>$pay_order_no, 'member_id' => is_login() ))->find();
+		
+		if(empty($order)) {
+			$this->redirect( U('Index/index') );	
+		}
+		
+		//初始化日志
+		$logHandler= new \CLogFileHandler( $data_path .date('Y-m-d').'.log');
+		
+		$log = \Log::Init($logHandler, 15);
+		
+		$member_info = M('member')->where( array('member_id' => $order['member_id']) )->find();
+		
+		//①、获取用户openid
+		$tools = new  \JsApiPay();
+		//$order['total'] = 0.01;
+		//②、统一下单
+		$input = new \WxPayUnifiedOrder();
+		$input->SetBody(mb_substr('商品购买', 0, 30, 'utf-8'));
+		$input->SetAttach(mb_substr('商品购买', 0, 30, 'utf-8'));
+		$input->SetOut_trade_no($order['id'].'-'.time());
+		$input->SetTotal_fee( ( $order['total_money'] *100) );
+		$input->SetTime_start(date("YmdHis"));
+		$input->SetTime_expire(date("YmdHis", time() + 600));
+		$input->SetGoods_tag("");
+		
+		$notify_url = C('SITE_URL').'notify.php';
+		
+		$input->SetNotify_url($notify_url);
+		
+		$input->SetTrade_type("JSAPI");
+		$input->SetOpenid($member_info['openid']);
+		
+	
+		$order_str = \WxPayApi::unifiedOrder($input);
+		
+		$jsApiParameters = $tools->GetJsApiParameters($order_str);
+		//var_dump($jsApiParameters);die();
+		//获取共享收货地址js函数参数
+		$editAddress = $tools->GetEditAddressParameters();
+		
+		$hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
+		//$order_id = $hashids->encode($order['id']); 
+		
+		if($order['is_pin'] == 1)
+		{
+			$order_relate =  M('order_relate')->where( array('order_all_id' => $order['id']) )->find();
+			$order_id = $hashids->encode($order_relate['order_id']); 
+			
+			$refurl = C('SITE_URL')."index.php?s=/Group/info/group_order_id/{$order_id}/is_show/1";
+		} else {
+			$refurl = C('SITE_URL')."index.php?s=/order/order_all_info/id/{$order[id]}";
+		}
+		$backurl = C('SITE_URL')."index.php?s=/order/order_all_info/id/{$order[id]}";
+		
+		$this->order_id = $order['id'];
+		
+		
+		$this->refurl = $refurl;
+		$this->backurl = $backurl;
+		$this->jsApiParameters = $jsApiParameters;
+		$this->editAddress = $editAddress;
+		
+		$this->display();
+		
+	}
+	
+	//写入订单
+	function pay(){
+	    $json=array();
+	
+	//pickup express
+	    $pay_method = I('post.pay_method');//支付类型
+	    $order_msg_str = I('post.order_msg_str');//商品订单留言
+		$quan_arr = I('post.quan_arr');//使用优惠券
+		
+		//express_method:express_method,pick_mobile:pick_mobile,pick_id:pick_id,pick_name:pick_name
+		$pick_up_id = I('post.pick_id');//$data_s['pick_up_id'];
+		$dispatching = I('post.dispatching');//$data_s['dispatching'];
+		$ziti_name = I('post.pick_name');//$data_s['ziti_name'];
+		$ziti_mobile = I('post.pick_mobile');//$data_s['ziti_mobile'];
+	
+	    $order_msg_arr = explode('@,@', $order_msg_str);
+	
+	    $msg_arr = array();
+	    foreach($order_msg_arr as $val)
+	    {
+	        $tmp_val = explode('@_@', $val);
+	        $msg_arr[ $tmp_val[0] ] = $tmp_val[1];
+	    }
+		
+		$member_id = session('user_auth.uid');
+		$order_quan_arr = array();
+		
+		if( !empty($quan_arr) )
+		{
+			foreach($quan_arr as $q_val)
+			{
+				$tmp_q = array();
+				$tmp_q = explode('_',$q_val);
+				
+				$voucher_info =  M('voucher_list')->where( array('id' =>$tmp_q[1],
+				'store_id' =>$tmp_q[0], 'user_id' => session('user_auth.uid'),'consume' =>'N','end_time' => array('gt',time() ) ) )->find();
+			
+				if( !empty($voucher_info) )
+				{
+					$order_quan_arr[$tmp_q[0]] = $tmp_q[1];
+				}
+			}
+			
+		}
+		
+		
+	    
+	    $cart=new \Lib\Cart();
+	
+	    // 验证商品数量
+	  
+	    $buy_type = I('post.buy_type');
+	
+	    $is_pin = 0;
+	    if($buy_type == 'pin')
+	    {
+	        $is_pin = 1;
+	    }
+	    $goodss = $cart->get_all_goods($buy_type,1);
+		
+		$seller_goodss = array();
+		$del_integral = 0;
+		
+		foreach($goodss as $key => $val)
+		{
+			if($buy_type == 'dan')
+			{
+				$new_key = 'cart.'.$key;
+				$s = session($new_key);
+				
+			
+				if( isset($s['can_del']) && $s['can_del'] == 1)
+				{
+					$cart->remove($key);
+				}else if(isset($s['old_quantity'])){
+					
+					$s['quantity'] = $s['old_quantity'];
+					
+					session($new_key,$s);
+				}
+			}
+			$goods_store_field =  M('goods')->field('store_id')->where( array('goods_id' => $val['goods_id']) )->find();
+			$seller_goodss[ $goods_store_field['store_id'] ][$key] = $val;
+		}
+		
+		
+	    //付款人
+	    $payment=M('Member')->find(session('user_auth.uid'));
+	
+	    //收货人
+	    $add_where = array('member_id'=>session('user_auth.uid'));
+	    $address = M('address')->where( $add_where )->order('is_default desc,address_id desc')->find();
+		
+		$pay_total = 0;
+		//M('order_all')
+		$order_all_data = array();
+		$order_all_data['member_id'] = session('user_auth.uid');
+		$order_all_data['order_num_alias'] = build_order_no(session('user_auth.uid'));;
+		$order_all_data['transaction_id'] = '';
+		$order_all_data['order_status_id'] = 3;
+		$order_all_data['is_pin'] = $is_pin;
+		$order_all_data['paytime'] = 0;
+		
+		$order_all_data['addtime'] = time();
+		
+		$order_all_id = M('order_all')->add($order_all_data);
+		
+		 
+		$integral_model = D('Seller/Integral');
+		
+		foreach($seller_goodss as $kk => $vv)
+		{
+			$data = array();
+	
+			$data['member_id']=session('user_auth.uid');
+			$data['name']=session('user_auth.username');
+		
+			$data['telephone']=$address['telephone'];
+		
+			$data['shipping_name']=$address['name'];
+			$data['shipping_address']=$address['address'];
+			$data['shipping_tel']=$address['telephone'];
+		
+			$data['shipping_province_id']=$address['province_id'];
+			$data['shipping_city_id']=$address['city_id'];
+			$data['shipping_country_id']=$address['country_id'];
+		
+			$data['shipping_method'] = 0;
+			
+			$data['delivery']=$dispatching;
+			$data['pick_up_id']=$pick_up_id;
+			$data['ziti_name']=$ziti_name;
+			$data['ziti_mobile']=$ziti_mobile;
+		
+		
+			$data['payment_method']=$pay_method;
+		
+			$data['address_id']= $address['address_id'];
+			//quan_arr
+			$data['voucher_id'] = isset($order_quan_arr[$kk]) ? $order_quan_arr[$kk]:0;
+		
+			$data['user_agent']=$_SERVER['HTTP_USER_AGENT'];
+			$data['date_added']=time();
+		
+			$hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
+			$subject='';
+			$fare = 0;
+				
+			$goodss = $vv;
+
+			$trans_free_toal = 0;//运费
+
+			$goods_data = array();
+			$order_total = 0;
+			$is_lottery = 0;
+			$is_integral = 0;
+			
+			foreach($goodss as $key => $good)
+			{
+				if($good['shipping']==1)
+				{
+					//统一运费
+					$trans_free_toal += $good['goods_freight'];
+					$trans_free = $good['goods_freight'];
+				}else {
+					//运费模板
+					$trans_free = D('Home/Transport')->calc_transport($good['transport_id'], $good['quantity']*$good['weight'], $address['city_id'] );
+					$trans_free_toal +=$trans_free;
+				}
+				$goods_info = explode(':', $key);
+
+				$goods_id = $goods_info[0];
+
+				
+				
+				if (!empty($goods_info[1])) {
+					$options = base64_decode($goods_info[1]);
+				} else {
+					$options = '';
+				}
+				$order_total += $good['total'];
+
+
+				$tp_goods_info = M('goods')->field('store_id,type')->where( array('goods_id' =>$good['goods_id'] ) )->find();
+				
+				if($tp_goods_info['type'] == 'lottery')
+				{
+					$is_lottery = 1;
+				}
+				
+				if($tp_goods_info['type'] == 'integral')
+				{
+					$is_integral = 1;
+					$is_pin = 0;
+					$check_result = $integral_model->check_user_score_can_pay($member_id, $good['sku_str'], $good['goods_id'] );
+					if($check_result['code'] == 1)
+					{
+						die();
+					}
+				}
+				
+				$goods_data[] = array(
+					'goods_id'   => $good['goods_id'],
+					'store_id' => $tp_goods_info['store_id'],
+					'name'       => $good['name'],
+					'model'      => $good['model'],
+					'is_pin' => $is_pin,
+					'pin_id' => $good['pin_id'],
+					'header_disc' => $good['header_disc'],
+					'option'     => $options,
+					'quantity'   => $good['quantity'],
+					'shipping_fare' => $trans_free,
+					'price'      => $good['price'],
+					'total'      => $good['total'],
+					'comment' => htmlspecialchars($msg_arr[$key])
+				);
+
+			}
+			$data['type'] = 'normal';
+			if($is_pin == 1)
+			{
+				$data['type'] = 'pintuan';
+				if($is_lottery == 1)
+				{
+					$data['type'] = 'lottery';
+				}
+			}
+			if($is_integral == 1)
+			{
+				$data['type'] = 'integral';
+				$is_pin = 0;
+			}
+			
+			$data['shipping_fare'] = floatval($trans_free_toal);
+				
+			$data['store_id']= $kk;
+			
+		   // $tp_goods_info['store_id'],
+			
+			
+			
+			
+			$data['goodss'] = $goods_data;
+			$data['order_num_alias']=build_order_no($kk);
+				
+			$data['totals'][0]=array(
+				'code'=>'sub_total',
+				'title'=>'商品价格',
+				'text'=>'¥'.$order_total,
+				'value'=>$order_total
+			);
+			$data['totals'][1]=array(
+				'code'=>'shipping',
+				'title'=>'运费',
+				'text'=>'¥'.$trans_free_toal,
+				'value'=>$trans_free_toal
+			);
+				
+			$data['totals'][2]=array(
+				'code'=>'total',
+				'title'=>'总价',
+				'text'=>'¥'.($order_total+$trans_free_toal),
+				'value'=>($order_total+$trans_free_toal)
+			);
+			
+			
+			if($data['voucher_id'] > 0) {
+				$voucher_info = M('voucher_list')->where( array('id' => $data['voucher_id']) )->find();
+				$data['voucher_credit'] = $voucher_info['credit'];
+				M('voucher_list')->where( array('id' => $data['voucher_id']) )->save( array('consume' => 'Y') );
+			} else {
+				$data['voucher_credit'] = 0;
+			}
+					
+			$data['total']=($order_total+$trans_free_toal- $data['voucher_credit'] );
+
+			//积分商城
+			if($data['type'] == 'integral')
+			{
+				$del_integral += $order_total;//扣除积分
+				$data['total'] = 0;
+				$order_total = 0;
+			}			
+			$oid=D('Order')->addOrder($data);
+			
+			if($data['delivery'] == 'pickup')
+			{
+				$verify_bool = true;
+				$verifycode = 0;
+				while($verify_bool)
+				{
+					$code  = (ceil(time()/100)+rand(10000000,40000000)).rand(1000,9999);
+					$verifycode = $code ? $code : rand(100000,999999);
+					$verifycode = str_replace('1989','9819',$verifycode);
+					$verifycode = str_replace('1259','9521',$verifycode);
+					$verifycode = str_replace('12590','95210',$verifycode);
+					$verifycode = str_replace('10086','68001',$verifycode);
+					
+					$pick_order = M('pick_order')->where( array('pick_sn' => $verifycode) )->find();
+					if(empty($pick_order))
+					{
+						$verify_bool = false;
+					}
+				}
+				$pick_data = array();
+				$pick_data['pick_sn'] = $verifycode;
+				$pick_data['pick_id'] = $pick_up_id;
+				$pick_data['order_id'] = $oid;
+				$pick_data['state'] = 0;
+				
+				$pick_data['ziti_name'] = $ziti_name;
+				$pick_data['ziti_mobile'] = $ziti_mobile;
+				
+			
+				$pick_data['addtime'] = time();
+				M('pick_order')->add($pick_data);
+			}
+			$pay_total = $pay_total + $order_total+$trans_free_toal- $data['voucher_credit'];
+			
+			
+			$order_relate_data = array();
+			$order_relate_data['order_all_id'] = $order_all_id;
+			$order_relate_data['order_id'] = $oid;
+			$order_relate_data['addtime'] = time();
+			
+			M('order_relate')->add($order_relate_data);
+		}
+		M('order_all')->where( array('id' => $order_all_id) )->save( array('total_money' => $pay_total) );
+		
+	    
+	
+	        if($order_all_id){
+	            //session('cart_total',null);
+	            $order['notify_url']=C('SITE_URL').U('Payment/alipay_notify');
+	            $order['return_url']=C('SITE_URL').U('Payment/alipay_return');
+	            $order['order_type']='goods_buy';
+	            $order['subject']=$subject;
+	            $order['name']=session('shipping_name');
+	            $order['order_num_alias']=$data['order_num_alias'];
+	            $order['pay_total']=($order_total+$trans_free_toal);
+	            //free_tuan
+	            
+	            //session('back_cart_address_id',null);
+	            //session('cart',null);
+	            //session('total',null);
+	            //session('shipping_address_id',null);
+	            //session('back_order_id',$oid);
+	            	
+	            if($data['total']<=0 )
+	            {
+					//检测是否需要扣除积分
+					//var_dump($del_integral,$is_integral );die();
+					if($del_integral> 0 && $is_integral == 1)
+					{
+						//
+						$integral_model->charge_member_score( $member_id, $del_integral,'out', 'orderbuy', $oid);
+					}
+	                $this->yuer_payreturn($oid); //测试使用
+	            }else {
+	                $url=$this->pay_api('wxpay', $order_all_id);
+	            }
+	            	
+	            die();
+	        }else{
+	
+	            echo 9999;die();
+	            $url=U('/checkout');
+	            @header("Location: ".$url);
+	            	
+	            die();
+	        }
+	
+	  
+	    	
+	}
+	//写入订单
+	function pay2(){
+		$json=array();
+		if(I('token')!=md5(session('token'))){
+			$url=U('/checkout');
+			@header("Location: ".$url);
+			die();
+		}		
+
+		$cart=new \Lib\Cart();	
+		
+		// 验证商品数量		
+		$goodss = $cart->get_all_goods();
+		
+		//付款人
+		$payment=M('Member')->find(session('user_auth.uid'));
+		
+		//收货人 
+		$shipping=M('Address')->find(session('shipping_address_id'));
+		
+		$data['member_id']=session('user_auth.uid');
+		$data['name']=session('user_auth.username');
+		
+		$data['telephone']=$payment['telephone'];
+		
+		$data['shipping_name']=$shipping['name'];
+		$data['shipping_address']=$shipping['address'];
+		$data['shipping_tel']=$shipping['telephone'];
+		
+		$data['shipping_province_id']=$shipping['province_id'];
+		$data['shipping_city_id']=$shipping['city_id'];
+		$data['shipping_country_id']=$shipping['country_id'];		
+		
+		$data['shipping_method'] = session('express_id');
+		$data['delivery']=session('shipping_method');
+		
+		
+		$data['payment_method']=session('payment_method');
+		
+		$data['address_id']=session('shipping_address_id');
+		
+		$data['voucher_id']=session('payment_voucher_id');
+		//payment_voucher_id
+
+		$data['user_agent']=$_SERVER['HTTP_USER_AGENT'];
+		$data['date_added']=time();
+		$data['comment']=session('remark');
+		$hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
+		$subject='';
+		$fare = 0;
+		if($goodss){				
+		    
+				/**
+				$sm=D('Transport')->calc_transport(session('shipping_method'),
+				session('quantity'),
+				$shipping['city_id']
+				);	
+				**/
+				
+				$sm = D('Transport')->calc_transport(null,
+				session('quantity'),
+				$shipping['city_id']
+				);
+				
+				$t=0;		
+				foreach ($goodss as $goods) {
+					
+					$option_data = array();
+	
+					foreach ($goods['option'] as $option) {
+						
+						$value = $option['value'];						
+	
+						$option_data[] = array(
+							'goods_option_id'       => $option['goods_option_id'],
+							'goods_option_value_id' => $option['goods_option_value_id'],
+							'option_id'               => $option['option_id'],
+							'option_value_id'         => $option['option_value_id'],								   
+							'name'                    => $option['name'],
+							'value'                   => $value,
+							'type'                    => $option['type']
+						);					
+					}
+					
+					$tp_goods_info = M('goods')->field('store_id,express_list')->where( array('goods_id' =>$hashids->decode($goods['goods_id'])) )->find();
+					
+					$express_list_arr = unserialize($tp_goods_info['express_list']);
+					
+					if($data['delivery'] == 'express')
+					{
+						$fare = isset($express_list_arr[$data['shipping_method']]) ? $express_list_arr[$data['shipping_method']]['price'] : 0;
+					}
+					
+					$t+=$goods['total'];					
+					
+					$goods['total'] = $goods['total'];
+					
+					$goods_data[] = array(
+						'goods_id'   => $goods['goods_id'],
+						'name'       => $goods['name'],
+					    'is_header_disc' => $goods['is_header_disc'],
+					    'store_id'   => $tp_goods_info['store_id'],
+						'model'      => $goods['model'],		
+						'option'     => $option_data,						
+						'quantity'   => $goods['quantity'],
+						'pin_type'   => $goods['pin_type'],
+					    'pin_id'     => $goods['pin_id'],
+						'price'      => $goods['price'],
+						'total'      => $goods['total']				
+					); 		
+			
+					$subject.=$goods['name'].' ';					
+						
+					}
+					
+					if($data['voucher_id'] > 0) {
+						$voucher_info = M('voucher_list')->where( array('id' => $data['voucher_id']) )->find();
+						$data['voucher_credit'] = $voucher_info['credit'];
+						M('voucher_list')->where( array('id' => $data['voucher_id']) )->save( array('consume' => 'Y') );
+					} else {
+						$data['voucher_credit'] = 0;
+					}
+					
+					$data['shipping_fare'] = floatval($fare);
+					
+					$data['total']=($t+$fare - $data['voucher_credit']);
+					$data['goodss'] = $goods_data;
+					$data['order_num_alias']=build_order_no($data['member_id']);
+					
+					$data['totals'][0]=array(
+						'code'=>'sub_total',
+						'title'=>'商品价格',
+						'text'=>'¥'.$t,
+						'value'=>$t				
+					);
+					$data['totals'][1]=array(
+						'code'=>'shipping',
+						'title'=>'运费',
+						'text'=>'¥'.$fare,
+						'value'=>$fare				
+					);				
+					$data['totals'][2]=array(
+						'code'=>'voucher',
+						'title'=>'优惠券',
+						'text'=>'¥'.$data['voucher_credit'],
+						'value'=>$data['voucher_credit']				
+					);	
+					$data['totals'][3]=array(
+						'code'=>'total',
+						'title'=>'总价',
+						'text'=>'¥'.($t+$fare- $data['voucher_credit']),
+						'value'=>($t+$fare- $data['voucher_credit'])				
+					);
+				
+				
+				$oid=D('Order')->addOrder($data);
+				
+				//delivery  pickup pick_up_id
+				if($data['delivery'] == 'pickup')
+				{
+					$verify_bool = true;
+					$verifycode = 0;
+					while($verify_bool)
+					{
+						$code  = (ceil(time()/100)+rand(10000000,40000000)).rand(1000,9999);
+						$verifycode = $code ? $code : rand(100000,999999);
+						$verifycode = str_replace('1989','9819',$verifycode);
+						$verifycode = str_replace('1259','9521',$verifycode);
+						$verifycode = str_replace('12590','95210',$verifycode);
+						$verifycode = str_replace('10086','68001',$verifycode);
+						
+						$pick_order = M('pick_order')->where( array('pick_sn' => $verifycode) )->find();
+						if(empty($pick_order))
+						{
+							$verify_bool = false;
+						}
+					}
+					$pick_data = array();
+					$pick_data['pick_sn'] = $verifycode;
+					$pick_data['pick_id'] = session('pick_up_id');
+					$pick_data['order_id'] = $oid;
+					$pick_data['state'] = 0;
+					$pick_data['addtime'] = time();
+					M('pick_order')->add($pick_data);
+				}
+				if($oid){				
+					session('cart_total',null);
+					$order['notify_url']=C('SITE_URL').U('Payment/alipay_notify');
+					$order['return_url']=C('SITE_URL').U('Payment/alipay_return');
+					$order['order_type']='goods_buy';
+					$order['subject']=$subject;
+					$order['name']=session('shipping_name');
+					$order['order_num_alias']=$data['order_num_alias'];
+					$order['pay_total']=($t+$sm['price']);			
+					//free_tuan
+					$order_goods_info = M('order_goods')->where( array('order_id' => $oid) )->find();
+					
+					session('back_cart_address_id',null);
+					session('cart',null);
+					session('total',null);					
+					session('shipping_address_id',null);	
+					session('back_order_id',$oid);
+					
+					if($data['total']<=0 || $order_goods_info['free_tuan'] ==1)
+					{
+					    $this->yuer_payreturn($data['order_num_alias']); //测试使用
+					}else {
+					    $url=$this->pay_api('wxpay', $order);
+					}
+					
+					die();
+				}else{
+				    
+				    echo 9999;die();
+					$url=U('/checkout');
+					@header("Location: ".$url);
+					
+					die();
+				}
+				
+			}
+			
+	}
+
+	public function success()
+	{
+	    $order_id = I('get.order_id');
+	    //removeAll
+	    $cart=new \Lib\Cart();
+	    $cart->removeAll();
+	    session('total',null);
+	     
+	    $pin_order = M('pin_order')->field('pin_id')->where( array('order_id' =>$order_id) )->find();
+	     
+	    //Order/info/id/14
+	     
+	    $redir_url = U('Order/info', array('id' => $order_id));
+	    if(!empty($pin_order))
+	    {
+	        $hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
+	        $group_order_id = $hashids->encode($order_id);
+	         
+	        $redir_url = U('Group/info', array('group_order_id' => $group_order_id,'is_show' =>1));
+			redirect($redir_url,0);
+	    }
+	    $this->redir_url = $redir_url;
+	     
+	    $this->order_id = $order_id;
+	    $this->display();
+	}
+	
+	function de_bug($content){
+		$file = ROOT_PATH."/Tmp/wxpay_debug.php";
+		file_put_contents($file,$content);	
+	}
+
+	//数据以post方式返回
+	function alipay_notify(){
+		
+		$alipay= new \Lib\Payment\Alipay(get_payment_config('alipay'));
+		
+		$verify_result = $alipay->verifyNotify();
+		
+		if($verify_result) {
+			
+			//$this->de_bug('success');
+			
+			//商户订单号	
+			//$out_trade_no = $_POST['out_trade_no'];	
+			//支付宝交易号	
+			//$trade_no = $_POST['trade_no'];	
+			//交易状态
+			//$trade_status = $_POST['trade_status'];
+			
+			if($_POST['trade_status'] == 'TRADE_FINISHED') {
+				//$this->de_bug('TRADE_FINISHED');
+				
+		    }
+		    else if ($_POST['trade_status'] == 'TRADE_SUCCESS') {
+				//$this->de_bug('TRADE_SUCCESS');
+				
+				$order=M('Order')->getByOrderNumAlias($_POST['out_trade_no']);
+				
+				if($order&&($order['order_status_id']!=C('paid_order_status_id'))){
+						//支付完成						
+						$o['order_id']=$order['order_id'];
+						$o['order_status_id']=C('paid_order_status_id');
+						$o['date_modified']=time();
+						$o['pay_time']=time();
+						M('Order')->save($o);
+						
+						$oh['order_id']=$order['order_id'];
+						$oh['order_status_id']=C('paid_order_status_id');
+				
+						$oh['comment']='买家已付款';
+						$oh['date_added']=time();
+						$oh['notify']=1;
+						M('OrderHistory')->add($oh);
+						
+						$model=new \Admin\Model\OrderModel();	   
+					    $this->order=$model->order_info($order['order_id']);
+					    $html=$this->fetch('Mail:order');				   
+					    think_send_mail($order['email'],$order['name'],'下单成功-'.C('SITE_NAME'),$html);
+						
+						storage_user_action(session('user_auth.uid'),session('user_auth.username'),C('FRONTEND_USER'),'支付了订单 '.$order['order_num_alias']);
+						
+						//@header("Location: ".U('/pay_success'));	
+											
+				}
+				
+		        
+				echo "success";		
+		    }
+		
+			
+			
+		}else{
+			//$this->de_bug('fail');
+			echo "fail";
+		}
+		
+	}
+	
+	private function yuer_payreturn($order_id){
+	    // $order=M('Order')->getByOrderNumAlias($out_trade_no);
+	    $order=M('Order')->where( array('order_id' => $order_id) )->find();
+	    $out_trade_no = $order['order_num_alias'];
+	     
+	    if($order['order_status_id']==C('paid_order_status_id')){
+	        @header("Location: ".U('/pay_success'));
+	        die;
+	    }
+	     
+	    if($order&&($order['order_status_id']!=C('paid_order_status_id'))){
+	        //支付完成
+	        if(true){
+	             
+	            
+	
+	            $goods_model = D('Home/Goods');
+	
+	            $kucun_method = C('kucun_method');
+	            $kucun_method  = empty($kucun_method) ? 0 : intval($kucun_method);
+	            if($kucun_method == 1)
+	            {//支付完减库存,增加销量
+	                $order_goods_list = M('order_goods')->where( array('order_id' => $order['order_id']) )->select();
+	                foreach($order_goods_list as $order_goods)
+	                {
+	                    //销量增加 del_goods_mult_option_quantity($order_id,$option,$goods_id,$quantity,$type='1')
+	                    $goods_model->del_goods_mult_option_quantity($order['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity'],1);
+	                    //扣除库存
+	                }
+	            }
+	
+	            $oh['order_id']=$order['order_id'];
+	            $oh['order_status_id'] = 1;
+	            $oh['comment']='买家已付款';
+	            $oh['date_added']=time();
+	            $oh['notify']=0;
+	            M('OrderHistory')->add($oh);
+	             
+	            $pin_order = M('pin_order')->where( array('order_id' =>$order['order_id'] ) )->find();
+	           
+	            if(!empty($pin_order))
+	            {
+					$o = array();
+					$o['order_id']=$order['order_id'];
+					$o['order_status_id']= 2;
+					$o['date_modified']=time();
+					$o['pay_time']=time();
+					M('Order')->save($o);
+	                //group_order_id
+	                $pin_model = D('Home/Pin');
+	                $is_pin_success = $pin_model->checkPinSuccess($pin_order['pin_id']);
+	
+	                if($is_pin_success) {
+	                    //todo send pintuan success notify
+	                    $pin_model->updatePintuanSuccess($pin_order['pin_id']);
+						
+	                }else{
+						
+					}
+	            }else{
+					$o = array();
+					$o['order_id']=$order['order_id'];
+					$o['order_status_id']= 1;
+					$o['date_modified']=time();
+					$o['pay_time']=time();
+					M('Order')->save($o);
+					$share_model = D('Seller/Fissionsharing');
+					$share_model->send_order_commiss_money( $order['order_id'] );
+				}
+	             
+	            $result = array('code' => 1, 'url' => U('Payment/success',array('order_id' => $order['order_id'])));
+	             
+	            echo json_encode($result);
+	            die();
+	            
+	        }
+	    }
+	}
+	
+	
+	private function yuer_payreturn2($out_trade_no){
+	    $order=M('Order')->getByOrderNumAlias($out_trade_no);
+	   
+	    if($order['order_status_id']==C('paid_order_status_id')){
+	        @header("Location: ".U('/pay_success'));
+	        die;
+	    }
+	    
+	    if($order&&($order['order_status_id']!=C('paid_order_status_id'))){
+	        //支付完成
+	        if(true){
+	            	 
+	                
+	            $o['order_id']=$order['order_id'];
+	            $o['order_status_id']= $order['is_pin'] == 1 ? 2:1;
+	            $o['date_modified']=time();
+	            $o['pay_time']=time();
+	            M('Order')->save($o);
+				
+				$goods_model = D('Home/Goods');
+				
+				$kucun_method = C('kucun_method');
+				$kucun_method  = empty($kucun_method) ? 0 : intval($kucun_method);
+				if($kucun_method == 1)
+				{//支付完减库存,增加销量
+					$order_goods_list = M('order_goods')->where( array('order_id' => $order['order_id']) )->select();
+					foreach($order_goods_list as $order_goods)
+					{
+						//销量增加 rela_goodsoption_valueid
+						$goods_model->del_goods_mult_option_quantity($order['order_id'],$order_goods['quantity'],1);
+						//扣除库存
+					}
+				}
+	            	
+	            $oh['order_id']=$order['order_id'];
+	            $oh['order_status_id']= $order['is_pin'] == 1 ? 2:1;
+	            $oh['comment']='买家已付款';
+	            $oh['date_added']=time();
+	            $oh['notify']=1;
+	            M('OrderHistory')->add($oh);
+	            
+	            //发送购买通知
+	            $weixin_nofity = D('Home/Weixinnotify');
+	            $weixin_nofity->orderBuy($order);
+	            
+	            $model=new \Admin\Model\OrderModel();
+	            $this->order=$model->order_info($order['order_id']);
+	           
+	            $hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
+	            $order_id = $hashids->encode($order['order_id']);
+	            
+	            if($order['is_pin'] == 1)
+	            {
+	                $pin_model = D('Home/Pin');
+	                $is_pin_success = $pin_model->checkPinSuccess($order['pin_id']);
+	                
+	                if($is_pin_success) {
+	                    //todo send pintuan success notify
+	                    $pin_model->updatePintuanSuccess($order['pin_id']);
+	                }
+	                $refurl = C('SITE_URL')."index.php?s=/Group/info/group_order_id/{$order_id}/is_show/1";
+	                @header("Location: ".$refurl);
+	                die();
+	            } else {
+	                @header("Location: ".U('Order/info',array('id' =>$order['order_id'] )));
+	                die();
+	            }
+	           
+	        }
+	    }
+	}
+
+	function alipay_return(){
+		
+		$alipay= new \Lib\Payment\Alipay(get_payment_config('alipay'));
+		
+		//对进入的参数进行远程数据判断
+		$verify = $alipay->return_verify();
+	
+		if($verify){
+			$order=M('Order')->getByOrderNumAlias($_GET['out_trade_no']);
+			
+			if($order['order_status_id']==C('paid_order_status_id')){
+				@header("Location: ".U('/pay_success'));	
+				die;
+			}
+			
+			if($order&&($order['order_status_id']!=C('paid_order_status_id'))){
+				//支付完成
+				if($_GET['trade_status']=='TRADE_SUCCESS'){					
+					
+					$o['order_id']=$order['order_id'];
+					$o['order_status_id']=C('paid_order_status_id');
+					$o['date_modified']=time();
+					$o['pay_time']=time();
+					M('Order')->save($o);
+					
+					$oh['order_id']=$order['order_id'];
+					$oh['order_status_id']=C('paid_order_status_id');
+			
+					$oh['comment']='买家已付款';
+					$oh['date_added']=time();
+					$oh['notify']=1;
+					M('OrderHistory')->add($oh);
+					
+					$model=new \Admin\Model\OrderModel();	   
+				    $this->order=$model->order_info($order['order_id']);
+				    $html=$this->fetch('Mail:order');				   
+				    think_send_mail($order['email'],$order['name'],'下单成功-'.C('SITE_NAME'),$html);
+					
+					storage_user_action(session('user_auth.uid'),session('user_auth.username'),C('FRONTEND_USER'),'支付了订单 '.$order['order_num_alias']);
+					
+					@header("Location: ".U('/pay_success'));	
+				}						
+			}else{
+				die('订单不存在');
+			}
+			
+		}else{
+			die('支付失败');
+		}		
+		
+	}
+}

+ 1289 - 1495
Modules/Home/Model/WeixinModel.class.php

@@ -1,1496 +1,1290 @@
-<?php
-/**
- * lionfish 商城系统
- *
- * ==========================================================================
- * @link      http://www.liofis.com/
- * @copyright Copyright (c) 2015 liofis.com. 
- * @license   http://www.liofis.com/license.html License
- * ==========================================================================
- *
- * @author    fish
- *
- */
-namespace Home\Model;
-class WeixinModel{
-
-	
-	public function refundOrder($order_id, $money=0, $uniacid=0,$order_goods_id=0,$is_back_sellcount = 1,$refund_quantity = 0,$is_zi_order_refund =0)
-	
-	{
-		$_GPC = I('request.');
-		$lib_path = dirname(dirname( dirname(__FILE__) )).'/Lib/';
-		
-		set_time_limit(0);
-		
-		require_once $lib_path."/Weixin/lib/WxPay.Api.php";
-		
-		
-		$order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->find();
-		
-				
-		$member_info = M('lionfish_comshop_member')->where( array('member_id' => $order_info['member_id'] ) )->find();		
-		
-		
-		$openId = $member_info['openid'];
-		$we_openid = $member_info['we_openid'];
-		
-		if( $order_info['from_type'] == 'wepro' )
-		{
-			$openId = $we_openid;
-		}
-		//we_openid
-		//money
-		$transaction_id = $order_info["transaction_id"];
-
-		
-		if( $order_info['type'] == 'integral' )
-		{
-			$total_fee = ( $order_info["shipping_fare"] )*100;
-		
-		}else{
-			$total_fee = ($order_info["total"] + $order_info["shipping_fare"]-$order_info['voucher_credit']-$order_info['fullreduction_money'] - $order_info['score_for_money']-$order_info['fare_shipping_free'] )*100;
-		}
-		
-		//预售begin
-        $presale_result = D('Home/PresaleGoods')->getOrderPresaleInfo( $order_id );
-		if( $presale_result['code'] ==0 )
-        {
-            $total_fee = $total_fee - $presale_result['data']['presale_ding_money'] * 100;
-        }
-        //end
-
-		$refund_fee = $total_fee;
-		
-		
-		
-		//order_goods_id
-		if( !empty($order_goods_id) )
-		{
-			$order_goods_info = M('lionfish_comshop_order_goods')->where( array('order_goods_id' =>$order_goods_id ) )->find();
-			
-			$refund_fee = ($order_goods_info["total"] + $order_goods_info["shipping_fare"]-$order_goods_info['voucher_credit']-$order_goods_info['fullreduction_money'] - $order_goods_info['score_for_money']-$order_goods_info['fare_shipping_free'])*100;
-		
-			if( $order_info['type'] == 'integral' )
-			{
-				$refund_fee = ( $order_goods_info["shipping_fare"] )*100;
-			}
-		}
-		
-		
-		if($money > 0 && $order_info['type'] != 'integral' )
-		{
-			$refund_fee = $money * 100;
-		}else if(  $money > 0 && $order_info['type'] == 'integral' && !empty($order_goods_info) ) 
-		{
-			if(!empty($_GPC['refund_money'])){
-					$refund_money = isset($_GPC['refund_money']) && $_GPC['refund_money'] >0  ? floatval($_GPC['refund_money']) : 0;
-					//商品多个运费和
-					$refund_fee = ( $money - $refund_money )*100;
-					//商品多个商品单价和
-					$order_info['total'] = $refund_money;
-			}else{
-				$order_refund_history_image = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_id) )->order('addtime asc')->find();	
-				$ref_shipping_fare = M('lionfish_comshop_order_refund')->field('ref_id,ref_money,real_refund_quantity,ref_shipping_fare')->where( array('order_id' => $order_id ))->order('ref_id desc')->find();
-				$refund_fee = ( $ref_shipping_fare['ref_shipping_fare'] )*100;
-				$order_info['total'] = $money ;
-			}
-		}
-		// else if( isset($is_open_yinpay) && $is_open_yinpay == 3 )  
-		    
-		$is_open_yinpay = D('Home/Front')->get_config_by_name('is_open_yinpay');
-
-        if($order_info['payment_code'] == 'fypay'){
-
-        $order_relate_info = M('lionfish_comshop_order_relate')->where( array('order_id' => $order_id ) )->order('id desc')->find();
-
-        if( !empty($order_relate_info) && $order_relate_info['order_all_id'] > 0 )
-        {
-            $order_all_info = M('lionfish_comshop_order_all')->where( array('id' => $order_relate_info['order_all_id'] ) )->find();
-
-            if( !empty($order_all_info) && !empty($order_all_info['out_trade_no']) )
-            {
-
-                $out_trade_no = $order_all_info['out_trade_no'];
-
-                $appid =  D('Home/Front')->get_config_by_name('wepro_appid');
-                $mch_id =      D('Home/Front')->get_config_by_name('wepro_partnerid');
-                $nonce_str =    nonce_str();
-
-                $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
-
-
-                $post = array();
-                $post['appid'] = $appid;
-                $post['mch_id'] = $mch_id;
-                $post['nonce_str'] = $nonce_str;
-                $post['out_trade_no'] = $out_trade_no;
-
-                $sign = sign($post,$pay_key);
-
-                $post_xml = '<xml>
-							   <appid>'.$appid.'</appid>
-							   <mch_id>'.$mch_id.'</mch_id>
-							   <nonce_str>'.$nonce_str.'</nonce_str>
-							   <out_trade_no>'.$out_trade_no.'</out_trade_no>
-							   <sign>'.$sign.'</sign>
-							</xml>';
-
-                $url = "https://api.mch.weixin.qq.com/pay/orderquery";
-
-                $result = http_request($url,$post_xml);
-
-                $array = xml($result);
-
-                if( $array['RETURN_CODE'] == 'SUCCESS' && $array['RETURN_MSG'] == 'OK' )
-                {
-                    if( $array['TRADE_STATE'] == 'SUCCESS' || $array['TRADE_STATE'] == 'REFUND' )
-                    {
-                        $total_fee = $array['TOTAL_FEE'];
-                    }
-                }
-
-            }
-        }
-
-        //
-        require_once $lib_path . "/Weixin/Wxfy.class.php";
-
-        $refund_no = '1450'.date("YmdHis").$order_info['order_id'];
-//            dump(strlen($refund_no));
-//            exit();
-            $order_all=D("lionfish_comshop_order_all")->where(array("transaction_id"=>$transaction_id))->find();
-
-            if($order_all['transaction_id']==$transaction_id){
-                $input = new \Wxfy();
-                $notify_data=[
-                    "version"=>"1",
-                    "ins_cd"=>"08M0027018",
-                    "mchnt_cd"=>"0001000F6549249",
-                    "order_type"=>"WECHAT",
-                    "mchnt_order_no"=>$order_all['out_trade_no'],
-                    "random_str"=>$nonce_str,
-                    "term_id"=>"88888888",
-                    "refund_order_no"=>$refund_no,
-                    "total_amt"=>$total_fee,
-                    'refund_amt'=>$refund_fee
-
-                ];
-
-                $res=$input->refundOrder($notify_data);
-            }else{
-                return array('code' => 0, 'msg' =>"该订单不存在");
-            }
-
-//        dump($res);
-//        exit();
-
-//            $res='{"ins_cd":"08M0027018","mchnt_cd":"0005210F3948471","mchnt_order_no":"145036-1698222261","order_type":"WECHAT","random_str":"8AHA9V61UY1VOXJ5CJP27MIOURZO1TTL","refund_id":"50101607462023102545369668637","refund_order_no":"145014502023102519014730","reserved_fy_settle_dt":"20231025","reserved_fy_trace_no":"221210993339","reserved_refund_amt":"1","result_code":"000000","result_msg":"SUCCESS","sign":"Fi2gsgMHan11IIru8sLAJ8jwLbtUYfndURakne9l16qtEqaQrkhDx+aXo0jfQGPkx171bBi0T74I8Z6PI1RdBZX0Wf2h9tWKnCRVnxEjQIy0BRPN3g+ktkxrtQgzmDL5jxyatjVFrA43J4gwoqt6o7onlclGUeltsdRPJvoOVGs=","term_id":"88888888","transaction_id":"4200001999202310251498038501"}
-//';
-            $res=json_decode($res,true);
-
-
-        if($res["result_code"] != '000000'){
-            if( $res['result_msg'] == '订单已全额退款' )
-            {
-                $res['result_code'] = '000000';
-            }else{
-                return array('code' => 0, 'msg' => $res['result_msg']);
-            }
-
-        }
-
-
-
-
-
-        if($res['result_code'] == '000000')
-        {
-
-            if($order_info['order_status_id'] == 12)
-            {
-                $ref_count = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_info['order_id'], 'state' => 0 ) )->count();
-                if( $ref_count <= 1 )
-                {
-                    M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
-                }
-            }
-
-            $order_info['total'] = $refund_fee / 100;
-
-
-            $order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_info['order_id']) )->select();
-
-            $order_goods_name_arr = array();
-            $order_goods_name = '';
-
-            foreach($order_goods_list as $order_goods)
-            {
-
-                $order_goods_name_arr[] = $order_goods['name'];
-                //...
-                if( !empty($order_goods_id) && $order_goods_id > 0  )
-                {
-                    if($order_goods_id ==  $order_goods['order_goods_id'] )
-                    {
-                        if($is_back_sellcount == 1)
-                        {
-                            if( $is_zi_order_refund == 1 && $refund_quantity > 0 )
-                            {
-                                D('Home/Pingoods')->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$refund_quantity,2);
-                            }else{
-                                //获取已退款数量
-                                $has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
-                                if(!$has_refund_quantity){
-                                    $has_refund_quantity = 0;
-                                }
-                                D('Home/Pingoods')->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
-                            }
-                        }
-
-                        $score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_id' => $order_info['order_id'],'order_goods_id'=>$order_goods['order_goods_id'] ,'type' => 'orderbuy') )->find();
-
-                        if( !empty($score_refund_info) && $is_zi_order_refund == 1  )
-                        {
-                            // D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
-                        }
-                    }
-                }else if( empty($order_goods_id) || $order_goods_id <=0 ){
-                    if($is_back_sellcount == 1){
-                        $has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
-                        if(!$has_refund_quantity){
-                            $has_refund_quantity = 0;
-                        }
-                        D('Home/Pingoods')->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
-                    }
-
-
-                    $score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_id' => $order_info['order_id'],'order_goods_id' =>$order_goods['order_goods_id'] ,'type' => 'orderbuy') )->find();
-
-                    if( !empty($score_refund_info) )
-                    {
-                        // D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
-                    }
-                }
-
-                if( $order_info['type'] == 'integral' )
-                {
-                    D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$order_goods['total'], 0 ,'退款增加积分','refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
-                }
-
-            }
-
-            $order_goods_name = implode('\r\n', $order_goods_name_arr); //."\r\n";
-
-
-            //分佣也要退回去
-            if($is_zi_order_refund == 0)
-                D('Seller/Community')->back_order_commission($order_info['order_id'],$order_goods_id);
-
-            return array('code' => 1);
-
-        } else {
-
-            $order_refund_history = array();
-            $order_refund_history['order_id'] =  $order_info['order_id'];
-            $order_refund_history['order_goods_id'] =  $order_goods_id;
-
-            $order_refund_history['message'] = $res['err_code_des'];
-            $order_refund_history['type'] = 2;
-            $order_refund_history['addtime'] = time();
-
-            M('lionfish_comshop_order_refund_history')->add($order_refund_history);
-
-            /**
-            M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 10, 'remarksaler' => $res[err_code_des]) );
-             **/
-
-            return array('code' => 0, 'msg' => $res['result_msg']);
-
-        }
-    }
-		else if($order_info['payment_code'] == 'yuer')
-		{
-			//余额支付的,退款到余额
-			//退款到余额
-			
-			//增加会员余额
-			$refund_fee = $refund_fee / 100;
-
-			if( $refund_fee > 0 )
-			{
-				//判断是否积分类型的
-
-				M('lionfish_comshop_member')->where( array('member_id' => $order_info['member_id']) )->setInc('account_money',$refund_fee);
-				
-				$account_money_info = M('lionfish_comshop_member')->field('account_money')->where( array('member_id' =>$order_info['member_id'] ) )->find();
-		
-				$account_money = $account_money_info['account_money'];
-				
-		
-				$member_charge_flow_data = array();
-				
-				$member_charge_flow_data['member_id'] = $order_info['member_id'];
-				$member_charge_flow_data['money'] = $refund_fee;
-				$member_charge_flow_data['operate_end_yuer'] = $account_money;
-				$member_charge_flow_data['state'] = 4;
-				$member_charge_flow_data['trans_id'] = $order_id;
-				$member_charge_flow_data['order_goods_id'] = $order_goods_id;
-				$member_charge_flow_data['charge_time'] = time();
-				$member_charge_flow_data['add_time'] = time();
-				
-				M('lionfish_comshop_member_charge_flow')->add($member_charge_flow_data);
-			}
-			
-			
-			if($order_info['order_status_id'] == 12)
-			{
-				$ref_count = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_info['order_id'], 'state' => 0 ) )->count();
-				
-				
-				if( $ref_count <= 1 )
-				{
-					M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
-				}
-			}
-			
-			
-			
-			
-			$order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_info['order_id'] ) )->select();
-			
-			$goods_model = D('Home/Pingoods');
-			
-			foreach($order_goods_list as $order_goods)
-			{
-				//$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity'],2);
-				
-				if( !empty($order_goods_id) && $order_goods_id > 0  )
-				{
-					if($order_goods_id ==  $order_goods['order_goods_id'] )
-					{
-						
-						if($is_back_sellcount == 1)
-						{
-							if( $is_zi_order_refund == 1 && $refund_quantity > 0 )
-							{
-								$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$refund_quantity,2);
-							}else{
-								//获取已退款数量
-								$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
-								if(!$has_refund_quantity){
-									$has_refund_quantity = 0;
-								}
-								$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
-							}
-						}
-						
-						$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_goods_id' => $order_goods['order_goods_id'],'order_id' =>$order_info['order_id'],'type' => 'orderbuy' ) )->find();
-						
-						if( !empty($score_refund_info) && $is_zi_order_refund == 1  )
-						{
-							// D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
-						}
-					}
-				}else if( empty($order_goods_id) || $order_goods_id <=0 ){
-					if($is_back_sellcount == 1){
-						//获取已退款数量
-						$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
-						if(!$has_refund_quantity){
-							$has_refund_quantity = 0;
-						}
-						$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
-					}
-
-					
-					$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_goods_id' => $order_goods['order_goods_id'],'order_id' => $order_info['order_id'] ,'type' => 'orderbuy') )->find();			
-										
-					if( !empty($score_refund_info) )
-					{
-						// D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分','refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
-					}
-				}
-				
-				if( $order_info['type'] == 'integral' )
-				{
-					
-					D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$order_info['total'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
-				}
-			}
-			//分佣也要退回去
-			if($is_zi_order_refund == 0)
-					D('Seller/Community')->back_order_commission($order_info['order_id'],$order_goods_id);
-				
-			return array('code' => 1);
-			//$this->refundOrder_success($order_info,$openId);
-			//检测是否有需要退回积分的订单
-		//货到付款订单
-		}else if($order_info['payment_code'] == 'cashon_delivery')
-		{
-			//货到付款订单退款金额不到账,但有退款记录
-
-			if($order_info['order_status_id'] == 12)
-			{
-				$ref_count = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_info['order_id'], 'state' => 0 ) )->count();
-
-				if( $ref_count <= 1 )
-				{
-					M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
-				}
-			}
-
-			$order_info['total'] = $refund_fee / 100;
-
-			$order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_info['order_id'] ) )->select();
-
-			$goods_model = D('Home/Pingoods');
-
-			foreach($order_goods_list as $order_goods)
-			{
-				//$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity'],2);
-
-				if( !empty($order_goods_id) && $order_goods_id > 0  )
-				{
-					if($order_goods_id ==  $order_goods['order_goods_id'] )
-					{
-
-						if($is_back_sellcount == 1)
-						{
-							if( $is_zi_order_refund == 1 && $refund_quantity > 0 )
-							{
-								$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$refund_quantity,2);
-							}else{
-								//获取已退款数量
-								$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
-								if(!$has_refund_quantity){
-									$has_refund_quantity = 0;
-								}
-								$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
-							}
-						}
-
-						$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_goods_id' => $order_goods['order_goods_id'],'order_id' =>$order_info['order_id'],'type' => 'orderbuy' ) )->find();
-
-						if( !empty($score_refund_info) && $is_zi_order_refund == 1  )
-						{
-							// D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
-						}
-					}
-				}else if( empty($order_goods_id) || $order_goods_id <=0 ){
-					if($is_back_sellcount == 1){
-						//获取已退款数量
-						$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
-						if(!$has_refund_quantity){
-							$has_refund_quantity = 0;
-						}
-						$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
-					}
-
-
-					$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_goods_id' => $order_goods['order_goods_id'],'order_id' => $order_info['order_id'] ,'type' => 'orderbuy') )->find();
-
-					if( !empty($score_refund_info) )
-					{
-						// D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分','refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
-					}
-				}
-
-				/*if( $order_info['type'] == 'integral' )
-				{
-
-					D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$order_info['total'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
-				}*/
-			}
-			//分佣也要退回去
-			if($is_zi_order_refund == 0)
-				D('Seller/Community')->back_order_commission($order_info['order_id'],$order_goods_id);
-
-			return array('code' => 1);
-			//$this->refundOrder_success($order_info,$openId);
-			//检测是否有需要退回积分的订单
-		}
-		else if($order_info['payment_code'] == 'admin'){
-			 
-			if($order_info['order_status_id'] == 12)
-			{
-				$ref_count = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_info['order_id'], 'state' => 0 ) )->count();
-				if( $ref_count <= 1 )
-				{
-					M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
-				}
-			}
-				
-			$order_info['total'] = $refund_fee / 100;
-			
-			$order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_info['order_id'] ) )->select();
-			
-			
-			$goods_model = D('Home/Pingoods');
-			foreach($order_goods_list as $order_goods)
-			{
-				//$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity'],2);
-				
-				if( !empty($order_goods_id) && $order_goods_id > 0  )
-				{
-					if($order_goods_id ==  $order_goods['order_goods_id'] )
-					{
-						
-						if($is_back_sellcount == 1)
-						{
-							if( $is_zi_order_refund == 1 && $refund_quantity > 0 )
-							{
-								$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$refund_quantity,2);
-							}else{
-								//获取已退款数量
-								$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
-								if(!$has_refund_quantity){
-									$has_refund_quantity = 0;
-								}
-								$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
-							}
-						}	
-						
-						$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_goods_id' => $order_goods['order_goods_id'],'order_id' =>$order_info['order_id'],'type' => 'orderbuy' ) )->find();
-						
-						if( !empty($score_refund_info) && $is_zi_order_refund == 1 )
-						{
-							 //D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
-						}
-					}
-				}else if( empty($order_goods_id) || $order_goods_id <=0 ){
-					if($is_back_sellcount == 1){
-						//获取已退款数量
-						$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
-						if(!$has_refund_quantity){
-							$has_refund_quantity = 0;
-						}
-						$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
-					}
-
-					
-					$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_goods_id' => $order_goods['order_goods_id'],'order_id' => $order_info['order_id'] ,'type' => 'orderbuy') )->find();			
-										
-					if( !empty($score_refund_info) )
-					{
-						// D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分','refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
-					}
-				}
-				
-				if( $order_info['type'] == 'integral' )
-				{
-					//D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$order_goods['total'], 0 ,'退款增加积分','refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
-				}
-			
-			}
-			//分佣也要退回去
-			if($is_zi_order_refund == 0)
-				D('Seller/Community')->back_order_commission($order_info['order_id'],$order_goods_id);
-			return array('code' => 1);
-			
-		}
-		else if($refund_fee == 0)
-		{
-			if($order_info['order_status_id'] == 12)
-			{
-				$ref_count = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_info['order_id'], 'state' => 0 ) )->count();
-				if( $ref_count <= 1 )
-				{
-					M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
-				}
-			}
-				
-			//ims_ lionfish_comshop_order_goods
-			$order_goods = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_info['order_id']) )->select();
-			
-			$order_goods_name = '';
-			$order_goods_name_arr = array();
-			$goods_model = D('Home/Pingoods');
-			
-			//get_config_by_name($name) 
-			
-			
-			
-			foreach ($order_goods as $key => $value) {
-				//($order_id,$option,$goods_id,$quantity,$type='1')
-				if($is_back_sellcount == 1)
-				{
-					if( $is_zi_order_refund == 1 && $refund_quantity > 0 )
-					{
-						$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$value['rela_goodsoption_valueid'],$value['goods_id'],$refund_quantity,2);
-					}else{
-						//获取已退款数量
-						$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
-						if(!$has_refund_quantity){
-							$has_refund_quantity = 0;
-						}
-						$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$value['rela_goodsoption_valueid'],$value['goods_id'],$value['quantity']-$has_refund_quantity,2);
-					}
-				}	
-				
-				$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_id' =>$order_info['order_id'] ,'order_goods_id' =>$value['order_goods_id'] ,'type' => 'orderbuy') )->find();
-				
-				if( !empty($score_refund_info) )
-				{
-					// D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分','refundorder', $order_info['order_id'] ,$value['order_goods_id'] );
-				}
-					
-				//销量回退
-				$order_goods_name_arr[] = $value['name'];
-			}
-			$order_goods_name = implode('\r\n', $order_goods_name_arr); //."\r\n";	
-		
-			
-			$msg = '订单退款: 您的订单'.$order_info['order_num_alias'].'参团未成功,现退款:'.round($order_info["total"],2).'元,商品名称:'.$order_goods_name;
-			
-			$url = D('Home/Front')->get_config_by_name('shop_domain');
-			
-			//weixin_template_refund_order
-			//send_template_msg($wx_template_data,$url,$openid,C('weixin_template_refund_order'));
-			
-			/**
-			{{first.DATA}}
-			订单编号:{{keyword1.DATA}}
-			退款金额:{{keyword2.DATA}}
-			{{remark.DATA}}
-			---------------------------
-			校白君提醒您,您有一笔退款成功,请留意。
-			订单编号:20088115853
-			退款金额:¥19.00
-			更多学生价好货,在底部菜单栏哦~猛戳“校园专区”,享更多优惠!
-			**/
-			
-			$wx_template_data = array();
-			$wx_template_data['first'] = array('value' => '退款通知', 'color' => '#030303');
-			$wx_template_data['keyword1'] = array('value' => $order_goods_name, 'color' => '#030303');
-			$wx_template_data['keyword2'] = array('value' => round($order_info["total"],2), 'color' => '#030303');
-			$wx_template_data['remark'] = array('value' => '拼团失败已按原路退款', 'color' => '#030303');
-		
-			
-			if( $order_info['from_type'] == 'wepro' )
-			{
-				$template_data = array();
-				$template_data['keyword1'] = array('value' => $order_info['order_num_alias'], 'color' => '#030303');
-				$template_data['keyword2'] = array('value' => '商户名称', 'color' => '#030303');
-				$template_data['keyword2'] = array('value' => $order_goods_name, 'color' => '#030303');
-				$template_data['keyword3'] = array('value' => $order_info['total'].'元', 'color' => '#030303');
-				$template_data['keyword4'] = array('value' => '已按原路退款', 'color' => '#030303');
-				$template_data['keyword5'] = array('value' => $member_info['uname'], 'color' => '#030303');
-				
-				
-				$template_id = D('Home/Front')->get_config_by_name('weprogram_template_refund_order');
-				
-				$pagepath = 'lionfish_comshop/pages/order/order?id='.$order_info['order_id'];
-				
-				
-				$member_formid_info = M('lionfish_comshop_member_formid')->where("member_id=".$order_info['member_id']." and formid != '' and state =0")->order('id desc')->find();
-				
-				if(!empty( $member_formid_info ))
-				{
-					D('Seller/User')->send_wxtemplate_msg($template_data,$url,$pagepath,$member_info['we_openid'],$template_id,$member_formid_info['formid'] );
-					
-					M('lionfish_comshop_member_formid')->where( array('id' => $member_formid_info['id']) )->save(array('state' => 1));
-				}
-				
-				if( $openid != '1')
-				{
-					//send_template_msg($wx_template_data,$url,$member_info['openid'],C('weixin_template_refund_order'));
-				}
-			}else{
-				//send_template_msg($wx_template_data,$url,$member_info['openid'],C('weixin_template_refund_order'));
-			}
-			
-			//检测是否有需要退回积分的订单
-			
-		}
-		else if( isset($is_open_yinpay) && $is_open_yinpay == 3 )
-		{
-		    $order_relate_info = M('lionfish_comshop_order_relate')->where( array('order_id' => $order_id ) )->order('id desc')->find();
-		    
-		    if( !empty($order_relate_info) && $order_relate_info['order_all_id'] > 0 )
-		    {
-		        $order_all_info = M('lionfish_comshop_order_all')->where( array('id' => $order_relate_info['order_all_id'] ) )->find();
-		         
-		        if( !empty($order_all_info) && !empty($order_all_info['out_trade_no']) )
-		        {
-		    
-		            $out_trade_no = $order_all_info['out_trade_no'];
-		    
-		            $appid =  D('Home/Front')->get_config_by_name('wepro_fuwu_appid');
-		            $mch_id =      D('Home/Front')->get_config_by_name('wepro_fuwu_partnerid');
-		            
-		            $nonce_str =    nonce_str();
-		    
-		            $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
-		    
-		            $sub_appid = D('Home/Front')->get_config_by_name('wepro_appid');
-		            $sub_mch_id = D('Home/Front')->get_config_by_name('wepro_sub_mch_id');
-		            
-		            
-		            $post = array();
-		            $post['appid'] = $appid;
-		            $post['mch_id'] = $mch_id;
-		            $post['nonce_str'] = $nonce_str;
-		            $post['out_trade_no'] = $out_trade_no;
-		            $post['sub_appid'] = $sub_appid;
-		            $post['sub_mch_id'] = $sub_mch_id;
-		             
-		            $sign = sign($post,$pay_key);
-		    
-		            $post_xml = '<xml>
-							   <appid>'.$appid.'</appid>
-							   <mch_id>'.$mch_id.'</mch_id>
-							   <nonce_str>'.$nonce_str.'</nonce_str>
-							   <out_trade_no>'.$out_trade_no.'</out_trade_no>
-							   <sub_appid>'.$post['sub_appid'].'</sub_appid>
-							   <sub_mch_id>'.$post['sub_mch_id'].'</sub_mch_id>
-							   <sign>'.$sign.'</sign>
-							</xml>';
-		             
-		            $url = "https://api.mch.weixin.qq.com/pay/orderquery";
-		    
-		            $result = http_request($url,$post_xml);
-		    
-		            $array = xml($result);
-		    
-		            if( $array['RETURN_CODE'] == 'SUCCESS' && $array['RETURN_MSG'] == 'OK' )
-		            {
-		                if( $array['TRADE_STATE'] == 'SUCCESS' || $array['TRADE_STATE'] == 'REFUND' )
-		                {
-		                    $total_fee = $array['TOTAL_FEE'];
-		                }
-		            }
-		    
-		        }
-		    }
-		    
-		    //
-		    	
-		    	
-		    $input = new \WxPayRefund();
-		    	
-		    $input->SetTransaction_id($transaction_id);
-		    $input->SetTotal_fee($total_fee);
-		    $input->SetRefund_fee($refund_fee);
-		    	
-		    $mchid = D('Home/Front')->get_config_by_name('wepro_partnerid');
-		    	
-		    $refund_no = $mchid.date("YmdHis").$order_info['order_id'];
-		    	
-		    $input->SetOut_refund_no($refund_no);
-		    $input->SetOp_user_id($mchid);
-		    	
-		    	
-		    $res = \WxPayApi::refund($input,6,'teweixin');
-		    	
-		    if($res["return_code"] == 'FAIL'){
-          		return array('code' => 0, 'msg' => $res['return_msg']);
-			}	
-		    	
-		    if( $res['err_code_des'] == '订单已全额退款' )
-		    {
-		        $res['result_code'] = 'SUCCESS';
-		    }
-		    	
-		    if($res['result_code'] == 'SUCCESS')
-		    {
-		    
-		        if($order_info['order_status_id'] == 12)
-		        {
-		            $ref_count = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_info['order_id'], 'state' => 0 ) )->count();
-		            if( $ref_count <= 1 )
-		            {
-		                M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
-		            }
-		        }
-		    
-		        $order_info['total'] = $refund_fee / 100;
-		    
-		    
-		        $order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_info['order_id']) )->select();
-		        	
-		        $order_goods_name_arr = array();
-		        $order_goods_name = '';
-		        	
-		        foreach($order_goods_list as $order_goods)
-		        {
-		            	
-		            $order_goods_name_arr[] = $order_goods['name'];
-		            //...
-		            if( !empty($order_goods_id) && $order_goods_id > 0  )
-		            {
-		                if($order_goods_id ==  $order_goods['order_goods_id'] )
-		                {
-		                    if($is_back_sellcount == 1)
-		                    {
-		                        if( $is_zi_order_refund == 1 && $refund_quantity > 0 )
-		                        {
-		                            D('Home/Pingoods')->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$refund_quantity,2);
-		                        }else{
-		                            //获取已退款数量
-		                            $has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
-		                            if(!$has_refund_quantity){
-		                                $has_refund_quantity = 0;
-		                            }
-		                            D('Home/Pingoods')->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
-		                        }
-		                    }
-		                    	
-		                    $score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_id' => $order_info['order_id'],'order_goods_id'=>$order_goods['order_goods_id'] ,'type' => 'orderbuy') )->find();
-		                    	
-		                    if( !empty($score_refund_info) && $is_zi_order_refund == 1  )
-		                    {
-		                        // D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
-		                    }
-		                }
-		            }else if( empty($order_goods_id) || $order_goods_id <=0 ){
-		                if($is_back_sellcount == 1){
-		                    $has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
-		                    if(!$has_refund_quantity){
-		                        $has_refund_quantity = 0;
-		                    }
-		                    D('Home/Pingoods')->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
-		                }
-		    
-		    
-		                $score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_id' => $order_info['order_id'],'order_goods_id' =>$order_goods['order_goods_id'] ,'type' => 'orderbuy') )->find();
-		    
-		                if( !empty($score_refund_info) )
-		                {
-		                    // D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
-		                }
-		            }
-		            	
-		            if( $order_info['type'] == 'integral' )
-		            {
-		                D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$order_goods['total'], 0 ,'退款增加积分','refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
-		            }
-		    
-		        }
-		    
-		        $order_goods_name = implode('\r\n', $order_goods_name_arr); //."\r\n";
-		    
-		        	
-		        //分佣也要退回去
-		        if($is_zi_order_refund == 0)
-		            D('Seller/Community')->back_order_commission($order_info['order_id'],$order_goods_id);
-		    
-		        return array('code' => 1);
-		    
-		    } else {
-		    
-		        $order_refund_history = array();
-		        $order_refund_history['order_id'] =  $order_info['order_id'];
-		        $order_refund_history['order_goods_id'] =  $order_goods_id;
-		    
-		        $order_refund_history['message'] = $res['err_code_des'];
-		        $order_refund_history['type'] = 2;
-		        $order_refund_history['addtime'] = time();
-		    
-		        M('lionfish_comshop_order_refund_history')->add($order_refund_history);
-		    
-		        /**
-		         M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 10, 'remarksaler' => $res[err_code_des]) );
-		        **/
-		    
-		        return array('code' => 0, 'msg' => $res['err_code_des']);
-		    
-		    }
-		    
-		}
-		else {
-            $order_relate_info = M('lionfish_comshop_order_relate')->where( array('order_id' => $order_id ) )->order('id desc')->find();
-            
-            if( !empty($order_relate_info) && $order_relate_info['order_all_id'] > 0 )
-            {
-                $order_all_info = M('lionfish_comshop_order_all')->where( array('id' => $order_relate_info['order_all_id'] ) )->find();
-                	
-                if( !empty($order_all_info) && !empty($order_all_info['out_trade_no']) )
-                {
-            
-                    $out_trade_no = $order_all_info['out_trade_no'];
-            
-                    $appid =  D('Home/Front')->get_config_by_name('wepro_appid');
-                    $mch_id =      D('Home/Front')->get_config_by_name('wepro_partnerid');
-                    $nonce_str =    nonce_str();
-            
-                    $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
-            
-            
-                    $post = array();
-                    $post['appid'] = $appid;
-                    $post['mch_id'] = $mch_id;
-                    $post['nonce_str'] = $nonce_str;
-                    $post['out_trade_no'] = $out_trade_no;
-                    	
-                    $sign = sign($post,$pay_key);
-            
-                    $post_xml = '<xml>
-							   <appid>'.$appid.'</appid>
-							   <mch_id>'.$mch_id.'</mch_id>
-							   <nonce_str>'.$nonce_str.'</nonce_str>
-							   <out_trade_no>'.$out_trade_no.'</out_trade_no>
-							   <sign>'.$sign.'</sign>
-							</xml>';
-                    	
-                    $url = "https://api.mch.weixin.qq.com/pay/orderquery";
-            
-                    $result = http_request($url,$post_xml);
-            
-                    $array = xml($result);
-            
-                    if( $array['RETURN_CODE'] == 'SUCCESS' && $array['RETURN_MSG'] == 'OK' )
-                    {
-                        if( $array['TRADE_STATE'] == 'SUCCESS' || $array['TRADE_STATE'] == 'REFUND' ) 
-                        {
-                           $total_fee = $array['TOTAL_FEE'];
-                        }
-                    }
-            
-                }
-            }
-            
-            //
-			
-			
-			$input = new \WxPayRefund();
-			
-			$input->SetTransaction_id($transaction_id);
-			$input->SetTotal_fee($total_fee);
-			$input->SetRefund_fee($refund_fee);
-			
-			$mchid = D('Home/Front')->get_config_by_name('wepro_partnerid');
-			
-			$refund_no = $mchid.date("YmdHis").$order_info['order_id'];
-			
-			$input->SetOut_refund_no($refund_no);
-			$input->SetOp_user_id($mchid);
-			
-			
-			$res = \WxPayApi::refund($input,6,$order_info['from_type']);
-			
-			if($res["return_code"] == 'FAIL'){
-          		return array('code' => 0, 'msg' => $res['return_msg']);
-			}
-			
-			if( $res['err_code_des'] == '订单已全额退款' )
-			{
-				$res['result_code'] = 'SUCCESS';
-			}
-			
-			if($res['result_code'] == 'SUCCESS')
-			{
-				
-				if($order_info['order_status_id'] == 12)
-				{
-					$ref_count = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_info['order_id'], 'state' => 0 ) )->count();
-					if( $ref_count <= 1 )
-					{
-						M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
-					}
-				}
-				
-				$order_info['total'] = $refund_fee / 100;
-				
-				
-				$order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_info['order_id']) )->select();	
-					
-				$order_goods_name_arr = array();
-				$order_goods_name = '';
-					
-				foreach($order_goods_list as $order_goods)
-				{
-					
-					$order_goods_name_arr[] = $order_goods['name'];
-					//...
-					if( !empty($order_goods_id) && $order_goods_id > 0  )
-					{
-						if($order_goods_id ==  $order_goods['order_goods_id'] )
-						{
-							if($is_back_sellcount == 1)
-							{
-								if( $is_zi_order_refund == 1 && $refund_quantity > 0 )
-								{
-									D('Home/Pingoods')->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$refund_quantity,2);
-								}else{
-									//获取已退款数量
-									$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
-									if(!$has_refund_quantity){
-										$has_refund_quantity = 0;
-									}
-									D('Home/Pingoods')->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
-								}
-							}
-							
-							$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_id' => $order_info['order_id'],'order_goods_id'=>$order_goods['order_goods_id'] ,'type' => 'orderbuy') )->find();
-							
-							if( !empty($score_refund_info) && $is_zi_order_refund == 1  )
-							{
-								// D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
-							}
-						}
-					}else if( empty($order_goods_id) || $order_goods_id <=0 ){
-						if($is_back_sellcount == 1){
-							$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
-							if(!$has_refund_quantity){
-								$has_refund_quantity = 0;
-							}
-							D('Home/Pingoods')->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
-						}
-
-						
-						$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_id' => $order_info['order_id'],'order_goods_id' =>$order_goods['order_goods_id'] ,'type' => 'orderbuy') )->find();
-						
-						if( !empty($score_refund_info) )
-						{
-							// D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
-						}
-					}
-					
-					if( $order_info['type'] == 'integral' )
-					{
-						D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$order_goods['total'], 0 ,'退款增加积分','refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
-					}
-				
-				}
-				
-				$order_goods_name = implode('\r\n', $order_goods_name_arr); //."\r\n";	
-		
-				 
-				//分佣也要退回去 
-				if($is_zi_order_refund == 0)
-					D('Seller/Community')->back_order_commission($order_info['order_id'],$order_goods_id);
-				
-				return array('code' => 1);
-				
-			} else {
-				
-				$order_refund_history = array();
-				$order_refund_history['order_id'] =  $order_info['order_id'];
-				$order_refund_history['order_goods_id'] =  $order_goods_id;
-				
-				$order_refund_history['message'] = $res['err_code_des'];
-				$order_refund_history['type'] = 2;
-				$order_refund_history['addtime'] = time();
-				
-				M('lionfish_comshop_order_refund_history')->add($order_refund_history);
-				
-				/**
-				M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 10, 'remarksaler' => $res[err_code_des]) );
-				**/
-				
-				return array('code' => 0, 'msg' => $res['err_code_des']);
-				
-			}
-			
-		}
-		
-		
-		
-		
-	}
-	
-	public function refundOrder2($order_id,$money =0)
-	{
-		
-		$lib_path = dirname(dirname( dirname(__FILE__) )).'/Lib/';
-		$data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
-		RecursiveMkdir($data_path);
-		
-		set_time_limit(0);
-		
-		
-		require_once $lib_path."/Weixin/lib/WxPay.Api.php";
-		require_once $lib_path."/Weixin/log.php";
-		
-		//初始化日志
-		$logHandler= new \CLogFileHandler( $data_path .date('Y-m-d').'.log');
-		
-		\Log::Init($logHandler, 15);
-		\Log::DEBUG("进行中,订单ID :".$order_id );
-		
-		//pin
-		$order_info = M('order')->where( array('order_id' => $order_id) )->find();
-		
-		$member_info = M('member')->where( array('member_id' => $order_info['member_id']) )->find();
-		
-		$openId = $member_info['openid'];
-		$we_openid = $member_info['we_openid'];
-		
-		if( $order_info['from_type'] == 'wepro' )
-		{
-			$openId = $we_openid;
-		}
-		//we_openid
-		//money
-		$transaction_id = $order_info["transaction_id"];
-		
-		
-		
-		$total_fee = ($order_info["total"])*100;
-		$refund_fee = $total_fee;
-		if($money > 0)
-		{
-			$refund_fee = $money * 100;
-		}
-		
-		
-		
-		if($order_info['payment_code'] == 'yuer')
-		{
-			//余额支付的,退款到余额
-			//退款到余额
-			$member_charge_flow_data = array();
-			$member_charge_flow_data['member_id'] = $order_info['member_id'];
-			$member_charge_flow_data['money'] = $order_info["total"];
-			$member_charge_flow_data['state'] = 4;
-			$member_charge_flow_data['trans_id'] = $order_id;
-			$member_charge_flow_data['charge_time'] = time();
-			$member_charge_flow_data['add_time'] = time();
-			
-			M('member_charge_flow')->add($member_charge_flow_data);
-			//增加会员余额
-			M('member')->where( array('member_id'=> $order_info['member_id'] ) )->setInc('account_money',$order_info["total"] ); 
-					
-			
-			$order_info['total'] = $refund_fee / 100;
-			$this->refundOrder_success($order_info,$openId);
-			//检测是否有需要退回积分的订单
-		}
-		else if($refund_fee == 0)
-		{
-			M('order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
-			
-			$config_info = M('config')->where( array('name' => 'SITE_URL') )->find();
-			
-			$order_goods = M('order_goods')->where( array('order_id' => $order_info['order_id']) )->select();
-			
-			$order_goods_name = '';
-			$order_goods_name_arr = array();
-			
-			foreach ($order_goods as $key => $value) {
-				
-				$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$value['rela_goodsoption_valueid'],$value['goods_id'],$value['quantity'],2);
-				//销量回退
-				//$this->execute("UPDATE " . C('DB_PREFIX') . "goods SET seller_count = (seller_count - " . (int)$value['quantity'] . ") WHERE goods_id = '" . $value['goods_id'] . "' ");
-				$order_goods_name_arr[] = $value['name'];
-			}
-			$order_goods_name = implode('\r\n', $order_goods_name_arr); //."\r\n";	
-		
-			
-			$msg = '订单退款: 您的订单'.$order_info['order_num_alias'].'参团未成功,现退款:'.round($order_info["total"],2).'元,商品名称:'.$order_goods_name;
-			$url = $config_info['value'];
-			
-			//weixin_template_refund_order
-			//send_template_msg($wx_template_data,$url,$openid,C('weixin_template_refund_order'));
-			$url = $url."/index.php?s=/Order/info/id/{$order_info['order_id']}.html";
-			
-			/**
-			{{first.DATA}}
-			订单编号:{{keyword1.DATA}}
-			退款金额:{{keyword2.DATA}}
-			{{remark.DATA}}
-			---------------------------
-			校白君提醒您,您有一笔退款成功,请留意。
-			订单编号:20088115853
-			退款金额:¥19.00
-			更多学生价好货,在底部菜单栏哦~猛戳“校园专区”,享更多优惠!
-			**/
-			
-			$wx_template_data = array();
-			$wx_template_data['first'] = array('value' => '退款通知', 'color' => '#030303');
-			$wx_template_data['keyword1'] = array('value' => $order_goods_name, 'color' => '#030303');
-			$wx_template_data['keyword2'] = array('value' => round($order_info["total"],2), 'color' => '#030303');
-			$wx_template_data['remark'] = array('value' => '拼团失败已按原路退款', 'color' => '#030303');
-		
-			
-			if( $order_info['from_type'] == 'wepro' )
-			{
-				$template_data = array();
-				$template_data['keyword1'] = array('value' => $order_goods_name, 'color' => '#030303');
-				$template_data['keyword2'] = array('value' => '参团未成功', 'color' => '#030303');
-				$template_data['keyword3'] = array('value' => '拼团失败已按原路退款', 'color' => '#030303');
-				
-				$pay_order_msg_info =  M('config')->where( array('name' => 'weprogram_template_fail_pin') )->find();
-				$template_id = $pay_order_msg_info['value'];
-				
-				
-				$pagepath = 'pages/order/order?id='.$order_info['order_id'];
-				
-				/**
-				$member_formid_info = M('member_formid')->where( array('member_id' => $order_info['member_id'], 'state' => 0) )->find();
-					
-				send_wxtemplate_msg($template_data,$url,$pagepath,$member_info['we_openid'],$template_id,$member_formid_info['formid']);
-				//更新
-				M('member_formid')->where( array('id' => $member_formid_info['id']) )->save( array('state' => 1) );
-				
-				$order_info['member_id']
-				**/
-				
-				$member_formid_info = M('member_formid')->where( array('member_id' => $order_info['member_id'], 'formid' =>array('neq',''), 'state' => 0) )->order('id desc')->find();
-				if(!empty( $member_formid_info ))
-				{
-					send_wxtemplate_msg($template_data,$url,$pagepath,$member_info['we_openid'],$template_id,$member_formid_info['formid'] );
-					M('member_formid')->where( array('id' => $member_formid_info['id']) )->save( array('state' => 1) );
-				}
-				
-				
-				if( $openid != '1')
-				{
-					//notify_weixin_msg($member_info['openid'],$msg,'退款通知',$url);
-					send_template_msg($wx_template_data,$url,$member_info['openid'],C('weixin_template_refund_order'));
-				}
-			}else{
-				//notify_weixin_msg($member_info['openid'],$msg,'退款通知',$url);
-				send_template_msg($wx_template_data,$url,$member_info['openid'],C('weixin_template_refund_order'));
-			}
-			
-			//检测是否有需要退回积分的订单
-			
-			\Log::DEBUG("退款成功。。。退款日志:退款订单号:" . $order_info['order_id'].',ten:'.$transaction_id.'   退款金额: '
-			.$order_info["total"].',退款给:openid='.$openId);
-			
-		} else {
-			
-			$input = new \WxPayRefund();
-			$input->SetTransaction_id($transaction_id);
-			$input->SetTotal_fee($total_fee);
-			$input->SetRefund_fee($refund_fee);
-			$refund_no = \WxPayConfig::MCHID.date("YmdHis").$order_info['order_id'];
-			
-			$input->SetOut_refund_no($refund_no);
-			$input->SetOp_user_id(\WxPayConfig::MCHID);
-			
-			$res = (\WxPayApi::refund($input,6,$order_info['from_type']));
-			
-			//var_dump($res);die();  wx80131aa7dfc4ff71
-			
-			if($res['result_code'] == 'SUCCESS')
-			{
-				$order_info['total'] = $refund_fee / 100;
-				$this->refundOrder_success($order_info,$openId);
-				
-				\Log::DEBUG("退款成功。。。退款日志:退款订单号:" . $order_info['order_id'].',ten:'.$transaction_id.'   退款金额: '.$order_info["total"].',退款给:openid='.$openid);
-				//检测是否有需要退回积分的订单
-				
-			} else {
-			
-				M('order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 10, 'comment' => $res[err_code_des]) );
-				
-				\Log::DEBUG("退款失败。原因:{$res[err_code_des]}。。退款日志:退款订单号:" . $order_info['order_id'].',退款金额: '.$order_info["total"].',退款给:openid='.$openId);
-			}
-			
-		}
-		
-		return true;
-	}
-	
-	/**
-		取消已经付款的 待发货订单
-		5、处理订单,
-		6、处理退款,
-	**/
-	public  function del_cancle_order($order_id)
-	{				
-		$order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
-		
-		
-		//判断订单状态是否已付款,避免多次退款,不合理
-		if( $order_info['order_status_id'] == 1 )
-		{
-			//del_cancle_order 
-			
-			$total_money = D('Seller/Commonorder')->get_order_paymoney( $order_id );
-			
-			$has_refun_money = D('Seller/Commonorder')->order_refund_totalmoney( $order_id );
-
-			//是否预售订单begin
-            $presale_result = D('Home/PresaleGoods')->getOrderPresaleInfo( $order_id );
-            $presale_info = [];
-            if( $presale_result['code'] == 0 )
-            {
-                $presale_info = $presale_result['data'];
-                $total_money = $total_money - $presale_info['presale_ding_money'];
-            }
-            //end
-
-			$refund_money = round($total_money - $has_refun_money,2);
-			
-			
-			
-			$result = $this->refundOrder($order_id, $refund_money);
-			
-		
-			if( $result['code'] == 1 )
-			{
-				$order_history = array();
-				$order_history['order_id'] = $order_id;
-				$order_history['order_status_id'] = 5;
-				$order_history['notify'] = 0;
-				$order_history['comment'] = '会员前台申请取消订单,取消成功,并退款。';
-				$order_history['date_added'] = time();
-				
-				M('lionfish_comshop_order_history')->add( $order_history );
-				
-				M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('order_status_id' => 5) );
-				
-				//整笔
-				D('Seller/Commonorder')->refund_one_order( $order_id ,1);
-				
-				
-				return array('code' => 0);
-			}else{
-				$order_history = array();
-				$order_history['order_id'] = $order_id;
-				$order_history['order_status_id'] = 10;
-				$order_history['notify'] = 0;
-				$order_history['comment'] = '申请取消订单,但是退款失败。';
-				$order_history['date_added'] = time();
-				
-				M('lionfish_comshop_order_history')->add( $order_history );
-				
-				M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->save( array('order_status_id' => 10, 'remarksaler' => $result['msg']) );
-				
-				return array('code' => 1, 'msg' => $result['msg'] ,'s' => $result['code'] );
-			}
-			
-		}
-		 //如果退款成功了。那么就进行
-		
-	}
-	
-	
-	
-	
-	public function test_form_msg()
-	{
-		$member_info = M('member')->where( array('member_id' => 26) )->find();
-		
-		$form_id_arr = M('member_formid')->where( array('member_id' => 26,'state' =>0) )->find();
-		
-		M('member_formid')->where( array('id' => $form_id_arr['id'] ) )->save( array('state' =>1) );
-		$form_id = $form_id_arr['formid'];
-		
-		$template_data = array();
-		$template_data['keyword1'] = array('value' => '338866', 'color' => '#030303');
-		$template_data['keyword2'] = array('value' => '商品名称', 'color' => '#030303');
-		$template_data['keyword3'] = array('value' => '18元', 'color' => '#030303');
-		$template_data['keyword4'] = array('value' => '已按原路退款', 'color' => '#030303');
-		$template_data['keyword5'] = array('value' => '小鱼', 'color' => '#030303');
-		
-		$pay_order_msg_info =  M('config')->where( array('name' => 'weprogram_template_refund_order') )->find();
-		$template_id = $pay_order_msg_info['value'];
-		
-		
-		$pagepath = 'pages/order/order?id='.$order_info['order_id'];
-			
-		$rs = 	send_wxtemplate_msg($template_data,$url,$pagepath,$member_info['we_openid'],$template_id,$form_id);
-			var_dump($rs);die();
-	}
-	
-	public function refundOrder_success($order_info,$openid)
-	{
-		M('order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
-		
-		$member_info = M('member')->where( array('member_id' => $order_info['member_id']) )->find();
-		
-		
-		$config_info = M('config')->where( array('name' => 'SITE_URL') )->find();
-		
-		$order_goods = M('order_goods')->where( array('order_id' => $order_info['order_id']) )->select();
-		$goods_model = D('Home/Goods');
-		
-		$order_goods_name = '';
-		$order_goods_name_arr = array();
-		
-		foreach ($order_goods as $key => $value) {
-			//$this->execute("UPDATE " . C('DB_PREFIX') . "goods SET quantity = (quantity + " . (int)$value['quantity'] . ") WHERE goods_id = '" . $value['goods_id'] . "' ");
-			
-			$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$value['rela_goodsoption_valueid'],$value['goods_id'],$value['quantity'],2);
-			//销量回退
-			//$this->execute("UPDATE " . C('DB_PREFIX') . "goods SET seller_count = (seller_count - " . (int)$value['quantity'] . ") WHERE goods_id = '" . $value['goods_id'] . "' ");
-			$order_goods_name_arr[] = $value['name'];
-		}
-			
-		$order_goods_name = implode('\r\n', $order_goods_name_arr); //."\r\n";	
-		
-		$msg = '订单退款: 您的订单'.$order_info['order_num_alias'].'参团未成功,现退款:'.round($order_info["total"],2).'元,商品名称:'.$order_goods_name;
-		$url = $config_info['value'];
-		
-		$wx_template_data = array();
-		$wx_template_data['first'] = array('value' => '退款通知', 'color' => '#030303');
-		$wx_template_data['keyword1'] = array('value' => $order_goods_name, 'color' => '#030303');
-		$wx_template_data['keyword2'] = array('value' => $order_info['total'].'元', 'color' => '#030303');
-		$wx_template_data['remark'] = array('value' => '已按原路退款', 'color' => '#030303');
-		
-		 
-		$url = $url."/index.php?s=/Order/info/id/{$order_info['order_id']}.html";
-		
-		
-		if( $order_info['from_type'] == 'wepro' )
-		{
-			/**
-			退款成功通知
-			关键词
-			订单号
-			{{keyword1.DATA}}
-			商品名称
-			{{keyword2.DATA}}
-			退款金额
-			{{keyword3.DATA}}
-			温馨提示
-			{{keyword4.DATA}}
-			备注
-			{{keyword5.DATA}}
-			**/
-			
-			//$total_money = ($order_info["total"],2);
-			
-			$template_data = array();
-			$template_data['keyword1'] = array('value' => $order_info['order_num_alias'], 'color' => '#030303');
-			$template_data['keyword2'] = array('value' => $order_goods_name, 'color' => '#030303');
-			$template_data['keyword3'] = array('value' => $order_info['total'].'元', 'color' => '#030303');
-			$template_data['keyword4'] = array('value' => '已按原路退款', 'color' => '#030303');
-			$template_data['keyword5'] = array('value' => $member_info['uname'], 'color' => '#030303');
-			
-			$pay_order_msg_info =  M('config')->where( array('name' => 'weprogram_template_refund_order') )->find();
-			$template_id = $pay_order_msg_info['value'];
-			
-			
-			$pagepath = 'pages/order/order?id='.$order_info['order_id'];
-			
-			
-			/**
-				$member_formid_info = M('member_formid')->where( array('member_id' => $order_info['member_id'], 'state' => 0) )->find();
-					
-				send_wxtemplate_msg($template_data,$url,$pagepath,$member_info['we_openid'],$template_id,$member_formid_info['formid']);
-				//更新
-				M('member_formid')->where( array('id' => $member_formid_info['id']) )->save( array('state' => 1) );
-				
-			**/
-			$member_formid_info = M('member_formid')->where( array('member_id' => $order_info['member_id'],'formid' =>array('neq',''), 'state' => 0) )->order('id desc')->find();
-				
-			//$order_info['member_id']
-			if( !empty($member_formid_info) )
-			{
-				$rs = 	send_wxtemplate_msg($template_data,$url,$pagepath,$member_info['we_openid'],$template_id,$member_formid_info['formid']);
-				M('member_formid')->where( array('id' => $member_formid_info['id']) )->save( array('state' => 1) );
-			}
-				
-			
-			if( $openid != '1')
-			{
-				//notify_weixin_msg($openid,$msg,'退款通知',$url);
-				send_template_msg($wx_template_data,$url,$openid,C('weixin_template_refund_order'));
-			
-			}
-		}else{
-			//notify_weixin_msg($openid,$msg,'退款通知',$url);
-			send_template_msg($wx_template_data,$url,$openid,C('weixin_template_refund_order'));
-			
-		}
-		
-		
-		
-	}
-}
+<?php
+/**
+ * lionfish 商城系统
+ *
+ * ==========================================================================
+ * @link      http://www.liofis.com/
+ * @copyright Copyright (c) 2015 liofis.com. 
+ * @license   http://www.liofis.com/license.html License
+ * ==========================================================================
+ *
+ * @author    fish
+ *
+ */
+namespace Home\Model;
+class WeixinModel{
+
+	
+	public function refundOrder($order_id, $money=0, $uniacid=0,$order_goods_id=0,$is_back_sellcount = 1,$refund_quantity = 0,$is_zi_order_refund =0)
+	
+	{
+		$_GPC = I('request.');
+		$lib_path = dirname(dirname( dirname(__FILE__) )).'/Lib/';
+		
+		set_time_limit(0);
+		
+		require_once $lib_path."/Weixin/lib/WxPay.Api.php";
+		
+		
+		$order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->find();
+		
+				
+		$member_info = M('lionfish_comshop_member')->where( array('member_id' => $order_info['member_id'] ) )->find();		
+		
+		
+		$openId = $member_info['openid'];
+		$we_openid = $member_info['we_openid'];
+		
+		if( $order_info['from_type'] == 'wepro' )
+		{
+			$openId = $we_openid;
+		}
+		//we_openid
+		//money
+		$transaction_id = $order_info["transaction_id"];
+		
+		
+		if( $order_info['type'] == 'integral' )
+		{
+			$total_fee = ( $order_info["shipping_fare"] )*100;
+		
+		}else{
+			$total_fee = ($order_info["total"] + $order_info["shipping_fare"]-$order_info['voucher_credit']-$order_info['fullreduction_money'] - $order_info['score_for_money']-$order_info['fare_shipping_free'] )*100;
+		}
+		
+		//预售begin
+        $presale_result = D('Home/PresaleGoods')->getOrderPresaleInfo( $order_id );
+		if( $presale_result['code'] ==0 )
+        {
+            $total_fee = $total_fee - $presale_result['data']['presale_ding_money'] * 100;
+        }
+        //end
+
+		$refund_fee = $total_fee;
+		
+		
+		
+		//order_goods_id
+		if( !empty($order_goods_id) )
+		{
+			$order_goods_info = M('lionfish_comshop_order_goods')->where( array('order_goods_id' =>$order_goods_id ) )->find();
+			
+			$refund_fee = ($order_goods_info["total"] + $order_goods_info["shipping_fare"]-$order_goods_info['voucher_credit']-$order_goods_info['fullreduction_money'] - $order_goods_info['score_for_money']-$order_goods_info['fare_shipping_free'])*100;
+		
+			if( $order_info['type'] == 'integral' )
+			{
+				$refund_fee = ( $order_goods_info["shipping_fare"] )*100;
+			}
+		}
+		
+		
+		if($money > 0 && $order_info['type'] != 'integral' )
+		{
+			$refund_fee = $money * 100;
+		}else if(  $money > 0 && $order_info['type'] == 'integral' && !empty($order_goods_info) ) 
+		{
+			if(!empty($_GPC['refund_money'])){
+					$refund_money = isset($_GPC['refund_money']) && $_GPC['refund_money'] >0  ? floatval($_GPC['refund_money']) : 0;
+					//商品多个运费和
+					$refund_fee = ( $money - $refund_money )*100;
+					//商品多个商品单价和
+					$order_info['total'] = $refund_money;
+			}else{
+				$order_refund_history_image = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_id) )->order('addtime asc')->find();	
+				$ref_shipping_fare = M('lionfish_comshop_order_refund')->field('ref_id,ref_money,real_refund_quantity,ref_shipping_fare')->where( array('order_id' => $order_id ))->order('ref_id desc')->find();
+				$refund_fee = ( $ref_shipping_fare['ref_shipping_fare'] )*100;
+				$order_info['total'] = $money ;
+			}
+		}
+		// else if( isset($is_open_yinpay) && $is_open_yinpay == 3 )  
+		    
+		$is_open_yinpay = D('Home/Front')->get_config_by_name('is_open_yinpay');
+		
+		if($order_info['payment_code'] == 'yuer')
+		{
+			//余额支付的,退款到余额
+			//退款到余额
+			
+			//增加会员余额
+			$refund_fee = $refund_fee / 100;
+
+			if( $refund_fee > 0 )
+			{
+				//判断是否积分类型的
+
+				M('lionfish_comshop_member')->where( array('member_id' => $order_info['member_id']) )->setInc('account_money',$refund_fee);
+				
+				$account_money_info = M('lionfish_comshop_member')->field('account_money')->where( array('member_id' =>$order_info['member_id'] ) )->find();
+		
+				$account_money = $account_money_info['account_money'];
+				
+		
+				$member_charge_flow_data = array();
+				
+				$member_charge_flow_data['member_id'] = $order_info['member_id'];
+				$member_charge_flow_data['money'] = $refund_fee;
+				$member_charge_flow_data['operate_end_yuer'] = $account_money;
+				$member_charge_flow_data['state'] = 4;
+				$member_charge_flow_data['trans_id'] = $order_id;
+				$member_charge_flow_data['order_goods_id'] = $order_goods_id;
+				$member_charge_flow_data['charge_time'] = time();
+				$member_charge_flow_data['add_time'] = time();
+				
+				M('lionfish_comshop_member_charge_flow')->add($member_charge_flow_data);
+			}
+			
+			
+			if($order_info['order_status_id'] == 12)
+			{
+				$ref_count = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_info['order_id'], 'state' => 0 ) )->count();
+				
+				
+				if( $ref_count <= 1 )
+				{
+					M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
+				}
+			}
+			
+			
+			
+			
+			$order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_info['order_id'] ) )->select();
+			
+			$goods_model = D('Home/Pingoods');
+			
+			foreach($order_goods_list as $order_goods)
+			{
+				//$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity'],2);
+				
+				if( !empty($order_goods_id) && $order_goods_id > 0  )
+				{
+					if($order_goods_id ==  $order_goods['order_goods_id'] )
+					{
+						
+						if($is_back_sellcount == 1)
+						{
+							if( $is_zi_order_refund == 1 && $refund_quantity > 0 )
+							{
+								$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$refund_quantity,2);
+							}else{
+								//获取已退款数量
+								$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
+								if(!$has_refund_quantity){
+									$has_refund_quantity = 0;
+								}
+								$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
+							}
+						}
+						
+						$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_goods_id' => $order_goods['order_goods_id'],'order_id' =>$order_info['order_id'],'type' => 'orderbuy' ) )->find();
+						
+						if( !empty($score_refund_info) && $is_zi_order_refund == 1  )
+						{
+							// D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+						}
+					}
+				}else if( empty($order_goods_id) || $order_goods_id <=0 ){
+					if($is_back_sellcount == 1){
+						//获取已退款数量
+						$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
+						if(!$has_refund_quantity){
+							$has_refund_quantity = 0;
+						}
+						$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
+					}
+
+					
+					$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_goods_id' => $order_goods['order_goods_id'],'order_id' => $order_info['order_id'] ,'type' => 'orderbuy') )->find();			
+										
+					if( !empty($score_refund_info) )
+					{
+						// D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分','refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+					}
+				}
+				
+				if( $order_info['type'] == 'integral' )
+				{
+					
+					D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$order_info['total'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+				}
+			}
+			//分佣也要退回去
+			if($is_zi_order_refund == 0)
+					D('Seller/Community')->back_order_commission($order_info['order_id'],$order_goods_id);
+				
+			return array('code' => 1);
+			//$this->refundOrder_success($order_info,$openId);
+			//检测是否有需要退回积分的订单
+		//货到付款订单
+		}else if($order_info['payment_code'] == 'cashon_delivery')
+		{
+			//货到付款订单退款金额不到账,但有退款记录
+
+			if($order_info['order_status_id'] == 12)
+			{
+				$ref_count = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_info['order_id'], 'state' => 0 ) )->count();
+
+				if( $ref_count <= 1 )
+				{
+					M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
+				}
+			}
+
+			$order_info['total'] = $refund_fee / 100;
+
+			$order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_info['order_id'] ) )->select();
+
+			$goods_model = D('Home/Pingoods');
+
+			foreach($order_goods_list as $order_goods)
+			{
+				//$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity'],2);
+
+				if( !empty($order_goods_id) && $order_goods_id > 0  )
+				{
+					if($order_goods_id ==  $order_goods['order_goods_id'] )
+					{
+
+						if($is_back_sellcount == 1)
+						{
+							if( $is_zi_order_refund == 1 && $refund_quantity > 0 )
+							{
+								$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$refund_quantity,2);
+							}else{
+								//获取已退款数量
+								$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
+								if(!$has_refund_quantity){
+									$has_refund_quantity = 0;
+								}
+								$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
+							}
+						}
+
+						$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_goods_id' => $order_goods['order_goods_id'],'order_id' =>$order_info['order_id'],'type' => 'orderbuy' ) )->find();
+
+						if( !empty($score_refund_info) && $is_zi_order_refund == 1  )
+						{
+							// D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+						}
+					}
+				}else if( empty($order_goods_id) || $order_goods_id <=0 ){
+					if($is_back_sellcount == 1){
+						//获取已退款数量
+						$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
+						if(!$has_refund_quantity){
+							$has_refund_quantity = 0;
+						}
+						$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
+					}
+
+
+					$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_goods_id' => $order_goods['order_goods_id'],'order_id' => $order_info['order_id'] ,'type' => 'orderbuy') )->find();
+
+					if( !empty($score_refund_info) )
+					{
+						// D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分','refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+					}
+				}
+
+				/*if( $order_info['type'] == 'integral' )
+				{
+
+					D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$order_info['total'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+				}*/
+			}
+			//分佣也要退回去
+			if($is_zi_order_refund == 0)
+				D('Seller/Community')->back_order_commission($order_info['order_id'],$order_goods_id);
+
+			return array('code' => 1);
+			//$this->refundOrder_success($order_info,$openId);
+			//检测是否有需要退回积分的订单
+		}
+		else if($order_info['payment_code'] == 'admin'){
+			 
+			if($order_info['order_status_id'] == 12)
+			{
+				$ref_count = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_info['order_id'], 'state' => 0 ) )->count();
+				if( $ref_count <= 1 )
+				{
+					M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
+				}
+			}
+				
+			$order_info['total'] = $refund_fee / 100;
+			
+			$order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_info['order_id'] ) )->select();
+			
+			
+			$goods_model = D('Home/Pingoods');
+			foreach($order_goods_list as $order_goods)
+			{
+				//$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity'],2);
+				
+				if( !empty($order_goods_id) && $order_goods_id > 0  )
+				{
+					if($order_goods_id ==  $order_goods['order_goods_id'] )
+					{
+						
+						if($is_back_sellcount == 1)
+						{
+							if( $is_zi_order_refund == 1 && $refund_quantity > 0 )
+							{
+								$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$refund_quantity,2);
+							}else{
+								//获取已退款数量
+								$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
+								if(!$has_refund_quantity){
+									$has_refund_quantity = 0;
+								}
+								$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
+							}
+						}	
+						
+						$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_goods_id' => $order_goods['order_goods_id'],'order_id' =>$order_info['order_id'],'type' => 'orderbuy' ) )->find();
+						
+						if( !empty($score_refund_info) && $is_zi_order_refund == 1 )
+						{
+							 //D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+						}
+					}
+				}else if( empty($order_goods_id) || $order_goods_id <=0 ){
+					if($is_back_sellcount == 1){
+						//获取已退款数量
+						$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
+						if(!$has_refund_quantity){
+							$has_refund_quantity = 0;
+						}
+						$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
+					}
+
+					
+					$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_goods_id' => $order_goods['order_goods_id'],'order_id' => $order_info['order_id'] ,'type' => 'orderbuy') )->find();			
+										
+					if( !empty($score_refund_info) )
+					{
+						// D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分','refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+					}
+				}
+				
+				if( $order_info['type'] == 'integral' )
+				{
+					//D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$order_goods['total'], 0 ,'退款增加积分','refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+				}
+			
+			}
+			//分佣也要退回去
+			if($is_zi_order_refund == 0)
+				D('Seller/Community')->back_order_commission($order_info['order_id'],$order_goods_id);
+			return array('code' => 1);
+			
+		}
+		else if($refund_fee == 0)
+		{
+			if($order_info['order_status_id'] == 12)
+			{
+				$ref_count = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_info['order_id'], 'state' => 0 ) )->count();
+				if( $ref_count <= 1 )
+				{
+					M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
+				}
+			}
+				
+			//ims_ lionfish_comshop_order_goods
+			$order_goods = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_info['order_id']) )->select();
+			
+			$order_goods_name = '';
+			$order_goods_name_arr = array();
+			$goods_model = D('Home/Pingoods');
+			
+			//get_config_by_name($name) 
+			
+			
+			
+			foreach ($order_goods as $key => $value) {
+				//($order_id,$option,$goods_id,$quantity,$type='1')
+				if($is_back_sellcount == 1)
+				{
+					if( $is_zi_order_refund == 1 && $refund_quantity > 0 )
+					{
+						$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$value['rela_goodsoption_valueid'],$value['goods_id'],$refund_quantity,2);
+					}else{
+						//获取已退款数量
+						$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
+						if(!$has_refund_quantity){
+							$has_refund_quantity = 0;
+						}
+						$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$value['rela_goodsoption_valueid'],$value['goods_id'],$value['quantity']-$has_refund_quantity,2);
+					}
+				}	
+				
+				$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_id' =>$order_info['order_id'] ,'order_goods_id' =>$value['order_goods_id'] ,'type' => 'orderbuy') )->find();
+				
+				if( !empty($score_refund_info) )
+				{
+					// D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分','refundorder', $order_info['order_id'] ,$value['order_goods_id'] );
+				}
+					
+				//销量回退
+				$order_goods_name_arr[] = $value['name'];
+			}
+			$order_goods_name = implode('\r\n', $order_goods_name_arr); //."\r\n";	
+		
+			
+			$msg = '订单退款: 您的订单'.$order_info['order_num_alias'].'参团未成功,现退款:'.round($order_info["total"],2).'元,商品名称:'.$order_goods_name;
+			
+			$url = D('Home/Front')->get_config_by_name('shop_domain');
+			
+			//weixin_template_refund_order
+			//send_template_msg($wx_template_data,$url,$openid,C('weixin_template_refund_order'));
+			
+			/**
+			{{first.DATA}}
+			订单编号:{{keyword1.DATA}}
+			退款金额:{{keyword2.DATA}}
+			{{remark.DATA}}
+			---------------------------
+			校白君提醒您,您有一笔退款成功,请留意。
+			订单编号:20088115853
+			退款金额:¥19.00
+			更多学生价好货,在底部菜单栏哦~猛戳“校园专区”,享更多优惠!
+			**/
+			
+			$wx_template_data = array();
+			$wx_template_data['first'] = array('value' => '退款通知', 'color' => '#030303');
+			$wx_template_data['keyword1'] = array('value' => $order_goods_name, 'color' => '#030303');
+			$wx_template_data['keyword2'] = array('value' => round($order_info["total"],2), 'color' => '#030303');
+			$wx_template_data['remark'] = array('value' => '拼团失败已按原路退款', 'color' => '#030303');
+		
+			
+			if( $order_info['from_type'] == 'wepro' )
+			{
+				$template_data = array();
+				$template_data['keyword1'] = array('value' => $order_info['order_num_alias'], 'color' => '#030303');
+				$template_data['keyword2'] = array('value' => '商户名称', 'color' => '#030303');
+				$template_data['keyword2'] = array('value' => $order_goods_name, 'color' => '#030303');
+				$template_data['keyword3'] = array('value' => $order_info['total'].'元', 'color' => '#030303');
+				$template_data['keyword4'] = array('value' => '已按原路退款', 'color' => '#030303');
+				$template_data['keyword5'] = array('value' => $member_info['uname'], 'color' => '#030303');
+				
+				
+				$template_id = D('Home/Front')->get_config_by_name('weprogram_template_refund_order');
+				
+				$pagepath = 'lionfish_comshop/pages/order/order?id='.$order_info['order_id'];
+				
+				
+				$member_formid_info = M('lionfish_comshop_member_formid')->where("member_id=".$order_info['member_id']." and formid != '' and state =0")->order('id desc')->find();
+				
+				if(!empty( $member_formid_info ))
+				{
+					D('Seller/User')->send_wxtemplate_msg($template_data,$url,$pagepath,$member_info['we_openid'],$template_id,$member_formid_info['formid'] );
+					
+					M('lionfish_comshop_member_formid')->where( array('id' => $member_formid_info['id']) )->save(array('state' => 1));
+				}
+				
+				if( $openid != '1')
+				{
+					//send_template_msg($wx_template_data,$url,$member_info['openid'],C('weixin_template_refund_order'));
+				}
+			}else{
+				//send_template_msg($wx_template_data,$url,$member_info['openid'],C('weixin_template_refund_order'));
+			}
+			
+			//检测是否有需要退回积分的订单
+			
+		}
+		else if( isset($is_open_yinpay) && $is_open_yinpay == 3 )
+		{
+		    $order_relate_info = M('lionfish_comshop_order_relate')->where( array('order_id' => $order_id ) )->order('id desc')->find();
+		    
+		    if( !empty($order_relate_info) && $order_relate_info['order_all_id'] > 0 )
+		    {
+		        $order_all_info = M('lionfish_comshop_order_all')->where( array('id' => $order_relate_info['order_all_id'] ) )->find();
+		         
+		        if( !empty($order_all_info) && !empty($order_all_info['out_trade_no']) )
+		        {
+		    
+		            $out_trade_no = $order_all_info['out_trade_no'];
+		    
+		            $appid =  D('Home/Front')->get_config_by_name('wepro_fuwu_appid');
+		            $mch_id =      D('Home/Front')->get_config_by_name('wepro_fuwu_partnerid');
+		            
+		            $nonce_str =    nonce_str();
+		    
+		            $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
+		    
+		            $sub_appid = D('Home/Front')->get_config_by_name('wepro_appid');
+		            $sub_mch_id = D('Home/Front')->get_config_by_name('wepro_sub_mch_id');
+		            
+		            
+		            $post = array();
+		            $post['appid'] = $appid;
+		            $post['mch_id'] = $mch_id;
+		            $post['nonce_str'] = $nonce_str;
+		            $post['out_trade_no'] = $out_trade_no;
+		            $post['sub_appid'] = $sub_appid;
+		            $post['sub_mch_id'] = $sub_mch_id;
+		             
+		            $sign = sign($post,$pay_key);
+		    
+		            $post_xml = '<xml>
+							   <appid>'.$appid.'</appid>
+							   <mch_id>'.$mch_id.'</mch_id>
+							   <nonce_str>'.$nonce_str.'</nonce_str>
+							   <out_trade_no>'.$out_trade_no.'</out_trade_no>
+							   <sub_appid>'.$post['sub_appid'].'</sub_appid>
+							   <sub_mch_id>'.$post['sub_mch_id'].'</sub_mch_id>
+							   <sign>'.$sign.'</sign>
+							</xml>';
+		             
+		            $url = "https://api.mch.weixin.qq.com/pay/orderquery";
+		    
+		            $result = http_request($url,$post_xml);
+		    
+		            $array = xml($result);
+		    
+		            if( $array['RETURN_CODE'] == 'SUCCESS' && $array['RETURN_MSG'] == 'OK' )
+		            {
+		                if( $array['TRADE_STATE'] == 'SUCCESS' || $array['TRADE_STATE'] == 'REFUND' )
+		                {
+		                    $total_fee = $array['TOTAL_FEE'];
+		                }
+		            }
+		    
+		        }
+		    }
+		    
+		    //
+		    	
+		    	
+		    $input = new \WxPayRefund();
+		    	
+		    $input->SetTransaction_id($transaction_id);
+		    $input->SetTotal_fee($total_fee);
+		    $input->SetRefund_fee($refund_fee);
+		    	
+		    $mchid = D('Home/Front')->get_config_by_name('wepro_partnerid');
+		    	
+		    $refund_no = $mchid.date("YmdHis").$order_info['order_id'];
+		    	
+		    $input->SetOut_refund_no($refund_no);
+		    $input->SetOp_user_id($mchid);
+		    	
+		    	
+		    $res = \WxPayApi::refund($input,6,'teweixin');
+		    	
+		    if($res["return_code"] == 'FAIL'){
+          		return array('code' => 0, 'msg' => $res['return_msg']);
+			}	
+		    	
+		    if( $res['err_code_des'] == '订单已全额退款' )
+		    {
+		        $res['result_code'] = 'SUCCESS';
+		    }
+		    	
+		    if($res['result_code'] == 'SUCCESS')
+		    {
+		    
+		        if($order_info['order_status_id'] == 12)
+		        {
+		            $ref_count = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_info['order_id'], 'state' => 0 ) )->count();
+		            if( $ref_count <= 1 )
+		            {
+		                M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
+		            }
+		        }
+		    
+		        $order_info['total'] = $refund_fee / 100;
+		    
+		    
+		        $order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_info['order_id']) )->select();
+		        	
+		        $order_goods_name_arr = array();
+		        $order_goods_name = '';
+		        	
+		        foreach($order_goods_list as $order_goods)
+		        {
+		            	
+		            $order_goods_name_arr[] = $order_goods['name'];
+		            //...
+		            if( !empty($order_goods_id) && $order_goods_id > 0  )
+		            {
+		                if($order_goods_id ==  $order_goods['order_goods_id'] )
+		                {
+		                    if($is_back_sellcount == 1)
+		                    {
+		                        if( $is_zi_order_refund == 1 && $refund_quantity > 0 )
+		                        {
+		                            D('Home/Pingoods')->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$refund_quantity,2);
+		                        }else{
+		                            //获取已退款数量
+		                            $has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
+		                            if(!$has_refund_quantity){
+		                                $has_refund_quantity = 0;
+		                            }
+		                            D('Home/Pingoods')->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
+		                        }
+		                    }
+		                    	
+		                    $score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_id' => $order_info['order_id'],'order_goods_id'=>$order_goods['order_goods_id'] ,'type' => 'orderbuy') )->find();
+		                    	
+		                    if( !empty($score_refund_info) && $is_zi_order_refund == 1  )
+		                    {
+		                        // D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+		                    }
+		                }
+		            }else if( empty($order_goods_id) || $order_goods_id <=0 ){
+		                if($is_back_sellcount == 1){
+		                    $has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
+		                    if(!$has_refund_quantity){
+		                        $has_refund_quantity = 0;
+		                    }
+		                    D('Home/Pingoods')->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
+		                }
+		    
+		    
+		                $score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_id' => $order_info['order_id'],'order_goods_id' =>$order_goods['order_goods_id'] ,'type' => 'orderbuy') )->find();
+		    
+		                if( !empty($score_refund_info) )
+		                {
+		                    // D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+		                }
+		            }
+		            	
+		            if( $order_info['type'] == 'integral' )
+		            {
+		                D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$order_goods['total'], 0 ,'退款增加积分','refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+		            }
+		    
+		        }
+		    
+		        $order_goods_name = implode('\r\n', $order_goods_name_arr); //."\r\n";
+		    
+		        	
+		        //分佣也要退回去
+		        if($is_zi_order_refund == 0)
+		            D('Seller/Community')->back_order_commission($order_info['order_id'],$order_goods_id);
+		    
+		        return array('code' => 1);
+		    
+		    } else {
+		    
+		        $order_refund_history = array();
+		        $order_refund_history['order_id'] =  $order_info['order_id'];
+		        $order_refund_history['order_goods_id'] =  $order_goods_id;
+		    
+		        $order_refund_history['message'] = $res['err_code_des'];
+		        $order_refund_history['type'] = 2;
+		        $order_refund_history['addtime'] = time();
+		    
+		        M('lionfish_comshop_order_refund_history')->add($order_refund_history);
+		    
+		        /**
+		         M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 10, 'remarksaler' => $res[err_code_des]) );
+		        **/
+		    
+		        return array('code' => 0, 'msg' => $res['err_code_des']);
+		    
+		    }
+		    
+		}
+		else {
+			
+			
+            
+            $order_relate_info = M('lionfish_comshop_order_relate')->where( array('order_id' => $order_id ) )->order('id desc')->find();
+            
+            if( !empty($order_relate_info) && $order_relate_info['order_all_id'] > 0 )
+            {
+                $order_all_info = M('lionfish_comshop_order_all')->where( array('id' => $order_relate_info['order_all_id'] ) )->find();
+                	
+                if( !empty($order_all_info) && !empty($order_all_info['out_trade_no']) )
+                {
+            
+                    $out_trade_no = $order_all_info['out_trade_no'];
+            
+                    $appid =  D('Home/Front')->get_config_by_name('wepro_appid');
+                    $mch_id =      D('Home/Front')->get_config_by_name('wepro_partnerid');
+                    $nonce_str =    nonce_str();
+            
+                    $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
+            
+            
+                    $post = array();
+                    $post['appid'] = $appid;
+                    $post['mch_id'] = $mch_id;
+                    $post['nonce_str'] = $nonce_str;
+                    $post['out_trade_no'] = $out_trade_no;
+                    	
+                    $sign = sign($post,$pay_key);
+            
+                    $post_xml = '<xml>
+							   <appid>'.$appid.'</appid>
+							   <mch_id>'.$mch_id.'</mch_id>
+							   <nonce_str>'.$nonce_str.'</nonce_str>
+							   <out_trade_no>'.$out_trade_no.'</out_trade_no>
+							   <sign>'.$sign.'</sign>
+							</xml>';
+                    	
+                    $url = "https://api.mch.weixin.qq.com/pay/orderquery";
+            
+                    $result = http_request($url,$post_xml);
+            
+                    $array = xml($result);
+            
+                    if( $array['RETURN_CODE'] == 'SUCCESS' && $array['RETURN_MSG'] == 'OK' )
+                    {
+                        if( $array['TRADE_STATE'] == 'SUCCESS' || $array['TRADE_STATE'] == 'REFUND' ) 
+                        {
+                           $total_fee = $array['TOTAL_FEE'];
+                        }
+                    }
+            
+                }
+            }
+            
+            //
+			
+			
+			$input = new \WxPayRefund();
+			
+			$input->SetTransaction_id($transaction_id);
+			$input->SetTotal_fee($total_fee);
+			$input->SetRefund_fee($refund_fee);
+			
+			$mchid = D('Home/Front')->get_config_by_name('wepro_partnerid');
+			
+			$refund_no = $mchid.date("YmdHis").$order_info['order_id'];
+			
+			$input->SetOut_refund_no($refund_no);
+			$input->SetOp_user_id($mchid);
+			
+			
+			$res = \WxPayApi::refund($input,6,$order_info['from_type']);
+			
+			if($res["return_code"] == 'FAIL'){
+          		return array('code' => 0, 'msg' => $res['return_msg']);
+			}
+			
+			if( $res['err_code_des'] == '订单已全额退款' )
+			{
+				$res['result_code'] = 'SUCCESS';
+			}
+			
+			if($res['result_code'] == 'SUCCESS')
+			{
+				
+				if($order_info['order_status_id'] == 12)
+				{
+					$ref_count = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_info['order_id'], 'state' => 0 ) )->count();
+					if( $ref_count <= 1 )
+					{
+						M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
+					}
+				}
+				
+				$order_info['total'] = $refund_fee / 100;
+				
+				
+				$order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_info['order_id']) )->select();	
+					
+				$order_goods_name_arr = array();
+				$order_goods_name = '';
+					
+				foreach($order_goods_list as $order_goods)
+				{
+					
+					$order_goods_name_arr[] = $order_goods['name'];
+					//...
+					if( !empty($order_goods_id) && $order_goods_id > 0  )
+					{
+						if($order_goods_id ==  $order_goods['order_goods_id'] )
+						{
+							if($is_back_sellcount == 1)
+							{
+								if( $is_zi_order_refund == 1 && $refund_quantity > 0 )
+								{
+									D('Home/Pingoods')->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$refund_quantity,2);
+								}else{
+									//获取已退款数量
+									$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
+									if(!$has_refund_quantity){
+										$has_refund_quantity = 0;
+									}
+									D('Home/Pingoods')->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
+								}
+							}
+							
+							$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_id' => $order_info['order_id'],'order_goods_id'=>$order_goods['order_goods_id'] ,'type' => 'orderbuy') )->find();
+							
+							if( !empty($score_refund_info) && $is_zi_order_refund == 1  )
+							{
+								// D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+							}
+						}
+					}else if( empty($order_goods_id) || $order_goods_id <=0 ){
+						if($is_back_sellcount == 1){
+							$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
+							if(!$has_refund_quantity){
+								$has_refund_quantity = 0;
+							}
+							D('Home/Pingoods')->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
+						}
+
+						
+						$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_id' => $order_info['order_id'],'order_goods_id' =>$order_goods['order_goods_id'] ,'type' => 'orderbuy') )->find();
+						
+						if( !empty($score_refund_info) )
+						{
+							// D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+						}
+					}
+					
+					if( $order_info['type'] == 'integral' )
+					{
+						D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$order_goods['total'], 0 ,'退款增加积分','refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+					}
+				
+				}
+				
+				$order_goods_name = implode('\r\n', $order_goods_name_arr); //."\r\n";	
+		
+				 
+				//分佣也要退回去 
+				if($is_zi_order_refund == 0)
+					D('Seller/Community')->back_order_commission($order_info['order_id'],$order_goods_id);
+				
+				return array('code' => 1);
+				
+			} else {
+				
+				$order_refund_history = array();
+				$order_refund_history['order_id'] =  $order_info['order_id'];
+				$order_refund_history['order_goods_id'] =  $order_goods_id;
+				
+				$order_refund_history['message'] = $res['err_code_des'];
+				$order_refund_history['type'] = 2;
+				$order_refund_history['addtime'] = time();
+				
+				M('lionfish_comshop_order_refund_history')->add($order_refund_history);
+				
+				/**
+				M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 10, 'remarksaler' => $res[err_code_des]) );
+				**/
+				
+				return array('code' => 0, 'msg' => $res['err_code_des']);
+				
+			}
+			
+		}
+		
+		
+		
+		
+	}
+	
+	public function refundOrder2($order_id,$money =0)
+	{
+		
+		$lib_path = dirname(dirname( dirname(__FILE__) )).'/Lib/';
+		$data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
+		RecursiveMkdir($data_path);
+		
+		set_time_limit(0);
+		
+		
+		require_once $lib_path."/Weixin/lib/WxPay.Api.php";
+		require_once $lib_path."/Weixin/log.php";
+		
+		//初始化日志
+		$logHandler= new \CLogFileHandler( $data_path .date('Y-m-d').'.log');
+		
+		\Log::Init($logHandler, 15);
+		\Log::DEBUG("进行中,订单ID :".$order_id );
+		
+		//pin
+		$order_info = M('order')->where( array('order_id' => $order_id) )->find();
+		
+		$member_info = M('member')->where( array('member_id' => $order_info['member_id']) )->find();
+		
+		$openId = $member_info['openid'];
+		$we_openid = $member_info['we_openid'];
+		
+		if( $order_info['from_type'] == 'wepro' )
+		{
+			$openId = $we_openid;
+		}
+		//we_openid
+		//money
+		$transaction_id = $order_info["transaction_id"];
+		
+		
+		
+		$total_fee = ($order_info["total"])*100;
+		$refund_fee = $total_fee;
+		if($money > 0)
+		{
+			$refund_fee = $money * 100;
+		}
+		
+		
+		
+		if($order_info['payment_code'] == 'yuer')
+		{
+			//余额支付的,退款到余额
+			//退款到余额
+			$member_charge_flow_data = array();
+			$member_charge_flow_data['member_id'] = $order_info['member_id'];
+			$member_charge_flow_data['money'] = $order_info["total"];
+			$member_charge_flow_data['state'] = 4;
+			$member_charge_flow_data['trans_id'] = $order_id;
+			$member_charge_flow_data['charge_time'] = time();
+			$member_charge_flow_data['add_time'] = time();
+			
+			M('member_charge_flow')->add($member_charge_flow_data);
+			//增加会员余额
+			M('member')->where( array('member_id'=> $order_info['member_id'] ) )->setInc('account_money',$order_info["total"] ); 
+					
+			
+			$order_info['total'] = $refund_fee / 100;
+			$this->refundOrder_success($order_info,$openId);
+			//检测是否有需要退回积分的订单
+		}
+		else if($refund_fee == 0)
+		{
+			M('order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
+			
+			$config_info = M('config')->where( array('name' => 'SITE_URL') )->find();
+			
+			$order_goods = M('order_goods')->where( array('order_id' => $order_info['order_id']) )->select();
+			
+			$order_goods_name = '';
+			$order_goods_name_arr = array();
+			
+			foreach ($order_goods as $key => $value) {
+				
+				$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$value['rela_goodsoption_valueid'],$value['goods_id'],$value['quantity'],2);
+				//销量回退
+				//$this->execute("UPDATE " . C('DB_PREFIX') . "goods SET seller_count = (seller_count - " . (int)$value['quantity'] . ") WHERE goods_id = '" . $value['goods_id'] . "' ");
+				$order_goods_name_arr[] = $value['name'];
+			}
+			$order_goods_name = implode('\r\n', $order_goods_name_arr); //."\r\n";	
+		
+			
+			$msg = '订单退款: 您的订单'.$order_info['order_num_alias'].'参团未成功,现退款:'.round($order_info["total"],2).'元,商品名称:'.$order_goods_name;
+			$url = $config_info['value'];
+			
+			//weixin_template_refund_order
+			//send_template_msg($wx_template_data,$url,$openid,C('weixin_template_refund_order'));
+			$url = $url."/index.php?s=/Order/info/id/{$order_info['order_id']}.html";
+			
+			/**
+			{{first.DATA}}
+			订单编号:{{keyword1.DATA}}
+			退款金额:{{keyword2.DATA}}
+			{{remark.DATA}}
+			---------------------------
+			校白君提醒您,您有一笔退款成功,请留意。
+			订单编号:20088115853
+			退款金额:¥19.00
+			更多学生价好货,在底部菜单栏哦~猛戳“校园专区”,享更多优惠!
+			**/
+			
+			$wx_template_data = array();
+			$wx_template_data['first'] = array('value' => '退款通知', 'color' => '#030303');
+			$wx_template_data['keyword1'] = array('value' => $order_goods_name, 'color' => '#030303');
+			$wx_template_data['keyword2'] = array('value' => round($order_info["total"],2), 'color' => '#030303');
+			$wx_template_data['remark'] = array('value' => '拼团失败已按原路退款', 'color' => '#030303');
+		
+			
+			if( $order_info['from_type'] == 'wepro' )
+			{
+				$template_data = array();
+				$template_data['keyword1'] = array('value' => $order_goods_name, 'color' => '#030303');
+				$template_data['keyword2'] = array('value' => '参团未成功', 'color' => '#030303');
+				$template_data['keyword3'] = array('value' => '拼团失败已按原路退款', 'color' => '#030303');
+				
+				$pay_order_msg_info =  M('config')->where( array('name' => 'weprogram_template_fail_pin') )->find();
+				$template_id = $pay_order_msg_info['value'];
+				
+				
+				$pagepath = 'pages/order/order?id='.$order_info['order_id'];
+				
+				/**
+				$member_formid_info = M('member_formid')->where( array('member_id' => $order_info['member_id'], 'state' => 0) )->find();
+					
+				send_wxtemplate_msg($template_data,$url,$pagepath,$member_info['we_openid'],$template_id,$member_formid_info['formid']);
+				//更新
+				M('member_formid')->where( array('id' => $member_formid_info['id']) )->save( array('state' => 1) );
+				
+				$order_info['member_id']
+				**/
+				
+				$member_formid_info = M('member_formid')->where( array('member_id' => $order_info['member_id'], 'formid' =>array('neq',''), 'state' => 0) )->order('id desc')->find();
+				if(!empty( $member_formid_info ))
+				{
+					send_wxtemplate_msg($template_data,$url,$pagepath,$member_info['we_openid'],$template_id,$member_formid_info['formid'] );
+					M('member_formid')->where( array('id' => $member_formid_info['id']) )->save( array('state' => 1) );
+				}
+				
+				
+				if( $openid != '1')
+				{
+					//notify_weixin_msg($member_info['openid'],$msg,'退款通知',$url);
+					send_template_msg($wx_template_data,$url,$member_info['openid'],C('weixin_template_refund_order'));
+				}
+			}else{
+				//notify_weixin_msg($member_info['openid'],$msg,'退款通知',$url);
+				send_template_msg($wx_template_data,$url,$member_info['openid'],C('weixin_template_refund_order'));
+			}
+			
+			//检测是否有需要退回积分的订单
+			
+			\Log::DEBUG("退款成功。。。退款日志:退款订单号:" . $order_info['order_id'].',ten:'.$transaction_id.'   退款金额: '
+			.$order_info["total"].',退款给:openid='.$openId);
+			
+		} else {
+			
+			$input = new \WxPayRefund();
+			$input->SetTransaction_id($transaction_id);
+			$input->SetTotal_fee($total_fee);
+			$input->SetRefund_fee($refund_fee);
+			$refund_no = \WxPayConfig::MCHID.date("YmdHis").$order_info['order_id'];
+			
+			$input->SetOut_refund_no($refund_no);
+			$input->SetOp_user_id(\WxPayConfig::MCHID);
+			
+			$res = (\WxPayApi::refund($input,6,$order_info['from_type']));
+			
+			//var_dump($res);die();  wx80131aa7dfc4ff71
+			
+			if($res['result_code'] == 'SUCCESS')
+			{
+				$order_info['total'] = $refund_fee / 100;
+				$this->refundOrder_success($order_info,$openId);
+				
+				\Log::DEBUG("退款成功。。。退款日志:退款订单号:" . $order_info['order_id'].',ten:'.$transaction_id.'   退款金额: '.$order_info["total"].',退款给:openid='.$openid);
+				//检测是否有需要退回积分的订单
+				
+			} else {
+			
+				M('order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 10, 'comment' => $res[err_code_des]) );
+				
+				\Log::DEBUG("退款失败。原因:{$res[err_code_des]}。。退款日志:退款订单号:" . $order_info['order_id'].',退款金额: '.$order_info["total"].',退款给:openid='.$openId);
+			}
+			
+		}
+		
+		return true;
+	}
+	
+	/**
+		取消已经付款的 待发货订单
+		5、处理订单,
+		6、处理退款,
+	**/
+	public  function del_cancle_order($order_id)
+	{				
+		$order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
+		
+		
+		//判断订单状态是否已付款,避免多次退款,不合理
+		if( $order_info['order_status_id'] == 1 )
+		{
+			//del_cancle_order 
+			
+			$total_money = D('Seller/Commonorder')->get_order_paymoney( $order_id );
+			
+			$has_refun_money = D('Seller/Commonorder')->order_refund_totalmoney( $order_id );
+
+			//是否预售订单begin
+            $presale_result = D('Home/PresaleGoods')->getOrderPresaleInfo( $order_id );
+            $presale_info = [];
+            if( $presale_result['code'] == 0 )
+            {
+                $presale_info = $presale_result['data'];
+                $total_money = $total_money - $presale_info['presale_ding_money'];
+            }
+            //end
+
+			$refund_money = round($total_money - $has_refun_money,2);
+			
+			
+			
+			$result = $this->refundOrder($order_id, $refund_money);
+			
+		
+			if( $result['code'] == 1 )
+			{
+				$order_history = array();
+				$order_history['order_id'] = $order_id;
+				$order_history['order_status_id'] = 5;
+				$order_history['notify'] = 0;
+				$order_history['comment'] = '会员前台申请取消订单,取消成功,并退款。';
+				$order_history['date_added'] = time();
+				
+				M('lionfish_comshop_order_history')->add( $order_history );
+				
+				M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('order_status_id' => 5) );
+				
+				//整笔
+				D('Seller/Commonorder')->refund_one_order( $order_id ,1);
+				
+				
+				return array('code' => 0);
+			}else{
+				$order_history = array();
+				$order_history['order_id'] = $order_id;
+				$order_history['order_status_id'] = 10;
+				$order_history['notify'] = 0;
+				$order_history['comment'] = '申请取消订单,但是退款失败。';
+				$order_history['date_added'] = time();
+				
+				M('lionfish_comshop_order_history')->add( $order_history );
+				
+				M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->save( array('order_status_id' => 10, 'remarksaler' => $result['msg']) );
+				
+				return array('code' => 1, 'msg' => $result['msg'] ,'s' => $result['code'] );
+			}
+			
+		}
+		 //如果退款成功了。那么就进行
+		
+	}
+	
+	
+	
+	
+	public function test_form_msg()
+	{
+		$member_info = M('member')->where( array('member_id' => 26) )->find();
+		
+		$form_id_arr = M('member_formid')->where( array('member_id' => 26,'state' =>0) )->find();
+		
+		M('member_formid')->where( array('id' => $form_id_arr['id'] ) )->save( array('state' =>1) );
+		$form_id = $form_id_arr['formid'];
+		
+		$template_data = array();
+		$template_data['keyword1'] = array('value' => '338866', 'color' => '#030303');
+		$template_data['keyword2'] = array('value' => '商品名称', 'color' => '#030303');
+		$template_data['keyword3'] = array('value' => '18元', 'color' => '#030303');
+		$template_data['keyword4'] = array('value' => '已按原路退款', 'color' => '#030303');
+		$template_data['keyword5'] = array('value' => '小鱼', 'color' => '#030303');
+		
+		$pay_order_msg_info =  M('config')->where( array('name' => 'weprogram_template_refund_order') )->find();
+		$template_id = $pay_order_msg_info['value'];
+		
+		
+		$pagepath = 'pages/order/order?id='.$order_info['order_id'];
+			
+		$rs = 	send_wxtemplate_msg($template_data,$url,$pagepath,$member_info['we_openid'],$template_id,$form_id);
+			var_dump($rs);die();
+	}
+	
+	public function refundOrder_success($order_info,$openid)
+	{
+		M('order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
+		
+		$member_info = M('member')->where( array('member_id' => $order_info['member_id']) )->find();
+		
+		
+		$config_info = M('config')->where( array('name' => 'SITE_URL') )->find();
+		
+		$order_goods = M('order_goods')->where( array('order_id' => $order_info['order_id']) )->select();
+		$goods_model = D('Home/Goods');
+		
+		$order_goods_name = '';
+		$order_goods_name_arr = array();
+		
+		foreach ($order_goods as $key => $value) {
+			//$this->execute("UPDATE " . C('DB_PREFIX') . "goods SET quantity = (quantity + " . (int)$value['quantity'] . ") WHERE goods_id = '" . $value['goods_id'] . "' ");
+			
+			$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$value['rela_goodsoption_valueid'],$value['goods_id'],$value['quantity'],2);
+			//销量回退
+			//$this->execute("UPDATE " . C('DB_PREFIX') . "goods SET seller_count = (seller_count - " . (int)$value['quantity'] . ") WHERE goods_id = '" . $value['goods_id'] . "' ");
+			$order_goods_name_arr[] = $value['name'];
+		}
+			
+		$order_goods_name = implode('\r\n', $order_goods_name_arr); //."\r\n";	
+		
+		$msg = '订单退款: 您的订单'.$order_info['order_num_alias'].'参团未成功,现退款:'.round($order_info["total"],2).'元,商品名称:'.$order_goods_name;
+		$url = $config_info['value'];
+		
+		$wx_template_data = array();
+		$wx_template_data['first'] = array('value' => '退款通知', 'color' => '#030303');
+		$wx_template_data['keyword1'] = array('value' => $order_goods_name, 'color' => '#030303');
+		$wx_template_data['keyword2'] = array('value' => $order_info['total'].'元', 'color' => '#030303');
+		$wx_template_data['remark'] = array('value' => '已按原路退款', 'color' => '#030303');
+		
+		 
+		$url = $url."/index.php?s=/Order/info/id/{$order_info['order_id']}.html";
+		
+		
+		if( $order_info['from_type'] == 'wepro' )
+		{
+			/**
+			退款成功通知
+			关键词
+			订单号
+			{{keyword1.DATA}}
+			商品名称
+			{{keyword2.DATA}}
+			退款金额
+			{{keyword3.DATA}}
+			温馨提示
+			{{keyword4.DATA}}
+			备注
+			{{keyword5.DATA}}
+			**/
+			
+			//$total_money = ($order_info["total"],2);
+			
+			$template_data = array();
+			$template_data['keyword1'] = array('value' => $order_info['order_num_alias'], 'color' => '#030303');
+			$template_data['keyword2'] = array('value' => $order_goods_name, 'color' => '#030303');
+			$template_data['keyword3'] = array('value' => $order_info['total'].'元', 'color' => '#030303');
+			$template_data['keyword4'] = array('value' => '已按原路退款', 'color' => '#030303');
+			$template_data['keyword5'] = array('value' => $member_info['uname'], 'color' => '#030303');
+			
+			$pay_order_msg_info =  M('config')->where( array('name' => 'weprogram_template_refund_order') )->find();
+			$template_id = $pay_order_msg_info['value'];
+			
+			
+			$pagepath = 'pages/order/order?id='.$order_info['order_id'];
+			
+			
+			/**
+				$member_formid_info = M('member_formid')->where( array('member_id' => $order_info['member_id'], 'state' => 0) )->find();
+					
+				send_wxtemplate_msg($template_data,$url,$pagepath,$member_info['we_openid'],$template_id,$member_formid_info['formid']);
+				//更新
+				M('member_formid')->where( array('id' => $member_formid_info['id']) )->save( array('state' => 1) );
+				
+			**/
+			$member_formid_info = M('member_formid')->where( array('member_id' => $order_info['member_id'],'formid' =>array('neq',''), 'state' => 0) )->order('id desc')->find();
+				
+			//$order_info['member_id']
+			if( !empty($member_formid_info) )
+			{
+				$rs = 	send_wxtemplate_msg($template_data,$url,$pagepath,$member_info['we_openid'],$template_id,$member_formid_info['formid']);
+				M('member_formid')->where( array('id' => $member_formid_info['id']) )->save( array('state' => 1) );
+			}
+				
+			
+			if( $openid != '1')
+			{
+				//notify_weixin_msg($openid,$msg,'退款通知',$url);
+				send_template_msg($wx_template_data,$url,$openid,C('weixin_template_refund_order'));
+			
+			}
+		}else{
+			//notify_weixin_msg($openid,$msg,'退款通知',$url);
+			send_template_msg($wx_template_data,$url,$openid,C('weixin_template_refund_order'));
+			
+		}
+		
+		
+		
+	}
+}
 ?>

+ 1496 - 0
Modules/Home/Model/WeixinModel.class.php.back

@@ -0,0 +1,1496 @@
+<?php
+/**
+ * lionfish 商城系统
+ *
+ * ==========================================================================
+ * @link      http://www.liofis.com/
+ * @copyright Copyright (c) 2015 liofis.com. 
+ * @license   http://www.liofis.com/license.html License
+ * ==========================================================================
+ *
+ * @author    fish
+ *
+ */
+namespace Home\Model;
+class WeixinModel{
+
+	
+	public function refundOrder($order_id, $money=0, $uniacid=0,$order_goods_id=0,$is_back_sellcount = 1,$refund_quantity = 0,$is_zi_order_refund =0)
+	
+	{
+		$_GPC = I('request.');
+		$lib_path = dirname(dirname( dirname(__FILE__) )).'/Lib/';
+		
+		set_time_limit(0);
+		
+		require_once $lib_path."/Weixin/lib/WxPay.Api.php";
+		
+		
+		$order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->find();
+		
+				
+		$member_info = M('lionfish_comshop_member')->where( array('member_id' => $order_info['member_id'] ) )->find();		
+		
+		
+		$openId = $member_info['openid'];
+		$we_openid = $member_info['we_openid'];
+		
+		if( $order_info['from_type'] == 'wepro' )
+		{
+			$openId = $we_openid;
+		}
+		//we_openid
+		//money
+		$transaction_id = $order_info["transaction_id"];
+
+		
+		if( $order_info['type'] == 'integral' )
+		{
+			$total_fee = ( $order_info["shipping_fare"] )*100;
+		
+		}else{
+			$total_fee = ($order_info["total"] + $order_info["shipping_fare"]-$order_info['voucher_credit']-$order_info['fullreduction_money'] - $order_info['score_for_money']-$order_info['fare_shipping_free'] )*100;
+		}
+		
+		//预售begin
+        $presale_result = D('Home/PresaleGoods')->getOrderPresaleInfo( $order_id );
+		if( $presale_result['code'] ==0 )
+        {
+            $total_fee = $total_fee - $presale_result['data']['presale_ding_money'] * 100;
+        }
+        //end
+
+		$refund_fee = $total_fee;
+		
+		
+		
+		//order_goods_id
+		if( !empty($order_goods_id) )
+		{
+			$order_goods_info = M('lionfish_comshop_order_goods')->where( array('order_goods_id' =>$order_goods_id ) )->find();
+			
+			$refund_fee = ($order_goods_info["total"] + $order_goods_info["shipping_fare"]-$order_goods_info['voucher_credit']-$order_goods_info['fullreduction_money'] - $order_goods_info['score_for_money']-$order_goods_info['fare_shipping_free'])*100;
+		
+			if( $order_info['type'] == 'integral' )
+			{
+				$refund_fee = ( $order_goods_info["shipping_fare"] )*100;
+			}
+		}
+		
+		
+		if($money > 0 && $order_info['type'] != 'integral' )
+		{
+			$refund_fee = $money * 100;
+		}else if(  $money > 0 && $order_info['type'] == 'integral' && !empty($order_goods_info) ) 
+		{
+			if(!empty($_GPC['refund_money'])){
+					$refund_money = isset($_GPC['refund_money']) && $_GPC['refund_money'] >0  ? floatval($_GPC['refund_money']) : 0;
+					//商品多个运费和
+					$refund_fee = ( $money - $refund_money )*100;
+					//商品多个商品单价和
+					$order_info['total'] = $refund_money;
+			}else{
+				$order_refund_history_image = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_id) )->order('addtime asc')->find();	
+				$ref_shipping_fare = M('lionfish_comshop_order_refund')->field('ref_id,ref_money,real_refund_quantity,ref_shipping_fare')->where( array('order_id' => $order_id ))->order('ref_id desc')->find();
+				$refund_fee = ( $ref_shipping_fare['ref_shipping_fare'] )*100;
+				$order_info['total'] = $money ;
+			}
+		}
+		// else if( isset($is_open_yinpay) && $is_open_yinpay == 3 )  
+		    
+		$is_open_yinpay = D('Home/Front')->get_config_by_name('is_open_yinpay');
+
+        if($order_info['payment_code'] == 'fypay'){
+
+        $order_relate_info = M('lionfish_comshop_order_relate')->where( array('order_id' => $order_id ) )->order('id desc')->find();
+
+        if( !empty($order_relate_info) && $order_relate_info['order_all_id'] > 0 )
+        {
+            $order_all_info = M('lionfish_comshop_order_all')->where( array('id' => $order_relate_info['order_all_id'] ) )->find();
+
+            if( !empty($order_all_info) && !empty($order_all_info['out_trade_no']) )
+            {
+
+                $out_trade_no = $order_all_info['out_trade_no'];
+
+                $appid =  D('Home/Front')->get_config_by_name('wepro_appid');
+                $mch_id =      D('Home/Front')->get_config_by_name('wepro_partnerid');
+                $nonce_str =    nonce_str();
+
+                $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
+
+
+                $post = array();
+                $post['appid'] = $appid;
+                $post['mch_id'] = $mch_id;
+                $post['nonce_str'] = $nonce_str;
+                $post['out_trade_no'] = $out_trade_no;
+
+                $sign = sign($post,$pay_key);
+
+                $post_xml = '<xml>
+							   <appid>'.$appid.'</appid>
+							   <mch_id>'.$mch_id.'</mch_id>
+							   <nonce_str>'.$nonce_str.'</nonce_str>
+							   <out_trade_no>'.$out_trade_no.'</out_trade_no>
+							   <sign>'.$sign.'</sign>
+							</xml>';
+
+                $url = "https://api.mch.weixin.qq.com/pay/orderquery";
+
+                $result = http_request($url,$post_xml);
+
+                $array = xml($result);
+
+                if( $array['RETURN_CODE'] == 'SUCCESS' && $array['RETURN_MSG'] == 'OK' )
+                {
+                    if( $array['TRADE_STATE'] == 'SUCCESS' || $array['TRADE_STATE'] == 'REFUND' )
+                    {
+                        $total_fee = $array['TOTAL_FEE'];
+                    }
+                }
+
+            }
+        }
+
+        //
+        require_once $lib_path . "/Weixin/Wxfy.class.php";
+
+        $refund_no = '1450'.date("YmdHis").$order_info['order_id'];
+//            dump(strlen($refund_no));
+//            exit();
+            $order_all=D("lionfish_comshop_order_all")->where(array("transaction_id"=>$transaction_id))->find();
+
+            if($order_all['transaction_id']==$transaction_id){
+                $input = new \Wxfy();
+                $notify_data=[
+                    "version"=>"1",
+                    "ins_cd"=>"08M0027018",
+                    "mchnt_cd"=>"0001000F6549249",
+                    "order_type"=>"WECHAT",
+                    "mchnt_order_no"=>$order_all['out_trade_no'],
+                    "random_str"=>$nonce_str,
+                    "term_id"=>"88888888",
+                    "refund_order_no"=>$refund_no,
+                    "total_amt"=>$total_fee,
+                    'refund_amt'=>$refund_fee
+
+                ];
+
+                $res=$input->refundOrder($notify_data);
+            }else{
+                return array('code' => 0, 'msg' =>"该订单不存在");
+            }
+
+//        dump($res);
+//        exit();
+
+//            $res='{"ins_cd":"08M0027018","mchnt_cd":"0005210F3948471","mchnt_order_no":"145036-1698222261","order_type":"WECHAT","random_str":"8AHA9V61UY1VOXJ5CJP27MIOURZO1TTL","refund_id":"50101607462023102545369668637","refund_order_no":"145014502023102519014730","reserved_fy_settle_dt":"20231025","reserved_fy_trace_no":"221210993339","reserved_refund_amt":"1","result_code":"000000","result_msg":"SUCCESS","sign":"Fi2gsgMHan11IIru8sLAJ8jwLbtUYfndURakne9l16qtEqaQrkhDx+aXo0jfQGPkx171bBi0T74I8Z6PI1RdBZX0Wf2h9tWKnCRVnxEjQIy0BRPN3g+ktkxrtQgzmDL5jxyatjVFrA43J4gwoqt6o7onlclGUeltsdRPJvoOVGs=","term_id":"88888888","transaction_id":"4200001999202310251498038501"}
+//';
+            $res=json_decode($res,true);
+
+
+        if($res["result_code"] != '000000'){
+            if( $res['result_msg'] == '订单已全额退款' )
+            {
+                $res['result_code'] = '000000';
+            }else{
+                return array('code' => 0, 'msg' => $res['result_msg']);
+            }
+
+        }
+
+
+
+
+
+        if($res['result_code'] == '000000')
+        {
+
+            if($order_info['order_status_id'] == 12)
+            {
+                $ref_count = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_info['order_id'], 'state' => 0 ) )->count();
+                if( $ref_count <= 1 )
+                {
+                    M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
+                }
+            }
+
+            $order_info['total'] = $refund_fee / 100;
+
+
+            $order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_info['order_id']) )->select();
+
+            $order_goods_name_arr = array();
+            $order_goods_name = '';
+
+            foreach($order_goods_list as $order_goods)
+            {
+
+                $order_goods_name_arr[] = $order_goods['name'];
+                //...
+                if( !empty($order_goods_id) && $order_goods_id > 0  )
+                {
+                    if($order_goods_id ==  $order_goods['order_goods_id'] )
+                    {
+                        if($is_back_sellcount == 1)
+                        {
+                            if( $is_zi_order_refund == 1 && $refund_quantity > 0 )
+                            {
+                                D('Home/Pingoods')->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$refund_quantity,2);
+                            }else{
+                                //获取已退款数量
+                                $has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
+                                if(!$has_refund_quantity){
+                                    $has_refund_quantity = 0;
+                                }
+                                D('Home/Pingoods')->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
+                            }
+                        }
+
+                        $score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_id' => $order_info['order_id'],'order_goods_id'=>$order_goods['order_goods_id'] ,'type' => 'orderbuy') )->find();
+
+                        if( !empty($score_refund_info) && $is_zi_order_refund == 1  )
+                        {
+                            // D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+                        }
+                    }
+                }else if( empty($order_goods_id) || $order_goods_id <=0 ){
+                    if($is_back_sellcount == 1){
+                        $has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
+                        if(!$has_refund_quantity){
+                            $has_refund_quantity = 0;
+                        }
+                        D('Home/Pingoods')->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
+                    }
+
+
+                    $score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_id' => $order_info['order_id'],'order_goods_id' =>$order_goods['order_goods_id'] ,'type' => 'orderbuy') )->find();
+
+                    if( !empty($score_refund_info) )
+                    {
+                        // D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+                    }
+                }
+
+                if( $order_info['type'] == 'integral' )
+                {
+                    D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$order_goods['total'], 0 ,'退款增加积分','refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+                }
+
+            }
+
+            $order_goods_name = implode('\r\n', $order_goods_name_arr); //."\r\n";
+
+
+            //分佣也要退回去
+            if($is_zi_order_refund == 0)
+                D('Seller/Community')->back_order_commission($order_info['order_id'],$order_goods_id);
+
+            return array('code' => 1);
+
+        } else {
+
+            $order_refund_history = array();
+            $order_refund_history['order_id'] =  $order_info['order_id'];
+            $order_refund_history['order_goods_id'] =  $order_goods_id;
+
+            $order_refund_history['message'] = $res['err_code_des'];
+            $order_refund_history['type'] = 2;
+            $order_refund_history['addtime'] = time();
+
+            M('lionfish_comshop_order_refund_history')->add($order_refund_history);
+
+            /**
+            M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 10, 'remarksaler' => $res[err_code_des]) );
+             **/
+
+            return array('code' => 0, 'msg' => $res['result_msg']);
+
+        }
+    }
+		else if($order_info['payment_code'] == 'yuer')
+		{
+			//余额支付的,退款到余额
+			//退款到余额
+			
+			//增加会员余额
+			$refund_fee = $refund_fee / 100;
+
+			if( $refund_fee > 0 )
+			{
+				//判断是否积分类型的
+
+				M('lionfish_comshop_member')->where( array('member_id' => $order_info['member_id']) )->setInc('account_money',$refund_fee);
+				
+				$account_money_info = M('lionfish_comshop_member')->field('account_money')->where( array('member_id' =>$order_info['member_id'] ) )->find();
+		
+				$account_money = $account_money_info['account_money'];
+				
+		
+				$member_charge_flow_data = array();
+				
+				$member_charge_flow_data['member_id'] = $order_info['member_id'];
+				$member_charge_flow_data['money'] = $refund_fee;
+				$member_charge_flow_data['operate_end_yuer'] = $account_money;
+				$member_charge_flow_data['state'] = 4;
+				$member_charge_flow_data['trans_id'] = $order_id;
+				$member_charge_flow_data['order_goods_id'] = $order_goods_id;
+				$member_charge_flow_data['charge_time'] = time();
+				$member_charge_flow_data['add_time'] = time();
+				
+				M('lionfish_comshop_member_charge_flow')->add($member_charge_flow_data);
+			}
+			
+			
+			if($order_info['order_status_id'] == 12)
+			{
+				$ref_count = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_info['order_id'], 'state' => 0 ) )->count();
+				
+				
+				if( $ref_count <= 1 )
+				{
+					M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
+				}
+			}
+			
+			
+			
+			
+			$order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_info['order_id'] ) )->select();
+			
+			$goods_model = D('Home/Pingoods');
+			
+			foreach($order_goods_list as $order_goods)
+			{
+				//$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity'],2);
+				
+				if( !empty($order_goods_id) && $order_goods_id > 0  )
+				{
+					if($order_goods_id ==  $order_goods['order_goods_id'] )
+					{
+						
+						if($is_back_sellcount == 1)
+						{
+							if( $is_zi_order_refund == 1 && $refund_quantity > 0 )
+							{
+								$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$refund_quantity,2);
+							}else{
+								//获取已退款数量
+								$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
+								if(!$has_refund_quantity){
+									$has_refund_quantity = 0;
+								}
+								$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
+							}
+						}
+						
+						$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_goods_id' => $order_goods['order_goods_id'],'order_id' =>$order_info['order_id'],'type' => 'orderbuy' ) )->find();
+						
+						if( !empty($score_refund_info) && $is_zi_order_refund == 1  )
+						{
+							// D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+						}
+					}
+				}else if( empty($order_goods_id) || $order_goods_id <=0 ){
+					if($is_back_sellcount == 1){
+						//获取已退款数量
+						$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
+						if(!$has_refund_quantity){
+							$has_refund_quantity = 0;
+						}
+						$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
+					}
+
+					
+					$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_goods_id' => $order_goods['order_goods_id'],'order_id' => $order_info['order_id'] ,'type' => 'orderbuy') )->find();			
+										
+					if( !empty($score_refund_info) )
+					{
+						// D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分','refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+					}
+				}
+				
+				if( $order_info['type'] == 'integral' )
+				{
+					
+					D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$order_info['total'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+				}
+			}
+			//分佣也要退回去
+			if($is_zi_order_refund == 0)
+					D('Seller/Community')->back_order_commission($order_info['order_id'],$order_goods_id);
+				
+			return array('code' => 1);
+			//$this->refundOrder_success($order_info,$openId);
+			//检测是否有需要退回积分的订单
+		//货到付款订单
+		}else if($order_info['payment_code'] == 'cashon_delivery')
+		{
+			//货到付款订单退款金额不到账,但有退款记录
+
+			if($order_info['order_status_id'] == 12)
+			{
+				$ref_count = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_info['order_id'], 'state' => 0 ) )->count();
+
+				if( $ref_count <= 1 )
+				{
+					M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
+				}
+			}
+
+			$order_info['total'] = $refund_fee / 100;
+
+			$order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_info['order_id'] ) )->select();
+
+			$goods_model = D('Home/Pingoods');
+
+			foreach($order_goods_list as $order_goods)
+			{
+				//$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity'],2);
+
+				if( !empty($order_goods_id) && $order_goods_id > 0  )
+				{
+					if($order_goods_id ==  $order_goods['order_goods_id'] )
+					{
+
+						if($is_back_sellcount == 1)
+						{
+							if( $is_zi_order_refund == 1 && $refund_quantity > 0 )
+							{
+								$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$refund_quantity,2);
+							}else{
+								//获取已退款数量
+								$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
+								if(!$has_refund_quantity){
+									$has_refund_quantity = 0;
+								}
+								$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
+							}
+						}
+
+						$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_goods_id' => $order_goods['order_goods_id'],'order_id' =>$order_info['order_id'],'type' => 'orderbuy' ) )->find();
+
+						if( !empty($score_refund_info) && $is_zi_order_refund == 1  )
+						{
+							// D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+						}
+					}
+				}else if( empty($order_goods_id) || $order_goods_id <=0 ){
+					if($is_back_sellcount == 1){
+						//获取已退款数量
+						$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
+						if(!$has_refund_quantity){
+							$has_refund_quantity = 0;
+						}
+						$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
+					}
+
+
+					$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_goods_id' => $order_goods['order_goods_id'],'order_id' => $order_info['order_id'] ,'type' => 'orderbuy') )->find();
+
+					if( !empty($score_refund_info) )
+					{
+						// D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分','refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+					}
+				}
+
+				/*if( $order_info['type'] == 'integral' )
+				{
+
+					D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$order_info['total'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+				}*/
+			}
+			//分佣也要退回去
+			if($is_zi_order_refund == 0)
+				D('Seller/Community')->back_order_commission($order_info['order_id'],$order_goods_id);
+
+			return array('code' => 1);
+			//$this->refundOrder_success($order_info,$openId);
+			//检测是否有需要退回积分的订单
+		}
+		else if($order_info['payment_code'] == 'admin'){
+			 
+			if($order_info['order_status_id'] == 12)
+			{
+				$ref_count = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_info['order_id'], 'state' => 0 ) )->count();
+				if( $ref_count <= 1 )
+				{
+					M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
+				}
+			}
+				
+			$order_info['total'] = $refund_fee / 100;
+			
+			$order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_info['order_id'] ) )->select();
+			
+			
+			$goods_model = D('Home/Pingoods');
+			foreach($order_goods_list as $order_goods)
+			{
+				//$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity'],2);
+				
+				if( !empty($order_goods_id) && $order_goods_id > 0  )
+				{
+					if($order_goods_id ==  $order_goods['order_goods_id'] )
+					{
+						
+						if($is_back_sellcount == 1)
+						{
+							if( $is_zi_order_refund == 1 && $refund_quantity > 0 )
+							{
+								$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$refund_quantity,2);
+							}else{
+								//获取已退款数量
+								$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
+								if(!$has_refund_quantity){
+									$has_refund_quantity = 0;
+								}
+								$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
+							}
+						}	
+						
+						$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_goods_id' => $order_goods['order_goods_id'],'order_id' =>$order_info['order_id'],'type' => 'orderbuy' ) )->find();
+						
+						if( !empty($score_refund_info) && $is_zi_order_refund == 1 )
+						{
+							 //D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+						}
+					}
+				}else if( empty($order_goods_id) || $order_goods_id <=0 ){
+					if($is_back_sellcount == 1){
+						//获取已退款数量
+						$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
+						if(!$has_refund_quantity){
+							$has_refund_quantity = 0;
+						}
+						$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
+					}
+
+					
+					$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_goods_id' => $order_goods['order_goods_id'],'order_id' => $order_info['order_id'] ,'type' => 'orderbuy') )->find();			
+										
+					if( !empty($score_refund_info) )
+					{
+						// D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分','refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+					}
+				}
+				
+				if( $order_info['type'] == 'integral' )
+				{
+					//D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$order_goods['total'], 0 ,'退款增加积分','refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+				}
+			
+			}
+			//分佣也要退回去
+			if($is_zi_order_refund == 0)
+				D('Seller/Community')->back_order_commission($order_info['order_id'],$order_goods_id);
+			return array('code' => 1);
+			
+		}
+		else if($refund_fee == 0)
+		{
+			if($order_info['order_status_id'] == 12)
+			{
+				$ref_count = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_info['order_id'], 'state' => 0 ) )->count();
+				if( $ref_count <= 1 )
+				{
+					M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
+				}
+			}
+				
+			//ims_ lionfish_comshop_order_goods
+			$order_goods = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_info['order_id']) )->select();
+			
+			$order_goods_name = '';
+			$order_goods_name_arr = array();
+			$goods_model = D('Home/Pingoods');
+			
+			//get_config_by_name($name) 
+			
+			
+			
+			foreach ($order_goods as $key => $value) {
+				//($order_id,$option,$goods_id,$quantity,$type='1')
+				if($is_back_sellcount == 1)
+				{
+					if( $is_zi_order_refund == 1 && $refund_quantity > 0 )
+					{
+						$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$value['rela_goodsoption_valueid'],$value['goods_id'],$refund_quantity,2);
+					}else{
+						//获取已退款数量
+						$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
+						if(!$has_refund_quantity){
+							$has_refund_quantity = 0;
+						}
+						$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$value['rela_goodsoption_valueid'],$value['goods_id'],$value['quantity']-$has_refund_quantity,2);
+					}
+				}	
+				
+				$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_id' =>$order_info['order_id'] ,'order_goods_id' =>$value['order_goods_id'] ,'type' => 'orderbuy') )->find();
+				
+				if( !empty($score_refund_info) )
+				{
+					// D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分','refundorder', $order_info['order_id'] ,$value['order_goods_id'] );
+				}
+					
+				//销量回退
+				$order_goods_name_arr[] = $value['name'];
+			}
+			$order_goods_name = implode('\r\n', $order_goods_name_arr); //."\r\n";	
+		
+			
+			$msg = '订单退款: 您的订单'.$order_info['order_num_alias'].'参团未成功,现退款:'.round($order_info["total"],2).'元,商品名称:'.$order_goods_name;
+			
+			$url = D('Home/Front')->get_config_by_name('shop_domain');
+			
+			//weixin_template_refund_order
+			//send_template_msg($wx_template_data,$url,$openid,C('weixin_template_refund_order'));
+			
+			/**
+			{{first.DATA}}
+			订单编号:{{keyword1.DATA}}
+			退款金额:{{keyword2.DATA}}
+			{{remark.DATA}}
+			---------------------------
+			校白君提醒您,您有一笔退款成功,请留意。
+			订单编号:20088115853
+			退款金额:¥19.00
+			更多学生价好货,在底部菜单栏哦~猛戳“校园专区”,享更多优惠!
+			**/
+			
+			$wx_template_data = array();
+			$wx_template_data['first'] = array('value' => '退款通知', 'color' => '#030303');
+			$wx_template_data['keyword1'] = array('value' => $order_goods_name, 'color' => '#030303');
+			$wx_template_data['keyword2'] = array('value' => round($order_info["total"],2), 'color' => '#030303');
+			$wx_template_data['remark'] = array('value' => '拼团失败已按原路退款', 'color' => '#030303');
+		
+			
+			if( $order_info['from_type'] == 'wepro' )
+			{
+				$template_data = array();
+				$template_data['keyword1'] = array('value' => $order_info['order_num_alias'], 'color' => '#030303');
+				$template_data['keyword2'] = array('value' => '商户名称', 'color' => '#030303');
+				$template_data['keyword2'] = array('value' => $order_goods_name, 'color' => '#030303');
+				$template_data['keyword3'] = array('value' => $order_info['total'].'元', 'color' => '#030303');
+				$template_data['keyword4'] = array('value' => '已按原路退款', 'color' => '#030303');
+				$template_data['keyword5'] = array('value' => $member_info['uname'], 'color' => '#030303');
+				
+				
+				$template_id = D('Home/Front')->get_config_by_name('weprogram_template_refund_order');
+				
+				$pagepath = 'lionfish_comshop/pages/order/order?id='.$order_info['order_id'];
+				
+				
+				$member_formid_info = M('lionfish_comshop_member_formid')->where("member_id=".$order_info['member_id']." and formid != '' and state =0")->order('id desc')->find();
+				
+				if(!empty( $member_formid_info ))
+				{
+					D('Seller/User')->send_wxtemplate_msg($template_data,$url,$pagepath,$member_info['we_openid'],$template_id,$member_formid_info['formid'] );
+					
+					M('lionfish_comshop_member_formid')->where( array('id' => $member_formid_info['id']) )->save(array('state' => 1));
+				}
+				
+				if( $openid != '1')
+				{
+					//send_template_msg($wx_template_data,$url,$member_info['openid'],C('weixin_template_refund_order'));
+				}
+			}else{
+				//send_template_msg($wx_template_data,$url,$member_info['openid'],C('weixin_template_refund_order'));
+			}
+			
+			//检测是否有需要退回积分的订单
+			
+		}
+		else if( isset($is_open_yinpay) && $is_open_yinpay == 3 )
+		{
+		    $order_relate_info = M('lionfish_comshop_order_relate')->where( array('order_id' => $order_id ) )->order('id desc')->find();
+		    
+		    if( !empty($order_relate_info) && $order_relate_info['order_all_id'] > 0 )
+		    {
+		        $order_all_info = M('lionfish_comshop_order_all')->where( array('id' => $order_relate_info['order_all_id'] ) )->find();
+		         
+		        if( !empty($order_all_info) && !empty($order_all_info['out_trade_no']) )
+		        {
+		    
+		            $out_trade_no = $order_all_info['out_trade_no'];
+		    
+		            $appid =  D('Home/Front')->get_config_by_name('wepro_fuwu_appid');
+		            $mch_id =      D('Home/Front')->get_config_by_name('wepro_fuwu_partnerid');
+		            
+		            $nonce_str =    nonce_str();
+		    
+		            $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
+		    
+		            $sub_appid = D('Home/Front')->get_config_by_name('wepro_appid');
+		            $sub_mch_id = D('Home/Front')->get_config_by_name('wepro_sub_mch_id');
+		            
+		            
+		            $post = array();
+		            $post['appid'] = $appid;
+		            $post['mch_id'] = $mch_id;
+		            $post['nonce_str'] = $nonce_str;
+		            $post['out_trade_no'] = $out_trade_no;
+		            $post['sub_appid'] = $sub_appid;
+		            $post['sub_mch_id'] = $sub_mch_id;
+		             
+		            $sign = sign($post,$pay_key);
+		    
+		            $post_xml = '<xml>
+							   <appid>'.$appid.'</appid>
+							   <mch_id>'.$mch_id.'</mch_id>
+							   <nonce_str>'.$nonce_str.'</nonce_str>
+							   <out_trade_no>'.$out_trade_no.'</out_trade_no>
+							   <sub_appid>'.$post['sub_appid'].'</sub_appid>
+							   <sub_mch_id>'.$post['sub_mch_id'].'</sub_mch_id>
+							   <sign>'.$sign.'</sign>
+							</xml>';
+		             
+		            $url = "https://api.mch.weixin.qq.com/pay/orderquery";
+		    
+		            $result = http_request($url,$post_xml);
+		    
+		            $array = xml($result);
+		    
+		            if( $array['RETURN_CODE'] == 'SUCCESS' && $array['RETURN_MSG'] == 'OK' )
+		            {
+		                if( $array['TRADE_STATE'] == 'SUCCESS' || $array['TRADE_STATE'] == 'REFUND' )
+		                {
+		                    $total_fee = $array['TOTAL_FEE'];
+		                }
+		            }
+		    
+		        }
+		    }
+		    
+		    //
+		    	
+		    	
+		    $input = new \WxPayRefund();
+		    	
+		    $input->SetTransaction_id($transaction_id);
+		    $input->SetTotal_fee($total_fee);
+		    $input->SetRefund_fee($refund_fee);
+		    	
+		    $mchid = D('Home/Front')->get_config_by_name('wepro_partnerid');
+		    	
+		    $refund_no = $mchid.date("YmdHis").$order_info['order_id'];
+		    	
+		    $input->SetOut_refund_no($refund_no);
+		    $input->SetOp_user_id($mchid);
+		    	
+		    	
+		    $res = \WxPayApi::refund($input,6,'teweixin');
+		    	
+		    if($res["return_code"] == 'FAIL'){
+          		return array('code' => 0, 'msg' => $res['return_msg']);
+			}	
+		    	
+		    if( $res['err_code_des'] == '订单已全额退款' )
+		    {
+		        $res['result_code'] = 'SUCCESS';
+		    }
+		    	
+		    if($res['result_code'] == 'SUCCESS')
+		    {
+		    
+		        if($order_info['order_status_id'] == 12)
+		        {
+		            $ref_count = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_info['order_id'], 'state' => 0 ) )->count();
+		            if( $ref_count <= 1 )
+		            {
+		                M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
+		            }
+		        }
+		    
+		        $order_info['total'] = $refund_fee / 100;
+		    
+		    
+		        $order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_info['order_id']) )->select();
+		        	
+		        $order_goods_name_arr = array();
+		        $order_goods_name = '';
+		        	
+		        foreach($order_goods_list as $order_goods)
+		        {
+		            	
+		            $order_goods_name_arr[] = $order_goods['name'];
+		            //...
+		            if( !empty($order_goods_id) && $order_goods_id > 0  )
+		            {
+		                if($order_goods_id ==  $order_goods['order_goods_id'] )
+		                {
+		                    if($is_back_sellcount == 1)
+		                    {
+		                        if( $is_zi_order_refund == 1 && $refund_quantity > 0 )
+		                        {
+		                            D('Home/Pingoods')->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$refund_quantity,2);
+		                        }else{
+		                            //获取已退款数量
+		                            $has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
+		                            if(!$has_refund_quantity){
+		                                $has_refund_quantity = 0;
+		                            }
+		                            D('Home/Pingoods')->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
+		                        }
+		                    }
+		                    	
+		                    $score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_id' => $order_info['order_id'],'order_goods_id'=>$order_goods['order_goods_id'] ,'type' => 'orderbuy') )->find();
+		                    	
+		                    if( !empty($score_refund_info) && $is_zi_order_refund == 1  )
+		                    {
+		                        // D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+		                    }
+		                }
+		            }else if( empty($order_goods_id) || $order_goods_id <=0 ){
+		                if($is_back_sellcount == 1){
+		                    $has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
+		                    if(!$has_refund_quantity){
+		                        $has_refund_quantity = 0;
+		                    }
+		                    D('Home/Pingoods')->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
+		                }
+		    
+		    
+		                $score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_id' => $order_info['order_id'],'order_goods_id' =>$order_goods['order_goods_id'] ,'type' => 'orderbuy') )->find();
+		    
+		                if( !empty($score_refund_info) )
+		                {
+		                    // D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+		                }
+		            }
+		            	
+		            if( $order_info['type'] == 'integral' )
+		            {
+		                D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$order_goods['total'], 0 ,'退款增加积分','refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+		            }
+		    
+		        }
+		    
+		        $order_goods_name = implode('\r\n', $order_goods_name_arr); //."\r\n";
+		    
+		        	
+		        //分佣也要退回去
+		        if($is_zi_order_refund == 0)
+		            D('Seller/Community')->back_order_commission($order_info['order_id'],$order_goods_id);
+		    
+		        return array('code' => 1);
+		    
+		    } else {
+		    
+		        $order_refund_history = array();
+		        $order_refund_history['order_id'] =  $order_info['order_id'];
+		        $order_refund_history['order_goods_id'] =  $order_goods_id;
+		    
+		        $order_refund_history['message'] = $res['err_code_des'];
+		        $order_refund_history['type'] = 2;
+		        $order_refund_history['addtime'] = time();
+		    
+		        M('lionfish_comshop_order_refund_history')->add($order_refund_history);
+		    
+		        /**
+		         M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 10, 'remarksaler' => $res[err_code_des]) );
+		        **/
+		    
+		        return array('code' => 0, 'msg' => $res['err_code_des']);
+		    
+		    }
+		    
+		}
+		else {
+            $order_relate_info = M('lionfish_comshop_order_relate')->where( array('order_id' => $order_id ) )->order('id desc')->find();
+            
+            if( !empty($order_relate_info) && $order_relate_info['order_all_id'] > 0 )
+            {
+                $order_all_info = M('lionfish_comshop_order_all')->where( array('id' => $order_relate_info['order_all_id'] ) )->find();
+                	
+                if( !empty($order_all_info) && !empty($order_all_info['out_trade_no']) )
+                {
+            
+                    $out_trade_no = $order_all_info['out_trade_no'];
+            
+                    $appid =  D('Home/Front')->get_config_by_name('wepro_appid');
+                    $mch_id =      D('Home/Front')->get_config_by_name('wepro_partnerid');
+                    $nonce_str =    nonce_str();
+            
+                    $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
+            
+            
+                    $post = array();
+                    $post['appid'] = $appid;
+                    $post['mch_id'] = $mch_id;
+                    $post['nonce_str'] = $nonce_str;
+                    $post['out_trade_no'] = $out_trade_no;
+                    	
+                    $sign = sign($post,$pay_key);
+            
+                    $post_xml = '<xml>
+							   <appid>'.$appid.'</appid>
+							   <mch_id>'.$mch_id.'</mch_id>
+							   <nonce_str>'.$nonce_str.'</nonce_str>
+							   <out_trade_no>'.$out_trade_no.'</out_trade_no>
+							   <sign>'.$sign.'</sign>
+							</xml>';
+                    	
+                    $url = "https://api.mch.weixin.qq.com/pay/orderquery";
+            
+                    $result = http_request($url,$post_xml);
+            
+                    $array = xml($result);
+            
+                    if( $array['RETURN_CODE'] == 'SUCCESS' && $array['RETURN_MSG'] == 'OK' )
+                    {
+                        if( $array['TRADE_STATE'] == 'SUCCESS' || $array['TRADE_STATE'] == 'REFUND' ) 
+                        {
+                           $total_fee = $array['TOTAL_FEE'];
+                        }
+                    }
+            
+                }
+            }
+            
+            //
+			
+			
+			$input = new \WxPayRefund();
+			
+			$input->SetTransaction_id($transaction_id);
+			$input->SetTotal_fee($total_fee);
+			$input->SetRefund_fee($refund_fee);
+			
+			$mchid = D('Home/Front')->get_config_by_name('wepro_partnerid');
+			
+			$refund_no = $mchid.date("YmdHis").$order_info['order_id'];
+			
+			$input->SetOut_refund_no($refund_no);
+			$input->SetOp_user_id($mchid);
+			
+			
+			$res = \WxPayApi::refund($input,6,$order_info['from_type']);
+			
+			if($res["return_code"] == 'FAIL'){
+          		return array('code' => 0, 'msg' => $res['return_msg']);
+			}
+			
+			if( $res['err_code_des'] == '订单已全额退款' )
+			{
+				$res['result_code'] = 'SUCCESS';
+			}
+			
+			if($res['result_code'] == 'SUCCESS')
+			{
+				
+				if($order_info['order_status_id'] == 12)
+				{
+					$ref_count = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_info['order_id'], 'state' => 0 ) )->count();
+					if( $ref_count <= 1 )
+					{
+						M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
+					}
+				}
+				
+				$order_info['total'] = $refund_fee / 100;
+				
+				
+				$order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_info['order_id']) )->select();	
+					
+				$order_goods_name_arr = array();
+				$order_goods_name = '';
+					
+				foreach($order_goods_list as $order_goods)
+				{
+					
+					$order_goods_name_arr[] = $order_goods['name'];
+					//...
+					if( !empty($order_goods_id) && $order_goods_id > 0  )
+					{
+						if($order_goods_id ==  $order_goods['order_goods_id'] )
+						{
+							if($is_back_sellcount == 1)
+							{
+								if( $is_zi_order_refund == 1 && $refund_quantity > 0 )
+								{
+									D('Home/Pingoods')->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$refund_quantity,2);
+								}else{
+									//获取已退款数量
+									$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
+									if(!$has_refund_quantity){
+										$has_refund_quantity = 0;
+									}
+									D('Home/Pingoods')->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
+								}
+							}
+							
+							$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_id' => $order_info['order_id'],'order_goods_id'=>$order_goods['order_goods_id'] ,'type' => 'orderbuy') )->find();
+							
+							if( !empty($score_refund_info) && $is_zi_order_refund == 1  )
+							{
+								// D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+							}
+						}
+					}else if( empty($order_goods_id) || $order_goods_id <=0 ){
+						if($is_back_sellcount == 1){
+							$has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $order_info['order_id'], 'order_goods_id' =>$order_goods['order_goods_id']) )->sum('quantity');
+							if(!$has_refund_quantity){
+								$has_refund_quantity = 0;
+							}
+							D('Home/Pingoods')->del_goods_mult_option_quantity($order_info['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity']-$has_refund_quantity,2);
+						}
+
+						
+						$score_refund_info = M('lionfish_comshop_member_integral_flow')->where( array('order_id' => $order_info['order_id'],'order_goods_id' =>$order_goods['order_goods_id'] ,'type' => 'orderbuy') )->find();
+						
+						if( !empty($score_refund_info) )
+						{
+							// D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$score_refund_info['score'], 0 ,'退款增加积分', 'refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+						}
+					}
+					
+					if( $order_info['type'] == 'integral' )
+					{
+						D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$order_goods['total'], 0 ,'退款增加积分','refundorder', $order_info['order_id'] ,$order_goods['order_goods_id'] );
+					}
+				
+				}
+				
+				$order_goods_name = implode('\r\n', $order_goods_name_arr); //."\r\n";	
+		
+				 
+				//分佣也要退回去 
+				if($is_zi_order_refund == 0)
+					D('Seller/Community')->back_order_commission($order_info['order_id'],$order_goods_id);
+				
+				return array('code' => 1);
+				
+			} else {
+				
+				$order_refund_history = array();
+				$order_refund_history['order_id'] =  $order_info['order_id'];
+				$order_refund_history['order_goods_id'] =  $order_goods_id;
+				
+				$order_refund_history['message'] = $res['err_code_des'];
+				$order_refund_history['type'] = 2;
+				$order_refund_history['addtime'] = time();
+				
+				M('lionfish_comshop_order_refund_history')->add($order_refund_history);
+				
+				/**
+				M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 10, 'remarksaler' => $res[err_code_des]) );
+				**/
+				
+				return array('code' => 0, 'msg' => $res['err_code_des']);
+				
+			}
+			
+		}
+		
+		
+		
+		
+	}
+	
+	public function refundOrder2($order_id,$money =0)
+	{
+		
+		$lib_path = dirname(dirname( dirname(__FILE__) )).'/Lib/';
+		$data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
+		RecursiveMkdir($data_path);
+		
+		set_time_limit(0);
+		
+		
+		require_once $lib_path."/Weixin/lib/WxPay.Api.php";
+		require_once $lib_path."/Weixin/log.php";
+		
+		//初始化日志
+		$logHandler= new \CLogFileHandler( $data_path .date('Y-m-d').'.log');
+		
+		\Log::Init($logHandler, 15);
+		\Log::DEBUG("进行中,订单ID :".$order_id );
+		
+		//pin
+		$order_info = M('order')->where( array('order_id' => $order_id) )->find();
+		
+		$member_info = M('member')->where( array('member_id' => $order_info['member_id']) )->find();
+		
+		$openId = $member_info['openid'];
+		$we_openid = $member_info['we_openid'];
+		
+		if( $order_info['from_type'] == 'wepro' )
+		{
+			$openId = $we_openid;
+		}
+		//we_openid
+		//money
+		$transaction_id = $order_info["transaction_id"];
+		
+		
+		
+		$total_fee = ($order_info["total"])*100;
+		$refund_fee = $total_fee;
+		if($money > 0)
+		{
+			$refund_fee = $money * 100;
+		}
+		
+		
+		
+		if($order_info['payment_code'] == 'yuer')
+		{
+			//余额支付的,退款到余额
+			//退款到余额
+			$member_charge_flow_data = array();
+			$member_charge_flow_data['member_id'] = $order_info['member_id'];
+			$member_charge_flow_data['money'] = $order_info["total"];
+			$member_charge_flow_data['state'] = 4;
+			$member_charge_flow_data['trans_id'] = $order_id;
+			$member_charge_flow_data['charge_time'] = time();
+			$member_charge_flow_data['add_time'] = time();
+			
+			M('member_charge_flow')->add($member_charge_flow_data);
+			//增加会员余额
+			M('member')->where( array('member_id'=> $order_info['member_id'] ) )->setInc('account_money',$order_info["total"] ); 
+					
+			
+			$order_info['total'] = $refund_fee / 100;
+			$this->refundOrder_success($order_info,$openId);
+			//检测是否有需要退回积分的订单
+		}
+		else if($refund_fee == 0)
+		{
+			M('order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
+			
+			$config_info = M('config')->where( array('name' => 'SITE_URL') )->find();
+			
+			$order_goods = M('order_goods')->where( array('order_id' => $order_info['order_id']) )->select();
+			
+			$order_goods_name = '';
+			$order_goods_name_arr = array();
+			
+			foreach ($order_goods as $key => $value) {
+				
+				$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$value['rela_goodsoption_valueid'],$value['goods_id'],$value['quantity'],2);
+				//销量回退
+				//$this->execute("UPDATE " . C('DB_PREFIX') . "goods SET seller_count = (seller_count - " . (int)$value['quantity'] . ") WHERE goods_id = '" . $value['goods_id'] . "' ");
+				$order_goods_name_arr[] = $value['name'];
+			}
+			$order_goods_name = implode('\r\n', $order_goods_name_arr); //."\r\n";	
+		
+			
+			$msg = '订单退款: 您的订单'.$order_info['order_num_alias'].'参团未成功,现退款:'.round($order_info["total"],2).'元,商品名称:'.$order_goods_name;
+			$url = $config_info['value'];
+			
+			//weixin_template_refund_order
+			//send_template_msg($wx_template_data,$url,$openid,C('weixin_template_refund_order'));
+			$url = $url."/index.php?s=/Order/info/id/{$order_info['order_id']}.html";
+			
+			/**
+			{{first.DATA}}
+			订单编号:{{keyword1.DATA}}
+			退款金额:{{keyword2.DATA}}
+			{{remark.DATA}}
+			---------------------------
+			校白君提醒您,您有一笔退款成功,请留意。
+			订单编号:20088115853
+			退款金额:¥19.00
+			更多学生价好货,在底部菜单栏哦~猛戳“校园专区”,享更多优惠!
+			**/
+			
+			$wx_template_data = array();
+			$wx_template_data['first'] = array('value' => '退款通知', 'color' => '#030303');
+			$wx_template_data['keyword1'] = array('value' => $order_goods_name, 'color' => '#030303');
+			$wx_template_data['keyword2'] = array('value' => round($order_info["total"],2), 'color' => '#030303');
+			$wx_template_data['remark'] = array('value' => '拼团失败已按原路退款', 'color' => '#030303');
+		
+			
+			if( $order_info['from_type'] == 'wepro' )
+			{
+				$template_data = array();
+				$template_data['keyword1'] = array('value' => $order_goods_name, 'color' => '#030303');
+				$template_data['keyword2'] = array('value' => '参团未成功', 'color' => '#030303');
+				$template_data['keyword3'] = array('value' => '拼团失败已按原路退款', 'color' => '#030303');
+				
+				$pay_order_msg_info =  M('config')->where( array('name' => 'weprogram_template_fail_pin') )->find();
+				$template_id = $pay_order_msg_info['value'];
+				
+				
+				$pagepath = 'pages/order/order?id='.$order_info['order_id'];
+				
+				/**
+				$member_formid_info = M('member_formid')->where( array('member_id' => $order_info['member_id'], 'state' => 0) )->find();
+					
+				send_wxtemplate_msg($template_data,$url,$pagepath,$member_info['we_openid'],$template_id,$member_formid_info['formid']);
+				//更新
+				M('member_formid')->where( array('id' => $member_formid_info['id']) )->save( array('state' => 1) );
+				
+				$order_info['member_id']
+				**/
+				
+				$member_formid_info = M('member_formid')->where( array('member_id' => $order_info['member_id'], 'formid' =>array('neq',''), 'state' => 0) )->order('id desc')->find();
+				if(!empty( $member_formid_info ))
+				{
+					send_wxtemplate_msg($template_data,$url,$pagepath,$member_info['we_openid'],$template_id,$member_formid_info['formid'] );
+					M('member_formid')->where( array('id' => $member_formid_info['id']) )->save( array('state' => 1) );
+				}
+				
+				
+				if( $openid != '1')
+				{
+					//notify_weixin_msg($member_info['openid'],$msg,'退款通知',$url);
+					send_template_msg($wx_template_data,$url,$member_info['openid'],C('weixin_template_refund_order'));
+				}
+			}else{
+				//notify_weixin_msg($member_info['openid'],$msg,'退款通知',$url);
+				send_template_msg($wx_template_data,$url,$member_info['openid'],C('weixin_template_refund_order'));
+			}
+			
+			//检测是否有需要退回积分的订单
+			
+			\Log::DEBUG("退款成功。。。退款日志:退款订单号:" . $order_info['order_id'].',ten:'.$transaction_id.'   退款金额: '
+			.$order_info["total"].',退款给:openid='.$openId);
+			
+		} else {
+			
+			$input = new \WxPayRefund();
+			$input->SetTransaction_id($transaction_id);
+			$input->SetTotal_fee($total_fee);
+			$input->SetRefund_fee($refund_fee);
+			$refund_no = \WxPayConfig::MCHID.date("YmdHis").$order_info['order_id'];
+			
+			$input->SetOut_refund_no($refund_no);
+			$input->SetOp_user_id(\WxPayConfig::MCHID);
+			
+			$res = (\WxPayApi::refund($input,6,$order_info['from_type']));
+			
+			//var_dump($res);die();  wx80131aa7dfc4ff71
+			
+			if($res['result_code'] == 'SUCCESS')
+			{
+				$order_info['total'] = $refund_fee / 100;
+				$this->refundOrder_success($order_info,$openId);
+				
+				\Log::DEBUG("退款成功。。。退款日志:退款订单号:" . $order_info['order_id'].',ten:'.$transaction_id.'   退款金额: '.$order_info["total"].',退款给:openid='.$openid);
+				//检测是否有需要退回积分的订单
+				
+			} else {
+			
+				M('order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 10, 'comment' => $res[err_code_des]) );
+				
+				\Log::DEBUG("退款失败。原因:{$res[err_code_des]}。。退款日志:退款订单号:" . $order_info['order_id'].',退款金额: '.$order_info["total"].',退款给:openid='.$openId);
+			}
+			
+		}
+		
+		return true;
+	}
+	
+	/**
+		取消已经付款的 待发货订单
+		5、处理订单,
+		6、处理退款,
+	**/
+	public  function del_cancle_order($order_id)
+	{				
+		$order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
+		
+		
+		//判断订单状态是否已付款,避免多次退款,不合理
+		if( $order_info['order_status_id'] == 1 )
+		{
+			//del_cancle_order 
+			
+			$total_money = D('Seller/Commonorder')->get_order_paymoney( $order_id );
+			
+			$has_refun_money = D('Seller/Commonorder')->order_refund_totalmoney( $order_id );
+
+			//是否预售订单begin
+            $presale_result = D('Home/PresaleGoods')->getOrderPresaleInfo( $order_id );
+            $presale_info = [];
+            if( $presale_result['code'] == 0 )
+            {
+                $presale_info = $presale_result['data'];
+                $total_money = $total_money - $presale_info['presale_ding_money'];
+            }
+            //end
+
+			$refund_money = round($total_money - $has_refun_money,2);
+			
+			
+			
+			$result = $this->refundOrder($order_id, $refund_money);
+			
+		
+			if( $result['code'] == 1 )
+			{
+				$order_history = array();
+				$order_history['order_id'] = $order_id;
+				$order_history['order_status_id'] = 5;
+				$order_history['notify'] = 0;
+				$order_history['comment'] = '会员前台申请取消订单,取消成功,并退款。';
+				$order_history['date_added'] = time();
+				
+				M('lionfish_comshop_order_history')->add( $order_history );
+				
+				M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('order_status_id' => 5) );
+				
+				//整笔
+				D('Seller/Commonorder')->refund_one_order( $order_id ,1);
+				
+				
+				return array('code' => 0);
+			}else{
+				$order_history = array();
+				$order_history['order_id'] = $order_id;
+				$order_history['order_status_id'] = 10;
+				$order_history['notify'] = 0;
+				$order_history['comment'] = '申请取消订单,但是退款失败。';
+				$order_history['date_added'] = time();
+				
+				M('lionfish_comshop_order_history')->add( $order_history );
+				
+				M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->save( array('order_status_id' => 10, 'remarksaler' => $result['msg']) );
+				
+				return array('code' => 1, 'msg' => $result['msg'] ,'s' => $result['code'] );
+			}
+			
+		}
+		 //如果退款成功了。那么就进行
+		
+	}
+	
+	
+	
+	
+	public function test_form_msg()
+	{
+		$member_info = M('member')->where( array('member_id' => 26) )->find();
+		
+		$form_id_arr = M('member_formid')->where( array('member_id' => 26,'state' =>0) )->find();
+		
+		M('member_formid')->where( array('id' => $form_id_arr['id'] ) )->save( array('state' =>1) );
+		$form_id = $form_id_arr['formid'];
+		
+		$template_data = array();
+		$template_data['keyword1'] = array('value' => '338866', 'color' => '#030303');
+		$template_data['keyword2'] = array('value' => '商品名称', 'color' => '#030303');
+		$template_data['keyword3'] = array('value' => '18元', 'color' => '#030303');
+		$template_data['keyword4'] = array('value' => '已按原路退款', 'color' => '#030303');
+		$template_data['keyword5'] = array('value' => '小鱼', 'color' => '#030303');
+		
+		$pay_order_msg_info =  M('config')->where( array('name' => 'weprogram_template_refund_order') )->find();
+		$template_id = $pay_order_msg_info['value'];
+		
+		
+		$pagepath = 'pages/order/order?id='.$order_info['order_id'];
+			
+		$rs = 	send_wxtemplate_msg($template_data,$url,$pagepath,$member_info['we_openid'],$template_id,$form_id);
+			var_dump($rs);die();
+	}
+	
+	public function refundOrder_success($order_info,$openid)
+	{
+		M('order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 7) );
+		
+		$member_info = M('member')->where( array('member_id' => $order_info['member_id']) )->find();
+		
+		
+		$config_info = M('config')->where( array('name' => 'SITE_URL') )->find();
+		
+		$order_goods = M('order_goods')->where( array('order_id' => $order_info['order_id']) )->select();
+		$goods_model = D('Home/Goods');
+		
+		$order_goods_name = '';
+		$order_goods_name_arr = array();
+		
+		foreach ($order_goods as $key => $value) {
+			//$this->execute("UPDATE " . C('DB_PREFIX') . "goods SET quantity = (quantity + " . (int)$value['quantity'] . ") WHERE goods_id = '" . $value['goods_id'] . "' ");
+			
+			$goods_model->del_goods_mult_option_quantity($order_info['order_id'],$value['rela_goodsoption_valueid'],$value['goods_id'],$value['quantity'],2);
+			//销量回退
+			//$this->execute("UPDATE " . C('DB_PREFIX') . "goods SET seller_count = (seller_count - " . (int)$value['quantity'] . ") WHERE goods_id = '" . $value['goods_id'] . "' ");
+			$order_goods_name_arr[] = $value['name'];
+		}
+			
+		$order_goods_name = implode('\r\n', $order_goods_name_arr); //."\r\n";	
+		
+		$msg = '订单退款: 您的订单'.$order_info['order_num_alias'].'参团未成功,现退款:'.round($order_info["total"],2).'元,商品名称:'.$order_goods_name;
+		$url = $config_info['value'];
+		
+		$wx_template_data = array();
+		$wx_template_data['first'] = array('value' => '退款通知', 'color' => '#030303');
+		$wx_template_data['keyword1'] = array('value' => $order_goods_name, 'color' => '#030303');
+		$wx_template_data['keyword2'] = array('value' => $order_info['total'].'元', 'color' => '#030303');
+		$wx_template_data['remark'] = array('value' => '已按原路退款', 'color' => '#030303');
+		
+		 
+		$url = $url."/index.php?s=/Order/info/id/{$order_info['order_id']}.html";
+		
+		
+		if( $order_info['from_type'] == 'wepro' )
+		{
+			/**
+			退款成功通知
+			关键词
+			订单号
+			{{keyword1.DATA}}
+			商品名称
+			{{keyword2.DATA}}
+			退款金额
+			{{keyword3.DATA}}
+			温馨提示
+			{{keyword4.DATA}}
+			备注
+			{{keyword5.DATA}}
+			**/
+			
+			//$total_money = ($order_info["total"],2);
+			
+			$template_data = array();
+			$template_data['keyword1'] = array('value' => $order_info['order_num_alias'], 'color' => '#030303');
+			$template_data['keyword2'] = array('value' => $order_goods_name, 'color' => '#030303');
+			$template_data['keyword3'] = array('value' => $order_info['total'].'元', 'color' => '#030303');
+			$template_data['keyword4'] = array('value' => '已按原路退款', 'color' => '#030303');
+			$template_data['keyword5'] = array('value' => $member_info['uname'], 'color' => '#030303');
+			
+			$pay_order_msg_info =  M('config')->where( array('name' => 'weprogram_template_refund_order') )->find();
+			$template_id = $pay_order_msg_info['value'];
+			
+			
+			$pagepath = 'pages/order/order?id='.$order_info['order_id'];
+			
+			
+			/**
+				$member_formid_info = M('member_formid')->where( array('member_id' => $order_info['member_id'], 'state' => 0) )->find();
+					
+				send_wxtemplate_msg($template_data,$url,$pagepath,$member_info['we_openid'],$template_id,$member_formid_info['formid']);
+				//更新
+				M('member_formid')->where( array('id' => $member_formid_info['id']) )->save( array('state' => 1) );
+				
+			**/
+			$member_formid_info = M('member_formid')->where( array('member_id' => $order_info['member_id'],'formid' =>array('neq',''), 'state' => 0) )->order('id desc')->find();
+				
+			//$order_info['member_id']
+			if( !empty($member_formid_info) )
+			{
+				$rs = 	send_wxtemplate_msg($template_data,$url,$pagepath,$member_info['we_openid'],$template_id,$member_formid_info['formid']);
+				M('member_formid')->where( array('id' => $member_formid_info['id']) )->save( array('state' => 1) );
+			}
+				
+			
+			if( $openid != '1')
+			{
+				//notify_weixin_msg($openid,$msg,'退款通知',$url);
+				send_template_msg($wx_template_data,$url,$openid,C('weixin_template_refund_order'));
+			
+			}
+		}else{
+			//notify_weixin_msg($openid,$msg,'退款通知',$url);
+			send_template_msg($wx_template_data,$url,$openid,C('weixin_template_refund_order'));
+			
+		}
+		
+		
+		
+	}
+}
+?>

+ 216 - 216
Modules/Lib/Weixin/JsApiPay.class.php

@@ -1,217 +1,217 @@
-<?php
-require_once dirname(__FILE__) ."/lib/WxPay.Api.php";
-require_once dirname(__FILE__) ."/log.php";
-
-$data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
-
-RecursiveMkdir($data_path);
-
-
-
-/**
- * 
- * JSAPI支付实现类
- * 该类实现了从微信公众平台获取code、通过code获取openid和access_token、
- * 生成jsapi支付js接口所需的参数、生成获取共享收货地址所需的参数
- * 
- * 该类是微信支付提供的样例程序,商户可根据自己的需求修改,或者使用lib中的api自行开发
- * 
- * @author widy
- *
- */
-class JsApiPay
-{
-	/**
-	 * 
-	 * 网页授权接口微信服务器返回的数据,返回样例如下
-	 * {
-	 *  "access_token":"ACCESS_TOKEN",
-	 *  "expires_in":7200,
-	 *  "refresh_token":"REFRESH_TOKEN",
-	 *  "openid":"OPENID",
-	 *  "scope":"SCOPE",
-	 *  "unionid": "o6_bmasdasdsad6_2sgVt7hMZOPfL"
-	 * }
-	 * 其中access_token可用于获取共享收货地址
-	 * openid是微信支付jsapi支付接口必须的参数
-	 * @var array
-	 */
-	public $data = null;
-	
-	/**
-	 * 
-	 * 通过跳转获取用户的openid,跳转流程如下:
-	 * 1、设置自己需要调回的url及其其他参数,跳转到微信服务器https://open.weixin.qq.com/connect/oauth2/authorize
-	 * 2、微信服务处理完成之后会跳转回用户redirect_uri地址,此时会带上一些参数,如:code
-	 * 
-	 * @return 用户的openid
-	 */
-	public function GetOpenid()
-	{
-		//通过code获得openid
-		if (!isset($_GET['code'])){
-			//触发微信返回code码
-			
-			$baseUrl = urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']);
-			$url = $this->__CreateOauthUrlForCode($baseUrl);
-			Header("Location: $url");
-			exit();
-		} else {
-			//获取code码,以获取openid
-		    $code = $_GET['code'];
-			$openid = $this->getOpenidFromMp($code);
-			return $openid;
-		}
-	}
-	
-	/**
-	 * 
-	 * 获取jsapi支付的参数
-	 * @param array $UnifiedOrderResult 统一支付接口返回的数据
-	 * @throws WxPayException
-	 * 
-	 * @return json数据,可直接填入js函数作为参数
-	 */
-	public function GetJsApiParameters($UnifiedOrderResult)
-	{
-		if(!array_key_exists("appid", $UnifiedOrderResult)
-		|| !array_key_exists("prepay_id", $UnifiedOrderResult)
-		|| $UnifiedOrderResult['prepay_id'] == "")
-		{
-			throw new WxPayException("参数错误");
-		}
-		$jsapi = new WxPayJsApiPay();
-		$jsapi->SetAppid($UnifiedOrderResult["appid"]);
-		$time = time();
-		$timeStamp = "$time";
-		$jsapi->SetTimeStamp($timeStamp);
-		$jsapi->SetNonceStr(WxPayApi::getNonceStr());
-		$jsapi->SetPackage("prepay_id=" . $UnifiedOrderResult['prepay_id']);
-		$jsapi->SetSignType("MD5");
-		$jsapi->SetPaySign($jsapi->MakeSign());
-		$parameters = json_encode($jsapi->GetValues());
-		return $parameters;
-	}
-	
-	/**
-	 * 
-	 * 通过code从工作平台获取openid机器access_token
-	 * @param string $code 微信跳转回来带上的code
-	 * 
-	 * @return openid
-	 */
-	public function GetOpenidFromMp($code)
-	{
-		$url = $this->__CreateOauthUrlForOpenid($code);
-		//初始化curl
-		$ch = curl_init();
-		//设置超时
-		curl_setopt($ch, CURLOP_TIMEOUT, 30);
-		curl_setopt($ch, CURLOPT_URL, $url);
-		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE);
-		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,FALSE);
-		curl_setopt($ch, CURLOPT_HEADER, FALSE);
-		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
-		if(WxPayConfig::CURL_PROXY_HOST != "0.0.0.0" 
-			&& WxPayConfig::CURL_PROXY_PORT != 0){
-			curl_setopt($ch,CURLOPT_PROXY, WxPayConfig::CURL_PROXY_HOST);
-			curl_setopt($ch,CURLOPT_PROXYPORT, WxPayConfig::CURL_PROXY_PORT);
-		}
-		//运行curl,结果以jason形式返回
-		$res = curl_exec($ch);
-		curl_close($ch);
-		//取出openid
-		$data = json_decode($res,true);
-		$this->data = $data;
-		$openid = $data['openid'];
-		return $openid;
-	}
-	
-	/**
-	 * 
-	 * 拼接签名字符串
-	 * @param array $urlObj
-	 * 
-	 * @return 返回已经拼接好的字符串
-	 */
-	private function ToUrlParams($urlObj)
-	{
-		$buff = "";
-		foreach ($urlObj as $k => $v)
-		{
-			if($k != "sign"){
-				$buff .= $k . "=" . $v . "&";
-			}
-		}
-		
-		$buff = trim($buff, "&");
-		return $buff;
-	}
-	
-	/**
-	 * 
-	 * 获取地址js参数
-	 * 
-	 * @return 获取共享收货地址js函数需要的参数,json格式可以直接做参数使用
-	 */
-	public function GetEditAddressParameters()
-	{	
-		$getData = $this->data;
-		$data = array();
-		$data["appid"] = WxPayConfig::APPID;
-		$data["url"] = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
-		$time = time();
-		$data["timestamp"] = "$time";
-		$data["noncestr"] = "1234568";
-		$data["accesstoken"] = $getData["access_token"];
-		ksort($data);
-		$params = $this->ToUrlParams($data);
-		$addrSign = sha1($params);
-		
-		$afterData = array(
-			"addrSign" => $addrSign,
-			"signType" => "sha1",
-			"scope" => "jsapi_address",
-			"appId" => WxPayConfig::APPID,
-			"timeStamp" => $data["timestamp"],
-			"nonceStr" => $data["noncestr"]
-		);
-		$parameters = json_encode($afterData);
-		return $parameters;
-	}
-	
-	/**
-	 * 
-	 * 构造获取code的url连接
-	 * @param string $redirectUrl 微信服务器回跳的url,需要url编码
-	 * 
-	 * @return 返回构造好的url
-	 */
-	private function __CreateOauthUrlForCode($redirectUrl)
-	{
-		$urlObj["appid"] = WxPayConfig::APPID;
-		$urlObj["redirect_uri"] = "$redirectUrl";
-		$urlObj["response_type"] = "code";
-		$urlObj["scope"] = "snsapi_base";
-		$urlObj["state"] = "STATE"."#wechat_redirect";
-		$bizString = $this->ToUrlParams($urlObj);
-		return "https://open.weixin.qq.com/connect/oauth2/authorize?".$bizString;
-	}
-	
-	/**
-	 * 
-	 * 构造获取open和access_toke的url地址
-	 * @param string $code,微信跳转带回的code
-	 * 
-	 * @return 请求的url
-	 */
-	private function __CreateOauthUrlForOpenid($code)
-	{
-		$urlObj["appid"] = WxPayConfig::APPID;
-		$urlObj["secret"] = WxPayConfig::APPSECRET;
-		$urlObj["code"] = $code;
-		$urlObj["grant_type"] = "authorization_code";
-		$bizString = $this->ToUrlParams($urlObj);
-		return "https://api.weixin.qq.com/sns/oauth2/access_token?".$bizString;
-	}
+<?php
+require_once dirname(__FILE__) ."/lib/WxPay.Api.php";
+require_once dirname(__FILE__) ."/log.php";
+
+$data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
+
+RecursiveMkdir($data_path);
+
+
+
+/**
+ * 
+ * JSAPI支付实现类
+ * 该类实现了从微信公众平台获取code、通过code获取openid和access_token、
+ * 生成jsapi支付js接口所需的参数、生成获取共享收货地址所需的参数
+ * 
+ * 该类是微信支付提供的样例程序,商户可根据自己的需求修改,或者使用lib中的api自行开发
+ * 
+ * @author widy
+ *
+ */
+class JsApiPay
+{
+	/**
+	 * 
+	 * 网页授权接口微信服务器返回的数据,返回样例如下
+	 * {
+	 *  "access_token":"ACCESS_TOKEN",
+	 *  "expires_in":7200,
+	 *  "refresh_token":"REFRESH_TOKEN",
+	 *  "openid":"OPENID",
+	 *  "scope":"SCOPE",
+	 *  "unionid": "o6_bmasdasdsad6_2sgVt7hMZOPfL"
+	 * }
+	 * 其中access_token可用于获取共享收货地址
+	 * openid是微信支付jsapi支付接口必须的参数
+	 * @var array
+	 */
+	public $data = null;
+	
+	/**
+	 * 
+	 * 通过跳转获取用户的openid,跳转流程如下:
+	 * 1、设置自己需要调回的url及其其他参数,跳转到微信服务器https://open.weixin.qq.com/connect/oauth2/authorize
+	 * 2、微信服务处理完成之后会跳转回用户redirect_uri地址,此时会带上一些参数,如:code
+	 * 
+	 * @return 用户的openid
+	 */
+	public function GetOpenid()
+	{
+		//通过code获得openid
+		if (!isset($_GET['code'])){
+			//触发微信返回code码
+			
+			$baseUrl = urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']);
+			$url = $this->__CreateOauthUrlForCode($baseUrl);
+			Header("Location: $url");
+			exit();
+		} else {
+			//获取code码,以获取openid
+		    $code = $_GET['code'];
+			$openid = $this->getOpenidFromMp($code);
+			return $openid;
+		}
+	}
+	
+	/**
+	 * 
+	 * 获取jsapi支付的参数
+	 * @param array $UnifiedOrderResult 统一支付接口返回的数据
+	 * @throws WxPayException
+	 * 
+	 * @return json数据,可直接填入js函数作为参数
+	 */
+	public function GetJsApiParameters($UnifiedOrderResult)
+	{
+		if(!array_key_exists("appid", $UnifiedOrderResult)
+		|| !array_key_exists("prepay_id", $UnifiedOrderResult)
+		|| $UnifiedOrderResult['prepay_id'] == "")
+		{
+			throw new WxPayException("参数错误");
+		}
+		$jsapi = new WxPayJsApiPay();
+		$jsapi->SetAppid($UnifiedOrderResult["appid"]);
+		$time = time();
+		$timeStamp = "$time";
+		$jsapi->SetTimeStamp($timeStamp);
+		$jsapi->SetNonceStr(WxPayApi::getNonceStr());
+		$jsapi->SetPackage("prepay_id=" . $UnifiedOrderResult['prepay_id']);
+		$jsapi->SetSignType("MD5");
+		$jsapi->SetPaySign($jsapi->MakeSign());
+		$parameters = json_encode($jsapi->GetValues());
+		return $parameters;
+	}
+	
+	/**
+	 * 
+	 * 通过code从工作平台获取openid机器access_token
+	 * @param string $code 微信跳转回来带上的code
+	 * 
+	 * @return openid
+	 */
+	public function GetOpenidFromMp($code)
+	{
+		$url = $this->__CreateOauthUrlForOpenid($code);
+		//初始化curl
+		$ch = curl_init();
+		//设置超时
+		curl_setopt($ch, CURLOP_TIMEOUT, 30);
+		curl_setopt($ch, CURLOPT_URL, $url);
+		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE);
+		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,FALSE);
+		curl_setopt($ch, CURLOPT_HEADER, FALSE);
+		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
+		if(WxPayConfig::CURL_PROXY_HOST != "0.0.0.0" 
+			&& WxPayConfig::CURL_PROXY_PORT != 0){
+			curl_setopt($ch,CURLOPT_PROXY, WxPayConfig::CURL_PROXY_HOST);
+			curl_setopt($ch,CURLOPT_PROXYPORT, WxPayConfig::CURL_PROXY_PORT);
+		}
+		//运行curl,结果以jason形式返回
+		$res = curl_exec($ch);
+		curl_close($ch);
+		//取出openid
+		$data = json_decode($res,true);
+		$this->data = $data;
+		$openid = $data['openid'];
+		return $openid;
+	}
+	
+	/**
+	 * 
+	 * 拼接签名字符串
+	 * @param array $urlObj
+	 * 
+	 * @return 返回已经拼接好的字符串
+	 */
+	private function ToUrlParams($urlObj)
+	{
+		$buff = "";
+		foreach ($urlObj as $k => $v)
+		{
+			if($k != "sign"){
+				$buff .= $k . "=" . $v . "&";
+			}
+		}
+		
+		$buff = trim($buff, "&");
+		return $buff;
+	}
+	
+	/**
+	 * 
+	 * 获取地址js参数
+	 * 
+	 * @return 获取共享收货地址js函数需要的参数,json格式可以直接做参数使用
+	 */
+	public function GetEditAddressParameters()
+	{	
+		$getData = $this->data;
+		$data = array();
+		$data["appid"] = WxPayConfig::APPID;
+		$data["url"] = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
+		$time = time();
+		$data["timestamp"] = "$time";
+		$data["noncestr"] = "1234568";
+		$data["accesstoken"] = $getData["access_token"];
+		ksort($data);
+		$params = $this->ToUrlParams($data);
+		$addrSign = sha1($params);
+		
+		$afterData = array(
+			"addrSign" => $addrSign,
+			"signType" => "sha1",
+			"scope" => "jsapi_address",
+			"appId" => WxPayConfig::APPID,
+			"timeStamp" => $data["timestamp"],
+			"nonceStr" => $data["noncestr"]
+		);
+		$parameters = json_encode($afterData);
+		return $parameters;
+	}
+	
+	/**
+	 * 
+	 * 构造获取code的url连接
+	 * @param string $redirectUrl 微信服务器回跳的url,需要url编码
+	 * 
+	 * @return 返回构造好的url
+	 */
+	private function __CreateOauthUrlForCode($redirectUrl)
+	{
+		$urlObj["appid"] = WxPayConfig::APPID;
+		$urlObj["redirect_uri"] = "$redirectUrl";
+		$urlObj["response_type"] = "code";
+		$urlObj["scope"] = "snsapi_base";
+		$urlObj["state"] = "STATE"."#wechat_redirect";
+		$bizString = $this->ToUrlParams($urlObj);
+		return "https://open.weixin.qq.com/connect/oauth2/authorize?".$bizString;
+	}
+	
+	/**
+	 * 
+	 * 构造获取open和access_toke的url地址
+	 * @param string $code,微信跳转带回的code
+	 * 
+	 * @return 请求的url
+	 */
+	private function __CreateOauthUrlForOpenid($code)
+	{
+		$urlObj["appid"] = WxPayConfig::APPID;
+		$urlObj["secret"] = WxPayConfig::APPSECRET;
+		$urlObj["code"] = $code;
+		$urlObj["grant_type"] = "authorization_code";
+		$bizString = $this->ToUrlParams($urlObj);
+		return "https://api.weixin.qq.com/sns/oauth2/access_token?".$bizString;
+	}
 }

+ 217 - 0
Modules/Lib/Weixin/JsApiPay.class.php.back

@@ -0,0 +1,217 @@
+<?php
+require_once dirname(__FILE__) ."/lib/WxPay.Api.php";
+require_once dirname(__FILE__) ."/log.php";
+
+$data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
+
+RecursiveMkdir($data_path);
+
+
+
+/**
+ * 
+ * JSAPI支付实现类
+ * 该类实现了从微信公众平台获取code、通过code获取openid和access_token、
+ * 生成jsapi支付js接口所需的参数、生成获取共享收货地址所需的参数
+ * 
+ * 该类是微信支付提供的样例程序,商户可根据自己的需求修改,或者使用lib中的api自行开发
+ * 
+ * @author widy
+ *
+ */
+class JsApiPay
+{
+	/**
+	 * 
+	 * 网页授权接口微信服务器返回的数据,返回样例如下
+	 * {
+	 *  "access_token":"ACCESS_TOKEN",
+	 *  "expires_in":7200,
+	 *  "refresh_token":"REFRESH_TOKEN",
+	 *  "openid":"OPENID",
+	 *  "scope":"SCOPE",
+	 *  "unionid": "o6_bmasdasdsad6_2sgVt7hMZOPfL"
+	 * }
+	 * 其中access_token可用于获取共享收货地址
+	 * openid是微信支付jsapi支付接口必须的参数
+	 * @var array
+	 */
+	public $data = null;
+	
+	/**
+	 * 
+	 * 通过跳转获取用户的openid,跳转流程如下:
+	 * 1、设置自己需要调回的url及其其他参数,跳转到微信服务器https://open.weixin.qq.com/connect/oauth2/authorize
+	 * 2、微信服务处理完成之后会跳转回用户redirect_uri地址,此时会带上一些参数,如:code
+	 * 
+	 * @return 用户的openid
+	 */
+	public function GetOpenid()
+	{
+		//通过code获得openid
+		if (!isset($_GET['code'])){
+			//触发微信返回code码
+			
+			$baseUrl = urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']);
+			$url = $this->__CreateOauthUrlForCode($baseUrl);
+			Header("Location: $url");
+			exit();
+		} else {
+			//获取code码,以获取openid
+		    $code = $_GET['code'];
+			$openid = $this->getOpenidFromMp($code);
+			return $openid;
+		}
+	}
+	
+	/**
+	 * 
+	 * 获取jsapi支付的参数
+	 * @param array $UnifiedOrderResult 统一支付接口返回的数据
+	 * @throws WxPayException
+	 * 
+	 * @return json数据,可直接填入js函数作为参数
+	 */
+	public function GetJsApiParameters($UnifiedOrderResult)
+	{
+		if(!array_key_exists("appid", $UnifiedOrderResult)
+		|| !array_key_exists("prepay_id", $UnifiedOrderResult)
+		|| $UnifiedOrderResult['prepay_id'] == "")
+		{
+			throw new WxPayException("参数错误");
+		}
+		$jsapi = new WxPayJsApiPay();
+		$jsapi->SetAppid($UnifiedOrderResult["appid"]);
+		$time = time();
+		$timeStamp = "$time";
+		$jsapi->SetTimeStamp($timeStamp);
+		$jsapi->SetNonceStr(WxPayApi::getNonceStr());
+		$jsapi->SetPackage("prepay_id=" . $UnifiedOrderResult['prepay_id']);
+		$jsapi->SetSignType("MD5");
+		$jsapi->SetPaySign($jsapi->MakeSign());
+		$parameters = json_encode($jsapi->GetValues());
+		return $parameters;
+	}
+	
+	/**
+	 * 
+	 * 通过code从工作平台获取openid机器access_token
+	 * @param string $code 微信跳转回来带上的code
+	 * 
+	 * @return openid
+	 */
+	public function GetOpenidFromMp($code)
+	{
+		$url = $this->__CreateOauthUrlForOpenid($code);
+		//初始化curl
+		$ch = curl_init();
+		//设置超时
+		curl_setopt($ch, CURLOP_TIMEOUT, 30);
+		curl_setopt($ch, CURLOPT_URL, $url);
+		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE);
+		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,FALSE);
+		curl_setopt($ch, CURLOPT_HEADER, FALSE);
+		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
+		if(WxPayConfig::CURL_PROXY_HOST != "0.0.0.0" 
+			&& WxPayConfig::CURL_PROXY_PORT != 0){
+			curl_setopt($ch,CURLOPT_PROXY, WxPayConfig::CURL_PROXY_HOST);
+			curl_setopt($ch,CURLOPT_PROXYPORT, WxPayConfig::CURL_PROXY_PORT);
+		}
+		//运行curl,结果以jason形式返回
+		$res = curl_exec($ch);
+		curl_close($ch);
+		//取出openid
+		$data = json_decode($res,true);
+		$this->data = $data;
+		$openid = $data['openid'];
+		return $openid;
+	}
+	
+	/**
+	 * 
+	 * 拼接签名字符串
+	 * @param array $urlObj
+	 * 
+	 * @return 返回已经拼接好的字符串
+	 */
+	private function ToUrlParams($urlObj)
+	{
+		$buff = "";
+		foreach ($urlObj as $k => $v)
+		{
+			if($k != "sign"){
+				$buff .= $k . "=" . $v . "&";
+			}
+		}
+		
+		$buff = trim($buff, "&");
+		return $buff;
+	}
+	
+	/**
+	 * 
+	 * 获取地址js参数
+	 * 
+	 * @return 获取共享收货地址js函数需要的参数,json格式可以直接做参数使用
+	 */
+	public function GetEditAddressParameters()
+	{	
+		$getData = $this->data;
+		$data = array();
+		$data["appid"] = WxPayConfig::APPID;
+		$data["url"] = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
+		$time = time();
+		$data["timestamp"] = "$time";
+		$data["noncestr"] = "1234568";
+		$data["accesstoken"] = $getData["access_token"];
+		ksort($data);
+		$params = $this->ToUrlParams($data);
+		$addrSign = sha1($params);
+		
+		$afterData = array(
+			"addrSign" => $addrSign,
+			"signType" => "sha1",
+			"scope" => "jsapi_address",
+			"appId" => WxPayConfig::APPID,
+			"timeStamp" => $data["timestamp"],
+			"nonceStr" => $data["noncestr"]
+		);
+		$parameters = json_encode($afterData);
+		return $parameters;
+	}
+	
+	/**
+	 * 
+	 * 构造获取code的url连接
+	 * @param string $redirectUrl 微信服务器回跳的url,需要url编码
+	 * 
+	 * @return 返回构造好的url
+	 */
+	private function __CreateOauthUrlForCode($redirectUrl)
+	{
+		$urlObj["appid"] = WxPayConfig::APPID;
+		$urlObj["redirect_uri"] = "$redirectUrl";
+		$urlObj["response_type"] = "code";
+		$urlObj["scope"] = "snsapi_base";
+		$urlObj["state"] = "STATE"."#wechat_redirect";
+		$bizString = $this->ToUrlParams($urlObj);
+		return "https://open.weixin.qq.com/connect/oauth2/authorize?".$bizString;
+	}
+	
+	/**
+	 * 
+	 * 构造获取open和access_toke的url地址
+	 * @param string $code,微信跳转带回的code
+	 * 
+	 * @return 请求的url
+	 */
+	private function __CreateOauthUrlForOpenid($code)
+	{
+		$urlObj["appid"] = WxPayConfig::APPID;
+		$urlObj["secret"] = WxPayConfig::APPSECRET;
+		$urlObj["code"] = $code;
+		$urlObj["grant_type"] = "authorization_code";
+		$bizString = $this->ToUrlParams($urlObj);
+		return "https://api.weixin.qq.com/sns/oauth2/access_token?".$bizString;
+	}
+}

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 0 - 421
Modules/Lib/Weixin/Jssdk.class.php


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 421 - 0
Modules/Lib/Weixin/Jssdk.class.php.back


+ 458 - 459
Modules/Lib/Weixin/PayNotifyCallBack.class.php

@@ -1,459 +1,458 @@
-<?php
-require_once dirname(__FILE__) ."/lib/WxPay.Api.php";
-require_once dirname(__FILE__) ."/lib/WxFy.Api.php";
-require_once dirname(__FILE__) .'/lib/WxPay.Notify.php';
-require_once dirname(__FILE__) .'/log.php';
-
-
-$lib_path = dirname(dirname( dirname(__FILE__) )).'/Lib/';
-
-$data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
-
-RecursiveMkdir($data_path);
-
-
-
-
-//初始化日志
-//\Think\Log::record("begin notify222");
-
-class PayNotifyCallBack extends WxPayNotify
-{
-	//查询订单
-	public function Queryorder($transaction_id)
-	{
-		global $INI;
-		$input = new WxPayOrderQuery();
-		$input->SetTransaction_id($transaction_id);
-		$result = WxPayApi::orderQuery($input);
-		
-
-		
-
-		if(array_key_exists("return_code", $result)
-			&& array_key_exists("result_code", $result)
-			&& $result["return_code"] == "SUCCESS"
-			&& $result["result_code"] == "SUCCESS")
-		{
-			//DO
-			return true;
-		}
-		return false;
-	}
-	
-	//重写回调处理函数
-	public function NotifyProcess($data, &$msg)
-	{
-		global $_W;
-		global $_GPC;
-		
-
-		//global $_W;
-
-		 $out_trade_no_str = $data['out_trade_no'];
-		$out_trade_no_arr =  explode('-',$out_trade_no_str);
-		$out_trade_no = $out_trade_no_arr[0];
-		$fy_type=$data['type'];
-      
-      
-		$data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
-		
-		RecursiveMkdir($data_path);
-
-		$file = $data_path.date('Y-m-d').'.txt';
-		$handl = fopen($file,'a');
-		fwrite($handl,"Queryorder");
-		fwrite($handl,"call back:" . json_encode($data));
-     	 fwrite($handl,"小程序开始查询支付:");
-		fclose($handl);
-		
-		
-		
-		$notfiyOutput = array();
-		
-		//\Think\Log::record("call back:" . json_encode($data));
-		
-		if(!array_key_exists("transaction_id", $data)){
-			$msg = "输入参数不正确";
-			return false;
-		}
-		//查询订单,判断订单真实性
-		if( false &&  !$this->Queryorder($data["transaction_id"])){
-			
-			
-			
-			
-			$msg = "订单查询失败";
-			return false;
-		}else {
-			/**
-			{
-				"appid":"wx334ca53b2a62661a",
-				"bank_type":"CFT",
-				"cash_fee":"1",
-				"fee_type":"CNY",
-				"is_subscribe":"N",
-				"mch_id":"1246637501",
-				"nonce_str":"eKWYmZBlPgeRUoeyNpOAFuBXvXWVofsD",
-				"openid":"o_57D5DcRw-r6SdRxF98ikhf5dLY",
-				"out_trade_no":"7-1540693614",
-				"result_code":"SUCCESS",
-				"return_code":"SUCCESS",
-				"sign":"2B480C75338FCDE3972DF21AC7CC7596",
-				"time_end":"20181028102711",
-				"total_fee":"1",
-				"trade_type":"JSAPI",
-				"transaction_id":"4200000236201810287313447913"
-			}
-			**/
-			
-			
-			
-			$total_fee = $data['total_fee'];
-			$transaction_id = $data['transaction_id'];
-			$out_trade_no_arr =  explode('-',$data['out_trade_no']);
-			$out_trade_no = $out_trade_no_arr[0];
-			
-			if( isset($out_trade_no_arr[2]) && $out_trade_no_arr[2] == 'charge' )
-			{
-				//暂时屏蔽会员充值代码
-				
-				$member_charge_flow_info = M('lionfish_comshop_member_charge_flow')->where( array('id' => $out_trade_no ) )->find();
-				
-				if(!empty($member_charge_flow_info) && $member_charge_flow_info['state'] == 0)
-				{
-					$charge_flow_data = array();
-					$charge_flow_data['trans_id'] = $transaction_id;
-					$charge_flow_data['state'] = 1;
-					$charge_flow_data['charge_time'] = time();
-					
-					M('lionfish_comshop_member_charge_flow')->where( array('id' => $out_trade_no) )->save( $charge_flow_data );
-					
-					if( !empty($member_charge_flow_info['give_money']) && $member_charge_flow_info['give_money'] > 0 )
-					{
-						$member_charge_flow_info['money'] += $member_charge_flow_info['give_money'];
-					}
-					
-					
-					M('lionfish_comshop_member')->where( array('member_id' => $member_charge_flow_info['member_id'] ) )->setInc('account_money', $member_charge_flow_info['money'] );
-					
-					
-					$mb_info = M('lionfish_comshop_member')->field('account_money')->where( array('member_id' => $member_charge_flow_info['member_id']) )->find();
-					if( empty($mb_info['account_money']) )
-					{
-						$mb_info['account_money'] = 0;
-					}
-					M('lionfish_comshop_member_charge_flow')->where( array('id' => $out_trade_no) )->save(  array('operate_end_yuer' => $mb_info['account_money']) );
-					
-					
-					$mb_info = M('lionfish_comshop_member')->field('account_money')->where( array('member_id' => $member_charge_flow_info['member_id']) )->find();
-					
-					M('lionfish_comshop_member_charge_flow')->where( array('id' => $out_trade_no) )->save( array('operate_end_yuer' => $mb_info['account_money']) );
-					
-					
-					for($i=0;$i<3;$i++)
-					{
-						$member_formid_data = array();
-						$member_formid_data['member_id'] = $member_charge_flow_info['member_id'];
-						$member_formid_data['state'] = 0;
-						$member_formid_data['formid'] = $member_charge_flow_info['formid'];
-						$member_formid_data['addtime'] = time();
-						
-						M('lionfish_comshop_member_formid')->add($member_formid_data);
-					}
-					
-				}	
-				
-			}
-			else if(  isset($out_trade_no_arr[2]) && $out_trade_no_arr[2] == 'buycard' )
-			{
-				//购买会员卡代码	
-				$member_charge_flow_info = M('lionfish_comshop_member_card_order')->where( array('id' => $out_trade_no ) )->find();					
-				
-				$member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_charge_flow_info['member_id'] ) )->find();
-									
-				if(!empty($member_charge_flow_info) && $member_charge_flow_info['state'] == 0)
-				{
-					$begin_time = 0;
-					$end_time = 0;
-					
-					if($member_charge_flow_info['order_type'] == 1)
-					{
-						//首次购买
-						$begin_time = time();
-						$end_time = $begin_time + 86400 * $member_charge_flow_info['expire_day'];
-						
-					}else if($member_charge_flow_info['order_type'] == 2)
-					{
-						//有效期内续期
-						$begin_time = $member_info['card_end_time'];
-						$end_time = $begin_time + 86400 * $member_charge_flow_info['expire_day'];
-					}else if($member_charge_flow_info['order_type'] == 3)
-					{
-						//过期后续费
-						$begin_time = time();
-						$end_time = $begin_time + 86400 * $member_charge_flow_info['expire_day'];
-					}
-					
-					$charge_flow_data = array();
-					$charge_flow_data['trans_id'] = $transaction_id;
-					$charge_flow_data['state'] = 1;
-					$charge_flow_data['pay_time'] = time();
-					$charge_flow_data['begin_time'] = $begin_time;
-					$charge_flow_data['end_time'] = $end_time;
-					$charge_flow_data['state'] = 1;
-					
-					M('lionfish_comshop_member_card_order')->where( array('id' => $out_trade_no ) )->save( $charge_flow_data );
-					
-					$mb_up_data = array();
-					$mb_up_data['card_id'] = $member_charge_flow_info['car_id'];
-					$mb_up_data['card_begin_time'] = $begin_time;
-					$mb_up_data['card_end_time'] = $end_time;
-					
-					M('lionfish_comshop_member')->where( array('member_id' => $member_charge_flow_info['member_id']  ) )->save( $mb_up_data );
-					
-					for($i=0;$i<3;$i++)
-					{
-						$member_formid_data = array();
-						$member_formid_data['member_id'] = $member_charge_flow_info['member_id'];
-						$member_formid_data['state'] = 0;
-						$member_formid_data['formid'] = $member_charge_flow_info['formid'];
-						$member_formid_data['addtime'] = time();
-						
-						M('lionfish_comshop_member_formid')->add($member_formid_data);
-					}
-					
-					
-				}
-			}
-			else{
-				//
-				
-				$order_all = M('lionfish_comshop_order_all')->where( array('id' => $out_trade_no ) )->find();
-				
-				if( in_array($order_all['order_status_id'], array(1,2,15)) ){
-					
-					$stop_pay = false;
-					
-					$order_relate_list = M('lionfish_comshop_order_relate')->where( array('order_all_id' => $order_all['id'] ) )->select();
-					
-					foreach($order_relate_list as $order_relate)
-					{
-						$order = M('lionfish_comshop_order')->where( array('order_id' => $order_relate['order_id'] ) )->find();
-						
-						if( $order && ($order['order_status_id'] != 3 && $order['order_status_id'] == 5) )
-						{
-							$stop_pay = true;
-						}
-					}
-					
-					if( $stop_pay )
-					{
-						$msg = "付款成功";
-						return true;
-					}
-				}
-
-				$o = array();
-				$o['order_status_id'] =  $order_all['is_pin'] == 1 ? 2:1;
-				$o['paytime']=time();
-				$o['transaction_id'] = $transaction_id;
-				
-				M('lionfish_comshop_order_all')->where( array('id' => $out_trade_no) )->save($o);
-				
-				$order_relate_list = M('lionfish_comshop_order_relate')->where( array('order_all_id' => $order_all['id']) )->select();
-				
-				//1
-					$data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
-					RecursiveMkdir($data_path);
-					
-					$file = $data_path.date('Y-m-d').'.txt';
-					$handl = fopen($file,'a');
-					fwrite($handl,"关联--");
-					fwrite($handl,"关联");
-					fwrite($handl,":".json_encode($order_relate_list));
-					fclose($handl);
-				
-
-				foreach($order_relate_list as $order_relate)
-				{
-					$order = M('lionfish_comshop_order')->where( array('order_id' => $order_relate['order_id'] ) )->find();
-
-                    //检测是否预售
-                    $order_presale_info = M('lionfish_comshop_order_presale')->where(['order_id' => $order_relate['order_id'] ])->find();
-
-                    //检测是否礼品卡
-                    $order_virtualcard_info =  D('Seller/VirtualCard')->getOrderVirtualCardByOrderId( $order_relate['order_id'] );
-
-					if( $order && ($order['order_status_id'] == 3 || $order['order_status_id'] == 5 || $order['order_status_id'] == 15 ) )
-					{
-					    //begin 判断预售第一次还是第二次付款
-					    $order_status_id = $order['is_pin'] == 1 ? 2:1;
-					    if( !empty($order_presale_info) )
-                        {
-                            if( $order_presale_info['state'] == 0 )
-                            {
-                                $order_status_id = 15;//首次付款
-                            }else if( $order_presale_info['state'] == 1 )
-                            {
-                                $order_status_id = 1;//二次付款
-                            }
-                        }
-                        //end
-
-						$o = array();
-						$o['order_status_id'] =  $order_status_id;
-						$o['date_modified']=time();
-						$o['pay_time']=time();
-						$o['payment_code']=$fy_type?'fypay':'weixin';
-						$o['transaction_id'] = $transaction_id;
-
-						if( empty($order_presale_info) || $order_presale_info['state'] == 1 )
-                        {
-                            if($order['delivery'] == 'hexiao'  ){//核销订单 支付完成状态改成  已发货待收货
-                                $o['order_status_id'] =  4;
-                            }
-                        }
-
-						
-						M('lionfish_comshop_order')->where( array('order_id' => $order['order_id'] ) )->save( $o );
-						
-						//暂时屏蔽库存代码
-						
-						$kucun_method =  D('Home/Front')->get_config_by_name('kucun_method');
-						
-						if( empty($kucun_method) )
-						{
-							$kucun_method = 0;
-						}
-						
-						//kucun_method $_W['uniacid']
-						
-						if($kucun_method == 1)
-						{//支付完减库存,增加销量
-							
-							$order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order['order_id']) )->select();	
-							
-							foreach($order_goods_list as $order_goods)
-							{
-								D('Home/Pingoods')->del_goods_mult_option_quantity($order['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity'],1);
-								
-								
-							}
-						}
-						
-						$oh = array();	
-						$oh['order_id']=$order['order_id'];
-						$oh['uniacid']=$order['uniacid'];
-						$oh['order_status_id']= $order_status_id;
-							
-						$oh['comment']='买家已付款';
-						$oh['date_added']=time();
-						$oh['notify']=1;
-
-						if($order['delivery'] == 'hexiao' && empty($order_presale_info) ){//核销订单 支付完成状态改成  已发货待收货
-							$oh['order_status_id'] =  4;
-						}
-						
-						M('lionfish_comshop_order_history')->add($oh);
-
-						//邀新有礼下单完成领取礼包
-						D('Home/Invitegift')->collectInvitegiftAfterOrder($order, 'orderpay');
-
-                        if( empty($order_presale_info) )
-                        {
-                            //订单自动配送
-                            D('Home/Order')->order_auto_delivery($order);
-                        }
-
-						
-						//$weixin_nofity->orderBuy($order['order_id']);
-				
-						//$hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
-						//$order_id = $hashids->encode($order['order_id']); 
-						//group_order_id
-						
-						if($order['is_pin'] == 1)
-						{
-							$pin_order = M('lionfish_comshop_pin_order')->where( array('order_id' => $order['order_id'] ) )->find();
-							
-							D('Home/Pin')->insertNotifyOrder($order['order_id']);
-							
-							//检测拼团是否已经成功了。如果已经成功了。那么重新开团,并且迁移掉目前的这个拼团订单到新的团去
-							//state
-							
-							$pin_info = M('lionfish_comshop_pin')->where(array('pin_id' => $pin_order['pin_id'])  )->find();//加锁查询
-							
-							$pin_buy_count = D('Home/Pin')->get_tuan_buy_count($pin_order['pin_id']);
-							
-							
-							$res = D('Seller/Redisorder')->add_pintuan_user( $pin_order['pin_id'] );
-							
-							
-							if( $pin_info['state']  == 1 && !$res )
-							{
-							    $order_goods_info = M('lionfish_comshop_order_goods')->where( array('order_id' => $order['order_id']) )->find();
-							    
-							    M('lionfish_comshop_pin_order')->where( array('pin_id' =>$pin_order['pin_id'],'order_id' => $order['order_id'] ) )->delete();
-							    
-							    $newpin_id = D('Home/Pin')->openNewTuan($order['order_id'],$order_goods_info['goods_id'],$order['member_id']);
-							    //插入拼团订单
-							    D('Home/Pin')->insertTuanOrder($newpin_id,$order['order_id']);
-							    unset($pin_info);
-							   
-							    $is_pin_success = D('Home/Pin')->checkPinSuccess($newpin_id);
-							    
-							    if($is_pin_success) {
-							        D('Home/Pin')->updatePintuanSuccess($newpin_id);
-							    }
-							}else{
-							    $is_pin_success = D('Home/Pin')->checkPinSuccess($pin_order['pin_id']);
-							    	
-							    if($is_pin_success) {
-							        D('Home/Pin')->updatePintuanSuccess($pin_order['pin_id']);
-							    } 
-							}
-
-						}
-						//检测预售支付
-						if( !empty($order_presale_info) )
-                        {
-                            D('Home/PresaleGoods')->payBackOrder( $order['order_id'] , $transaction_id );
-                        }
-                        //检测是否礼品卡
-                        if( !empty($order_virtualcard_info) )
-                        {
-                            D('Seller/VirtualCard')->payBackOrder( $order['order_id'] );
-                        }
-
-						//发送购买通知
-						D('Home/Weixinnotify')->orderBuy($order['order_id']);
-
-                        //微信交易组件
-                        if( $order['from_type'] == 'tradecomponts' )
-                        {
-                            D('Seller/MpModifyTradeComponts')->orderPay( $order['order_id'], '1' );
-                        }
-						
-					}
-
-				}		
-				
-				
-			}
-			
-			
-			
-			
-			
-					
-			//$order=M('Order')->getByOrderNumAlias($out_trade_no);
-			
-		    
-			
-			
-			return true;
-		}
-	}
-}
-
+<?php
+require_once dirname(__FILE__) ."/lib/WxPay.Api.php";
+require_once dirname(__FILE__) .'/lib/WxPay.Notify.php';
+require_once dirname(__FILE__) .'/log.php';
+
+
+$lib_path = dirname(dirname( dirname(__FILE__) )).'/Lib/';
+
+$data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
+
+RecursiveMkdir($data_path);
+
+
+
+
+//初始化日志
+//\Think\Log::record("begin notify222");
+
+class PayNotifyCallBack extends WxPayNotify
+{
+	//查询订单
+	public function Queryorder($transaction_id)
+	{
+		global $INI;
+		$input = new WxPayOrderQuery();
+		$input->SetTransaction_id($transaction_id);
+		$result = WxPayApi::orderQuery($input);
+		
+
+		
+
+		if(array_key_exists("return_code", $result)
+			&& array_key_exists("result_code", $result)
+			&& $result["return_code"] == "SUCCESS"
+			&& $result["result_code"] == "SUCCESS")
+		{
+			//DO
+			return true;
+		}
+		return false;
+	}
+	
+	//重写回调处理函数
+	public function NotifyProcess($data, &$msg)
+	{
+		global $_W;
+		global $_GPC;
+		
+
+		//global $_W;
+		
+		 $out_trade_no_str = $data['out_trade_no'];
+		$out_trade_no_arr =  explode('-',$out_trade_no_str);
+		$out_trade_no = $out_trade_no_arr[0];
+		
+      
+      
+		$data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
+		
+		RecursiveMkdir($data_path);
+
+		$file = $data_path.date('Y-m-d').'.txt';
+		$handl = fopen($file,'a');
+		fwrite($handl,"Queryorder");
+		fwrite($handl,"call back:" . json_encode($data));
+     	 fwrite($handl,"小程序开始查询支付:");
+		fclose($handl);
+		
+		
+		
+		$notfiyOutput = array();
+		
+		//\Think\Log::record("call back:" . json_encode($data));
+		
+		if(!array_key_exists("transaction_id", $data)){
+			$msg = "输入参数不正确";
+			return false;
+		}
+		//查询订单,判断订单真实性
+		if( false &&  !$this->Queryorder($data["transaction_id"])){
+			
+			
+			
+			
+			$msg = "订单查询失败";
+			return false;
+		}else {
+			/**
+			{
+				"appid":"wx334ca53b2a62661a",
+				"bank_type":"CFT",
+				"cash_fee":"1",
+				"fee_type":"CNY",
+				"is_subscribe":"N",
+				"mch_id":"1246637501",
+				"nonce_str":"eKWYmZBlPgeRUoeyNpOAFuBXvXWVofsD",
+				"openid":"o_57D5DcRw-r6SdRxF98ikhf5dLY",
+				"out_trade_no":"7-1540693614",
+				"result_code":"SUCCESS",
+				"return_code":"SUCCESS",
+				"sign":"2B480C75338FCDE3972DF21AC7CC7596",
+				"time_end":"20181028102711",
+				"total_fee":"1",
+				"trade_type":"JSAPI",
+				"transaction_id":"4200000236201810287313447913"
+			}
+			**/
+			
+			
+			
+			$total_fee = $data['total_fee'];
+			$transaction_id = $data['transaction_id'];
+			$out_trade_no_arr =  explode('-',$data['out_trade_no']);
+			$out_trade_no = $out_trade_no_arr[0];
+			
+			if( isset($out_trade_no_arr[2]) && $out_trade_no_arr[2] == 'charge' )
+			{
+				//暂时屏蔽会员充值代码
+				
+				$member_charge_flow_info = M('lionfish_comshop_member_charge_flow')->where( array('id' => $out_trade_no ) )->find();
+				
+				if(!empty($member_charge_flow_info) && $member_charge_flow_info['state'] == 0)
+				{
+					$charge_flow_data = array();
+					$charge_flow_data['trans_id'] = $transaction_id;
+					$charge_flow_data['state'] = 1;
+					$charge_flow_data['charge_time'] = time();
+					
+					M('lionfish_comshop_member_charge_flow')->where( array('id' => $out_trade_no) )->save( $charge_flow_data );
+					
+					if( !empty($member_charge_flow_info['give_money']) && $member_charge_flow_info['give_money'] > 0 )
+					{
+						$member_charge_flow_info['money'] += $member_charge_flow_info['give_money'];
+					}
+					
+					
+					M('lionfish_comshop_member')->where( array('member_id' => $member_charge_flow_info['member_id'] ) )->setInc('account_money', $member_charge_flow_info['money'] );
+					
+					
+					$mb_info = M('lionfish_comshop_member')->field('account_money')->where( array('member_id' => $member_charge_flow_info['member_id']) )->find();
+					if( empty($mb_info['account_money']) )
+					{
+						$mb_info['account_money'] = 0;
+					}
+					M('lionfish_comshop_member_charge_flow')->where( array('id' => $out_trade_no) )->save(  array('operate_end_yuer' => $mb_info['account_money']) );
+					
+					
+					$mb_info = M('lionfish_comshop_member')->field('account_money')->where( array('member_id' => $member_charge_flow_info['member_id']) )->find();
+					
+					M('lionfish_comshop_member_charge_flow')->where( array('id' => $out_trade_no) )->save( array('operate_end_yuer' => $mb_info['account_money']) );
+					
+					
+					for($i=0;$i<3;$i++)
+					{
+						$member_formid_data = array();
+						$member_formid_data['member_id'] = $member_charge_flow_info['member_id'];
+						$member_formid_data['state'] = 0;
+						$member_formid_data['formid'] = $member_charge_flow_info['formid'];
+						$member_formid_data['addtime'] = time();
+						
+						M('lionfish_comshop_member_formid')->add($member_formid_data);
+					}
+					
+				}	
+				
+			}
+			else if(  isset($out_trade_no_arr[2]) && $out_trade_no_arr[2] == 'buycard' )
+			{
+				//购买会员卡代码	
+				$member_charge_flow_info = M('lionfish_comshop_member_card_order')->where( array('id' => $out_trade_no ) )->find();					
+				
+				$member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_charge_flow_info['member_id'] ) )->find();
+									
+				if(!empty($member_charge_flow_info) && $member_charge_flow_info['state'] == 0)
+				{
+					$begin_time = 0;
+					$end_time = 0;
+					
+					if($member_charge_flow_info['order_type'] == 1)
+					{
+						//首次购买
+						$begin_time = time();
+						$end_time = $begin_time + 86400 * $member_charge_flow_info['expire_day'];
+						
+					}else if($member_charge_flow_info['order_type'] == 2)
+					{
+						//有效期内续期
+						$begin_time = $member_info['card_end_time'];
+						$end_time = $begin_time + 86400 * $member_charge_flow_info['expire_day'];
+					}else if($member_charge_flow_info['order_type'] == 3)
+					{
+						//过期后续费
+						$begin_time = time();
+						$end_time = $begin_time + 86400 * $member_charge_flow_info['expire_day'];
+					}
+					
+					$charge_flow_data = array();
+					$charge_flow_data['trans_id'] = $transaction_id;
+					$charge_flow_data['state'] = 1;
+					$charge_flow_data['pay_time'] = time();
+					$charge_flow_data['begin_time'] = $begin_time;
+					$charge_flow_data['end_time'] = $end_time;
+					$charge_flow_data['state'] = 1;
+					
+					M('lionfish_comshop_member_card_order')->where( array('id' => $out_trade_no ) )->save( $charge_flow_data );
+					
+					$mb_up_data = array();
+					$mb_up_data['card_id'] = $member_charge_flow_info['car_id'];
+					$mb_up_data['card_begin_time'] = $begin_time;
+					$mb_up_data['card_end_time'] = $end_time;
+					
+					M('lionfish_comshop_member')->where( array('member_id' => $member_charge_flow_info['member_id']  ) )->save( $mb_up_data );
+					
+					for($i=0;$i<3;$i++)
+					{
+						$member_formid_data = array();
+						$member_formid_data['member_id'] = $member_charge_flow_info['member_id'];
+						$member_formid_data['state'] = 0;
+						$member_formid_data['formid'] = $member_charge_flow_info['formid'];
+						$member_formid_data['addtime'] = time();
+						
+						M('lionfish_comshop_member_formid')->add($member_formid_data);
+					}
+					
+					
+				}
+			}
+			else{
+				//
+				
+				$order_all = M('lionfish_comshop_order_all')->where( array('id' => $out_trade_no ) )->find();
+				
+				if( in_array($order_all['order_status_id'], array(1,2,15)) ){
+					
+					$stop_pay = false;
+					
+					$order_relate_list = M('lionfish_comshop_order_relate')->where( array('order_all_id' => $order_all['id'] ) )->select();
+					
+					foreach($order_relate_list as $order_relate)
+					{
+						$order = M('lionfish_comshop_order')->where( array('order_id' => $order_relate['order_id'] ) )->find();
+						
+						if( $order && ($order['order_status_id'] != 3 && $order['order_status_id'] == 5) )
+						{
+							$stop_pay = true;
+						}
+					}
+					
+					if( $stop_pay )
+					{
+						$msg = "付款成功";
+						return true;
+					}
+				}
+
+				$o = array();
+				$o['order_status_id'] =  $order_all['is_pin'] == 1 ? 2:1;
+				$o['paytime']=time();
+				$o['transaction_id'] = $transaction_id;
+				
+				M('lionfish_comshop_order_all')->where( array('id' => $out_trade_no) )->save($o);
+				
+				$order_relate_list = M('lionfish_comshop_order_relate')->where( array('order_all_id' => $order_all['id']) )->select();
+				
+				//1
+					$data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
+					RecursiveMkdir($data_path);
+					
+					$file = $data_path.date('Y-m-d').'.txt';
+					$handl = fopen($file,'a');
+					fwrite($handl,"关联--");
+					fwrite($handl,"关联");
+					fwrite($handl,":".json_encode($order_relate_list));
+					fclose($handl);
+				
+
+				foreach($order_relate_list as $order_relate)
+				{
+					$order = M('lionfish_comshop_order')->where( array('order_id' => $order_relate['order_id'] ) )->find();
+
+                    //检测是否预售
+                    $order_presale_info = M('lionfish_comshop_order_presale')->where(['order_id' => $order_relate['order_id'] ])->find();
+
+                    //检测是否礼品卡
+                    $order_virtualcard_info =  D('Seller/VirtualCard')->getOrderVirtualCardByOrderId( $order_relate['order_id'] );
+
+					if( $order && ($order['order_status_id'] == 3 || $order['order_status_id'] == 5 || $order['order_status_id'] == 15 ) )
+					{
+					    //begin 判断预售第一次还是第二次付款
+					    $order_status_id = $order['is_pin'] == 1 ? 2:1;
+					    if( !empty($order_presale_info) )
+                        {
+                            if( $order_presale_info['state'] == 0 )
+                            {
+                                $order_status_id = 15;//首次付款
+                            }else if( $order_presale_info['state'] == 1 )
+                            {
+                                $order_status_id = 1;//二次付款
+                            }
+                        }
+                        //end
+
+						$o = array();
+						$o['order_status_id'] =  $order_status_id;
+						$o['date_modified']=time();
+						$o['pay_time']=time();
+						$o['payment_code']='weixin';
+						$o['transaction_id'] = $transaction_id;
+
+						if( empty($order_presale_info) || $order_presale_info['state'] == 1 )
+                        {
+                            if($order['delivery'] == 'hexiao'  ){//核销订单 支付完成状态改成  已发货待收货
+                                $o['order_status_id'] =  4;
+                            }
+                        }
+
+						
+						M('lionfish_comshop_order')->where( array('order_id' => $order['order_id'] ) )->save( $o );
+						
+						//暂时屏蔽库存代码
+						
+						$kucun_method =  D('Home/Front')->get_config_by_name('kucun_method');
+						
+						if( empty($kucun_method) )
+						{
+							$kucun_method = 0;
+						}
+						
+						//kucun_method $_W['uniacid']
+						
+						if($kucun_method == 1)
+						{//支付完减库存,增加销量
+							
+							$order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order['order_id']) )->select();	
+							
+							foreach($order_goods_list as $order_goods)
+							{
+								D('Home/Pingoods')->del_goods_mult_option_quantity($order['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity'],1);
+								
+								
+							}
+						}
+						
+						$oh = array();	
+						$oh['order_id']=$order['order_id'];
+						$oh['uniacid']=$order['uniacid'];
+						$oh['order_status_id']= $order_status_id;
+							
+						$oh['comment']='买家已付款';
+						$oh['date_added']=time();
+						$oh['notify']=1;
+
+						if($order['delivery'] == 'hexiao' && empty($order_presale_info) ){//核销订单 支付完成状态改成  已发货待收货
+							$oh['order_status_id'] =  4;
+						}
+						
+						M('lionfish_comshop_order_history')->add($oh);
+
+						//邀新有礼下单完成领取礼包
+						D('Home/Invitegift')->collectInvitegiftAfterOrder($order, 'orderpay');
+
+                        if( empty($order_presale_info) )
+                        {
+                            //订单自动配送
+                            D('Home/Order')->order_auto_delivery($order);
+                        }
+
+						
+						//$weixin_nofity->orderBuy($order['order_id']);
+				
+						//$hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
+						//$order_id = $hashids->encode($order['order_id']); 
+						//group_order_id
+						
+						if($order['is_pin'] == 1)
+						{
+							$pin_order = M('lionfish_comshop_pin_order')->where( array('order_id' => $order['order_id'] ) )->find();
+							
+							D('Home/Pin')->insertNotifyOrder($order['order_id']);
+							
+							//检测拼团是否已经成功了。如果已经成功了。那么重新开团,并且迁移掉目前的这个拼团订单到新的团去
+							//state
+							
+							$pin_info = M('lionfish_comshop_pin')->where(array('pin_id' => $pin_order['pin_id'])  )->find();//加锁查询
+							
+							$pin_buy_count = D('Home/Pin')->get_tuan_buy_count($pin_order['pin_id']);
+							
+							
+							$res = D('Seller/Redisorder')->add_pintuan_user( $pin_order['pin_id'] );
+							
+							
+							if( $pin_info['state']  == 1 && !$res )
+							{
+							    $order_goods_info = M('lionfish_comshop_order_goods')->where( array('order_id' => $order['order_id']) )->find();
+							    
+							    M('lionfish_comshop_pin_order')->where( array('pin_id' =>$pin_order['pin_id'],'order_id' => $order['order_id'] ) )->delete();
+							    
+							    $newpin_id = D('Home/Pin')->openNewTuan($order['order_id'],$order_goods_info['goods_id'],$order['member_id']);
+							    //插入拼团订单
+							    D('Home/Pin')->insertTuanOrder($newpin_id,$order['order_id']);
+							    unset($pin_info);
+							   
+							    $is_pin_success = D('Home/Pin')->checkPinSuccess($newpin_id);
+							    
+							    if($is_pin_success) {
+							        D('Home/Pin')->updatePintuanSuccess($newpin_id);
+							    }
+							}else{
+							    $is_pin_success = D('Home/Pin')->checkPinSuccess($pin_order['pin_id']);
+							    	
+							    if($is_pin_success) {
+							        D('Home/Pin')->updatePintuanSuccess($pin_order['pin_id']);
+							    } 
+							}
+
+						}
+						//检测预售支付
+						if( !empty($order_presale_info) )
+                        {
+                            D('Home/PresaleGoods')->payBackOrder( $order['order_id'] , $transaction_id );
+                        }
+                        //检测是否礼品卡
+                        if( !empty($order_virtualcard_info) )
+                        {
+                            D('Seller/VirtualCard')->payBackOrder( $order['order_id'] );
+                        }
+
+						//发送购买通知
+						D('Home/Weixinnotify')->orderBuy($order['order_id']);
+
+                        //微信交易组件
+                        if( $order['from_type'] == 'tradecomponts' )
+                        {
+                            D('Seller/MpModifyTradeComponts')->orderPay( $order['order_id'], '1' );
+                        }
+						
+					}
+
+				}		
+				
+				
+			}
+			
+			
+			
+			
+			
+					
+			//$order=M('Order')->getByOrderNumAlias($out_trade_no);
+			
+		    
+			
+			
+			return true;
+		}
+	}
+}
+

+ 459 - 0
Modules/Lib/Weixin/PayNotifyCallBack.class.php.back

@@ -0,0 +1,459 @@
+<?php
+require_once dirname(__FILE__) ."/lib/WxPay.Api.php";
+require_once dirname(__FILE__) ."/lib/WxFy.Api.php";
+require_once dirname(__FILE__) .'/lib/WxPay.Notify.php';
+require_once dirname(__FILE__) .'/log.php';
+
+
+$lib_path = dirname(dirname( dirname(__FILE__) )).'/Lib/';
+
+$data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
+
+RecursiveMkdir($data_path);
+
+
+
+
+//初始化日志
+//\Think\Log::record("begin notify222");
+
+class PayNotifyCallBack extends WxPayNotify
+{
+	//查询订单
+	public function Queryorder($transaction_id)
+	{
+		global $INI;
+		$input = new WxPayOrderQuery();
+		$input->SetTransaction_id($transaction_id);
+		$result = WxPayApi::orderQuery($input);
+		
+
+		
+
+		if(array_key_exists("return_code", $result)
+			&& array_key_exists("result_code", $result)
+			&& $result["return_code"] == "SUCCESS"
+			&& $result["result_code"] == "SUCCESS")
+		{
+			//DO
+			return true;
+		}
+		return false;
+	}
+	
+	//重写回调处理函数
+	public function NotifyProcess($data, &$msg)
+	{
+		global $_W;
+		global $_GPC;
+		
+
+		//global $_W;
+
+		 $out_trade_no_str = $data['out_trade_no'];
+		$out_trade_no_arr =  explode('-',$out_trade_no_str);
+		$out_trade_no = $out_trade_no_arr[0];
+		$fy_type=$data['type'];
+      
+      
+		$data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
+		
+		RecursiveMkdir($data_path);
+
+		$file = $data_path.date('Y-m-d').'.txt';
+		$handl = fopen($file,'a');
+		fwrite($handl,"Queryorder");
+		fwrite($handl,"call back:" . json_encode($data));
+     	 fwrite($handl,"小程序开始查询支付:");
+		fclose($handl);
+		
+		
+		
+		$notfiyOutput = array();
+		
+		//\Think\Log::record("call back:" . json_encode($data));
+		
+		if(!array_key_exists("transaction_id", $data)){
+			$msg = "输入参数不正确";
+			return false;
+		}
+		//查询订单,判断订单真实性
+		if( false &&  !$this->Queryorder($data["transaction_id"])){
+			
+			
+			
+			
+			$msg = "订单查询失败";
+			return false;
+		}else {
+			/**
+			{
+				"appid":"wx334ca53b2a62661a",
+				"bank_type":"CFT",
+				"cash_fee":"1",
+				"fee_type":"CNY",
+				"is_subscribe":"N",
+				"mch_id":"1246637501",
+				"nonce_str":"eKWYmZBlPgeRUoeyNpOAFuBXvXWVofsD",
+				"openid":"o_57D5DcRw-r6SdRxF98ikhf5dLY",
+				"out_trade_no":"7-1540693614",
+				"result_code":"SUCCESS",
+				"return_code":"SUCCESS",
+				"sign":"2B480C75338FCDE3972DF21AC7CC7596",
+				"time_end":"20181028102711",
+				"total_fee":"1",
+				"trade_type":"JSAPI",
+				"transaction_id":"4200000236201810287313447913"
+			}
+			**/
+			
+			
+			
+			$total_fee = $data['total_fee'];
+			$transaction_id = $data['transaction_id'];
+			$out_trade_no_arr =  explode('-',$data['out_trade_no']);
+			$out_trade_no = $out_trade_no_arr[0];
+			
+			if( isset($out_trade_no_arr[2]) && $out_trade_no_arr[2] == 'charge' )
+			{
+				//暂时屏蔽会员充值代码
+				
+				$member_charge_flow_info = M('lionfish_comshop_member_charge_flow')->where( array('id' => $out_trade_no ) )->find();
+				
+				if(!empty($member_charge_flow_info) && $member_charge_flow_info['state'] == 0)
+				{
+					$charge_flow_data = array();
+					$charge_flow_data['trans_id'] = $transaction_id;
+					$charge_flow_data['state'] = 1;
+					$charge_flow_data['charge_time'] = time();
+					
+					M('lionfish_comshop_member_charge_flow')->where( array('id' => $out_trade_no) )->save( $charge_flow_data );
+					
+					if( !empty($member_charge_flow_info['give_money']) && $member_charge_flow_info['give_money'] > 0 )
+					{
+						$member_charge_flow_info['money'] += $member_charge_flow_info['give_money'];
+					}
+					
+					
+					M('lionfish_comshop_member')->where( array('member_id' => $member_charge_flow_info['member_id'] ) )->setInc('account_money', $member_charge_flow_info['money'] );
+					
+					
+					$mb_info = M('lionfish_comshop_member')->field('account_money')->where( array('member_id' => $member_charge_flow_info['member_id']) )->find();
+					if( empty($mb_info['account_money']) )
+					{
+						$mb_info['account_money'] = 0;
+					}
+					M('lionfish_comshop_member_charge_flow')->where( array('id' => $out_trade_no) )->save(  array('operate_end_yuer' => $mb_info['account_money']) );
+					
+					
+					$mb_info = M('lionfish_comshop_member')->field('account_money')->where( array('member_id' => $member_charge_flow_info['member_id']) )->find();
+					
+					M('lionfish_comshop_member_charge_flow')->where( array('id' => $out_trade_no) )->save( array('operate_end_yuer' => $mb_info['account_money']) );
+					
+					
+					for($i=0;$i<3;$i++)
+					{
+						$member_formid_data = array();
+						$member_formid_data['member_id'] = $member_charge_flow_info['member_id'];
+						$member_formid_data['state'] = 0;
+						$member_formid_data['formid'] = $member_charge_flow_info['formid'];
+						$member_formid_data['addtime'] = time();
+						
+						M('lionfish_comshop_member_formid')->add($member_formid_data);
+					}
+					
+				}	
+				
+			}
+			else if(  isset($out_trade_no_arr[2]) && $out_trade_no_arr[2] == 'buycard' )
+			{
+				//购买会员卡代码	
+				$member_charge_flow_info = M('lionfish_comshop_member_card_order')->where( array('id' => $out_trade_no ) )->find();					
+				
+				$member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_charge_flow_info['member_id'] ) )->find();
+									
+				if(!empty($member_charge_flow_info) && $member_charge_flow_info['state'] == 0)
+				{
+					$begin_time = 0;
+					$end_time = 0;
+					
+					if($member_charge_flow_info['order_type'] == 1)
+					{
+						//首次购买
+						$begin_time = time();
+						$end_time = $begin_time + 86400 * $member_charge_flow_info['expire_day'];
+						
+					}else if($member_charge_flow_info['order_type'] == 2)
+					{
+						//有效期内续期
+						$begin_time = $member_info['card_end_time'];
+						$end_time = $begin_time + 86400 * $member_charge_flow_info['expire_day'];
+					}else if($member_charge_flow_info['order_type'] == 3)
+					{
+						//过期后续费
+						$begin_time = time();
+						$end_time = $begin_time + 86400 * $member_charge_flow_info['expire_day'];
+					}
+					
+					$charge_flow_data = array();
+					$charge_flow_data['trans_id'] = $transaction_id;
+					$charge_flow_data['state'] = 1;
+					$charge_flow_data['pay_time'] = time();
+					$charge_flow_data['begin_time'] = $begin_time;
+					$charge_flow_data['end_time'] = $end_time;
+					$charge_flow_data['state'] = 1;
+					
+					M('lionfish_comshop_member_card_order')->where( array('id' => $out_trade_no ) )->save( $charge_flow_data );
+					
+					$mb_up_data = array();
+					$mb_up_data['card_id'] = $member_charge_flow_info['car_id'];
+					$mb_up_data['card_begin_time'] = $begin_time;
+					$mb_up_data['card_end_time'] = $end_time;
+					
+					M('lionfish_comshop_member')->where( array('member_id' => $member_charge_flow_info['member_id']  ) )->save( $mb_up_data );
+					
+					for($i=0;$i<3;$i++)
+					{
+						$member_formid_data = array();
+						$member_formid_data['member_id'] = $member_charge_flow_info['member_id'];
+						$member_formid_data['state'] = 0;
+						$member_formid_data['formid'] = $member_charge_flow_info['formid'];
+						$member_formid_data['addtime'] = time();
+						
+						M('lionfish_comshop_member_formid')->add($member_formid_data);
+					}
+					
+					
+				}
+			}
+			else{
+				//
+				
+				$order_all = M('lionfish_comshop_order_all')->where( array('id' => $out_trade_no ) )->find();
+				
+				if( in_array($order_all['order_status_id'], array(1,2,15)) ){
+					
+					$stop_pay = false;
+					
+					$order_relate_list = M('lionfish_comshop_order_relate')->where( array('order_all_id' => $order_all['id'] ) )->select();
+					
+					foreach($order_relate_list as $order_relate)
+					{
+						$order = M('lionfish_comshop_order')->where( array('order_id' => $order_relate['order_id'] ) )->find();
+						
+						if( $order && ($order['order_status_id'] != 3 && $order['order_status_id'] == 5) )
+						{
+							$stop_pay = true;
+						}
+					}
+					
+					if( $stop_pay )
+					{
+						$msg = "付款成功";
+						return true;
+					}
+				}
+
+				$o = array();
+				$o['order_status_id'] =  $order_all['is_pin'] == 1 ? 2:1;
+				$o['paytime']=time();
+				$o['transaction_id'] = $transaction_id;
+				
+				M('lionfish_comshop_order_all')->where( array('id' => $out_trade_no) )->save($o);
+				
+				$order_relate_list = M('lionfish_comshop_order_relate')->where( array('order_all_id' => $order_all['id']) )->select();
+				
+				//1
+					$data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
+					RecursiveMkdir($data_path);
+					
+					$file = $data_path.date('Y-m-d').'.txt';
+					$handl = fopen($file,'a');
+					fwrite($handl,"关联--");
+					fwrite($handl,"关联");
+					fwrite($handl,":".json_encode($order_relate_list));
+					fclose($handl);
+				
+
+				foreach($order_relate_list as $order_relate)
+				{
+					$order = M('lionfish_comshop_order')->where( array('order_id' => $order_relate['order_id'] ) )->find();
+
+                    //检测是否预售
+                    $order_presale_info = M('lionfish_comshop_order_presale')->where(['order_id' => $order_relate['order_id'] ])->find();
+
+                    //检测是否礼品卡
+                    $order_virtualcard_info =  D('Seller/VirtualCard')->getOrderVirtualCardByOrderId( $order_relate['order_id'] );
+
+					if( $order && ($order['order_status_id'] == 3 || $order['order_status_id'] == 5 || $order['order_status_id'] == 15 ) )
+					{
+					    //begin 判断预售第一次还是第二次付款
+					    $order_status_id = $order['is_pin'] == 1 ? 2:1;
+					    if( !empty($order_presale_info) )
+                        {
+                            if( $order_presale_info['state'] == 0 )
+                            {
+                                $order_status_id = 15;//首次付款
+                            }else if( $order_presale_info['state'] == 1 )
+                            {
+                                $order_status_id = 1;//二次付款
+                            }
+                        }
+                        //end
+
+						$o = array();
+						$o['order_status_id'] =  $order_status_id;
+						$o['date_modified']=time();
+						$o['pay_time']=time();
+						$o['payment_code']=$fy_type?'fypay':'weixin';
+						$o['transaction_id'] = $transaction_id;
+
+						if( empty($order_presale_info) || $order_presale_info['state'] == 1 )
+                        {
+                            if($order['delivery'] == 'hexiao'  ){//核销订单 支付完成状态改成  已发货待收货
+                                $o['order_status_id'] =  4;
+                            }
+                        }
+
+						
+						M('lionfish_comshop_order')->where( array('order_id' => $order['order_id'] ) )->save( $o );
+						
+						//暂时屏蔽库存代码
+						
+						$kucun_method =  D('Home/Front')->get_config_by_name('kucun_method');
+						
+						if( empty($kucun_method) )
+						{
+							$kucun_method = 0;
+						}
+						
+						//kucun_method $_W['uniacid']
+						
+						if($kucun_method == 1)
+						{//支付完减库存,增加销量
+							
+							$order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order['order_id']) )->select();	
+							
+							foreach($order_goods_list as $order_goods)
+							{
+								D('Home/Pingoods')->del_goods_mult_option_quantity($order['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity'],1);
+								
+								
+							}
+						}
+						
+						$oh = array();	
+						$oh['order_id']=$order['order_id'];
+						$oh['uniacid']=$order['uniacid'];
+						$oh['order_status_id']= $order_status_id;
+							
+						$oh['comment']='买家已付款';
+						$oh['date_added']=time();
+						$oh['notify']=1;
+
+						if($order['delivery'] == 'hexiao' && empty($order_presale_info) ){//核销订单 支付完成状态改成  已发货待收货
+							$oh['order_status_id'] =  4;
+						}
+						
+						M('lionfish_comshop_order_history')->add($oh);
+
+						//邀新有礼下单完成领取礼包
+						D('Home/Invitegift')->collectInvitegiftAfterOrder($order, 'orderpay');
+
+                        if( empty($order_presale_info) )
+                        {
+                            //订单自动配送
+                            D('Home/Order')->order_auto_delivery($order);
+                        }
+
+						
+						//$weixin_nofity->orderBuy($order['order_id']);
+				
+						//$hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
+						//$order_id = $hashids->encode($order['order_id']); 
+						//group_order_id
+						
+						if($order['is_pin'] == 1)
+						{
+							$pin_order = M('lionfish_comshop_pin_order')->where( array('order_id' => $order['order_id'] ) )->find();
+							
+							D('Home/Pin')->insertNotifyOrder($order['order_id']);
+							
+							//检测拼团是否已经成功了。如果已经成功了。那么重新开团,并且迁移掉目前的这个拼团订单到新的团去
+							//state
+							
+							$pin_info = M('lionfish_comshop_pin')->where(array('pin_id' => $pin_order['pin_id'])  )->find();//加锁查询
+							
+							$pin_buy_count = D('Home/Pin')->get_tuan_buy_count($pin_order['pin_id']);
+							
+							
+							$res = D('Seller/Redisorder')->add_pintuan_user( $pin_order['pin_id'] );
+							
+							
+							if( $pin_info['state']  == 1 && !$res )
+							{
+							    $order_goods_info = M('lionfish_comshop_order_goods')->where( array('order_id' => $order['order_id']) )->find();
+							    
+							    M('lionfish_comshop_pin_order')->where( array('pin_id' =>$pin_order['pin_id'],'order_id' => $order['order_id'] ) )->delete();
+							    
+							    $newpin_id = D('Home/Pin')->openNewTuan($order['order_id'],$order_goods_info['goods_id'],$order['member_id']);
+							    //插入拼团订单
+							    D('Home/Pin')->insertTuanOrder($newpin_id,$order['order_id']);
+							    unset($pin_info);
+							   
+							    $is_pin_success = D('Home/Pin')->checkPinSuccess($newpin_id);
+							    
+							    if($is_pin_success) {
+							        D('Home/Pin')->updatePintuanSuccess($newpin_id);
+							    }
+							}else{
+							    $is_pin_success = D('Home/Pin')->checkPinSuccess($pin_order['pin_id']);
+							    	
+							    if($is_pin_success) {
+							        D('Home/Pin')->updatePintuanSuccess($pin_order['pin_id']);
+							    } 
+							}
+
+						}
+						//检测预售支付
+						if( !empty($order_presale_info) )
+                        {
+                            D('Home/PresaleGoods')->payBackOrder( $order['order_id'] , $transaction_id );
+                        }
+                        //检测是否礼品卡
+                        if( !empty($order_virtualcard_info) )
+                        {
+                            D('Seller/VirtualCard')->payBackOrder( $order['order_id'] );
+                        }
+
+						//发送购买通知
+						D('Home/Weixinnotify')->orderBuy($order['order_id']);
+
+                        //微信交易组件
+                        if( $order['from_type'] == 'tradecomponts' )
+                        {
+                            D('Seller/MpModifyTradeComponts')->orderPay( $order['order_id'], '1' );
+                        }
+						
+					}
+
+				}		
+				
+				
+			}
+			
+			
+			
+			
+			
+					
+			//$order=M('Order')->getByOrderNumAlias($out_trade_no);
+			
+		    
+			
+			
+			return true;
+		}
+	}
+}
+

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 0 - 49
Modules/Lib/Weixin/WeChatEmoji.class.php


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 49 - 0
Modules/Lib/Weixin/WeChatEmoji.class.php.back


+ 1371 - 1371
Modules/Lib/Weixin/WebController.class.php

@@ -1,1372 +1,1372 @@
-<?php
-
-namespace Addons\LuojiangKaoping\Controller;
-use Mp\Controller\AddonsController;
-
-/**
- * 洛江考评微官网后台管理控制器
- * @author 大鱼
- */
-class WebController extends AddonsController {
-	public function test()
-	{
-		//luojiang_achievement 
-		$all_list = M('luojiang_article')->select();
-		Vendor('HyperDown.Parser');
-		$parser = new \Parser();
-		
-		foreach( $all_list as $val )
-		{
-			$content = $parser->makeHtml($val['content']);
-			M('luojiang_article')->where( array('id' => $val['id']) )->save( array('content' => $content) );
-			//id 
-		}
-		var_dump('success');
-		die();
-		//LuojiangKaoping
-	}
-	public function eventreport()
-	{
-		/**
-		Vendor('HyperDown.Parser');
-		$parser = new \Parser();
-		$markdown = $parser->makeHtml("![](http://wx.mnw.cn/Uploads/Pictures/20180411/5acd6d78033a2.jpg)");
-
-
-
-		Vendor('Michelf.Markdown');
-		$html = \Michelf\Markdown::defaultTransform("![](http://wx.mnw.cn/Uploads/Pictures/20180411/5acd6d78033a2.jpg)");
-
-		var_dump($markdown,$html);
-		die();
-		**/
-
-		$custom = array(
-			'options' => array(
-				'lool_to_material' => array(
-					'title' => '处理上报事件',
-					'url' => U('addon/LuojiangKaoping/web/editeventreport', array('id'=>'{id}')),
-					'class' => 'btn btn-primary btn-sm icon-edit'
-				),
-				'edit_fans' => array(
-					'title' => '查看用户信息',
-					'url' => U('Mp/Fans/edit_fans_byid', array('fansid'=>'{fans_id}')),
-					'class' => 'btn btn-primary btn-sm icon-edit'
-				)
-			)
-		);
-		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
-			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
-			 ->addCrumb('事件上报', '', 'active')
-			 ->setModel('luojiang_eventreport')
-			 ->setListOrder('addtime desc')
-			 ->setListMap(array('mpid'=>get_mpid()))
-             ->setTip('<p id="msg_flush">暂无新消息</p>')
-             ->setListSearch(array('nickname' => '会员名称'))
-			 ->addListItem('fans_id', '会员名称', 'callback', array('callback_name'=>'get_fans_name'))
-			 ->addListItem('event_type', '事件类型', 'enum', array('options'=>array('井盖缺失'=>'井盖缺失','道路破损'=>'道路破损','道路淘空'=>'道路淘空','陈年垃圾'=>'陈年垃圾','卫生死角'=>'卫生死角','公共设施'=>'公共设施','市容环境'=>'市容环境','其他情况'=>'其他情况')))
-			 ->addListItem('descript', '事件描述')
-			 ->addListItem('image_list', '图片列表', 'callback', array('callback_name'=>'get_images_str'))
-			 ->addListItem('video_file', '视频', 'callback', array('callback_name'=>'get_video_str'))
-			 ->addListItem('jiangli', '奖励')
-			 ->addListItem('id', '位置', 'callback', array('callback_name'=>'get_message_content'))
-			 ->addListItem('addtime', '创建时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
-			 ->addListItem('reply_info', '处理结果', '', array('placeholder'=>'<font color="red">未处理</font>'))
-			 ->addListItem('id', '操作', 'custom', $custom)
-             ->addButton('导出', U('addon/LuojiangKaoping/web/loadexcel'), 'btn btn-primary')
-             ->common_lists();
-			echo '<script src="/Public/Mp/js/checkflush.js"></script>';
-			echo "<style>.table-striped > tbody > tr:nth-child(odd) > td, .table-striped > tbody > tr:nth-child(odd) > th{border-top:1px solid #000; ;border-bottom:1px solid #000;}</style>";
-
-	}
-	public function get_message_content($id) {
-		$map['id'] = $id;
-		$map['mpid'] = get_mpid();
-		$message = M('luojiang_eventreport')->where($map)->find();
-		if(!empty($message['location_addr'])){
-			return $message['location_addr'].'<br/><button type="button" class="btn btn-sm btn-success"  onclick="lookMap('.$message['lat'].','.$message['lng'].')">查看【位置】</button>';
-		}else{
-			return "未提供";
-		}
-	}
-
-	public function downfile()
-	{
-		//.jpg  mp4
-		//$mp_message_info['msgtype'] == 'video'
-		$file_url = urldecode( I('get.file_url') );
-		$type = urldecode( I('get.type') );
-
-		$file_url = str_replace('/Uploads/','Uploads/',$file_url);
-		$file_name = $file_url.'.'.$type;
-
-		$file_sub_path= "/data/web/wx.mnw.cn/";
-		$file_path=$file_sub_path.$file_name;
-
-		$filectime = filectime($file_path);
-
-		if( strpos($file_name,'jpg') !== false )
-		{
-			$img_arrs = explode('.', $file_name);
-			$file_name = '微信图片_'.date('Ymd',$filectime).'_'.$filectime.'.'.$img_arrs[1];
-		}
-		else if( strpos($file_name,'png') !== false  ){
-			$img_arrs = explode('.', $file_name);
-			$file_name = '微信图片_'.date('Ymd',$filectime).'_'.$filectime.'.'.$img_arrs[1];
-		}
-		else if( strpos($file_name,'gif') !== false  ){
-			$img_arrs = explode('.', $file_name);
-			$file_name = '微信图片_'.date('Ymd',$filectime).'_'.$filectime.'.'.$img_arrs[1];
-		}
-		else if( strpos($file_name,'jpeg') !== false  ){
-			$img_arrs = explode('.', $file_name);
-			$file_name = '微信图片_'.date('Ymd',$filectime).'_'.$filectime.'.'.$img_arrs[1];
-		}
-		else if( strpos($file_name,'mp4') !== false  ){
-			$img_arrs = explode('.', $file_name);
-			$file_name = '微信视频_'.date('Ymd',$filectime).'_'.$filectime.'.'.$img_arrs[1];
-		}
-		else if($mp_message_info['msgtype'] == 'voice' ){
-			$img_arrs = explode('.', $file_name);
-			$file_name = '微信语音_'.date('Ymd',$filectime).'_'.$filectime.'.'.$img_arrs[1];
-		}
-
-		$fp=fopen($file_path,"r");
-        $file_size=filesize($file_path);
-
-		//var_dump($file_size);die();
-        //下载文件需要用到的头
-        Header("Content-type: application/octet-stream");
-        Header("Accept-Ranges: bytes");
-        Header("Accept-Length:".$file_size);
-        Header("Content-Disposition: attachment; filename=".$file_name);
-        $buffer=1024;
-        $file_count=0;
-        //向浏览器返回数据
-        while(!feof($fp) && $file_count<$file_size){
-            $file_con=fread($fp,$buffer);
-            $file_count+=$buffer;
-            echo $file_con;
-        }
-        fclose($fp);
-
-		echo $file_url;
-		die();
-
-	}
-	/**
-     * 获取视频
-     * @author lyf
-     */
-    public function get_video_str($video_file)
-    {
-        if(empty($video_file))
-        {
-            return '暂无';
-        }else{
-            return '<button type="button" class="btn btn-sm btn-warning icon-video" data-src="'.$video_file.'" onclick="lookVideo(this)">查看视频</button><a href="'.U('addon/HuianKaoping/web/downfile', array('type' =>'mp4', 'file_url' => urlencode($video_file) )).'" title="点击下载视频" target=_blank">【下载】</a>';
-        }
-    }
-	/*
-     * 导出
-     */
-    public function loadexcel()
-    {
-        header("content-type:text/html; charset=uft-8");
-
-        if(IS_POST)
-        {
-            //date_added_begin:2017-08-02 0:00:00
-            //date_added_end:2017-08-19 0:00:00
-            $data = I('post.');
-            $where = array();
-
-            if(!empty($data['date_added_begin']))
-            {
-                $where['addtime'] = array('gt',strtotime($data['date_added_begin']) );
-            }
-            if(!empty($data['date_added_end']))
-            {
-                $where['addtime'] = array('lt',strtotime($data['date_added_end']) );
-            }
-
-
-
-            $s_time = strtotime($data['date_added_begin']);
-            $e_time = strtotime($data['date_added_end']);
-
-
-            if($s_time && $e_time)
-            {
-                $where['addtime'] = array('between',array($s_time,$e_time));
-            }
-
-
-            $list = M('luojiang_eventreport')->where($where)->order('id desc')->select();
-
-            //$need_data = array( array('order_sn'=>1,'get_image'=>'http://wx.mnw.cn/Uploads/Pictures/2/2017-08-07/2_oA7ocv8o0sk-tPmG87fjPD25nQWs_1502095440.jpg'),array('order_sn'=>1,'get_image'=>'http://wx.mnw.cn/Uploads/Pictures/2/2017-08-07/2_oA7ocv8o0sk-tPmG87fjPD25nQWs_1502095440.jpg')  );
-
-            $need_data = array();
-
-            $xlsCell  = array(
-                array('id','序号'),
-                array('addtime','日期'),
-                array('fans_id','微信名'),
-				array('mobile','联系人电话'),
-				array('jifen','积分'),
-
-                array('descript','事件描述'),
-                array('image_list','图否'),
-				array('jiangli','奖励'),
-                array('is_reply','反馈情况'),
-                array('reply_info','反馈内容'),
-                array('video_file','视频')
-
-                /*
-
-                array('contact_tel','联系电话'),
-                array('jifen','积分'),
-                array('nickname','微信名'),
-                array('content','问题描述'),
-                array('get_img','图否'),
-                array('fankui','反馈情况'),
-                array('fankui_tu','反馈图片'),
-                */
-            );
-            $i = 1;
-            foreach($list as $val)
-            {
-                $tmp_data = array();
-                $tmp_data['id'] = $i;
-                $tmp_data['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
-				//openid
-                $mp_fans = M('mp_fans')->field('nickname')->where( array('id' => $val['fans_id']) )->find();
-                $tmp_data['fans_id'] = $mp_fans['nickname'];
-				$tmp_data['mobile'] = $mp_fans['mobile'];
-
-				if(  empty($val['reply_info']) ){
-                    $tmp_data['jifen'] = 0;
-                }else{
-                    $tmp_data['jifen'] = 2;
-                }
-
-
-                $tmp_data['jiangli'] = $val['jiangli'];
-                //$tmp_data['title'] = $val['title'];
-                $tmp_data['descript'] = $val['descript'];
-                if(  empty($val['reply_info']) ){
-                    $tmp_data['is_reply'] = '否';
-                }else{
-                    $tmp_data['is_reply'] = '是';
-                }
-                $tmp_data['reply_info'] = $val['reply_info'];
-                if(empty($val['video_file']))
-                {
-                    $tmp_data['video_file'] ='否';
-
-                }else{
-					$tmp_data['video_file'] ='是';
-                    //$tmp_data['video_file'] ='http://'.$_SERVER['SERVER_NAME'].str_replace('./','',$val['video_file']);
-                }
-
-
-
-                //http://wx.mnw.cn/Uploads/Pictures/2/2017-08-07/2_oA7ocv8o0sk-tPmG87fjPD25nQWs_1502095440.jpg
-                if(!empty($val['image_list']))
-                {
-                    $img_arr = explode(',',$val['image_list']);
-                    if($val['image_list'] == ',undefined/undefined' || $val['image_list'] == 'undefined/undefined')
-                    {
-                        $img_url = '';
-						$img_urls = array();
-                    }else{
-						$img_urls = explode(',', $val['image_list']);
-
-						foreach($img_urls as $kk => $vv)
-						{
-							$vv = str_replace('./','/',$vv );
-
-							$vv = '/data/web/wx.mnw.cn'.$vv;
-							$img_urls[$kk] = $vv;
-						}
-
-                        //$img_url = str_replace('./','http://'.$_SERVER['SERVER_NAME'],$val['image_list']);
-                    }
-                    $tmp_data['image_list'] = $img_urls;
-                }
-                $i++;
-                $need_data[] = $tmp_data;
-            }
-            $expTitle = date('Y-m-d H:i:s');
-
-
-            export_excel($expTitle,$xlsCell,$need_data);
-
-        }
-        $this->display();
-    }
-	public function editeventreport()
-	{
-
-		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
-		 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
-		 ->addCrumb('处理上报事件', '', 'active')
-
-		 ->setModel('luojiang_eventreport')
-		 ->addFormField('jiangli', '上报奖励', 'text')
-		 ->addFormField('reply_info', '处理意见', 'text')
-
-		 ->setFormData( M('luojiang_eventreport')->find(I('get.id')) )
-		 ->setEditMap( array('id'=>I('get.id')) )
-		 ->setEditSuccessUrl( U('addon/LuojiangKaoping/web/eventreport') )
-		 ->common_edit();
-	}
-	public function opinionsuggestion()
-	{
-		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
-			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
-			 ->addCrumb('意见建议', '', 'active')
-			 ->setModel('luojiang_opinionsuggestion')
-			 ->setListOrder('addtime desc')
-			 ->setListMap(array('mpid'=>get_mpid()))
-			 ->addListItem('fans_id', '会员名称', 'callback', array('callback_name'=>'get_fans_name'))
-			 ->addListItem('opinion_name', '建议人姓名')
-			 ->addListItem('contact', '建议人联系电话')
-			 ->addListItem('email', '邮箱')
-			 ->addListItem('title', '建议标题')
-			 ->addListItem('content', '建议内容')
-			 ->addListItem('image_list', '图片列表', 'callback', array('callback_name'=>'get_images_str'))
-			 ->addListItem('reply_method', '回复方式', 'enum', array('options'=>array('1'=>'网上',2=>'电话',3=>'当面')))
-			 //->addListItem('is_reply', '是否回复', 'enum', array('options'=>array(0=>'未回复',1=>'已回复')))
-			 ->addListItem('addtime', '创建时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
-			->addListItem('id', '操作', 'custom', array('options'=>array('edit_eventreport'=>array('处理意见建议', U('addon/LuojiangKaoping/web/editopinionsuggestion', array('id'=>'{id}')),'btn btn-primary btn-sm icon-edit',''))))
-			//->addListItem('id', '操作', 'custom', array('options'=>array('edit_fans'=>array('编辑粉丝资料', U('Mp/Fans/edit_fans', array('openid'=>'{openid}')),'btn btn-primary btn-sm icon-edit',''))))
-		     ->common_lists();
-	}
-	public function editopinionsuggestion()
-	{
-		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
-		 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
-		 ->addCrumb('处理意见建议', '', 'active')
-
-		 ->setModel('luojiang_opinionsuggestion')
-		 ->addFormField('reply_info', '处理意见', 'text')
-
-		 ->setFormData( M('luojiang_opinionsuggestion')->find(I('get.id')) )
-		 ->setEditMap( array('id'=>I('get.id')) )
-		 ->setEditSuccessUrl( U('addon/LuojiangKaoping/web/opinionsuggestion') )
-		 ->common_edit();
-
-	}
-	public function newsnenter_two()
-	{
-		$options = array(
-			'edit_fans'=>array('编辑', U('addon/LuojiangKaoping/web/editarticle', array('id'=>'{id}') )
-			,'btn btn-primary btn-sm icon-edit',''),
-			'delete' =>	array(
-				'title' => '删除',
-				'url' => U('addon/LuojiangKaoping/web/deletearticle', array('id'=>'{id}')),
-				'class' => 'btn btn-danger btn-sm icon-delete'
-			)
-		);
-		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
-			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
-			 ->addCrumb('新闻中心', '', 'active')
-			 ->setModel('luojiang_article')
-			 ->setListMap(array('type'=>2))
-			 ->setListOrder('addtime desc')
-
-			 ->addListItem('title', '标题')
-			// ->addListItem('logo', '图片', 'image', array('attr'=>'width=50 height=50','placeholder'=>__ROOT__ . '/Public/Admin/img/noname.jpg'))
-			 ->addListItem('cate_id', '所属分类', 'callback',array('callback_name'=>'get_cate_name'))
-			 ->addListItem('sendtime', '发布时间')
-			 ->addListItem('addtime', '创建时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
-			 ->addListItem('id', '操作', 'custom', array('options'=>$options))
-			 //->addButton('新增文章分类', U('addon/HuianKaoping/web/addarticlecate'), 'btn btn-primary')
-			 ->addButton('新增文章', U('addon/LuojiangKaoping/web/addarticle_two'), 'btn btn-primary')
-			 ->common_lists();
-	}
-	public function newsnenter()
-	{
-		$options = array(
-			'edit_fans'=>array('编辑', U('addon/LuojiangKaoping/web/editarticle', array('id'=>'{id}') )
-			,'btn btn-primary btn-sm icon-edit',''),
-			'delete' =>	array(
-				'title' => '删除',
-				'url' => U('addon/LuojiangKaoping/web/deletearticle', array('id'=>'{id}')),
-				'class' => 'btn btn-danger btn-sm icon-delete'
-			)
-		);
-		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
-			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
-			 ->addCrumb('新闻中心', '', 'active')
-			 ->setModel('luojiang_article')
-			 ->setListMap(array('type'=>1))
-			 ->setListOrder('addtime desc')
-
-			 ->addListItem('title', '标题')
-			 ->addListItem('logo', '图片', 'image', array('attr'=>'width=50 height=50','placeholder'=>__ROOT__ . '/Public/Admin/img/noname.jpg'))
-			 ->addListItem('cate_id', '所属分类', 'callback',array('callback_name'=>'get_cate_name'))
-			 ->addListItem('sendtime', '发布时间')
-			 ->addListItem('addtime', '创建时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
-			 ->addListItem('id', '操作', 'custom', array('options'=>$options))
-			 //->addButton('新增文章分类', U('addon/HuianKaoping/web/addarticlecate'), 'btn btn-primary')
-			 ->addButton('新增文章', U('addon/LuojiangKaoping/web/addarticle'), 'btn btn-primary')
-			 ->common_lists();
-	}
-
-	/**
-	 * 删除关键词回复
-	 * @author 艾逗笔<765532665@qq.com>
-	 */
-	public function deletearticle() {
-
-		M('luojiang_article')->where( array('id' =>I('get.id') ) )->delete();
-		$this->success('删除成功');
-
-	}
-	public function votecenter()
-	{
-		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
-			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
-			 ->addCrumb('投票专区', '', 'active')
-			 ->setModel('vote')
-
-			 ->addListItem('title', '标题')
-			 ->addListItem('begin_time', '开始时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
-			 ->addListItem('end_time', '结束时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
-			 ->addListItem('addtime', '添加时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
-
-			 ->addListItem('vote_id', '操作', 'custom', array('options'=>array(
-				'edit_fans'=>array('编辑', U('addon/LuojiangKaoping/web/editvote', array('vote_id'=>'{vote_id}') ) ,'btn btn-primary btn-sm icon-edit',''),
-				'add_votesubject'=>array('添加投票选项', U('addon/LuojiangKaoping/web/addvotesubject', array('vote_id'=>'{vote_id}') ) ,'btn btn-primary btn-sm icon-edit',''),
-			 )))
-		     ->addButton('新增投票', U('addon/LuojiangKaoping/web/addvote'), 'btn btn-primary')
-			 ->common_lists();
-	}
-	public function addvote()
-	{
-		if( IS_POST )
-		{
-			$data = I('post.');
-			$vote_data = array();
-			$vote_data['mpid'] = get_mpid();
-			$vote_data['title'] = $data['name'];
-			$vote_data['begin_time'] = strtotime( $data['date_added_begin'] );
-			$vote_data['end_time'] = strtotime( $data['date_added_end'] );
-			$vote_data['addtime'] = time();
-			M('vote')->add($vote_data);
-			$this->success('添加投票成功', U('addon/LuojiangKaoping/web/votecenter'));
-			die();
-		}
-
-		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
-			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
-			 ->addCrumb('新闻中心', '', 'active')
-			 ->display();
-	}
-	public function addvotesubject()
-	{
-		$vote_id = I('get.vote_id');
-		$this->vote_id = $vote_id;
-
-		if( IS_POST )
-		{
-			$data = I('post.');
-
-			if( isset($data['edit_votesubject']) )
-			{
-				$has_key = array();
-				$del_key = array();
-
-				foreach( $data['attr_title'] as $key => $val)
-				{
-					$has_key[] = $key;
-				}
-				$vote_sub_all =  M('vote_subject')->where( array('vote_id' => $data['vote_id']) )->select();
-
-				foreach($vote_sub_all as $vote_sub)
-				{
-					if( !in_array($vote_sub['sub_id'],$has_key ) )
-					{
-						$del_key[] = $vote_sub['sub_id'];
-					}
-				}
-				//删除多余键
-				if( !empty($del_key) )
-				{
-					M('vote_subject')->where( array('sub_id' => array('in', $del_key ) ) )->delete();
-					//删除投票记录
-					M('vote_record')->where( array('sub_id' => array('in', $del_key ) ) )->delete();
-				}
-				//开始更新和新增选项
-
-				foreach($data['attr_title'] as $key => $val)
-				{
-					if( strpos($key, 'new') !== false )
-					{
-						//新增的模块
-						$tmp_vote_subject = array();
-						$tmp_vote_subject['vote_id'] = $data['vote_id'];
-						$tmp_vote_subject['title'] = $val;
-						$tmp_vote_subject['type'] = $data['type'][$key];
-						$tmp_vote_subject['addtime'] = time();
-						M('vote_subject')->add($tmp_vote_subject);
-						$sub_id = M('vote_subject')->getLastInsID();
-
-						$extra = $data['extra'][$key];
-						$extra_arr = explode('|', $extra);
-						foreach($extra_arr as $vv)
-						{
-							$xun_data = array();
-							$xun_data['sub_id'] = $sub_id;
-							$xun_data['titile'] = $vv;
-							$xun_data['addtime'] = time();
-							M('vote_xuan')->add($xun_data);
-						}
-					} else {
-						//需要更新板块
-						$tmp_vote_subject = array();
-						$tmp_vote_subject['title'] = $val;
-						$tmp_vote_subject['type'] = $data['type'][$key];
-						M('vote_subject')->where( array('sub_id' =>$key ) ) ->save($tmp_vote_subject);
-
-						//更新子内容
-						//先判断原来有几个
-						$vote_xuan_list = M('vote_xuan')->where( array('sub_id' => $key) )->order('xu_id asc')->select();
-
-						$extra = array();
-						$extra = $data['extra'][$key];
-						$extra_arr = explode('|', $extra);
-						foreach($vote_xuan_list as $xun_vo)
-						{
-							if( !empty($extra_arr) )
-							{
-								$tmp_xun = array_shift( $extra_arr );
-								M('vote_xuan')->where( array('xu_id' => $xun_vo['xu_id']) )->save( array('titile' => $tmp_xun) );
-							}else {
-								//需要删除的
-								M('vote_xuan')->where( array('xu_id' => $xun_vo['xu_id']) )->delete();
-							}
-						}
-						//判断是否可以新增
-						if( !empty($extra_arr) )
-						{
-							foreach($extra_arr as $vv)
-							{
-								$xun_data = array();
-								$xun_data['sub_id'] = $key;
-								$xun_data['titile'] = $vv;
-								$xun_data['addtime'] = time();
-								M('vote_xuan')->add($xun_data);
-							}
-						}
-					}
-				}
-				$this->success('编辑投票选项成功', U('addon/HuianKaoping/web/votecenter'));
-				die();
-			}
-
-
-
-			foreach($data['attr_title'] as $key => $val)
-			{
-				if( !empty($val) )
-				{
-					$tmp_vote_subject = array();
-					$tmp_vote_subject['vote_id'] = $data['vote_id'];
-					$tmp_vote_subject['title'] = $val;
-					$tmp_vote_subject['type'] = $data['type'][$key];
-					$tmp_vote_subject['addtime'] = time();
-					M('vote_subject')->add($tmp_vote_subject);
-					$sub_id = M('vote_subject')->getLastInsID();
-
-					$extra = $data['extra'][$key];
-					//vote_xuan
-					$extra_arr = explode('|', $extra);
-					foreach($extra_arr as $vv)
-					{
-						$xun_data = array();
-						$xun_data['sub_id'] = $sub_id;
-						$xun_data['titile'] = $vv;
-						$xun_data['addtime'] = time();
-						M('vote_xuan')->add($xun_data);
-					}
-				}
-			}
-
-			$this->success('新增投票选项成功', U('addon/HuianKaoping/web/votecenter'));
-			die();
-
-		}
-
-		$vote_subject = M('vote_subject')->where( array('vote_id' => $vote_id) )->order('sub_id asc')->select();
-
-		if( !empty($vote_subject) )
-		{
-			foreach( $vote_subject as $key=> $val )
-			{
-				$vote_xuan_list = M('vote_xuan')->where( array('sub_id' => $val['sub_id']) )->order('xu_id asc')->select();
-				$xun_arr = array();
-
-				foreach( $vote_xuan_list as $vv )
-				{
-					$xun_arr[] = $vv['titile'];
-				}
-
-				$val['xun_title'] =  implode('|', $xun_arr);
-				$val['vote_xuan_list'] = $vote_xuan_list;
-				$vote_subject[$key] = $val;
-			}
-
-			$this->vote_subject = $vote_subject;
-
-
-
-			$this->addCrumb('洛江考评微官网', U('addon/HuianKaoping/index'), '')
-			 ->addCrumb('业务导航', U('addon/HuianKaoping/web/eventreport'), '')
-			 ->addCrumb('新闻中心', '', 'active')
-			 ->display('editvotesubject');
-		} else {
-			$this->addCrumb('洛江考评微官网', U('addon/HuianKaoping/index'), '')
-			 ->addCrumb('业务导航', U('addon/HuianKaoping/web/eventreport'), '')
-			 ->addCrumb('新闻中心', '', 'active')
-			 ->display();
-		}
-	}
-	public function loadachievement()
-	{
-        $type = I('type');
-		if( IS_POST )
-		{
-            set_time_limit(0);
-			  if(isset($_FILES["file"]) && ($_FILES["file"]["error"] == 0)){
-
-
-				  $excel_dir = './Uploads/Pictures/' . date('Y-m-d') . '/';
-					if (!file_exists($excel_dir)) {
-						$dirs = explode('/', $excel_dir);
-						$dir = $dirs[0] . '/';
-						for ($i=1, $j=count($dirs)-1; $i<$j; $i++) {
-							$dir .= $dirs[$i] . '/';
-							if (!is_dir($dir)) {
-								mkdir($dir, 0777);
-							}
-						}
-					}
-
-				  $extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
-
-
-				  $path = $excel_dir.'/'.md5($_FILES['file']['name'].mt_rand(1, 999)).'.'.$extension;
-				  $rs = move_uploaded_file($_FILES["file"]["tmp_name"],$path);
-
-
-
-				$file = $path;
-				$type = pathinfo($file);
-				$type = strtolower($type["extension"]);
-				$type=$type==='csv' ? $type : 'Excel5';
-				ini_set('max_execution_time', '0');
-				vendor("PHPExcel.PHPExcel");
-				// 判断使用哪种格式
-				$objReader = \PHPExcel_IOFactory::createReader($type);
-				$objPHPExcel = $objReader->load($file);
-				$sheet = $objPHPExcel->getSheet(0);
-				// 取得总行数
-				$highestRow = $sheet->getHighestRow();
-				// 取得总列数
-				$highestColumn = $sheet->getHighestColumn();
-				//循环读取excel文件,读取一条,插入一条
-				$data=array();
-				//从第一行开始读取数据
-				for($j=1;$j<=$highestRow;$j++){
-					if($j <=2) {
-						continue;
-					}
-					//从A列读取数据
-					for($k='A';$k<=$highestColumn;$k++){
-						// 读取单元格
-						$data[$j][]=$objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue();
-					}
-				}
-
-				$result = $data;
-				$get_data = array();
-				if(!empty($result)) {
-					foreach($result as $key => $val){
-
-						//array(5) { [0]=> string(6) "村庄" [1]=> string(18) "2017-8月上半月"
-						//[2]=> string(9) "小岞镇" [3]=> string(9) "新桥村" [4]=> float(92.5) }
-						if(empty($val[0]))
-						{
-							continue;
-						}
-						//$val[1] = str_replace('上半月','01',$val[1]);
-						//$val[1] = str_replace('下半月','15',$val[1]);
-
-
-
-						//$val[1] = $val[1]->__toString();
-						$val[1] .= ' 00:00:00';
-						//$val[1] = str_replace('年','-',$val[1]);
-						//$val[1] = str_replace('月','',$val[1]);
-
-						$need_data = array();
-						$need_data['name'] = $val[0];
-						$need_data['kao_time'] = strtotime($val[1]);
-						$need_data['zeren_danwei'] = $val[2];
-						$need_data['stree'] = $val[3];
-						$need_data['kaoping_dian'] = '';
-						$need_data['chengji'] = $val[4];
-                        if(I('type') == 2)
-                        {
-                            $need_data['type'] = 2;
-                        }else{
-                            $need_data['type'] = 1;
-                        }
-						if(empty($need_data['stree']))
-                        {
-                            $need_data['stree'] = '';
-                        }
-						$need_data['paiming'] = 0;
-						$need_data['addtime'] = time();
-						M('luojiang_achievement')->add($need_data);
-					}
-                    if(I('type') == 2){
-                        $this->success('导入成绩成功', U('addon/LuojiangKaoping/web/achievementmanage_two'));
-                    }else{
-                        $this->success('导入成绩成功', U('addon/LuojiangKaoping/web/achievementmanage'));
-                    }
-					die();
-				}
-			  }
-		}
-        $this->assign('type', $type);
-		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
-			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
-			 ->addCrumb('成绩管理', '', 'active')
-			 ->display();
-	}
-
-	public function editvote()
-	{
-		// /vote_id/1
-		$vote_id = I('get.vote_id');
-
-		if( IS_POST )
-		{
-			$data = I('post.');
-
-			$data = I('post.');
-			$vote_data = array();
-			$vote_data['mpid'] = get_mpid();
-			$vote_data['title'] = $data['name'];
-			$vote_data['begin_time'] = strtotime( $data['date_added_begin'] );
-			$vote_data['end_time'] = strtotime( $data['date_added_end'] );
-
-			M('vote')->where( array('vote_id' => $data['vote_id']) )->save($vote_data);
-
-			$this->success('编辑投票成功', U('addon/HuianKaoping/web/votecenter'));
-			die();
-		}
-
-		$vote = M('vote')->where( array('vote_id' => $vote_id) )->find();
-
-		$this->vote = $vote;
-
-		$this->addCrumb('洛江考评微官网', U('addon/HuianKaoping/index'), '')
-			 ->addCrumb('业务导航', U('addon/HuianKaoping/web/eventreport'), '')
-			 ->addCrumb('新闻中心', '', 'active')
-			 ->display('addvote');
-	}
-
-	public function editachievement()
-	{
-		$id = I('get.id');
-		$type = I('get.type');
-		if( IS_POST )
-		{
-			$data = I('post.');
-
-
-			$vote_data = array();
-			$vote_data['name'] = $data['name'];
-			$vote_data['kao_time'] = strtotime( $data['kao_time'] );
-			$vote_data['zeren_danwei'] = $data['zeren_danwei'];
-			$vote_data['stree'] = $data['stree'];
-			$vote_data['content'] = ($data['content']);
-			//$vote_data['kaoping_dian'] = $data['kaoping_dian'];
-			$vote_data['chengji'] = $data['chengji'];
-			//$vote_data['paiming'] = $data['paiming'];
-			M('luojiang_achievement')->where( array('id' => $id) )->save($vote_data);
-
-            if($data['type'] == 2)
-            {
-                $this->success('编辑成功', U('addon/LuojiangKaoping/web/achievementmanage_two'));
-            }else{
-                $this->success('编辑成功', U('addon/LuojiangKaoping/web/achievementmanage'));
-            }
-
-			die();
-		}
-
-        if($type == 2)
-        {
-            $this->setEditSuccessUrl( U('addon/LuojiangKaoping/web/achievementmanage_two') );
-        }else{
-            $this->setEditSuccessUrl( U('addon/LuojiangKaoping/web/achievementmanage') );
-        }
-        $this->assign('type', $type);
-		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
-		 ->addCrumb('成绩管理', U('addon/LuojiangKaoping/web/achievementmanage'), '')
-		 ->addCrumb('成绩管理', '', 'active')
-		 ->setModel('luojiang_achievement')
-		 ->addFormField('name', '类别', 'text')
-		 ->addFormField('kao_time', '考评时间', 'date')
-		 ->addFormField('zeren_danwei', '街道(乡镇)/责任单位', 'text')
-		 ->addFormField('stree', '抽评点', 'text')
-		 ->addFormField('content', '内容', 'editor')
-		 //->addFormField('kaoping_dian', '考评点', 'text')
-		 ->addFormField('chengji', '成绩', 'text')
-		 //->addFormField('paiming', '排名', 'text')
-
-		 ->setEditMap( array('id'=>I('get.id')))
-		 ->common_edit();
-
-	}
-	public function get_cate_name($cate_id)
-	{
-		$category_info =  M('luojiang_articlecategory')->where( array('id' => $cate_id) )->find();
-		return $category_info['name'];
-	}
-
-	public function editarticle()
-	{
-		$cateinfos = M('luojiang_articlecategory')->where( array('pid' => 0) )->select();
-
-		$cate_arr = array();
-		foreach($cateinfos as $val)
-		{
-			$cate_arr[$val[id]] = $val['name'];
-		}
-
-		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
-		 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
-		 ->addCrumb('编辑文章', '', 'active')
-		 ->setModel('huian_article')
-		 ->addFormField('title', '标题', 'text')
-		 ->addFormField('link', '外链', 'text')
-		 ->addFormField('logo', '图片', 'image')
-		 ->addFormField('sendtime', '发布时间', 'time')
-		 ->addFormField('cate_id', '所属分类', 'select', array('options'=>$cate_arr))
-		 ->addFormField('content', '内容', 'editor')
-		 ->setValidate(array(
-				array('name', 'require', '标题不能为空')//,
-				//array('logo', 'require', '请上传图片')
-		   ))
-		 ->setFormData( M('luojiang_article')->find(I('get.id')) )
-		 ->setEditMap( array('id'=>I('get.id')) )
-		 ->setEditSuccessUrl( U('addon/LuojiangKaoping/web/newsnenter') )
-		 ->common_edit();
-
-
-	}
-	public function addarticlecate()
-	{
-		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
-			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
-			 ->addCrumb('添加文章分类', '', 'active')
-			 ->setModel('luojiang_articlecategory')
-			 ->addFormField('name', '名称', 'text')
-			 //->addFormField('type', '类型', 'radio', array('options'=>array(1=>'普通订阅号',2=>'认证订阅号',3=>'普通服务号',4=>'认证服务号',5=>'测试号'),'value'=>4,'is_must'=>1))
-			// ->addFormField('pid', '原始ID', 'text', array('is_must'=>1))
-			 //->addFormField('mp_number', '微信号', 'text')
-			// ->addFormField('appid', 'APPID', 'text')
-			// ->addFormField('appsecret', 'APPSECRET', 'text')
-			 //->addFormField('headimg', '头像', 'image')
-			 //->addFormField('qrcode', '二维码', 'image')
-			 ->setValidate(array(
-					array('name', 'require', '名称不能为空'),
-			   ))
-			 ->setAuto(array(
-					array('pid', '0'),
-					array('addtime', 'time', 1, 'function')
-			 ))
-			 ->setAddSuccessUrl( U('addon/LuojiangKaoping/web/newsnenter') )
-			 ->common_add();
-	}
-
-	public function addarticle_two()
-	{
-		$cateinfos = M('luojiang_articlecategory')->where( array('pid' => 0) )->select();
-
-		$cate_arr = array();
-		foreach($cateinfos as $val)
-		{
-			$cate_arr[$val[id]] = $val['name'];
-		}
-
-		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
-			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
-			 ->addCrumb('添加文章', '', 'active')
-			 ->setModel('luojiang_article')
-			 ->addFormField('title', '标题', 'text')
-			 ->addFormField('type', '1', 'hidden',array('value'=>2))
-			 //->addFormField('link', '外链', 'text')
-			 //->addFormField('logo', '图片', 'image')
-			 ->addFormField('sendtime', '发布时间', 'time')
-			 ->addFormField('cate_id', '1', 'hidden',array('value'=>1))
-			 //->addFormField('cate_id', '所属分类', 'select', array('options'=>$cate_arr))
-			 ->addFormField('content', '内容', 'editor')
-			 ->setValidate(array(
-					array('name', 'require', '标题不能为空'),
-					//array('logo', 'require', '请上传图片')
-			   ))
-			 ->setAuto(array(
-					array('addtime', 'time', 1, 'function')
-			   ))
-			 ->setAddSuccessUrl( U('addon/LuojiangKaoping/web/newsnenter_two') )
-			 ->common_add();
-	}
-
-	public function addarticle()
-	{
-		$cateinfos = M('luojiang_articlecategory')->where( array('pid' => 0) )->select();
-
-		$cate_arr = array();
-		foreach($cateinfos as $val)
-		{
-			$cate_arr[$val[id]] = $val['name'];
-		}
-
-		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
-			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
-			 ->addCrumb('添加文章', '', 'active')
-			 ->setModel('luojiang_article')
-			 ->addFormField('title', '标题', 'text')
-			 ->addFormField('type', '1', 'hidden',array('value'=>1))
-			 ->addFormField('link', '外链', 'text')
-			 ->addFormField('logo', '图片', 'image')
-			 ->addFormField('sendtime', '发布时间', 'time')
-			 ->addFormField('cate_id', '所属分类', 'select', array('options'=>$cate_arr))
-			 ->addFormField('content', '内容', 'editor')
-			 ->setValidate(array(
-					array('name', 'require', '标题不能为空')//,
-					//array('logo', 'require', '请上传图片')
-			   ))
-			 ->setAuto(array(
-					array('addtime', 'time', 1, 'function')
-			   ))
-			 ->setAddSuccessUrl( U('addon/LuojiangKaoping/web/newsnenter') )
-			 ->common_add();
-	}
-	public function achievementmanage()
-	{
-		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
-			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
-			 ->addCrumb('乡镇成绩管理', '', 'active')
-			 ->setModel('luojiang_achievement')
-			 ->setListOrder('addtime desc')
-			 ->addListItem('name', '类别')
-            //->addListItem('kao_time', '考评时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
-             ->setListMap(array('type'=>1))
-             ->addListItem('kao_time', '考评时间', 'callback', array('callback_name'=>'get_date_hui'))
-			 ->addListItem('zeren_danwei', '街道办事处')
-			 ->addListItem('stree', '抽评点')
-			 //->addListItem('kaoping_dian', '考评点')
-			 ->addListItem('chengji', '成绩')
-			 //->addListItem('paiming', '排名')
-			 ->addListItem('addtime', '添加时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
-			 ->addButton('导入考评成绩', U('addon/LuojiangKaoping/web/loadachievement'), 'btn btn-primary')
-			 ->addListItem('id', '操作', 'custom', array('options'=>array('edit_fans'=>array('编辑成绩', U('addon/LuojiangKaoping/web/editachievement', array('id'=>'{id}','type'=>1)),'btn btn-primary btn-sm icon-edit',''))))
-		     ->common_lists();
-
-		$cjcount = M('luojiang_achievement')->where(array('paiming'=>0,'type'=>1))->count();
-		if($cjcount>0)
-		{
-			$paiming = array();
-			$pagecount = M('luojiang_achievement')->field('kao_time')->where(array('type'=>1))->group('kao_time')->order('kao_time desc')->select();
-			foreach($pagecount as $val)
-			{
-				$data = M('luojiang_achievement')->field('id,chengji')->where(array("kao_time"=>$val['kao_time'],"type"=>1))->order('chengji desc, id asc')->select();
-				$chengji = $data[0]['chengji'];
-				$order = 1;$num = 0;
-				foreach($data as $key=>$subval)
-				{
-					if($key != 0){
-						if($subval["chengji"] < $chengji){
-							$order += 1;
-							$chengji = $subval['chengji'];
-							$order += $num;
-							$num = 0;
-						}
-						else {
-							$num++;
-						}
-					}
-					$paiming[] = array('id'=>$subval["id"],'paiming'=>$order);
-				}
-				krsort($data);
-				$chengji = $data[count($data)-1]['chengji'];
-				$order = -5;$num = 0;
-				foreach($data as $key=>$subval)
-				{
-					if($key != count($data)-1){
-						if($subval["chengji"] > $chengji){
-							$order += 1;
-							$chengji = $subval['chengji'];
-							$order += $num;
-							$num = 0;
-						}
-						else {
-							$num++;
-						}
-					}
-					if($order == 0) break;
-					$paiming[] = array('id'=>$subval["id"],'paiming'=>$order);
-				}
-			}
-			foreach($paiming as $val)
-			{
-				$data['paiming'] = $val['paiming'];
-				M('luojiang_achievement')->where(array("id"=>$val['id']))->save($data);
-			}
-		}
-	}
-
-	 public function achievementmanage_two()
-    {
-        $this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
-            ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
-            ->addCrumb('部门成绩管理', '', 'active')
-            ->setModel('luojiang_achievement')
-            ->setListOrder('addtime desc')
-            ->setListMap(array('type'=>2))
-            ->addListItem('name', '类别')
-            //->addListItem('kao_time', '考评时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
-            ->addListItem('kao_time', '考评时间', 'callback', array('callback_name'=>'get_date_hui'))
-            ->addListItem('zeren_danwei', '部门')
-            ->addListItem('stree', '考评对象')
-            //->addListItem('kaoping_dian', '考评点')
-            ->addListItem('chengji', '成绩')
-            //->addListItem('paiming', '排名')
-            ->addListItem('addtime', '添加时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
-            ->addButton('导入考评成绩', U('addon/LuojiangKaoping/web/loadachievement',array('type'=>2)), 'btn btn-primary')
-            ->addListItem('id', '操作', 'custom', array('options'=>array('edit_fans'=>array('编辑成绩', U('addon/HuianKaoping/web/editachievement', array('id'=>'{id}','type'=>2)),'btn btn-primary btn-sm icon-edit',''))))
-            ->common_lists();
-
-        $cjcount = M('luojiang_achievement')->where(array('paiming'=>0,'type'=>2))->count();
-        if($cjcount>0)
-        {
-            $paiming = array();
-            $pagecount = M('luojiang_achievement')->field('kao_time')->where(array('type'=>2))->group('kao_time')->order('kao_time desc')->select();
-            foreach($pagecount as $val)
-            {
-                $data = M('luojiang_achievement')->field('id,chengji')->where(array("kao_time"=>$val['kao_time'],'type'=>2))->order('chengji desc, id asc')->select();
-                $chengji = $data[0]['chengji'];
-                $order = 1;$num = 0;
-                foreach($data as $key=>$subval)
-                {
-                    if($key != 0){
-                        if($subval["chengji"] < $chengji){
-                            $order += 1;
-                            $chengji = $subval['chengji'];
-                            $order += $num;
-                            $num = 0;
-                        }
-                        else {
-                            $num++;
-                        }
-                    }
-                    $paiming[] = array('id'=>$subval["id"],'paiming'=>$order);
-                }
-                krsort($data);
-                $chengji = $data[count($data)-1]['chengji'];
-                $order = -5;$num = 0;
-                foreach($data as $key=>$subval)
-                {
-                    if($key != count($data)-1){
-                        if($subval["chengji"] > $chengji){
-                            $order += 1;
-                            $chengji = $subval['chengji'];
-                            $order += $num;
-                            $num = 0;
-                        }
-                        else {
-                            $num++;
-                        }
-                    }
-                    if($order == 0) break;
-                    $paiming[] = array('id'=>$subval["id"],'paiming'=>$order);
-                }
-            }
-            foreach($paiming as $val)
-            {
-                $data['paiming'] = $val['paiming'];
-                M('luojiang_achievement')->where(array("id"=>$val['id']))->save($data);
-            }
-        }
-    }
-
-	public function get_date_hui($kao_time)
-	{
-		$d = date('d',$kao_time);
-		/**
-		if($d == '15')
-		{
-			$kao_time = date('Y-m',$kao_time).'-下半月';
-		} else {
-			$kao_time = date('Y-m',$kao_time).'-上半月';
-
-		}
-		**/
-		$kao_time = date('Y-m-d',$kao_time);
-		return $kao_time;
-	}
-	public function usermanage()
-	{
-
-		//->addListItem('msgid', '消息内容', 'callback', array('callback_name'=>'get_message_content'))
-
-		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
-			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
-			 ->addCrumb('用户管理', '', 'active')
-			 ->setModel('luojiang_eventreport')
-			 ->setListMap(array('mpid'=>get_mpid()))
-			 ->addListItem('fans_id', '会员名称', 'callback', array('callback_name'=>'get_fans_name'))
-			 ->addListItem('event_type', '事件类型', 'enum', array('options'=>array('0'=>'未知',1=>'事件类型1',2=>'事件类型2',3=>'事件类型3')))
-			 ->addListItem('title', '标题')
-			 ->addListItem('descript', '事件描述')
-			 ->addListItem('image_list', '图片列表', 'callback', array('callback_name'=>'get_images_str'))
-			 ->addListItem('is_reply', '是否回复', 'enum', array('options'=>array(0=>'未回复',1=>'已回复')))
-			 ->addListItem('location_addr', '位置', '', array('placeholder'=>'未提供'))
-			 ->addListItem('addtime', '创建时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
-			 ->addListItem('id', '操作', 'custom', array('options'=>array('edit_fans'=>array('编辑粉丝资料', U('Mp/Fans/edit_fans', array('openid'=>'{openid}')),'btn btn-primary btn-sm icon-edit',''))))
-		     ->common_lists();
-	}
-	function get_images_str($image_list)
-	{
-		$image_arr = explode(',', $image_list);
-		$image_str = '';
-		$image_need_arr = array();
-
-		if( !empty($image_arr) )
-		{
-			foreach($image_arr as $img)
-			{
-				$img = str_replace('./Uploads/','/Uploads/',$img);
-				$img = str_replace('//','/',$img);
-				$imgtemp = explode('.',$img);
-				//$thumb_img =  $this->resize($img,100,100);
-				$image_need_arr[] = "<div style='float:left;width:100px;margin-right:5px;'><img src='".$img."' width=100 height=100 'placeholder'= '".__ROOT__ ."/Public/Admin/img/noname.jpg' /><br/>【<a href='".$img."' target='_blank'>预览</a> | <a href='".U('addon/HuianKaoping/web/downfile', array('type' =>$imgtemp[1], 'file_url' => urlencode($img) ))."' target='_blank'>下载】</a></div>";
-			}
-			$image_str = implode(' ', $image_need_arr);
-		}
-		return "<div style='width:220px;'> ".$image_str."</div>";
-
-	}
-	//字符串截取
-function utf8_substr($string, $offset, $length = null) {
-	// generates E_NOTICE
-	// for PHP4 objects, but not PHP5 objects
-	$string = (string)$string;
-	$offset = (int)$offset;
-
-	if (!is_null($length)) {
-		$length = (int)$length;
-	}
-
-	// handle trivial cases
-	if ($length === 0) {
-		return '';
-	}
-
-	if ($offset < 0 && $length < 0 && $length < $offset) {
-		return '';
-	}
-
-	// normalise negative offsets (we could use a tail
-	// anchored pattern, but they are horribly slow!)
-	if ($offset < 0) {
-		$strlen = strlen(utf8_decode($string));
-		$offset = $strlen + $offset;
-
-		if ($offset < 0) {
-			$offset = 0;
-		}
-	}
-
-	$Op = '';
-	$Lp = '';
-
-	// establish a pattern for offset, a
-	// non-captured group equal in length to offset
-	if ($offset > 0) {
-		$Ox = (int)($offset / 65535);
-		$Oy = $offset%65535;
-
-		if ($Ox) {
-			$Op = '(?:.{65535}){' . $Ox . '}';
-		}
-
-		$Op = '^(?:' . $Op . '.{' . $Oy . '})';
-	} else {
-		$Op = '^';
-	}
-
-	// establish a pattern for length
-	if (is_null($length)) {
-		$Lp = '(.*)$';
-	} else {
-		if (!isset($strlen)) {
-			$strlen = strlen(utf8_decode($string));
-		}
-
-		// another trivial case
-		if ($offset > $strlen) {
-			return '';
-		}
-
-		if ($length > 0) {
-			$length = min($strlen - $offset, $length);
-
-			$Lx = (int)($length / 65535);
-			$Ly = $length % 65535;
-
-			// negative length requires a captured group
-			// of length characters
-			if ($Lx) {
-				$Lp = '(?:.{65535}){' . $Lx . '}';
-			}
-
-			$Lp = '(' . $Lp . '.{' . $Ly . '})';
-		} elseif ($length < 0) {
-			if ($length < ($offset - $strlen)) {
-				return '';
-			}
-
-			$Lx = (int)((-$length) / 65535);
-			$Ly = (-$length)%65535;
-
-			// negative length requires ... capture everything
-			// except a group of  -length characters
-			// anchored at the tail-end of the string
-			if ($Lx) {
-				$Lp = '(?:.{65535}){' . $Lx . '}';
-			}
-
-			$Lp = '(.*)(?:' . $Lp . '.{' . $Ly . '})$';
-		}
-	}
-
-	if (!preg_match( '#' . $Op . $Lp . '#us', $string, $match)) {
-		return '';
-	}
-
-	return $match[1];
-
-}
-/**
- * 递归生成目录
- */
-function RecursiveMkdir($path) {
-	if (!file_exists($path)) {
-		$this->RecursiveMkdir(dirname($path));
-		@mkdir($path, 0777);
-	}
-}
-
-
-//字符串长度计算
-function utf8_strlen($string) {
-	return strlen(utf8_decode($string));
-}
-
-function utf8_strrpos($string, $needle, $offset = null) {
-	if (is_null($offset)) {
-		$data = explode($needle, $string);
-
-		if (count($data) > 1) {
-			array_pop($data);
-
-			$string = join($needle, $data);
-
-			return $this->utf8_strlen($string);
-		}
-
-		return false;
-	} else {
-		if (!is_int($offset)) {
-			trigger_error('utf8_strrpos expects parameter 3 to be long', E_USER_WARNING);
-
-			return false;
-		}
-
-		$string = $this->utf8_substr($string, $offset);
-
-		if (false !== ($position = utf8_strrpos($string, $needle))) {
-			return $position + $offset;
-		}
-
-		return false;
-	}
-}
-
-	/**
- * 自动生成新尺寸 的图片
- */
-	function resize($filename, $width, $height) {
-			define(ROOT_PATH,'/data/web/wx.mnw.cn/');
-			///data/web/wx.mnw.cn/Addons/HuianKaoping/Controller
-
-		$image_dir=ROOT_PATH;
-
-
-		if (!is_file($image_dir . $filename)) {
-			return;
-		}
-
-		$extension = pathinfo($filename, PATHINFO_EXTENSION);
-
-		$old_image = $filename;
-		$new_image = 'cache/' . $this->utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
-
-		if (!is_file($image_dir . $new_image) || (filectime($image_dir . $old_image) > filectime($image_dir . $new_image))) {
-			$path = '';
-
-			$directories = explode('/', dirname(str_replace('../', '', $new_image)));
-
-			foreach ($directories as $directory) {
-				$path = $path . '/' . $directory;
-
-				if (!is_dir($image_dir . $path)) {
-					@mkdir($image_dir . $path, 0777);
-				}
-			}
-
-			list($width_orig, $height_orig) = getimagesize($image_dir . $old_image);
-
-			if ($width_orig != $width || $height_orig != $height) {
-				$image = new \Lib\Image($image_dir . $old_image);
-			$image->resize($width, $height);
-				$image->save($image_dir . $new_image);
-			} else {
-				copy($image_dir . $old_image, $image_dir . $new_image);
-			}
-		}
-
-		return 'Uploads/image/' . $new_image;
-
-		}
-
-	public function get_fans_name($fans_id)
-	{
-		$fans_info = M('mp_fans')->where( array('id' => $fans_id) )->find();
-		return $fans_info['nickname'];
-		//return '<a href="'.U('Mp/Fans/edit_fans', array('openid'=>$fans_info['openid'])).'" target="_blank" title="点击查看用户信息">'.$fans_info['nickname'].'</a>';
-	}
-
-}
-
+<?php
+
+namespace Addons\LuojiangKaoping\Controller;
+use Mp\Controller\AddonsController;
+
+/**
+ * 洛江考评微官网后台管理控制器
+ * @author 大鱼
+ */
+class WebController extends AddonsController {
+	public function test()
+	{
+		//luojiang_achievement 
+		$all_list = M('luojiang_article')->select();
+		Vendor('HyperDown.Parser');
+		$parser = new \Parser();
+		
+		foreach( $all_list as $val )
+		{
+			$content = $parser->makeHtml($val['content']);
+			M('luojiang_article')->where( array('id' => $val['id']) )->save( array('content' => $content) );
+			//id 
+		}
+		var_dump('success');
+		die();
+		//LuojiangKaoping
+	}
+	public function eventreport()
+	{
+		/**
+		Vendor('HyperDown.Parser');
+		$parser = new \Parser();
+		$markdown = $parser->makeHtml("![](http://wx.mnw.cn/Uploads/Pictures/20180411/5acd6d78033a2.jpg)");
+
+
+
+		Vendor('Michelf.Markdown');
+		$html = \Michelf\Markdown::defaultTransform("![](http://wx.mnw.cn/Uploads/Pictures/20180411/5acd6d78033a2.jpg)");
+
+		var_dump($markdown,$html);
+		die();
+		**/
+
+		$custom = array(
+			'options' => array(
+				'lool_to_material' => array(
+					'title' => '处理上报事件',
+					'url' => U('addon/LuojiangKaoping/web/editeventreport', array('id'=>'{id}')),
+					'class' => 'btn btn-primary btn-sm icon-edit'
+				),
+				'edit_fans' => array(
+					'title' => '查看用户信息',
+					'url' => U('Mp/Fans/edit_fans_byid', array('fansid'=>'{fans_id}')),
+					'class' => 'btn btn-primary btn-sm icon-edit'
+				)
+			)
+		);
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+			 ->addCrumb('事件上报', '', 'active')
+			 ->setModel('luojiang_eventreport')
+			 ->setListOrder('addtime desc')
+			 ->setListMap(array('mpid'=>get_mpid()))
+             ->setTip('<p id="msg_flush">暂无新消息</p>')
+             ->setListSearch(array('nickname' => '会员名称'))
+			 ->addListItem('fans_id', '会员名称', 'callback', array('callback_name'=>'get_fans_name'))
+			 ->addListItem('event_type', '事件类型', 'enum', array('options'=>array('井盖缺失'=>'井盖缺失','道路破损'=>'道路破损','道路淘空'=>'道路淘空','陈年垃圾'=>'陈年垃圾','卫生死角'=>'卫生死角','公共设施'=>'公共设施','市容环境'=>'市容环境','其他情况'=>'其他情况')))
+			 ->addListItem('descript', '事件描述')
+			 ->addListItem('image_list', '图片列表', 'callback', array('callback_name'=>'get_images_str'))
+			 ->addListItem('video_file', '视频', 'callback', array('callback_name'=>'get_video_str'))
+			 ->addListItem('jiangli', '奖励')
+			 ->addListItem('id', '位置', 'callback', array('callback_name'=>'get_message_content'))
+			 ->addListItem('addtime', '创建时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
+			 ->addListItem('reply_info', '处理结果', '', array('placeholder'=>'<font color="red">未处理</font>'))
+			 ->addListItem('id', '操作', 'custom', $custom)
+             ->addButton('导出', U('addon/LuojiangKaoping/web/loadexcel'), 'btn btn-primary')
+             ->common_lists();
+			echo '<script src="/Public/Mp/js/checkflush.js"></script>';
+			echo "<style>.table-striped > tbody > tr:nth-child(odd) > td, .table-striped > tbody > tr:nth-child(odd) > th{border-top:1px solid #000; ;border-bottom:1px solid #000;}</style>";
+
+	}
+	public function get_message_content($id) {
+		$map['id'] = $id;
+		$map['mpid'] = get_mpid();
+		$message = M('luojiang_eventreport')->where($map)->find();
+		if(!empty($message['location_addr'])){
+			return $message['location_addr'].'<br/><button type="button" class="btn btn-sm btn-success"  onclick="lookMap('.$message['lat'].','.$message['lng'].')">查看【位置】</button>';
+		}else{
+			return "未提供";
+		}
+	}
+
+	public function downfile()
+	{
+		//.jpg  mp4
+		//$mp_message_info['msgtype'] == 'video'
+		$file_url = urldecode( I('get.file_url') );
+		$type = urldecode( I('get.type') );
+
+		$file_url = str_replace('/Uploads/','Uploads/',$file_url);
+		$file_name = $file_url.'.'.$type;
+
+		$file_sub_path= "/data/web/wx.mnw.cn/";
+		$file_path=$file_sub_path.$file_name;
+
+		$filectime = filectime($file_path);
+
+		if( strpos($file_name,'jpg') !== false )
+		{
+			$img_arrs = explode('.', $file_name);
+			$file_name = '微信图片_'.date('Ymd',$filectime).'_'.$filectime.'.'.$img_arrs[1];
+		}
+		else if( strpos($file_name,'png') !== false  ){
+			$img_arrs = explode('.', $file_name);
+			$file_name = '微信图片_'.date('Ymd',$filectime).'_'.$filectime.'.'.$img_arrs[1];
+		}
+		else if( strpos($file_name,'gif') !== false  ){
+			$img_arrs = explode('.', $file_name);
+			$file_name = '微信图片_'.date('Ymd',$filectime).'_'.$filectime.'.'.$img_arrs[1];
+		}
+		else if( strpos($file_name,'jpeg') !== false  ){
+			$img_arrs = explode('.', $file_name);
+			$file_name = '微信图片_'.date('Ymd',$filectime).'_'.$filectime.'.'.$img_arrs[1];
+		}
+		else if( strpos($file_name,'mp4') !== false  ){
+			$img_arrs = explode('.', $file_name);
+			$file_name = '微信视频_'.date('Ymd',$filectime).'_'.$filectime.'.'.$img_arrs[1];
+		}
+		else if($mp_message_info['msgtype'] == 'voice' ){
+			$img_arrs = explode('.', $file_name);
+			$file_name = '微信语音_'.date('Ymd',$filectime).'_'.$filectime.'.'.$img_arrs[1];
+		}
+
+		$fp=fopen($file_path,"r");
+        $file_size=filesize($file_path);
+
+		//var_dump($file_size);die();
+        //下载文件需要用到的头
+        Header("Content-type: application/octet-stream");
+        Header("Accept-Ranges: bytes");
+        Header("Accept-Length:".$file_size);
+        Header("Content-Disposition: attachment; filename=".$file_name);
+        $buffer=1024;
+        $file_count=0;
+        //向浏览器返回数据
+        while(!feof($fp) && $file_count<$file_size){
+            $file_con=fread($fp,$buffer);
+            $file_count+=$buffer;
+            echo $file_con;
+        }
+        fclose($fp);
+
+		echo $file_url;
+		die();
+
+	}
+	/**
+     * 获取视频
+     * @author lyf
+     */
+    public function get_video_str($video_file)
+    {
+        if(empty($video_file))
+        {
+            return '暂无';
+        }else{
+            return '<button type="button" class="btn btn-sm btn-warning icon-video" data-src="'.$video_file.'" onclick="lookVideo(this)">查看视频</button><a href="'.U('addon/HuianKaoping/web/downfile', array('type' =>'mp4', 'file_url' => urlencode($video_file) )).'" title="点击下载视频" target=_blank">【下载】</a>';
+        }
+    }
+	/*
+     * 导出
+     */
+    public function loadexcel()
+    {
+        header("content-type:text/html; charset=uft-8");
+
+        if(IS_POST)
+        {
+            //date_added_begin:2017-08-02 0:00:00
+            //date_added_end:2017-08-19 0:00:00
+            $data = I('post.');
+            $where = array();
+
+            if(!empty($data['date_added_begin']))
+            {
+                $where['addtime'] = array('gt',strtotime($data['date_added_begin']) );
+            }
+            if(!empty($data['date_added_end']))
+            {
+                $where['addtime'] = array('lt',strtotime($data['date_added_end']) );
+            }
+
+
+
+            $s_time = strtotime($data['date_added_begin']);
+            $e_time = strtotime($data['date_added_end']);
+
+
+            if($s_time && $e_time)
+            {
+                $where['addtime'] = array('between',array($s_time,$e_time));
+            }
+
+
+            $list = M('luojiang_eventreport')->where($where)->order('id desc')->select();
+
+            //$need_data = array( array('order_sn'=>1,'get_image'=>'http://wx.mnw.cn/Uploads/Pictures/2/2017-08-07/2_oA7ocv8o0sk-tPmG87fjPD25nQWs_1502095440.jpg'),array('order_sn'=>1,'get_image'=>'http://wx.mnw.cn/Uploads/Pictures/2/2017-08-07/2_oA7ocv8o0sk-tPmG87fjPD25nQWs_1502095440.jpg')  );
+
+            $need_data = array();
+
+            $xlsCell  = array(
+                array('id','序号'),
+                array('addtime','日期'),
+                array('fans_id','微信名'),
+				array('mobile','联系人电话'),
+				array('jifen','积分'),
+
+                array('descript','事件描述'),
+                array('image_list','图否'),
+				array('jiangli','奖励'),
+                array('is_reply','反馈情况'),
+                array('reply_info','反馈内容'),
+                array('video_file','视频')
+
+                /*
+
+                array('contact_tel','联系电话'),
+                array('jifen','积分'),
+                array('nickname','微信名'),
+                array('content','问题描述'),
+                array('get_img','图否'),
+                array('fankui','反馈情况'),
+                array('fankui_tu','反馈图片'),
+                */
+            );
+            $i = 1;
+            foreach($list as $val)
+            {
+                $tmp_data = array();
+                $tmp_data['id'] = $i;
+                $tmp_data['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
+				//openid
+                $mp_fans = M('mp_fans')->field('nickname')->where( array('id' => $val['fans_id']) )->find();
+                $tmp_data['fans_id'] = $mp_fans['nickname'];
+				$tmp_data['mobile'] = $mp_fans['mobile'];
+
+				if(  empty($val['reply_info']) ){
+                    $tmp_data['jifen'] = 0;
+                }else{
+                    $tmp_data['jifen'] = 2;
+                }
+
+
+                $tmp_data['jiangli'] = $val['jiangli'];
+                //$tmp_data['title'] = $val['title'];
+                $tmp_data['descript'] = $val['descript'];
+                if(  empty($val['reply_info']) ){
+                    $tmp_data['is_reply'] = '否';
+                }else{
+                    $tmp_data['is_reply'] = '是';
+                }
+                $tmp_data['reply_info'] = $val['reply_info'];
+                if(empty($val['video_file']))
+                {
+                    $tmp_data['video_file'] ='否';
+
+                }else{
+					$tmp_data['video_file'] ='是';
+                    //$tmp_data['video_file'] ='http://'.$_SERVER['SERVER_NAME'].str_replace('./','',$val['video_file']);
+                }
+
+
+
+                //http://wx.mnw.cn/Uploads/Pictures/2/2017-08-07/2_oA7ocv8o0sk-tPmG87fjPD25nQWs_1502095440.jpg
+                if(!empty($val['image_list']))
+                {
+                    $img_arr = explode(',',$val['image_list']);
+                    if($val['image_list'] == ',undefined/undefined' || $val['image_list'] == 'undefined/undefined')
+                    {
+                        $img_url = '';
+						$img_urls = array();
+                    }else{
+						$img_urls = explode(',', $val['image_list']);
+
+						foreach($img_urls as $kk => $vv)
+						{
+							$vv = str_replace('./','/',$vv );
+
+							$vv = '/data/web/wx.mnw.cn'.$vv;
+							$img_urls[$kk] = $vv;
+						}
+
+                        //$img_url = str_replace('./','http://'.$_SERVER['SERVER_NAME'],$val['image_list']);
+                    }
+                    $tmp_data['image_list'] = $img_urls;
+                }
+                $i++;
+                $need_data[] = $tmp_data;
+            }
+            $expTitle = date('Y-m-d H:i:s');
+
+
+            export_excel($expTitle,$xlsCell,$need_data);
+
+        }
+        $this->display();
+    }
+	public function editeventreport()
+	{
+
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+		 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+		 ->addCrumb('处理上报事件', '', 'active')
+
+		 ->setModel('luojiang_eventreport')
+		 ->addFormField('jiangli', '上报奖励', 'text')
+		 ->addFormField('reply_info', '处理意见', 'text')
+
+		 ->setFormData( M('luojiang_eventreport')->find(I('get.id')) )
+		 ->setEditMap( array('id'=>I('get.id')) )
+		 ->setEditSuccessUrl( U('addon/LuojiangKaoping/web/eventreport') )
+		 ->common_edit();
+	}
+	public function opinionsuggestion()
+	{
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+			 ->addCrumb('意见建议', '', 'active')
+			 ->setModel('luojiang_opinionsuggestion')
+			 ->setListOrder('addtime desc')
+			 ->setListMap(array('mpid'=>get_mpid()))
+			 ->addListItem('fans_id', '会员名称', 'callback', array('callback_name'=>'get_fans_name'))
+			 ->addListItem('opinion_name', '建议人姓名')
+			 ->addListItem('contact', '建议人联系电话')
+			 ->addListItem('email', '邮箱')
+			 ->addListItem('title', '建议标题')
+			 ->addListItem('content', '建议内容')
+			 ->addListItem('image_list', '图片列表', 'callback', array('callback_name'=>'get_images_str'))
+			 ->addListItem('reply_method', '回复方式', 'enum', array('options'=>array('1'=>'网上',2=>'电话',3=>'当面')))
+			 //->addListItem('is_reply', '是否回复', 'enum', array('options'=>array(0=>'未回复',1=>'已回复')))
+			 ->addListItem('addtime', '创建时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
+			->addListItem('id', '操作', 'custom', array('options'=>array('edit_eventreport'=>array('处理意见建议', U('addon/LuojiangKaoping/web/editopinionsuggestion', array('id'=>'{id}')),'btn btn-primary btn-sm icon-edit',''))))
+			//->addListItem('id', '操作', 'custom', array('options'=>array('edit_fans'=>array('编辑粉丝资料', U('Mp/Fans/edit_fans', array('openid'=>'{openid}')),'btn btn-primary btn-sm icon-edit',''))))
+		     ->common_lists();
+	}
+	public function editopinionsuggestion()
+	{
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+		 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+		 ->addCrumb('处理意见建议', '', 'active')
+
+		 ->setModel('luojiang_opinionsuggestion')
+		 ->addFormField('reply_info', '处理意见', 'text')
+
+		 ->setFormData( M('luojiang_opinionsuggestion')->find(I('get.id')) )
+		 ->setEditMap( array('id'=>I('get.id')) )
+		 ->setEditSuccessUrl( U('addon/LuojiangKaoping/web/opinionsuggestion') )
+		 ->common_edit();
+
+	}
+	public function newsnenter_two()
+	{
+		$options = array(
+			'edit_fans'=>array('编辑', U('addon/LuojiangKaoping/web/editarticle', array('id'=>'{id}') )
+			,'btn btn-primary btn-sm icon-edit',''),
+			'delete' =>	array(
+				'title' => '删除',
+				'url' => U('addon/LuojiangKaoping/web/deletearticle', array('id'=>'{id}')),
+				'class' => 'btn btn-danger btn-sm icon-delete'
+			)
+		);
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+			 ->addCrumb('新闻中心', '', 'active')
+			 ->setModel('luojiang_article')
+			 ->setListMap(array('type'=>2))
+			 ->setListOrder('addtime desc')
+
+			 ->addListItem('title', '标题')
+			// ->addListItem('logo', '图片', 'image', array('attr'=>'width=50 height=50','placeholder'=>__ROOT__ . '/Public/Admin/img/noname.jpg'))
+			 ->addListItem('cate_id', '所属分类', 'callback',array('callback_name'=>'get_cate_name'))
+			 ->addListItem('sendtime', '发布时间')
+			 ->addListItem('addtime', '创建时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
+			 ->addListItem('id', '操作', 'custom', array('options'=>$options))
+			 //->addButton('新增文章分类', U('addon/HuianKaoping/web/addarticlecate'), 'btn btn-primary')
+			 ->addButton('新增文章', U('addon/LuojiangKaoping/web/addarticle_two'), 'btn btn-primary')
+			 ->common_lists();
+	}
+	public function newsnenter()
+	{
+		$options = array(
+			'edit_fans'=>array('编辑', U('addon/LuojiangKaoping/web/editarticle', array('id'=>'{id}') )
+			,'btn btn-primary btn-sm icon-edit',''),
+			'delete' =>	array(
+				'title' => '删除',
+				'url' => U('addon/LuojiangKaoping/web/deletearticle', array('id'=>'{id}')),
+				'class' => 'btn btn-danger btn-sm icon-delete'
+			)
+		);
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+			 ->addCrumb('新闻中心', '', 'active')
+			 ->setModel('luojiang_article')
+			 ->setListMap(array('type'=>1))
+			 ->setListOrder('addtime desc')
+
+			 ->addListItem('title', '标题')
+			 ->addListItem('logo', '图片', 'image', array('attr'=>'width=50 height=50','placeholder'=>__ROOT__ . '/Public/Admin/img/noname.jpg'))
+			 ->addListItem('cate_id', '所属分类', 'callback',array('callback_name'=>'get_cate_name'))
+			 ->addListItem('sendtime', '发布时间')
+			 ->addListItem('addtime', '创建时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
+			 ->addListItem('id', '操作', 'custom', array('options'=>$options))
+			 //->addButton('新增文章分类', U('addon/HuianKaoping/web/addarticlecate'), 'btn btn-primary')
+			 ->addButton('新增文章', U('addon/LuojiangKaoping/web/addarticle'), 'btn btn-primary')
+			 ->common_lists();
+	}
+
+	/**
+	 * 删除关键词回复
+	 * @author 艾逗笔<765532665@qq.com>
+	 */
+	public function deletearticle() {
+
+		M('luojiang_article')->where( array('id' =>I('get.id') ) )->delete();
+		$this->success('删除成功');
+
+	}
+	public function votecenter()
+	{
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+			 ->addCrumb('投票专区', '', 'active')
+			 ->setModel('vote')
+
+			 ->addListItem('title', '标题')
+			 ->addListItem('begin_time', '开始时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
+			 ->addListItem('end_time', '结束时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
+			 ->addListItem('addtime', '添加时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
+
+			 ->addListItem('vote_id', '操作', 'custom', array('options'=>array(
+				'edit_fans'=>array('编辑', U('addon/LuojiangKaoping/web/editvote', array('vote_id'=>'{vote_id}') ) ,'btn btn-primary btn-sm icon-edit',''),
+				'add_votesubject'=>array('添加投票选项', U('addon/LuojiangKaoping/web/addvotesubject', array('vote_id'=>'{vote_id}') ) ,'btn btn-primary btn-sm icon-edit',''),
+			 )))
+		     ->addButton('新增投票', U('addon/LuojiangKaoping/web/addvote'), 'btn btn-primary')
+			 ->common_lists();
+	}
+	public function addvote()
+	{
+		if( IS_POST )
+		{
+			$data = I('post.');
+			$vote_data = array();
+			$vote_data['mpid'] = get_mpid();
+			$vote_data['title'] = $data['name'];
+			$vote_data['begin_time'] = strtotime( $data['date_added_begin'] );
+			$vote_data['end_time'] = strtotime( $data['date_added_end'] );
+			$vote_data['addtime'] = time();
+			M('vote')->add($vote_data);
+			$this->success('添加投票成功', U('addon/LuojiangKaoping/web/votecenter'));
+			die();
+		}
+
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+			 ->addCrumb('新闻中心', '', 'active')
+			 ->display();
+	}
+	public function addvotesubject()
+	{
+		$vote_id = I('get.vote_id');
+		$this->vote_id = $vote_id;
+
+		if( IS_POST )
+		{
+			$data = I('post.');
+
+			if( isset($data['edit_votesubject']) )
+			{
+				$has_key = array();
+				$del_key = array();
+
+				foreach( $data['attr_title'] as $key => $val)
+				{
+					$has_key[] = $key;
+				}
+				$vote_sub_all =  M('vote_subject')->where( array('vote_id' => $data['vote_id']) )->select();
+
+				foreach($vote_sub_all as $vote_sub)
+				{
+					if( !in_array($vote_sub['sub_id'],$has_key ) )
+					{
+						$del_key[] = $vote_sub['sub_id'];
+					}
+				}
+				//删除多余键
+				if( !empty($del_key) )
+				{
+					M('vote_subject')->where( array('sub_id' => array('in', $del_key ) ) )->delete();
+					//删除投票记录
+					M('vote_record')->where( array('sub_id' => array('in', $del_key ) ) )->delete();
+				}
+				//开始更新和新增选项
+
+				foreach($data['attr_title'] as $key => $val)
+				{
+					if( strpos($key, 'new') !== false )
+					{
+						//新增的模块
+						$tmp_vote_subject = array();
+						$tmp_vote_subject['vote_id'] = $data['vote_id'];
+						$tmp_vote_subject['title'] = $val;
+						$tmp_vote_subject['type'] = $data['type'][$key];
+						$tmp_vote_subject['addtime'] = time();
+						M('vote_subject')->add($tmp_vote_subject);
+						$sub_id = M('vote_subject')->getLastInsID();
+
+						$extra = $data['extra'][$key];
+						$extra_arr = explode('|', $extra);
+						foreach($extra_arr as $vv)
+						{
+							$xun_data = array();
+							$xun_data['sub_id'] = $sub_id;
+							$xun_data['titile'] = $vv;
+							$xun_data['addtime'] = time();
+							M('vote_xuan')->add($xun_data);
+						}
+					} else {
+						//需要更新板块
+						$tmp_vote_subject = array();
+						$tmp_vote_subject['title'] = $val;
+						$tmp_vote_subject['type'] = $data['type'][$key];
+						M('vote_subject')->where( array('sub_id' =>$key ) ) ->save($tmp_vote_subject);
+
+						//更新子内容
+						//先判断原来有几个
+						$vote_xuan_list = M('vote_xuan')->where( array('sub_id' => $key) )->order('xu_id asc')->select();
+
+						$extra = array();
+						$extra = $data['extra'][$key];
+						$extra_arr = explode('|', $extra);
+						foreach($vote_xuan_list as $xun_vo)
+						{
+							if( !empty($extra_arr) )
+							{
+								$tmp_xun = array_shift( $extra_arr );
+								M('vote_xuan')->where( array('xu_id' => $xun_vo['xu_id']) )->save( array('titile' => $tmp_xun) );
+							}else {
+								//需要删除的
+								M('vote_xuan')->where( array('xu_id' => $xun_vo['xu_id']) )->delete();
+							}
+						}
+						//判断是否可以新增
+						if( !empty($extra_arr) )
+						{
+							foreach($extra_arr as $vv)
+							{
+								$xun_data = array();
+								$xun_data['sub_id'] = $key;
+								$xun_data['titile'] = $vv;
+								$xun_data['addtime'] = time();
+								M('vote_xuan')->add($xun_data);
+							}
+						}
+					}
+				}
+				$this->success('编辑投票选项成功', U('addon/HuianKaoping/web/votecenter'));
+				die();
+			}
+
+
+
+			foreach($data['attr_title'] as $key => $val)
+			{
+				if( !empty($val) )
+				{
+					$tmp_vote_subject = array();
+					$tmp_vote_subject['vote_id'] = $data['vote_id'];
+					$tmp_vote_subject['title'] = $val;
+					$tmp_vote_subject['type'] = $data['type'][$key];
+					$tmp_vote_subject['addtime'] = time();
+					M('vote_subject')->add($tmp_vote_subject);
+					$sub_id = M('vote_subject')->getLastInsID();
+
+					$extra = $data['extra'][$key];
+					//vote_xuan
+					$extra_arr = explode('|', $extra);
+					foreach($extra_arr as $vv)
+					{
+						$xun_data = array();
+						$xun_data['sub_id'] = $sub_id;
+						$xun_data['titile'] = $vv;
+						$xun_data['addtime'] = time();
+						M('vote_xuan')->add($xun_data);
+					}
+				}
+			}
+
+			$this->success('新增投票选项成功', U('addon/HuianKaoping/web/votecenter'));
+			die();
+
+		}
+
+		$vote_subject = M('vote_subject')->where( array('vote_id' => $vote_id) )->order('sub_id asc')->select();
+
+		if( !empty($vote_subject) )
+		{
+			foreach( $vote_subject as $key=> $val )
+			{
+				$vote_xuan_list = M('vote_xuan')->where( array('sub_id' => $val['sub_id']) )->order('xu_id asc')->select();
+				$xun_arr = array();
+
+				foreach( $vote_xuan_list as $vv )
+				{
+					$xun_arr[] = $vv['titile'];
+				}
+
+				$val['xun_title'] =  implode('|', $xun_arr);
+				$val['vote_xuan_list'] = $vote_xuan_list;
+				$vote_subject[$key] = $val;
+			}
+
+			$this->vote_subject = $vote_subject;
+
+
+
+			$this->addCrumb('洛江考评微官网', U('addon/HuianKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/HuianKaoping/web/eventreport'), '')
+			 ->addCrumb('新闻中心', '', 'active')
+			 ->display('editvotesubject');
+		} else {
+			$this->addCrumb('洛江考评微官网', U('addon/HuianKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/HuianKaoping/web/eventreport'), '')
+			 ->addCrumb('新闻中心', '', 'active')
+			 ->display();
+		}
+	}
+	public function loadachievement()
+	{
+        $type = I('type');
+		if( IS_POST )
+		{
+            set_time_limit(0);
+			  if(isset($_FILES["file"]) && ($_FILES["file"]["error"] == 0)){
+
+
+				  $excel_dir = './Uploads/Pictures/' . date('Y-m-d') . '/';
+					if (!file_exists($excel_dir)) {
+						$dirs = explode('/', $excel_dir);
+						$dir = $dirs[0] . '/';
+						for ($i=1, $j=count($dirs)-1; $i<$j; $i++) {
+							$dir .= $dirs[$i] . '/';
+							if (!is_dir($dir)) {
+								mkdir($dir, 0777);
+							}
+						}
+					}
+
+				  $extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
+
+
+				  $path = $excel_dir.'/'.md5($_FILES['file']['name'].mt_rand(1, 999)).'.'.$extension;
+				  $rs = move_uploaded_file($_FILES["file"]["tmp_name"],$path);
+
+
+
+				$file = $path;
+				$type = pathinfo($file);
+				$type = strtolower($type["extension"]);
+				$type=$type==='csv' ? $type : 'Excel5';
+				ini_set('max_execution_time', '0');
+				vendor("PHPExcel.PHPExcel");
+				// 判断使用哪种格式
+				$objReader = \PHPExcel_IOFactory::createReader($type);
+				$objPHPExcel = $objReader->load($file);
+				$sheet = $objPHPExcel->getSheet(0);
+				// 取得总行数
+				$highestRow = $sheet->getHighestRow();
+				// 取得总列数
+				$highestColumn = $sheet->getHighestColumn();
+				//循环读取excel文件,读取一条,插入一条
+				$data=array();
+				//从第一行开始读取数据
+				for($j=1;$j<=$highestRow;$j++){
+					if($j <=2) {
+						continue;
+					}
+					//从A列读取数据
+					for($k='A';$k<=$highestColumn;$k++){
+						// 读取单元格
+						$data[$j][]=$objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue();
+					}
+				}
+
+				$result = $data;
+				$get_data = array();
+				if(!empty($result)) {
+					foreach($result as $key => $val){
+
+						//array(5) { [0]=> string(6) "村庄" [1]=> string(18) "2017-8月上半月"
+						//[2]=> string(9) "小岞镇" [3]=> string(9) "新桥村" [4]=> float(92.5) }
+						if(empty($val[0]))
+						{
+							continue;
+						}
+						//$val[1] = str_replace('上半月','01',$val[1]);
+						//$val[1] = str_replace('下半月','15',$val[1]);
+
+
+
+						//$val[1] = $val[1]->__toString();
+						$val[1] .= ' 00:00:00';
+						//$val[1] = str_replace('年','-',$val[1]);
+						//$val[1] = str_replace('月','',$val[1]);
+
+						$need_data = array();
+						$need_data['name'] = $val[0];
+						$need_data['kao_time'] = strtotime($val[1]);
+						$need_data['zeren_danwei'] = $val[2];
+						$need_data['stree'] = $val[3];
+						$need_data['kaoping_dian'] = '';
+						$need_data['chengji'] = $val[4];
+                        if(I('type') == 2)
+                        {
+                            $need_data['type'] = 2;
+                        }else{
+                            $need_data['type'] = 1;
+                        }
+						if(empty($need_data['stree']))
+                        {
+                            $need_data['stree'] = '';
+                        }
+						$need_data['paiming'] = 0;
+						$need_data['addtime'] = time();
+						M('luojiang_achievement')->add($need_data);
+					}
+                    if(I('type') == 2){
+                        $this->success('导入成绩成功', U('addon/LuojiangKaoping/web/achievementmanage_two'));
+                    }else{
+                        $this->success('导入成绩成功', U('addon/LuojiangKaoping/web/achievementmanage'));
+                    }
+					die();
+				}
+			  }
+		}
+        $this->assign('type', $type);
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+			 ->addCrumb('成绩管理', '', 'active')
+			 ->display();
+	}
+
+	public function editvote()
+	{
+		// /vote_id/1
+		$vote_id = I('get.vote_id');
+
+		if( IS_POST )
+		{
+			$data = I('post.');
+
+			$data = I('post.');
+			$vote_data = array();
+			$vote_data['mpid'] = get_mpid();
+			$vote_data['title'] = $data['name'];
+			$vote_data['begin_time'] = strtotime( $data['date_added_begin'] );
+			$vote_data['end_time'] = strtotime( $data['date_added_end'] );
+
+			M('vote')->where( array('vote_id' => $data['vote_id']) )->save($vote_data);
+
+			$this->success('编辑投票成功', U('addon/HuianKaoping/web/votecenter'));
+			die();
+		}
+
+		$vote = M('vote')->where( array('vote_id' => $vote_id) )->find();
+
+		$this->vote = $vote;
+
+		$this->addCrumb('洛江考评微官网', U('addon/HuianKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/HuianKaoping/web/eventreport'), '')
+			 ->addCrumb('新闻中心', '', 'active')
+			 ->display('addvote');
+	}
+
+	public function editachievement()
+	{
+		$id = I('get.id');
+		$type = I('get.type');
+		if( IS_POST )
+		{
+			$data = I('post.');
+
+
+			$vote_data = array();
+			$vote_data['name'] = $data['name'];
+			$vote_data['kao_time'] = strtotime( $data['kao_time'] );
+			$vote_data['zeren_danwei'] = $data['zeren_danwei'];
+			$vote_data['stree'] = $data['stree'];
+			$vote_data['content'] = ($data['content']);
+			//$vote_data['kaoping_dian'] = $data['kaoping_dian'];
+			$vote_data['chengji'] = $data['chengji'];
+			//$vote_data['paiming'] = $data['paiming'];
+			M('luojiang_achievement')->where( array('id' => $id) )->save($vote_data);
+
+            if($data['type'] == 2)
+            {
+                $this->success('编辑成功', U('addon/LuojiangKaoping/web/achievementmanage_two'));
+            }else{
+                $this->success('编辑成功', U('addon/LuojiangKaoping/web/achievementmanage'));
+            }
+
+			die();
+		}
+
+        if($type == 2)
+        {
+            $this->setEditSuccessUrl( U('addon/LuojiangKaoping/web/achievementmanage_two') );
+        }else{
+            $this->setEditSuccessUrl( U('addon/LuojiangKaoping/web/achievementmanage') );
+        }
+        $this->assign('type', $type);
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+		 ->addCrumb('成绩管理', U('addon/LuojiangKaoping/web/achievementmanage'), '')
+		 ->addCrumb('成绩管理', '', 'active')
+		 ->setModel('luojiang_achievement')
+		 ->addFormField('name', '类别', 'text')
+		 ->addFormField('kao_time', '考评时间', 'date')
+		 ->addFormField('zeren_danwei', '街道(乡镇)/责任单位', 'text')
+		 ->addFormField('stree', '抽评点', 'text')
+		 ->addFormField('content', '内容', 'editor')
+		 //->addFormField('kaoping_dian', '考评点', 'text')
+		 ->addFormField('chengji', '成绩', 'text')
+		 //->addFormField('paiming', '排名', 'text')
+
+		 ->setEditMap( array('id'=>I('get.id')))
+		 ->common_edit();
+
+	}
+	public function get_cate_name($cate_id)
+	{
+		$category_info =  M('luojiang_articlecategory')->where( array('id' => $cate_id) )->find();
+		return $category_info['name'];
+	}
+
+	public function editarticle()
+	{
+		$cateinfos = M('luojiang_articlecategory')->where( array('pid' => 0) )->select();
+
+		$cate_arr = array();
+		foreach($cateinfos as $val)
+		{
+			$cate_arr[$val[id]] = $val['name'];
+		}
+
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+		 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+		 ->addCrumb('编辑文章', '', 'active')
+		 ->setModel('huian_article')
+		 ->addFormField('title', '标题', 'text')
+		 ->addFormField('link', '外链', 'text')
+		 ->addFormField('logo', '图片', 'image')
+		 ->addFormField('sendtime', '发布时间', 'time')
+		 ->addFormField('cate_id', '所属分类', 'select', array('options'=>$cate_arr))
+		 ->addFormField('content', '内容', 'editor')
+		 ->setValidate(array(
+				array('name', 'require', '标题不能为空')//,
+				//array('logo', 'require', '请上传图片')
+		   ))
+		 ->setFormData( M('luojiang_article')->find(I('get.id')) )
+		 ->setEditMap( array('id'=>I('get.id')) )
+		 ->setEditSuccessUrl( U('addon/LuojiangKaoping/web/newsnenter') )
+		 ->common_edit();
+
+
+	}
+	public function addarticlecate()
+	{
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+			 ->addCrumb('添加文章分类', '', 'active')
+			 ->setModel('luojiang_articlecategory')
+			 ->addFormField('name', '名称', 'text')
+			 //->addFormField('type', '类型', 'radio', array('options'=>array(1=>'普通订阅号',2=>'认证订阅号',3=>'普通服务号',4=>'认证服务号',5=>'测试号'),'value'=>4,'is_must'=>1))
+			// ->addFormField('pid', '原始ID', 'text', array('is_must'=>1))
+			 //->addFormField('mp_number', '微信号', 'text')
+			// ->addFormField('appid', 'APPID', 'text')
+			// ->addFormField('appsecret', 'APPSECRET', 'text')
+			 //->addFormField('headimg', '头像', 'image')
+			 //->addFormField('qrcode', '二维码', 'image')
+			 ->setValidate(array(
+					array('name', 'require', '名称不能为空'),
+			   ))
+			 ->setAuto(array(
+					array('pid', '0'),
+					array('addtime', 'time', 1, 'function')
+			 ))
+			 ->setAddSuccessUrl( U('addon/LuojiangKaoping/web/newsnenter') )
+			 ->common_add();
+	}
+
+	public function addarticle_two()
+	{
+		$cateinfos = M('luojiang_articlecategory')->where( array('pid' => 0) )->select();
+
+		$cate_arr = array();
+		foreach($cateinfos as $val)
+		{
+			$cate_arr[$val[id]] = $val['name'];
+		}
+
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+			 ->addCrumb('添加文章', '', 'active')
+			 ->setModel('luojiang_article')
+			 ->addFormField('title', '标题', 'text')
+			 ->addFormField('type', '1', 'hidden',array('value'=>2))
+			 //->addFormField('link', '外链', 'text')
+			 //->addFormField('logo', '图片', 'image')
+			 ->addFormField('sendtime', '发布时间', 'time')
+			 ->addFormField('cate_id', '1', 'hidden',array('value'=>1))
+			 //->addFormField('cate_id', '所属分类', 'select', array('options'=>$cate_arr))
+			 ->addFormField('content', '内容', 'editor')
+			 ->setValidate(array(
+					array('name', 'require', '标题不能为空'),
+					//array('logo', 'require', '请上传图片')
+			   ))
+			 ->setAuto(array(
+					array('addtime', 'time', 1, 'function')
+			   ))
+			 ->setAddSuccessUrl( U('addon/LuojiangKaoping/web/newsnenter_two') )
+			 ->common_add();
+	}
+
+	public function addarticle()
+	{
+		$cateinfos = M('luojiang_articlecategory')->where( array('pid' => 0) )->select();
+
+		$cate_arr = array();
+		foreach($cateinfos as $val)
+		{
+			$cate_arr[$val[id]] = $val['name'];
+		}
+
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+			 ->addCrumb('添加文章', '', 'active')
+			 ->setModel('luojiang_article')
+			 ->addFormField('title', '标题', 'text')
+			 ->addFormField('type', '1', 'hidden',array('value'=>1))
+			 ->addFormField('link', '外链', 'text')
+			 ->addFormField('logo', '图片', 'image')
+			 ->addFormField('sendtime', '发布时间', 'time')
+			 ->addFormField('cate_id', '所属分类', 'select', array('options'=>$cate_arr))
+			 ->addFormField('content', '内容', 'editor')
+			 ->setValidate(array(
+					array('name', 'require', '标题不能为空')//,
+					//array('logo', 'require', '请上传图片')
+			   ))
+			 ->setAuto(array(
+					array('addtime', 'time', 1, 'function')
+			   ))
+			 ->setAddSuccessUrl( U('addon/LuojiangKaoping/web/newsnenter') )
+			 ->common_add();
+	}
+	public function achievementmanage()
+	{
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+			 ->addCrumb('乡镇成绩管理', '', 'active')
+			 ->setModel('luojiang_achievement')
+			 ->setListOrder('addtime desc')
+			 ->addListItem('name', '类别')
+            //->addListItem('kao_time', '考评时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
+             ->setListMap(array('type'=>1))
+             ->addListItem('kao_time', '考评时间', 'callback', array('callback_name'=>'get_date_hui'))
+			 ->addListItem('zeren_danwei', '街道办事处')
+			 ->addListItem('stree', '抽评点')
+			 //->addListItem('kaoping_dian', '考评点')
+			 ->addListItem('chengji', '成绩')
+			 //->addListItem('paiming', '排名')
+			 ->addListItem('addtime', '添加时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
+			 ->addButton('导入考评成绩', U('addon/LuojiangKaoping/web/loadachievement'), 'btn btn-primary')
+			 ->addListItem('id', '操作', 'custom', array('options'=>array('edit_fans'=>array('编辑成绩', U('addon/LuojiangKaoping/web/editachievement', array('id'=>'{id}','type'=>1)),'btn btn-primary btn-sm icon-edit',''))))
+		     ->common_lists();
+
+		$cjcount = M('luojiang_achievement')->where(array('paiming'=>0,'type'=>1))->count();
+		if($cjcount>0)
+		{
+			$paiming = array();
+			$pagecount = M('luojiang_achievement')->field('kao_time')->where(array('type'=>1))->group('kao_time')->order('kao_time desc')->select();
+			foreach($pagecount as $val)
+			{
+				$data = M('luojiang_achievement')->field('id,chengji')->where(array("kao_time"=>$val['kao_time'],"type"=>1))->order('chengji desc, id asc')->select();
+				$chengji = $data[0]['chengji'];
+				$order = 1;$num = 0;
+				foreach($data as $key=>$subval)
+				{
+					if($key != 0){
+						if($subval["chengji"] < $chengji){
+							$order += 1;
+							$chengji = $subval['chengji'];
+							$order += $num;
+							$num = 0;
+						}
+						else {
+							$num++;
+						}
+					}
+					$paiming[] = array('id'=>$subval["id"],'paiming'=>$order);
+				}
+				krsort($data);
+				$chengji = $data[count($data)-1]['chengji'];
+				$order = -5;$num = 0;
+				foreach($data as $key=>$subval)
+				{
+					if($key != count($data)-1){
+						if($subval["chengji"] > $chengji){
+							$order += 1;
+							$chengji = $subval['chengji'];
+							$order += $num;
+							$num = 0;
+						}
+						else {
+							$num++;
+						}
+					}
+					if($order == 0) break;
+					$paiming[] = array('id'=>$subval["id"],'paiming'=>$order);
+				}
+			}
+			foreach($paiming as $val)
+			{
+				$data['paiming'] = $val['paiming'];
+				M('luojiang_achievement')->where(array("id"=>$val['id']))->save($data);
+			}
+		}
+	}
+
+	 public function achievementmanage_two()
+    {
+        $this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+            ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+            ->addCrumb('部门成绩管理', '', 'active')
+            ->setModel('luojiang_achievement')
+            ->setListOrder('addtime desc')
+            ->setListMap(array('type'=>2))
+            ->addListItem('name', '类别')
+            //->addListItem('kao_time', '考评时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
+            ->addListItem('kao_time', '考评时间', 'callback', array('callback_name'=>'get_date_hui'))
+            ->addListItem('zeren_danwei', '部门')
+            ->addListItem('stree', '考评对象')
+            //->addListItem('kaoping_dian', '考评点')
+            ->addListItem('chengji', '成绩')
+            //->addListItem('paiming', '排名')
+            ->addListItem('addtime', '添加时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
+            ->addButton('导入考评成绩', U('addon/LuojiangKaoping/web/loadachievement',array('type'=>2)), 'btn btn-primary')
+            ->addListItem('id', '操作', 'custom', array('options'=>array('edit_fans'=>array('编辑成绩', U('addon/HuianKaoping/web/editachievement', array('id'=>'{id}','type'=>2)),'btn btn-primary btn-sm icon-edit',''))))
+            ->common_lists();
+
+        $cjcount = M('luojiang_achievement')->where(array('paiming'=>0,'type'=>2))->count();
+        if($cjcount>0)
+        {
+            $paiming = array();
+            $pagecount = M('luojiang_achievement')->field('kao_time')->where(array('type'=>2))->group('kao_time')->order('kao_time desc')->select();
+            foreach($pagecount as $val)
+            {
+                $data = M('luojiang_achievement')->field('id,chengji')->where(array("kao_time"=>$val['kao_time'],'type'=>2))->order('chengji desc, id asc')->select();
+                $chengji = $data[0]['chengji'];
+                $order = 1;$num = 0;
+                foreach($data as $key=>$subval)
+                {
+                    if($key != 0){
+                        if($subval["chengji"] < $chengji){
+                            $order += 1;
+                            $chengji = $subval['chengji'];
+                            $order += $num;
+                            $num = 0;
+                        }
+                        else {
+                            $num++;
+                        }
+                    }
+                    $paiming[] = array('id'=>$subval["id"],'paiming'=>$order);
+                }
+                krsort($data);
+                $chengji = $data[count($data)-1]['chengji'];
+                $order = -5;$num = 0;
+                foreach($data as $key=>$subval)
+                {
+                    if($key != count($data)-1){
+                        if($subval["chengji"] > $chengji){
+                            $order += 1;
+                            $chengji = $subval['chengji'];
+                            $order += $num;
+                            $num = 0;
+                        }
+                        else {
+                            $num++;
+                        }
+                    }
+                    if($order == 0) break;
+                    $paiming[] = array('id'=>$subval["id"],'paiming'=>$order);
+                }
+            }
+            foreach($paiming as $val)
+            {
+                $data['paiming'] = $val['paiming'];
+                M('luojiang_achievement')->where(array("id"=>$val['id']))->save($data);
+            }
+        }
+    }
+
+	public function get_date_hui($kao_time)
+	{
+		$d = date('d',$kao_time);
+		/**
+		if($d == '15')
+		{
+			$kao_time = date('Y-m',$kao_time).'-下半月';
+		} else {
+			$kao_time = date('Y-m',$kao_time).'-上半月';
+
+		}
+		**/
+		$kao_time = date('Y-m-d',$kao_time);
+		return $kao_time;
+	}
+	public function usermanage()
+	{
+
+		//->addListItem('msgid', '消息内容', 'callback', array('callback_name'=>'get_message_content'))
+
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+			 ->addCrumb('用户管理', '', 'active')
+			 ->setModel('luojiang_eventreport')
+			 ->setListMap(array('mpid'=>get_mpid()))
+			 ->addListItem('fans_id', '会员名称', 'callback', array('callback_name'=>'get_fans_name'))
+			 ->addListItem('event_type', '事件类型', 'enum', array('options'=>array('0'=>'未知',1=>'事件类型1',2=>'事件类型2',3=>'事件类型3')))
+			 ->addListItem('title', '标题')
+			 ->addListItem('descript', '事件描述')
+			 ->addListItem('image_list', '图片列表', 'callback', array('callback_name'=>'get_images_str'))
+			 ->addListItem('is_reply', '是否回复', 'enum', array('options'=>array(0=>'未回复',1=>'已回复')))
+			 ->addListItem('location_addr', '位置', '', array('placeholder'=>'未提供'))
+			 ->addListItem('addtime', '创建时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
+			 ->addListItem('id', '操作', 'custom', array('options'=>array('edit_fans'=>array('编辑粉丝资料', U('Mp/Fans/edit_fans', array('openid'=>'{openid}')),'btn btn-primary btn-sm icon-edit',''))))
+		     ->common_lists();
+	}
+	function get_images_str($image_list)
+	{
+		$image_arr = explode(',', $image_list);
+		$image_str = '';
+		$image_need_arr = array();
+
+		if( !empty($image_arr) )
+		{
+			foreach($image_arr as $img)
+			{
+				$img = str_replace('./Uploads/','/Uploads/',$img);
+				$img = str_replace('//','/',$img);
+				$imgtemp = explode('.',$img);
+				//$thumb_img =  $this->resize($img,100,100);
+				$image_need_arr[] = "<div style='float:left;width:100px;margin-right:5px;'><img src='".$img."' width=100 height=100 'placeholder'= '".__ROOT__ ."/Public/Admin/img/noname.jpg' /><br/>【<a href='".$img."' target='_blank'>预览</a> | <a href='".U('addon/HuianKaoping/web/downfile', array('type' =>$imgtemp[1], 'file_url' => urlencode($img) ))."' target='_blank'>下载】</a></div>";
+			}
+			$image_str = implode(' ', $image_need_arr);
+		}
+		return "<div style='width:220px;'> ".$image_str."</div>";
+
+	}
+	//字符串截取
+function utf8_substr($string, $offset, $length = null) {
+	// generates E_NOTICE
+	// for PHP4 objects, but not PHP5 objects
+	$string = (string)$string;
+	$offset = (int)$offset;
+
+	if (!is_null($length)) {
+		$length = (int)$length;
+	}
+
+	// handle trivial cases
+	if ($length === 0) {
+		return '';
+	}
+
+	if ($offset < 0 && $length < 0 && $length < $offset) {
+		return '';
+	}
+
+	// normalise negative offsets (we could use a tail
+	// anchored pattern, but they are horribly slow!)
+	if ($offset < 0) {
+		$strlen = strlen(utf8_decode($string));
+		$offset = $strlen + $offset;
+
+		if ($offset < 0) {
+			$offset = 0;
+		}
+	}
+
+	$Op = '';
+	$Lp = '';
+
+	// establish a pattern for offset, a
+	// non-captured group equal in length to offset
+	if ($offset > 0) {
+		$Ox = (int)($offset / 65535);
+		$Oy = $offset%65535;
+
+		if ($Ox) {
+			$Op = '(?:.{65535}){' . $Ox . '}';
+		}
+
+		$Op = '^(?:' . $Op . '.{' . $Oy . '})';
+	} else {
+		$Op = '^';
+	}
+
+	// establish a pattern for length
+	if (is_null($length)) {
+		$Lp = '(.*)$';
+	} else {
+		if (!isset($strlen)) {
+			$strlen = strlen(utf8_decode($string));
+		}
+
+		// another trivial case
+		if ($offset > $strlen) {
+			return '';
+		}
+
+		if ($length > 0) {
+			$length = min($strlen - $offset, $length);
+
+			$Lx = (int)($length / 65535);
+			$Ly = $length % 65535;
+
+			// negative length requires a captured group
+			// of length characters
+			if ($Lx) {
+				$Lp = '(?:.{65535}){' . $Lx . '}';
+			}
+
+			$Lp = '(' . $Lp . '.{' . $Ly . '})';
+		} elseif ($length < 0) {
+			if ($length < ($offset - $strlen)) {
+				return '';
+			}
+
+			$Lx = (int)((-$length) / 65535);
+			$Ly = (-$length)%65535;
+
+			// negative length requires ... capture everything
+			// except a group of  -length characters
+			// anchored at the tail-end of the string
+			if ($Lx) {
+				$Lp = '(?:.{65535}){' . $Lx . '}';
+			}
+
+			$Lp = '(.*)(?:' . $Lp . '.{' . $Ly . '})$';
+		}
+	}
+
+	if (!preg_match( '#' . $Op . $Lp . '#us', $string, $match)) {
+		return '';
+	}
+
+	return $match[1];
+
+}
+/**
+ * 递归生成目录
+ */
+function RecursiveMkdir($path) {
+	if (!file_exists($path)) {
+		$this->RecursiveMkdir(dirname($path));
+		@mkdir($path, 0777);
+	}
+}
+
+
+//字符串长度计算
+function utf8_strlen($string) {
+	return strlen(utf8_decode($string));
+}
+
+function utf8_strrpos($string, $needle, $offset = null) {
+	if (is_null($offset)) {
+		$data = explode($needle, $string);
+
+		if (count($data) > 1) {
+			array_pop($data);
+
+			$string = join($needle, $data);
+
+			return $this->utf8_strlen($string);
+		}
+
+		return false;
+	} else {
+		if (!is_int($offset)) {
+			trigger_error('utf8_strrpos expects parameter 3 to be long', E_USER_WARNING);
+
+			return false;
+		}
+
+		$string = $this->utf8_substr($string, $offset);
+
+		if (false !== ($position = utf8_strrpos($string, $needle))) {
+			return $position + $offset;
+		}
+
+		return false;
+	}
+}
+
+	/**
+ * 自动生成新尺寸 的图片
+ */
+	function resize($filename, $width, $height) {
+			define(ROOT_PATH,'/data/web/wx.mnw.cn/');
+			///data/web/wx.mnw.cn/Addons/HuianKaoping/Controller
+
+		$image_dir=ROOT_PATH;
+
+
+		if (!is_file($image_dir . $filename)) {
+			return;
+		}
+
+		$extension = pathinfo($filename, PATHINFO_EXTENSION);
+
+		$old_image = $filename;
+		$new_image = 'cache/' . $this->utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
+
+		if (!is_file($image_dir . $new_image) || (filectime($image_dir . $old_image) > filectime($image_dir . $new_image))) {
+			$path = '';
+
+			$directories = explode('/', dirname(str_replace('../', '', $new_image)));
+
+			foreach ($directories as $directory) {
+				$path = $path . '/' . $directory;
+
+				if (!is_dir($image_dir . $path)) {
+					@mkdir($image_dir . $path, 0777);
+				}
+			}
+
+			list($width_orig, $height_orig) = getimagesize($image_dir . $old_image);
+
+			if ($width_orig != $width || $height_orig != $height) {
+				$image = new \Lib\Image($image_dir . $old_image);
+			$image->resize($width, $height);
+				$image->save($image_dir . $new_image);
+			} else {
+				copy($image_dir . $old_image, $image_dir . $new_image);
+			}
+		}
+
+		return 'Uploads/image/' . $new_image;
+
+		}
+
+	public function get_fans_name($fans_id)
+	{
+		$fans_info = M('mp_fans')->where( array('id' => $fans_id) )->find();
+		return $fans_info['nickname'];
+		//return '<a href="'.U('Mp/Fans/edit_fans', array('openid'=>$fans_info['openid'])).'" target="_blank" title="点击查看用户信息">'.$fans_info['nickname'].'</a>';
+	}
+
+}
+
 ?>

+ 1372 - 0
Modules/Lib/Weixin/WebController.class.php.back

@@ -0,0 +1,1372 @@
+<?php
+
+namespace Addons\LuojiangKaoping\Controller;
+use Mp\Controller\AddonsController;
+
+/**
+ * 洛江考评微官网后台管理控制器
+ * @author 大鱼
+ */
+class WebController extends AddonsController {
+	public function test()
+	{
+		//luojiang_achievement 
+		$all_list = M('luojiang_article')->select();
+		Vendor('HyperDown.Parser');
+		$parser = new \Parser();
+		
+		foreach( $all_list as $val )
+		{
+			$content = $parser->makeHtml($val['content']);
+			M('luojiang_article')->where( array('id' => $val['id']) )->save( array('content' => $content) );
+			//id 
+		}
+		var_dump('success');
+		die();
+		//LuojiangKaoping
+	}
+	public function eventreport()
+	{
+		/**
+		Vendor('HyperDown.Parser');
+		$parser = new \Parser();
+		$markdown = $parser->makeHtml("![](http://wx.mnw.cn/Uploads/Pictures/20180411/5acd6d78033a2.jpg)");
+
+
+
+		Vendor('Michelf.Markdown');
+		$html = \Michelf\Markdown::defaultTransform("![](http://wx.mnw.cn/Uploads/Pictures/20180411/5acd6d78033a2.jpg)");
+
+		var_dump($markdown,$html);
+		die();
+		**/
+
+		$custom = array(
+			'options' => array(
+				'lool_to_material' => array(
+					'title' => '处理上报事件',
+					'url' => U('addon/LuojiangKaoping/web/editeventreport', array('id'=>'{id}')),
+					'class' => 'btn btn-primary btn-sm icon-edit'
+				),
+				'edit_fans' => array(
+					'title' => '查看用户信息',
+					'url' => U('Mp/Fans/edit_fans_byid', array('fansid'=>'{fans_id}')),
+					'class' => 'btn btn-primary btn-sm icon-edit'
+				)
+			)
+		);
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+			 ->addCrumb('事件上报', '', 'active')
+			 ->setModel('luojiang_eventreport')
+			 ->setListOrder('addtime desc')
+			 ->setListMap(array('mpid'=>get_mpid()))
+             ->setTip('<p id="msg_flush">暂无新消息</p>')
+             ->setListSearch(array('nickname' => '会员名称'))
+			 ->addListItem('fans_id', '会员名称', 'callback', array('callback_name'=>'get_fans_name'))
+			 ->addListItem('event_type', '事件类型', 'enum', array('options'=>array('井盖缺失'=>'井盖缺失','道路破损'=>'道路破损','道路淘空'=>'道路淘空','陈年垃圾'=>'陈年垃圾','卫生死角'=>'卫生死角','公共设施'=>'公共设施','市容环境'=>'市容环境','其他情况'=>'其他情况')))
+			 ->addListItem('descript', '事件描述')
+			 ->addListItem('image_list', '图片列表', 'callback', array('callback_name'=>'get_images_str'))
+			 ->addListItem('video_file', '视频', 'callback', array('callback_name'=>'get_video_str'))
+			 ->addListItem('jiangli', '奖励')
+			 ->addListItem('id', '位置', 'callback', array('callback_name'=>'get_message_content'))
+			 ->addListItem('addtime', '创建时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
+			 ->addListItem('reply_info', '处理结果', '', array('placeholder'=>'<font color="red">未处理</font>'))
+			 ->addListItem('id', '操作', 'custom', $custom)
+             ->addButton('导出', U('addon/LuojiangKaoping/web/loadexcel'), 'btn btn-primary')
+             ->common_lists();
+			echo '<script src="/Public/Mp/js/checkflush.js"></script>';
+			echo "<style>.table-striped > tbody > tr:nth-child(odd) > td, .table-striped > tbody > tr:nth-child(odd) > th{border-top:1px solid #000; ;border-bottom:1px solid #000;}</style>";
+
+	}
+	public function get_message_content($id) {
+		$map['id'] = $id;
+		$map['mpid'] = get_mpid();
+		$message = M('luojiang_eventreport')->where($map)->find();
+		if(!empty($message['location_addr'])){
+			return $message['location_addr'].'<br/><button type="button" class="btn btn-sm btn-success"  onclick="lookMap('.$message['lat'].','.$message['lng'].')">查看【位置】</button>';
+		}else{
+			return "未提供";
+		}
+	}
+
+	public function downfile()
+	{
+		//.jpg  mp4
+		//$mp_message_info['msgtype'] == 'video'
+		$file_url = urldecode( I('get.file_url') );
+		$type = urldecode( I('get.type') );
+
+		$file_url = str_replace('/Uploads/','Uploads/',$file_url);
+		$file_name = $file_url.'.'.$type;
+
+		$file_sub_path= "/data/web/wx.mnw.cn/";
+		$file_path=$file_sub_path.$file_name;
+
+		$filectime = filectime($file_path);
+
+		if( strpos($file_name,'jpg') !== false )
+		{
+			$img_arrs = explode('.', $file_name);
+			$file_name = '微信图片_'.date('Ymd',$filectime).'_'.$filectime.'.'.$img_arrs[1];
+		}
+		else if( strpos($file_name,'png') !== false  ){
+			$img_arrs = explode('.', $file_name);
+			$file_name = '微信图片_'.date('Ymd',$filectime).'_'.$filectime.'.'.$img_arrs[1];
+		}
+		else if( strpos($file_name,'gif') !== false  ){
+			$img_arrs = explode('.', $file_name);
+			$file_name = '微信图片_'.date('Ymd',$filectime).'_'.$filectime.'.'.$img_arrs[1];
+		}
+		else if( strpos($file_name,'jpeg') !== false  ){
+			$img_arrs = explode('.', $file_name);
+			$file_name = '微信图片_'.date('Ymd',$filectime).'_'.$filectime.'.'.$img_arrs[1];
+		}
+		else if( strpos($file_name,'mp4') !== false  ){
+			$img_arrs = explode('.', $file_name);
+			$file_name = '微信视频_'.date('Ymd',$filectime).'_'.$filectime.'.'.$img_arrs[1];
+		}
+		else if($mp_message_info['msgtype'] == 'voice' ){
+			$img_arrs = explode('.', $file_name);
+			$file_name = '微信语音_'.date('Ymd',$filectime).'_'.$filectime.'.'.$img_arrs[1];
+		}
+
+		$fp=fopen($file_path,"r");
+        $file_size=filesize($file_path);
+
+		//var_dump($file_size);die();
+        //下载文件需要用到的头
+        Header("Content-type: application/octet-stream");
+        Header("Accept-Ranges: bytes");
+        Header("Accept-Length:".$file_size);
+        Header("Content-Disposition: attachment; filename=".$file_name);
+        $buffer=1024;
+        $file_count=0;
+        //向浏览器返回数据
+        while(!feof($fp) && $file_count<$file_size){
+            $file_con=fread($fp,$buffer);
+            $file_count+=$buffer;
+            echo $file_con;
+        }
+        fclose($fp);
+
+		echo $file_url;
+		die();
+
+	}
+	/**
+     * 获取视频
+     * @author lyf
+     */
+    public function get_video_str($video_file)
+    {
+        if(empty($video_file))
+        {
+            return '暂无';
+        }else{
+            return '<button type="button" class="btn btn-sm btn-warning icon-video" data-src="'.$video_file.'" onclick="lookVideo(this)">查看视频</button><a href="'.U('addon/HuianKaoping/web/downfile', array('type' =>'mp4', 'file_url' => urlencode($video_file) )).'" title="点击下载视频" target=_blank">【下载】</a>';
+        }
+    }
+	/*
+     * 导出
+     */
+    public function loadexcel()
+    {
+        header("content-type:text/html; charset=uft-8");
+
+        if(IS_POST)
+        {
+            //date_added_begin:2017-08-02 0:00:00
+            //date_added_end:2017-08-19 0:00:00
+            $data = I('post.');
+            $where = array();
+
+            if(!empty($data['date_added_begin']))
+            {
+                $where['addtime'] = array('gt',strtotime($data['date_added_begin']) );
+            }
+            if(!empty($data['date_added_end']))
+            {
+                $where['addtime'] = array('lt',strtotime($data['date_added_end']) );
+            }
+
+
+
+            $s_time = strtotime($data['date_added_begin']);
+            $e_time = strtotime($data['date_added_end']);
+
+
+            if($s_time && $e_time)
+            {
+                $where['addtime'] = array('between',array($s_time,$e_time));
+            }
+
+
+            $list = M('luojiang_eventreport')->where($where)->order('id desc')->select();
+
+            //$need_data = array( array('order_sn'=>1,'get_image'=>'http://wx.mnw.cn/Uploads/Pictures/2/2017-08-07/2_oA7ocv8o0sk-tPmG87fjPD25nQWs_1502095440.jpg'),array('order_sn'=>1,'get_image'=>'http://wx.mnw.cn/Uploads/Pictures/2/2017-08-07/2_oA7ocv8o0sk-tPmG87fjPD25nQWs_1502095440.jpg')  );
+
+            $need_data = array();
+
+            $xlsCell  = array(
+                array('id','序号'),
+                array('addtime','日期'),
+                array('fans_id','微信名'),
+				array('mobile','联系人电话'),
+				array('jifen','积分'),
+
+                array('descript','事件描述'),
+                array('image_list','图否'),
+				array('jiangli','奖励'),
+                array('is_reply','反馈情况'),
+                array('reply_info','反馈内容'),
+                array('video_file','视频')
+
+                /*
+
+                array('contact_tel','联系电话'),
+                array('jifen','积分'),
+                array('nickname','微信名'),
+                array('content','问题描述'),
+                array('get_img','图否'),
+                array('fankui','反馈情况'),
+                array('fankui_tu','反馈图片'),
+                */
+            );
+            $i = 1;
+            foreach($list as $val)
+            {
+                $tmp_data = array();
+                $tmp_data['id'] = $i;
+                $tmp_data['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
+				//openid
+                $mp_fans = M('mp_fans')->field('nickname')->where( array('id' => $val['fans_id']) )->find();
+                $tmp_data['fans_id'] = $mp_fans['nickname'];
+				$tmp_data['mobile'] = $mp_fans['mobile'];
+
+				if(  empty($val['reply_info']) ){
+                    $tmp_data['jifen'] = 0;
+                }else{
+                    $tmp_data['jifen'] = 2;
+                }
+
+
+                $tmp_data['jiangli'] = $val['jiangli'];
+                //$tmp_data['title'] = $val['title'];
+                $tmp_data['descript'] = $val['descript'];
+                if(  empty($val['reply_info']) ){
+                    $tmp_data['is_reply'] = '否';
+                }else{
+                    $tmp_data['is_reply'] = '是';
+                }
+                $tmp_data['reply_info'] = $val['reply_info'];
+                if(empty($val['video_file']))
+                {
+                    $tmp_data['video_file'] ='否';
+
+                }else{
+					$tmp_data['video_file'] ='是';
+                    //$tmp_data['video_file'] ='http://'.$_SERVER['SERVER_NAME'].str_replace('./','',$val['video_file']);
+                }
+
+
+
+                //http://wx.mnw.cn/Uploads/Pictures/2/2017-08-07/2_oA7ocv8o0sk-tPmG87fjPD25nQWs_1502095440.jpg
+                if(!empty($val['image_list']))
+                {
+                    $img_arr = explode(',',$val['image_list']);
+                    if($val['image_list'] == ',undefined/undefined' || $val['image_list'] == 'undefined/undefined')
+                    {
+                        $img_url = '';
+						$img_urls = array();
+                    }else{
+						$img_urls = explode(',', $val['image_list']);
+
+						foreach($img_urls as $kk => $vv)
+						{
+							$vv = str_replace('./','/',$vv );
+
+							$vv = '/data/web/wx.mnw.cn'.$vv;
+							$img_urls[$kk] = $vv;
+						}
+
+                        //$img_url = str_replace('./','http://'.$_SERVER['SERVER_NAME'],$val['image_list']);
+                    }
+                    $tmp_data['image_list'] = $img_urls;
+                }
+                $i++;
+                $need_data[] = $tmp_data;
+            }
+            $expTitle = date('Y-m-d H:i:s');
+
+
+            export_excel($expTitle,$xlsCell,$need_data);
+
+        }
+        $this->display();
+    }
+	public function editeventreport()
+	{
+
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+		 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+		 ->addCrumb('处理上报事件', '', 'active')
+
+		 ->setModel('luojiang_eventreport')
+		 ->addFormField('jiangli', '上报奖励', 'text')
+		 ->addFormField('reply_info', '处理意见', 'text')
+
+		 ->setFormData( M('luojiang_eventreport')->find(I('get.id')) )
+		 ->setEditMap( array('id'=>I('get.id')) )
+		 ->setEditSuccessUrl( U('addon/LuojiangKaoping/web/eventreport') )
+		 ->common_edit();
+	}
+	public function opinionsuggestion()
+	{
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+			 ->addCrumb('意见建议', '', 'active')
+			 ->setModel('luojiang_opinionsuggestion')
+			 ->setListOrder('addtime desc')
+			 ->setListMap(array('mpid'=>get_mpid()))
+			 ->addListItem('fans_id', '会员名称', 'callback', array('callback_name'=>'get_fans_name'))
+			 ->addListItem('opinion_name', '建议人姓名')
+			 ->addListItem('contact', '建议人联系电话')
+			 ->addListItem('email', '邮箱')
+			 ->addListItem('title', '建议标题')
+			 ->addListItem('content', '建议内容')
+			 ->addListItem('image_list', '图片列表', 'callback', array('callback_name'=>'get_images_str'))
+			 ->addListItem('reply_method', '回复方式', 'enum', array('options'=>array('1'=>'网上',2=>'电话',3=>'当面')))
+			 //->addListItem('is_reply', '是否回复', 'enum', array('options'=>array(0=>'未回复',1=>'已回复')))
+			 ->addListItem('addtime', '创建时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
+			->addListItem('id', '操作', 'custom', array('options'=>array('edit_eventreport'=>array('处理意见建议', U('addon/LuojiangKaoping/web/editopinionsuggestion', array('id'=>'{id}')),'btn btn-primary btn-sm icon-edit',''))))
+			//->addListItem('id', '操作', 'custom', array('options'=>array('edit_fans'=>array('编辑粉丝资料', U('Mp/Fans/edit_fans', array('openid'=>'{openid}')),'btn btn-primary btn-sm icon-edit',''))))
+		     ->common_lists();
+	}
+	public function editopinionsuggestion()
+	{
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+		 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+		 ->addCrumb('处理意见建议', '', 'active')
+
+		 ->setModel('luojiang_opinionsuggestion')
+		 ->addFormField('reply_info', '处理意见', 'text')
+
+		 ->setFormData( M('luojiang_opinionsuggestion')->find(I('get.id')) )
+		 ->setEditMap( array('id'=>I('get.id')) )
+		 ->setEditSuccessUrl( U('addon/LuojiangKaoping/web/opinionsuggestion') )
+		 ->common_edit();
+
+	}
+	public function newsnenter_two()
+	{
+		$options = array(
+			'edit_fans'=>array('编辑', U('addon/LuojiangKaoping/web/editarticle', array('id'=>'{id}') )
+			,'btn btn-primary btn-sm icon-edit',''),
+			'delete' =>	array(
+				'title' => '删除',
+				'url' => U('addon/LuojiangKaoping/web/deletearticle', array('id'=>'{id}')),
+				'class' => 'btn btn-danger btn-sm icon-delete'
+			)
+		);
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+			 ->addCrumb('新闻中心', '', 'active')
+			 ->setModel('luojiang_article')
+			 ->setListMap(array('type'=>2))
+			 ->setListOrder('addtime desc')
+
+			 ->addListItem('title', '标题')
+			// ->addListItem('logo', '图片', 'image', array('attr'=>'width=50 height=50','placeholder'=>__ROOT__ . '/Public/Admin/img/noname.jpg'))
+			 ->addListItem('cate_id', '所属分类', 'callback',array('callback_name'=>'get_cate_name'))
+			 ->addListItem('sendtime', '发布时间')
+			 ->addListItem('addtime', '创建时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
+			 ->addListItem('id', '操作', 'custom', array('options'=>$options))
+			 //->addButton('新增文章分类', U('addon/HuianKaoping/web/addarticlecate'), 'btn btn-primary')
+			 ->addButton('新增文章', U('addon/LuojiangKaoping/web/addarticle_two'), 'btn btn-primary')
+			 ->common_lists();
+	}
+	public function newsnenter()
+	{
+		$options = array(
+			'edit_fans'=>array('编辑', U('addon/LuojiangKaoping/web/editarticle', array('id'=>'{id}') )
+			,'btn btn-primary btn-sm icon-edit',''),
+			'delete' =>	array(
+				'title' => '删除',
+				'url' => U('addon/LuojiangKaoping/web/deletearticle', array('id'=>'{id}')),
+				'class' => 'btn btn-danger btn-sm icon-delete'
+			)
+		);
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+			 ->addCrumb('新闻中心', '', 'active')
+			 ->setModel('luojiang_article')
+			 ->setListMap(array('type'=>1))
+			 ->setListOrder('addtime desc')
+
+			 ->addListItem('title', '标题')
+			 ->addListItem('logo', '图片', 'image', array('attr'=>'width=50 height=50','placeholder'=>__ROOT__ . '/Public/Admin/img/noname.jpg'))
+			 ->addListItem('cate_id', '所属分类', 'callback',array('callback_name'=>'get_cate_name'))
+			 ->addListItem('sendtime', '发布时间')
+			 ->addListItem('addtime', '创建时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
+			 ->addListItem('id', '操作', 'custom', array('options'=>$options))
+			 //->addButton('新增文章分类', U('addon/HuianKaoping/web/addarticlecate'), 'btn btn-primary')
+			 ->addButton('新增文章', U('addon/LuojiangKaoping/web/addarticle'), 'btn btn-primary')
+			 ->common_lists();
+	}
+
+	/**
+	 * 删除关键词回复
+	 * @author 艾逗笔<765532665@qq.com>
+	 */
+	public function deletearticle() {
+
+		M('luojiang_article')->where( array('id' =>I('get.id') ) )->delete();
+		$this->success('删除成功');
+
+	}
+	public function votecenter()
+	{
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+			 ->addCrumb('投票专区', '', 'active')
+			 ->setModel('vote')
+
+			 ->addListItem('title', '标题')
+			 ->addListItem('begin_time', '开始时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
+			 ->addListItem('end_time', '结束时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
+			 ->addListItem('addtime', '添加时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
+
+			 ->addListItem('vote_id', '操作', 'custom', array('options'=>array(
+				'edit_fans'=>array('编辑', U('addon/LuojiangKaoping/web/editvote', array('vote_id'=>'{vote_id}') ) ,'btn btn-primary btn-sm icon-edit',''),
+				'add_votesubject'=>array('添加投票选项', U('addon/LuojiangKaoping/web/addvotesubject', array('vote_id'=>'{vote_id}') ) ,'btn btn-primary btn-sm icon-edit',''),
+			 )))
+		     ->addButton('新增投票', U('addon/LuojiangKaoping/web/addvote'), 'btn btn-primary')
+			 ->common_lists();
+	}
+	public function addvote()
+	{
+		if( IS_POST )
+		{
+			$data = I('post.');
+			$vote_data = array();
+			$vote_data['mpid'] = get_mpid();
+			$vote_data['title'] = $data['name'];
+			$vote_data['begin_time'] = strtotime( $data['date_added_begin'] );
+			$vote_data['end_time'] = strtotime( $data['date_added_end'] );
+			$vote_data['addtime'] = time();
+			M('vote')->add($vote_data);
+			$this->success('添加投票成功', U('addon/LuojiangKaoping/web/votecenter'));
+			die();
+		}
+
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+			 ->addCrumb('新闻中心', '', 'active')
+			 ->display();
+	}
+	public function addvotesubject()
+	{
+		$vote_id = I('get.vote_id');
+		$this->vote_id = $vote_id;
+
+		if( IS_POST )
+		{
+			$data = I('post.');
+
+			if( isset($data['edit_votesubject']) )
+			{
+				$has_key = array();
+				$del_key = array();
+
+				foreach( $data['attr_title'] as $key => $val)
+				{
+					$has_key[] = $key;
+				}
+				$vote_sub_all =  M('vote_subject')->where( array('vote_id' => $data['vote_id']) )->select();
+
+				foreach($vote_sub_all as $vote_sub)
+				{
+					if( !in_array($vote_sub['sub_id'],$has_key ) )
+					{
+						$del_key[] = $vote_sub['sub_id'];
+					}
+				}
+				//删除多余键
+				if( !empty($del_key) )
+				{
+					M('vote_subject')->where( array('sub_id' => array('in', $del_key ) ) )->delete();
+					//删除投票记录
+					M('vote_record')->where( array('sub_id' => array('in', $del_key ) ) )->delete();
+				}
+				//开始更新和新增选项
+
+				foreach($data['attr_title'] as $key => $val)
+				{
+					if( strpos($key, 'new') !== false )
+					{
+						//新增的模块
+						$tmp_vote_subject = array();
+						$tmp_vote_subject['vote_id'] = $data['vote_id'];
+						$tmp_vote_subject['title'] = $val;
+						$tmp_vote_subject['type'] = $data['type'][$key];
+						$tmp_vote_subject['addtime'] = time();
+						M('vote_subject')->add($tmp_vote_subject);
+						$sub_id = M('vote_subject')->getLastInsID();
+
+						$extra = $data['extra'][$key];
+						$extra_arr = explode('|', $extra);
+						foreach($extra_arr as $vv)
+						{
+							$xun_data = array();
+							$xun_data['sub_id'] = $sub_id;
+							$xun_data['titile'] = $vv;
+							$xun_data['addtime'] = time();
+							M('vote_xuan')->add($xun_data);
+						}
+					} else {
+						//需要更新板块
+						$tmp_vote_subject = array();
+						$tmp_vote_subject['title'] = $val;
+						$tmp_vote_subject['type'] = $data['type'][$key];
+						M('vote_subject')->where( array('sub_id' =>$key ) ) ->save($tmp_vote_subject);
+
+						//更新子内容
+						//先判断原来有几个
+						$vote_xuan_list = M('vote_xuan')->where( array('sub_id' => $key) )->order('xu_id asc')->select();
+
+						$extra = array();
+						$extra = $data['extra'][$key];
+						$extra_arr = explode('|', $extra);
+						foreach($vote_xuan_list as $xun_vo)
+						{
+							if( !empty($extra_arr) )
+							{
+								$tmp_xun = array_shift( $extra_arr );
+								M('vote_xuan')->where( array('xu_id' => $xun_vo['xu_id']) )->save( array('titile' => $tmp_xun) );
+							}else {
+								//需要删除的
+								M('vote_xuan')->where( array('xu_id' => $xun_vo['xu_id']) )->delete();
+							}
+						}
+						//判断是否可以新增
+						if( !empty($extra_arr) )
+						{
+							foreach($extra_arr as $vv)
+							{
+								$xun_data = array();
+								$xun_data['sub_id'] = $key;
+								$xun_data['titile'] = $vv;
+								$xun_data['addtime'] = time();
+								M('vote_xuan')->add($xun_data);
+							}
+						}
+					}
+				}
+				$this->success('编辑投票选项成功', U('addon/HuianKaoping/web/votecenter'));
+				die();
+			}
+
+
+
+			foreach($data['attr_title'] as $key => $val)
+			{
+				if( !empty($val) )
+				{
+					$tmp_vote_subject = array();
+					$tmp_vote_subject['vote_id'] = $data['vote_id'];
+					$tmp_vote_subject['title'] = $val;
+					$tmp_vote_subject['type'] = $data['type'][$key];
+					$tmp_vote_subject['addtime'] = time();
+					M('vote_subject')->add($tmp_vote_subject);
+					$sub_id = M('vote_subject')->getLastInsID();
+
+					$extra = $data['extra'][$key];
+					//vote_xuan
+					$extra_arr = explode('|', $extra);
+					foreach($extra_arr as $vv)
+					{
+						$xun_data = array();
+						$xun_data['sub_id'] = $sub_id;
+						$xun_data['titile'] = $vv;
+						$xun_data['addtime'] = time();
+						M('vote_xuan')->add($xun_data);
+					}
+				}
+			}
+
+			$this->success('新增投票选项成功', U('addon/HuianKaoping/web/votecenter'));
+			die();
+
+		}
+
+		$vote_subject = M('vote_subject')->where( array('vote_id' => $vote_id) )->order('sub_id asc')->select();
+
+		if( !empty($vote_subject) )
+		{
+			foreach( $vote_subject as $key=> $val )
+			{
+				$vote_xuan_list = M('vote_xuan')->where( array('sub_id' => $val['sub_id']) )->order('xu_id asc')->select();
+				$xun_arr = array();
+
+				foreach( $vote_xuan_list as $vv )
+				{
+					$xun_arr[] = $vv['titile'];
+				}
+
+				$val['xun_title'] =  implode('|', $xun_arr);
+				$val['vote_xuan_list'] = $vote_xuan_list;
+				$vote_subject[$key] = $val;
+			}
+
+			$this->vote_subject = $vote_subject;
+
+
+
+			$this->addCrumb('洛江考评微官网', U('addon/HuianKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/HuianKaoping/web/eventreport'), '')
+			 ->addCrumb('新闻中心', '', 'active')
+			 ->display('editvotesubject');
+		} else {
+			$this->addCrumb('洛江考评微官网', U('addon/HuianKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/HuianKaoping/web/eventreport'), '')
+			 ->addCrumb('新闻中心', '', 'active')
+			 ->display();
+		}
+	}
+	public function loadachievement()
+	{
+        $type = I('type');
+		if( IS_POST )
+		{
+            set_time_limit(0);
+			  if(isset($_FILES["file"]) && ($_FILES["file"]["error"] == 0)){
+
+
+				  $excel_dir = './Uploads/Pictures/' . date('Y-m-d') . '/';
+					if (!file_exists($excel_dir)) {
+						$dirs = explode('/', $excel_dir);
+						$dir = $dirs[0] . '/';
+						for ($i=1, $j=count($dirs)-1; $i<$j; $i++) {
+							$dir .= $dirs[$i] . '/';
+							if (!is_dir($dir)) {
+								mkdir($dir, 0777);
+							}
+						}
+					}
+
+				  $extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
+
+
+				  $path = $excel_dir.'/'.md5($_FILES['file']['name'].mt_rand(1, 999)).'.'.$extension;
+				  $rs = move_uploaded_file($_FILES["file"]["tmp_name"],$path);
+
+
+
+				$file = $path;
+				$type = pathinfo($file);
+				$type = strtolower($type["extension"]);
+				$type=$type==='csv' ? $type : 'Excel5';
+				ini_set('max_execution_time', '0');
+				vendor("PHPExcel.PHPExcel");
+				// 判断使用哪种格式
+				$objReader = \PHPExcel_IOFactory::createReader($type);
+				$objPHPExcel = $objReader->load($file);
+				$sheet = $objPHPExcel->getSheet(0);
+				// 取得总行数
+				$highestRow = $sheet->getHighestRow();
+				// 取得总列数
+				$highestColumn = $sheet->getHighestColumn();
+				//循环读取excel文件,读取一条,插入一条
+				$data=array();
+				//从第一行开始读取数据
+				for($j=1;$j<=$highestRow;$j++){
+					if($j <=2) {
+						continue;
+					}
+					//从A列读取数据
+					for($k='A';$k<=$highestColumn;$k++){
+						// 读取单元格
+						$data[$j][]=$objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue();
+					}
+				}
+
+				$result = $data;
+				$get_data = array();
+				if(!empty($result)) {
+					foreach($result as $key => $val){
+
+						//array(5) { [0]=> string(6) "村庄" [1]=> string(18) "2017-8月上半月"
+						//[2]=> string(9) "小岞镇" [3]=> string(9) "新桥村" [4]=> float(92.5) }
+						if(empty($val[0]))
+						{
+							continue;
+						}
+						//$val[1] = str_replace('上半月','01',$val[1]);
+						//$val[1] = str_replace('下半月','15',$val[1]);
+
+
+
+						//$val[1] = $val[1]->__toString();
+						$val[1] .= ' 00:00:00';
+						//$val[1] = str_replace('年','-',$val[1]);
+						//$val[1] = str_replace('月','',$val[1]);
+
+						$need_data = array();
+						$need_data['name'] = $val[0];
+						$need_data['kao_time'] = strtotime($val[1]);
+						$need_data['zeren_danwei'] = $val[2];
+						$need_data['stree'] = $val[3];
+						$need_data['kaoping_dian'] = '';
+						$need_data['chengji'] = $val[4];
+                        if(I('type') == 2)
+                        {
+                            $need_data['type'] = 2;
+                        }else{
+                            $need_data['type'] = 1;
+                        }
+						if(empty($need_data['stree']))
+                        {
+                            $need_data['stree'] = '';
+                        }
+						$need_data['paiming'] = 0;
+						$need_data['addtime'] = time();
+						M('luojiang_achievement')->add($need_data);
+					}
+                    if(I('type') == 2){
+                        $this->success('导入成绩成功', U('addon/LuojiangKaoping/web/achievementmanage_two'));
+                    }else{
+                        $this->success('导入成绩成功', U('addon/LuojiangKaoping/web/achievementmanage'));
+                    }
+					die();
+				}
+			  }
+		}
+        $this->assign('type', $type);
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+			 ->addCrumb('成绩管理', '', 'active')
+			 ->display();
+	}
+
+	public function editvote()
+	{
+		// /vote_id/1
+		$vote_id = I('get.vote_id');
+
+		if( IS_POST )
+		{
+			$data = I('post.');
+
+			$data = I('post.');
+			$vote_data = array();
+			$vote_data['mpid'] = get_mpid();
+			$vote_data['title'] = $data['name'];
+			$vote_data['begin_time'] = strtotime( $data['date_added_begin'] );
+			$vote_data['end_time'] = strtotime( $data['date_added_end'] );
+
+			M('vote')->where( array('vote_id' => $data['vote_id']) )->save($vote_data);
+
+			$this->success('编辑投票成功', U('addon/HuianKaoping/web/votecenter'));
+			die();
+		}
+
+		$vote = M('vote')->where( array('vote_id' => $vote_id) )->find();
+
+		$this->vote = $vote;
+
+		$this->addCrumb('洛江考评微官网', U('addon/HuianKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/HuianKaoping/web/eventreport'), '')
+			 ->addCrumb('新闻中心', '', 'active')
+			 ->display('addvote');
+	}
+
+	public function editachievement()
+	{
+		$id = I('get.id');
+		$type = I('get.type');
+		if( IS_POST )
+		{
+			$data = I('post.');
+
+
+			$vote_data = array();
+			$vote_data['name'] = $data['name'];
+			$vote_data['kao_time'] = strtotime( $data['kao_time'] );
+			$vote_data['zeren_danwei'] = $data['zeren_danwei'];
+			$vote_data['stree'] = $data['stree'];
+			$vote_data['content'] = ($data['content']);
+			//$vote_data['kaoping_dian'] = $data['kaoping_dian'];
+			$vote_data['chengji'] = $data['chengji'];
+			//$vote_data['paiming'] = $data['paiming'];
+			M('luojiang_achievement')->where( array('id' => $id) )->save($vote_data);
+
+            if($data['type'] == 2)
+            {
+                $this->success('编辑成功', U('addon/LuojiangKaoping/web/achievementmanage_two'));
+            }else{
+                $this->success('编辑成功', U('addon/LuojiangKaoping/web/achievementmanage'));
+            }
+
+			die();
+		}
+
+        if($type == 2)
+        {
+            $this->setEditSuccessUrl( U('addon/LuojiangKaoping/web/achievementmanage_two') );
+        }else{
+            $this->setEditSuccessUrl( U('addon/LuojiangKaoping/web/achievementmanage') );
+        }
+        $this->assign('type', $type);
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+		 ->addCrumb('成绩管理', U('addon/LuojiangKaoping/web/achievementmanage'), '')
+		 ->addCrumb('成绩管理', '', 'active')
+		 ->setModel('luojiang_achievement')
+		 ->addFormField('name', '类别', 'text')
+		 ->addFormField('kao_time', '考评时间', 'date')
+		 ->addFormField('zeren_danwei', '街道(乡镇)/责任单位', 'text')
+		 ->addFormField('stree', '抽评点', 'text')
+		 ->addFormField('content', '内容', 'editor')
+		 //->addFormField('kaoping_dian', '考评点', 'text')
+		 ->addFormField('chengji', '成绩', 'text')
+		 //->addFormField('paiming', '排名', 'text')
+
+		 ->setEditMap( array('id'=>I('get.id')))
+		 ->common_edit();
+
+	}
+	public function get_cate_name($cate_id)
+	{
+		$category_info =  M('luojiang_articlecategory')->where( array('id' => $cate_id) )->find();
+		return $category_info['name'];
+	}
+
+	public function editarticle()
+	{
+		$cateinfos = M('luojiang_articlecategory')->where( array('pid' => 0) )->select();
+
+		$cate_arr = array();
+		foreach($cateinfos as $val)
+		{
+			$cate_arr[$val[id]] = $val['name'];
+		}
+
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+		 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+		 ->addCrumb('编辑文章', '', 'active')
+		 ->setModel('huian_article')
+		 ->addFormField('title', '标题', 'text')
+		 ->addFormField('link', '外链', 'text')
+		 ->addFormField('logo', '图片', 'image')
+		 ->addFormField('sendtime', '发布时间', 'time')
+		 ->addFormField('cate_id', '所属分类', 'select', array('options'=>$cate_arr))
+		 ->addFormField('content', '内容', 'editor')
+		 ->setValidate(array(
+				array('name', 'require', '标题不能为空')//,
+				//array('logo', 'require', '请上传图片')
+		   ))
+		 ->setFormData( M('luojiang_article')->find(I('get.id')) )
+		 ->setEditMap( array('id'=>I('get.id')) )
+		 ->setEditSuccessUrl( U('addon/LuojiangKaoping/web/newsnenter') )
+		 ->common_edit();
+
+
+	}
+	public function addarticlecate()
+	{
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+			 ->addCrumb('添加文章分类', '', 'active')
+			 ->setModel('luojiang_articlecategory')
+			 ->addFormField('name', '名称', 'text')
+			 //->addFormField('type', '类型', 'radio', array('options'=>array(1=>'普通订阅号',2=>'认证订阅号',3=>'普通服务号',4=>'认证服务号',5=>'测试号'),'value'=>4,'is_must'=>1))
+			// ->addFormField('pid', '原始ID', 'text', array('is_must'=>1))
+			 //->addFormField('mp_number', '微信号', 'text')
+			// ->addFormField('appid', 'APPID', 'text')
+			// ->addFormField('appsecret', 'APPSECRET', 'text')
+			 //->addFormField('headimg', '头像', 'image')
+			 //->addFormField('qrcode', '二维码', 'image')
+			 ->setValidate(array(
+					array('name', 'require', '名称不能为空'),
+			   ))
+			 ->setAuto(array(
+					array('pid', '0'),
+					array('addtime', 'time', 1, 'function')
+			 ))
+			 ->setAddSuccessUrl( U('addon/LuojiangKaoping/web/newsnenter') )
+			 ->common_add();
+	}
+
+	public function addarticle_two()
+	{
+		$cateinfos = M('luojiang_articlecategory')->where( array('pid' => 0) )->select();
+
+		$cate_arr = array();
+		foreach($cateinfos as $val)
+		{
+			$cate_arr[$val[id]] = $val['name'];
+		}
+
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+			 ->addCrumb('添加文章', '', 'active')
+			 ->setModel('luojiang_article')
+			 ->addFormField('title', '标题', 'text')
+			 ->addFormField('type', '1', 'hidden',array('value'=>2))
+			 //->addFormField('link', '外链', 'text')
+			 //->addFormField('logo', '图片', 'image')
+			 ->addFormField('sendtime', '发布时间', 'time')
+			 ->addFormField('cate_id', '1', 'hidden',array('value'=>1))
+			 //->addFormField('cate_id', '所属分类', 'select', array('options'=>$cate_arr))
+			 ->addFormField('content', '内容', 'editor')
+			 ->setValidate(array(
+					array('name', 'require', '标题不能为空'),
+					//array('logo', 'require', '请上传图片')
+			   ))
+			 ->setAuto(array(
+					array('addtime', 'time', 1, 'function')
+			   ))
+			 ->setAddSuccessUrl( U('addon/LuojiangKaoping/web/newsnenter_two') )
+			 ->common_add();
+	}
+
+	public function addarticle()
+	{
+		$cateinfos = M('luojiang_articlecategory')->where( array('pid' => 0) )->select();
+
+		$cate_arr = array();
+		foreach($cateinfos as $val)
+		{
+			$cate_arr[$val[id]] = $val['name'];
+		}
+
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+			 ->addCrumb('添加文章', '', 'active')
+			 ->setModel('luojiang_article')
+			 ->addFormField('title', '标题', 'text')
+			 ->addFormField('type', '1', 'hidden',array('value'=>1))
+			 ->addFormField('link', '外链', 'text')
+			 ->addFormField('logo', '图片', 'image')
+			 ->addFormField('sendtime', '发布时间', 'time')
+			 ->addFormField('cate_id', '所属分类', 'select', array('options'=>$cate_arr))
+			 ->addFormField('content', '内容', 'editor')
+			 ->setValidate(array(
+					array('name', 'require', '标题不能为空')//,
+					//array('logo', 'require', '请上传图片')
+			   ))
+			 ->setAuto(array(
+					array('addtime', 'time', 1, 'function')
+			   ))
+			 ->setAddSuccessUrl( U('addon/LuojiangKaoping/web/newsnenter') )
+			 ->common_add();
+	}
+	public function achievementmanage()
+	{
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+			 ->addCrumb('乡镇成绩管理', '', 'active')
+			 ->setModel('luojiang_achievement')
+			 ->setListOrder('addtime desc')
+			 ->addListItem('name', '类别')
+            //->addListItem('kao_time', '考评时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
+             ->setListMap(array('type'=>1))
+             ->addListItem('kao_time', '考评时间', 'callback', array('callback_name'=>'get_date_hui'))
+			 ->addListItem('zeren_danwei', '街道办事处')
+			 ->addListItem('stree', '抽评点')
+			 //->addListItem('kaoping_dian', '考评点')
+			 ->addListItem('chengji', '成绩')
+			 //->addListItem('paiming', '排名')
+			 ->addListItem('addtime', '添加时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
+			 ->addButton('导入考评成绩', U('addon/LuojiangKaoping/web/loadachievement'), 'btn btn-primary')
+			 ->addListItem('id', '操作', 'custom', array('options'=>array('edit_fans'=>array('编辑成绩', U('addon/LuojiangKaoping/web/editachievement', array('id'=>'{id}','type'=>1)),'btn btn-primary btn-sm icon-edit',''))))
+		     ->common_lists();
+
+		$cjcount = M('luojiang_achievement')->where(array('paiming'=>0,'type'=>1))->count();
+		if($cjcount>0)
+		{
+			$paiming = array();
+			$pagecount = M('luojiang_achievement')->field('kao_time')->where(array('type'=>1))->group('kao_time')->order('kao_time desc')->select();
+			foreach($pagecount as $val)
+			{
+				$data = M('luojiang_achievement')->field('id,chengji')->where(array("kao_time"=>$val['kao_time'],"type"=>1))->order('chengji desc, id asc')->select();
+				$chengji = $data[0]['chengji'];
+				$order = 1;$num = 0;
+				foreach($data as $key=>$subval)
+				{
+					if($key != 0){
+						if($subval["chengji"] < $chengji){
+							$order += 1;
+							$chengji = $subval['chengji'];
+							$order += $num;
+							$num = 0;
+						}
+						else {
+							$num++;
+						}
+					}
+					$paiming[] = array('id'=>$subval["id"],'paiming'=>$order);
+				}
+				krsort($data);
+				$chengji = $data[count($data)-1]['chengji'];
+				$order = -5;$num = 0;
+				foreach($data as $key=>$subval)
+				{
+					if($key != count($data)-1){
+						if($subval["chengji"] > $chengji){
+							$order += 1;
+							$chengji = $subval['chengji'];
+							$order += $num;
+							$num = 0;
+						}
+						else {
+							$num++;
+						}
+					}
+					if($order == 0) break;
+					$paiming[] = array('id'=>$subval["id"],'paiming'=>$order);
+				}
+			}
+			foreach($paiming as $val)
+			{
+				$data['paiming'] = $val['paiming'];
+				M('luojiang_achievement')->where(array("id"=>$val['id']))->save($data);
+			}
+		}
+	}
+
+	 public function achievementmanage_two()
+    {
+        $this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+            ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+            ->addCrumb('部门成绩管理', '', 'active')
+            ->setModel('luojiang_achievement')
+            ->setListOrder('addtime desc')
+            ->setListMap(array('type'=>2))
+            ->addListItem('name', '类别')
+            //->addListItem('kao_time', '考评时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
+            ->addListItem('kao_time', '考评时间', 'callback', array('callback_name'=>'get_date_hui'))
+            ->addListItem('zeren_danwei', '部门')
+            ->addListItem('stree', '考评对象')
+            //->addListItem('kaoping_dian', '考评点')
+            ->addListItem('chengji', '成绩')
+            //->addListItem('paiming', '排名')
+            ->addListItem('addtime', '添加时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
+            ->addButton('导入考评成绩', U('addon/LuojiangKaoping/web/loadachievement',array('type'=>2)), 'btn btn-primary')
+            ->addListItem('id', '操作', 'custom', array('options'=>array('edit_fans'=>array('编辑成绩', U('addon/HuianKaoping/web/editachievement', array('id'=>'{id}','type'=>2)),'btn btn-primary btn-sm icon-edit',''))))
+            ->common_lists();
+
+        $cjcount = M('luojiang_achievement')->where(array('paiming'=>0,'type'=>2))->count();
+        if($cjcount>0)
+        {
+            $paiming = array();
+            $pagecount = M('luojiang_achievement')->field('kao_time')->where(array('type'=>2))->group('kao_time')->order('kao_time desc')->select();
+            foreach($pagecount as $val)
+            {
+                $data = M('luojiang_achievement')->field('id,chengji')->where(array("kao_time"=>$val['kao_time'],'type'=>2))->order('chengji desc, id asc')->select();
+                $chengji = $data[0]['chengji'];
+                $order = 1;$num = 0;
+                foreach($data as $key=>$subval)
+                {
+                    if($key != 0){
+                        if($subval["chengji"] < $chengji){
+                            $order += 1;
+                            $chengji = $subval['chengji'];
+                            $order += $num;
+                            $num = 0;
+                        }
+                        else {
+                            $num++;
+                        }
+                    }
+                    $paiming[] = array('id'=>$subval["id"],'paiming'=>$order);
+                }
+                krsort($data);
+                $chengji = $data[count($data)-1]['chengji'];
+                $order = -5;$num = 0;
+                foreach($data as $key=>$subval)
+                {
+                    if($key != count($data)-1){
+                        if($subval["chengji"] > $chengji){
+                            $order += 1;
+                            $chengji = $subval['chengji'];
+                            $order += $num;
+                            $num = 0;
+                        }
+                        else {
+                            $num++;
+                        }
+                    }
+                    if($order == 0) break;
+                    $paiming[] = array('id'=>$subval["id"],'paiming'=>$order);
+                }
+            }
+            foreach($paiming as $val)
+            {
+                $data['paiming'] = $val['paiming'];
+                M('luojiang_achievement')->where(array("id"=>$val['id']))->save($data);
+            }
+        }
+    }
+
+	public function get_date_hui($kao_time)
+	{
+		$d = date('d',$kao_time);
+		/**
+		if($d == '15')
+		{
+			$kao_time = date('Y-m',$kao_time).'-下半月';
+		} else {
+			$kao_time = date('Y-m',$kao_time).'-上半月';
+
+		}
+		**/
+		$kao_time = date('Y-m-d',$kao_time);
+		return $kao_time;
+	}
+	public function usermanage()
+	{
+
+		//->addListItem('msgid', '消息内容', 'callback', array('callback_name'=>'get_message_content'))
+
+		$this->addCrumb('洛江考评微官网', U('addon/LuojiangKaoping/index'), '')
+			 ->addCrumb('业务导航', U('addon/LuojiangKaoping/web/eventreport'), '')
+			 ->addCrumb('用户管理', '', 'active')
+			 ->setModel('luojiang_eventreport')
+			 ->setListMap(array('mpid'=>get_mpid()))
+			 ->addListItem('fans_id', '会员名称', 'callback', array('callback_name'=>'get_fans_name'))
+			 ->addListItem('event_type', '事件类型', 'enum', array('options'=>array('0'=>'未知',1=>'事件类型1',2=>'事件类型2',3=>'事件类型3')))
+			 ->addListItem('title', '标题')
+			 ->addListItem('descript', '事件描述')
+			 ->addListItem('image_list', '图片列表', 'callback', array('callback_name'=>'get_images_str'))
+			 ->addListItem('is_reply', '是否回复', 'enum', array('options'=>array(0=>'未回复',1=>'已回复')))
+			 ->addListItem('location_addr', '位置', '', array('placeholder'=>'未提供'))
+			 ->addListItem('addtime', '创建时间', 'function', array('function_name'=>'date','params'=>'Y-m-d H:i:s,###'))
+			 ->addListItem('id', '操作', 'custom', array('options'=>array('edit_fans'=>array('编辑粉丝资料', U('Mp/Fans/edit_fans', array('openid'=>'{openid}')),'btn btn-primary btn-sm icon-edit',''))))
+		     ->common_lists();
+	}
+	function get_images_str($image_list)
+	{
+		$image_arr = explode(',', $image_list);
+		$image_str = '';
+		$image_need_arr = array();
+
+		if( !empty($image_arr) )
+		{
+			foreach($image_arr as $img)
+			{
+				$img = str_replace('./Uploads/','/Uploads/',$img);
+				$img = str_replace('//','/',$img);
+				$imgtemp = explode('.',$img);
+				//$thumb_img =  $this->resize($img,100,100);
+				$image_need_arr[] = "<div style='float:left;width:100px;margin-right:5px;'><img src='".$img."' width=100 height=100 'placeholder'= '".__ROOT__ ."/Public/Admin/img/noname.jpg' /><br/>【<a href='".$img."' target='_blank'>预览</a> | <a href='".U('addon/HuianKaoping/web/downfile', array('type' =>$imgtemp[1], 'file_url' => urlencode($img) ))."' target='_blank'>下载】</a></div>";
+			}
+			$image_str = implode(' ', $image_need_arr);
+		}
+		return "<div style='width:220px;'> ".$image_str."</div>";
+
+	}
+	//字符串截取
+function utf8_substr($string, $offset, $length = null) {
+	// generates E_NOTICE
+	// for PHP4 objects, but not PHP5 objects
+	$string = (string)$string;
+	$offset = (int)$offset;
+
+	if (!is_null($length)) {
+		$length = (int)$length;
+	}
+
+	// handle trivial cases
+	if ($length === 0) {
+		return '';
+	}
+
+	if ($offset < 0 && $length < 0 && $length < $offset) {
+		return '';
+	}
+
+	// normalise negative offsets (we could use a tail
+	// anchored pattern, but they are horribly slow!)
+	if ($offset < 0) {
+		$strlen = strlen(utf8_decode($string));
+		$offset = $strlen + $offset;
+
+		if ($offset < 0) {
+			$offset = 0;
+		}
+	}
+
+	$Op = '';
+	$Lp = '';
+
+	// establish a pattern for offset, a
+	// non-captured group equal in length to offset
+	if ($offset > 0) {
+		$Ox = (int)($offset / 65535);
+		$Oy = $offset%65535;
+
+		if ($Ox) {
+			$Op = '(?:.{65535}){' . $Ox . '}';
+		}
+
+		$Op = '^(?:' . $Op . '.{' . $Oy . '})';
+	} else {
+		$Op = '^';
+	}
+
+	// establish a pattern for length
+	if (is_null($length)) {
+		$Lp = '(.*)$';
+	} else {
+		if (!isset($strlen)) {
+			$strlen = strlen(utf8_decode($string));
+		}
+
+		// another trivial case
+		if ($offset > $strlen) {
+			return '';
+		}
+
+		if ($length > 0) {
+			$length = min($strlen - $offset, $length);
+
+			$Lx = (int)($length / 65535);
+			$Ly = $length % 65535;
+
+			// negative length requires a captured group
+			// of length characters
+			if ($Lx) {
+				$Lp = '(?:.{65535}){' . $Lx . '}';
+			}
+
+			$Lp = '(' . $Lp . '.{' . $Ly . '})';
+		} elseif ($length < 0) {
+			if ($length < ($offset - $strlen)) {
+				return '';
+			}
+
+			$Lx = (int)((-$length) / 65535);
+			$Ly = (-$length)%65535;
+
+			// negative length requires ... capture everything
+			// except a group of  -length characters
+			// anchored at the tail-end of the string
+			if ($Lx) {
+				$Lp = '(?:.{65535}){' . $Lx . '}';
+			}
+
+			$Lp = '(.*)(?:' . $Lp . '.{' . $Ly . '})$';
+		}
+	}
+
+	if (!preg_match( '#' . $Op . $Lp . '#us', $string, $match)) {
+		return '';
+	}
+
+	return $match[1];
+
+}
+/**
+ * 递归生成目录
+ */
+function RecursiveMkdir($path) {
+	if (!file_exists($path)) {
+		$this->RecursiveMkdir(dirname($path));
+		@mkdir($path, 0777);
+	}
+}
+
+
+//字符串长度计算
+function utf8_strlen($string) {
+	return strlen(utf8_decode($string));
+}
+
+function utf8_strrpos($string, $needle, $offset = null) {
+	if (is_null($offset)) {
+		$data = explode($needle, $string);
+
+		if (count($data) > 1) {
+			array_pop($data);
+
+			$string = join($needle, $data);
+
+			return $this->utf8_strlen($string);
+		}
+
+		return false;
+	} else {
+		if (!is_int($offset)) {
+			trigger_error('utf8_strrpos expects parameter 3 to be long', E_USER_WARNING);
+
+			return false;
+		}
+
+		$string = $this->utf8_substr($string, $offset);
+
+		if (false !== ($position = utf8_strrpos($string, $needle))) {
+			return $position + $offset;
+		}
+
+		return false;
+	}
+}
+
+	/**
+ * 自动生成新尺寸 的图片
+ */
+	function resize($filename, $width, $height) {
+			define(ROOT_PATH,'/data/web/wx.mnw.cn/');
+			///data/web/wx.mnw.cn/Addons/HuianKaoping/Controller
+
+		$image_dir=ROOT_PATH;
+
+
+		if (!is_file($image_dir . $filename)) {
+			return;
+		}
+
+		$extension = pathinfo($filename, PATHINFO_EXTENSION);
+
+		$old_image = $filename;
+		$new_image = 'cache/' . $this->utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
+
+		if (!is_file($image_dir . $new_image) || (filectime($image_dir . $old_image) > filectime($image_dir . $new_image))) {
+			$path = '';
+
+			$directories = explode('/', dirname(str_replace('../', '', $new_image)));
+
+			foreach ($directories as $directory) {
+				$path = $path . '/' . $directory;
+
+				if (!is_dir($image_dir . $path)) {
+					@mkdir($image_dir . $path, 0777);
+				}
+			}
+
+			list($width_orig, $height_orig) = getimagesize($image_dir . $old_image);
+
+			if ($width_orig != $width || $height_orig != $height) {
+				$image = new \Lib\Image($image_dir . $old_image);
+			$image->resize($width, $height);
+				$image->save($image_dir . $new_image);
+			} else {
+				copy($image_dir . $old_image, $image_dir . $new_image);
+			}
+		}
+
+		return 'Uploads/image/' . $new_image;
+
+		}
+
+	public function get_fans_name($fans_id)
+	{
+		$fans_info = M('mp_fans')->where( array('id' => $fans_id) )->find();
+		return $fans_info['nickname'];
+		//return '<a href="'.U('Mp/Fans/edit_fans', array('openid'=>$fans_info['openid'])).'" target="_blank" title="点击查看用户信息">'.$fans_info['nickname'].'</a>';
+	}
+
+}
+
+?>

+ 0 - 0
Modules/Lib/Weixin/Wxfy.class.php → Modules/Lib/Weixin/Wxfy.class.php.back


Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä