CarModel.class.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  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. //C('DB_PREFIX')
  69. $s_arr = M('lionfish_comshop_car')->field('format_data')->where( array('carkey' => $key,'token' => $token) )->find();
  70. $tmp_format_data = unserialize($s_arr['format_data']);
  71. return $tmp_format_data['quantity'];
  72. }
  73. //得到商品数量
  74. public function get_goods_quantity($goods_id) {
  75. $quantity = D('Seller/Redisorder')->get_goods_total_quantity($goods_id);
  76. if($quantity <= 0)
  77. {
  78. $info = M('lionfish_comshop_goods')->field('total as quantity')->where(array('id' =>$goods_id))->find();
  79. $quantity = $info['quantity'];
  80. }
  81. return $quantity;
  82. }
  83. public function addwecar($token, $goods_id, $format_data = array() , $option, $community_id,$car_prefix='cart.',$soli_id='') {
  84. $key = (int)$goods_id . ':'.$community_id.':';
  85. if( !empty($soli_id) )
  86. {
  87. $key .= $soli_id.':';
  88. }
  89. $qty = $format_data['quantity'];
  90. if ($option) {
  91. $key.= base64_encode($option) . ':';
  92. } else {
  93. $key.= ':';
  94. }
  95. if( $format_data['is_just_addcar'] == 0 )
  96. {
  97. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  98. where token='{$token}' and carkey like '".$car_prefix."%' ";
  99. $all_cart = M()->query($cart_sql);
  100. if(!empty($all_cart))
  101. {
  102. foreach($all_cart as $val)
  103. {
  104. $tmp_format_data = unserialize($val['format_data']);
  105. $tmp_format_data['singledel'] = 0;
  106. $tmp_format_data_new = array('format_data' => serialize($tmp_format_data) );
  107. M('lionfish_comshop_car')->where( array('id' => $val['id']) )->save( $tmp_format_data_new );
  108. }
  109. }
  110. }
  111. $carkey = $car_prefix.$key;
  112. $s_arr = M('lionfish_comshop_car')->field('format_data')->where( array('carkey' => $carkey,'token' => $token) )->find();
  113. if ((int)$qty && ((int)$qty > 0)) {
  114. $key = $car_prefix . $key;
  115. $s = array();
  116. if (!empty($s_arr)) {
  117. $s = unserialize($s_arr['format_data']);
  118. }
  119. if (!empty($s)) {
  120. if( $format_data['is_just_addcar'] == 1 )
  121. {
  122. $format_data['quantity']+= $s['quantity'];
  123. }
  124. }
  125. }
  126. if (!empty($s_arr)) {
  127. $car_data = array();
  128. $car_data['format_data'] = serialize($format_data);
  129. $car_data['modifytime'] = time();
  130. M('lionfish_comshop_car')->where( array('token' => $token,'carkey' => $key) )->save( $car_data );
  131. } else {
  132. $car_data = array();
  133. $car_data['token'] = $token;
  134. $car_data['community_id'] = $community_id;
  135. $car_data['carkey'] = $key;
  136. $car_data['modifytime'] = time();
  137. $car_data['format_data'] = serialize($format_data);
  138. M('lionfish_comshop_car')->add( $car_data );
  139. }
  140. $this->data = array();
  141. }
  142. public function add_activitycar($token, $goods_id, $format_data = array() , $option) {
  143. global $_W;
  144. global $_GPC;
  145. $this->removeActivityAllcar($token);
  146. $key = (int)$goods_id . ':';
  147. $qty = $format_data['quantity'];
  148. if ($option) {
  149. $key.= base64_encode($option) . ':';
  150. } else {
  151. $key.= ':';
  152. }
  153. $key.= "buy_type:" ;
  154. if ((int)$qty && ((int)$qty > 0)) {
  155. $key = 'cart_activity.' . $key;
  156. $carkey = 'cart.'.$key;
  157. $s_arr = M('lionfish_comshop_car')->where( array('token' => $token, 'carkey' => $carkey) )->find();
  158. $s = array();
  159. if (!empty($s_arr)) {
  160. $s = unserialize($s_arr['format_data']);
  161. }
  162. if (!empty($s)) {
  163. $format_data['quantity']+= $s['quantity'];
  164. }
  165. if (!empty($s_arr)) {
  166. $car_data = array();
  167. $car_data['format_data'] = serialize($format_data);
  168. M('lionfish_comshop_car')->where( array('token' => $token,'carkey' => $key) )->save( $car_data );
  169. } else {
  170. $car_data = array();
  171. $car_data['token'] = $token;
  172. $car_data['carkey'] = $key;
  173. $car_data['format_data'] = serialize($format_data);
  174. M('lionfish_comshop_car')->add($car_data);
  175. }
  176. }
  177. $this->data = array();
  178. }
  179. /**
  180. * @author yj
  181. * @desc 获取不同类型的购物车数据
  182. * @param string $buy_type
  183. * @param $token
  184. * @param $community_id
  185. * @param string $soli_id
  186. * @return array|mixed
  187. */
  188. public function getCarDataByTypeAndHeadIdAndToken( $buy_type = 'dan', $token, $community_id,$soli_id='' )
  189. {
  190. $cart = [];
  191. //单独购买类型
  192. if ($buy_type == 'dan') {
  193. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  194. where token='{$token}' and community_id='{$community_id}' and carkey like 'cart.%' order by modifytime desc ";
  195. $cart = M()->query($cart_sql);
  196. }
  197. else if( $buy_type == 'pindan' )
  198. {//拼团单独购买
  199. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  200. where token='{$token}' and community_id={$community_id} and carkey like 'pindancart.%' order by modifytime desc ";
  201. $cart = M()->query($cart_sql);
  202. }else if( $buy_type == 'pintuan' )
  203. {
  204. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  205. where token='{$token}' and community_id={$community_id} and carkey like 'pintuancart.%' order by modifytime desc ";
  206. $cart = M()->query($cart_sql);
  207. }
  208. else if( $buy_type == 'presale' )
  209. {
  210. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  211. where token='{$token}' and community_id={$community_id} and carkey like 'presalecart.%' order by modifytime desc ";
  212. $cart = M()->query($cart_sql);
  213. }
  214. else if( $buy_type == 'virtualcard' )
  215. {
  216. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  217. where token='{$token}' and community_id={$community_id} and carkey like 'virtualcardcart.%' order by modifytime desc ";
  218. $cart = M()->query($cart_sql);
  219. }
  220. else if( $buy_type == 'soitaire' )
  221. {
  222. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  223. where token='{$token}' and community_id={$community_id} and carkey like 'soitairecart.%' order by modifytime desc ";
  224. $cart_arr = M()->query($cart_sql);
  225. $cart = array();
  226. if( !empty($cart_arr) )
  227. {
  228. foreach( $cart_arr as $key => $val )
  229. {
  230. $key_arr = explode(':', $val['carkey']);
  231. if( $key_arr[2] == $soli_id )
  232. {
  233. $cart[$key] = $val;
  234. }
  235. }
  236. }
  237. }
  238. else if( $buy_type == 'integral' )
  239. {
  240. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  241. where token='{$token}' and community_id={$community_id} and carkey like 'integralcart.%' order by modifytime desc ";
  242. $cart = M()->query($cart_sql);
  243. }
  244. else {
  245. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  246. where token='{$token}' and community_id='{$community_id}' and carkey like 'cart_activity.%' order by modifytime desc ";
  247. $cart = M()->query($cart_sql);
  248. }
  249. return $cart;
  250. }
  251. /**
  252. * @author yj
  253. * @desc 获取所有购物车中的商品
  254. * @param string $buy_type
  255. * @param $token
  256. * @param int $is_pay_need
  257. * @param $community_id
  258. * @param string $soli_id
  259. * @return array
  260. */
  261. public function get_all_goodswecar($buy_type = 'dan', $token,$is_pay_need = 1, $community_id,$soli_id='') {
  262. if (!($this->data)) {
  263. //获取购物车中数据
  264. $cart = $this->getCarDataByTypeAndHeadIdAndToken( $buy_type , $token, $community_id,$soli_id );
  265. $is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
  266. $is_open_vipcard_buy = !empty($is_open_vipcard_buy) && $is_open_vipcard_buy ==1 ? 1:0;
  267. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  268. $member_id = $weprogram_token['member_id'];
  269. //$goods_model = D('Home/Goods');
  270. foreach ($cart as $key => $val_uns) {
  271. $val = unserialize( $val_uns['format_data'] );
  272. if($buy_type =='dan' && $is_pay_need == 1)
  273. {
  274. if(isset($val['singledel']) && $val['singledel'] == 0)
  275. {
  276. continue;
  277. }
  278. }else if($buy_type == 'dan' && $is_pay_need == 0)
  279. {
  280. //判断是否支持自提,如果支持自提,那么就不要剔除购物车列表
  281. //$val['goods_id'] pick_just pick_just
  282. $goods_common_info = D('Seller/Front')->get_goods_common_field($val['goods_id'] , 'pick_just');
  283. $pick_just = $goods_common_info['pick_just'];
  284. if(!empty($pick_just) && isset($pick_just['pick_just']) && $pick_just['pick_just'] > 0)
  285. {
  286. //continue;
  287. }else {
  288. }
  289. }
  290. //$pin_type = $val['pin_type'];
  291. $quantity = $val['quantity'];
  292. //$quantity
  293. $goods = explode(':', $key);
  294. $goods_id = $val['goods_id'];
  295. $stock = true;
  296. // Options sku_str
  297. $options = $val['sku_str'];
  298. $goods_query_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_goods as p left join ".C('DB_PREFIX')."lionfish_comshop_good_commiss as pd
  299. on p.id = pd.goods_id where p.id ={$goods_id} ";
  300. $goods_query_arr = M()->query($goods_query_sql);
  301. $goods_query = $goods_query_arr[0];
  302. $goods_query['model'] = $goods_query['codes'];
  303. if ($goods_query) {
  304. $option_price = null;
  305. $option_weight = $goods_query['weight'];
  306. $option_data = array();
  307. $max_quantity = $goods_query['total'];
  308. if (!empty($options)) {
  309. $goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->where( array('goods_id' => $goods_id,'option_item_ids' => $options) )->find();
  310. $goods_option_mult_value['pin_price'] = $goods_option_mult_value['pinprice'];
  311. $goods_option_mult_value['dan_price'] = $goods_option_mult_value['marketprice'];
  312. $goods_option_mult_value['costprice'] = $goods_option_mult_value['costprice'];
  313. $goods_query['card_price'] = $goods_option_mult_value['card_price'];
  314. $goods_query['costprice'] = $goods_option_mult_value['costprice'];
  315. $goods_query['model'] = $goods_option_mult_value['goodssn'];
  316. $options_arr = array();
  317. $option_value_id_arr = explode('_', $options);
  318. foreach ($option_value_id_arr as $id_val) {
  319. $goods_option_value = M('lionfish_comshop_goods_option_item')->where( array('goods_id' => $goods_id,'id' => $id_val) )->find();
  320. $options_arr[$goods_option_value['goods_option_id']] = $goods_option_value['id'];
  321. }
  322. }
  323. $option_value_image = '';
  324. if($options_arr){
  325. foreach ($options_arr as $goods_option_id => $goods_option_item_id ) {
  326. //option_value
  327. $option_query = M('lionfish_comshop_goods_option')->where( array('goods_id' => $goods_id,'id' => $goods_option_id) )->find();
  328. if ($option_query) {
  329. $option_value_query = M('lionfish_comshop_goods_option_item')->where( array('id' => $goods_option_item_id,'goods_id' => $goods_id) )->find();
  330. if ($option_value_query) {
  331. if( !empty($option_value_query['thumb']) )
  332. {
  333. $option_value_image = $option_value_query['thumb'];
  334. }
  335. $max_quantity = $goods_option_mult_value['stock'];
  336. //根据商品类型获取不同价格 begin pinprice pin_price productprice dan_price
  337. if ($buy_type == 'pintuan' && $goods_query['type'] != 'spike') {
  338. $option_price = $goods_option_mult_value['pin_price'];
  339. }else if($goods_query['type'] == 'spike')
  340. {
  341. $option_price = $goods_option_mult_value['dan_price'];
  342. }
  343. else {
  344. $option_price = $goods_option_mult_value['dan_price'];
  345. }
  346. //根据商品类型获取不同价格 begin
  347. $option_weight = $goods_option_mult_value['weight'];
  348. $costprice = $goods_option_mult_value['costprice'];
  349. $option_data[] = array(
  350. 'goods_option_id' => $goods_option_id,
  351. 'goods_option_value_id' => $goods_option_item_id,
  352. 'option_id' => $goods_option_id,
  353. 'option_value_id' => $goods_option_item_id,
  354. 'name' => $option_query['title'],
  355. 'value' => $option_value_query['title'],
  356. 'quantity' => $quantity,
  357. 'price' => $option_price,
  358. 'card_price' => $goods_option_mult_value['card_price'],
  359. 'costprice' => $costprice,
  360. 'weight' => $option_weight,
  361. );
  362. }
  363. }
  364. }
  365. }
  366. $header_disc = 100;
  367. $shop_price = $goods_query['productprice'];
  368. $goods_query['price'] = $goods_query['price'];
  369. $thumb_image = D('Home/Pingoods')->get_goods_images($goods_id);
  370. if( !empty($thumb_image) )
  371. {
  372. $thumb_image = tomedia($thumb_image['image']);
  373. }
  374. if(!empty($option_value_image))
  375. {
  376. $thumb_image = tomedia($option_value_image);
  377. }
  378. $store_info = array('s_true_name' => '');
  379. $s_logo = D('Seller/Front')->get_config_by_name('shoplogo');
  380. if( !empty($s_logo) )
  381. {
  382. $s_logo = tomedia($s_logo);
  383. }
  384. //$goods_query['price']
  385. if ( !is_null($option_price)) {
  386. $goods_query['price'] = $option_price;
  387. } else {
  388. //根据商品类型获取不同价格 begin
  389. if ($buy_type == 'pintuan') {//判断类型是否是积分商品
  390. if($goods_query['type'] == 'integral')
  391. {
  392. //TODO....等待打开积分
  393. //$intgral_goods_info = M('intgral_goods')->field('score')->where( array('goods_id' => $goods_id) )->find();
  394. //$goods_query['price'] = $intgral_goods_info['score'];
  395. }
  396. else if($goods_query['type'] == 'spike')
  397. {
  398. }
  399. else{
  400. if($goods_query['type'] == 'pin')
  401. {
  402. //ims_
  403. $pin_goods = M('lionfish_comshop_good_pin')->where( array('goods_id' => $goods_id) )->find();
  404. $goods_query['price'] = $pin_goods['pinprice'];
  405. }
  406. }
  407. }
  408. //根据商品类型获取不同价格 begin
  409. }
  410. if (!empty($option_weight)) {
  411. $goods_query['weight'] = $option_weight;
  412. }
  413. //拼团才会有pin_id
  414. $pin_id = 0;
  415. if ($buy_type == 'pintuan' && isset($val['pin_id'])) {
  416. $pin_id = $val['pin_id'];
  417. }
  418. $price = $goods_query['price'];
  419. //判断是否有团长折扣 暂时屏蔽 TODO.....
  420. /**
  421. if( $buy_type == 'pin' && $pin_id == 0 && $goods_query['head_disc'] != 100)
  422. {
  423. $price = round(( $price * intval($goods_query['head_disc']) )/100,2);
  424. $header_disc = intval($goods_query['head_disc']);
  425. }
  426. **/
  427. //判断是否会员折扣 TODO。。。先关闭
  428. $level_info = array('member_discount' => 100,'level_name' =>'');
  429. $member_info = M('lionfish_comshop_member')->field('level_id')->where( array('member_id' => $member_id) )->find();
  430. //修改商品独立会员等级折扣设置 2020.05.11
  431. $goods_common = M('lionfish_comshop_good_common')->field('is_mb_level_buy,has_mb_level_buy,mb_level_buy_list,packing_free,goods_start_count')->where( array('goods_id' => $goods_id ) )->find();
  432. $goods_query['is_mb_level_buy'] = 0;
  433. $goods_query['levelprice'] = 0;
  434. $goods_query['goods_start_count'] = $goods_common['goods_start_count'];
  435. if( $buy_type == 'dan' || $buy_type == 'soitaire' )
  436. {
  437. //商品独立会员等级折扣 begin 关闭会员折扣
  438. if($member_info['level_id'] > 0 && $goods_common['has_mb_level_buy'] == 1 && $goods_common['is_mb_level_buy'] == 1 && $buy_type != 'pesale' ){
  439. $member_level_info = M('lionfish_comshop_member_level')->where( array('id' => $member_info['level_id'] ) )->find();
  440. $mb_level_buy_list = unserialize($goods_common['mb_level_buy_list']);
  441. $mb_level_discount_list = array();
  442. foreach($mb_level_buy_list as $k=>$v){
  443. $mb_level_discount_list[$v['level_id']] = $v['discount'];
  444. }
  445. if(isset($mb_level_discount_list[$member_info['level_id']]) && !empty($mb_level_discount_list[$member_info['level_id']])){
  446. $level_info['member_discount'] = $mb_level_discount_list[$member_info['level_id']];
  447. }else{
  448. $level_info['member_discount'] = 0;
  449. }
  450. if($level_info['member_discount']>0 && $level_info['member_discount'] <100)
  451. {
  452. $level_info['level_name'] = $member_level_info['levelname'];
  453. if($level_info['member_discount'] == 0){
  454. $price2 = round( $price,2);
  455. }else{
  456. $price2 = round(( $price * $mb_level_discount_list[$member_info['level_id']] )/100,2);
  457. }
  458. $goods_query['is_mb_level_buy'] = 1;
  459. $goods_query['levelprice'] = $price2;
  460. //商品独立会员等级折扣 end
  461. }
  462. }else{
  463. //预售不参与会员等级折扣
  464. if($member_info['level_id'] > 0 && $goods_common['is_mb_level_buy'] == 1 && $buy_type != 'pesale')
  465. {
  466. $member_level_info = M('lionfish_comshop_member_level')->where( array('id' => $member_info['level_id'] ) )->find();
  467. $level_info['member_discount'] = $member_level_info['discount'] ;
  468. if( $level_info['member_discount'] > 0 && $level_info['member_discount'] < 100 )
  469. {
  470. $level_info['level_name'] = $member_level_info['levelname'];
  471. $price2 = round(( $price * $member_level_info['discount'] )/100,2);
  472. $goods_query['is_mb_level_buy'] = 1;
  473. $goods_query['levelprice'] = $price2;
  474. //$goods_query['price'] = $price2 ;
  475. //$price = $price2;//['price'];
  476. }
  477. }
  478. }
  479. }
  480. //判断商品能否参与满减活动 fullreduction_money
  481. $is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
  482. $can_man_jian = 0;
  483. //预售不参与满减
  484. if( $buy_type == 'pesale')
  485. {
  486. $is_open_fullreduction = 0;
  487. }
  488. if( $buy_type == 'dan' || $buy_type == 'soitaire' || $buy_type == 'virtualcard' )
  489. {
  490. if( !empty($is_open_fullreduction) && $is_open_fullreduction == 1)
  491. {
  492. $gd_full_info = D('Home/Front')->get_goods_common_field($goods_id , 'is_take_fullreduction,supply_id,is_new_buy');
  493. $is_take_fullreduction = $gd_full_info['is_take_fullreduction'];
  494. //supply_id
  495. if( $gd_full_info['supply_id'] > 0)
  496. {
  497. $supply_info = M('lionfish_comshop_supply')->field('type')->where( array('id' => $gd_full_info['supply_id'] ) )->find();
  498. if(!empty($supply_info) && $supply_info['type'] == 1)
  499. {
  500. $can_man_jian = 0;
  501. }else{
  502. if( $is_take_fullreduction == 1 )
  503. {
  504. $can_man_jian = 1;
  505. }
  506. }
  507. }else{
  508. if( $is_take_fullreduction == 1 )
  509. {
  510. $can_man_jian = 1;
  511. }
  512. }
  513. $is_new_buy = $gd_full_info['is_new_buy'];
  514. }
  515. }
  516. $is_open_only_express = D('Home/Front')->get_config_by_name('is_open_only_express');
  517. $is_only_express = 0;
  518. if( !empty($is_open_only_express) && $is_open_only_express == 1)
  519. {
  520. $gd_s_info = D('Home/Front')->get_goods_common_field($goods_id , 'is_only_express');
  521. $is_only_express = $gd_s_info['is_only_express'];
  522. }
  523. if( $is_only_express == 0 )
  524. {
  525. $gd_s_info = D('Home/Front')->get_goods_common_field($goods_id , 'is_only_distribution,supply_id,is_only_hexiao');
  526. $is_only_distribution = $gd_s_info['is_only_distribution'];
  527. $isopen_localtown_delivery = D('Home/Front')->get_config_by_name('isopen_localtown_delivery');
  528. if($gd_s_info['supply_id'] > 0){
  529. $isopen_supply_localtown_delivery = D('Home/Front')->get_supply_config_by_name('isopen_localtown_delivery',$gd_s_info['supply_id']);
  530. if( $is_only_distribution == 1 && $isopen_localtown_delivery == 1 && $isopen_supply_localtown_delivery == 1)
  531. {
  532. $is_only_express = 3;
  533. }
  534. }else{
  535. if( $is_only_distribution == 1 && $isopen_localtown_delivery == 1)
  536. {
  537. $is_only_express = 3;
  538. }
  539. }
  540. if($gd_s_info['is_only_hexiao'] == 1){
  541. $is_only_express = 2;
  542. }
  543. }
  544. // $is_open_vipcard_buy
  545. if( $is_open_vipcard_buy == 1 && $goods_query['is_take_vipcard'] == 1 )
  546. {
  547. }else{
  548. $goods_query['is_take_vipcard'] = 0;
  549. }
  550. //拼团 end
  551. //begin 检测是否校验组件
  552. $isTradeComponts = D('Seller/MpModifyTradeComponts')->checkGoodsIsTradeComponts( $goods_id );
  553. //end 检测是否校验组件
  554. $this->data[$key] = array(
  555. 'key' => $val_uns['carkey'],
  556. 'goods_id' => $goods_id ,
  557. 'is_only_express' => $is_only_express,
  558. 'name' => $goods_query['goodsname'],
  559. 'seller_name' => $store_info['s_true_name'],
  560. 'seller_logo' => $s_logo,
  561. 'weight' => $option_weight,
  562. 'singledel' => $val['singledel'],
  563. //$val['singledel']
  564. 'can_man_jian' => $can_man_jian,
  565. 'header_disc' => $header_disc,
  566. 'member_disc' => $level_info['member_discount'],
  567. 'level_name' => $level_info['level_name'],
  568. 'pin_id' => $pin_id,
  569. 'shipping' => $goods_query['dispatchtype'],
  570. 'goods_freight' => $goods_query['dispatchprice'],
  571. 'transport_id' => $goods_query['dispatchid'],
  572. 'image' => $thumb_image,
  573. 'quantity' => $quantity,
  574. 'max_quantity' => $max_quantity,
  575. 'shop_price' => $shop_price,
  576. 'price' => $goods_query['price'],
  577. 'costprice' => $goods_query['costprice'],
  578. 'levelprice' => $goods_query['levelprice'],
  579. 'card_price' => $goods_query['card_price'],
  580. 'total' => round( ($price) * $quantity , 2),
  581. 'level_total' => round( $goods_query['levelprice'] * $quantity , 2),
  582. 'card_total' => round($goods_query['card_price'] * $quantity ,2),
  583. 'is_take_vipcard' => $goods_query['is_take_vipcard'],
  584. 'is_mb_level_buy' => $goods_query['is_mb_level_buy'],
  585. 'model' => $goods_query['model'],
  586. 'option' => $option_data,
  587. 'sku_str' => $val['sku_str'],
  588. 'soli_id' => isset($val['soli_id']) ? intval($val['soli_id']) : 0,
  589. 'is_new_buy' => $is_new_buy,
  590. 'packing_free' => $goods_common['packing_free'],
  591. 'goods_start_count' => $goods_query['goods_start_count'],
  592. 'isTradeComponts' => $isTradeComponts,//是否参与交易组件
  593. );
  594. } else {
  595. $this->removecar($key,$token);
  596. }
  597. }
  598. }
  599. return $this->data;
  600. }
  601. //删除商品
  602. public function removecar($key,$token) {
  603. $key = $key; //重新给$key赋值
  604. M('lionfish_comshop_car')->where( array('token' => $token,'carkey' => $key) )->delete();
  605. }
  606. //购物车是否为空
  607. public function has_goodswecar($buy_type = 'dan', $token, $community_id) {
  608. if ($buy_type == 'dan') {
  609. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  610. where token='{$token}' and community_id='{$community_id}' and carkey like 'cart.%' ";
  611. $s = M()->query($cart_sql);
  612. }
  613. else if( $buy_type == 'pindan' )
  614. {
  615. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  616. where token='{$token}' and carkey like 'pindancart.%' ";
  617. $s = M()->query($cart_sql);
  618. }else if( $buy_type == 'pintuan' )
  619. {
  620. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  621. where token='{$token}' and carkey like 'pintuancart.%' ";
  622. $s = M()->query($cart_sql);
  623. }
  624. else if( $buy_type == 'soitaire' )
  625. {
  626. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  627. where token='{$token}' and carkey like 'soitairecart.%' ";
  628. $s = M()->query($cart_sql);
  629. }
  630. else if( $buy_type == 'presale' )
  631. {
  632. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  633. where token='{$token}' and carkey like 'presalecart.%' ";
  634. $s = M()->query($cart_sql);
  635. }
  636. else if( $buy_type == 'virtualcard' )
  637. {
  638. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  639. where token='{$token}' and carkey like 'virtualcardcart.%' ";
  640. $s = M()->query($cart_sql);
  641. }
  642. else if( $buy_type == 'integral' )
  643. {
  644. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  645. where token='{$token}' and carkey like 'integralcart.%' ";
  646. $s = M()->query($cart_sql);
  647. }
  648. else if ($buy_type == 'pin') {
  649. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  650. where token='{$token}' and carkey like 'cart_activity.%' ";
  651. $s = M()->query($cart_sql);
  652. }
  653. return count($s);
  654. }
  655. public function count_activitycar($token) {
  656. $quantity = 0;
  657. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  658. where token='{$token}' and carkey like 'cart_activity.%' ";
  659. $cart = M()->query($cart_sql);
  660. foreach ($cart as $key => $val) {
  661. $format_data = unserialize($val['format_data']);
  662. $quantity += $format_data['quantity'];
  663. }
  664. return $quantity;
  665. }
  666. public function removeActivityAllcar($token ,$car_prefix='pindancart.') {
  667. M('lionfish_comshop_car')->where(" token = '{$token}' and carkey like '".$car_prefix."%' ")->delete();
  668. }
  669. public function count_goodscar($token, $community_id) {
  670. $quantity = 0;
  671. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  672. where token='{$token}' and community_id='{$community_id}' and carkey like 'cart.%' ";
  673. $cart = M()->query($cart_sql);
  674. foreach ($cart as $key => $val) {
  675. $format_data = unserialize($val['format_data']);
  676. if(isset($format_data['quantity']))
  677. $quantity += $format_data['quantity'];
  678. }
  679. return $quantity;
  680. }
  681. /**
  682. * @author cy 2020-12-07
  683. * @desc 获取会员购物车中新人专享商品种类数
  684. * @param $token
  685. * @param $gid 商品id
  686. * @param $sku_str 商品规格id
  687. * @return int
  688. */
  689. public function get_new_goods_count($token,$gid,$sku_str){
  690. $count = 0;
  691. $cart_sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_car
  692. where token='{$token}' and carkey like 'cart.%' ";
  693. $cart = M()->query($cart_sql);
  694. foreach ($cart as $key => $val) {
  695. $format_data = unserialize($val['format_data']);
  696. $goods_id = $format_data['goods_id'];
  697. $goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'is_new_buy');
  698. if( !empty($goods_description['is_new_buy']) && $goods_description['is_new_buy'] == 1){
  699. if($goods_id != $gid){
  700. $count++;
  701. }else{
  702. if(!empty($sku_str) && $sku_str != $format_data['sku_str']){
  703. $count++;
  704. }
  705. }
  706. }
  707. }
  708. return $count;
  709. }
  710. }