CarModel.class.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. <?php
  2. namespace Home\Model;
  3. /**
  4. * 拼团模型模型
  5. * @author fish
  6. *
  7. */
  8. class CarModel {
  9. private $data = array();
  10. public function get_wecartall_goods($goods_id, $sku_str, $community_id,$token,$car_prefix='cart.',$soli_id ='')
  11. {
  12. if( $community_id <=0 )
  13. {
  14. return 0;
  15. }
  16. $key = (int)$goods_id . ':'.$community_id.':';
  17. if( !empty($soli_id) )
  18. {
  19. $key .= $soli_id.':';
  20. }
  21. $key = $car_prefix . $key;
  22. $s_arr = M('lionfish_comshop_car')->field('format_data')->where( " token='{$token}' and carkey like '%{$key}%' " )->select();
  23. $quantity = 0;
  24. foreach($s_arr as $val)
  25. {
  26. $tmp_format_data = unserialize($val['format_data']);
  27. $quantity += $tmp_format_data['quantity'];
  28. }
  29. return $quantity;
  30. }
  31. public function get_wecart_goods_solicount($goods_id, $community_id,$token,$soli_id = '')
  32. {
  33. $key = (int)$goods_id . ':'.$community_id.':'.$soli_id.':' ;
  34. $key = 'soitairecart.'.$key;
  35. $car_sql = "select format_data from ".C('DB_PREFIX')."lionfish_comshop_car
  36. where token ='{$token}' and carkey like '{$key}%' ";
  37. $s_arr = M()->query($car_sql);
  38. if( !empty($s_arr) )
  39. {
  40. $s_count = 0;
  41. foreach( $s_arr as $val )
  42. {
  43. $tmp_format_data = unserialize($val['format_data']);
  44. $s_count += $tmp_format_data['quantity'];
  45. }
  46. return $s_count;
  47. }else{
  48. return 0;
  49. }
  50. }
  51. public function get_wecart_goods($goods_id, $sku_str, $community_id,$token,$car_prefix='cart.',$soli_id = '')
  52. {
  53. if( $community_id <=0 )
  54. {
  55. return 0;
  56. }
  57. $key = (int)$goods_id . ':'.$community_id.':';
  58. if( !empty($soli_id) )
  59. {
  60. $key .= $soli_id.':';
  61. }
  62. if ($sku_str) {
  63. $key.= base64_encode($sku_str) . ':';
  64. } else {
  65. $key.= ':';//xx
  66. }
  67. $key = $car_prefix . $key;
  68. $car_param = array();
  69. $car_param[':uniacid'] = $_W['uniacid'];
  70. $car_param[':token'] = $token;
  71. $car_param[':carkey'] = $key;
  72. //C('DB_PREFIX')
  73. $s_arr = M('lionfish_comshop_car')->field('format_data')->where( array('carkey' => $key,'token' => $token) )->find();
  74. $tmp_format_data = unserialize($s_arr['format_data']);
  75. return $tmp_format_data['quantity'];
  76. }
  77. //得到商品数量
  78. public function get_goods_quantity($goods_id) {
  79. $quantity = D('Seller/Redisorder')->get_goods_total_quantity($goods_id);
  80. if($quantity <= 0)
  81. {
  82. $info = M('lionfish_comshop_goods')->field('total as quantity')->where(array('id' =>$goods_id))->find();
  83. $quantity = $info['quantity'];
  84. }
  85. return $quantity;
  86. }
  87. public function addwecar($token, $goods_id, $format_data = array() , $option, $community_id,$car_prefix='cart.',$soli_id='') {
  88. $key = (int)$goods_id . ':'.$community_id.':';
  89. if( !empty($soli_id) )
  90. {
  91. $key .= $soli_id.':';
  92. }
  93. $qty = $format_data['quantity'];
  94. if ($option) {
  95. $key.= base64_encode($option) . ':';
  96. } else {
  97. $key.= ':';
  98. }
  99. if( $format_data['is_just_addcar'] == 0 )
  100. {
  101. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  102. where token='{$token}' and carkey like '".$car_prefix."%' ";
  103. $all_cart = M()->query($cart_sql);
  104. if(!empty($all_cart))
  105. {
  106. foreach($all_cart as $val)
  107. {
  108. $tmp_format_data = unserialize($val['format_data']);
  109. $tmp_format_data['singledel'] = 0;
  110. $tmp_format_data_new = array('format_data' => serialize($tmp_format_data) );
  111. M('lionfish_comshop_car')->where( array('id' => $val['id']) )->save( $tmp_format_data_new );
  112. }
  113. }
  114. }
  115. $carkey = $car_prefix.$key;
  116. $s_arr = M('lionfish_comshop_car')->field('format_data')->where( array('carkey' => $carkey,'token' => $token) )->find();
  117. if ((int)$qty && ((int)$qty > 0)) {
  118. $key = $car_prefix . $key;
  119. $s = array();
  120. if (!empty($s_arr)) {
  121. $s = unserialize($s_arr['format_data']);
  122. }
  123. if (!empty($s)) {
  124. if( $format_data['is_just_addcar'] == 1 )
  125. {
  126. $format_data['quantity']+= $s['quantity'];
  127. }
  128. }
  129. }
  130. if (!empty($s_arr)) {
  131. $car_data = array();
  132. $car_data['format_data'] = serialize($format_data);
  133. $car_data['modifytime'] = time();
  134. M('lionfish_comshop_car')->where( array('token' => $token,'carkey' => $key) )->save( $car_data );
  135. } else {
  136. $car_data = array();
  137. $car_data['token'] = $token;
  138. $car_data['community_id'] = $community_id;
  139. $car_data['carkey'] = $key;
  140. $car_data['modifytime'] = time();
  141. $car_data['format_data'] = serialize($format_data);
  142. M('lionfish_comshop_car')->add( $car_data );
  143. }
  144. $this->data = array();
  145. }
  146. public function add_activitycar($token, $goods_id, $format_data = array() , $option) {
  147. global $_W;
  148. global $_GPC;
  149. $this->removeActivityAllcar($token);
  150. $key = (int)$goods_id . ':';
  151. $qty = $format_data['quantity'];
  152. if ($option) {
  153. $key.= base64_encode($option) . ':';
  154. } else {
  155. $key.= ':';
  156. }
  157. $key.= "buy_type:" ;
  158. if ((int)$qty && ((int)$qty > 0)) {
  159. $key = 'cart_activity.' . $key;
  160. $carkey = 'cart.'.$key;
  161. $s_arr = M('lionfish_comshop_car')->where( array('token' => $token, 'carkey' => $carkey) )->find();
  162. $s = array();
  163. if (!empty($s_arr)) {
  164. $s = unserialize($s_arr['format_data']);
  165. }
  166. if (!empty($s)) {
  167. $format_data['quantity']+= $s['quantity'];
  168. }
  169. if (!empty($s_arr)) {
  170. $car_data = array();
  171. $car_data['format_data'] = serialize($format_data);
  172. M('lionfish_comshop_car')->where( array('token' => $token,'carkey' => $key) )->save( $car_data );
  173. } else {
  174. $car_data = array();
  175. $car_data['token'] = $token;
  176. $car_data['carkey'] = $key;
  177. $car_data['format_data'] = serialize($format_data);
  178. M('lionfish_comshop_car')->add($car_data);
  179. }
  180. }
  181. $this->data = array();
  182. }
  183. public function get_all_goodswecar($buy_type = 'dan', $token,$is_pay_need = 1, $community_id,$soli_id='') {
  184. if (!($this->data)) {
  185. if ($buy_type == 'dan') {
  186. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  187. where token='{$token}' and community_id='{$community_id}' and carkey like 'cart.%' order by modifytime desc ";
  188. $cart = M()->query($cart_sql);
  189. }
  190. else if( $buy_type == 'pindan' )
  191. {
  192. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  193. where token='{$token}' and community_id={$community_id} and carkey like 'pindancart.%' order by modifytime desc ";
  194. $cart = M()->query($cart_sql);
  195. }else if( $buy_type == 'pintuan' )
  196. {
  197. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  198. where token='{$token}' and community_id={$community_id} and carkey like 'pintuancart.%' order by modifytime desc ";
  199. $cart = M()->query($cart_sql);
  200. }
  201. else if( $buy_type == 'soitaire' )
  202. {
  203. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  204. where token='{$token}' and community_id={$community_id} and carkey like 'soitairecart.%' order by modifytime desc ";
  205. $cart_arr = M()->query($cart_sql);
  206. $cart = array();
  207. if( !empty($cart_arr) )
  208. {
  209. foreach( $cart_arr as $key => $val )
  210. {
  211. $key_arr = explode(':', $val['carkey']);
  212. if( $key_arr[2] == $soli_id )
  213. {
  214. $cart[$key] = $val;
  215. }
  216. }
  217. }
  218. }
  219. else if( $buy_type == 'integral' )
  220. {
  221. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  222. where token='{$token}' and community_id={$community_id} and carkey like 'integralcart.%' order by modifytime desc ";
  223. $cart = M()->query($cart_sql);
  224. }
  225. else {
  226. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  227. where token='{$token}' and community_id='{$community_id}' and carkey like 'cart_activity.%' order by modifytime desc ";
  228. $cart = M()->query($cart_sql);
  229. }
  230. $is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
  231. $is_open_vipcard_buy = !empty($is_open_vipcard_buy) && $is_open_vipcard_buy ==1 ? 1:0;
  232. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  233. $member_id = $weprogram_token['member_id'];
  234. //$goods_model = D('Home/Goods');
  235. foreach ($cart as $key => $val_uns) {
  236. $val = unserialize( $val_uns['format_data'] );
  237. if($buy_type =='dan' && $is_pay_need == 1)
  238. {
  239. if(isset($val['singledel']) && $val['singledel'] == 0)
  240. {
  241. continue;
  242. }
  243. }else if($buy_type == 'dan' && $is_pay_need == 0)
  244. {
  245. //判断是否支持自提,如果支持自提,那么就不要剔除购物车列表
  246. //$val['goods_id'] pick_just pick_just
  247. $goods_common_info = D('Seller/Front')->get_goods_common_field($val['goods_id'] , 'pick_just');
  248. $pick_just = $goods_common_info['pick_just'];
  249. if(!empty($pick_just) && isset($pick_just['pick_just']) && $pick_just['pick_just'] > 0)
  250. {
  251. //continue;
  252. }else {
  253. }
  254. }
  255. //$pin_type = $val['pin_type'];
  256. $quantity = $val['quantity'];
  257. //$quantity
  258. $goods = explode(':', $key);
  259. $goods_id = $val['goods_id'];
  260. $stock = true;
  261. // Options sku_str
  262. $options = $val['sku_str'];
  263. $goods_query_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_goods as p left join ".C('DB_PREFIX')."lionfish_comshop_good_commiss as pd
  264. on p.id = pd.goods_id where p.id ={$goods_id} and p.grounding = 1 ";
  265. $goods_query_arr = M()->query($goods_query_sql);
  266. $goods_query = $goods_query_arr[0];
  267. $goods_query['model'] = $goods_query['codes'];
  268. if ($goods_query) {
  269. $option_price = null;
  270. $option_weight = $goods_query['weight'];
  271. $option_data = array();
  272. $max_quantity = $goods_query['total'];
  273. if (!empty($options)) {
  274. $goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->where( array('goods_id' => $goods_id,'option_item_ids' => $options) )->find();
  275. $goods_option_mult_value['pin_price'] = $goods_option_mult_value['pinprice'];
  276. $goods_option_mult_value['dan_price'] = $goods_option_mult_value['marketprice'];
  277. $goods_query['card_price'] = $goods_option_mult_value['card_price'];
  278. $goods_query['model'] = $goods_option_mult_value['goodssn'];
  279. $options_arr = array();
  280. $option_value_id_arr = explode('_', $options);
  281. foreach ($option_value_id_arr as $id_val) {
  282. $goods_option_value = M('lionfish_comshop_goods_option_item')->where( array('goods_id' => $goods_id,'id' => $id_val) )->find();
  283. $options_arr[$goods_option_value['goods_option_id']] = $goods_option_value['id'];
  284. }
  285. }
  286. $option_value_image = '';
  287. if($options_arr){
  288. foreach ($options_arr as $goods_option_id => $goods_option_item_id ) {
  289. //option_value
  290. $option_query = M('lionfish_comshop_goods_option')->where( array('goods_id' => $goods_id,'id' => $goods_option_id) )->find();
  291. if ($option_query) {
  292. $option_value_query = M('lionfish_comshop_goods_option_item')->where( array('id' => $goods_option_item_id,'goods_id' => $goods_id) )->find();
  293. if ($option_value_query) {
  294. if( !empty($option_value_query['thumb']) )
  295. {
  296. $option_value_image = $option_value_query['thumb'];
  297. }
  298. $max_quantity = $goods_option_mult_value['stock'];
  299. //根据商品类型获取不同价格 begin pinprice pin_price productprice dan_price
  300. if ($buy_type == 'pintuan' && $goods_query['type'] != 'spike') {
  301. $option_price = $goods_option_mult_value['pin_price'];
  302. }else if($goods_query['type'] == 'spike')
  303. {
  304. $option_price = $goods_option_mult_value['dan_price'];
  305. }
  306. else {
  307. $option_price = $goods_option_mult_value['dan_price'];
  308. }
  309. //根据商品类型获取不同价格 begin
  310. $option_weight = $goods_option_mult_value['weight'];
  311. $option_data[] = array(
  312. 'goods_option_id' => $goods_option_id,
  313. 'goods_option_value_id' => $goods_option_item_id,
  314. 'option_id' => $goods_option_id,
  315. 'option_value_id' => $goods_option_item_id,
  316. 'name' => $option_query['title'],
  317. 'value' => $option_value_query['title'],
  318. 'quantity' => $quantity,
  319. 'price' => $option_price,
  320. 'card_price' => $goods_option_mult_value['card_price'],
  321. 'weight' => $option_weight,
  322. );
  323. }
  324. }
  325. }
  326. }
  327. $header_disc = 100;
  328. $shop_price = $goods_query['productprice'];
  329. $goods_query['price'] = $goods_query['price'];
  330. $thumb_image = D('Home/Pingoods')->get_goods_images($goods_id);
  331. if( !empty($thumb_image) )
  332. {
  333. $thumb_image = tomedia($thumb_image['image']);
  334. }
  335. if(!empty($option_value_image))
  336. {
  337. $thumb_image = tomedia($option_value_image);
  338. }
  339. $store_info = array('s_true_name' => '');
  340. $s_logo = D('Seller/Front')->get_config_by_name('shoplogo');
  341. if( !empty($s_logo) )
  342. {
  343. $s_logo = tomedia($s_logo);
  344. }
  345. //$goods_query['price']
  346. if ( !is_null($option_price)) {
  347. $goods_query['price'] = $option_price;
  348. } else {
  349. //根据商品类型获取不同价格 begin
  350. if ($buy_type == 'pintuan') {//判断类型是否是积分商品
  351. if($goods_query['type'] == 'integral')
  352. {
  353. //TODO....等待打开积分
  354. //$intgral_goods_info = M('intgral_goods')->field('score')->where( array('goods_id' => $goods_id) )->find();
  355. //$goods_query['price'] = $intgral_goods_info['score'];
  356. }
  357. else if($goods_query['type'] == 'spike')
  358. {
  359. }
  360. else{
  361. if($goods_query['type'] == 'pin')
  362. {
  363. //ims_
  364. $pin_goods = M('lionfish_comshop_good_pin')->where( array('goods_id' => $goods_id) )->find();
  365. $goods_query['price'] = $pin_goods['pinprice'];
  366. }
  367. }
  368. }
  369. //根据商品类型获取不同价格 begin
  370. }
  371. if (!empty($option_weight)) {
  372. $goods_query['weight'] = $option_weight;
  373. }
  374. //拼团才会有pin_id
  375. $pin_id = 0;
  376. if ($buy_type == 'pintuan' && isset($val['pin_id'])) {
  377. $pin_id = $val['pin_id'];
  378. }
  379. $price = $goods_query['price'];
  380. //判断是否有团长折扣 暂时屏蔽 TODO.....
  381. /**
  382. if( $buy_type == 'pin' && $pin_id == 0 && $goods_query['head_disc'] != 100)
  383. {
  384. $price = round(( $price * intval($goods_query['head_disc']) )/100,2);
  385. $header_disc = intval($goods_query['head_disc']);
  386. }
  387. **/
  388. //判断是否会员折扣 TODO。。。先关闭
  389. $level_info = array('member_discount' => 100,'level_name' =>'');
  390. $member_info = M('lionfish_comshop_member')->field('level_id')->where( array('member_id' => $member_id) )->find();
  391. $goods_common = M('lionfish_comshop_good_common')->field('is_mb_level_buy')->where( array('goods_id' => $goods_id ) )->find();
  392. $goods_query['is_mb_level_buy'] = 0;
  393. $goods_query['levelprice'] = 0;
  394. if( $buy_type == 'dan' )
  395. {
  396. if($member_info['level_id'] > 0 && $goods_common['is_mb_level_buy'] == 1)
  397. {
  398. $member_level_info = M('lionfish_comshop_member_level')->where( array('id' => $member_info['level_id'] ) )->find();
  399. $level_info['member_discount'] = $member_level_info['discount'] ;
  400. $level_info['level_name'] = $member_level_info['levelname'];
  401. $price2 = round(( $price * $member_level_info['discount'] )/100,2);
  402. $goods_query['is_mb_level_buy'] = 1;
  403. $goods_query['levelprice'] = $price2;
  404. //$goods_query['price'] = $price ;
  405. }
  406. }
  407. //判断商品能否参与满减活动 fullreduction_money
  408. $is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
  409. $can_man_jian = 0;
  410. if( $buy_type == 'dan' || $buy_type == 'soitaire')
  411. {
  412. if( !empty($is_open_fullreduction) && $is_open_fullreduction == 1)
  413. {
  414. $gd_full_info = D('Home/Front')->get_goods_common_field($goods_id , 'is_take_fullreduction,supply_id,is_new_buy');
  415. $is_take_fullreduction = $gd_full_info['is_take_fullreduction'];
  416. //supply_id
  417. if( $gd_full_info['supply_id'] > 0)
  418. {
  419. $supply_info = M('lionfish_comshop_supply')->field('type')->where( array('id' => $gd_full_info['supply_id'] ) )->find();
  420. if(!empty($supply_info) && $supply_info['type'] == 1)
  421. {
  422. $can_man_jian = 0;
  423. }else{
  424. if( $is_take_fullreduction == 1 )
  425. {
  426. $can_man_jian = 1;
  427. }
  428. }
  429. }else{
  430. if( $is_take_fullreduction == 1 )
  431. {
  432. $can_man_jian = 1;
  433. }
  434. }
  435. $is_new_buy = $gd_full_info['is_new_buy'];
  436. }
  437. }
  438. $is_open_only_express = D('Home/Front')->get_config_by_name('is_open_only_express');
  439. $is_only_express = 0;
  440. if( !empty($is_open_only_express) && $is_open_only_express == 1)
  441. {
  442. $gd_s_info = D('Home/Front')->get_goods_common_field($goods_id , 'is_only_express');
  443. $is_only_express = $gd_s_info['is_only_express'];
  444. }
  445. // $is_open_vipcard_buy
  446. if( $is_open_vipcard_buy == 1 && $goods_query['is_take_vipcard'] == 1 )
  447. {
  448. }else{
  449. $goods_query['is_take_vipcard'] == 0;
  450. }
  451. //拼团 end
  452. $this->data[$key] = array(
  453. 'key' => $val_uns['carkey'],
  454. 'goods_id' => $goods_id ,
  455. 'is_only_express' => $is_only_express,
  456. 'name' => $goods_query['goodsname'],
  457. 'seller_name' => $store_info['s_true_name'],
  458. 'seller_logo' => $s_logo,
  459. 'weight' => $option_weight,
  460. 'singledel' => $val['singledel'],
  461. //$val['singledel']
  462. 'can_man_jian' => $can_man_jian,
  463. 'header_disc' => $header_disc,
  464. 'member_disc' => $level_info['member_discount'],
  465. 'level_name' => $level_info['level_name'],
  466. 'pin_id' => $pin_id,
  467. 'shipping' => $goods_query['dispatchtype'],
  468. 'goods_freight' => $goods_query['dispatchprice'],
  469. 'transport_id' => $goods_query['dispatchid'],
  470. 'image' => $thumb_image,
  471. 'quantity' => $quantity,
  472. 'max_quantity' => $max_quantity,
  473. 'shop_price' => $shop_price,
  474. 'price' => $goods_query['price'],
  475. 'levelprice' => $goods_query['levelprice'],
  476. 'card_price' => $goods_query['card_price'],
  477. 'total' => round( ($price) * $quantity , 2),
  478. 'level_total' => round( $goods_query['levelprice'] * $quantity , 2),
  479. 'card_total' => round($goods_query['card_price'] * $quantity ,2),
  480. 'is_take_vipcard' => $goods_query['is_take_vipcard'],
  481. 'is_mb_level_buy' => $goods_query['is_mb_level_buy'],
  482. 'model' => $goods_query['model'],
  483. 'option' => $option_data,
  484. 'sku_str' => $val['sku_str'],
  485. 'soli_id' => isset($val['soli_id']) ? intval($val['soli_id']) : 0,
  486. 'is_new_buy' => $is_new_buy
  487. );
  488. } else {
  489. $this->removecar($key,$token);
  490. }
  491. }
  492. }
  493. return $this->data;
  494. }
  495. //删除商品
  496. public function removecar($key,$token) {
  497. $key = $key; //重新给$key赋值
  498. M('lionfish_comshop_car')->where( array('token' => $token,'carkey' => $key) )->delete();
  499. }
  500. //购物车是否为空
  501. public function has_goodswecar($buy_type = 'dan', $token, $community_id) {
  502. if ($buy_type == 'dan') {
  503. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  504. where token='{$token}' and community_id='{$community_id}' and carkey like 'cart.%' ";
  505. $s = M()->query($cart_sql);
  506. }
  507. else if( $buy_type == 'pindan' )
  508. {
  509. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  510. where token='{$token}' and carkey like 'pindancart.%' ";
  511. $s = M()->query($cart_sql);
  512. }else if( $buy_type == 'pintuan' )
  513. {
  514. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  515. where token='{$token}' and carkey like 'pintuancart.%' ";
  516. $s = M()->query($cart_sql);
  517. }
  518. else if( $buy_type == 'soitaire' )
  519. {
  520. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  521. where token='{$token}' and carkey like 'soitairecart.%' ";
  522. $s = M()->query($cart_sql);
  523. }
  524. else if( $buy_type == 'integral' )
  525. {
  526. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  527. where token='{$token}' and carkey like 'integralcart.%' ";
  528. $s = M()->query($cart_sql);
  529. }
  530. else if ($buy_type == 'pin') {
  531. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  532. where token='{$token}' and carkey like 'cart_activity.%' ";
  533. $s = M()->query($cart_sql);
  534. }
  535. return count($s);
  536. }
  537. public function count_activitycar($token) {
  538. $quantity = 0;
  539. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  540. where token='{$token}' and carkey like 'cart_activity.%' ";
  541. $cart = M()->query($cart_sql);
  542. foreach ($cart as $key => $val) {
  543. $format_data = unserialize($val['format_data']);
  544. $quantity += $format_data['quantity'];
  545. }
  546. return $quantity;
  547. }
  548. public function removeActivityAllcar($token ,$car_prefix='pindancart.') {
  549. M('lionfish_comshop_car')->where(" token = '{$token}' and carkey like '".$car_prefix."%' ")->delete();
  550. }
  551. public function count_goodscar($token, $community_id) {
  552. $quantity = 0;
  553. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  554. where token='{$token}' and community_id='{$community_id}' and carkey like 'cart.%' ";
  555. $cart = M()->query($cart_sql);
  556. foreach ($cart as $key => $val) {
  557. $format_data = unserialize($val['format_data']);
  558. if(isset($format_data['quantity']))
  559. $quantity += $format_data['quantity'];
  560. }
  561. return $quantity;
  562. }
  563. }