Пример #1
0
 public function index()
 {
     //检查用户,用户密码
     $user = $GLOBALS['user_info'];
     $user_id = intval($user['id']);
     $root = array();
     $root['return'] = 1;
     if ($user_id > 0) {
         $root['user_login_status'] = 1;
         $id = intval($GLOBALS['request']['id']);
         $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set is_delete = 1,order_status = 1 where id = " . $id . " and user_id = " . intval($user_id) . " and pay_status = 0");
         $rs = $GLOBALS['db']->affected_rows();
         if ($rs) {
             require_once APP_ROOT_PATH . "system/model/deal_order.php";
             distribute_order($id);
             $root['return'] = 1;
             $root['info'] = "删除成功";
         } else {
             $root['return'] = 0;
             $root['info'] = "删除失败";
         }
     } else {
         $root['return'] = 0;
         $root['info'] = "未登录";
         $root['user_login_status'] = 0;
     }
     output($root);
 }
Пример #2
0
 public function do_refuse()
 {
     $order_item_id = intval($_REQUEST['order_item_id']);
     $coupon_id = intval($_REQUEST['coupon_id']);
     $price = floatval($_REQUEST['price']);
     $balance_price = floatval($_REQUEST['balance_price']);
     $content = strim($_REQUEST['content']);
     if ($order_item_id) {
         $oi = $order_item_id;
         $data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order_item where id = " . $order_item_id);
         if ($data['refund_status'] == 2) {
             $this->error("已退款", 1);
         }
         if ($data) {
             $order_id = $data['order_id'];
             $supplier_id = $data['supplier_id'];
         }
         $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set refund_status = 3,is_arrival = 0 where id = " . $order_item_id);
         $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set refund_status = 3,is_refuse_delivery=0 where id = " . $order_id);
     } elseif ($coupon_id) {
         $data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_coupon where id = " . $coupon_id);
         if ($data['refund_status'] == 2) {
             $this->error("已退款", 1);
         }
         if ($data) {
             $oi = $data['order_deal_id'];
             $order_item = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order_item where id = " . $data['order_deal_id']);
             $data['name'] = $order_item['name'];
             $order_id = $data['order_id'];
             $supplier_id = $data['supplier_id'];
         }
         $GLOBALS['db']->query("update " . DB_PREFIX . "deal_coupon set refund_status = 3 where id = " . $coupon_id);
         $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set refund_status = 3 where id = " . $data['order_deal_id']);
         $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set  refund_status = 3  where id = " . $order_id);
     }
     $order_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order where id = " . $order_id);
     require_once APP_ROOT_PATH . "system/model/deal_order.php";
     order_log($data['name'] . "退款不通过 " . " " . $content, $order_id);
     auto_over_status($order_id);
     update_order_cache($order_id);
     distribute_order($order_id);
     send_msg($order_info['user_id'], $data['name'] . "退款不通过 " . " " . $content, "orderitem", $oi);
     $this->success("操作成功", 1);
 }
Пример #3
0
 public function order_done()
 {
     require_once APP_ROOT_PATH . "system/model/deal.php";
     require_once APP_ROOT_PATH . "system/model/deal_order.php";
     global_run();
     $ajax = 1;
     $user_info = $GLOBALS['user_info'];
     $id = intval($_REQUEST['id']);
     //订单号
     $order = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order where id = " . $id . " and is_delete = 0 and user_id = " . $user_info['id']);
     if (!$order) {
         showErr($GLOBALS['lang']['INVALID_ORDER_DATA'], $ajax);
     }
     if ($order['refund_status'] == 1) {
         showErr($GLOBALS['lang']['REFUNDING_CANNOT_PAY'], $ajax);
     }
     if ($order['refund_status'] == 2) {
         showErr($GLOBALS['lang']['REFUNDED_CANNOT_PAY'], $ajax);
     }
     $region4_id = intval($_REQUEST['region_lv4']);
     $region3_id = intval($_REQUEST['region_lv3']);
     $region2_id = intval($_REQUEST['region_lv2']);
     $region1_id = intval($_REQUEST['region_lv1']);
     if ($region4_id == 0) {
         if ($region3_id == 0) {
             if ($region2_id == 0) {
                 $region_id = $region1_id;
             } else {
                 $region_id = $region2_id;
             }
         } else {
             $region_id = $region3_id;
         }
     } else {
         $region_id = $region4_id;
     }
     $delivery_id = intval($_REQUEST['delivery']);
     $payment = intval($_REQUEST['payment']);
     $account_money = floatval($_REQUEST['account_money']);
     $all_account_money = intval($_REQUEST['all_account_money']);
     $ecvsn = $_REQUEST['ecvsn'] ? strim($_REQUEST['ecvsn']) : '';
     $ecvpassword = $_REQUEST['ecvpassword'] ? strim($_REQUEST['ecvpassword']) : '';
     $goods_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order['id']);
     //验证购物车
     if (check_save_login() != LOGIN_STATUS_LOGINED) {
         showErr($GLOBALS['lang']['PLEASE_LOGIN_FIRST'], $ajax, url("index", "user#login"));
     }
     //验证支付方式的支持
     foreach ($goods_list as $k => $row) {
         if ($GLOBALS['db']->getOne("select define_payment from " . DB_PREFIX . "deal where id = " . $row['deal_id']) == 1) {
             if ($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal_payment where deal_id = " . $row['deal_id'] . " and payment_id = " . $payment)) {
                 showErr($GLOBALS['lang']['INVALID_PAYMENT'], $ajax);
             }
         }
     }
     //结束验证购物车
     $deal_s = $GLOBALS['db']->getAll("select distinct(deal_id) as deal_id from " . DB_PREFIX . "deal_order_item where order_id = " . $order['id']);
     //如果属于未支付的
     if ($order['pay_status'] == 0) {
         foreach ($deal_s as $row) {
             $checker = check_deal_number($row['deal_id'], 0);
             if ($checker['status'] == 0) {
                 showErr($checker['info'] . " " . $GLOBALS['lang']['DEAL_ERROR_' . $checker['data']], $ajax);
             }
         }
         foreach ($goods_list as $k => $v) {
             $checker = check_deal_number_attr($v['deal_id'], $v['attr_str'], 0);
             if ($checker['status'] == 0) {
                 showErr($checker['info'] . " " . $GLOBALS['lang']['DEAL_ERROR_' . $checker['data']], $ajax);
             }
         }
         //验证商品是否过期
         foreach ($deal_s as $row) {
             $checker = check_deal_time($row['deal_id']);
             if ($checker['status'] == 0) {
                 showErr($checker['info'] . " " . $GLOBALS['lang']['DEAL_ERROR_' . $checker['data']], $ajax);
             }
         }
     }
     //开始验证订单接交信息
     require_once APP_ROOT_PATH . "system/model/cart.php";
     $data = count_buy_total($region_id, $delivery_id, $payment, $account_money, $all_account_money, $ecvsn, $ecvpassword, $goods_list, $order['account_money'], $order['ecv_money']);
     if ($data['is_delivery'] == 1) {
         //配送验证
         if (!$data['region_info'] || $data['region_info']['region_level'] != 4) {
             showErr($GLOBALS['lang']['FILL_CORRECT_CONSIGNEE_ADDRESS'], $ajax);
         }
         if (trim($_REQUEST['consignee']) == '') {
             showErr($GLOBALS['lang']['FILL_CORRECT_CONSIGNEE'], $ajax);
         }
         if (trim($_REQUEST['address']) == '') {
             showErr($GLOBALS['lang']['FILL_CORRECT_ADDRESS'], $ajax);
         }
         if (trim($_REQUEST['zip']) == '') {
             showErr($GLOBALS['lang']['FILL_CORRECT_ZIP'], $ajax);
         }
         if (trim($_REQUEST['mobile']) == '') {
             showErr($GLOBALS['lang']['FILL_MOBILE_PHONE'], $ajax);
         }
         if (!check_mobile(trim($_REQUEST['mobile']))) {
             showErr($GLOBALS['lang']['FILL_CORRECT_MOBILE_PHONE'], $ajax);
         }
         if (!$data['delivery_info']) {
             showErr($GLOBALS['lang']['PLEASE_SELECT_DELIVERY'], $ajax);
         }
     }
     if (round($data['pay_price'], 4) > 0 && !$data['payment_info']) {
         showErr($GLOBALS['lang']['PLEASE_SELECT_PAYMENT'], $ajax);
     }
     //结束验证订单接交信息
     //开始修正订单
     $now = NOW_TIME;
     $order['total_price'] = $data['pay_total_price'];
     //应付总额  商品价 - 会员折扣 + 运费 + 支付手续费
     $order['memo'] = strim($_REQUEST['memo']);
     $order['region_lv1'] = intval($_REQUEST['region_lv1']);
     $order['region_lv2'] = intval($_REQUEST['region_lv2']);
     $order['region_lv3'] = intval($_REQUEST['region_lv3']);
     $order['region_lv4'] = intval($_REQUEST['region_lv4']);
     $order['address'] = strim($_REQUEST['address']);
     $order['mobile'] = strim($_REQUEST['mobile']);
     $order['consignee'] = strim($_REQUEST['consignee']);
     $order['zip'] = strim($_REQUEST['zip']);
     $order['delivery_fee'] = $data['delivery_fee'];
     $order['delivery_id'] = $data['delivery_info']['id'];
     $order['payment_id'] = $data['payment_info']['id'];
     $order['payment_fee'] = $data['payment_fee'];
     $order['discount_price'] = $data['user_discount'];
     $order['bank_id'] = strim($_REQUEST['bank_id']);
     $order['promote_description'] = "";
     foreach ($data['promote_description'] as $promote_item) {
         $order['promote_description'] .= $promote_item . "<br />";
     }
     $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_order", $order, 'UPDATE', 'id=' . $order['id'], 'SILENT');
     if ($data['is_delivery'] == 1) {
         //保存收款人
         $consignee_id = intval($_REQUEST['consignee_id']);
         $user_consignee = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user_consignee where user_id = " . $order['user_id'] . " and id = " . $consignee_id);
         $user_consignee['region_lv1'] = intval($_REQUEST['region_lv1']);
         $user_consignee['region_lv2'] = intval($_REQUEST['region_lv2']);
         $user_consignee['region_lv3'] = intval($_REQUEST['region_lv3']);
         $user_consignee['region_lv4'] = intval($_REQUEST['region_lv4']);
         $user_consignee['address'] = strim($_REQUEST['address']);
         $user_consignee['mobile'] = strim($_REQUEST['mobile']);
         $user_consignee['consignee'] = strim($_REQUEST['consignee']);
         $user_consignee['zip'] = strim($_REQUEST['zip']);
         $user_consignee['user_id'] = $order['user_id'];
         if (intval($user_consignee['id']) == 0) {
             //新增,修改订单不新增配送
             // 				$user_consignee['is_default'] = 1;
             // 				$GLOBALS['db']->autoExecute(DB_PREFIX."user_consignee",$user_consignee,'INSERT','','SILENT');
         } else {
             //更新
             $GLOBALS['db']->autoExecute(DB_PREFIX . "user_consignee", $user_consignee, 'UPDATE', 'id=' . $user_consignee['id'], 'SILENT');
             rm_auto_cache("consignee_info", array("consignee_id" => intval($user_consignee['id'])));
         }
     }
     //生成order_id 后
     //1. 余额支付
     $account_money = $data['account_money'];
     if (floatval($account_money) > 0) {
         $account_payment_id = $GLOBALS['db']->getOne("select id from " . DB_PREFIX . "payment where class_name = 'Account'");
         $payment_notice_id = make_payment_notice($account_money, $order['id'], $account_payment_id);
         require_once APP_ROOT_PATH . "system/payment/Account_payment.php";
         $account_payment = new Account_payment();
         $account_payment->get_payment_code($payment_notice_id);
     }
     //3. 相应的支付接口
     $payment_info = $data['payment_info'];
     if ($payment_info && $data['pay_price'] > 0) {
         $payment_notice_id = make_payment_notice($data['pay_price'], $order['id'], $payment_info['id']);
         //创建支付接口的付款单
     }
     $rs = order_paid($order['id']);
     if ($rs) {
         $data = array();
         $data['info'] = "";
         $data['jump'] = url("index", "payment#done", array("id" => $order['id']));
         ajax_return($data);
         //支付成功
     } else {
         distribute_order($order['id']);
         $data = array();
         $data['info'] = "";
         $data['jump'] = url("index", "payment#pay", array("id" => $payment_notice_id));
         ajax_return($data);
     }
 }
Пример #4
0
 public function index()
 {
     $city_name = strim($GLOBALS['request']['city_name']);
     //城市名称
     $root = array();
     //检查用户,用户密码
     $user = $GLOBALS['user_info'];
     $user_id = intval($user['id']);
     $root['return'] = 1;
     if ($user_id > 0) {
         $did = intval($GLOBALS['request']['did']);
         $cid = intval($GLOBALS['request']['cid']);
         $content = strim($GLOBALS['request']['content']);
         if (empty($content)) {
             $root['status'] = 0;
             $root['info'] = "请填写退款原因";
             output($root);
         }
         if ($did) {
             //退单
             $deal_order_item = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order_item where id = " . $did);
             $order_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order where id = '" . $deal_order_item['order_id'] . "' and order_status = 0 and user_id = " . $user_id);
             if ($order_info) {
                 if ($deal_order_item['delivery_status'] == 0 && $order_info['pay_status'] == 2 && $deal_order_item['is_refund'] == 1) {
                     if ($deal_order_item['refund_status'] == 0) {
                         //执行退单,标记:deal_order_item表与deal_order表,
                         $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set refund_status = 1 where id = " . $deal_order_item['id']);
                         $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set refund_status = 1 where id = " . $deal_order_item['order_id']);
                         $msg = array();
                         $msg['rel_table'] = "deal_order";
                         $msg['rel_id'] = $deal_order_item['order_id'];
                         $msg['title'] = "退款申请";
                         $msg['content'] = "退款申请:" . $content;
                         $msg['create_time'] = NOW_TIME;
                         $msg['user_id'] = $user_id;
                         $GLOBALS['db']->autoExecute(DB_PREFIX . "message", $msg);
                         update_order_cache($deal_order_item['order_id']);
                         order_log($deal_order_item['sub_name'] . "申请退款,等待审核", $deal_order_item['order_id']);
                         require_once APP_ROOT_PATH . "system/model/deal_order.php";
                         distribute_order($order_info['id']);
                         $root['status'] = 1;
                         $root['info'] = "退款申请已提交,请等待审核";
                         output($root);
                     } else {
                         $root['status'] = 0;
                         $root['info'] = "不允许退款";
                         output($root);
                     }
                 } else {
                     $root['status'] = 0;
                     $root['info'] = "非法操作";
                     output($root);
                 }
             } else {
                 $root['status'] = 0;
                 $root['info'] = "非法操作";
                 output($root);
             }
         } elseif ($cid) {
             //退券
             $coupon = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_coupon where user_id = " . $user_id . " and id = " . $cid);
             if ($coupon) {
                 if ($coupon['refund_status'] == 0 && $coupon['confirm_time'] == 0) {
                     //从未退过款可以退款,且未使用过
                     if ($coupon['any_refund'] == 1 || $coupon['expire_refund'] == 1 && $coupon['end_time'] > 0 && $coupon['end_time'] < NOW_TIME) {
                         //随时退或过期退已过期
                         //执行退券
                         $GLOBALS['db']->query("update " . DB_PREFIX . "deal_coupon set refund_status = 1 where id = " . $coupon['id']);
                         $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set refund_status = 1 where id = " . $coupon['order_deal_id']);
                         $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set refund_status = 1 where id = " . $coupon['order_id']);
                         $deal_order_item = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order_item where id = " . $coupon['order_deal_id']);
                         $msg = array();
                         $msg['rel_table'] = "deal_order";
                         $msg['rel_id'] = $coupon['order_id'];
                         $msg['title'] = "退款申请";
                         $msg['content'] = $content;
                         $msg['create_time'] = NOW_TIME;
                         $msg['user_id'] = $user_id;
                         $GLOBALS['db']->autoExecute(DB_PREFIX . "message", $msg);
                         update_order_cache($coupon['order_id']);
                         order_log($deal_order_item['sub_name'] . "申请退一张团购券,等待审核", $coupon['order_id']);
                         require_once APP_ROOT_PATH . "system/model/deal_order.php";
                         distribute_order($coupon['order_id']);
                         $root['status'] = 1;
                         $root['info'] = "退款申请已提交,请等待审核";
                         output($root);
                     } else {
                         $root['status'] = 0;
                         $root['info'] = "不允许退款";
                         output($root);
                     }
                 } else {
                     $root['status'] = 0;
                     $root['info'] = "非法操作";
                     output($root);
                 }
             } else {
                 $root['status'] = 0;
                 $root['info'] = "非法操作";
                 output($root);
             }
         } else {
             $root['status'] = 0;
             $root['info'] = "非法操作";
             output($root);
         }
     } else {
         $root['user_login_status'] = 0;
     }
     output($root);
 }
Пример #5
0
/**
 * 结单操作,结单操作将发放邀请返利
 * @param unknown_type $order_id
 */
function over_order($order_id)
{
    $order_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order where order_status = 0 and id = " . $order_id);
    if ($order_info) {
        $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set order_status = 1,is_refuse_delivery = 0 where order_status = 0 and id = " . $order_id);
        if (!$GLOBALS['db']->affected_rows()) {
            return;
            //结单失败
        }
        order_log("订单完结", $order_id);
        $GLOBALS['db']->query("update " . DB_PREFIX . "deal_coupon set is_valid = 2 where order_id = " . $order_id);
        distribute_order($order_id);
        //结单后只要有未退款的才可返利
        $coupon_refunded = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal_coupon where order_id = " . $order_id . " and refund_status = 2");
        $order_item_refunded = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id . " and refund_status = 2");
        if ($order_item_refunded > 0 || $coupon_refunded > 0 || $order_info['is_delete'] == 1) {
            return;
            //不再返利
        }
        $goods_list = $GLOBALS['db']->getAll("select deal_id,sum(number) as num from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id . " group by deal_id");
        //返利
        //开始处理返利,只创建返利, 发放将与msg_list的自动运行一起执行
        $user_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . $order_info['user_id']);
        //开始查询所购买的列表中支不支持促销
        $is_referrals = 1;
        //默认为返利
        foreach ($goods_list as $k => $v) {
            $is_referrals = $GLOBALS['db']->getOne("select is_referral from " . DB_PREFIX . "deal where id = " . $v['deal_id']);
            if ($is_referrals == 0) {
                break;
            }
        }
        if ($user_info['referral_count'] < app_conf("REFERRAL_LIMIT") && $is_referrals == 1) {
            //开始返利给推荐人
            $parent_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . $user_info['pid']);
            if ($parent_info) {
                if (app_conf("REFERRAL_IP_LIMIT") == 1 && $parent_info['login_ip'] != CLIENT_IP || app_conf("REFERRAL_IP_LIMIT") == 0) {
                    if (app_conf("INVITE_REFERRALS_TYPE") == 0) {
                        $referral_data['user_id'] = $parent_info['id'];
                        //初返利的会员ID
                        $referral_data['rel_user_id'] = $user_info['id'];
                        //被推荐且发生购买的会员ID
                        $referral_data['create_time'] = NOW_TIME;
                        $referral_data['money'] = app_conf("INVITE_REFERRALS");
                        $referral_data['order_id'] = $order_info['id'];
                        $GLOBALS['db']->autoExecute(DB_PREFIX . "referrals", $referral_data);
                        //插入
                    } else {
                        $referral_data['user_id'] = $parent_info['id'];
                        //初返利的会员ID
                        $referral_data['rel_user_id'] = $user_info['id'];
                        //被推荐且发生购买的会员ID
                        $referral_data['create_time'] = NOW_TIME;
                        $referral_data['score'] = app_conf("INVITE_REFERRALS");
                        $referral_data['order_id'] = $order_info['id'];
                        $GLOBALS['db']->autoExecute(DB_PREFIX . "referrals", $referral_data);
                        //插入
                    }
                    $GLOBALS['db']->query("update " . DB_PREFIX . "user set referral_count = referral_count + 1 where id = " . $user_info['id']);
                }
            }
        }
        //返利over
    }
}
Пример #6
0
/**
 * 提交保存点评
 * @param unknown_type $user_id 提交点评的会员
 * @param unknown_type $param 参数 详细规则见 check_dp_status函数说明
 * @param unknown_type $content 点评文字内容
 * @param unknown_type $dp_point 总评分
 * @param unknown_type $dp_image 点评的图片数组 array("./public/...","./public/.....");
 * @param unknown_type $tag_group 点评标签(二维数组),格式如下
 * array(
 * 		"group_id" = array("tag","tag")
 * ); 其中group_id为分组的ID,第二维为每个分组中的tag
 * @param unknown_type $point_group 点评评分分组数据,格式如下
 * array(
 * 		"group_id" 	=>	"point"
 * ); 其中group_id为分组的ID,point为对应分组的评分
 * 
 * 返回 array("status"=>bool, "info"=>"消息","location_id"=>"门店的ID","deal_id"=>"","youhui_id"=>"","event_id"=>"");
 */
function save_review($user_id, $param = array("deal_id" => 0, "youhui_id" => 0, "event_id" => 0, "location_id" => 0, "order_item_id" => 0, "youhui_log_id" => 0, "event_submit_id" => 0), $content, $dp_point, $dp_image = array(), $tag_group = array(), $point_group = array())
{
    //获取参数
    $order_item_id = intval($param['order_item_id']);
    //订单商品ID
    $youhui_log_id = intval($param['youhui_log_id']);
    //优惠券领取日志ID
    $event_submit_id = intval($param['event_submit_id']);
    //活动报名日志ID
    if ($order_item_id > 0) {
        $deal_id = intval($GLOBALS['db']->getOne("select deal_id from " . DB_PREFIX . "deal_order_item where id = " . $order_item_id));
    } else {
        $deal_id = intval($param['deal_id']);
    }
    if ($youhui_log_id > 0) {
        $youhui_id = intval($GLOBALS['db']->getOne("select youhui_id from " . DB_PREFIX . "youhui_log where id = " . $youhui_log_id));
    } else {
        $youhui_id = intval($param['youhui_id']);
    }
    if ($event_submit_id > 0) {
        $event_id = intval($GLOBALS['db']->getOne("select event_id from " . DB_PREFIX . "event_submit where id = " . $event_submit_id));
    } else {
        $event_id = intval($param['event_id']);
    }
    $location_id = intval($param['location_id']);
    //部份初始化的变量
    $is_buy = 0;
    //默认的点评为非购物点评
    $avg_price = 0;
    //均价为0
    if ($deal_id > 0) {
        require_once APP_ROOT_PATH . "system/model/deal.php";
        $deal_info = get_deal($deal_id);
        if ($deal_info) {
            //验证是否可以点评
            $checker = check_dp_status($GLOBALS['user_info']['id'], array("deal_id" => $deal_id, "order_item_id" => $order_item_id));
            if (!$checker['status']) {
                return array("status" => false, "info" => $checker['info']);
            } else {
                $supplier_location_id = $checker['supplier_location_id'];
            }
            $is_buy = 1;
            $avg_price = $checker['avg_price'];
        } else {
            return array("status" => false, "info" => "你要点评的商品不存在");
        }
    } elseif ($youhui_id > 0) {
        require_once APP_ROOT_PATH . "system/model/youhui.php";
        $youhui_info = get_youhui($youhui_id);
        if ($youhui_info) {
            //验证是否可以点评
            $checker = check_dp_status($GLOBALS['user_info']['id'], array("youhui_id" => $youhui_id, "youhui_log_id" => $youhui_log_id));
            if (!$checker['status']) {
                return array("status" => false, "info" => $checker['info']);
            } else {
                $supplier_location_id = $checker['supplier_location_id'];
            }
        } else {
            return array("status" => false, "info" => "你要点评的优惠券不存在");
        }
    } elseif ($event_id > 0) {
        require_once APP_ROOT_PATH . "system/model/event.php";
        $event_info = get_event($event_id);
        if ($event_info) {
            //验证是否可以点评
            $checker = check_dp_status($GLOBALS['user_info']['id'], array("event_id" => $event_id, "event_submit_id" => $event_submit_id));
            if (!$checker['status']) {
                return array("status" => false, "info" => $checker['info']);
            } else {
                $supplier_location_id = $checker['supplier_location_id'];
            }
        } else {
            return array("status" => false, "info" => "你要点评的活动不存在");
        }
    } elseif ($location_id > 0) {
        require_once APP_ROOT_PATH . "system/model/supplier.php";
        $location_info = get_location($location_id);
        if ($location_info) {
            //验证是否可以点评
            $checker = check_dp_status($GLOBALS['user_info']['id'], array("location_id" => $location_id));
            if (!$checker['status']) {
                return array("status" => false, "info" => $checker['info']);
            } else {
                $supplier_location_id = $checker['supplier_location_id'];
            }
        } else {
            return array("status" => false, "info" => "你要点评的商家不存在");
        }
    }
    if ($deal_id == 0 && $youhui_id == 0 && $event_id == 0 && $location_id == 0) {
        return array("status" => false, "info" => "非法的数据");
    }
    //点评入库
    $supplier_info = $GLOBALS['db']->getRow("select name,id,new_dp_count_time,supplier_id from " . DB_PREFIX . "supplier_location where id = " . intval($supplier_location_id));
    $supplier_id = $supplier_info['supplier_id'];
    $dp_data = array();
    if ($content != "") {
        $dp_data['is_content'] = 1;
        $dp_data['content'] = $content;
    }
    $dp_data['create_time'] = NOW_TIME;
    $dp_data['point'] = $dp_point;
    $dp_data['user_id'] = $user_id;
    $dp_data['supplier_location_id'] = $supplier_location_id;
    $dp_data['youhui_id'] = $youhui_id;
    $dp_data['event_id'] = $event_id;
    $dp_data['deal_id'] = $deal_id;
    $dp_data['images_cache'] = serialize($dp_image);
    $dp_data['supplier_id'] = $supplier_id;
    $dp_data['status'] = 1;
    if (count($dp_image) > 0) {
        $dp_data['is_img'] = 1;
    }
    $dp_data['avg_price'] = floatval($avg_price);
    $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_location_dp", $dp_data, "INSERT");
    $dp_id = $GLOBALS['db']->insert_id();
    if ($dp_id > 0) {
        if ($checker['order_item_id']) {
            $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set dp_id = " . $dp_id . " where id = '" . $checker['order_item_id'] . "'");
            $order_id = intval($GLOBALS['db']->getOne("select order_id from " . DB_PREFIX . "deal_order_item where id = " . $checker['order_item_id']));
            update_order_cache($order_id);
            require_once APP_ROOT_PATH . "system/model/deal_order.php";
            distribute_order($order_id);
        }
        if ($checker['youhui_log_id']) {
            $GLOBALS['db']->query("update " . DB_PREFIX . "youhui_log set dp_id = " . $dp_id . " where id = '" . $checker['youhui_log_id'] . "'");
        }
        if ($checker['event_submit_id']) {
            $GLOBALS['db']->query("update " . DB_PREFIX . "event_submit set dp_id = " . $dp_id . " where id = '" . $checker['event_submit_id'] . "'");
        }
        increase_user_active($user_id, "发表了一则点评");
        $GLOBALS['db']->query("update " . DB_PREFIX . "user set dp_count = dp_count + 1 where id = " . $user_id);
        //创建点评图库
        if (count($dp_image) > 0) {
            foreach ($dp_image as $pkey => $photo) {
                //点评图片不入商户图片库
                // 				$c_data = array();
                // 				$c_data['image'] = $photo;
                // 				$c_data['sort'] = 10;
                // 				$c_data['create_time'] = NOW_TIME;
                // 				$c_data['user_id'] = $user_id;
                // 				$c_data['supplier_location_id'] = $supplier_location_id;
                // 				$c_data['dp_id'] = $dp_id;
                // 				$c_data['status'] = 0;
                // 				$GLOBALS['db']->autoExecute(DB_PREFIX."supplier_location_images", $c_data,"INSERT");
                $c_data = array();
                $c_data['image'] = $photo;
                $c_data['dp_id'] = $dp_id;
                $c_data['create_time'] = NOW_TIME;
                $c_data['location_id'] = $supplier_location_id;
                $c_data['supplier_id'] = $supplier_id;
                $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_location_dp_images", $c_data, "INSERT");
            }
        }
        //创建点评评分
        foreach ($point_group as $group_id => $point) {
            $point_data = array();
            $point_data['group_id'] = $group_id;
            $point_data['dp_id'] = $dp_id;
            $point_data['supplier_location_id'] = $supplier_location_id;
            $point_data['point'] = $point;
            $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_location_dp_point_result", $point_data, "INSERT");
            //创建商品点评数据
            if ($dp_data['deal_id'] > 0) {
                $point_data = array();
                $point_data['group_id'] = $group_id;
                $point_data['dp_id'] = $dp_id;
                $point_data['deal_id'] = $dp_data['deal_id'];
                $point_data['point'] = $point;
                $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_dp_point_result", $point_data, "INSERT");
            }
            //创建优惠券点评数据
            if ($dp_data['youhui_id'] > 0) {
                $point_data = array();
                $point_data['group_id'] = $group_id;
                $point_data['dp_id'] = $dp_id;
                $point_data['youhui_id'] = $dp_data['youhui_id'];
                $point_data['point'] = $point;
                $GLOBALS['db']->autoExecute(DB_PREFIX . "youhui_dp_point_result", $point_data, "INSERT");
            }
            //创建活动点评数据
            if ($dp_data['event_id'] > 0) {
                $point_data = array();
                $point_data['group_id'] = $group_id;
                $point_data['dp_id'] = $dp_id;
                $point_data['event_id'] = $dp_data['event_id'];
                $point_data['point'] = $point;
                $GLOBALS['db']->autoExecute(DB_PREFIX . "event_dp_point_result", $point_data, "INSERT");
            }
        }
        //创建点评分组的标签
        foreach ($tag_group as $group_id => $tag_row_arr) {
            foreach ($tag_row_arr as $tag_row) {
                $tag_row_data = array();
                $tag_row_data['tags'] = $tag_row;
                $tag_row_data['dp_id'] = $dp_id;
                $tag_row_data['supplier_location_id'] = $supplier_location_id;
                $tag_row_data['group_id'] = $group_id;
                $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_location_dp_tag_result", $tag_row_data, "INSERT");
                insert_match_item($tag_row, "supplier_location_dp", $dp_id, "tags_match");
                //更新点评的索引
                review_supplier_location_match($supplier_location_id, $tag_row, $group_id);
                //创建商品点评数据
                if ($dp_data['deal_id'] > 0) {
                    $tag_row_data = array();
                    $tag_row_data['tags'] = $tag_row;
                    $tag_row_data['dp_id'] = $dp_id;
                    $tag_row_data['deal_id'] = $dp_data['deal_id'];
                    $tag_row_data['group_id'] = $group_id;
                    $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_dp_tag_result", $tag_row_data, "INSERT");
                }
                //创建优惠券点评数据
                if ($dp_data['youhui_id'] > 0) {
                    $tag_row_data = array();
                    $tag_row_data['tags'] = $tag_row;
                    $tag_row_data['dp_id'] = $dp_id;
                    $tag_row_data['youhui_id'] = $dp_data['youhui_id'];
                    $tag_row_data['group_id'] = $group_id;
                    $GLOBALS['db']->autoExecute(DB_PREFIX . "youhui_dp_tag_result", $tag_row_data, "INSERT");
                }
                //创建活动点评数据
                if ($dp_data['event_id'] > 0) {
                    $tag_row_data = array();
                    $tag_row_data['tags'] = $tag_row;
                    $tag_row_data['dp_id'] = $dp_id;
                    $tag_row_data['event_id'] = $dp_data['event_id'];
                    $tag_row_data['group_id'] = $group_id;
                    $GLOBALS['db']->autoExecute(DB_PREFIX . "event_dp_tag_result", $tag_row_data, "INSERT");
                }
            }
        }
        //更新统计
        syn_supplier_locationcount($supplier_info);
        cache_store_point($supplier_info['id']);
        //统计商品点评数据
        if ($dp_data['deal_id'] > 0) {
            //计算总点评1-5星人数
            $item_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal where id = " . $dp_data['deal_id']);
            $sql = "select count(*) as total,point from " . DB_PREFIX . "supplier_location_dp  where deal_id = " . $item_data['id'] . " group by point ";
            $data_result = $GLOBALS['db']->getAll($sql);
            foreach ($data_result as $k => $v) {
                $item_data['dp_count_' . $v['point']] = $v['total'];
            }
            $GLOBALS['db']->autoExecute(DB_PREFIX . "deal", $item_data, "UPDATE", " id = " . $item_data['id'] . " ");
            syn_deal_review_count($item_data['id']);
        }
        //创建优惠券点评数据
        if ($dp_data['youhui_id'] > 0) {
            //计算总点评1-5星人数
            $item_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "youhui where id = " . $dp_data['youhui_id']);
            $sql = "select count(*) as total,point from " . DB_PREFIX . "supplier_location_dp  where youhui_id = " . $item_data['id'] . " group by point ";
            $data_result = $GLOBALS['db']->getAll($sql);
            foreach ($data_result as $k => $v) {
                $item_data['dp_count_' . $v['point']] = $v['total'];
            }
            $GLOBALS['db']->autoExecute(DB_PREFIX . "youhui", $item_data, "UPDATE", " id = " . $item_data['id'] . " ");
            syn_youhui_review_count($item_data['id']);
        }
        //创建活动点评数据
        if ($dp_data['event_id'] > 0) {
            //计算总点评1-5星人数
            $item_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "event where id = " . $dp_data['event_id']);
            $sql = "select count(*) as total,point from " . DB_PREFIX . "supplier_location_dp where event_id = " . $item_data['id'] . " group by point ";
            $data_result = $GLOBALS['db']->getAll($sql);
            foreach ($data_result as $k => $v) {
                $item_data['dp_count_' . $v['point']] = $v['total'];
            }
            $GLOBALS['db']->autoExecute(DB_PREFIX . "event", $item_data, "UPDATE", " id = " . $item_data['id'] . " ");
            syn_event_review_count($item_data['id']);
        }
        $return['location_id'] = $supplier_location_id;
        $return['deal_id'] = $dp_data['deal_id'];
        $return['youhui_id'] = $dp_data['youhui_id'];
        $return['event_id'] = $dp_data['event_id'];
        $return['status'] = 1;
        $return['info'] = "发表成功";
        return $return;
    } else {
        $return['status'] = 0;
        $return['info'] = "数据库异常,提交失败";
        return $return;
    }
}
Пример #7
0
function order_paid_done($order_id)
{
    //处理支付成功后的操作
    /**
     * 1. 发货
     * 2. 超量发货的存到会员中心
     * 3. 发券
     * 4. 发放抽奖
     */
    require_once APP_ROOT_PATH . "system/model/deal.php";
    require_once APP_ROOT_PATH . "system/model/supplier.php";
    require_once APP_ROOT_PATH . "system/model/deal_order.php";
    $order_id = intval($order_id);
    $stock_status = true;
    //团购状态
    $order_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order where id = " . $order_id);
    if ($order_info['type'] == 0) {
        //首先验证所有的规格库存
        $order_goods_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id);
        foreach ($order_goods_list as $k => $v) {
            if ($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "attr_stock where deal_id = " . $v['deal_id'] . " and locate(attr_str,'" . $v['attr_str'] . "') > 0")) {
                $sql = "update " . DB_PREFIX . "attr_stock set buy_count = buy_count + " . $v['number'] . " where deal_id = " . $v['deal_id'] . " and ((buy_count + " . $v['number'] . " <= stock_cfg) or stock_cfg = 0 )" . " and locate(attr_str,'" . $v['attr_str'] . "') > 0 ";
                $GLOBALS['db']->query($sql);
                //增加商品的发货量
                $rs = $GLOBALS['db']->affected_rows();
                if ($rs) {
                    $affect_attr_list[] = $v;
                } else {
                    $stock_status = false;
                    break;
                }
            }
        }
        if ($stock_status) {
            $goods_list = $GLOBALS['db']->getAll("select buy_type,deal_id,sum(number) as num,sum(add_balance_price_total) as add_balance_price_total,sum(balance_total_price) as balance_total_price,sum(return_total_money) as return_total_money,sum(return_total_score) as return_total_score from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id . " group by deal_id");
            foreach ($goods_list as $k => $v) {
                $sql = "update " . DB_PREFIX . "deal set buy_count = buy_count + " . $v['num'] . ",user_count = user_count + 1 where id=" . $v['deal_id'] . " and ((buy_count + " . $v['num'] . "<= max_bought) or max_bought = 0) " . " and time_status = 1 and buy_status <> 2";
                $GLOBALS['db']->query($sql);
                //增加商品的发货量
                $rs = $GLOBALS['db']->affected_rows();
                if ($rs) {
                    $affect_list[] = $v;
                    //记录下更新成功的团购商品,用于回滚
                } else {
                    //失败成功,即过期支付,超量支付
                    $stock_status = false;
                    break;
                }
            }
        }
        $return_money = 0;
        //非发券非配送的即时返还
        $return_score = 0;
        //非发券非配送的即时返还
        $use_score = 0;
        //积分商品所耗费的积分
        if ($stock_status) {
            foreach ($goods_list as $k => $v) {
                $deal_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal where id = " . intval($v['deal_id']));
                //统计商户销售额
                $supplier_log = "ID:" . $deal_info['id'] . " " . $deal_info['sub_name'] . " 订单:" . $order_info['order_sn'];
                modify_supplier_account($v['balance_total_price'] + $v['add_balance_price_total'], $deal_info['supplier_id'], 0, $supplier_log);
                if ($deal_info['is_coupon'] == 0 && $deal_info['is_delivery'] == 0) {
                    //更新订单中相关产品的消费状态
                    $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set consume_count = consume_count + 1 where order_id = " . $order_info['id'] . " and deal_id = " . $deal_info['id']);
                    update_order_cache($order_info['id']);
                    distribute_order($order_info['id']);
                    modify_supplier_account($v['balance_total_price'] + $v['add_balance_price_total'], $deal_info['supplier_id'], 2, $supplier_log);
                    //等结算金额增加
                } else {
                    modify_supplier_account($v['balance_total_price'] + $v['add_balance_price_total'], $deal_info['supplier_id'], 1, $supplier_log);
                    //冻结资金
                }
                //不发货不发券的实时返还
                if ($deal_info['is_coupon'] == 0 && $deal_info['is_delivery'] == 0 && $v['buy_type'] == 0) {
                    $return_money += $v['return_total_money'];
                    $return_score += $v['return_total_score'];
                }
                if ($v['buy_type'] == 1) {
                    $use_score += $v['return_total_score'];
                }
                $balance_price += $v['balance_total_price'];
                $add_balance_price += $v['add_balance_price_total'];
                //发券
                if ($deal_info['is_coupon'] == 1) {
                    if ($deal_info['deal_type'] == 1) {
                        $deal_order_item_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order_info['id'] . " and deal_id = " . $v['deal_id']);
                        foreach ($deal_order_item_list as $item) {
                            //							for($i=0;$i<$item['number'];$i++) //按单
                            //							{
                            //需要发券
                            /**
                             * 1. 先从已有团购券中发送
                             * 2. 无有未发送的券,自动发送
                             * 3. 发送状态的is_valid 都是 0, 该状态的激活在syn_deal_status中处理
                             */
                            /*修正后台手动建团购劵,购买的时候按单发送团购劵,数量不一致*/
                            $sql = "update " . DB_PREFIX . "deal_coupon set user_id=" . $order_info['user_id'] . ",order_id = " . $order_info['id'] . ",order_deal_id = " . $item['id'] . ",expire_refund = " . $deal_info['expire_refund'] . ",any_refund = " . $deal_info['any_refund'] . ",coupon_price = " . $item['total_price'] . ",coupon_score = " . $item['return_total_score'] . ",coupon_money = " . $item['return_total_money'] . ",add_balance_price = " . $item['add_balance_price'] . ",deal_type = " . $deal_info['deal_type'] . ",balance_price = " . $item['balance_total_price'] . " where deal_id = " . $v['deal_id'] . " and user_id = 0 " . " and is_delete = 0 order by id ASC limit 1";
                            $GLOBALS['db']->query($sql);
                            $exist_coupon = $GLOBALS['db']->affected_rows();
                            if (!$exist_coupon) {
                                //未发送成功,即无可发放的预设团购券
                                add_coupon($v['deal_id'], $order_info['user_id'], 0, '', '', 0, 0, $item['id'], $order_info['id']);
                            }
                            //							}
                        }
                    } else {
                        $deal_order_item_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order_info['id'] . " and deal_id = " . $v['deal_id']);
                        foreach ($deal_order_item_list as $item) {
                            for ($i = 0; $i < $item['number']; $i++) {
                                //需要发券
                                /**
                                 * 1. 先从已有团购券中发送
                                 * 2. 无有未发送的券,自动发送
                                 * 3. 发送状态的is_valid 都是 0, 该状态的激活在syn_deal_status中处理
                                 */
                                $sql = "update " . DB_PREFIX . "deal_coupon set user_id=" . $order_info['user_id'] . ",order_id = " . $order_info['id'] . ",order_deal_id = " . $item['id'] . ",expire_refund = " . $deal_info['expire_refund'] . ",any_refund = " . $deal_info['any_refund'] . ",coupon_price = " . $item['unit_price'] . ",coupon_score = " . $item['return_score'] . ",coupon_money = " . $item['return_money'] . ",add_balance_price = " . $item['add_balance_price'] . ",deal_type = " . $deal_info['deal_type'] . ",balance_price = " . $item['balance_unit_price'] . " where deal_id = " . $v['deal_id'] . " and user_id = 0 " . " and is_delete = 0 limit 1";
                                $GLOBALS['db']->query($sql);
                                $exist_coupon = $GLOBALS['db']->affected_rows();
                                if (!$exist_coupon) {
                                    //未发送成功,即无可发放的预设团购券
                                    add_coupon($v['deal_id'], $order_info['user_id'], 0, '', '', 0, 0, $item['id'], $order_info['id']);
                                }
                            }
                        }
                    }
                }
                //发券结束
            }
            //开始处理返还的积分或现金,此处返还不用发货不用配送不用发券的产品返还
            require_once APP_ROOT_PATH . "system/model/user.php";
            if ($return_money != 0) {
                $msg = sprintf($GLOBALS['lang']['ORDER_RETURN_MONEY'], $order_info['order_sn']);
                modify_account(array('money' => $return_money, 'score' => 0), $order_info['user_id'], $msg);
            }
            if ($return_score != 0) {
                $msg = sprintf($GLOBALS['lang']['ORDER_RETURN_SCORE'], $order_info['order_sn']);
                modify_account(array('money' => 0, 'score' => $return_score), $order_info['user_id'], $msg);
                send_score_sms($order_info['id']);
                send_score_mail($order_info['id']);
            }
            if ($use_score != 0) {
                $user_score = $GLOBALS['db']->getOne("select score from " . DB_PREFIX . "user where id = " . $order_info['user_id']);
                if ($user_score + $use_score < 0) {
                    //积分不足,不能支付
                    $msg = $order_info['order_sn'] . "订单支付失败,积分不足";
                    $refund_money = $order_info['pay_amount'];
                    if ($order_info['account_money'] > $refund_money) {
                        $account_money_now = $order_info['account_money'] - $refund_money;
                    } else {
                        $account_money_now = 0;
                    }
                    $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set account_money = " . $account_money_now . " where id = " . $order_info['id']);
                    if ($order_info['ecv_money'] > $refund_money) {
                        $ecv_money_now = $order_info['ecv_money'] - $refund_money;
                    } else {
                        $ecv_money_now = 0;
                    }
                    $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set ecv_money = " . $ecv_money_now . " where id = " . $order_info['id']);
                    if ($refund_money > 0) {
                        modify_account(array('money' => $refund_money, 'score' => 0), $order_info['user_id'], $msg);
                        $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set refund_money = refund_money + " . $refund_money . ",refund_amount = refund_amount + " . $refund_money . ",after_sale = 1,refund_status = 2 where id = " . $order_info['id']);
                        $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set refund_status = 2 where order_id = " . $order_info['id']);
                        order_log($order_info['order_sn'] . "积分不足," . format_price($refund_money) . "已退到会员余额", $order_info['id']);
                        modify_statements("-" . $refund_money, 1, $order_info['order_sn'] . "积分不足,退款");
                        modify_statements($refund_money, 2, $order_info['order_sn'] . "积分不足,退款");
                    } else {
                        order_log($order_info['order_sn'] . "积分不足", $order_info['id']);
                    }
                    require_once APP_ROOT_PATH . "system/model/deal_order.php";
                    update_order_cache($order_info['id']);
                    over_order($order_info['id']);
                } else {
                    modify_account(array('score' => $use_score), $order_info['user_id'], "积分商品兑换");
                    send_score_sms($order_info['id']);
                    send_score_mail($order_info['id']);
                    order_log($order_info['order_sn'] . "积分订单支付成功", $order_info['id']);
                    send_msg($order_info['user_id'], "订单" . $order_info['order_sn'] . "兑换成功", "orderitem", $order_goods_list[0]['id']);
                    if ($order_info['total_price'] > 0) {
                        modify_statements($order_info['total_price'], 8, $order_info['order_sn'] . "订单成功付款");
                    }
                    //增加营业额
                }
            } else {
                //开始处理返利,只创建返利, 发放将与msg_list的自动运行一起执行
                // 			$user_info = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."user where id = ".$order_info['user_id']);
                // 			//开始查询所购买的列表中支不支持促销
                // 			$is_referrals = 1; //默认为返利
                // 			foreach($goods_list as $k=>$v)
                // 			{
                // 				$is_referrals = $GLOBALS['db']->getOne("select is_referral from ".DB_PREFIX."deal where id = ".$v['deal_id']);
                // 				if($is_referrals == 0)
                // 				{
                // 					break;
                // 				}
                // 			}
                // 			if($user_info['referral_count']<app_conf("REFERRAL_LIMIT")&&$is_referrals == 1)
                // 			{
                // 				//开始返利给推荐人
                // 				$parent_info = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."user where id = ".$user_info['pid']);
                // 				if($parent_info)
                // 				{
                // 					if((app_conf("REFERRAL_IP_LIMIT")==1&&$parent_info['login_ip']!=CLIENT_IP)||app_conf("REFERRAL_IP_LIMIT")==0) //IP限制
                // 					{
                // 						if(app_conf("INVITE_REFERRALS_TYPE")==0) //现金返利
                // 						{
                // 							$referral_data['user_id'] = $parent_info['id']; //初返利的会员ID
                // 							$referral_data['rel_user_id'] = $user_info['id'];	 //被推荐且发生购买的会员ID
                // 							$referral_data['create_time'] = NOW_TIME;
                // 							$referral_data['money']	=	app_conf("INVITE_REFERRALS");
                // 							$referral_data['order_id']	=	$order_info['id'];
                // 							$GLOBALS['db']->autoExecute(DB_PREFIX."referrals",$referral_data); //插入
                // 						}
                // 						else
                // 						{
                // 							$referral_data['user_id'] = $parent_info['id']; //初返利的会员ID
                // 							$referral_data['rel_user_id'] = $user_info['id'];	 //被推荐且发生购买的会员ID
                // 							$referral_data['create_time'] = NOW_TIME;
                // 							$referral_data['score']	=	app_conf("INVITE_REFERRALS");
                // 							$referral_data['order_id']	=	$order_info['id'];
                // 							$GLOBALS['db']->autoExecute(DB_PREFIX."referrals",$referral_data); //插入
                // 						}
                // 						$GLOBALS['db']->query("update ".DB_PREFIX."user set referral_count = referral_count + 1 where id = ".$user_info['id']);
                // 					}
                // 				}
                // 			}
                //超出充值
                if ($order_info['pay_amount'] > $order_info['total_price']) {
                    require_once APP_ROOT_PATH . "system/model/user.php";
                    if ($order_info['total_price'] < 0) {
                        $msg = sprintf($GLOBALS['lang']['MONEYORDER_INCHARGE'], $order_info['order_sn']);
                    } else {
                        $msg = sprintf($GLOBALS['lang']['OUTOFMONEY_INCHARGE'], $order_info['order_sn']);
                    }
                    $refund_money = $order_info['pay_amount'] - $order_info['total_price'];
                    if ($order_info['account_money'] > $refund_money) {
                        $account_money_now = $order_info['account_money'] - $refund_money;
                    } else {
                        $account_money_now = 0;
                    }
                    $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set account_money = " . $account_money_now . " where id = " . $order_info['id']);
                    if ($order_info['ecv_money'] > $refund_money) {
                        $ecv_money_now = $order_info['ecv_money'] - $refund_money;
                    } else {
                        $ecv_money_now = 0;
                    }
                    $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set ecv_money = " . $ecv_money_now . " where id = " . $order_info['id']);
                    modify_account(array('money' => $refund_money, 'score' => 0), $order_info['user_id'], $msg);
                    $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set refund_money = refund_money + " . $refund_money . ",refund_amount = refund_amount + " . $refund_money . " where id = " . $order_info['id']);
                    order_log($order_info['order_sn'] . "订单超额支付," . format_price($refund_money) . "已退到会员余额", $order_info['id']);
                    modify_statements("-" . $refund_money, 1, $order_info['order_sn'] . "订单超额");
                    modify_statements($refund_money, 2, $order_info['order_sn'] . "订单超额");
                }
                modify_statements($order_info['total_price'], 8, $order_info['order_sn'] . "订单成功付款");
                //增加营业额
                $balance_total = $GLOBALS['db']->getOne("select sum(balance_total_price)+sum(add_balance_price_total) from " . DB_PREFIX . "deal_order_item where order_id = " . $order_info['id']);
                modify_statements($balance_total, 9, $order_info['order_sn'] . "订单成功付款");
                //增加营业额中的成本
                //生成抽奖
                $lottery_list = $GLOBALS['db']->getAll("select d.id as did,doi.number from " . DB_PREFIX . "deal_order_item as doi left join " . DB_PREFIX . "deal_order as do on doi.order_id = do.id left join " . DB_PREFIX . "deal as d on doi.deal_id = d.id where d.is_lottery = 1 and do.id = " . $order_info['id']);
                $lottery_user = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . intval($order_info['user_id']));
                //如为首次抽奖,先为推荐人生成抽奖号
                $lottery_count = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "lottery where user_id = " . intval($order_info['user_id']));
                if ($lottery_count == 0 && $lottery_user['pid'] != 0) {
                    $lottery_puser = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . intval($lottery_user['pid']));
                    foreach ($lottery_list as $lottery) {
                        $k = 0;
                        do {
                            if ($k > 10) {
                                break;
                            }
                            $buy_count = $GLOBALS['db']->getOne("select buy_count from " . DB_PREFIX . "deal where id = " . $lottery['did']);
                            $max_sn = $buy_count - $lottery['number'] + intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "lottery where deal_id = " . intval($lottery['did']) . " and buyer_id <> 0 "));
                            //$max_sn = intval($GLOBALS['db']->getOne("select lottery_sn from ".DB_PREFIX."lottery where deal_id = '".$lottery['did']."' order by lottery_sn desc limit 1"));
                            $sn = $max_sn + 1;
                            $sn = str_pad($sn, "6", "0", STR_PAD_LEFT);
                            $sql = "insert into " . DB_PREFIX . "lottery (`lottery_sn`,`deal_id`,`user_id`,`mobile`,`create_time`,`buyer_id`) select '" . $sn . "','" . $lottery['did'] . "'," . $lottery_puser['id'] . ",'" . $lottery_puser['lottery_mobile'] . "'," . NOW_TIME . "," . $order_info['user_id'] . " from dual where not exists( select * from " . DB_PREFIX . "lottery where deal_id = " . $lottery['did'] . " and lottery_sn = '" . $sn . "')";
                            $GLOBALS['db']->query($sql);
                            send_lottery_sms(intval($GLOBALS['db']->insert_id()));
                            $k++;
                        } while (intval($GLOBALS['db']->insert_id()) == 0);
                    }
                }
                foreach ($lottery_list as $lottery) {
                    for ($i = 0; $i < $lottery['number']; $i++) {
                        $k = 0;
                        do {
                            if ($k > 10) {
                                break;
                            }
                            $buy_count = $GLOBALS['db']->getOne("select buy_count from " . DB_PREFIX . "deal where id = " . $lottery['did']);
                            $max_sn = $buy_count - $lottery['number'] + intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "lottery where deal_id = " . intval($lottery['did']) . " and buyer_id <> 0 "));
                            //$max_sn = intval($GLOBALS['db']->getOne("select lottery_sn from ".DB_PREFIX."lottery where deal_id = '".$lottery['did']."' order by lottery_sn desc limit 1"));
                            $sn = $max_sn + $i + 1;
                            $sn = str_pad($sn, "6", "0", STR_PAD_LEFT);
                            $sql = "insert into " . DB_PREFIX . "lottery (`lottery_sn`,`deal_id`,`user_id`,`mobile`,`create_time`,`buyer_id`) select '" . $sn . "','" . $lottery['did'] . "'," . $order_info['user_id'] . ",'" . $lottery_user['mobile'] . "'," . NOW_TIME . ",0 from dual where not exists( select * from " . DB_PREFIX . "lottery where deal_id = " . $lottery['did'] . " and lottery_sn = '" . $sn . "')";
                            $GLOBALS['db']->query($sql);
                            send_lottery_sms(intval($GLOBALS['db']->insert_id()));
                            $k++;
                        } while (intval($GLOBALS['db']->insert_id()) == 0);
                    }
                }
                send_msg($order_info['user_id'], "订单" . $order_info['order_sn'] . "付款成功", "orderitem", $order_goods_list[0]['id']);
            }
        } else {
            //开始模拟事务回滚
            foreach ($affect_attr_list as $k => $v) {
                $sql = "update " . DB_PREFIX . "attr_stock set buy_count = buy_count - " . $v['number'] . " where deal_id = " . $v['deal_id'] . " and locate(attr_str,'" . $v['attr_str'] . "') > 0 ";
                $GLOBALS['db']->query($sql);
                //回滚已发的货量
            }
            foreach ($affect_list as $k => $v) {
                $sql = "update " . DB_PREFIX . "deal set buy_count = buy_count - " . $v['num'] . ",user_count = user_count - 1 where id=" . $v['deal_id'];
                $GLOBALS['db']->query($sql);
                //回滚已发的货量
            }
            $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set refund_status = 2 where order_id = " . $order_info['id']);
            //超出充值
            require_once APP_ROOT_PATH . "system/model/user.php";
            $msg = sprintf($GLOBALS['lang']['OUTOFSTOCK_INCHARGE'], $order_info['order_sn']);
            modify_account(array('money' => $order_info['total_price'], 'score' => 0), $order_info['user_id'], $msg);
            order_log($order_info['order_sn'] . "订单库存不足," . format_price($order_info['total_price']) . "已退到会员余额", $order_info['id']);
            modify_statements("-" . $order_info['total_price'], 1, $order_info['order_sn'] . "订单库存不足");
            modify_statements($order_info['total_price'], 2, $order_info['order_sn'] . "订单库存不足");
            //将订单的extra_status 状态更新为2,并自动退款
            $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set extra_status = 2, after_sale = 1, refund_money = pay_amount where id = " . intval($order_info['id']));
            update_order_cache($order_info['id']);
            //记录退款的订单日志
            $log['log_info'] = $msg;
            $log['log_time'] = NOW_TIME;
            $log['order_id'] = intval($order_info['id']);
            $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_order_log", $log);
        }
        //同步所有未过期的团购状态
        foreach ($goods_list as $item) {
            syn_deal_status($item['deal_id'], true);
        }
        auto_over_status($order_id);
        //自动结单
    } else {
        //订单充值
        // 		$GLOBALS['db']->query("update ".DB_PREFIX."deal_order set order_status = 1 where id = ".$order_info['id']); //充值单自动结单
        require_once APP_ROOT_PATH . "system/model/user.php";
        $msg = sprintf($GLOBALS['lang']['USER_INCHARGE_DONE'], $order_info['order_sn']);
        modify_account(array('money' => $order_info['total_price'] - $order_info['payment_fee'], 'score' => 0), $order_info['user_id'], $msg);
        modify_statements("-" . $order_info['total_price'], 1, $order_info['order_sn'] . "会员充值");
        modify_statements($order_info['total_price'], 2, $order_info['order_sn'] . "会员充值,含手续费");
        send_msg($order_info['user_id'], "成功充值" . format_price($order_info['total_price'] - $order_info['payment_fee']), "notify", $order_id);
        auto_over_status($order_id);
        //自动结单
    }
}
Пример #8
0
 public function index()
 {
     $id = intval($GLOBALS['request']['id']);
     if ($id == '') {
         $root['status'] = 0;
         $root['info'] = '订单号不能为空';
     }
     /*设置发货开始*/
     $silent = intval($_REQUEST['silent']);
     $order_id = $id;
     $order_items = $GLOBALS['db']->getAll("select id from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id);
     foreach ($order_items as $k => $v) {
         $order_deals[] = $v['id'];
     }
     $delivery_sn = $_REQUEST['delivery_sn'];
     $express_id = intval($_REQUEST['express_id']);
     $memo = $_REQUEST['memo'];
     if (!$order_deals) {
     } else {
         $deal_names = array();
         foreach ($order_deals as $order_deal_id) {
             $deal_info = $GLOBALS['db']->getRow("select d.*,doi.id as doiid from " . DB_PREFIX . "deal as d left join " . DB_PREFIX . "deal_order_item as doi on doi.deal_id = d.id where doi.id = " . $order_deal_id);
             $deal_name = $deal_info['sub_name'];
             array_push($deal_names, $deal_name);
             $rs = make_delivery_notice($order_id, $order_deal_id, $delivery_sn, $memo, $express_id);
             if ($rs) {
                 $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set delivery_status = 1,is_arrival = 0 where id = " . $order_deal_id);
                 update_balance($order_deal_id, $deal_info['id']);
             }
         }
         $deal_names = implode(",", $deal_names);
         //开始同步订单的发货状态
         $order_deal_items = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id);
         foreach ($order_deal_items as $k => $v) {
             if ($GLOBALS['db']->getOne("select is_delivery from " . DB_PREFIX . "Deal where id = " . $v['deal_id']) == 0) {
                 unset($order_deal_items[$k]);
             }
         }
         $delivery_deal_items = $order_deal_items;
         foreach ($delivery_deal_items as $k => $v) {
             if ($v['delivery_status'] == 0) {
                 unset($delivery_deal_items[$k]);
             }
         }
         if (count($delivery_deal_items) == 0 && count($order_deal_items) != 0) {
             $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set delivery_status = 0 where id = " . $order_id);
             //未发货
         } elseif (count($delivery_deal_items) > 0 && count($order_deal_items) != 0 && count($delivery_deal_items) < count($order_deal_items)) {
             $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set delivery_status = 1 where id = " . $order_id);
             //部分发
         } else {
             $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set delivery_status = 2 where id = " . $order_id);
             //全部发
         }
         $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set update_time = " . time() . ",is_refuse_delivery=0 where id = " . $order_id);
         //全部发
         $refund_item_count = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal_order_item where (refund_status = 1 or is_arrival = 2) and order_id = " . $order_id);
         $coupon_item_count = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal_coupon where refund_status = 1 and order_id = " . $order_id);
         if ($refund_item_count == 0 && $coupon_item_count == 0) {
             $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set refund_status = 0,is_refuse_delivery=0 where id = " . $order_id);
         }
         //查询快递名
         $express_name = $GLOBALS['db']->getAll("select name from " . DB_PREFIX . "Express where id = " . $express_id);
         require_once APP_ROOT_PATH . "system/model/deal_order.php";
         order_log("发货成功" . $express_name . $delivery_sn . $_REQUEST['memo'], $order_id);
         update_order_cache($order_id);
         distribute_order($order_id);
     }
     /*设置发货结束*/
     $result = $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_order", array("service_start_time" => time()), "UPDATE", "id=" . intval($id));
     // 更新服务时间为当前时间
     if ($result) {
         $root['status'] = 1;
         $root['info'] = '服务开始';
     }
     output($root);
 }
Пример #9
0
 public function do_delivery()
 {
     $s_account_info = $GLOBALS['account_info'];
     $supplier_id = intval($s_account_info['supplier_id']);
     require_once APP_ROOT_PATH . "system/model/deal_order.php";
     $order_item_table_name = get_supplier_order_item_table_name($supplier_id);
     $order_table_name = get_supplier_order_table_name($supplier_id);
     $id = intval($_REQUEST['id']);
     //发货商品的ID
     $delivery_sn = strim($_REQUEST['delivery_sn']);
     $memo = strim($_REQUEST['memo']);
     $express_id = intval($_REQUEST['express_id']);
     $location_id = intval($_REQUEST['location_id']);
     $order_id = $GLOBALS['db']->getOne("select order_id from " . $order_item_table_name . " where id = " . $id);
     $order_info = $GLOBALS['db']->getRow("select * from " . $order_table_name . " where id = '" . $order_id . "'");
     if (empty($delivery_sn)) {
         $data['status'] = 0;
         $data['info'] = "请输入快递单号";
         ajax_return($data);
     }
     $item = $GLOBALS['db']->getRow("select doi.* from " . $order_item_table_name . " as doi left join " . DB_PREFIX . "deal_location_link as l on doi.deal_id = l.deal_id where doi.id = " . $id . " and l.location_id in (" . implode(",", $s_account_info['location_ids']) . ")");
     if ($item) {
         $rs = make_delivery_notice($order_id, $id, $delivery_sn, $memo, $express_id, $location_id);
         if ($rs) {
             $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set delivery_status = 1 where id = " . $id);
         }
         send_delivery_mail($delivery_sn, $item['name'], $order_id);
         send_delivery_sms($delivery_sn, $item['name'], $order_id);
         //开始同步订单的发货状态
         $order_deal_items = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_order_item where order_id = " . $order_id);
         foreach ($order_deal_items as $k => $v) {
             if ($v['delivery_status'] == 5) {
                 unset($order_deal_items[$k]);
             }
         }
         $delivery_deal_items = $order_deal_items;
         foreach ($delivery_deal_items as $k => $v) {
             if ($v['delivery_status'] == 0) {
                 unset($delivery_deal_items[$k]);
             }
         }
         if (count($delivery_deal_items) == 0 && count($order_deal_items) != 0) {
             $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set delivery_status = 0,update_time = '" . NOW_TIME . "' where id = " . $order_id);
             //未发货
         } elseif (count($delivery_deal_items) > 0 && count($order_deal_items) != 0 && count($delivery_deal_items) < count($order_deal_items)) {
             $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set delivery_status = 1,update_time = '" . NOW_TIME . "' where id = " . $order_id);
             //部分发
         } else {
             $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set delivery_status = 2,update_time = '" . NOW_TIME . "' where id = " . $order_id);
             //全部发
         }
         order_log($item['name'] . "发货了,发货单号:" . $delivery_sn, $order_id);
         update_order_cache($order_id);
         distribute_order($order_id);
         send_msg($order_info['user_id'], $item['name'] . "发货了,发货单号:" . $delivery_sn, "orderitem", $item['id']);
         $data['status'] = 1;
         $data['info'] = "发货成功";
         ajax_return($data);
     } else {
         $data['status'] = 0;
         $data['info'] = "非法的数据";
         ajax_return($data);
     }
 }
Пример #10
0
 /**
  * 退款申请
  */
 public function do_refund()
 {
     global_run();
     if (check_save_login() != LOGIN_STATUS_LOGINED) {
         $data['status'] = 1000;
         ajax_return($data);
     } else {
         $did = intval($_REQUEST['did']);
         $cid = intval($_REQUEST['cid']);
         $content = strim($_REQUEST['content']);
         if (empty($content)) {
             $data['status'] = 0;
             $data['info'] = "请填写退款原因";
             ajax_return($data);
         }
         if ($did) {
             //退单
             $deal_order_item = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order_item where id = " . $did);
             $order_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order where id = '" . $deal_order_item['order_id'] . "' and order_status = 0 and user_id = " . $GLOBALS['user_info']['id']);
             if ($order_info) {
                 if ($deal_order_item['delivery_status'] == 0 && $order_info['pay_status'] == 2 && $deal_order_item['is_refund'] == 1) {
                     if ($deal_order_item['refund_status'] == 0) {
                         //执行退单,标记:deal_order_item表与deal_order表,
                         $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set refund_status = 1 where id = " . $deal_order_item['id']);
                         $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set refund_status = 1 where id = " . $deal_order_item['order_id']);
                         $msg = array();
                         $msg['rel_table'] = "deal_order";
                         $msg['rel_id'] = $deal_order_item['order_id'];
                         $msg['title'] = "退款申请";
                         $msg['content'] = "退款申请:" . $content;
                         $msg['create_time'] = NOW_TIME;
                         $msg['user_id'] = $GLOBALS['user_info']['id'];
                         $GLOBALS['db']->autoExecute(DB_PREFIX . "message", $msg);
                         update_order_cache($deal_order_item['order_id']);
                         order_log($deal_order_item['sub_name'] . "申请退款,等待审核", $deal_order_item['order_id']);
                         require_once APP_ROOT_PATH . "system/model/deal_order.php";
                         distribute_order($order_info['id']);
                         $data['status'] = true;
                         $data['info'] = "退款申请已提交,请等待审核";
                         ajax_return($data);
                     } else {
                         $data['status'] = 0;
                         $data['info'] = "不允许退款";
                         ajax_return($data);
                     }
                 } else {
                     $data['status'] = 0;
                     $data['info'] = "非法操作";
                     ajax_return($data);
                 }
             } else {
                 $data['status'] = 0;
                 $data['info'] = "非法操作";
                 ajax_return($data);
             }
         } elseif ($cid) {
             //退券
             $coupon = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_coupon where user_id = " . $GLOBALS['user_info']['id'] . " and id = " . $cid);
             if ($coupon) {
                 if ($coupon['refund_status'] == 0 && $coupon['confirm_time'] == 0) {
                     if ($coupon['any_refund'] == 1 || $coupon['expire_refund'] == 1 && $coupon['end_time'] > 0 && $coupon['end_time'] < NOW_TIME) {
                         //执行退券
                         $GLOBALS['db']->query("update " . DB_PREFIX . "deal_coupon set refund_status = 1 where id = " . $coupon['id']);
                         $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order_item set refund_status = 1 where id = " . $coupon['order_deal_id']);
                         $GLOBALS['db']->query("update " . DB_PREFIX . "deal_order set refund_status = 1 where id = " . $coupon['order_id']);
                         $deal_order_item = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_order_item where id = " . $coupon['order_deal_id']);
                         $msg = array();
                         $msg['rel_table'] = "deal_order";
                         $msg['rel_id'] = $coupon['order_id'];
                         $msg['title'] = "退款申请";
                         $msg['content'] = $content;
                         $msg['create_time'] = NOW_TIME;
                         $msg['user_id'] = $GLOBALS['user_info']['id'];
                         $GLOBALS['db']->autoExecute(DB_PREFIX . "message", $msg);
                         update_order_cache($coupon['order_id']);
                         order_log($deal_order_item['sub_name'] . "申请退一张团购券,等待审核", $coupon['order_id']);
                         require_once APP_ROOT_PATH . "system/model/deal_order.php";
                         distribute_order($coupon['order_id']);
                         $data['status'] = true;
                         $data['info'] = "退款申请已提交,请等待审核";
                         ajax_return($data);
                     } else {
                         $data['status'] = 0;
                         $data['info'] = "不允许退款";
                         ajax_return($data);
                     }
                 } else {
                     $data['status'] = 0;
                     $data['info'] = "非法操作";
                     ajax_return($data);
                 }
             } else {
                 $data['status'] = 0;
                 $data['info'] = "非法操作";
                 ajax_return($data);
             }
         } else {
             $data['status'] = 0;
             $data['info'] = "非法操作";
             ajax_return($data);
         }
     }
 }