Exemplo n.º 1
0
/**
 * 使用团购券
 * @param unknown_type $password 密码
 * @param unknown_type $location_id 所消费的门店ID
 * @param unknown_type $account_id 执行使用的商家账号ID
 * @param unknown_type $send_return 是否要发放奖励
 * @param unknown_type $send_notify 是否发放通知(短信/邮件)
 * return:true,false true:已使用掉  false:未使用掉
 */
function use_coupon($password, $location_id = 0, $account_id = 0, $send_return = false, $send_notify = false)
{
    $GLOBALS['db']->query("update " . DB_PREFIX . "deal_coupon set is_balance = 1 ,location_id=" . $location_id . ", confirm_account = " . $account_id . ",confirm_time=" . NOW_TIME . " where password = '******' and confirm_time = 0");
    $coupon_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_coupon where password = '******'");
    if ($GLOBALS['db']->affected_rows() && $coupon_data) {
        $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set consume_count = consume_count + 1 where id = " . $coupon_data['order_deal_id']);
        update_order_cache($coupon_data['order_id']);
        distribute_order($coupon_data['order_id']);
        $order_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order where id = " . $coupon_data['order_id']);
        if ($order_info) {
            $order_msg = "订单号" . $order_info['order_sn'] . " ";
        }
        if ($send_return) {
            if ($coupon_data['coupon_money'] > 0 || $coupon_data['coupon_score'] > 0) {
                $money = $coupon_data['coupon_money'];
                $score = $coupon_data['coupon_score'];
                require_once APP_ROOT_PATH . "system/model/user.php";
                $log = $order_msg . $password . "消费券验证成功";
                modify_account(array("money" => $money, "score" => $score), $coupon_data['user_id'], $log);
            }
        }
        if ($send_notify) {
            send_use_coupon_sms(intval($coupon_data['id']));
            //发送团购券确认消息
            send_use_coupon_mail(intval($coupon_data['id']));
            //发送团购券确认消息
        }
        update_balance($coupon_data['id'], $coupon_data['deal_id']);
        $balance_price = $coupon_data['balance_price'] + $coupon_data['add_balance_price'];
        require_once APP_ROOT_PATH . "system/model/supplier.php";
        modify_supplier_account("-" . $balance_price, $coupon_data['supplier_id'], 1, $order_msg . $password . "消费券验证成功");
        //解冻资金
        modify_supplier_account($balance_price, $coupon_data['supplier_id'], 2, $order_msg . $password . "消费券验证成功");
        //等结算金额增加
        modify_statements($coupon_data['coupon_price'], 11, $order_msg . $password . "消费券验证成功");
        //增加消费额
        modify_statements($balance_price, 12, $order_msg . $password . "消费券验证成功");
        //增加消费额成本
        send_msg($coupon_data['user_id'], "消费券验证成功", "orderitem", $coupon_data['order_deal_id']);
        auto_over_status($coupon_data['order_id']);
        //检测自动结单
    }
    return $coupon_data['confirm_time'] > 0;
}
Exemplo n.º 2
0
 public function check_coupon_batch()
 {
     $s_account_info = es_session::get("account_info");
     if (intval($s_account_info['id']) == 0) {
         $res['status'] = 0;
         ajax_return($res);
     } else {
         $now = get_gmtime();
         $supplier_id = intval($s_account_info['supplier_id']);
         $temp = explode(",", $_REQUEST['code']);
         $k = 0;
         foreach ($temp as $v) {
             $coupon = explode('-', $v);
             $deal_id = $coupon['0'];
             $sn = $coupon['1'];
             $pwd = $coupon['2'];
             $coupon_data = $GLOBALS['db']->getRow("select c.refund_status,c.begin_time,c.end_time, c.id as id,c.is_valid,c.deal_id,doi.name as name,doi.sub_name as sub_name,c.password as password,doi.number as number,c.sn as sn,c.supplier_id as supplier_id,c.confirm_time as confirm_time from " . DB_PREFIX . "deal_coupon as c left join " . DB_PREFIX . "deal_order_item as doi on c.order_deal_id = doi.id where c.sn = '" . $sn . "' and c.password = '******' and c.is_valid in(1,2) and c.is_delete = 0 ");
             if ($coupon_data) {
                 if ($coupon_data['is_valid'] == 2) {
                     //改团购劵因为退款被锁定
                     $result[$k]['msg'] = $GLOBALS['lang']['COUPON_IS_VALID_2'];
                     $result[$k]['deal_id'] = $deal_id;
                     $result[$k]['id'] = $coupon_data['id'];
                     $result[$k]['name'] = $coupon_data['name'];
                     $result[$k]['sub_name'] = $coupon_data['sub_name'];
                     $result[$k]['password'] = $coupon_data['password'];
                     $result[$k]['sn'] = $sn;
                     $result[$k]['status'] = 0;
                     $k++;
                     continue;
                 }
                 if ($coupon_data['refund_status'] > 0) {
                     $result[$k]['msg'] = "团购券提交了退款申请,无法验证";
                     $result[$k]['deal_id'] = $deal_id;
                     $result[$k]['id'] = $coupon_data['id'];
                     $result[$k]['name'] = $coupon_data['name'];
                     $result[$k]['sub_name'] = $coupon_data['sub_name'];
                     $result[$k]['password'] = $coupon_data['password'];
                     $result[$k]['sn'] = $sn;
                     $result[$k]['status'] = 0;
                     $k++;
                     continue;
                 }
                 if ($coupon_data['begin_time'] > 0 && $coupon_data['begin_time'] > get_gmtime()) {
                     //未启用
                     $result[$k]['msg'] = "团购券未生效";
                     $result[$k]['deal_id'] = $deal_id;
                     $result[$k]['id'] = $coupon_data['id'];
                     $result[$k]['name'] = $coupon_data['name'];
                     $result[$k]['sub_name'] = $coupon_data['sub_name'];
                     $result[$k]['password'] = $coupon_data['password'];
                     $result[$k]['sn'] = $sn;
                     $result[$k]['status'] = 0;
                     $k++;
                     continue;
                 }
                 if ($coupon_data['end_time'] > 0 && $coupon_data['end_time'] < get_gmtime()) {
                     //过期
                     $result[$k]['msg'] = "团购券已过期";
                     $result[$k]['deal_id'] = $deal_id;
                     $result[$k]['id'] = $coupon_data['id'];
                     $result[$k]['name'] = $coupon_data['name'];
                     $result[$k]['sub_name'] = $coupon_data['sub_name'];
                     $result[$k]['password'] = $coupon_data['password'];
                     $result[$k]['sn'] = $sn;
                     $result[$k]['status'] = 0;
                     $k++;
                     continue;
                 }
                 $sql = "select d.* from " . DB_PREFIX . "deal as d left join " . DB_PREFIX . "deal_location_link as l on l.deal_id = d.id where l.deal_id = " . $coupon_data['deal_id'] . " and l.location_id in (" . implode(",", $s_account_info['location_ids']) . ")";
                 $deal_info = $GLOBALS['db']->getRow($sql);
                 if (!$deal_info) {
                     $result[$k]['msg'] = $GLOBALS['lang']['NO_AUTH'];
                     $result[$k]['deal_id'] = $deal_id;
                     $result[$k]['id'] = $coupon_data['id'];
                     $result[$k]['name'] = $coupon_data['name'];
                     $result[$k]['sub_name'] = $coupon_data['sub_name'];
                     $result[$k]['password'] = $coupon_data['password'];
                     $result[$k]['sn'] = $sn;
                     $result[$k]['status'] = 0;
                     $k++;
                     continue;
                 }
                 if ($coupon_data['supplier_id'] != $supplier_id) {
                     $result[$k]['msg'] = $GLOBALS['lang']['COUPON_INVALID_SUPPLIER'];
                     $result[$k]['deal_id'] = $deal_id;
                     $result[$k]['id'] = $coupon_data['id'];
                     $result[$k]['name'] = $coupon_data['name'];
                     $result[$k]['sub_name'] = $coupon_data['sub_name'];
                     $result[$k]['password'] = $coupon_data['password'];
                     $result[$k]['sn'] = $sn;
                     $result[$k]['status'] = 0;
                     $k++;
                     continue;
                 } elseif ($coupon_data['confirm_time'] > 0) {
                     $result[$k]['msg'] = sprintf($GLOBALS['lang']['COUPON_INVALID_USED'], to_date($coupon_data['confirm_time']));
                     $result[$k]['deal_id'] = $deal_id;
                     $result[$k]['id'] = $coupon_data['id'];
                     $result[$k]['name'] = $coupon_data['name'];
                     $result[$k]['sub_name'] = $coupon_data['sub_name'];
                     $result[$k]['password'] = $coupon_data['password'];
                     $result[$k]['sn'] = $sn;
                     $result[$k]['status'] = 0;
                     $k++;
                     continue;
                 } else {
                     //开始确认
                     $GLOBALS['db']->query("update " . DB_PREFIX . "deal_coupon set confirm_account = " . intval($s_account_info['id']) . ",confirm_time=" . $now . " where id = " . intval($coupon_data['id']));
                     $result[$k]['msg'] = $GLOBALS['lang']['COUPON_SUCCESS'];
                     $result[$k]['deal_id'] = $deal_id;
                     $result[$k]['id'] = $coupon_data['id'];
                     $result[$k]['name'] = $coupon_data['name'];
                     $result[$k]['sub_name'] = $coupon_data['sub_name'];
                     $result[$k]['password'] = $coupon_data['password'];
                     $result[$k]['sn'] = $sn;
                     $result[$k]['status'] = 1;
                     $k++;
                     //						$deal_type = intval($GLOBALS['db']->getOne("select deal_type from ".DB_PREFIX."deal where id = ".intval($coupon_data['deal_id'])));
                     //						if($deal_type == 1)
                     //						{
                     //							$result['msg'] = $coupon_data['name']."(购买数量:".$coupon_data['number'].")".sprintf($GLOBALS['lang']['COUPON_USED_OK'],to_date($now));;
                     //						}
                     //						else
                     //						{
                     //							$result['msg'] = $coupon_data['name'].sprintf($GLOBALS['lang']['COUPON_USED_OK'],to_date($now));;
                     //						}
                     send_use_coupon_sms(intval($coupon_data['id']));
                     //发送团购券确认消息
                     send_use_coupon_mail(intval($coupon_data['id']));
                     //发送团购券确认消息
                     update_balance($coupon_data['id'], $coupon_data['deal_id']);
                     continue;
                 }
             } else {
                 $result[$k]['msg'] = $GLOBALS['lang']['COUPON_INVALID'];
                 $result[$k]['deal_id'] = $deal_id;
                 $result[$k]['sn'] = $sn;
                 $result[$k]['id'] = 0;
                 $result[$k]['name'] = '-';
                 $result[$k]['sub_name'] = '-';
                 $result[$k]['password'] = '';
                 $result[$k]['status'] = 0;
                 $k++;
                 continue;
             }
         }
         $GLOBALS['tmpl']->assign('result', $result);
         $html = $GLOBALS['tmpl']->fetch("biz/user_coupon_batch_reult.html");
         $res['status'] = 1;
         $res['html'] = $html;
         header("Content-Type:text/html; charset=utf-8");
         ajax_return($res);
     }
 }
Exemplo n.º 3
0
     $msg_data['send_type'] = 0;
     $msg_data['content'] = $coupon_data['sn'] . sprintf($GLOBALS['lang']['COUPON_INVALID_USED'], to_date($coupon_data['confirm_time']));
     $msg_data['send_time'] = 0;
     $msg_data['is_send'] = 0;
     $msg_data['create_time'] = get_gmtime();
     $msg_data['user_id'] = 0;
     $msg_data['is_html'] = 0;
     $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
     //插入
     exit;
 } else {
     //开始确认
     $GLOBALS['db']->query("update " . DB_PREFIX . "deal_coupon set confirm_account = 999999,confirm_time=" . $now . " where id = " . intval($coupon_data['id']));
     $msg = $GLOBALS['lang']['COUPON_USE_LOG'] . ":(" . $SrcMobile . ")" . sprintf($GLOBALS['lang']['COUPON_USED_OK'], to_date($now));
     log_coupon($coupon_data['sn'], $msg, $RecvTime);
     send_use_coupon_sms(intval($coupon_data['id']));
     //发送团购券确认消息
     send_use_coupon_mail(intval($coupon_data['id']));
     //发送团购券确认消息
     $msg_data['dest'] = $SrcMobile;
     $msg_data['send_type'] = 0;
     $msg_data['content'] = $coupon_data['sub_name'] . "(" . $coupon_data['sn'] . ")" . sprintf($GLOBALS['lang']['COUPON_USED_OK'], to_date($now));
     $msg_data['send_time'] = 0;
     $msg_data['is_send'] = 0;
     $msg_data['create_time'] = get_gmtime();
     $msg_data['user_id'] = 0;
     $msg_data['is_html'] = 0;
     $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
     //插入
     exit;
 }