Esempio n. 1
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);
 }
        if (!isset($json->{'BSSID'})) {
            echo_invalid_param($json);
        }
        get_shop_info_by_bssid($json);
        break;
    case OPCODE::SERVICE_GET_PICTURE_REQUEST:
        if (!isset($json->{'ShopId'})) {
            echo_invalid_param($json);
        }
        get_picture($json);
        break;
    case OPCODE::SERVICE_GET_PROMOTION_REQUEST:
        if (!isset($json->{'ShopId'})) {
            echo_invalid_param($json);
        }
        get_promotion($json);
        break;
}
function get_requested_co_promotion($json)
{
    $database = new Database();
    $coProTbl = $database->getCoPromotionTbl();
    $promotionTbl = $database->getPromotionTbl();
    $copros = $coProTbl->getAllRequested($json->{'ShopId'});
    $ret_array = array();
    $cnt = 0;
    foreach ($copros as $co) {
        $promotionId = $co->PromotionId;
        $promotion = $promotionTbl->get($promotionId);
        $ret_array[$cnt++] = array("CoPromotionId" => $co->CoPromotionId, "ShopRequesterId" => $co->ShopRequesterId, "ShopPartnerId" => $co->ShopPartnerId, "PromotionName" => $promotion->Name, "PromotionDetail" => $promotion->Detail, "RecordDate" => $promotion->RecordDate, "PicturePath" => $promotion->PicturePath);
    }
Esempio n. 3
0
        if ($days === 0) {
            $wheresql .= " p.cp_endtime< " . time() . " ";
        } else {
            $wheresql .= " p.cp_endtime< " . $settr . " ";
        }
    }
    $promotionid = isset($_GET['promotionid']) ? intval($_GET['promotionid']) : "";
    if ($promotionid > 0) {
        $wheresql .= empty($wheresql) ? " WHERE p.cp_promotionid={$promotionid} " : " AND p.cp_promotionid={$promotionid} ";
    }
    $total_sql = "SELECT COUNT(*) AS num FROM " . table('promotion') . " AS p " . $joinsql . $wheresql;
    $total_val = $db->get_total($total_sql);
    $page = new page(array('total' => $total_val, 'perpage' => $perpage, 'getarray' => $_GET));
    $currenpage = $page->nowindex;
    $offset = ($currenpage - 1) * $perpage;
    $list = get_promotion($offset, $perpage, $joinsql . $wheresql . $oderbysql);
    $smarty->assign('navlabel', "list");
    $smarty->assign('list', $list);
    $smarty->assign('cat', get_promotion_cat(1));
    $smarty->assign('page', $page->show(3));
    $smarty->display('promotion/admin_promotion_list.htm');
} elseif ($act == 'promotion_add') {
    get_token();
    $smarty->assign('navlabel', "add");
    $smarty->assign('list', get_promotion_cat());
    $smarty->assign('cat', get_promotion_cat(1));
    $smarty->display('promotion/admin_promotion_add.htm');
} elseif ($act == 'promotion_save') {
    check_token();
    $setsqlarr['cp_days'] = intval($_POST['days']);
    if ($setsqlarr['cp_days'] == 0) {
Esempio n. 4
0
} elseif ($act == 'promotion') {
    $promotionid = intval($_GET['promotionid']);
    if ($promotionid == 0) {
        $wheresql = " WHERE uid='{$_SESSION['uid']}' ";
        $orderby = " order by refreshtime desc";
        require_once QISHI_ROOT_PATH . 'include/page.class.php';
        $perpage = 10;
        $total_sql = "SELECT COUNT(*) AS num FROM " . table('jobs') . $wheresql;
        $total_val = $db->get_total($total_sql);
        $page = new page(array('total' => $total_val, 'perpage' => $perpage));
        $offset = ($page->nowindex - 1) * $perpage;
        $sql = "SELECT * FROM " . table('jobs') . $wheresql . $orderby;
        $smarty->assign('list', get_jobs($offset, $perpage, $sql, true));
        $smarty->assign('page', $page->show(3));
    } else {
        $smarty->assign('list', get_promotion($_SESSION['uid'], $promotionid));
        //获取已经使用过某种推广的职位
    }
    $smarty->assign('promotionid', $promotionid);
    $smarty->assign('title', "职位推广 - 企业会员中心 - {$_CFG['site_name']}");
    $smarty->display('member_company/company_promotion.htm');
} elseif ($act == 'promotion_add') {
    $promotionid = intval($_GET['promotionid']);
    $promotion = get_promotion_category_one($promotionid);
    $smarty->assign('color', get_color());
    $smarty->assign('title', "{$promotion['cat_name']} - 企业推广 - 企业会员中心 - {$_CFG['site_name']}");
    $smarty->assign('promotion', $promotion);
    $smarty->assign('jobs', get_auditjobs($_SESSION['uid']));
    if ($_CFG['operation_mode'] == '2') {
        $setmeal = get_user_setmeal($_SESSION['uid']);
        //获取会员套餐