CarModel.class.php 35 KB

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