Example #1
0
 public function del_deal_vote()
 {
     $ajax = intval($_REQUEST['ajax']);
     $id = $_REQUEST['id'];
     if (isset($id)) {
         $condition = array('id' => array('in', explode(',', $id)));
         $rel_data = M("DealVote")->where($condition)->findAll();
         foreach ($rel_data as $data) {
             $deal_id = $data['deal_id'];
             $info[] = format_price($data['money']);
         }
         if ($info) {
             $info = implode(",", $info);
         }
         $info = "项目ID" . $deal_id . ":" . $info;
         $list = M("DealVote")->where($condition)->delete();
         if ($list !== false) {
             M("Deal")->where("id=" . $deal_id)->setField("deal_extra_cache", "");
             syn_deal($deal_id);
             save_log($info . l("FOREVER_DELETE_SUCCESS"), 1);
             $this->success(l("FOREVER_DELETE_SUCCESS"), $ajax);
         } else {
             save_log($info . l("FOREVER_DELETE_FAILED"), 0);
             $this->error(l("FOREVER_DELETE_FAILED"), $ajax);
         }
     } else {
         $this->error(l("INVALID_OPERATION"), $ajax);
     }
 }
 public function refund()
 {
     $id = intval($_REQUEST['id']);
     $order_info = M("DealOrder")->getById($id);
     if ($order_info) {
         $count_pay_log = M("DealPayLog")->where("deal_id=" . intval($order_info['deal_id']))->count();
         if ($count_pay_log > 0) {
             $this->error("筹款已发,不能退款");
         }
         if ($order_info['is_refund'] == 0) {
             $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set is_refund = 1 where id = " . $id . " and is_refund = 0");
             if ($GLOBALS['db']->affected_rows() > 0) {
                 require_once APP_ROOT_PATH . "system/libs/user.php";
                 modify_account(array("money" => $order_info['online_pay'] + $order_info['credit_pay']), $order_info['user_id'], $order_info['deal_name'] . "退款");
                 //退回积分
                 if ($order_info['score'] > 0) {
                     $log_info = $order_info['deal_name'] . "退款,退回" . $order_info['score'] . "积分";
                     modify_account(array("score" => $order_info['score']), $order_info['user_id'], $log_info);
                 }
                 //扣掉购买时送的积分和信用值
                 $sp_multiple = unserialize($order_info['sp_multiple']);
                 if ($sp_multiple['score_multiple'] > 0) {
                     $score = intval($order_info['total_price'] * $sp_multiple['score_multiple']);
                     $log_info = $order_info['deal_name'] . "退款,扣掉" . $score . "积分";
                     modify_account(array("score" => "-" . $score), $order_info['user_id'], $log_info);
                 }
                 if ($sp_multiple['point_multiple'] > 0) {
                     $point = intval($order_info['total_price'] * $sp_multiple['point_multiple']);
                     $log_info = $order_info['deal_name'] . "退款,扣掉" . $point . "信用值";
                     modify_account(array("point" => "-" . $point), $order_info['user_id'], $log_info);
                 }
                 syn_deal($order_info['deal_id']);
                 $deal_item['support_count'] = intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal_order where deal_id = " . $order_info['deal_id'] . " and order_status=3 and is_refund=0 and deal_item_id=" . intval($order_info['deal_item_id'])));
                 $deal_item['support_amount'] = floatval($GLOBALS['db']->getOne("select sum(deal_price) from " . DB_PREFIX . "deal_order where deal_id = " . $order_info['deal_id'] . " and order_status=3 and is_refund=0 and deal_item_id=" . intval($order_info['deal_item_id'])));
                 $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_item", $deal_item, $mode = 'UPDATE', "id=" . intval($order_info['deal_item_id']), $querymode = 'SILENT');
             }
             $this->success("成功退款到会员余额");
         } else {
             $this->error("已经退款");
         }
     } else {
         $this->error("没有该项目的支持");
     }
 }
Example #3
0
 public function index()
 {
     $add_order_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "add_order where time < " . time() . " and state=0");
     if ($add_order_list) {
         $deal_id_array = array();
         foreach ($add_order_list as $key => $val) {
             if (!in_array($val['deal_id'], $deal_id_array)) {
                 $deal_id_array[] = $val['deal_id'];
             }
             $tmp_deal_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal where id = " . $val['deal_id']);
             $tmp_deal_item_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_item where id = " . $val['deal_item_id']);
             for ($i = 0; $i < $val['num']; $i++) {
                 $tmp_num = rand(0, 50000);
                 $tmp_time = rand(100, 86000);
                 //获取导入用户
                 $tmp_user_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where login_ip = '' limit " . $tmp_num . ",1");
                 $tmp_order_info = array();
                 $tmp_order_info['deal_id'] = $val['deal_id'];
                 $tmp_order_info['deal_item_id'] = $val['deal_item_id'];
                 $tmp_order_info['user_id'] = $tmp_user_info['id'];
                 $tmp_order_info['user_name'] = $tmp_user_info['user_name'];
                 $tmp_order_info['pay_time'] = $val['time'] + $tmp_time;
                 $tmp_order_info['total_price'] = $tmp_deal_item_info['delivery_fee'] + $tmp_deal_item_info['price'];
                 $tmp_order_info['delivery_fee'] = $tmp_deal_item_info['delivery_fee'];
                 $tmp_order_info['deal_price'] = $tmp_deal_item_info['price'];
                 $tmp_order_info['support_memo'] = '支持!加油!';
                 $tmp_order_info['payment_id'] = 35;
                 $tmp_order_info['credit_pay'] = 0;
                 $tmp_order_info['online_pay'] = $tmp_deal_item_info['delivery_fee'] + $tmp_deal_item_info['price'];
                 $tmp_order_info['deal_name'] = $tmp_deal_info['name'];
                 $tmp_order_info['order_status'] = 3;
                 $tmp_order_info['create_time'] = $val['time'] + $tmp_time;
                 $tmp_order_info['is_has_send_success'] = 1;
                 if ($tmp_deal_item_info['is_delivery'] == 1) {
                     $tmp_order_info['consignee'] = '杨小帆';
                     $tmp_order_info['mobile'] = '18601911314';
                     $tmp_order_info['province'] = '北京';
                     $tmp_order_info['city'] = '东城区';
                     $tmp_order_info['address'] = '朝阳门 银河SOHO D2座 5层 50538';
                 }
                 $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_order", $tmp_order_info);
             }
             $GLOBALS['db']->query("update " . DB_PREFIX . "add_order set state = 1 where id = " . $val['id']);
         }
         foreach ($deal_id_array as $k2 => $v2) {
             $id = $v2;
             $order_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order where deal_id = " . $id . " and order_status=3");
             $item_array = array();
             foreach ($order_list as $k => $v) {
                 $log_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_support_log where deal_id = " . $v['deal_id'] . " and user_id=" . $v['user_id'] . " and create_time='" . $v['pay_time'] . "' and deal_item_id=" . $v['deal_item_id']);
                 if ($log_list) {
                 } else {
                     $tmp_log_info = array();
                     $tmp_log_info['deal_id'] = $v['deal_id'];
                     $tmp_log_info['deal_item_id'] = $v['deal_item_id'];
                     $tmp_log_info['user_id'] = $v['user_id'];
                     $tmp_log_info['create_time'] = $v['pay_time'];
                     $tmp_log_info['price'] = $v['total_price'];
                     $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_support_log", $tmp_log_info);
                     $tmp_log_id = $GLOBALS['db']->insert_id();
                     echo 'add log id = ' . $tmp_log_id . ' 。' . "<br>";
                 }
                 if (isset($item_array[$v['deal_item_id']])) {
                     $item_array[$v['deal_item_id']]['num'] += 1;
                     $item_array[$v['deal_item_id']]['total'] += $v['total_price'];
                 } else {
                     $item_array[$v['deal_item_id']] = array();
                     $item_array[$v['deal_item_id']]['num'] = 1;
                     $item_array[$v['deal_item_id']]['total'] = $v['total_price'];
                 }
             }
             foreach ($item_array as $ki => $vi) {
                 $GLOBALS['db']->query("update " . DB_PREFIX . "deal_item set support_count = " . intval($vi['num']) . ",support_amount = " . intval($vi['total']) . " where id = " . $ki);
                 echo 'update item num = ' . $vi['num'] . "<br>";
             }
             syn_deal_status($id);
             syn_deal($id);
             echo 'OK';
         }
     }
 }
function pay_order($order_id)
{
    require_once APP_ROOT_PATH . "system/libs/user.php";
    $order_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order where id = " . $order_id);
    if ($order_info['credit_pay'] + $order_info['online_pay'] >= $order_info['total_price']) {
        if ($order_info['credit_pay'] + $order_info['online_pay'] > $order_info['total_price']) {
            $more_money = $order_info['credit_pay'] + $order_info['online_pay'] - $order_info['total_price'];
            modify_account(array("money" => $more_money), $order_info['user_id'], $order_info['deal_name'] . "超额支付,转存入会员帐户");
        }
        $order_info['pay_time'] = get_gmtime();
        $GLOBALS['db']->query("update " . DB_PREFIX . "deal set support_count = support_count + 1,support_amount = support_amount + " . $order_info['deal_price'] . ",pay_amount = pay_amount + " . $order_info['total_price'] . ",delivery_fee_amount = delivery_fee_amount + " . $order_info['delivery_fee'] . " where id = " . $order_info['deal_id'] . " and is_effect = 1 and is_delete = 0 and begin_time < " . get_gmtime() . " and (end_time > " . get_gmtime() . " or end_time = 0)");
        if ($GLOBALS['db']->affected_rows() > 0) {
            //记录支持日志
            $support_log['deal_id'] = $order_info['deal_id'];
            $support_log['user_id'] = $order_info['user_id'];
            $support_log['create_time'] = get_gmtime();
            $support_log['price'] = $order_info['deal_price'];
            $support_log['deal_item_id'] = $order_info['deal_item_id'];
            $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_support_log", $support_log);
            $support_log_id = intval($GLOBALS['db']->insert_id());
            $GLOBALS['db']->query("update " . DB_PREFIX . "deal_item set support_count = support_count + 1,support_amount = support_amount +" . $order_info['deal_price'] . " where (support_count + 1 <= limit_user or limit_user = 0) and id = " . $order_info['deal_item_id']);
            if ($GLOBALS['db']->affected_rows() > 0) {
                $result['status'] = 3;
                $order_info['order_status'] = 3;
                $deal_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal where id = " . $order_info['deal_id'] . " and is_effect = 1 and is_delete = 0");
                //下单项目成功,准备加入准备队列
                if ($deal_info['is_success'] == 0) {
                    //未成功的项止准备生成队列
                    $notify['user_id'] = $GLOBALS['user_info']['id'];
                    $notify['deal_id'] = $deal_info['id'];
                    $notify['create_time'] = get_gmtime();
                    $GLOBALS['db']->autoExecute(DB_PREFIX . "user_deal_notify", $notify, "INSERT", "", "SILENT");
                }
                //更新用户的支持数
                $GLOBALS['db']->query("update " . DB_PREFIX . "user set support_count = support_count + 1 where id = " . $order_info['user_id']);
                //同步项目状态
                syn_deal_status($order_info['deal_id']);
                syn_deal($order_info['deal_id']);
            } else {
                $result['status'] = 2;
                $order_info['order_status'] = 2;
                $order_info['is_refund'] = 1;
                $GLOBALS['db']->query("update " . DB_PREFIX . "deal set support_count = support_count - 1,support_amount = support_amount - " . $order_info['deal_price'] . ",pay_amount = pay_amount - " . $order_info['total_price'] . ",delivery_fee_amount = delivery_fee_amount - " . $order_info['delivery_fee'] . " where id = " . $order_info['deal_id']);
                $GLOBALS['db']->query("delete from " . DB_PREFIX . "deal_support_log where id = " . $support_log_id);
                modify_account(array("money" => $order_info['total_price']), $order_info['user_id'], $order_info['deal_name'] . "限额已满,转存入会员帐户");
            }
        } else {
            $result['status'] = 1;
            $order_info['order_status'] = 1;
            $order_info['is_refund'] = 1;
            modify_account(array("money" => $order_info['total_price']), $order_info['user_id'], $order_info['deal_name'] . "已过期,转存入会员帐户");
        }
        $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set order_status = " . intval($order_info['order_status']) . ",pay_time = " . $order_info['pay_time'] . ",is_refund = " . $order_info['is_refund'] . " where id = " . $order_info['id']);
    } else {
        $result['status'] = 0;
        $result['money'] = $order_info['total_price'] - $order_info['online_pay'] - $order_info['credit_pay'];
    }
    return $result;
}