CartController.class.php 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000
  1. <?php
  2. /**
  3. * 小梦科技资源nanodreamtech.com
  4. *
  5. * ==========================================================================
  6. * @link https://www.nanodreamtech.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license https://www.nanodreamtech.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Home\Controller;
  15. class CartController extends CommonController {
  16. public function add()
  17. {
  18. global $_W;
  19. global $_GPC;
  20. $data = array();
  21. $data['goods_id'] = $_GPC['goods_id'];
  22. $data['community_id'] = $_GPC['community_id'];
  23. $data['quantity'] = $_GPC['quantity'];
  24. $data['sku_str'] = $_GPC['sku_str'];
  25. if($_GPC['sku_str'] == 'undefined')
  26. {
  27. $_GPC['sku_str'] = '';
  28. $data['sku_str'] = '';
  29. }
  30. $data['buy_type'] = $_GPC['buy_type'];
  31. $data['pin_id'] = $_GPC['pin_id'];
  32. $data['is_just_addcar'] = $_GPC['is_just_addcar'];
  33. if( !isset($data['buy_type']) || empty($data['buy_type']) )
  34. {
  35. $data['buy_type'] = 'dan';
  36. }
  37. $token = $_GPC['token'];
  38. $token_param = array();
  39. $token_param[':uniacid'] = $_W['uniacid'];
  40. $token_param[':token'] = $token;
  41. $weprogram_token = pdo_fetch("select member_id from ".tablename('lionfish_comshop_weprogram_token')." where uniacid=:uniacid and token=:token limit 1", $token_param);
  42. $member_id = $weprogram_token['member_id'];
  43. $is_just_addcar = empty($data['is_just_addcar']) ? 0: 1;
  44. $goods_id = $data['goods_id'];
  45. if( empty($member_id))
  46. {
  47. $result = array('code' =>4);
  48. echo json_encode($result);
  49. die();
  50. }
  51. if (isset($data['goods_id'])) {
  52. $goods_id = $data['goods_id'];
  53. } else {
  54. $goods_id = 0;
  55. }
  56. $goods_param = array();
  57. $goods_sql = "select * from ".tablename('lionfish_comshop_goods')." where uniacid=:uniacid and id=:id limit 1";
  58. $product = pdo_fetch($goods_sql, array(':uniacid' => $_W['uniacid'], ':id' => $goods_id));
  59. if( $product['grounding'] != 1)
  60. {
  61. $json['code'] =6;
  62. $json['msg']='商品已下架!';
  63. echo json_encode($json);
  64. die();
  65. }
  66. //判断是否积分兑换
  67. if( $product['type'] == 'integral')
  68. {
  69. //判断积分是否足够 member_id 暂时关闭以下代码
  70. /**
  71. $integral_model = D('Seller/Integral');
  72. $check_result = $integral_model->check_user_score_can_pay($member_id, $data['sku_str'], $goods_id);
  73. if( $check_result['code'] == 1 )
  74. {
  75. $json['code'] =6;
  76. $json['msg']='剩余'.$check_result['cur_score'].'积分,积分不足!';
  77. echo json_encode($json);
  78. die();
  79. }
  80. **/
  81. }
  82. //6
  83. if($is_just_addcar == 1)
  84. {
  85. if($product['pick_just'] > 0)
  86. {
  87. $json['code'] =6;
  88. $json['msg']='自提商品,请立即购买';
  89. echo json_encode($json);
  90. die();
  91. }
  92. }
  93. //商品存在
  94. if($product){
  95. $cart= load_model_class('car');
  96. if (isset($data['quantity'])) {
  97. $quantity = $data['quantity'];
  98. } else {
  99. $quantity = 1;
  100. }
  101. $option = array();
  102. if( !empty($data['sku_str'])){
  103. $option = explode('_', $data['sku_str']);
  104. }
  105. $cart_goods_quantity = $cart->get_wecart_goods($goods_id,$data['sku_str'],$data['community_id'] ,$token);
  106. $json=array('code' =>0);
  107. //$goods_model = D('Home/Goods');
  108. $goods_quantity=$cart->get_goods_quantity($goods_id);
  109. //检测商品限购 6
  110. $can_buy_count = D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
  111. $goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'total_limit_count');
  112. if($can_buy_count == -1)
  113. {
  114. $json['code'] =6;
  115. //$json['msg']='已经不能再买了';
  116. $json['msg']='每人最多购买'.$goods_description['total_limit_count'].'个哦';
  117. echo json_encode($json);
  118. die();
  119. }else if($can_buy_count >0 && $quantity >$can_buy_count)
  120. {
  121. $json['code'] =6;
  122. $json['msg']='您还能购买'.$can_buy_count.'份';
  123. echo json_encode($json);
  124. die();
  125. }
  126. //已加入购物车的总数
  127. if($goods_quantity<$quantity+$cart_goods_quantity){
  128. $json['code'] =3;
  129. if ($goods_quantity==0) {
  130. $json['msg']='已抢光';
  131. }else{
  132. $json['msg']='商品数量不足,剩余'.$goods_quantity.'个!!';
  133. }
  134. echo json_encode($json);
  135. die();
  136. }
  137. //rela_goodsoption_valueid
  138. if(!empty($option))
  139. {
  140. $mul_opt_arr = array();
  141. //ims_
  142. $mult_sql = "select * from ".tablename('lionfish_comshop_goods_option_item_value')."
  143. where uniacid=:uniacid and option_item_ids = :sku_str and goods_id =:goods_id limit 1 ";
  144. $goods_option_mult_value = pdo_fetch($mult_sql, array(':uniacid' => $_W['uniacid'],':sku_str' =>$data['sku_str'],':goods_id' => $goods_id ));
  145. if( !empty($goods_option_mult_value) )
  146. {
  147. if($goods_option_mult_value['stock']<$quantity+$cart_goods_quantity){
  148. $json['code'] =3;
  149. $json['msg']='商品数量不足,剩余'.$goods_option_mult_value['stock'].'个!!';
  150. echo json_encode($json);
  151. die();
  152. }
  153. }
  154. }
  155. //buy_type
  156. // $this->clear_all_cart(); $data['community_id']
  157. $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']);
  158. //区分活动商品还是普通商品。做两个购物车,活动商品是需要直接购买的,单独购买商品加入正常的购物车TODO....
  159. //is_just_addcar 0 1
  160. if($data['buy_type'] == 'dan' && $is_just_addcar == 0)
  161. {
  162. //$cart->removedancar($token);
  163. //清空一下购物车
  164. //singledel
  165. $format_data_array['is_just_addcar'] = 0;
  166. $format_data_array['singledel'] = 1;
  167. $cart->addwecar($token,$goods_id,$format_data_array,$data['sku_str'],$data['community_id']);
  168. $total=$cart->count_goodscar($token ,$data['community_id']);
  169. }
  170. else if($data['buy_type'] == 'dan' && $is_just_addcar == 1)
  171. {
  172. //singledel
  173. $format_data_array['is_just_addcar'] = 1;
  174. $format_data_array['singledel'] = 1;
  175. $cart->addwecar($token,$goods_id,$format_data_array,$data['sku_str'],$data['community_id']);
  176. $total=$cart->count_goodscar($token, $data['community_id']);
  177. }
  178. else {
  179. //buy_type:pin 活动购物车。
  180. $pin_id = isset($data['pin_id']) ? $data['pin_id'] : 0;
  181. //lottery
  182. if( $product['type'] == 'lottery' && $product['type'] == 'lottery' )
  183. {
  184. /**
  185. //等待把抽奖的活动打开
  186. $now_time = time();
  187. $lottery_goods_info = M('lottery_goods')->where( array('goods_id' => $goods_id) )->find();
  188. if($lottery_goods_info['end_time'] < $now_time)
  189. {
  190. $json['code'] =6;
  191. $json['msg']='抽奖活动已结束';
  192. echo json_encode($json);
  193. die();
  194. }
  195. **/
  196. }
  197. //检测商品是否老带新,新人才能参团
  198. if($pin_id > 0 )
  199. {
  200. //等待把老带新的活动打开
  201. /**
  202. if($product['type'] == 'newman')
  203. {
  204. $new_mamn_buy = $goods_model->check_goods_new_manbug($member_id);
  205. if($new_mamn_buy>0)
  206. {
  207. $json['code'] =5;
  208. $json['msg']='该商品只能新人参团';
  209. echo json_encode($json);
  210. die();
  211. }
  212. }
  213. **/
  214. }
  215. $format_data_array['pin_id'] = $pin_id;
  216. $cart->add_activitycar($token, $goods_id,$format_data_array,$data['sku_str']);
  217. $total=$cart->count_activitycar($token);
  218. }
  219. $car_total_sql = "select * from ".tablename('lionfish_comshop_car')." where token=:token and community_id=:community_id and uniacid=:uniacid and carkey ='cart_total' ";
  220. $carts = pdo_fetch($car_total_sql, array(':token' => $token,':community_id' => $data['community_id'],':uniacid' => $_W['uniacid']));
  221. if( !empty($carts) )
  222. {
  223. $car_data = array();
  224. $car_data['format_data'] = serialize(array('quantity' => $total));
  225. $car_data['modifytime'] = 1;
  226. pdo_update('lionfish_comshop_car', $car_data, array('token' => $token,'community_id' => $data['community_id'],'carkey' => 'cart_total'));
  227. } else{
  228. $car_data = array();
  229. $car_data['token'] = $token;
  230. $car_data['uniacid'] = $_W['uniacid'];
  231. $car_data['community_id'] = $data['community_id'];
  232. $car_data['carkey'] = 'cart_total';
  233. $car_data['format_data'] = serialize(array('quantity' => $total));
  234. pdo_insert('lionfish_comshop_car', $car_data);
  235. }
  236. //session('cart_total',$total);
  237. $json ['code'] = 1;
  238. if( $data['buy_type'] != 'dan' )
  239. {
  240. $json ['code'] = 2;
  241. }
  242. $json['success']='成功加入购物车!!';
  243. $json['total']=$total;
  244. echo json_encode($json);
  245. die();
  246. }
  247. }
  248. //显示购物车中商品列表
  249. function show_cart_goods(){
  250. global $_W;
  251. global $_GPC;
  252. $token = $_GPC['token'];
  253. $community_id = $_GPC['community_id'];
  254. $token_param = array();
  255. $token_param[':uniacid'] = $_W['uniacid'];
  256. $token_param[':token'] = $token;
  257. $weprogram_token = pdo_fetch("select member_id from ".tablename('lionfish_comshop_weprogram_token')." where uniacid=:uniacid and token=:token limit 1", $token_param);
  258. $member_id = $weprogram_token['member_id'];
  259. $buy_type = isset($_GPC['buy_type']) ? $_GPC['buy_type']: 'dan';
  260. if( empty($member_id) )
  261. {
  262. //需要登录
  263. echo json_encode( array('code' =>5) );
  264. die();
  265. }
  266. $cart = load_model_class('car');
  267. $goods = $cart->get_all_goodswecar($buy_type, $token, 0, $community_id);
  268. $seller_goodss = array();
  269. foreach($goods as $key => $val)
  270. {
  271. //$goods_store_field = M('goods')->field('store_id')->where( array('goods_id' => $val['goods_id']) )->find();
  272. //$seller_goodss[ $goods_store_field['store_id'] ]['goods'][$key] = $val;
  273. $seller_goodss[ 1 ]['goods'][$key] = $val;
  274. }
  275. $ck_goodstype_count = 0;
  276. foreach($seller_goodss as $store_id => $val)
  277. {
  278. //total
  279. $seller_voucher_list = array();
  280. $seller_total_fee = 0;
  281. $total_trans_free = 0;
  282. $tmp_goods = array();
  283. $is_store_ck = false;
  284. foreach($val['goods'] as $kk =>$d_goods)
  285. {
  286. $seller_total_fee += $d_goods['total'];
  287. $total_trans_free += $d_goods[$kk]['trans_free'];
  288. $val['goods'][$kk] = $d_goods;
  289. $tp_val = array();
  290. $tp_val['id'] = $d_goods['goods_id'];
  291. $tp_val['key'] = $d_goods['key'];
  292. if($d_goods['singledel'] == 1)
  293. {
  294. $tp_val['isselect'] = true;
  295. $is_store_ck = true;
  296. $ck_goodstype_count++;
  297. } else {
  298. $tp_val['isselect'] = false;
  299. }
  300. $tp_val['imgurl'] = $d_goods['image'];
  301. $tp_val['edit'] = 'inline';
  302. $tp_val['title'] = $d_goods['name'];
  303. $tp_val['finish'] = 'none';
  304. $tp_val['description'] = 'description';
  305. $option_arr = array();
  306. $option_str = "";
  307. foreach($d_goods['option'] as $option_val)
  308. {
  309. $option_arr[] = $option_val['name'].':'.$option_val['value'];
  310. }
  311. if(!empty($option_arr))
  312. {
  313. $option_str = implode(',', $option_arr);
  314. }
  315. $tp_val['goodstype'] = $option_str;
  316. $tp_val['goodstypeedit'] = $option_str;
  317. $tp_val['goodsnum'] = $d_goods['quantity'];
  318. $tp_val['max_quantity'] = $d_goods['max_quantity'];
  319. $tp_val['cartype'] = 'inline';
  320. $tp_val['currntprice'] = $d_goods['price'];
  321. $tp_val['price'] = $d_goods['shop_price'];
  322. $tmp_goods[] = $tp_val;
  323. }
  324. //$store_info = M('seller')->field('s_id,s_true_name,s_logo')->where( array('s_id' => $store_id) )->find();
  325. //$store_info['s_logo'] = C('SITE_URL').'Uploads/image/'.$store_info['s_logo'];
  326. $store_info = array('s_true_name' => '','s_id' => 1);
  327. $s_logo = D('Home/Front')->get_config_by_name('shoplogo');
  328. if( !empty($s_logo) )
  329. {
  330. $s_logo = tomedia($s_logo);
  331. }
  332. $val['store_info'] = $store_info;
  333. $store_data = array();
  334. $store_data['id'] = $store_info['s_id'];
  335. if($is_store_ck)
  336. {
  337. $store_data['isselect'] = true;
  338. } else {
  339. $store_data['isselect'] = false;
  340. }
  341. $store_data['shopname'] = $store_info['s_true_name'];
  342. $store_data['caredit'] = 'inline';
  343. $store_data['finish'] = 'none';
  344. $store_data['count'] = '0.00';
  345. $store_data['goodstype'] = 2;
  346. $store_data['goodstypeselect'] = 0;
  347. $store_data['shopcarts'] = $tmp_goods;
  348. $seller_goodss[$store_id] = $store_data;
  349. $i++;
  350. }
  351. $need_data = array();
  352. $need_data['code'] = 0;
  353. $need_data['carts'] = $seller_goodss;
  354. echo json_encode( $need_data );
  355. die();
  356. }
  357. public function checkout_flushall()
  358. {
  359. global $_W;
  360. global $_GPC;
  361. $token = $_GPC['token'];
  362. $community_id = $_GPC['community_id'];
  363. $token_param = array();
  364. $token_param[':uniacid'] = $_W['uniacid'];
  365. $token_param[':token'] = $token;
  366. $weprogram_token = pdo_fetch("select member_id from ".tablename('lionfish_comshop_weprogram_token')." where uniacid=:uniacid and token=:token limit 1", $token_param);
  367. $member_id = $weprogram_token['member_id'];
  368. $data = array();
  369. $data['car_key'] = $_GPC['car_key'];
  370. $data['all_keys_arr'] = $_GPC['all_keys_arr'];
  371. //car_key:cart.6:MTc0:,cart.13:MjcwXzI3Mw==:
  372. //all_keys_arr:cart.6:MTc0:_1,cart.13:MjcwXzI3Mw==:_1
  373. $car_key = explode(',', $data['car_key']);
  374. $all_keys_arr = explode(',', $data['all_keys_arr']) ;
  375. $save_keys = array();
  376. if(!empty($all_keys_arr)){
  377. foreach($all_keys_arr as $val)
  378. {
  379. $tmp_val = explode('_', $val);
  380. $save_keys[ $tmp_val[0] ] = $tmp_val[1];
  381. }
  382. }
  383. $all_cart = pdo_fetchall("select * from ".tablename('lionfish_comshop_car')." where uniacid=:uniacid and community_id=:community_id and token=:token and carkey like 'cart.%' ",
  384. array(':uniacid' => $_W['uniacid'],':community_id' => $community_id, ':token' => $token));
  385. if(!empty($all_cart))
  386. {
  387. foreach($all_cart as $val)
  388. {
  389. $tmp_format_data = unserialize($val['format_data']);
  390. $tmp_format_data['singledel'] = 0;
  391. $tmp_format_data['quantity'] = $save_keys[$val['carkey']];
  392. pdo_update('lionfish_comshop_car', array('format_data' => serialize($tmp_format_data) ), array('id' => $val['id'] ,'community_id' => $community_id));
  393. }
  394. }
  395. if(!empty($car_key)){
  396. foreach( $car_key as $key )
  397. {
  398. $car_info = pdo_fetch("select * from ".tablename('lionfish_comshop_car')." where uniacid=:uniacid and community_id=:community_id and carkey=:carkey and token=:token ",
  399. array(':token' => $token,':carkey' => $key,':uniacid' => $_W['uniacid'], ':community_id' => $community_id));
  400. if( !empty($car_info) )
  401. {
  402. $tmp_format_data = unserialize($car_info['format_data']);
  403. $tmp_format_data['singledel'] = 1;
  404. $quantity = $tmp_format_data['quantity'];
  405. $goods_id = $tmp_format_data['goods_id'];
  406. $sku_str = $tmp_format_data['sku_str'];
  407. $check_json = $this->_check_can_buy($member_id, $goods_id,$quantity);
  408. if($check_json['code'] != 0)
  409. {
  410. $tmp_format_data['quantity'] = $check_json['count'];
  411. pdo_update('lionfish_comshop_car', array('format_data' => serialize($tmp_format_data) ),
  412. array('id' => $car_info['id'], 'community_id' => $community_id));
  413. echo json_encode( array('code' => 6,'msg' => $check_json['msg']) );
  414. die();
  415. }
  416. $check_json = $this->_check_goods_quantity($goods_id,$quantity,$sku_str);
  417. if($check_json['code'] != 0)
  418. {
  419. echo json_encode( array('code' => 6,'msg' => $check_json['msg']) );
  420. die();
  421. }
  422. pdo_update('lionfish_comshop_car', array('format_data' => serialize($tmp_format_data) ),
  423. array('id' => $car_info['id'], 'community_id' => $community_id));
  424. }
  425. }
  426. }
  427. echo json_encode( array('code' => 0) );
  428. die();
  429. }
  430. public function del_car_goods()
  431. {
  432. global $_W;
  433. global $_GPC;
  434. $token = $_GPC['token'];
  435. $community_id = $_GPC['community_id'];
  436. $carkey = $_GPC['carkey'];
  437. $sql_del = "delete from ".tablename('lionfish_comshop_car')." where uniacid={$_W[uniacid]} and community_id={$community_id} and token='{$token}' and carkey='{$carkey}' ";
  438. $all_cart = pdo_query($sql_del);
  439. echo json_encode( array('code' => 0) );
  440. die();
  441. }
  442. public function _check_goods_quantity($goods_id,$quantity,$sku_str)
  443. {
  444. global $_W;
  445. global $_GPC;
  446. $goods_info = pdo_fetch("select goodsname as name from ".tablename('lionfish_comshop_goods')." where id=:id and uniacid=:uniacid ",array(':uniacid'=>$_W['uniacid'],':id' => $goods_id));
  447. $goods_quantity= load_model_class('car')->get_goods_quantity($goods_id);
  448. $json = array('code' => 0);
  449. if($goods_quantity<$quantity){
  450. $json['code'] =3;
  451. $json['msg']= mb_substr($goods_info['name'],0,4,'utf-8').'...,商品数量不足,剩余'.$goods_quantity.'个!!';
  452. }else if(!empty($sku_str))
  453. {
  454. $mul_opt_arr = array();
  455. $goods_option_mult_value = pdo_fetch("select stock as quantity from ".tablename('lionfish_comshop_goods_option_item_value')." where uniacid=:uniacid and goods_id=:goods_id and option_item_ids=:option_item_ids ", array(':goods_id'=>$goods_id,':option_item_ids' => $sku_str,':uniacid' => $_W['uniacid']));
  456. if( !empty($goods_option_mult_value) )
  457. {
  458. if($goods_option_mult_value['quantity']<$quantity+$cart_goods_quantity){
  459. $json['code'] =3;
  460. $json['msg']=mb_substr($goods_info['name'],0,4,'utf-8').'...,商品数量不足,剩余'.$goods_option_mult_value['quantity'].'个!!';
  461. }
  462. }
  463. }
  464. return $json;
  465. }
  466. private function _check_can_buy($member_id, $goods_id,$quantity)
  467. {
  468. global $_W;
  469. global $_GPC;
  470. $can_buy_count = D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
  471. $goods_info = pdo_fetch("select goodsname as name from ".tablename('lionfish_comshop_goods')." where id=:id and uniacid=:uniacid ",array(':uniacid'=>$_W['uniacid'],':id' => $goods_id));
  472. $goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'per_number');
  473. $json = array();
  474. if($can_buy_count == -1)
  475. {
  476. $json['code'] =6;
  477. $json['msg']=mb_substr($goods_info['name'],0,4,'utf-8').'...,每人最多购买'.$goods_description['per_number'].'个哦';
  478. }else if($can_buy_count >0 && $quantity >$can_buy_count)
  479. {
  480. $json['code'] =6;
  481. $json['msg']=mb_substr($goods_info['name'],0,4,'utf-8').'...,您还能购买'.$can_buy_count.'份';
  482. $json['count']=$can_buy_count;
  483. }else{
  484. $json['code'] = 0;
  485. }
  486. return $json;
  487. }
  488. public function checkout()
  489. {
  490. global $_W;
  491. global $_GPC;
  492. $buy_type = isset($_GPC['buy_type']) ? $_GPC['buy_type'] : 'dan';
  493. if($buy_type == 'undefined')
  494. {
  495. $buy_type = 'dan';
  496. }
  497. $community_id = $_GPC['community_id'];
  498. $token = $_GPC['token'];
  499. $voucher_id = isset($_GPC['voucher_id']) ? $_GPC['voucher_id'] : 0;
  500. $use_quan_str = isset($_GPC['use_quan_str']) ? $_GPC['use_quan_str'] : '';
  501. $use_quan_arr = array();
  502. if($use_quan_str != '')
  503. {
  504. $use_quan_arr_tmp = explode('@',$use_quan_str );
  505. foreach($use_quan_arr_tmp as $val)
  506. {
  507. $tmp_arr = explode('_', $val);
  508. $use_quan_arr[$tmp_arr[0]] = $tmp_arr[1];
  509. }
  510. }
  511. $token_param = array();
  512. $token_param[':uniacid'] = $_W['uniacid'];
  513. $token_param[':token'] = $token;
  514. $weprogram_token = pdo_fetch("select member_id from ".tablename('lionfish_comshop_weprogram_token')." where uniacid=:uniacid and token=:token limit 1", $token_param);
  515. $member_id = $weprogram_token['member_id'];
  516. if( empty($member_id) )
  517. {
  518. //需要登录
  519. echo json_encode( array('code' =>5) );
  520. die();
  521. }
  522. $cart = load_model_class('car');
  523. if ((!$cart->has_goodswecar($buy_type,$token,$community_id) ) ) {
  524. //购物车中没有商品
  525. echo json_encode( array('code' =>4) );
  526. die();
  527. }
  528. $member_param = array();
  529. $member_param[':uniacid'] = $_W['uniacid'];
  530. $member_param[':member_id'] = $member_id;
  531. $member_info = pdo_fetch("select * from ".tablename('lionfish_comshop_member')." where uniacid=:uniacid and member_id=:member_id",$member_param);
  532. $goods=$cart->get_all_goodswecar($buy_type, $token,1,$community_id);
  533. $add_where = array(':member_id'=>$member_id,':uniacid' => $_W['uniacid'] );
  534. $add_sql = "select * from ".tablename('lionfish_comshop_address')." where member_id=:member_id and uniacid=:uniacid order by is_default desc,address_id desc ";
  535. $address = pdo_fetch($add_sql, $add_where);
  536. if($address){
  537. //get_area_info($id)
  538. $province_info = D('Home/Front')->get_area_info($address['province_id']);// M('area')->field('area_name')->where( array('area_id' => $address['province_id']) )->find();
  539. $city_info = D('Home/Front')->get_area_info($address['city_id']);//M('area')->field('area_name')->where( array('area_id' => $address['city_id']) )->find();
  540. $country_info = D('Home/Front')->get_area_info($address['country_id']);//M('area')->field('area_name')->where( array('area_id' => $address['country_id']) )->find();
  541. $address['province_name'] = $province_info['name'];
  542. $address['city_name'] = $city_info['name'];
  543. $address['country_name'] = $country_info['name'];
  544. }
  545. $seller_goodss = array();
  546. $show_voucher = 0;
  547. foreach($goods as $key => $val)
  548. {
  549. //$goods_store_field = M('goods')->field('store_id')->where( array('goods_id' => $val['goods_id']) )->find();
  550. $seller_goodss[ 1 ]['goods'][$key] = $val;
  551. }
  552. $quan_model = load_model_class('voucher');
  553. $pin_model = load_model_class('pin');//D('Home/Pin');
  554. $voucher_price = 0;
  555. $is_pin_over = 0;
  556. //计算优惠券
  557. foreach($seller_goodss as $store_id => $val)
  558. {
  559. $seller_voucher_list = array();
  560. $seller_total_fee = 0;
  561. $total_trans_free = 0;
  562. $is_no_quan = false;
  563. foreach($val['goods'] as $kk =>$d_goods)
  564. {
  565. $seller_total_fee += $d_goods['total'];
  566. if($buy_type == 'pin' && $d_goods['pin_id'] > 0)
  567. {
  568. $is_pin_over = $pin_model->getNowPinState($d_goods['pin_id']);
  569. }
  570. $tp_goods_info = pdo_fetch("select type from ".tablename("lionfish_comshop_goods")." where id=:id and uniacid=:uniacid ",array(':id' => $d_goods['goods_id'], ':uniacid'=>$_W['uniacid']));
  571. $is_no_quan = true;
  572. if($tp_goods_info['type'] == 'integral')
  573. {
  574. //$is_no_quan = true;
  575. }
  576. $d_goods[$kk]['trans_free'] = 0;
  577. /**
  578. if($d_goods['shipping']==1)
  579. {
  580. //统一运费
  581. $d_goods[$kk]['trans_free'] = $d_goods['goods_freight'];
  582. }else {
  583. //运费模板
  584. if(!empty($address))
  585. {
  586. $trans_free = load_model_class('transport')->calc_transport($d_goods['transport_id'], $d_goods['quantity'],$d_goods['quantity']*$d_goods['weight'], $address['city_id'] );
  587. }else{
  588. $trans_free = 0;
  589. }
  590. $d_goods[$kk]['trans_free'] = $trans_free;
  591. }
  592. **/
  593. $total_trans_free += $d_goods[$kk]['trans_free'];
  594. $val['goods'][$kk] = $d_goods;
  595. }
  596. $chose_vouche = array();
  597. $show_voucher = 0;
  598. if(!$is_no_quan)
  599. {
  600. $vouche_list = $quan_model->get_user_canpay_voucher($member_id,$store_id,$seller_total_fee);
  601. if(!empty($vouche_list) && empty($use_quan_arr) ) {
  602. $show_voucher = 1;
  603. reset($vouche_list);
  604. $chose_vouche = current($vouche_list);
  605. $voucher_price += $chose_vouche['credit'];
  606. $seller_total_fee = round( $seller_total_fee - $chose_vouche['credit'], 2);
  607. }else if( !empty($vouche_list) && !empty($use_quan_arr) )
  608. {
  609. foreach($vouche_list as $tmp_voucher)
  610. {
  611. if($tmp_voucher['id'] == $use_quan_arr[$store_id])
  612. {
  613. $show_voucher = 1;
  614. $chose_vouche = $tmp_voucher;
  615. $seller_total_fee = round( $seller_total_fee - $chose_vouche['credit'], 2);
  616. $voucher_price += $chose_vouche['credit'];
  617. break;
  618. }
  619. }
  620. }
  621. }
  622. $val['chose_vouche'] = $chose_vouche;
  623. $val['show_voucher'] = $show_voucher;
  624. $val['voucher_list'] = $vouche_list;
  625. $val['total'] = $seller_total_fee;
  626. if($val['total'] < 0)
  627. {
  628. $val['total'] = 0;
  629. }
  630. $val['trans_free'] = $total_trans_free;
  631. $s_logo = D('Home/Front')->get_config_by_name('shoplogo');
  632. if( !empty($s_logo) )
  633. {
  634. $s_logo = tomedia( $s_logo );
  635. }
  636. $store_info = array('s_id' => 1,'s_true_name' => '','s_logo' => $s_logo );
  637. $val['store_info'] = $store_info;
  638. $seller_goodss[$store_id] = $val;
  639. }
  640. $trans_free_toal = 0;//运费
  641. $total_free = 0;
  642. $is_ziti = 2;
  643. $pick_up_time = "";
  644. $pick_up_type = -1;
  645. $pick_up_weekday = '';
  646. $today_time = time();
  647. $arr = array('天','一','二','三','四','五','六');
  648. $pick_up_arr = array();
  649. foreach($goods as $key => $good)
  650. {
  651. //暂时关闭
  652. //ims_lionfish_comshop_goods
  653. //ims_ lionfish_comshop_good_common
  654. $goods_info = pdo_fetch("select pick_up_type,pick_up_modify from ".tablename('lionfish_comshop_good_common').
  655. " where uniacid=:uniacid and goods_id=:goods_id ",
  656. array(':uniacid' => $_W['uniacid'], ':goods_id' => $good['goods_id']));
  657. if($pick_up_type == -1 || $goods_info['pick_up_type'] > $pick_up_type)
  658. {
  659. $pick_up_type = $goods_info['pick_up_type'];
  660. if($pick_up_type == 0)
  661. {
  662. $pick_up_time = date('m-d', $today_time);
  663. $pick_up_weekday = '周'.$arr[date('w',$today_time)];
  664. }else if( $pick_up_type == 1 ){
  665. $pick_up_time = date('m-d', $today_time+86400);
  666. $pick_up_weekday = '周'.$arr[date('w',$today_time+86400)];
  667. }else if( $pick_up_type == 2 )
  668. {
  669. $pick_up_time = date('m-d', $today_time+86400*2);
  670. $pick_up_weekday = '周'.$arr[date('w',$today_time+86400*2)];
  671. }else if($pick_up_type == 3)
  672. {
  673. $pick_up_time = $goods_info['pick_up_modify'];
  674. }
  675. }
  676. /**
  677. if($goods_info['pick_just'] >= 1)
  678. {
  679. $pick_up = $goods_info['pick_up'];
  680. $is_ziti = $goods_info['pick_just'];
  681. }
  682. **/
  683. $trans_free_toal += $good['goods_freight'];
  684. $goods[$key]['trans_free'] = $good['goods_freight'];
  685. /**
  686. if($good['shipping']==1)
  687. {
  688. //统一运费
  689. $trans_free_toal += $good['goods_freight'];
  690. $goods[$key]['trans_free'] = $good['goods_freight'];
  691. }else {
  692. //运费模板
  693. if(!empty($address))
  694. {
  695. $trans_free = load_model_class('transport')->calc_transport($good['transport_id'], $good['quantity'], $good['quantity']*$good['weight'], $address['city_id'] );
  696. }else{
  697. $trans_free = 0;
  698. }
  699. $goods[$key]['trans_free'] = $trans_free;
  700. $trans_free_toal +=$trans_free;
  701. }
  702. **/
  703. $total_free += $good['total'];
  704. }
  705. //暂时关闭自提代码
  706. /**
  707. if(!empty($pick_up))
  708. {
  709. $pick_up = unserialize($pick_up);
  710. $pick_up_ids = implode(',',$pick_up);
  711. $pick_up_arr = M('pick_up')->where( array('id'=>array('in',$pick_up_ids)) )->select();
  712. }
  713. **/
  714. $pick_up_name = '';
  715. $pick_up_mobile = '';
  716. if($is_ziti >= 1)
  717. {
  718. //寻找上一个订单的自提电话 自提姓名
  719. $last_order_info = pdo_fetch("select * from ".tablename('lionfish_comshop_order').
  720. " where uniacid=:uniacid and member_id=:member_id and delivery =:delivery order by order_id desc ",
  721. array(':uniacid' => $_W['uniacid'], ':member_id' => $member_id, ':delivery' => 'pickup' ));
  722. if(!empty($last_order_info))
  723. {
  724. $pick_up_name = $last_order_info['shipping_name'];
  725. $pick_up_mobile = $last_order_info['telephone'];
  726. }
  727. }
  728. /**
  729. **/
  730. $need_data = array();
  731. $need_data['code'] = 1;
  732. $need_data['pick_up_time'] = $pick_up_time;
  733. $need_data['pick_up_type'] = $pick_up_type;
  734. $need_data['pick_up_weekday'] = $pick_up_weekday;
  735. $need_data['is_pin_over'] = $is_pin_over;
  736. $need_data['is_integer'] = 0;//$is_no_quan ? 1: 0;
  737. $need_data['pick_up_arr'] = $pick_up_arr;
  738. $need_data['is_ziti'] = 2;
  739. $need_data['ziti_name'] = $pick_up_name;
  740. $need_data['ziti_mobile'] = $pick_up_mobile;
  741. $need_data['seller_goodss'] = $seller_goodss;
  742. $need_data['show_voucher'] = $show_voucher;
  743. $need_data['buy_type'] = $buy_type;
  744. $need_data['address'] = $address;
  745. $need_data['trans_free_toal'] = $trans_free_toal;
  746. $dispatching = isset($_GPC['dispatching']) ? $_GPC['dispatching']:'pickup';
  747. //is_ziti == 2
  748. if($dispatching == 'express')
  749. {
  750. $need_data['total_free'] = $total_free + $trans_free_toal - $voucher_price;
  751. }else{
  752. $need_data['total_free'] = $total_free - $voucher_price;
  753. }
  754. if($is_ziti == 2)
  755. {
  756. $need_data['total_free'] = $total_free - $voucher_price;
  757. }
  758. if($need_data['total_free'] < 0)
  759. {
  760. $need_data['total_free'] = 0;
  761. }
  762. //判断是否可以余额支付
  763. //暂时关闭 会员余额功能
  764. /**
  765. $is_yue_open_info = M('config')->where( array('name' => 'is_yue_open') )->find();
  766. $is_yue_open = $is_yue_open_info['value'];
  767. **/
  768. $is_yue_open = 0;
  769. $need_data['is_yue_open'] = $is_yue_open;
  770. $need_data['can_yupay'] = 0;
  771. //暂时关闭 会员余额功能
  772. /**
  773. if($is_yue_open == 1 && $need_data['total_free'] >=0 && $member_info['account_money'] >= $need_data['total_free'])
  774. {
  775. $need_data['can_yupay'] = 1;
  776. }
  777. **/
  778. $need_data['yu_money'] = $member_info['account_money'];
  779. $need_data['goods'] = $goods;
  780. echo json_encode($need_data);
  781. die();
  782. }
  783. public function sub_order()
  784. {
  785. global $_W;
  786. global $_GPC;
  787. $token = $_GPC['token'];
  788. $token_param = array();
  789. $token_param[':uniacid'] = $_W['uniacid'];
  790. $token_param[':token'] = $token;
  791. $weprogram_token = pdo_fetch("select member_id from ".tablename('lionfish_comshop_weprogram_token')." where uniacid=:uniacid and token=:token limit 1", $token_param);
  792. $member_id = $weprogram_token['member_id'];
  793. $data_s = array();
  794. $data_s['pay_method'] = $_GPC['wxpay'];
  795. $data_s['buy_type'] = $_GPC['buy_type'];
  796. $data_s['pick_up_id'] = $_GPC['pick_up_id'];
  797. $data_s['dispatching'] = $_GPC['dispatching'];
  798. $data_s['ziti_name'] = $_GPC['ziti_name'];
  799. $data_s['quan_arr'] = $_GPC['quan_arr'];
  800. $data_s['comment'] = $_GPC['comment'];
  801. $data_s['ziti_mobile'] = $_GPC['ziti_mobile'];
  802. $data_s['ck_yupay'] = $_GPC['ck_yupay'];
  803. $json=array();
  804. $pay_method = $data_s['pay_method'];//支付类型
  805. $order_msg_str = $data_s['order_msg_str'];//商品订单留言
  806. $comment = $data_s['comment'];//商品订单留言
  807. $pick_up_id = $data_s['pick_up_id'];
  808. $dispatching = $data_s['dispatching'];
  809. $ziti_name = $data_s['ziti_name'];
  810. $ziti_mobile = $data_s['ziti_mobile'];
  811. $ck_yupay = $data_s['ck_yupay'];
  812. /**
  813. pick_up_id: that.data.pick_up_id,
  814. dispatching: that.data.dispatching, //express pickup
  815. ziti_name: t_ziti_name,
  816. ziti_mobile: t_ziti_mobile
  817. **/
  818. $order_msg_arr = explode('@,@', $order_msg_str);
  819. $quan_arr = $data_s['quan_arr'];//商品订单留言
  820. $order_quan_arr = array();
  821. if( !empty($quan_arr) )
  822. {
  823. if( !is_array($quan_arr) )
  824. {
  825. $quan_arr = array($quan_arr);
  826. }
  827. foreach($quan_arr as $q_val)
  828. {
  829. $tmp_q = array();
  830. $tmp_q = explode('_',$q_val);
  831. $voucher_info = pdo_fetch("select * from ".tablename('lionfish_comshop_coupon_list')." where uniacid=:uniacid and consume='N' and id=:id and user_id=:user_id and end_time >:end_time ",
  832. array(':end_time' => time(),':user_id' => $member_id, ':id' => $tmp_q[1],':uniacid' => $_W['uniacid']));
  833. if( !empty($voucher_info) )
  834. {
  835. //$order_quan_arr[$tmp_q[0]] = $tmp_q[1];
  836. $order_quan_arr[1] = $tmp_q[1];
  837. }
  838. }
  839. }
  840. $msg_arr = array();
  841. foreach($order_msg_arr as $val)
  842. {
  843. $tmp_val = explode('@_@', $val);
  844. $msg_arr[ $tmp_val[0] ] = $tmp_val[1];
  845. }
  846. $cart= load_model_class('car');
  847. // 验证商品数量
  848. //buy_type:buy_type
  849. $buy_type = $data_s['buy_type'];//I('post.buy_type');
  850. $is_pin = 0;
  851. if($buy_type == 'pin')
  852. {
  853. $is_pin = 1;
  854. }
  855. $goodss = $cart->get_all_goodswecar($buy_type,$token,1,$data_s['pick_up_id']);
  856. //付款人
  857. $member_param = array();
  858. $member_param[':uniacid'] = $_W['uniacid'];
  859. $member_param[':member_id'] = $member_id;
  860. $payment = pdo_fetch("select * from ".tablename('lionfish_comshop_member')." where uniacid=:uniacid and member_id=:member_id",$member_param);
  861. //收货人
  862. $addr_param = array();
  863. $addr_param[':uniacid'] = $_W['uniacid'];
  864. $addr_param[':member_id'] = $member_id;
  865. //$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";
  866. //$address = pdo_fetch($addr_sql, $addr_param);
  867. $seller_goodss = array();
  868. foreach($goodss as $key => $val)
  869. {
  870. //单商户先屏蔽
  871. //$goods_store_field = M('goods')->field('store_id')->where( array('goods_id' => $val['goods_id']) )->find();
  872. $seller_goodss[ 1 ][$key] = $val;
  873. $cart->removecar($val['key'],$token);
  874. }
  875. $pay_total = 0;
  876. //M('order_all')
  877. $order_all_data = array();
  878. $order_all_data['uniacid'] = $_W['uniacid'];
  879. $order_all_data['member_id'] = $member_id;
  880. $order_all_data['order_num_alias'] = build_order_no($member_id);
  881. $order_all_data['transaction_id'] = '';
  882. $order_all_data['order_status_id'] = 3;
  883. $order_all_data['is_pin'] = $is_pin;
  884. $order_all_data['paytime'] = 0;
  885. $order_all_data['addtime'] = time();
  886. pdo_insert('lionfish_comshop_order_all',$order_all_data);
  887. $order_all_id = pdo_insertid();
  888. //暂时屏蔽积分商城模块
  889. //$integral_model = D('Seller/Integral');
  890. $order_ids_arr = array();
  891. $del_integral = 0;
  892. $community_info = pdo_fetch("select * from ".tablename('lionfish_community_head')." where uniacid=:uniacid and id=:id ",
  893. array(':uniacid' => $_W['uniacid'], ':id' => $data_s['pick_up_id']));
  894. //$data_s['pick_up_id']
  895. //community_info
  896. $community_detail_info = D('Home/Front')->get_community_byid($data_s['pick_up_id']);
  897. foreach($seller_goodss as $kk => $vv)
  898. {
  899. $data = array();
  900. $data['member_id']=$member_id;
  901. $data['name']= $payment['username'];
  902. $data['telephone']= $data_s['ziti_mobile'];
  903. $data['shipping_name']= $data_s['ziti_name'];
  904. $data['shipping_tel']= $data_s['ziti_mobile'];
  905. $data['shipping_address'] = $community_detail_info['fullAddress'];
  906. $data['shipping_province_id']=$community_info['province_id'];
  907. $data['shipping_city_id']=$community_info['city_id'];
  908. $data['shipping_stree_id']=$community_info['country_id'];
  909. $data['shipping_country_id']=$community_info['area_id'];
  910. $data['shipping_method'] = 0;
  911. $data['delivery']=$dispatching;
  912. $data['pick_up_id']=$pick_up_id;
  913. $data['ziti_name']=$community_info['head_name'];
  914. $data['ziti_mobile']=$community_info['head_mobile'];
  915. //$data['ziti_address']=$community_detail_info['fullAddress'];
  916. //$pick_up_id = $data_s['pick_up_id'];
  917. //$dispatching = $data_s['dispatching'];
  918. //$ziti_name = $data_s['ziti_name'];
  919. //$ziti_mobile = $data_s['ziti_mobile'];
  920. $data['payment_method']=$pay_method;
  921. $data['address_id']= $address['address_id'];
  922. $data['voucher_id'] = isset($order_quan_arr[$kk]) ? $order_quan_arr[$kk]:0;
  923. $data['user_agent']=$_SERVER['HTTP_USER_AGENT'];
  924. $data['date_added']=time();
  925. //$hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
  926. $subject='';
  927. $fare = 0;
  928. $trans_free_toal = 0;//运费
  929. $order_total = 0;
  930. $is_lottery = 0;
  931. $is_integral = 0;
  932. $is_spike = 0;
  933. foreach($goodss as $key => $good)
  934. {
  935. /**
  936. if($good['shipping']==1)
  937. {
  938. //统一运费
  939. $trans_free_toal += $good['goods_freight'];
  940. $trans_free = $good['goods_freight'];
  941. }else {
  942. //运费模板
  943. $trans_free = load_model_class('transport')->calc_transport($good['transport_id'], $good['quantity'], $good['quantity']*$good['weight'], $address['city_id'] );
  944. //$trans_free = D('Home/Transport')->calc_transport($good['transport_id'], $good['quantity']*$good['weight'], $address['city_id'] );
  945. $trans_free_toal +=$trans_free;
  946. }
  947. **/
  948. $trans_free = 0;
  949. $trans_free_toal +=$trans_free;
  950. //sku_str
  951. $order_total += $good['total'];
  952. $tp_goods_info = pdo_fetch("select type from ".tablename('lionfish_comshop_goods')." where id=:id and uniacid=:uniacid ", array(':id' => $good['goods_id'], ':uniacid' =>$_W['uniacid'] ));
  953. $tp_goods_info['store_id'] = 1;
  954. if($tp_goods_info['type'] == 'lottery')
  955. {
  956. $is_lottery = 1;
  957. }
  958. if($tp_goods_info['type'] == 'spike')
  959. {
  960. $is_spike = 1;
  961. $is_pin = 0;
  962. }
  963. //暂时屏蔽积分商城模块
  964. /**
  965. if($tp_goods_info['type'] == 'integral')
  966. {
  967. $is_integral = 1;
  968. $is_pin = 0;
  969. $check_result = $integral_model->check_user_score_can_pay($member_id, $good['sku_str'], $good['goods_id'] );
  970. if($check_result['code'] == 1)
  971. {
  972. die();
  973. }
  974. }
  975. **/
  976. $goods_data[] = array(
  977. 'goods_id' => $good['goods_id'],
  978. 'store_id' => $tp_goods_info['store_id'],
  979. 'name' => $good['name'],
  980. 'model' => $good['model'],
  981. 'is_pin' => $is_pin,
  982. 'pin_id' => $good['pin_id'],
  983. 'header_disc' => $good['header_disc'],
  984. 'member_disc' => $good['member_disc'],
  985. 'level_name' => $good['level_name'],
  986. 'option' => $good['sku_str'],
  987. 'quantity' => $good['quantity'],
  988. 'shipping_fare' => $trans_free,
  989. 'price' => $good['price'],
  990. 'total' => $good['total'],
  991. 'comment' => htmlspecialchars($comment)
  992. );
  993. }
  994. //$is_pin; is_lottery
  995. //'pintuan', 'normal', 'lottery'
  996. $data['type'] = 'normal';
  997. if($is_pin == 1)
  998. {
  999. $data['type'] = 'pintuan';
  1000. if($is_lottery == 1)
  1001. {
  1002. $data['type'] = 'lottery';
  1003. }
  1004. }
  1005. if($is_integral == 1)
  1006. {
  1007. $data['type'] = 'integral';
  1008. $is_pin = 0;
  1009. }
  1010. if($is_spike == 1)
  1011. {
  1012. $data['type'] = 'spike';
  1013. $is_pin = 0;
  1014. }
  1015. $data['shipping_fare'] = floatval($trans_free_toal);
  1016. $data['store_id']= $kk;
  1017. $data['goodss'] = $goods_data;
  1018. $data['order_num_alias']=build_order_no($member_id);
  1019. $data['totals'][0]=array(
  1020. 'code'=>'sub_total',
  1021. 'title'=>'商品价格',
  1022. 'text'=>'¥'.$order_total,
  1023. 'value'=>$order_total
  1024. );
  1025. $data['totals'][1]=array(
  1026. 'code'=>'shipping',
  1027. 'title'=>'运费',
  1028. 'text'=>'¥'.$trans_free_toal,
  1029. 'value'=>$trans_free_toal
  1030. );
  1031. $data['totals'][2]=array(
  1032. 'code'=>'total',
  1033. 'title'=>'总价',
  1034. 'text'=>'¥'.($order_total+$trans_free_toal),
  1035. 'value'=>($order_total+$trans_free_toal)
  1036. );
  1037. $data['from_type'] = 'wepro';
  1038. if($data['voucher_id'] > 0) {
  1039. //暂时屏蔽优惠券,等待开启
  1040. $voucher_info = pdo_fetch("select * from ".tablename('lionfish_comshop_coupon_list')." where uniacid=:uniacid and id=:id ",
  1041. array(':uniacid' => $_W['uniacid'],':id' => $data['voucher_id']));
  1042. $data['voucher_credit'] = $voucher_info['credit'];
  1043. pdo_update('lionfish_comshop_coupon_list', array('ordersn' => $data['order_num_alias'],'consume' => 'Y','usetime' => time()), array('id' => $data['voucher_id'] ));
  1044. } else {
  1045. $data['voucher_credit'] = 0;
  1046. }
  1047. $data['comment'] = htmlspecialchars($comment);
  1048. //判断自提 dispatching:"pickup"
  1049. //dispatching, //express pickup
  1050. if($dispatching == 'express')
  1051. {
  1052. $data['total']=($order_total+$fare - $data['voucher_credit']);
  1053. }else{
  1054. $data['total'] = ($order_total - $data['voucher_credit']);
  1055. }
  1056. //积分商城
  1057. //暂时屏蔽积分商城模块
  1058. /**
  1059. if($data['type'] == 'integral')
  1060. {
  1061. $del_integral += $order_total;//扣除积分
  1062. $data['total'] = 0;
  1063. $order_total = 0;
  1064. }
  1065. **/
  1066. $oid= load_model_class('frontorder')->addOrder($data);// D('Order')->addOrder($data);
  1067. //暂时屏蔽自提模块
  1068. /**
  1069. if($data['delivery'] == 'pickup')
  1070. {
  1071. $verify_bool = true;
  1072. $verifycode = 0;
  1073. while($verify_bool)
  1074. {
  1075. $code = (ceil(time()/100)+rand(10000000,40000000)).rand(1000,9999);
  1076. $verifycode = $code ? $code : rand(100000,999999);
  1077. $verifycode = str_replace('1989','9819',$verifycode);
  1078. $verifycode = str_replace('1259','9521',$verifycode);
  1079. $verifycode = str_replace('12590','95210',$verifycode);
  1080. $verifycode = str_replace('10086','68001',$verifycode);
  1081. $pick_order = M('pick_order')->where( array('pick_sn' => $verifycode) )->find();
  1082. if(empty($pick_order))
  1083. {
  1084. $verify_bool = false;
  1085. }
  1086. }
  1087. $pick_data = array();
  1088. $pick_data['pick_sn'] = $verifycode;
  1089. $pick_data['pick_id'] = $pick_up_id;
  1090. $pick_data['order_id'] = $oid;
  1091. $pick_data['state'] = 0;
  1092. $pick_data['ziti_name'] = $ziti_name;
  1093. $pick_data['ziti_mobile'] = $ziti_mobile;
  1094. $pick_data['addtime'] = time();
  1095. M('pick_order')->add($pick_data);
  1096. }
  1097. **/
  1098. $order_ids_arr[] = $oid;
  1099. //$pay_total = $pay_total + $order_total+$trans_free_toal - $data['voucher_credit'];
  1100. if($dispatching == 'express')
  1101. {
  1102. $pay_total = $pay_total + $order_total+$trans_free_toal - $data['voucher_credit'];
  1103. }else{
  1104. $pay_total = $pay_total + $order_total - $data['voucher_credit'];
  1105. }
  1106. $order_relate_data = array();
  1107. $order_relate_data['uniacid'] = $_W['uniacid'];
  1108. $order_relate_data['order_all_id'] = $order_all_id;
  1109. $order_relate_data['order_id'] = $oid;
  1110. $order_relate_data['addtime'] = time();
  1111. pdo_insert('lionfish_comshop_order_relate',$order_relate_data);
  1112. }
  1113. $order_all_data = array();
  1114. $order_all_data['total_money'] = $pay_total;
  1115. pdo_update('lionfish_comshop_order_all', $order_all_data, array('id' => $order_all_id,'uniacid' => $_W['uniacid']));
  1116. if($order_all_id){
  1117. $order = pdo_fetch("select * from ".tablename('lionfish_comshop_order')." where order_id=:order_id and uniacid=:uniacid ",array(':order_id'=>$oid,':uniacid' => $_W['uniacid']) );
  1118. $member_info = pdo_fetch('select we_openid,account_money from '.tablename('lionfish_comshop_member')." where member_id=:member_id and unionid=:uniacid " ,array(':uniacid' => $_W['uniacid'],':member_id'=>$member_id));
  1119. if( $pay_total<=0 || ($ck_yupay == 1 && $member_info['account_money'] >= $pay_total) )
  1120. {
  1121. /****
  1122. //暂时关闭
  1123. //检测是否需要扣除积分
  1124. if($del_integral> 0 && $is_integral == 1)
  1125. {
  1126. $integral_model->charge_member_score( $member_id, $del_integral,'out', 'orderbuy', $oid);
  1127. }
  1128. if($ck_yupay == 1 && $pay_total >0)
  1129. {
  1130. //开始余额支付
  1131. $member_charge_flow_data = array();
  1132. $member_charge_flow_data['member_id'] = $member_id;
  1133. $member_charge_flow_data['trans_id'] = $oid;
  1134. $member_charge_flow_data['money'] = $pay_total;
  1135. $member_charge_flow_data['state'] = 3;
  1136. $member_charge_flow_data['charge_time'] = time();
  1137. $member_charge_flow_data['add_time'] = time();
  1138. M('member_charge_flow')->add($member_charge_flow_data);
  1139. //开始处理扣钱
  1140. M('member')->where( array('member_id' => $member_id) )->setInc('account_money',-$pay_total);
  1141. }
  1142. ***/
  1143. //lionfish_comshop_order_all
  1144. //开始处理订单状态
  1145. //$order_all = M('order_all')->where( array('id' => $order_all_id) )->find();
  1146. $order_all = pdo_fetch("select * from ".tablename('lionfish_comshop_order_all')." where id=:id and uniacid=:uniacid ",array(':id'=>$order_all_id, ":uniacid"=>$_W['uniacid']));
  1147. if($order&&($order['order_status_id']!=1))
  1148. {
  1149. //支付完成
  1150. $o = array();
  1151. $o['order_status_id'] = $order['is_pin'] == 1 ? 2:1;
  1152. $o['paytime']=time();
  1153. $o['transaction_id'] = $transaction_id;
  1154. pdo_update('lionfish_comshop_order_all', $o, array( 'id' => $out_trade_no,'uniacid' =>$_W['uniacid'] ));
  1155. // ims_
  1156. $order_relate_list_sql = "select * from ".tablename('lionfish_comshop_order_relate')." where order_all_id=:id and uniacid=:uniacid ";
  1157. $order_relate_list = pdo_fetchall($order_relate_list_sql, array(':uniacid' =>$_W['uniacid'], ':id' => $order_all['id'] ));
  1158. foreach($order_relate_list as $order_relate)
  1159. {
  1160. $order = pdo_fetch("select * from ".tablename('lionfish_comshop_order')." where uniacid=:uniacid and order_id=:order_id " ,array(':uniacid' => $_W['uniacid'], ':order_id' => $order_relate['order_id'] ));
  1161. if( $order && $order['order_status_id'] == 3)
  1162. {
  1163. $o = array();
  1164. $o['payment_code'] = 'yuer';
  1165. $o['order_id']=$order['order_id'];
  1166. $o['order_status_id'] = $order['is_pin'] == 1 ? 2:1;
  1167. $o['date_modified']=time();
  1168. $o['pay_time']=time();
  1169. $o['transaction_id'] = $is_integral ==1? '积分兑换':'余额支付';
  1170. //ims_
  1171. pdo_update('lionfish_comshop_order', $o, array('order_id' => $order['order_id'],'uniacid' => $_W['uniacid']));
  1172. //暂时屏蔽
  1173. //$kucun_method = C('kucun_method');
  1174. //$kucun_method = empty($kucun_method) ? 0 : intval($kucun_method);
  1175. $kucun_method = 0;
  1176. //$goods_model = D('Home/Goods');
  1177. if($kucun_method == 1)
  1178. {//支付完减库存,增加销量
  1179. $order_goods_list = pdo_fetchall("select * from ".tablename('lionfish_comshop_order_goods')." where order_id=:order_id and uniacid=:uniacid ", array(':order_id' => $order['order_id'], ':uniacid' => $_W['uniacid']) );
  1180. foreach($order_goods_list as $order_goods)
  1181. {
  1182. load_model_class('pingoods')->del_goods_mult_option_quantity($order['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity'],1);
  1183. }
  1184. }
  1185. $oh = array();
  1186. $oh['uniacid'] = $_W['uniacid'];
  1187. $oh['order_id']=$order['order_id'];
  1188. $oh['order_status_id']= $order['is_pin'] == 1 ? 2:1;
  1189. $oh['comment']='买家已付款';
  1190. $oh['date_added']=time();
  1191. $oh['notify']=1;
  1192. pdo_insert('lionfish_comshop_order_history', $oh);
  1193. //发送购买通知
  1194. //TODO 先屏蔽,等待调试这个消息
  1195. //$weixin_nofity = D('Home/Weixinnotify');
  1196. //$weixin_nofity->orderBuy($order['order_id']);
  1197. if($order['is_pin'] == 1)
  1198. {
  1199. $pin_order = pdo_fetch('select * from '.tablename('lionfish_comshop_pin_order')." where order_id=:order_id and uniacid=:uniacid ", array(':order_id' => $order['order_id'], ':uniacid' => $_W['uniacid']) );
  1200. load_model_class('pin')->insertNotifyOrder($order['order_id']);
  1201. $is_pin_success = load_model_class('pin')->checkPinSuccess($pin_order['pin_id']);
  1202. if($is_pin_success) {
  1203. //todo send pintuan success notify
  1204. load_model_class('pin')->updatePintuanSuccess($pin_order['pin_id']);
  1205. }
  1206. }
  1207. }
  1208. }
  1209. //返回支付成功给app
  1210. $data = array();
  1211. $data['code'] = 0;
  1212. $data['has_yupay'] = 1;
  1213. $data['is_integral'] = $is_integral;
  1214. $data['is_spike'] = $is_spike;
  1215. }
  1216. }else{
  1217. $fee = $pay_total;
  1218. $appid = D('Home/Front')->get_config_by_name('wepro_appid');
  1219. $body = '商品购买';
  1220. $mch_id = D('Home/Front')->get_config_by_name('wepro_partnerid');
  1221. $nonce_str = nonce_str();
  1222. $notify_url = $_W['siteroot'].'addons/lionfish_comshop/notify.php';
  1223. $openid = $payment['we_openid'];
  1224. $out_trade_no = $order_all_id.'-'.time();
  1225. $spbill_create_ip = $_SERVER['REMOTE_ADDR'];
  1226. $total_fee = $fee*100;
  1227. $trade_type = 'JSAPI';
  1228. $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
  1229. $post['appid'] = $appid;
  1230. $post['body'] = $body;
  1231. $post['mch_id'] = $mch_id;
  1232. $post['nonce_str'] = $nonce_str;
  1233. $post['notify_url'] = $notify_url;
  1234. $post['openid'] = $openid;
  1235. $post['out_trade_no'] = $out_trade_no;
  1236. $post['spbill_create_ip'] = $spbill_create_ip;
  1237. $post['total_fee'] = $total_fee;
  1238. $post['trade_type'] = $trade_type;
  1239. $sign = sign($post,$pay_key);
  1240. $post_xml = '<xml>
  1241. <appid>'.$appid.'</appid>
  1242. <body>'.$body.'</body>
  1243. <mch_id>'.$mch_id.'</mch_id>
  1244. <nonce_str>'.$nonce_str.'</nonce_str>
  1245. <notify_url>'.$notify_url.'</notify_url>
  1246. <openid>'.$openid.'</openid>
  1247. <out_trade_no>'.$out_trade_no.'</out_trade_no>
  1248. <spbill_create_ip>'.$spbill_create_ip.'</spbill_create_ip>
  1249. <total_fee>'.$total_fee.'</total_fee>
  1250. <trade_type>'.$trade_type.'</trade_type>
  1251. <sign>'.$sign.'</sign>
  1252. </xml> ';
  1253. $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
  1254. $xml = http_request($url,$post_xml);
  1255. $array = xml($xml);
  1256. if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS'){
  1257. $time = time();
  1258. $tmp='';
  1259. $tmp['appId'] = $appid;
  1260. $tmp['nonceStr'] = $nonce_str;
  1261. $tmp['package'] = 'prepay_id='.$array['PREPAY_ID'];
  1262. $tmp['signType'] = 'MD5';
  1263. $tmp['timeStamp'] = "$time";
  1264. $prepay_id = (string)$array['PREPAY_ID'];
  1265. //ims_
  1266. $order_sql = "update ".tablename('lionfish_comshop_order')." set perpay_id='{$prepay_id}' where uniacid={$_W[uniacid]} and order_id in (".implode(',', $order_ids_arr).") ";
  1267. pdo_query($order_sql);
  1268. //M('order')->where( array('order_id' => array('in',$order_ids_arr) ) )->save( array('perpay_id' => (string)$array['PREPAY_ID']) );
  1269. $data = array();
  1270. $data['code'] = 0;
  1271. $data['appid'] = $appid;
  1272. $data['timeStamp'] = "$time";
  1273. $data['nonceStr'] = $nonce_str;
  1274. $data['signType'] = 'MD5';
  1275. $data['package'] = 'prepay_id='.$array['PREPAY_ID'];
  1276. $data['paySign'] = sign($tmp,$pay_key);
  1277. $data['out_trade_no'] = $out_trade_no;
  1278. if($is_pin == 1)
  1279. {
  1280. $data['redirect_url'] = '../groups/group?id='.$oid.'&is_show=1';
  1281. } else {
  1282. $data['redirect_url'] = '../orders/order_show_all?order_all_id=' + $order_all_id;
  1283. }
  1284. }else{
  1285. $data = array();
  1286. $data['code'] = 1;
  1287. $data['text'] = "错误";
  1288. $data['RETURN_CODE'] = $array['RETURN_CODE'];
  1289. $data['RETURN_MSG'] = $array['RETURN_MSG'];
  1290. }
  1291. $data['has_yupay'] = 0;
  1292. }
  1293. if($is_pin == 1)
  1294. {
  1295. $data['order_id'] = $oid;
  1296. $data['order_all_id'] = $order_all_id;
  1297. }else{
  1298. $data['order_id'] = $oid;
  1299. $data['order_all_id'] = $order_all_id;
  1300. }
  1301. $data['is_spike'] = $is_spike;
  1302. echo json_encode($data);
  1303. die();
  1304. }else{
  1305. echo json_encode( array('code' =>1,'order_all_id' =>$order_all_id) );
  1306. die();
  1307. }
  1308. }
  1309. public function wxpay()
  1310. {
  1311. global $_W;
  1312. global $_GPC;
  1313. $token = $_GPC['token'];
  1314. $order_id = $_GPC['order_id'];
  1315. $token_param = array();
  1316. $token_param[':uniacid'] = $_W['uniacid'];
  1317. $token_param[':token'] = $token;
  1318. $weprogram_token = pdo_fetch("select member_id from ".tablename('lionfish_comshop_weprogram_token')." where uniacid=:uniacid and token=:token limit 1", $token_param);
  1319. $member_id = $weprogram_token['member_id'];
  1320. if( empty($member_id) )
  1321. {
  1322. echo json_encode( array('code' =>1,'msg' =>'未登录') );
  1323. die();
  1324. }
  1325. //
  1326. $member_info = pdo_fetch("select we_openid from ".tablename('lionfish_comshop_member')." where uniacid=:uniacid and member_id=:member_id ", array(':member_id' => $member_id, ':uniacid' => $_W['uniacid']));
  1327. $order = pdo_fetch("select * from ".tablename('lionfish_comshop_order')." where uniacid=:uniacid and order_id=:order_id ",array(':uniacid' => $_W['uniacid'] , ':order_id' => $order_id));
  1328. //支付才减库存,才需要判断
  1329. $kucun_method = D('Home/Front')->get_config_by_name('kucun_method', $uniacid);
  1330. if( empty($kucun_method) )
  1331. {
  1332. $kucun_method = 0;
  1333. }
  1334. if($kucun_method == 1)
  1335. {
  1336. /*** 检测商品库存begin **/
  1337. $sql = "select name,quantity,rela_goodsoption_valueid,goods_id from ".tablename('lionfish_comshop_order_goods')."
  1338. where order_id=:order_id and uniacid=:uniacid ";
  1339. $order_goods_list = pdo_fetchall($sql, array(':order_id' => $order_id, ':uniacid' => $_W['uniacid']));
  1340. //goods_id
  1341. foreach($order_goods_list as $val)
  1342. {
  1343. $quantity = $val['quantity'];
  1344. $goods_id = $val['goods_id'];
  1345. $can_buy_count = D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
  1346. $goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'total_limit_count');
  1347. if($can_buy_count == -1)
  1348. {
  1349. $json['code'] = 2;
  1350. $json['msg']='每人最多购买'.$goods_description['total_limit_count'].'个哦';
  1351. echo json_encode($json);
  1352. die();
  1353. }else if($can_buy_count >0 && $quantity >$can_buy_count)
  1354. {
  1355. $json['code'] = 2;
  1356. $json['msg']='您还能购买'.$can_buy_count.'份';
  1357. echo json_encode($json);
  1358. die();
  1359. }
  1360. //rela_goodsoption_valueid
  1361. if(!empty($val['rela_goodsoption_valueid']))
  1362. {
  1363. $mul_opt_arr = array();
  1364. //ims_
  1365. $mult_sql = "select * from ".tablename('lionfish_comshop_goods_option_item_value')."
  1366. where uniacid=:uniacid and option_item_ids = :sku_str and goods_id =:goods_id limit 1 ";
  1367. $goods_option_mult_value = pdo_fetch($mult_sql, array(':uniacid' => $_W['uniacid'],':sku_str' =>$val['rela_goodsoption_valueid'],':goods_id' => $goods_id ));
  1368. if( !empty($goods_option_mult_value) )
  1369. {
  1370. if($goods_option_mult_value['stock']<$quantity){
  1371. $json['code'] =2;
  1372. $json['msg']='商品数量不足,剩余'.$goods_option_mult_value['stock'].'个!!';
  1373. echo json_encode($json);
  1374. die();
  1375. }
  1376. }
  1377. }
  1378. }
  1379. /*** 检测商品库存end **/
  1380. }
  1381. $pin_order = pdo_fetch("select * from ".tablename('lionfish_comshop_pin_order')." where uniacid=:uniacid and order_id=:order_id ", array(':order_id' => $order_id, ':uniacid' => $_W['uniacid']));
  1382. if( !empty($pin_order) )
  1383. {
  1384. $pin_model = load_model_class('pin');
  1385. $is_pin_over = $pin_model->getNowPinState($pin_order['pin_id']);
  1386. if($is_pin_over != 0)
  1387. {
  1388. pdo_query("delete from ".tablename('lionfish_comshop_pin_order')." where order_id = {$order_id} ");
  1389. pdo_query("delete from ".tablename('lionfish_comshop_pin')." where pin_id = ".$pin_order['pin_id']." and order_id = ".$order_id);
  1390. $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']));
  1391. //新开团
  1392. $pin_id = $pin_model->openNewTuan($order_id,$order_goods_info['goods_id'],$member_id);
  1393. //插入拼团订单
  1394. $pin_model->insertTuanOrder($pin_id,$order_id);
  1395. }
  1396. }
  1397. //单独支付一个店铺的订单
  1398. pdo_query("delete from ".tablename('lionfish_comshop_order_relate')." where order_id=".$order_id." and uniacid=".$_W['uniacid']);
  1399. $order_all_data = array();
  1400. $order_all_data['member_id'] = $member_id;
  1401. $order_all_data['uniacid'] = $_W['uniacid'];
  1402. $order_all_data['order_num_alias'] = build_order_no($member_id);
  1403. $order_all_data['transaction_id'] = '';
  1404. $order_all_data['order_status_id'] = 3;
  1405. $order_all_data['is_pin'] = $order['is_pin'];
  1406. $order_all_data['paytime'] = 0;
  1407. $order_all_data['total_money'] = $order['total'];
  1408. $order_all_data['addtime'] = time();
  1409. pdo_insert('lionfish_comshop_order_all', $order_all_data);
  1410. $order_all_id = pdo_insertid();
  1411. $order_relate_data = array();
  1412. $order_relate_data['uniacid'] = $_W['uniacid'];
  1413. $order_relate_data['order_all_id'] = $order_all_id;
  1414. $order_relate_data['order_id'] = $order_id;
  1415. $order_relate_data['addtime'] = time();
  1416. pdo_insert('lionfish_comshop_order_relate',$order_relate_data);//ims_
  1417. if( $order['delivery'] == 'pickup' )
  1418. {
  1419. $fee = $order['total'];
  1420. }else {
  1421. $fee = $order['total'];
  1422. }
  1423. $appid = D('Home/Front')->get_config_by_name('wepro_appid');
  1424. $body = '商品购买';
  1425. $mch_id = D('Home/Front')->get_config_by_name('wepro_partnerid');
  1426. $nonce_str = nonce_str();
  1427. $notify_url = $_W['siteroot'].'addons/lionfish_comshop/notify.php';
  1428. $openid = $member_info['we_openid'];
  1429. $out_trade_no = $order_all_id.'-'.time();
  1430. $spbill_create_ip = $_SERVER['REMOTE_ADDR'];
  1431. $total_fee = $fee*100;
  1432. $trade_type = 'JSAPI';
  1433. $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
  1434. $post['appid'] = $appid;
  1435. $post['body'] = $body;
  1436. $post['mch_id'] = $mch_id;
  1437. $post['nonce_str'] = $nonce_str;
  1438. $post['notify_url'] = $notify_url;
  1439. $post['openid'] = $openid;
  1440. $post['out_trade_no'] = $out_trade_no;
  1441. $post['spbill_create_ip'] = $spbill_create_ip;
  1442. $post['total_fee'] = $total_fee;
  1443. $post['trade_type'] = $trade_type;
  1444. $sign = sign($post,$pay_key);
  1445. $post_xml = '<xml>
  1446. <appid>'.$appid.'</appid>
  1447. <body>'.$body.'</body>
  1448. <mch_id>'.$mch_id.'</mch_id>
  1449. <nonce_str>'.$nonce_str.'</nonce_str>
  1450. <notify_url>'.$notify_url.'</notify_url>
  1451. <openid>'.$openid.'</openid>
  1452. <out_trade_no>'.$out_trade_no.'</out_trade_no>
  1453. <spbill_create_ip>'.$spbill_create_ip.'</spbill_create_ip>
  1454. <total_fee>'.$total_fee.'</total_fee>
  1455. <trade_type>'.$trade_type.'</trade_type>
  1456. <sign>'.$sign.'</sign>
  1457. </xml> ';
  1458. $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
  1459. $xml = http_request($url,$post_xml);
  1460. $array = xml($xml);
  1461. if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS'){
  1462. $time = time();
  1463. $tmp='';
  1464. $tmp['appId'] = $appid;
  1465. $tmp['nonceStr'] = $nonce_str;
  1466. $tmp['package'] = 'prepay_id='.$array['PREPAY_ID'];
  1467. $tmp['signType'] = 'MD5';
  1468. $tmp['timeStamp'] = "$time";
  1469. $prepay_id = (string)$array['PREPAY_ID'];
  1470. $order_sql = "update ".tablename('lionfish_comshop_order')." set perpay_id='{$prepay_id}' where uniacid={$_W[uniacid]} and order_id =".$order_id;
  1471. pdo_query($order_sql);
  1472. $data['code'] = 0;
  1473. $data['timeStamp'] = "$time";
  1474. $data['nonceStr'] = $nonce_str;
  1475. $data['signType'] = 'MD5';
  1476. $data['package'] = 'prepay_id='.$array['PREPAY_ID'];
  1477. $data['paySign'] = sign($tmp, $pay_key);
  1478. $data['out_trade_no'] = $out_trade_no;
  1479. $data['is_pin'] = $order['is_pin'];
  1480. if($order['is_pin'] == 1)
  1481. {
  1482. $data['redirect_url'] = '../groups/group?id='.$order_id.'&is_show=1';
  1483. } else {
  1484. $data['redirect_url'] = '../orders/order?id=' + $order_id;
  1485. }
  1486. }else{
  1487. $data['code'] = 1;
  1488. $data['text'] = "错误";
  1489. $data['RETURN_CODE'] = $array['RETURN_CODE'];
  1490. $data['RETURN_MSG'] = $array['RETURN_MSG'];
  1491. }
  1492. echo json_encode($data);
  1493. die();
  1494. }
  1495. /**
  1496. * 获取购物车总数
  1497. */
  1498. public function count() {
  1499. $data = I('param.');
  1500. var_dump($data,999);die();
  1501. global $_W;
  1502. global $_GPC;
  1503. $data = array();
  1504. $token = $_GPC['token'];
  1505. $community_id = $_GPC['community_id'];
  1506. $cart= load_model_class('car');
  1507. $total=$cart->count_goodscar($token, $community_id);
  1508. $data['code'] = 0;
  1509. $data['data'] = $total;
  1510. echo json_encode($data);
  1511. die();
  1512. }
  1513. }