Inheritance: extends First
Example #1
0
 public function getBy($id, $field = null)
 {
     $result = parent::getBy($id, $field);
     if ($result) {
         return $this->toEntity($result);
     }
     return false;
 }
Example #2
0
 public function testAliasAndHelperFunctions()
 {
     $this->assertSame('active', \Active::getClassIf(true));
     $this->assertSame('active', active_class(true));
 }
Example #3
0
<?php

/*
 *  Copyright (c) Codiad & Kent Safranski (codiad.com), distributed
 *  as-is and without warranty under the MIT License. See
 *  [root]/license.txt for more. This information must remain intact.
 */
require_once '../../common.php';
require_once 'class.active.php';
$Active = new Active();
//////////////////////////////////////////////////////////////////
// Verify Session or Key
//////////////////////////////////////////////////////////////////
checkSession();
//////////////////////////////////////////////////////////////////
// Get user's active files
//////////////////////////////////////////////////////////////////
if ($_GET['action'] == 'list') {
    $Active->username = $_SESSION['user'];
    $Active->ListActive();
}
//////////////////////////////////////////////////////////////////
// Add active record
//////////////////////////////////////////////////////////////////
if ($_GET['action'] == 'add') {
    $Active->username = $_SESSION['user'];
    $Active->path = $_GET['path'];
    $Active->Add();
}
//////////////////////////////////////////////////////////////////
// Rename
Example #4
0
 public function direct_count($id, $type, $buy_num = 1, $promo = '', $active_id = '')
 {
     /*开启促销活动*/
     if ($promo && $active_id) {
         //开启促销活动
         $activeObject = new Active($promo, $active_id, $this->user_id, $id, $type, $buy_num);
         $activeResult = $activeObject->checkValid();
         if ($activeResult === true) {
             $typeRow = $activeObject->originalGoodsInfo;
             $disPrice = $activeObject->activePrice;
             //设置优惠价格,如果不存在则优惠价等于商品原价
             $typeRow['reduce'] = $typeRow['sell_price'] - $disPrice;
             $typeRow['count'] = $buy_num;
             $typeRow['sum'] = $disPrice * $buy_num;
             //拼接返回数据
             $result = array('final_sum' => $typeRow['sum'], 'promotion' => array(), 'proReduce' => 0, 'sum' => $typeRow['sell_price'] * $buy_num, 'goodsList' => array($typeRow), 'count' => $buy_num, 'reduce' => $typeRow['reduce'] * $buy_num, 'weight' => $typeRow['weight'] * $buy_num, 'point' => $typeRow['point'] * $buy_num, 'exp' => $typeRow['exp'] * $buy_num, 'freeFreight' => false);
             return $result;
         } else {
             //报错信息
             return $activeResult;
         }
     } else {
         $buyInfo = array($type => array('id' => array($id), 'data' => array($id => array('count' => $buy_num)), 'count' => $buy_num));
         return $this->goodsCount($buyInfo);
     }
 }
Example #5
0
 /**
  * Добавляет составляющий актив в состав текущего актива.
  *
  * @param Active $active
  * @return $this
  */
 protected function addSubActive(Active $active)
 {
     $this->subActives[$active->getId()] = $active;
     return $this;
 }
Example #6
0
 /**
  * 生成订单
  */
 function cart3()
 {
     $accept_name = IFilter::act(IReq::get('accept_name'));
     $province = IFilter::act(IReq::get('province'), 'int');
     $city = IFilter::act(IReq::get('city'), 'int');
     $area = IFilter::act(IReq::get('area'), 'int');
     $address = IFilter::act(IReq::get('address'));
     $mobile = IFilter::act(IReq::get('mobile'));
     $telphone = IFilter::act(IReq::get('telphone'));
     $zip = IFilter::act(IReq::get('zip'));
     $delivery_id = IFilter::act(IReq::get('delivery_id'), 'int');
     $accept_time = IFilter::act(IReq::get('accept_time'));
     $payment = IFilter::act(IReq::get('payment'), 'int');
     $order_message = IFilter::act(IReq::get('message'));
     $ticket_id = IFilter::act(IReq::get('ticket_id'), 'int');
     $taxes = IFilter::act(IReq::get('taxes'), 'float');
     $insured = IFilter::act(IReq::get('insured'), 'float');
     $tax_title = IFilter::act(IReq::get('tax_title'), 'text');
     $gid = IFilter::act(IReq::get('direct_gid'), 'int');
     $num = IFilter::act(IReq::get('direct_num'), 'int');
     $type = IFilter::act(IReq::get('direct_type'));
     //商品或者货品
     $promo = IFilter::act(IReq::get('direct_promo'));
     $active_id = IFilter::act(IReq::get('direct_active_id'), 'int');
     $takeself = IFilter::act(IReq::get('takeself'), 'int');
     $order_no = Order_Class::createOrderNum();
     $order_type = 0;
     $dataArray = array();
     //pr($_POST);
     //防止表单重复提交
     if (IReq::get('timeKey') != null) {
         if (ISafe::get('timeKey') == IReq::get('timeKey')) {
             IError::show(403, '订单数据不能被重复提交');
             exit;
         } else {
             ISafe::set('timeKey', IReq::get('timeKey'));
         }
     }
     if ($province == 0 || $city == 0 || $area == 0) {
         IError::show(403, '请填写收货地址的省市地区');
     }
     if ($delivery_id == 0) {
         IError::show(403, '请选择配送方式');
     }
     $user_id = $this->user['user_id'] == null ? 0 : $this->user['user_id'];
     //配送方式,判断是否为货到付款
     $deliveryObj = new IModel('delivery');
     $deliveryRow = $deliveryObj->getObj('id = ' . $delivery_id);
     if ($deliveryRow['type'] == 0) {
         if ($payment == 0) {
             IError::show(403, '请选择正确的支付方式');
         }
     } else {
         if ($deliveryRow['type'] == 1) {
             $payment = 0;
         } else {
             if ($deliveryRow['type'] == 2) {
                 if ($takeself == 0) {
                     IError::show(403, '请选择正确的自提点');
                 }
             }
         }
     }
     //如果不是自提方式自动清空自提点
     if ($deliveryRow['type'] != 2) {
         $takeself = 0;
     }
     //计算费用
     $countSumObj = new CountSum($user_id);
     //直接购买商品方式
     if ($type && $gid) {
         //计算$gid商品
         $goodsResult = $countSumObj->direct_count($gid, $type, $num, $promo, $active_id);
     } else {
         //计算购物车中的商品价格$goodsResult
         $goodsResult = $countSumObj->cart_count();
         //清空购物车
         IInterceptor::reg("cart@onFinishAction");
     }
     //判断商品商品是否存在
     if (is_string($goodsResult) || empty($goodsResult['goodsList'])) {
         IError::show(403, '商品数据错误');
         exit;
     }
     //需要选择的地址数
     $need_choose_addr_num = 1;
     if (count($goodsResult['goodsList']) == 1 && $goodsResult['count'] > 1) {
         $need_choose_addr_num = $goodsResult['count'];
     }
     //匹配收获地址
     $address_arr = IFilter::act(IReq::get('radio_address'), 'int');
     if (count($address_arr) != $need_choose_addr_num) {
         IError::show(403, '请选择' . $need_choose_addr_num . '个收货地址');
         exit;
     }
     //加入促销活动
     if ($promo && $active_id) {
         $activeObject = new Active($promo, $active_id, $user_id, $gid, $type, $num);
         $order_type = $activeObject->getOrderType();
     }
     //获取红包减免金额
     if ($ticket_id != '') {
         $memberObj = new IModel('member');
         $memberRow = $memberObj->getObj('user_id = ' . $user_id, 'prop,custom');
         if (ISafe::get('ticket_' . $ticket_id) == $ticket_id || stripos(',' . trim($memberRow['prop'], ',') . ',', ',' . $ticket_id . ',') !== false) {
             $propObj = new IModel('prop');
             $ticketRow = $propObj->getObj('id = ' . $ticket_id . ' and NOW() between start_time and end_time and type = 0 and is_close = 0 and is_userd = 0 and is_send = 1');
             if (!empty($ticketRow)) {
                 $dataArray['prop'] = $ticket_id;
             }
             //锁定红包状态
             $propObj->setData(array('is_close' => 2));
             $propObj->update('id = ' . $ticket_id);
         }
     }
     $paymentObj = new IModel('payment');
     $paymentRow = $paymentObj->getObj('id = ' . $payment, 'type,name');
     $paymentName = $paymentRow['name'];
     $paymentType = $paymentRow['type'];
     //记录seller_id
     $seller_id = 0;
     if ($gid) {
         $goodsObj = new IModel("goods");
         $sell = $goodsObj->getObj("id = " . $gid, 'seller_id');
         if ($sell['seller_id'] > 0) {
             $seller_id = $sell['seller_id'];
         }
     }
     //最终订单金额计算
     $orderData = $countSumObj->countOrderFee($goodsResult['sum'], $goodsResult['final_sum'], $goodsResult['weight'], $province, $delivery_id, $payment, $goodsResult['freeFreight'], $insured, $taxes);
     //生成的订单数据
     $dataArray = array('order_no' => $order_no, 'user_id' => $user_id, 'accept_name' => $accept_name, 'pay_type' => $payment, 'distribution' => $delivery_id, 'postcode' => $zip, 'telphone' => $telphone, 'province' => $province, 'city' => $city, 'area' => $area, 'address' => $address, 'mobile' => $mobile, 'create_time' => ITime::getDateTime(), 'postscript' => $order_message, 'accept_time' => $accept_time, 'exp' => $goodsResult['exp'], 'point' => $goodsResult['point'], 'type' => $order_type, 'prop' => isset($dataArray['prop']) ? $dataArray['prop'] : null, 'payable_amount' => $goodsResult['sum'], 'real_amount' => $goodsResult['final_sum'], 'payable_freight' => $orderData['deliveryOrigPrice'], 'real_freight' => $orderData['deliveryPrice'], 'pay_fee' => $orderData['paymentPrice'], 'invoice' => $taxes ? 1 : 0, 'invoice_title' => $tax_title, 'taxes' => $taxes, 'promotions' => $goodsResult['proReduce'] + $goodsResult['reduce'] + (isset($ticketRow['value']) ? $ticketRow['value'] : 0), 'order_amount' => $orderData['orderAmountPrice'] - (isset($ticketRow['value']) ? $ticketRow['value'] : 0), 'if_insured' => $insured ? 1 : 0, 'insured' => $insured, 'takeself' => $takeself, 'active_id' => $active_id, 'seller_id' => $seller_id, 'address_id' => implode(',', $address_arr));
     $dataArray['order_amount'] = $dataArray['order_amount'] <= 0 ? 0 : $dataArray['order_amount'];
     if ($seller_id) {
         $sellerObj = new IModel('seller');
         $seller = $sellerObj->getObj("id = '{$seller_id}'");
         if ($seller) {
             //商家的预存款不足以扣除订单总价的1.2%
             $nedd = floatval($dataArray['order_amount'] * (1.2 * 0.01));
             if ($seller['balance'] <= 0 || $seller['balance'] < $nedd) {
                 IError::show(403, '商家预存款不足,不能进行购买');
                 exit;
             }
         }
     }
     $orderObj = new IModel('order');
     $orderObj->setData($dataArray);
     $this->order_id = $orderObj->add();
     if ($this->order_id == false) {
         IError::show(403, '订单生成错误');
     }
     /*将订单中的商品插入到order_goods表*/
     $orderInstance = new Order_Class();
     $orderInstance->insertOrderGoods($this->order_id, $goodsResult);
     //记录用户默认习惯的数据
     if (!isset($memberRow['custom'])) {
         $memberObj = new IModel('member');
         $memberRow = $memberObj->getObj('user_id = ' . $user_id, 'custom');
     }
     $memberData = array('custom' => serialize(array('payment' => $payment, 'delivery' => $delivery_id, 'takeself' => $takeself)));
     $memberObj->setData($memberData);
     $memberObj->update('user_id = ' . $user_id);
     //收货地址的处理
     /* if($user_id)
     		{
     			$addressObj = new IModel('address');
     
     			//如果用户之前没有收货地址,那么会自动记录此次的地址信息并且为默认
     			$addressRow = $addressObj->getObj('user_id = '.$user_id);
     			if(empty($addressRow))
     			{
     				$addressData = array('default'=>'1','user_id'=>$user_id,'accept_name'=>$accept_name,'province'=>$province,'city'=>$city,'area'=>$area,'address'=>$address,'zip'=>$zip,'telphone'=>$telphone,'mobile'=>$mobile);
     				$addressObj->setData($addressData);
     				$addressObj->add();
     			}
     			else
     			{
     				//如果用户有收货地址,但是没有设置默认项,那么会自动设置此次地址信息为默认
     				$radio_address = intval(IReq::get('radio_address'));
     				if($radio_address != 0)
     				{
     					$addressDefRow = $addressObj->getObj('user_id = '.$user_id.' and `default` = 1');
     					if(empty($addressDefRow))
     					{
     						$addressData = array('default' => 1);
     						$addressObj->setData($addressData);
     						$addressObj->update('user_id = '.$user_id.' and id = '.$radio_address);
     					}
     				}
     			}
     		} */
     //获取备货时间
     $siteConfigObj = new Config("site_config");
     $site_config = $siteConfigObj->getInfo();
     $this->stockup_time = isset($site_config['stockup_time']) ? $site_config['stockup_time'] : 2;
     //数据渲染
     $this->order_num = $dataArray['order_no'];
     $this->final_sum = $dataArray['order_amount'];
     $this->payment = $paymentName;
     $this->paymentType = $paymentType;
     $this->delivery = $deliveryRow['name'];
     $this->tax_title = $tax_title;
     $this->deliveryType = $deliveryRow['type'];
     //订单金额为0时,订单自动完成
     if ($this->final_sum <= 0) {
         $order_id = Order_Class::updateOrderStatus($dataArray['order_no']);
         if ($order_id) {
             if ($user_id) {
                 $this->redirect('/site/success/message/' . urlencode("订单确认成功,等待发货") . '/?callback=ucenter/order_detail/id/' . $order_id);
             } else {
                 $this->redirect('/site/success/message/' . urlencode("订单确认成功,等待发货"));
             }
         } else {
             IError::show(403, '订单修改失败');
         }
     } else {
         $this->setRenderData($dataArray);
         $this->redirect('cart3');
     }
 }
Example #7
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);
 }
Example #8
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;
         }
     }
 }
Example #9
0
<?php

/*
 *  Copyright (c) Codiad & Kent Safranski (codiad.com), distributed
 *  as-is and without warranty under the MIT License. See 
 *  [root]/license.txt for more. This information must remain intact.
 */
require_once '../../config.php';
require_once 'class.active.php';
$Active = new Active();
//////////////////////////////////////////////////////////////////
// Verify Session or Key
//////////////////////////////////////////////////////////////////
checkSession();
//////////////////////////////////////////////////////////////////
// Get user's active files
//////////////////////////////////////////////////////////////////
if ($_GET['action'] == 'list') {
    $Active->username = $_SESSION['user'];
    $Active->ListActive();
}
//////////////////////////////////////////////////////////////////
// Add active record
//////////////////////////////////////////////////////////////////
if ($_GET['action'] == 'add') {
    $Active->username = $_SESSION['user'];
    $Active->path = $_GET['path'];
    $Active->Add();
}
//////////////////////////////////////////////////////////////////
// Rename
Example #10
0
 /**
  * 生成订单
  */
 function cart3()
 {
     $accept_name = IFilter::act(IReq::get('accept_name'));
     $province = IFilter::act(IReq::get('province'), 'int');
     $city = IFilter::act(IReq::get('city'), 'int');
     $area = IFilter::act(IReq::get('area'), 'int');
     $address = IFilter::act(IReq::get('address'));
     $mobile = IFilter::act(IReq::get('mobile'));
     $telphone = IFilter::act(IReq::get('telphone'));
     $zip = IFilter::act(IReq::get('zip'));
     $delivery_id = IFilter::act(IReq::get('delivery_id'), 'int');
     $accept_time = IFilter::act(IReq::get('accept_time'));
     $payment = IFilter::act(IReq::get('payment'), 'int');
     $order_message = IFilter::act(IReq::get('message'));
     $ticket_id = IFilter::act(IReq::get('ticket_id'), 'int');
     $taxes = IFilter::act(IReq::get('taxes'), 'int');
     $tax_title = IFilter::act(IReq::get('tax_title'));
     $gid = IFilter::act(IReq::get('direct_gid'), 'int');
     $num = IFilter::act(IReq::get('direct_num'), 'int');
     $type = IFilter::act(IReq::get('direct_type'));
     //商品或者货品
     $promo = IFilter::act(IReq::get('direct_promo'));
     $active_id = IFilter::act(IReq::get('direct_active_id'), 'int');
     $takeself = IFilter::act(IReq::get('takeself'), 'int');
     $ticketUserd = IFilter::act(IReq::get('ticketUserd'), 'int');
     $order_type = 0;
     $dataArray = array();
     //防止表单重复提交
     if (IReq::get('timeKey') != null) {
         if (ISafe::get('timeKey') == IReq::get('timeKey')) {
             IError::show(403, '订单数据不能被重复提交');
             exit;
         } else {
             ISafe::set('timeKey', IReq::get('timeKey'));
         }
     }
     if ($province == 0 || $city == 0 || $area == 0) {
         IError::show(403, '请填写收货地址的省市地区');
     }
     if ($delivery_id == 0) {
         IError::show(403, '请选择配送方式');
     }
     $user_id = $this->user['user_id'] == null ? 0 : $this->user['user_id'];
     //配送方式,判断是否为货到付款
     $deliveryObj = new IModel('delivery');
     $deliveryRow = $deliveryObj->getObj('id = ' . $delivery_id);
     if ($deliveryRow['type'] == 0) {
         if ($payment == 0) {
             IError::show(403, '请选择正确的支付方式');
         }
     } else {
         if ($deliveryRow['type'] == 1) {
             $payment = 0;
         } else {
             if ($deliveryRow['type'] == 2) {
                 if ($takeself == 0) {
                     IError::show(403, '请选择正确的自提点');
                 }
             }
         }
     }
     //如果不是自提方式自动清空自提点
     if ($deliveryRow['type'] != 2) {
         $takeself = 0;
     }
     //计算费用
     $countSumObj = new CountSum($user_id);
     $goodsResult = $countSumObj->cart_count($gid, $type, $num, $promo, $active_id);
     if (!$gid) {
         //清空购物车
         IInterceptor::reg("cart@onFinishAction");
     }
     //判断商品商品是否存在
     if (is_string($goodsResult) || empty($goodsResult['goodsList'])) {
         IError::show(403, '商品数据错误');
         exit;
     }
     //加入促销活动
     if ($promo && $active_id) {
         $activeObject = new Active($promo, $active_id, $user_id, $gid, $type, $num);
         $order_type = $activeObject->getOrderType();
     }
     $paymentObj = new IModel('payment');
     $paymentRow = $paymentObj->getObj('id = ' . $payment, 'type,name');
     $paymentName = $paymentRow['name'];
     $paymentType = $paymentRow['type'];
     //最终订单金额计算
     $orderData = $countSumObj->countOrderFee($goodsResult, $province, $delivery_id, $payment, $taxes, 0, $promo, $active_id);
     if (is_string($orderData)) {
         IError::show(403, $orderData);
         exit;
     }
     //根据商品所属商家不同批量生成订单
     $orderIdArray = array();
     $orderNumArray = array();
     $final_sum = 0;
     foreach ($orderData as $seller_id => $goodsResult) {
         //生成的订单数据
         $dataArray = array('order_no' => Order_Class::createOrderNum(), 'user_id' => $user_id, 'accept_name' => $accept_name, 'pay_type' => $payment, 'distribution' => $delivery_id, 'postcode' => $zip, 'telphone' => $telphone, 'province' => $province, 'city' => $city, 'area' => $area, 'address' => $address, 'mobile' => $mobile, 'create_time' => ITime::getDateTime(), 'postscript' => $order_message, 'accept_time' => $accept_time, 'exp' => $goodsResult['exp'], 'point' => $goodsResult['point'], 'type' => $order_type, 'payable_amount' => $goodsResult['sum'], 'real_amount' => $goodsResult['final_sum'], 'payable_freight' => $goodsResult['deliveryOrigPrice'], 'real_freight' => $goodsResult['deliveryPrice'], 'pay_fee' => $goodsResult['paymentPrice'], 'invoice' => $taxes ? 1 : 0, 'invoice_title' => $tax_title, 'taxes' => $goodsResult['taxPrice'], 'promotions' => $goodsResult['proReduce'] + $goodsResult['reduce'], 'order_amount' => $goodsResult['orderAmountPrice'], 'insured' => $goodsResult['insuredPrice'], 'takeself' => $takeself, 'active_id' => $active_id, 'seller_id' => $seller_id, 'note' => '');
         //获取红包减免金额
         if ($ticket_id && $ticketUserd == $seller_id) {
             $memberObj = new IModel('member');
             $memberRow = $memberObj->getObj('user_id = ' . $user_id, 'prop,custom');
             //游客手动添加或注册用户道具中已有的代金券
             if (ISafe::get('ticket_' . $ticket_id) == $ticket_id || stripos(',' . trim($memberRow['prop'], ',') . ',', ',' . $ticket_id . ',') !== false) {
                 $propObj = new IModel('prop');
                 $ticketRow = $propObj->getObj('id = ' . $ticket_id . ' and NOW() between start_time and end_time and type = 0 and is_close = 0 and is_userd = 0 and is_send = 1');
                 if (!$ticketRow) {
                     IError::show(403, '代金券不可用');
                 }
                 if ($ticketRow['seller_id'] == 0 || $ticketRow['seller_id'] == $seller_id) {
                     $ticketRow['value'] = $ticketRow['value'] >= $goodsResult['final_sum'] ? $goodsResult['final_sum'] : $ticketRow['value'];
                     $dataArray['prop'] = $ticket_id;
                     $dataArray['promotions'] += $ticketRow['value'];
                     $dataArray['order_amount'] -= $ticketRow['value'];
                     $goodsResult['promotion'][] = array("plan" => "代金券", "info" => "使用了¥" . $ticketRow['value'] . "代金券");
                     //锁定红包状态
                     $propObj->setData(array('is_close' => 2));
                     $propObj->update('id = ' . $ticket_id);
                 }
             }
         }
         //促销规则
         if (isset($goodsResult['promotion']) && $goodsResult['promotion']) {
             foreach ($goodsResult['promotion'] as $key => $val) {
                 $dataArray['note'] .= " 【" . $val['info'] . "】 ";
             }
         }
         $dataArray['order_amount'] = $dataArray['order_amount'] <= 0 ? 0 : $dataArray['order_amount'];
         //生成订单插入order表中
         $orderObj = new IModel('order');
         $orderObj->setData($dataArray);
         $order_id = $orderObj->add();
         if ($order_id == false) {
             IError::show(403, '订单生成错误');
         }
         /*将订单中的商品插入到order_goods表*/
         $orderInstance = new Order_Class();
         $orderInstance->insertOrderGoods($order_id, $goodsResult['goodsResult']);
         //订单金额小于等于0直接免单
         if ($dataArray['order_amount'] <= 0) {
             Order_Class::updateOrderStatus($dataArray['order_no']);
         } else {
             $orderIdArray[] = $order_id;
             $orderNumArray[] = $dataArray['order_no'];
             $final_sum += $dataArray['order_amount'];
         }
     }
     //记录用户默认习惯的数据
     if (!isset($memberRow['custom'])) {
         $memberObj = new IModel('member');
         $memberRow = $memberObj->getObj('user_id = ' . $user_id, 'custom');
     }
     $memberData = array('custom' => serialize(array('payment' => $payment, 'delivery' => $delivery_id, 'takeself' => $takeself)));
     $memberObj->setData($memberData);
     $memberObj->update('user_id = ' . $user_id);
     //收货地址的处理
     if ($user_id) {
         $addressObj = new IModel('address');
         $addressDefRow = $addressObj->getObj('user_id = ' . $user_id . ' and `default` = 1');
         if (!$addressDefRow) {
             $radio_address = IFilter::act(IReq::get('radio_address'), 'int');
             $addressObj->setData(array('default' => 1));
             $addressObj->update('user_id = ' . $user_id . ' and id = ' . $radio_address);
         }
     }
     //获取备货时间
     $siteConfigObj = new Config("site_config");
     $site_config = $siteConfigObj->getInfo();
     $this->stockup_time = isset($site_config['stockup_time']) ? $site_config['stockup_time'] : 2;
     //数据渲染
     $this->order_id = join(",", $orderIdArray);
     $this->final_sum = $final_sum;
     $this->order_num = join(",", $orderNumArray);
     $this->payment = $paymentName;
     $this->paymentType = $paymentType;
     $this->delivery = $deliveryRow['name'];
     $this->tax_title = $tax_title;
     $this->deliveryType = $deliveryRow['type'];
     //订单金额为0时,订单自动完成
     if ($this->final_sum <= 0) {
         $this->redirect('/site/success/message/' . urlencode("订单确认成功,等待发货") . '/?callback=ucenter/order');
     } else {
         $this->setRenderData($dataArray);
         $this->redirect('cart3');
     }
 }
Example #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;
         }
     }
 }
Example #12
0
 public function doEvent()
 {
     $event = $this->postObj->Event;
     $this->msgType = "text";
     if ($event == "subscribe") {
         $eventKey = $this->postObj->EventKey;
         //                        if (strpos($eventKey, "qrscene_") !== false) {//未关注用户通过扫描带参数二维码进入
         //                                $eventKey = substr($eventKey,8);
         //                                if(trim($eventKey) === "1"){
         //                                     $ob = new Active();
         //                                     $ob -> doQrcode1($this->fromUsername,"1");
         //                                     exit;
         //                                }
         //                        } else {
         $this->contentStr = "\t人人猎 是中国最有效的优质互联网创业企业人才极速直招平台。她让企业在 7 天内搞定招聘需求、招到靠谱的人;既让猎头、HR、知名公司的面试官等推荐人暂不使用的简历得以轻松变现,又让中高端候选人快速找到匹配的工作。\n";
         $this->contentStr .= "\t人人猎 核心团队由来自百度、搜狐等知名互联网公司的互联网资深人士,及有10多年猎头从业经验的人才招聘行业专家组成。\n";
         $this->contentStr .= "\t人人猎 成立之初,相继获得知名投资人的种子资金和天使轮投资。人人猎以“简单、诚实、可靠”为企业理念,以“避免互联网创业企业长久招不到靠谱的人而受损失,帮助候选人加入最匹配的团队,让猎头和HR等推荐人的每个面试都有现金回报”为宗旨,以追求“极佳效果和服务”为始终如一的目标。\n";
         $this->contentStr .= "\t参与线下活动注册:http://m.renrenlie.com/index.php?s=Active/reg";
         //                        }
     } else {
         if ($event == "SCAN") {
             //已关注用户通过扫描带参数二维码进入
             $eventKey = $this->postObj->EventKey;
             if (!empty($eventKey)) {
                 if (trim($eventKey) === "1") {
                     $ob = new Active();
                     $ob->doQrcode1($this->fromUsername, "2");
                     exit;
                 }
             } else {
                 exit;
             }
         } else {
             if ($event == "CLICK") {
                 $eventKey = $this->postObj->EventKey;
                 if ($eventKey == "ABOUT") {
                     $this->contentStr = "\t人人猎 是中国最有效的优质互联网创业企业人才极速直招平台。她让企业在 7 天内搞定招聘需求、招到靠谱的人;既让猎头、HR、知名公司的面试官等推荐人暂不使用的简历得以轻松变现,又让中高端候选人快速找到匹配的工作。\n";
                     $this->contentStr .= "\t人人猎 核心团队由来自百度、搜狐等知名互联网公司的互联网资深人士,及有10多年猎头从业经验的人才招聘行业专家组成。\n";
                     $this->contentStr .= "\t人人猎 成立之初,相继获得知名投资人的种子资金和天使轮投资。人人猎以“简单、诚实、可靠”为企业理念,以“避免互联网创业企业长久招不到靠谱的人而受损失,帮助候选人加入最匹配的团队,让猎头和HR等推荐人的每个面试都有现金回报”为宗旨,以追求“极佳效果和服务”为始终如一的目标。";
                 }
             } else {
                 exit;
             }
         }
     }
     $resultStr = sprintf($this->textTpl, $this->fromUsername, $this->toUsername, $this->time, $this->msgType, $this->contentStr);
     echo $resultStr;
     exit;
 }