Ejemplo n.º 1
0
 public function getProrule()
 {
     $proRuleObj = new ProRule(999999999);
     $proRuleObj->isGiftOnce = false;
     $proRuleObj->isCashOnce = false;
     return $proRuleObj->getInfo();
 }
Ejemplo n.º 2
0
 public function getProrule($seller_id = 0)
 {
     $proRuleObj = new ProRule(999999999, $seller_id);
     $proRuleObj->isGiftOnce = false;
     $proRuleObj->isCashOnce = false;
     return $proRuleObj->getInfo();
 }
Ejemplo n.º 3
0
 /**
  * @brief查看订单
  */
 public function order_show()
 {
     //获得post传来的值
     $order_id = IFilter::act(IReq::get('id'), 'int');
     $data = array();
     if ($order_id) {
         $order_show = new Order_Class();
         $data = $order_show->getOrderShow($order_id);
         if ($data) {
             //获得折扣前的价格
             $rule = new ProRule($data['real_amount']);
             $this->result = $rule->getInfo();
             //获取地区
             $areas_id = $data['province'] . ',' . $data['city'] . ',' . $data['area'];
             $tb_area = new IModel('areas');
             $area_info = $tb_area->query('area_id in (' . $areas_id . ')');
             $data['area_addr'] = $area_info[0]['area_name'] . ' ' . $area_info[1]['area_name'] . ' ' . $area_info[2]['area_name'];
             $this->setRenderData($data);
             $this->redirect('order_show', false);
         }
     }
     if (!$data) {
         $this->redirect('order_list');
     }
 }
Ejemplo n.º 4
0
 /**
  * @brief查看订单
  */
 public function order_show()
 {
     //获得post传来的值
     $order_id = IFilter::act(IReq::get('id'), 'int');
     $data = array();
     if ($order_id) {
         $order_show = new Order_Class();
         $data = $order_show->getOrderShow($order_id);
         if ($data) {
             //获得折扣前的价格
             $rule = new ProRule($data['real_amount']);
             $this->result = $rule->getInfo();
             //获取地区
             $data['area_addr'] = join(' ', area::name($data['province'], $data['city'], $data['area']));
             $this->setRenderData($data);
             $this->redirect('order_show', false);
         }
     }
     if (!$data) {
         $this->redirect('order_list');
     }
 }
Ejemplo n.º 5
0
 /**
  * @brief 计算商品价格
  * @param Array $buyInfo ,购物车格式
  * @return array or bool
  */
 public function goodsCount($buyInfo)
 {
     $this->sum = 0;
     //原始总额(优惠前)
     $this->final_sum = 0;
     //应付总额(优惠后)
     $this->weight = 0;
     //总重量
     $this->reduce = 0;
     //减少总额
     $this->count = 0;
     //总数量
     $this->promotion = array();
     //促销活动规则文本
     $this->proReduce = 0;
     //促销活动规则优惠额
     $this->point = 0;
     //增加积分
     $this->exp = 0;
     //增加经验
     $this->isFreeFreight = false;
     //是否免运费
     $user_id = $this->user_id;
     $group_id = $this->group_id;
     $goodsList = array();
     $productList = array();
     /*开始计算goods和product的优惠信息 , 会根据条件分析出执行以下哪一种情况:
      *(1)查看此商品(货品)是否已经根据不同会员组设定了优惠价格;
      *(2)当前用户是否属于某个用户组中的成员,并且此用户组享受折扣率;
      *(3)优惠价等于商品(货品)原价;
      */
     //获取商品或货品数据
     /*Goods 拼装商品优惠价的数据*/
     if (isset($buyInfo['goods']['id']) && $buyInfo['goods']['id']) {
         //购物车中的商品数据
         $goodsIdStr = join(',', $buyInfo['goods']['id']);
         $goodsObj = new IModel('goods as go');
         $goodsList = $goodsObj->query('go.id in (' . $goodsIdStr . ')', 'go.name,go.id as goods_id,go.img,go.sell_price,go.point,go.weight,go.store_nums,go.exp,go.goods_no,0 as product_id');
         //开始优惠情况判断
         foreach ($goodsList as $key => $val) {
             //检查库存
             if ($buyInfo['goods']['data'][$val['goods_id']]['count'] <= 0 || $buyInfo['goods']['data'][$val['goods_id']]['count'] > $val['store_nums']) {
                 return "商品:" . $val['name'] . "购买数量超出库存,请重新调整购买数量";
             }
             $groupPrice = $this->getGroupPrice($val['goods_id'], 'goods');
             $goodsList[$key]['reduce'] = $groupPrice === null ? 0 : $val['sell_price'] - $groupPrice;
             $goodsList[$key]['count'] = $buyInfo['goods']['data'][$val['goods_id']]['count'];
             $current_sum_all = $goodsList[$key]['sell_price'] * $goodsList[$key]['count'];
             $current_reduce_all = $goodsList[$key]['reduce'] * $goodsList[$key]['count'];
             $goodsList[$key]['sum'] = $current_sum_all - $current_reduce_all;
             //全局统计
             $this->weight += $val['weight'] * $goodsList[$key]['count'];
             $this->point += $val['point'] * $goodsList[$key]['count'];
             $this->exp += $val['exp'] * $goodsList[$key]['count'];
             $this->sum += $current_sum_all;
             $this->reduce += $current_reduce_all;
             $this->count += $goodsList[$key]['count'];
         }
     }
     /*Product 拼装商品优惠价的数据*/
     if (isset($buyInfo['product']['id']) && $buyInfo['product']['id']) {
         //购物车中的货品数据
         $productIdStr = join(',', $buyInfo['product']['id']);
         $productObj = new IQuery('products as pro,goods as go');
         $productObj->where = 'pro.id in (' . $productIdStr . ') and go.id = pro.goods_id';
         $productObj->fields = 'pro.sell_price,pro.weight,pro.id as product_id,pro.spec_array,pro.goods_id,pro.store_nums,pro.products_no as goods_no,go.name,go.point,go.exp,go.img';
         $productList = $productObj->find();
         //开始优惠情况判断
         foreach ($productList as $key => $val) {
             //检查库存
             if ($buyInfo['product']['data'][$val['product_id']]['count'] <= 0 || $buyInfo['product']['data'][$val['product_id']]['count'] > $val['store_nums']) {
                 return "货品:" . $val['name'] . "购买数量超出库存,请重新调整购买数量";
             }
             $groupPrice = $this->getGroupPrice($val['product_id'], 'product');
             $productList[$key]['reduce'] = $groupPrice === null ? 0 : $val['sell_price'] - $groupPrice;
             $productList[$key]['count'] = $buyInfo['product']['data'][$val['product_id']]['count'];
             $current_sum_all = $productList[$key]['sell_price'] * $productList[$key]['count'];
             $current_reduce_all = $productList[$key]['reduce'] * $productList[$key]['count'];
             $productList[$key]['sum'] = $current_sum_all - $current_reduce_all;
             //全局统计
             $this->weight += $val['weight'] * $productList[$key]['count'];
             $this->point += $val['point'] * $productList[$key]['count'];
             $this->exp += $val['exp'] * $productList[$key]['count'];
             $this->sum += $current_sum_all;
             $this->reduce += $current_reduce_all;
             $this->count += $productList[$key]['count'];
         }
     }
     $final_sum = $this->sum - $this->reduce;
     //总金额满足的促销规则
     if ($user_id) {
         $proObj = new ProRule($final_sum);
         $proObj->setUserGroup($group_id);
         $this->isFreeFreight = $proObj->isFreeFreight();
         $this->promotion = $proObj->getInfo();
         $this->proReduce = $final_sum - $proObj->getSum();
     } else {
         $this->promotion = array();
         $this->proReduce = 0;
     }
     $this->final_sum = $final_sum - $this->proReduce;
     return array('final_sum' => $this->final_sum, 'promotion' => $this->promotion, 'proReduce' => $this->proReduce, 'sum' => $this->sum, 'goodsList' => array_merge($goodsList, $productList), 'count' => $this->count, 'reduce' => $this->reduce, 'weight' => $this->weight, 'freeFreight' => $this->isFreeFreight, 'point' => $this->point, 'exp' => $this->exp);
 }
Ejemplo n.º 6
0
 function promotionRuleAjax()
 {
     $promotion = array();
     $proReduce = 0;
     //总金额满足的促销规则
     if ($this->user['user_id']) {
         $final_sum = intval(IReq::get('final_sum'));
         //获取 user_group
         $groupObj = new IModel('member as m,user_group as g');
         $groupRow = $groupObj->getObj('m.user_id = ' . $this->user['user_id'] . ' and m.group_id = g.id', 'g.*');
         $groupRow['id'] = empty($groupRow) ? 0 : $groupRow['id'];
         $proObj = new ProRule($final_sum);
         $proObj->setUserGroup($groupRow['id']);
         $promotion = $proObj->getInfo();
         $proReduce = $final_sum - $proObj->getSum();
     }
     $result = array('promotion' => $promotion, 'proReduce' => $proReduce);
     echo JSON::encode($result);
 }
Ejemplo n.º 7
0
 /**
  * 支付成功后修改订单状态
  * @param $orderNo  string 订单编号
  * @param $admin_id int    管理员ID
  * @param $note     string 收款的备注
  * @return false or int order_id
  */
 public static function updateOrderStatus($orderNo, $admin_id = '', $note = '')
 {
     //获取订单信息
     $orderObj = new IModel('order');
     $orderRow = $orderObj->getObj('order_no = "' . $orderNo . '"');
     if (empty($orderRow)) {
         return false;
     }
     if ($orderRow['pay_status'] == 1) {
         return $orderRow['id'];
     } else {
         if ($orderRow['pay_status'] == 0) {
             $dataArray = array('status' => 2, 'pay_time' => ITime::getDateTime(), 'pay_status' => 1);
             $orderObj->setData($dataArray);
             $is_success = $orderObj->update('order_no = "' . $orderNo . '"');
             if ($is_success == '') {
                 return false;
             }
             //删除订单中使用的道具
             $ticket_id = trim($orderRow['prop']);
             if ($ticket_id != '') {
                 $propObj = new IModel('prop');
                 $propData = array('is_userd' => 1);
                 $propObj->setData($propData);
                 $propObj->update('id = ' . $ticket_id);
             }
             if (intval($orderRow['user_id']) != 0) {
                 $user_id = $orderRow['user_id'];
                 //获取用户信息
                 $memberObj = new IModel('member');
                 $memberRow = $memberObj->getObj('user_id = ' . $user_id, 'prop,group_id');
                 //(1)删除订单中使用的道具
                 if ($ticket_id != '') {
                     $finnalTicket = str_replace(',' . $ticket_id . ',', ',', ',' . trim($memberRow['prop'], ',') . ',');
                     $memberData = array('prop' => $finnalTicket);
                     $memberObj->setData($memberData);
                     $memberObj->update('user_id = ' . $user_id);
                 }
                 if ($memberRow) {
                     //(2)进行促销活动奖励
                     $proObj = new ProRule($orderRow['real_amount']);
                     $proObj->setUserGroup($memberRow['group_id']);
                     $proObj->setAward($user_id);
                     //(3)增加经验值
                     $memberData = array('exp' => 'exp + ' . $orderRow['exp']);
                     $memberObj->setData($memberData);
                     $memberObj->update('user_id = ' . $user_id, 'exp');
                     //(4)增加积分
                     $pointConfig = array('user_id' => $user_id, 'point' => $orderRow['point'], 'log' => '成功购买了订单号:' . $orderRow['order_no'] . '中的商品,奖励积分' . $orderRow['point']);
                     $pointObj = new Point();
                     $pointObj->update($pointConfig);
                 }
             }
             //插入收款单
             $collectionDocObj = new IModel('collection_doc');
             $collectionData = array('order_id' => $orderRow['id'], 'user_id' => $orderRow['user_id'], 'amount' => $orderRow['order_amount'], 'time' => ITime::getDateTime(), 'payment_id' => $orderRow['pay_type'], 'pay_status' => 1, 'if_del' => 0, 'note' => $note, 'admin_id' => $admin_id ? $admin_id : 0);
             $collectionDocObj->setData($collectionData);
             $collectionDocObj->add();
             /*同步数据*/
             //同步团购的数据
             if ($orderRow['type'] == 1) {
                 $regimentUserObj = new IModel('regiment_user_relation');
                 $regimentUserObj->setData(array('is_over' => 1));
                 $regimentUserObj->update("order_no = '" . $orderRow['order_no'] . "'");
             }
             //更改购买商品的库存数量
             self::updateStore($orderRow['id'], 'reduce');
             return $orderRow['id'];
         } else {
             return false;
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * @brief 计算商品价格
  * @param Array $buyInfo ,购物车格式
  * @promo string 活动类型 团购,抢购
  * @active_id int 活动ID
  * @return array or bool
  */
 public function goodsCount($buyInfo, $promo = '', $active_id = '')
 {
     $this->sum = 0;
     //原始总额(优惠前)
     $this->final_sum = 0;
     //应付总额(优惠后)
     $this->weight = 0;
     //总重量
     $this->reduce = 0;
     //减少总额
     $this->count = 0;
     //总数量
     $this->promotion = array();
     //促销活动规则文本
     $this->proReduce = 0;
     //促销活动规则优惠额
     $this->point = 0;
     //增加积分
     $this->exp = 0;
     //增加经验
     $this->freeFreight = array();
     //商家免运费
     $this->tax = 0;
     //商品税金
     $this->seller = array();
     //商家商品总额统计, 商家ID => 商品金额
     $user_id = $this->user_id;
     $group_id = $this->group_id;
     $goodsList = array();
     $productList = array();
     //活动购买情况
     if ($promo && $active_id) {
         $ac_type = isset($buyInfo['goods']) ? "goods" : "product";
         $ac_id = current($buyInfo[$ac_type]['id']);
         $ac_buy_num = $buyInfo[$ac_type]['data'][$ac_id]['count'];
         //开启促销活动
         $activeObject = new Active($promo, $active_id, $user_id, $ac_id, $ac_type, $ac_buy_num);
         $activeResult = $activeObject->checkValid();
         if ($activeResult === true) {
             $typeRow = $activeObject->originalGoodsInfo;
             $disPrice = $activeObject->activePrice;
             //设置优惠价格,如果不存在则优惠价等于商品原价
             $typeRow['reduce'] = $typeRow['sell_price'] - $disPrice;
             $typeRow['count'] = $ac_buy_num;
             $current_sum_all = $typeRow['sell_price'] * $ac_buy_num;
             $current_reduce_all = $typeRow['reduce'] * $ac_buy_num;
             $typeRow['sum'] = $current_sum_all - $current_reduce_all;
             if (!isset($this->seller[$typeRow['seller_id']])) {
                 $this->seller[$typeRow['seller_id']] = 0;
             }
             $this->seller[$typeRow['seller_id']] += $typeRow['sum'];
             //全局统计
             $this->weight += $typeRow['weight'] * $ac_buy_num;
             $this->point += $typeRow['point'] * $ac_buy_num;
             $this->exp += $typeRow['exp'] * $ac_buy_num;
             $this->sum += $current_sum_all;
             $this->reduce += $current_reduce_all;
             $this->count += $ac_buy_num;
             $this->tax += self::getGoodsTax($typeRow['sum'], $typeRow['seller_id']);
             $typeRow == "goods" ? $goodsList[] = $typeRow : ($productList[] = $typeRow);
         } else {
             //报错信息
             return $activeResult;
         }
     } else {
         /*开始计算goods和product的优惠信息 , 会根据条件分析出执行以下哪一种情况:
          *(1)查看此商品(货品)是否已经根据不同会员组设定了优惠价格;
          *(2)当前用户是否属于某个用户组中的成员,并且此用户组享受折扣率;
          *(3)优惠价等于商品(货品)原价;
          */
         //获取商品或货品数据
         /*Goods 拼装商品优惠价的数据*/
         if (isset($buyInfo['goods']['id']) && $buyInfo['goods']['id']) {
             //购物车中的商品数据
             $goodsIdStr = join(',', $buyInfo['goods']['id']);
             $goodsObj = new IModel('goods as go');
             $goodsList = $goodsObj->query('go.id in (' . $goodsIdStr . ')', 'go.name,go.id as goods_id,go.img,go.sell_price,go.point,go.weight,go.store_nums,go.exp,go.goods_no,0 as product_id,go.seller_id');
             //开始优惠情况判断
             foreach ($goodsList as $key => $val) {
                 //检查库存
                 if ($buyInfo['goods']['data'][$val['goods_id']]['count'] <= 0 || $buyInfo['goods']['data'][$val['goods_id']]['count'] > $val['store_nums']) {
                     return "商品:" . $val['name'] . "购买数量超出库存,请重新调整购买数量";
                 }
                 $groupPrice = $this->getGroupPrice($val['goods_id'], 'goods');
                 $goodsList[$key]['reduce'] = $groupPrice === null ? 0 : $val['sell_price'] - $groupPrice;
                 $goodsList[$key]['count'] = $buyInfo['goods']['data'][$val['goods_id']]['count'];
                 $current_sum_all = $goodsList[$key]['sell_price'] * $goodsList[$key]['count'];
                 $current_reduce_all = $goodsList[$key]['reduce'] * $goodsList[$key]['count'];
                 $goodsList[$key]['sum'] = $current_sum_all - $current_reduce_all;
                 if (!isset($this->seller[$val['seller_id']])) {
                     $this->seller[$val['seller_id']] = 0;
                 }
                 $this->seller[$val['seller_id']] += $goodsList[$key]['sum'];
                 //全局统计
                 $this->weight += $val['weight'] * $goodsList[$key]['count'];
                 $this->point += $val['point'] * $goodsList[$key]['count'];
                 $this->exp += $val['exp'] * $goodsList[$key]['count'];
                 $this->sum += $current_sum_all;
                 $this->reduce += $current_reduce_all;
                 $this->count += $goodsList[$key]['count'];
                 $this->tax += self::getGoodsTax($goodsList[$key]['sum'], $val['seller_id']);
             }
         }
         /*Product 拼装商品优惠价的数据*/
         if (isset($buyInfo['product']['id']) && $buyInfo['product']['id']) {
             //购物车中的货品数据
             $productIdStr = join(',', $buyInfo['product']['id']);
             $productObj = new IQuery('products as pro,goods as go');
             $productObj->where = 'pro.id in (' . $productIdStr . ') and go.id = pro.goods_id';
             $productObj->fields = 'pro.sell_price,pro.weight,pro.id as product_id,pro.spec_array,pro.goods_id,pro.store_nums,pro.products_no as goods_no,go.name,go.point,go.exp,go.img,go.seller_id';
             $productList = $productObj->find();
             //开始优惠情况判断
             foreach ($productList as $key => $val) {
                 //检查库存
                 if ($buyInfo['product']['data'][$val['product_id']]['count'] <= 0 || $buyInfo['product']['data'][$val['product_id']]['count'] > $val['store_nums']) {
                     return "货品:" . $val['name'] . "购买数量超出库存,请重新调整购买数量";
                 }
                 $groupPrice = $this->getGroupPrice($val['product_id'], 'product');
                 $productList[$key]['reduce'] = $groupPrice === null ? 0 : $val['sell_price'] - $groupPrice;
                 $productList[$key]['count'] = $buyInfo['product']['data'][$val['product_id']]['count'];
                 $current_sum_all = $productList[$key]['sell_price'] * $productList[$key]['count'];
                 $current_reduce_all = $productList[$key]['reduce'] * $productList[$key]['count'];
                 $productList[$key]['sum'] = $current_sum_all - $current_reduce_all;
                 if (!isset($this->seller[$val['seller_id']])) {
                     $this->seller[$val['seller_id']] = 0;
                 }
                 $this->seller[$val['seller_id']] += $productList[$key]['sum'];
                 //全局统计
                 $this->weight += $val['weight'] * $productList[$key]['count'];
                 $this->point += $val['point'] * $productList[$key]['count'];
                 $this->exp += $val['exp'] * $productList[$key]['count'];
                 $this->sum += $current_sum_all;
                 $this->reduce += $current_reduce_all;
                 $this->count += $productList[$key]['count'];
                 $this->tax += self::getGoodsTax($productList[$key]['sum'], $val['seller_id']);
             }
         }
         //总金额满足的促销规则
         if ($user_id) {
             //计算每个商家促销规则
             foreach ($this->seller as $seller_id => $sum) {
                 $proObj = new ProRule($sum, $seller_id);
                 $proObj->setUserGroup($group_id);
                 if ($proObj->isFreeFreight() == true) {
                     $this->freeFreight[] = $seller_id;
                 }
                 $this->promotion = array_merge($proObj->getInfo(), $this->promotion);
                 $this->proReduce += $sum - $proObj->getSum();
             }
         }
     }
     $this->final_sum = $this->sum - $this->reduce - $this->proReduce;
     return array('final_sum' => $this->final_sum, 'promotion' => $this->promotion, 'proReduce' => $this->proReduce, 'sum' => $this->sum, 'goodsList' => array_merge($goodsList, $productList), 'count' => $this->count, 'reduce' => $this->reduce, 'weight' => $this->weight, 'point' => $this->point, 'exp' => $this->exp, 'tax' => $this->tax, 'freeFreight' => $this->freeFreight, 'seller' => $this->seller);
 }
Ejemplo n.º 9
0
 /**
  * @brief 获得订单的实际金额和商品的实际价格
  */
 public function getAmount()
 {
     //获得ajax中post传来的数据
     $uid = IFilter::act(IReq::get('uid'));
     $price = IFilter::act(IReq::get('price'));
     $gid = IFilter::act(IReq::get('gid'));
     $number = IFilter::act(IReq::get('number'));
     $pid = IFilter::act(IReq::get('pid'));
     //将price和gid转换为数组
     $price_arr = array();
     $gid_arr = array();
     $num_arr = array();
     $pid_arr = array();
     $price_arr = explode(',', $price);
     $gid_arr = explode(',', $gid);
     $num_arr = explode(',', $number);
     $pid_arr = explode(',', $pid);
     //获得order_class的对象
     $ord_class = new Order_Class();
     //实际价格
     $real_price = '';
     //执行折扣前的总金额
     $real_amount = 0;
     //循环获得商品的实际价格和实际总金额
     foreach ($price_arr as $key => $value) {
         $real = $ord_class->get_real_price($uid, $gid_arr[$key], $pid_arr[$key], $price_arr[$key]);
         $real_price .= $real . ',';
         $real_amount = $real_amount + $real * $num_arr[$key];
     }
     $real_price = substr($real_price, 0, -1);
     //获得group_id
     $tb_member = new IModel('member');
     $member_info = $tb_member->query('user_id=' . $uid);
     //获得规则函数的对象
     $rule = new ProRule($real_amount);
     $rule->setUserGroup($member_info[0]['group_id']);
     //获得规则折扣后的实际总金额
     $real_amount = $rule->getSum();
     //判断是否免运费,true免,false不免
     $isBolg = $rule->isFreeFreight();
     $relieve = '0';
     if ($isBolg) {
         $relieve = '1';
     }
     //返回页面数据实际商品价格和实际总金额
     echo $relieve . ';' . $real_price . ';' . $real_amount;
 }
Ejemplo n.º 10
0
 /**
  * 支付成功后修改订单状态
  * @param $orderNo  string 订单编号
  * @param $admin_id int    管理员ID
  * @param $note     string 收款的备注
  * @return false or int order_id
  */
 public static function updateOrderStatus($orderNo, $admin_id = '', $note = '')
 {
     //获取订单信息
     $orderObj = new IModel('order');
     $orderRow = $orderObj->getObj('order_no = "' . $orderNo . '"');
     if (empty($orderRow)) {
         return false;
     }
     if ($orderRow['pay_status'] == 1) {
         return $orderRow['id'];
     } else {
         if ($orderRow['pay_status'] == 0) {
             $dataArray = array('status' => $orderRow['status'] == 5 ? 5 : 2, 'pay_time' => ITime::getDateTime(), 'pay_status' => 1);
             $orderObj->setData($dataArray);
             $is_success = $orderObj->update('order_no = "' . $orderNo . '"');
             if ($is_success == '') {
                 return false;
             }
             //删除订单中使用的道具
             $ticket_id = trim($orderRow['prop']);
             if ($ticket_id != '') {
                 $propObj = new IModel('prop');
                 $propData = array('is_userd' => 1);
                 $propObj->setData($propData);
                 $propObj->update('id = ' . $ticket_id);
             }
             //注册用户进行奖励
             if ($orderRow['user_id']) {
                 $user_id = $orderRow['user_id'];
                 //获取用户信息
                 $memberObj = new IModel('member');
                 $memberRow = $memberObj->getObj('user_id = ' . $user_id, 'prop,group_id');
                 //(1)删除订单中使用的道具
                 if ($ticket_id != '') {
                     $finnalTicket = str_replace(',' . $ticket_id . ',', ',', ',' . trim($memberRow['prop'], ',') . ',');
                     $memberData = array('prop' => $finnalTicket);
                     $memberObj->setData($memberData);
                     $memberObj->update('user_id = ' . $user_id);
                 }
                 if ($memberRow) {
                     //(2)进行促销活动奖励
                     $proObj = new ProRule($orderRow['real_amount'], $orderRow['seller_id']);
                     $proObj->setUserGroup($memberRow['group_id']);
                     $proObj->setAward($user_id);
                     //(3)增加经验值
                     $memberData = array('exp' => 'exp + ' . $orderRow['exp']);
                     $memberObj->setData($memberData);
                     $memberObj->update('user_id = ' . $user_id, 'exp');
                     //(4)增加积分
                     $pointConfig = array('user_id' => $user_id, 'point' => $orderRow['point'], 'log' => '成功购买了订单号:' . $orderRow['order_no'] . '中的商品,奖励积分' . $orderRow['point']);
                     $pointObj = new Point();
                     $pointObj->update($pointConfig);
                 }
             }
             //插入收款单
             $collectionDocObj = new IModel('collection_doc');
             $collectionData = array('order_id' => $orderRow['id'], 'user_id' => $orderRow['user_id'], 'amount' => $orderRow['order_amount'], 'time' => ITime::getDateTime(), 'payment_id' => $orderRow['pay_type'], 'pay_status' => 1, 'if_del' => 0, 'note' => $note, 'admin_id' => $admin_id ? $admin_id : 0);
             $collectionDocObj->setData($collectionData);
             $collectionDocObj->add();
             //促销活动订单
             if ($orderRow['type'] != 0) {
                 Active::payCallback($orderNo, $orderRow['type']);
             }
             //非货到付款的支付方式
             if ($orderRow['pay_type'] != 0) {
                 //减少库存量
                 $orderGoodsDB = new IModel('order_goods');
                 $orderGoodsList = $orderGoodsDB->query('order_id = ' . $orderRow['id']);
                 $orderGoodsListId = array();
                 foreach ($orderGoodsList as $key => $val) {
                     $orderGoodsListId[] = $val['id'];
                 }
                 self::updateStore($orderGoodsListId, 'reduce');
             }
             //自提点短信发送
             self::sendTakeself($orderNo);
             $mobile = "";
             //订单付款后短信通知商家或者管理员进行订单处理
             if ($orderRow['seller_id'] > 0) {
                 $sellerObj = new IModel('seller');
                 $sellerRow = $sellerObj->getObj("id = " . $orderRow['seller_id']);
                 $mobile = $sellerRow['mobile'] ? $sellerRow['mobile'] : "";
             } else {
                 $config = new Config('site_config');
                 $mobile = $config->mobile ? $config->mobile : "";
             }
             $smsContent = smsTemplate::payFinishToAdmin(array('{orderNo}' => $orderNo));
             Hsms::send($mobile, $smsContent, 0);
             return $orderRow['id'];
         } else {
             return false;
         }
     }
 }
Ejemplo n.º 11
0
 /**
  * 支付成功后修改订单状态
  * @param $orderNo  string 订单编号
  * @param $admin_id int    管理员ID
  * @param $note     string 收款的备注
  * @return false or int order_id
  */
 public static function updateOrderStatus($orderNo, $admin_id = '', $note = '')
 {
     //获取订单信息
     $orderObj = new IModel('order');
     $orderRow = $orderObj->getObj('order_no = "' . $orderNo . '"');
     if (empty($orderRow)) {
         return false;
     }
     if ($orderRow['pay_status'] == 1) {
         return $orderRow['id'];
     } else {
         if ($orderRow['pay_status'] == 0) {
             $dataArray = array('status' => $orderRow['status'] == 5 ? 5 : 2, 'pay_time' => ITime::getDateTime(), 'pay_status' => 1);
             $orderObj->setData($dataArray);
             $is_success = $orderObj->update('order_no = "' . $orderNo . '"');
             if ($is_success == '') {
                 return false;
             }
             //删除订单中使用的道具
             $ticket_id = trim($orderRow['prop']);
             if ($ticket_id != '') {
                 $propObj = new IModel('prop');
                 $propData = array('is_userd' => 1);
                 $propObj->setData($propData);
                 $propObj->update('id = ' . $ticket_id);
             }
             if (intval($orderRow['user_id']) != 0) {
                 $user_id = $orderRow['user_id'];
                 //获取用户信息
                 $memberObj = new IModel('member');
                 $memberRow = $memberObj->getObj('user_id = ' . $user_id, 'prop,group_id');
                 //(1)删除订单中使用的道具
                 if ($ticket_id != '') {
                     $finnalTicket = str_replace(',' . $ticket_id . ',', ',', ',' . trim($memberRow['prop'], ',') . ',');
                     $memberData = array('prop' => $finnalTicket);
                     $memberObj->setData($memberData);
                     $memberObj->update('user_id = ' . $user_id);
                 }
                 if ($memberRow) {
                     //(2)进行促销活动奖励
                     $proObj = new ProRule($orderRow['real_amount']);
                     $proObj->setUserGroup($memberRow['group_id']);
                     $proObj->setAward($user_id);
                     //(3)增加经验值
                     $memberData = array('exp' => 'exp + ' . $orderRow['exp']);
                     $memberObj->setData($memberData);
                     $memberObj->update('user_id = ' . $user_id, 'exp');
                     //(4)增加积分
                     $pointConfig = array('user_id' => $user_id, 'point' => $orderRow['point'], 'log' => '成功购买了订单号:' . $orderRow['order_no'] . '中的商品,奖励积分' . $orderRow['point']);
                     $pointObj = new Point();
                     $pointObj->update($pointConfig);
                 }
             }
             //插入收款单
             $collectionDocObj = new IModel('collection_doc');
             $collectionData = array('order_id' => $orderRow['id'], 'user_id' => $orderRow['user_id'], 'amount' => $orderRow['order_amount'], 'time' => ITime::getDateTime(), 'payment_id' => $orderRow['pay_type'], 'pay_status' => 1, 'if_del' => 0, 'note' => $note, 'admin_id' => $admin_id ? $admin_id : 0);
             $collectionDocObj->setData($collectionData);
             $collectionDocObj->add();
             //促销活动订单
             if ($orderRow['type'] != 0) {
                 Active::payCallback($orderNo, $orderRow['type']);
             }
             //订单为商家商品减去商家预存款的1.2%
             if ($orderRow['seller_id'] > 0) {
                 $sellerObj = new IModel('seller');
                 $seller = $sellerObj->getObj("id = '{$orderRow['seller_id']}'");
                 if ($seller['balance'] > 0) {
                     //减去1.2%
                     $need = floatval($orderRow['order_amount'] * (1.2 * 0.01));
                     $new_balance = $seller['balance'] - $need;
                     $sellerObj->setData(array('balance' => $new_balance));
                     $sellerObj->update("id = '{$orderRow['seller_id']}'");
                     //记录扣除日志
                     $balanceObj = new IModel('seller_balance_log');
                     $data = array('seller_id' => $orderRow['seller_id'], 'deduct_balance' => $need, 'surplus_balance' => $new_balance, 'time' => ITime::getDateTime());
                     $balanceObj->setData($data);
                     $balanceObj->add();
                 }
             }
             //更改购买商品的库存数量
             self::updateStore($orderRow['id'], 'reduce');
             //自提点短信发送
             self::sendTakeself($orderNo);
             //订单付款后短信通知管理员进行订单处理
             $config = new Config('site_config');
             if (isset($config->mobile) && $config->mobile) {
                 $smsContent = smsTemplate::payFinishToAdmin(array('{orderNo}' => $orderNo));
                 Hsms::send($config->mobile, $smsContent);
             }
             return $orderRow['id'];
         } else {
             return false;
         }
     }
 }
Ejemplo n.º 12
0
 /**
  * @brief 计算商品价格
  * @param Array $buyInfo ,购物车格式
  * @return array or bool
  */
 private function goodsCount($buyInfo)
 {
     $this->weight = 0;
     //总重量
     $this->sum = 0;
     //原始总额
     $this->reduce = 0;
     //减少总额
     $this->count = 0;
     //总量
     $this->final_sum = 0;
     //应付总额
     $this->proReduce = 0;
     //促销活动优惠额
     $this->point = 0;
     //增加积分
     $this->exp = 0;
     //增加经验
     $this->isFreeFreight = false;
     //是否免运费
     $user_id = ISafe::get('user_id');
     $group_id = 0;
     $goodsList = array();
     $productList = array();
     //获取用户组ID及组的折扣率
     if ($user_id != null) {
         $groupObj = new IModel('member as m , user_group as g');
         $groupRow = $groupObj->getObj('m.user_id = ' . $user_id . ' and m.group_id = g.id', 'g.*');
         if (!empty($groupRow)) {
             $group_id = $groupRow['id'];
             $group_discount = $groupRow['discount'] / 100;
             $groupPriceObj = new IModel('group_price');
         }
     }
     /*开始计算goods和product的优惠信息 , 会根据条件分析出执行以下哪一种情况:
      *(1)查看此商品(货品)是否已经根据不同会员组设定了优惠价格;
      *(2)当前用户是否属于某个用户组中的成员,并且此用户组享受折扣率;
      *(3)优惠价等于商品(货品)原价;
      */
     //获取商品或货品数据
     /*Goods 拼装商品优惠价的数据*/
     if (isset($buyInfo['goods']['id']) && !empty($buyInfo['goods']['id'])) {
         //购物车中的商品数据
         $goodsIdStr = join(',', $buyInfo['goods']['id']);
         $goodsObj = new IModel('goods as go');
         $goodsList = $goodsObj->query('go.id in (' . $goodsIdStr . ')', 'go.name,go.id,go.list_img,go.sell_price,go.point,go.weight,go.store_nums,go.exp');
         if ($group_id) {
             //获取 "优惠情况(1)" 中的商品优惠价格
             $discountGoodsResult = array();
             $discountGoodsList = $groupPriceObj->query('products_id = 0 and goods_id in(' . $goodsIdStr . ') and group_id = ' . $group_id);
             foreach ($discountGoodsList as $val) {
                 $discountGoodsResult[$val['goods_id']] = $val;
             }
         }
         //开始优惠情况判断
         foreach ($goodsList as $key => $val) {
             //优惠情况(1)
             if (isset($discountGoodsResult[$val['id']]['price'])) {
                 $goodsList[$key]['reduce'] = $val['sell_price'] - $discountGoodsResult[$val['id']]['price'];
             } else {
                 if (isset($group_discount) && $group_discount != 0) {
                     $goodsList[$key]['reduce'] = $val['sell_price'] - $val['sell_price'] * $group_discount;
                 } else {
                     $goodsList[$key]['reduce'] = 0;
                 }
             }
             $goodsList[$key]['count'] = $buyInfo['goods']['data'][$val['id']]['count'];
             $current_sum_all = $goodsList[$key]['sell_price'] * $goodsList[$key]['count'];
             $current_reduce_all = $goodsList[$key]['reduce'] * $goodsList[$key]['count'];
             $goodsList[$key]['sum'] = $current_sum_all - $current_reduce_all;
             //全局统计
             $this->weight += $val['weight'] * $goodsList[$key]['count'];
             $this->point += $val['point'] * $goodsList[$key]['count'];
             $this->exp += $val['exp'] * $goodsList[$key]['count'];
             $this->sum += $current_sum_all;
             $this->reduce += $current_reduce_all;
             $this->count += $goodsList[$key]['count'];
         }
     }
     /*Product 拼装商品优惠价的数据*/
     if (isset($buyInfo['product']['id']) && !empty($buyInfo['product']['id'])) {
         //购物车中的货品数据
         $productIdStr = join(',', $buyInfo['product']['id']);
         $productObj = new IQuery('products as pro,goods as go');
         $productObj->where = 'pro.id in (' . $productIdStr . ') and go.id = pro.goods_id';
         $productObj->fields = 'pro.sell_price,pro.weight,pro.id,pro.spec_array,pro.goods_id,pro.store_nums,go.name,go.point,go.exp,go.list_img';
         $productList = $productObj->find();
         if ($group_id) {
             //获取 "优惠情况(1)" 中的商品优惠价格
             $discountProductResult = array();
             $discountProductList = $groupPriceObj->query('products_id in (' . $productIdStr . ') and group_id = ' . $group_id);
             foreach ($discountProductList as $val) {
                 $discountProductResult[$val['goods_id']] = $val;
             }
         }
         //开始优惠情况判断
         foreach ($productList as $key => $val) {
             //优惠情况(1)
             if (isset($discountProductResult[$val['id']]['price'])) {
                 $productList[$key]['reduce'] = $val['sell_price'] - $discountProductResult[$val['id']]['price'];
             } else {
                 if (isset($group_discount) && $group_discount != 0) {
                     $productList[$key]['reduce'] = $val['sell_price'] - $val['sell_price'] * $group_discount;
                 } else {
                     $productList[$key]['reduce'] = 0;
                 }
             }
             $productList[$key]['count'] = $buyInfo['product']['data'][$val['id']]['count'];
             $current_sum_all = $productList[$key]['sell_price'] * $productList[$key]['count'];
             $current_reduce_all = $productList[$key]['reduce'] * $productList[$key]['count'];
             $productList[$key]['sum'] = $current_sum_all - $current_reduce_all;
             //全局统计
             $this->weight += $val['weight'] * $productList[$key]['count'];
             $this->point += $val['point'] * $productList[$key]['count'];
             $this->exp += $val['exp'] * $productList[$key]['count'];
             $this->sum += $current_sum_all;
             $this->reduce += $current_reduce_all;
             $this->count += $productList[$key]['count'];
         }
     }
     $final_sum = $this->sum - $this->reduce;
     //总金额满足的促销规则
     if ($user_id) {
         $proObj = new ProRule($final_sum);
         $proObj->setUserGroup($group_id);
         $this->isFreeFreight = $proObj->isFreeFreight();
         $this->promotion = $proObj->getInfo();
         $this->proReduce = $final_sum - $proObj->getSum();
     } else {
         $this->promotion = array();
         $this->proReduce = 0;
     }
     $this->final_sum = $final_sum - $this->proReduce;
     return array('final_sum' => $this->final_sum, 'promotion' => $this->promotion, 'proReduce' => $this->proReduce, 'sum' => $this->sum, 'goodsList' => $goodsList, 'productList' => $productList, 'count' => $this->count, 'reduce' => $this->reduce, 'weight' => $this->weight, 'freeFreight' => $this->isFreeFreight, 'point' => $this->point, 'exp' => $this->exp);
 }