public function point_exchange() { $id = Filter::int(Req::args('id')); $voucher = $this->model->table("voucher_template")->where("id={$id}")->find(); if ($voucher) { $use_point = 0 - $voucher['point']; $result = Pointlog::write($this->user['id'], $use_point, '积分兑换代金券,扣除了' . $use_point . '积分'); if (true === $result) { Common::paymentVoucher($voucher, $this->user['id']); $info = array('status' => 'success'); } else { $info = array('status' => 'fail', 'msg' => $result['msg']); } echo JSON::encode($info); } else { $info = array('status' => 'fail', 'msg' => '你要兑换的代金券,不存在!'); echo JSON::encode($info); } }
public static function updateStatus($orderNo, $payment_id = 0, $callback_info = null) { //SKM-ORDER-STATUS 这个方法得大改 $model = new Model("order"); $order = $model->where("order_no='" . $orderNo . "'")->find(); if (isset($callback_info['trade_no'])) { $trading_info = $callback_info['trade_no']; } else { $trading_info = ''; } if (empty($order)) { return false; } if ($order['pay_status'] == 1) { return $order['id']; } else { if ($order['pay_status'] == 0) { //更新订单信息 $data = array('status' => 3, 'pay_time' => date('Y-m-d H:i:s'), 'trading_info' => $trading_info, 'pay_status' => 1); //修改用户最后选择的支付方式 if ($payment_id != 0) { $data['payment'] = $payment_id; } else { $payment_id = $order['payment']; } //更新订单支付状态 $model->table("order")->data($data)->where("id=" . $order['id'])->update(); //SKM-SMS 支付成功 发送支付完成信息 $sms_inst = new Sms(); $orderNo = $order['order_no']; $text = "【全品电台】感谢您使用全品电台。您的订单 {$orderNo} 已经支付成功,我们将会在24小时内给您发货。"; $mobile = $order['mobile']; if ($mobile != "") { // 测试时 不发送SMS $sms_inst->sendSms($text, $mobile); } /* S 二次开发 */ //发送邮件 $order_url = Url::fullUrlFormat("/ucenter/order_detail/id/{$order['id']}"); $safebox = Safebox::getInstance(); $user = $safebox->get('user'); $email_message_model = new Model('email_message'); $email_message = $email_message_model->where('`trigger`=2 and status=1')->find(); if ($email_message) { $body = str_replace(array('{$order_no}', '{$user_name}', '{$current_time}', '{$order_url}'), array($orderNo, $user['name'], date('Y-m-d H:i:s'), $order_url), $email_message['content']); $mail = new Mail(); $mail->send_email($user['email'], $email_message['title'], $body); } /* E 二次开发 */ //商品中优惠券的处理 $products = $model->table("order_goods")->where("order_id=" . $order['id'])->findAll(); $goods_ids = array(); foreach ($products as $pro) { //SKM-ORDER-STATUS 添加捆绑促销的处理 if ($pro['prom_type'] == 'bundling') { // 添加 } else { $prom = unserialize($pro['prom_goods']); if (isset($prom['prom'])) { $prom_series = isset($prom['series']['prom']) ? $prom['series']['prom'] : null; $prom = $prom['prom']; //商品中优惠券的处理 if (isset($prom['type']) && $prom['type'] == 3 && $order['type'] == 0) { $voucher_template_id = $prom['expression']; $voucher_template = $model->table("voucher_template")->where("id=" . $voucher_template_id)->find(); Common::paymentVoucher($voucher_template, $order['user_id']); //优惠券发放日志 } //二次开发部分 //系列中的优惠券 if (isset($prom_series['type']) && $prom_series['type'] == 3 && $order['type'] == 0) { $voucher_template_id = $prom_series['expression']; $voucher_template = $model->table("voucher_template")->where("id=" . $voucher_template_id)->find(); Common::paymentVoucher($voucher_template, $order['user_id']); //优惠券发放日志 } } //更新货品中的库存信息 $goods_nums = $pro['goods_nums']; $product_id = $pro['product_id']; $model->table("products")->where("id=" . $product_id)->data(array('store_nums' => "`store_nums`-" . $goods_nums))->update(); $goods_ids[$pro['goods_id']] = $pro['goods_id']; } } //更新商品表里的库存信息 foreach ($goods_ids as $id) { $objs = $model->table('products')->fields('sum(store_nums) as store_nums')->where('goods_id=' . $id)->query(); if ($objs) { $num = $objs[0]['store_nums']; $model->table('goods')->data(array('store_nums' => $num))->where('id=' . $id)->update(); } } //普通订单的处理 foreach ($products as $pro) { //SKM-ORDER-STATUS 添加捆绑促销的处理 if ($pro['prom_type'] == 'bundling') { } else { if ($order['type'] == 0) { //订单优惠券活动事后处理 $prom = unserialize($order['prom']); if (!empty($prom) && $prom['type'] == 3) { $voucher_template_id = $prom['expression']; $voucher_template = $model->table("voucher_template")->where("id=" . $voucher_template_id)->find(); Common::paymentVoucher($voucher_template, $order['user_id']); } } else { if ($order['type'] == 1) { //更新团购信息 $prom = unserialize($order['prom']); if (isset($prom['id'])) { $groupbuy = $model->table("groupbuy")->where("id=" . $prom['id'])->find(); if ($groupbuy) { $goods_num = $groupbuy['goods_num']; $order_num = $groupbuy['order_num']; $max_num = $groupbuy['max_num']; $end_time = $groupbuy['end_time']; $time_diff = time() - strtotime($end_time); foreach ($products as $pro) { $data = array('goods_num' => $goods_num + $pro['goods_nums'], 'order_num' => $order_num + 1); } if ($time_diff >= 0 || $max_num <= $data['goods_num']) { $data['is_end'] = 1; } $model->table("groupbuy")->where("id=" . $prom['id'])->data($data)->update(); } } } else { if ($order['type'] == 2) { //更新抢购信息 $prom = unserialize($order['prom']); if (isset($prom['id'])) { $flashbuy = $model->table("flash_sale")->where("id=" . $prom['id'])->find(); if ($flashbuy) { $goods_num = $flashbuy['goods_num']; $order_num = $flashbuy['order_num']; $max_num = $flashbuy['max_num']; $end_time = $flashbuy['end_time']; $time_diff = time() - strtotime($end_time); foreach ($products as $pro) { $data = array('goods_num' => $goods_num + $pro['goods_nums'], 'order_num' => $order_num + 1); } if ($time_diff >= 0 || $max_num <= $data['goods_num']) { $data['is_end'] = 1; } $model->table("flash_sale")->where("id=" . $prom['id'])->data($data)->update(); } } } } } } } //送积分 Pointlog::write($order['user_id'], $order['point'], '购买商品,订单:' . $order['order_no'] . ' 赠送' . $order['point'] . '积分'); //对使用代金券的订单,修改代金券的状态 if ($order['voucher_id']) { $model->table("voucher")->where("id=" . $order['voucher_id'])->data(array('status' => 1))->update(); } //生成收款单 $receivingData = array('order_id' => $order['id'], 'user_id' => $order['user_id'], 'amount' => $order['order_amount'], 'create_time' => date('Y-m-d H:i:s'), 'payment_time' => date('Y-m-d H:i:s'), 'doc_type' => 0, 'payment_id' => $payment_id, 'pay_status' => 1); $model->table("doc_receiving")->data($receivingData)->insert(); //统计会员规定时间内的消费金额,进行会员升级。 $config = Config::getInstance(); $config_other = $config->get('other'); $grade_days = isset($config_other['other_grade_days']) ? intval($config_other['other_grade_days']) : 365; $time = date("Y-m-d H:i:s", strtotime("-" . $grade_days . " day")); $obj = $model->table("doc_receiving")->fields("sum(amount) as amount")->where("user_id=" . $order['user_id'] . " and doc_type=0 and payment_time > '{$time}'")->query(); if (isset($obj[0])) { $amount = $obj[0]['amount']; $grade = $model->table('grade')->where('money < ' . $amount)->order('money desc')->find(); if ($grade) { $model->table('customer')->data(array('group_id' => $grade['id']))->where("user_id=" . $order['user_id'])->update(); } } return $order['id']; } else { return false; } } }