Ejemplo n.º 1
0
/**
 *  支付完成后
 *  $order 订单信息
 */
function after_pay($order){
	$configs = getCache('Config:list');
	$od_model = M('Order_detail');
	$mw_model = M('Member_wallet');
	$od_data['order_id'] = $order['id'];
	$list = $od_model->table('`'.C('DB_PREFIX').'order_detail` as a')->join('`'.C('DB_PREFIX').'product` as b on a.product_id=b.id')->field('a.id,a.product_id,a.item_id,a.num,a.share_id,b.integral')->where($od_data)->select();
	//修改订单详情状态
	$od_sdata['status'] = 1;
	$od_model->where($od_data)->save($od_sdata);
	$result = true;
	//修改库存
	if($configs['site_inventorysetup']==2){
	  //产品减库存
	  $result = stock_update($list);
	}
	//积分处理
	$integral = 0;
	foreach($list as $item){
	  $integral += $item['integral'];
	}
	$mw_data['member_id'] = $order['member_id'];
	if($integral>0){
	  $result = $mw_model->where($mw_data)->setInc('score',$integral);
	  $member['id'] = $order['member_id'];
	  $member['member_name'] = $order['member_name'];
	  score_log($member,'order',$order['id'],$integral,'订单完成支付');
	}
	return $result;
}
Ejemplo n.º 2
0
 public function create()
 {
     $time = time();
     if (!$_REQUEST['cart_ids'] && (!$_REQUEST['item_id'] || !$_REQUEST['num']) && (!$_REQUEST['product_id'] || !$_REQUEST['num'])) {
         ajaxErrReturn('商品不存在!');
     }
     if (!$_REQUEST['consignee_id']) {
         ajaxErrReturn('收件人地址必须');
     }
     $logs_model = M('Logs');
     $pl_model = M('PmList');
     //收件人信息
     $admodel = M('MemberAddress');
     $ad_data['id'] = $_REQUEST['consignee_id'];
     $ad_data['member_id'] = $this->user['id'];
     $address = $admodel->where($ad_data)->find();
     if (!$address) {
         ajaxErrReturn('收件人地址必须');
     }
     $list = $this->products();
     $total_fee = 0;
     //组装,以商家为单位
     foreach ($list['data'] as $key => $val) {
         $seller_id = $val['seller_id'];
         $id = $val['id'];
         //$k = array_search($id,$_POST['ids']);
         if ($val['stock'] < 1) {
             ajaxErrReturn($val['name'] . '已无库存');
         }
         $num = $val['num'] > $val['stock'] ? $val['stock'] : $val['num'];
         //超过库存
         $list2[$seller_id]['seller_name'] = $val['seller_name'];
         $list2[$seller_id]['seller_realname'] = $val['seller_realname'];
         $list2[$seller_id]['num'] = $num;
         $list2[$seller_id]['total_num'] += $num;
         $val['amount'] = $num * $val['price'];
         //$list2[$member_id]['amount'] = $num*$val['price'];
         $val['module'] = $val['item_id'] ? 'Product_item' : 'Product';
         $val['num'] = $num;
         $list2[$seller_id]['list'][] = $val;
         $list2[$seller_id]['total_fee'] += $val['amount'];
         $total_fee += $num * $val['price'];
         //购买记录
         /*
         $logs_data['msg'] = '<span>'.name_hide($this->user['username']).'</span>下单购买作品'.$val['product_name'];
         $logs_data['create_time'] = $time;
         $logs_model->add($logs_data);
         */
     }
     //优惠券
     if ($_POST['coupon_user_id']) {
         $mc_model = M('MemberCoupon');
         $data['a.id'] = array('in', explode(',', $_POST['coupon_user_id']));
         //$data['a.id'] = $_POST['coupon_user_id'];
         $coupons = $mc_model->alias('a')->join('`' . C('DB_PREFIX') . 'coupon` as b on a.coupon_id=b.id')->field('a.id,a.member_id,a.coupon_id,a.deadline,a.status,b.title,b.value,b.info,b.status as c_status,b.seller_id')->group('b.id')->where($data)->select();
         //组装已商家为单位优惠券
         foreach ($coupons as $key => $val) {
             $seller_id = $val['seller_id'];
             $coupons2[$seller_id] = $val;
             if ($val['deadline'] < time()) {
                 ajaxErrReturn($val['title'] . '优惠券已过期');
             }
             if ($val['member_id'] != $this->user['id']) {
                 ajaxErrReturn($val['title'] . '非法优惠券');
             }
             if ($val['status'] == 1) {
                 ajaxErrReturn($val['title'] . '此优惠券已使用');
             }
         }
     }
     //促销
     if ($_POST['sp_id']) {
         $op_model = M('OrderPromotion');
         $op_data['id'] = array('in', explode(',', $_POST['sp_id']));
         $proms = $op_model->where($op_data)->select();
         //组装已商家为单位优惠券
         foreach ($proms as $key => $val) {
             $seller_id = $val['seller_id'];
             $proms2[$seller_id] = $val;
             if ($val['btime'] > time()) {
                 ajaxErrReturn($val['title'] . '促销活动还未开始');
             }
             if ($val['etime'] < time()) {
                 ajaxErrReturn($val['title'] . '促销活动已结束');
             }
         }
     }
     //生成订单
     $model = M('Order');
     $mem_model = M('Member');
     $od_model = M('OrderDetail');
     $time = time();
     $model->startTrans();
     //启用事务
     $mo_sn = '';
     if (count($list2) > 1) {
         $mo_sn = build_order_no($this->user['id']);
     }
     foreach ($list2 as $seller_id => $v) {
         if ($seller_id != 0) {
             //$mdata['id'] = $seller_id;
             //$user = $mem_model->field('id,pid')->where($mdata)->find();
             //$add_order['agent_id'] = $user['pid'];//代理商
             $add_order['seller_id'] = $seller_id;
         } else {
             $add_order['agent_id'] = 0;
         }
         //订单号
         $order_sn = $add_order['order_sn'] = build_order_no($this->user['id']);
         if ($mo_sn) {
             $add_order['mo_sn'] = $mo_sn;
         }
         //商品总价
         $add_order['total_fee'] = $v['total_fee'];
         //邮费处理
         $add_order['shipping_fee'] = shipping_fee($v['list'], $address);
         $add_order['type'] = 1;
         $add_order['title'] = '购买商品';
         //优惠券处理
         if ($_POST['coupon_user_id'] && $coupons2[$seller_id]) {
             $add_order['coupons_fee'] = $coupons2[$seller_id]['value'];
         } else {
             $add_order['coupons_fee'] = 0;
         }
         //促销价格
         if ($_POST['sp_id'] && $proms2[$seller_id]) {
             $options['prom_id'] = $proms2[$seller_id]['id'];
             $prom = get_promotion($v['list'], $options);
             if ($prom) {
                 $add_order['discount_fee'] = $prom[0]['award_value'];
             }
         } else {
             $add_order['discount_fee'] = 0;
         }
         //实付价格 = 总价 - 优惠券价 - 促销价 + 快递费
         $add_order['actual_paid'] = $add_order['total_fee'] - $add_order['coupons_fee'] - $add_order['discount_fee'] + $add_order['shipping_fee'];
         //发票税额
         if ($this->configs['tax_rate'] && $_POST['tax']) {
             $add_order['tax_fee'] = $add_order['actual_paid'] * $this->configs['tax_rate'] / 100;
         } else {
             $add_order['tax_fee'] = 0;
         }
         $add_order['tax_title'] = $_POST['tax_title'];
         $add_order['tax_content'] = $_POST['tax_content'];
         //总价 + 发票税
         $add_order['actual_paid'] = $add_order['actual_paid'] + $add_order['tax_fee'];
         $add_order['bond'] = 0;
         $add_order['total_num'] = $v['total_num'];
         $add_order['member_id'] = $this->user['id'];
         $add_order['member_name'] = $this->user['username'];
         //$add_order['realname'] = $this->user['realname'];
         $add_order['seller_id'] = $seller_id;
         $add_order['recipient'] = $address['name'];
         $add_order['pv_id'] = $address['pv_id'];
         $add_order['ct_id'] = $address['ct_id'];
         $add_order['dist_id'] = $address['dist_id'];
         $add_order['address'] = $address['province'] . $address['city'] . $address['district'] . $address['addr'];
         $add_order['zip_code'] = $address['zip_code'];
         $add_order['mobile'] = $address['mobile'];
         $add_order['memo'] = $_REQUEST['memo'] ? $_REQUEST['memo'] : '';
         $add_order['ip'] = $_SERVER['REMOTE_ADDR'];
         $add_order['create_time'] = $time;
         $add_order['order_time'] = $this->configs['order_expired'] != 0 ? $time + 3600 * $this->configs['order_expired'] : 0;
         $add_order['remark'] = $_POST['remark' . $mid] ? $_POST['remark' . $mid] : '';
         $oid = $model->add($add_order);
         //if(!$out_trade_no)$out_trade_no=$oid;
         if ($oid) {
             $result = true;
             if ($_POST['coupon_user_id'] && $coupons2[$seller_id]) {
                 //优惠券状态修改
                 $mc_wdata['id'] = $coupons2[$seller_id]['id'];
                 $mc_sdata['status'] = 1;
                 $mc_sdata['order_id'] = $oid;
                 $mc_sdata['use_time'] = $time;
                 $result = $mc_model->where($mc_wdata)->save($mc_sdata);
             }
             if (!$result) {
                 $result = $model->rollback();
                 ajaxErrReturn('优惠券无法使用');
                 exit;
             }
             //促销信息记录
             if ($_POST['sp_id'] && $proms2[$seller_id]) {
                 $pl_data['order_id'] = $oid;
                 //$pl_data['info'] = serialize($prom);
                 $pl_data['pm_type'] = 'Order';
                 $pl_data['pm_id'] = $proms2[$seller_id]['id'];
                 $pl_data['create_time'] = $time;
                 $result = $op_model->add($op_data);
             }
             if (!$result) {
                 $result = $model->rollback();
                 ajaxErrReturn('促销信息有误');
                 exit;
             }
             //订单产品详情
             foreach ($v['list'] as $goods) {
                 $od_data['member_id'] = $this->user['id'];
                 $od_data['seller_id'] = $seller_id;
                 $od_data['order_id'] = $oid;
                 $od_data['order_sn'] = $order_sn;
                 $od_data['source'] = $goods['item_id'] ? 'Product_item' : 'Product';
                 $gid = $goods['id'];
                 $od_data['sourceid'] = $gid;
                 $od_data['product_id'] = $goods['product_id'];
                 $od_data['item_id'] = $goods['item_id'];
                 $od_data['product_name'] = $goods['name'];
                 $od_data['spec'] = $goods['spec'] ? $goods['spec'] : '';
                 //$od_data['product_name'] = $goods['product_name'];
                 $share_id = $_SESSION['share'][$gid]['share_id'];
                 if ($share_id) {
                     if ($share_id == $this->user['id']) {
                         $share_id = 0;
                         //不能自己分享给自己
                     }
                 } else {
                     $share_id = 0;
                 }
                 $od_data['share_id'] = $share_id;
                 $od_data['lit_pic'] = $goods['lit_pic'];
                 $od_data['price'] = $goods['price'];
                 $od_data['num'] = $goods['num'];
                 $od_data['create_time'] = $time;
                 $md_id = $od_model->add($od_data);
                 //echo $od_model->getlastsql();exit;
                 if (!$md_id) {
                     $model->rollback();
                     ajaxErrReturn('详情订单生成失败');
                     exit;
                 }
             }
         } else {
             $model->rollback();
             ajaxErrReturn('订单生成失败');
             exit;
         }
     }
     //减去库存
     if ($this->configs['site_inventorysetup'] == 1) {
         stock_update($list['data']);
     }
     $model->commit();
     $msg['error_code'] = 0;
     $msg['notice'] = '订单生成成功';
     //清除购物车数据
     if ($_POST['cart_ids']) {
         //CartAction::delete();
         //$data = R('Cart/delete');
     }
     if ($mo_sn) {
         $msg['mo_sn'] = $mo_sn;
         $gourl = U('Order/beforpay', array('mo_sn', $mo_sn));
     } else {
         $msg['order_sn'] = $order_sn;
         $gourl = U('Order/beforpay', array('order_sn', $order_sn));
     }
     $msg['gourl'] = $gourl;
     ajaxSucReturn($msg);
 }
<?php

require "settings.php";
require_lib("encrypt");
if (isset($_REQUEST["key"])) {
    $key = strtolower($_REQUEST["key"]);
    switch ($key) {
        case "stock_out":
            $OUTPUT = stock_out();
            break;
        case "stock_update":
            $OUTPUT = stock_update();
            break;
        case "print":
            $OUTPUT = print_slip();
            break;
        case "dispatch_out":
            $OUTPUT = dispatch_out();
            break;
        case "invoice":
            $OUTPUT = invoice();
            break;
        case "quote":
            $OUTPUT = fromQuote();
            break;
    }
} else {
    $OUTPUT = stock_out();
}
$OUTPUT .= mkQuickLinks(ql(SELF . "?key=stock_out", "Create Picking Slip"), ql(SELF . "?key=dispatch_out", "Picking Slip Dispatch"), ql("stock-add.php", "Add Stock"));
require "template.php";