123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 16/9/19
- * Time: 下午6:48
- */
- require_once (BASE_ROOT_PATH . '/helper/activity_helper.php');
- require_once (BASE_ROOT_PATH . '/helper/goods_helper.php');
- require_once (BASE_ROOT_PATH . '/helper/pay_helper.php');
- require_once (BASE_ROOT_PATH . '/helper/predeposit_helper.php');
- class buy_first
- {
- private $mLogicOut;
- public function __construct($logic_out)
- {
- $this->mLogicOut = $logic_out;
- }
- //商品金额相关信息
- private function payinfo()
- {
- $result = [];
- //商品总价,红包可抵扣,满减金额
- $goods_amount = 0.00;
- $store_goods_total = $this->mLogicOut['store_goods_total'];
- foreach ($store_goods_total as $store_id => $value) {
- $goods_amount += doubleval($value);
- }
- $result['goods_amount'] = $goods_amount;
- //满送
- $full_discount = 0.00;
- $full_desc = '';
- $store_mansong_rule_list = $this->mLogicOut['store_mansong_rule_list'];
- foreach ($store_mansong_rule_list as $store_id => $value) {
- $full_discount += doubleval($value['discount']);
- $full_desc = $this->full_desc($value['desc']);
- }
- $result['full_discount'] = $full_discount;
- $result['full_desc'] = $full_desc;
- $result['full_goods'] = $this->full_goods();
- //运费
- if($this->freight($freight,$offpay_hash,$offpay_hash_batch) == true) {
- $result['freight'] = $freight;
- $result['offpay_hash_batch'] = $offpay_hash_batch;
- $result['offpay_hash'] = $offpay_hash;
- } else {
- $result['freight'] = 0;
- $result['offpay_hash_batch'] = "";
- $result['offpay_hash'] = "";
- }
- $result['freight_hash'] = $this->mLogicOut['freight_list'];
- //红包信息
- $result['total_pred'] = doubleval($this->mLogicOut['available_predeposit']);
- $result['available_pred'] = doubleval($this->available_pred($goods_amount,$full_discount,$result['total_pred']));
- $result['usable_pred'] = true;
- $result['pay_cash_pred'] = $result['goods_amount'] + $result['freight'] - $result['full_discount'] - $result['available_pred'];
- $result['pay_cash_nopred'] = $result['goods_amount'] + $result['freight'] - $result['full_discount'];
- //是否可以开增值税发票
- $result['vat_deny'] = $this->mLogicOut['vat_deny'];
- //发票
- $result['vat_hash'] = $this->mLogicOut['vat_hash'];
- return $result;
- }
- private function full_desc($desc)
- {
- $ret = preg_match('#(.*?)<a.*?title=("|\')(.*?)\2.*?>.*?</a>#s',$desc,$matches);
- if($ret != false && count($matches) == 4) {
- $desc = $matches[1] . $matches[3];
- }
- return $desc;
- }
- private function full_goods()
- {
- $store_mansong_rule_list = $this->mLogicOut['store_mansong_rule_list'];
- foreach ($store_mansong_rule_list as $store_id => $value) {
- return intval($value['goods_id']);
- }
- return 0;
- }
- private function city_id()
- {
- $address_info = $this->mLogicOut['address_info'];
- if(empty($address_info)) {
- return false;
- } else {
- return intval($address_info['city_id']);
- }
- }
- private function area_id()
- {
- $address_info = $this->mLogicOut['address_info'];
- if(empty($address_info)) {
- return false;
- } else {
- return intval($address_info['area_id']);
- }
- }
- private function paytype()
- {
- return pay_helper::pay_types();
- }
- //运费相关信息
- private function freight(&$freight,&$offpay_hash,&$offpay_hash_batch)
- {
- $logic_buy = Logic("buy");
- $freight_hash = $this->mLogicOut['freight_list'];
- $city_id = $this->city_id();
- $area_id = $this->area_id();
- $data = $logic_buy->changeAddr($freight_hash, $city_id, $area_id, $_SESSION['member_id']);
- if (!empty($data) && $data['state'] == 'success')
- {
- $offpay_hash = $data['offpay_hash'];
- $offpay_hash_batch = $data['offpay_hash_batch'];
- $freight = 0.00;
- foreach ($data['content'] as $value) {
- $freight += $value['value'];
- }
- return true;
- }
- else {
- return false;
- }
- }
- private function goods_ids()
- {
- $ids = [];
- $sent_id = $this->full_goods();
- if($sent_id > 0) {
- $ids[] = $sent_id;
- }
- $carts = $this->goods_list();
- foreach ($carts as $item)
- {
- if($item['bl_id'] > 0)
- {
- $bl_goods = activity_helper::bundling_goods($item['bl_id']);
- if($bl_goods != false) {
- foreach ($bl_goods as $gid) {
- $ids[] = $gid;
- }
- }
- }
- else
- {
- $ids[] = $item['goods_id'];
- }
- }
- return $ids;
- }
- private function summary()
- {
- $goods_ids = $this->goods_ids();
- $helper = new goods_helper();
- $summaries = $helper->get_summary($goods_ids,$related_goods);
- $summary_list = $summaries['summary'];
- if(!empty($related_goods)) {
- $related_summary = $helper->cart_summary($related_goods,$x);
- $summary_list = array_merge($summary_list,$related_summary['summary']);
- }
- $ret['summary'] = $summary_list;
- $ret['groupbuy'] = $summaries['groupbuy'];
- $ret['limitime'] = $summaries['limitime'];
- $ret['bundling'] = $summaries['bundling'];
- return $ret;
- }
- private function address()
- {
- return $this->mLogicOut['address_info'];
- }
- private function goods_list()
- {
- //购物车中商品列表
- $goods_list = [];
- $store_cart_list = $this->mLogicOut['store_cart_list'];
- foreach ($store_cart_list as $store_id => $carts)
- {
- foreach ($carts as $value) {
- $item['goods_id'] = intval($value['goods_id']);
- $item['goods_num'] = intval($value['goods_num']);
- $item['bl_id'] = intval($value['bl_id']);
- $goods_list[] = $item;
- }
- }
- return $goods_list;
- }
- private function invoice()
- {
- return $this->mLogicOut['inv_info'];
- }
- private function available_pred($goods_amount,$full_discount,$pd_total)
- {
- $full = intval($full_discount * 100 + 0.5);
- $scale = predeposit_helper::scale();
- $pred_amound = $this->pred_goods_amount();
- if($full > 0) {
- $pred_amound = intval($pred_amound - ($pred_amound / $goods_amount) * $full_discount);
- }
- $pred_cend = intval($pred_amound * $scale * 100 + 0.5);
- $pd_total = intval($pd_total * 100 + 0.5);
- return ($pred_cend > $pd_total) ? ($pd_total / 100) : ($pred_cend / 100);
- }
- private function pred_goods_amount()
- {
- $pred_amount = 0.00;
- $cart_list = $this->mLogicOut['store_cart_list'];
- foreach ($cart_list as $store => $cart)
- {
- foreach ($cart as $item)
- {
- $goods_total = $item['goods_total'];
- if(intval($item['bl_id']) > 0) {
- }
- elseif(!empty($item['groupbuy_info'])) {
- }
- elseif(!empty($item['xianshi_info'])) {
- }
- else {
- $pred_amount += $goods_total;
- }
- }
- }
- Log::record("pred_goods_amount = {$pred_amount}",Log::DEBUG);
- return $pred_amount;
- }
- public function format()
- {
- $result = [];
- $result['payinfo'] = $this->payinfo();
- $result['paytype'] = $this->paytype();
- $result['address'] = $this->address();
- $result['invoice'] = $this->invoice();
- $result['goods_list'] = $this->goods_list();
- $summary = $this->summary();
- $result['summary'] = $summary['summary'];
- $result['groupbuy'] = $summary['groupbuy'];
- $result['limitime'] = $summary['limitime'];
- $result['bundling'] = $summary['bundling'];
- return $result;
- }
- }
|