/** * 发送提货码短信消息 */ public function sendPickupcode($param) { $dorder_info = Model('delivery_order')->getDeliveryOrderInfo(array('order_id' => $param['order_id']), 'reciver_mobphone'); $tpl_info = Model('mail_templates')->getTplInfo(array('code' => 'send_pickup_code')); $data = array(); $data['site_name'] = C('site_name'); $data['pickup_code'] = $param['pickup_code']; $message = uk86_ncReplaceText($tpl_info['content'], $data); $sms = new Uk86Sms(); $result = $sms->uk86_send($dorder_info['reciver_mobphone'], $message); if (!$result) { return uk86_callback(false, '发送提货码短信消息失败order_id:' . $param['order_id']); } else { return uk86_callback(true); } }
/** * 系统收到货款 * @throws Exception */ private function _order_receive_pay($order_info, $post) { $order_id = $order_info['order_id']; $model_order = Model('order'); $logic_order = uk86_Logic('order'); $if_allow = $model_order->getOrderOperateState('system_receive_pay', $order_info); if (!$if_allow) { return uk86_callback(false, '无权操作'); } if (!uk86_chksubmit()) { Tpl::output('order_info', $order_info); //显示支付接口列表 $payment_list = Model('payment')->getPaymentOpenList(); //去掉预存款和货到付款 foreach ($payment_list as $key => $value) { if ($value['payment_code'] == 'predeposit' || $value['payment_code'] == 'offline') { unset($payment_list[$key]); } } Tpl::output('payment_list', $payment_list); Tpl::showpage('order.receive_pay'); exit; } $order_list = $model_order->getOrderList(array('pay_sn' => $order_info['pay_sn'], 'order_state' => ORDER_STATE_NEW)); $result = $logic_order->changeOrderReceivePay($order_list, 'system', $this->admin_info['name'], $post); if ($result['state']) { $this->log('将订单改为已收款状态,' . L('order_number') . ':' . $order_info['order_sn'], 1); } return $result; }
/** * 验证F码 * @param int $goods_commonid * @param string $fcode * @return array */ public function checkFcode($goods_commonid, $fcode) { $fcode_info = Model('goods_fcode')->getGoodsFCode(array('goods_commonid' => $goods_commonid, 'fc_code' => $fcode, 'fc_state' => 0)); if ($fcode_info) { return uk86_callback(true, '', $fcode_info); } else { return uk86_callback(false, 'F码错误'); } }
/** * 完成订单 * @param int $order_id * @return array */ public function changeOrderStateSuccess($order_id) { $model_vr_order = Model('vr_order'); $condition = array(); $condition['vr_state'] = 0; $condition['refund_lock'] = array('in', array(0, 1)); $condition['order_id'] = $order_id; $condition['vr_indate'] = array('gt', TIMESTAMP); $order_code_info = $model_vr_order->getOrderCodeInfo($condition, '*', true); if (empty($order_code_info)) { $update = $model_vr_order->editOrder(array('order_state' => ORDER_STATE_SUCCESS, 'finnshed_time' => TIMESTAMP), array('order_id' => $order_id)); if (!$update) { uk86_callback(false, '更新失败'); } } $order_info = $model_vr_order->getOrderInfo(array('order_id' => $order_id)); //添加会员U币 if (C('points_isuse') == 1) { Model('points')->savePointsLog('order', array('pl_memberid' => $order_info['buyer_id'], 'pl_membername' => $order_info['buyer_name'], 'orderprice' => $order_info['order_amount'], 'order_sn' => $order_info['order_sn'], 'order_id' => $order_info['order_id']), true); } //添加会员经验值 Model('exppoints')->saveExppointsLog('order', array('exp_memberid' => $order_info['buyer_id'], 'exp_membername' => $order_info['buyer_name'], 'orderprice' => $order_info['order_amount'], 'order_sn' => $order_info['order_sn'], 'order_id' => $order_info['order_id']), true); return uk86_callback(true, '更新成功'); }
/** * 取消订单 * @param arrty $order_info * @param arrty $post * @throws Exception */ private function _order_cancel($order_info, $post) { if (!uk86_chksubmit()) { Tpl::output('order_id', $order_info['order_id']); Tpl::output('order_info', $order_info); Tpl::showpage('store_vr_order.cancel', 'null_layout'); exit; } else { $model_vr_order = Model('vr_order'); $logic_vr_order = uk86_Logic('vr_order'); $if_allow = $model_vr_order->getOrderOperateState('store_cancel', $order_info); if (!$if_allow) { return uk86_callback(false, '无权操作'); } $msg = $post['state_info1'] != '' ? $post['state_info1'] : $post['state_info']; return $logic_vr_order->changeOrderStateCancel($order_info, 'seller', $msg); } }
/** * 系统收到货款 * @param unknown $order_info * @throws Exception */ private function _order_receive_pay($order_info, $post) { $model_pm_order = Model('pm_order'); $logic_pm_order = uk86_Logic('pm_order'); $if_allow = $model_pm_order->getOrderOperateState('system_receive_pay', $order_info); if (!$if_allow) { return uk86_callback(false, '无权操作'); } if (!uk86_chksubmit()) { Tpl::output('order_info', $order_info); //显示支付接口 $payment_list = Model('payment')->getPaymentOpenList(); //去掉预存款和货到付款 foreach ($payment_list as $key => $value) { if ($value['payment_code'] == 'predeposit' || $value['payment_code'] == 'offline') { unset($payment_list[$key]); } } Tpl::output('payment_list', $payment_list); Tpl::showpage('order.receive_pay'); exit; } else { $this->log('将虚拟订单改为已收款状态,' . L('order_number') . ':' . $order_info['order_sn'], 1); return $logic_pm_order->changeOrderStatePay($order_info, 'system', $post); } }
/** * 删除订单 */ private function _order_recycle($order_info, $get) { $model_order = Model('order'); $logic_order = uk86_Logic('order'); $state_type = str_replace(array('order_delete', 'order_drop', 'order_restore'), array('delete', 'drop', 'restore'), $_GET['state_type']); $if_allow = $model_order->getOrderOperateState($state_type, $order_info); if (!$if_allow) { return uk86_callback(false, '无权操作'); } return $logic_order->changeOrderStateRecycle($order_info, 'buyer', $state_type); }
/** * 收到货款 * @param array $order_info * @param string $role 操作角色 buyer、seller、admin、system 分别代表买家、商家、管理员、系统 * @param string $user 操作人 * @return array */ public function changeOrderReceivePay($order_list, $role, $user = '', $post = array()) { $model_order = Model('order'); try { $model_order->beginTransaction(); $data = array(); $data['api_pay_state'] = 1; // ukshop $update = $model_order->editOrderPay($data, array('pay_sn' => $order_list[0]['pay_sn'])); //$update = $model_order->editOrderPay($data,array('pay_sn'=>$order_info['pay_sn'])); if (!$update) { throw new Exception('更新支付单状态失败'); } $model_pd = Model('predeposit'); foreach ($order_list as $order_info) { $order_id = $order_info['order_id']; if ($order_info['order_state'] != ORDER_STATE_NEW) { continue; } //下单,支付被冻结的充值卡 $rcb_amount = floatval($order_info['rcb_amount']); if ($rcb_amount > 0) { $data_pd = array(); $data_pd['member_id'] = $order_info['buyer_id']; $data_pd['member_name'] = $order_info['buyer_name']; $data_pd['amount'] = $rcb_amount; $data_pd['order_sn'] = $order_info['order_sn']; $model_pd->changeRcb('order_comb_pay', $data_pd); } //下单,支付被冻结的预存款 $pd_amount = floatval($order_info['pd_amount']); if ($pd_amount > 0) { $data_pd = array(); $data_pd['member_id'] = $order_info['buyer_id']; $data_pd['member_name'] = $order_info['buyer_name']; $data_pd['amount'] = $pd_amount; $data_pd['order_sn'] = $order_info['order_sn']; $model_pd->changePd('order_comb_pay', $data_pd); } } //更新订单状态 $update_order = array(); $update_order['order_state'] = ORDER_STATE_PAY; $update_order['payment_time'] = $post['payment_time'] ? strtotime($post['payment_time']) : TIMESTAMP; $update_order['payment_code'] = $post['payment_code']; //$update_order['trade_no'] = $post['trade_no']; order表并没有trade_no字段 $update = $model_order->editOrder($update_order, array('pay_sn' => $order_info['pay_sn'], 'order_state' => ORDER_STATE_NEW)); if (!$update) { throw new Exception('操作失败'); } $model_order->commit(); } catch (Exception $e) { $model_order->rollback(); return uk86_callback(false, $e->getMessage()); } foreach ($order_list as $order_info) { //防止重复发送消息 if ($order_info['order_state'] != ORDER_STATE_NEW) { continue; } $order_id = $order_info['order_id']; // 支付成功发送买家消息 $param = array(); $param['code'] = 'order_payment_success'; $param['member_id'] = $order_info['buyer_id']; $param['param'] = array('order_sn' => $order_info['order_sn'], 'order_url' => uk86_urlShop('member_order', 'show_order', array('order_id' => $order_info['order_id']))); Uk86QueueClient::push('sendMemberMsg', $param); // 支付成功发送店铺消息 $param = array(); $param['code'] = 'new_order'; $param['store_id'] = $order_info['store_id']; $param['param'] = array('order_sn' => $order_info['order_sn']); Uk86QueueClient::push('sendStoreMsg', $param); //添加订单日志 $data = array(); $data['order_id'] = $order_id; $data['log_role'] = $role; $data['log_user'] = $user; $data['log_msg'] = '收到了货款 ( 支付平台交易号 : ' . $post['trade_no'] . ' )'; $data['log_orderstate'] = ORDER_STATE_PAY; $model_order->addOrderLog($data); } return uk86_callback(true, '操作成功'); }
/** * 创建促销的虚拟订单 * @author bzhang */ public function createPromotionVrOrder($post, $member_id) { $result = $this->getBuyStepData($post['goods_id'], $post['quantity'], $member_id); if (!$result['state']) { return $result; } // // $goods_info = $result['data']['goods_info']; // $member_info = $result['data']['member_info']; // // //应付总金额计算 // $pay_total = $goods_info['goods_price'] * $goods_info['quantity']; // $store_id = $goods_info['store_id']; // $store_goods_total_list = array($store_id => $pay_total); // $pay_total = $store_goods_total_list[$store_id]; // //会员数据 $member_info = Model('member')->getMemberInfoByID($member_id); //整理数据 $input = array(); $input['quantity'] = $post['quantity']; $input['buyer_msg'] = isset($post['buyer_msg']) ? $post['buyer_msg'] : ''; $input['pay_total'] = $post['price']; $input['order_from'] = isset($post['order_from']) ? $post['order_from'] : ''; try { $model_goods = Model('goods'); //开始事务 $model_goods->beginTransaction(); //生成订单 $order_info = $this->_createOrder($input, $goods_info, $member_info); if (!empty($post['password'])) { if ($member_info['member_paypwd'] != '' && $member_info['member_paypwd'] == md5($post['password'])) { //充值卡支付 if (!empty($post['rcb_pay'])) { $order_info = $this->_rcbPay($order_info, $post, $member_info); } //预存款支付 if (!empty($post['pd_pay'])) { $this->_pdPay($order_info, $post, $member_info); } } } //提交事务 $model_goods->commit(); } catch (Exception $e) { //回滚事务 $model_goods->rollback(); return uk86_callback(false, $e->getMessage()); } return uk86_callback(true, '', array('order_id' => $order_info['order_id'])); }
/** * 创建促销的虚拟订单 * @author bzhang,wangjiang * $type 虚拟订单类型 * $return_type info 返回order_info. */ public function createPromotionVrOrder($post, $type = '1', $member_id, $return_type = 'default') { //会员数据 $member_info = Model('member')->getMemberInfoByID($member_id); //整理数据 $input = array(); $input['quantity'] = isset($post['quantity']) ? $post['quantity'] : $post['quota_quantity']; $input['buyer_msg'] = isset($post['buyer_msg']) ? $post['buyer_msg'] : ''; $input['pay_total'] = $post['price']; $input['goods_price'] = $post['unit_price']; try { $model_goods = Model('goods'); //开始事务 $model_goods->beginTransaction(); //生成订单 $order_info = $this->_createOrder($input, $member_info, $type); if (!empty($post['password'])) { if ($member_info['member_paypwd'] != '' && $member_info['member_paypwd'] == md5($post['password'])) { //充值卡支付 if (!empty($post['rcb_pay'])) { $order_info = $this->_rcbPay($order_info, $post, $member_info); } //预存款支付 if (!empty($post['pd_pay'])) { $this->_pdPay($order_info, $post, $member_info); } } } //提交事务 $model_goods->commit(); } catch (Exception $e) { //回滚事务 $model_goods->rollback(); return uk86_callback(false, $e->getMessage()); } if ($return_type == 'default') { return uk86_callback(true, '', array('order_id' => $order_info['order_id'])); } elseif ($return_type == 'info') { return $order_info; } else { return uk86_callback(true, '', array('order_id' => $order_info['order_id'])); } }
/** * 支付成功后修改充值订单状态 * @param unknown $out_trade_no * @param unknown $trade_no * @param unknown $payment_info * @throws Exception * @return multitype:unknown */ public function updatePdOrder($out_trade_no, $trade_no, $payment_info, $recharge_info) { $condition = array(); $condition['pdr_sn'] = $recharge_info['pdr_sn']; $condition['pdr_payment_state'] = 0; $update = array(); $update['pdr_payment_state'] = 1; $update['pdr_payment_time'] = TIMESTAMP; $update['pdr_payment_code'] = $payment_info['payment_code']; $update['pdr_payment_name'] = $payment_info['payment_name']; $update['pdr_trade_sn'] = $trade_no; $model_pd = Model('predeposit'); try { $model_pd->beginTransaction(); $pdnum = $model_pd->getPdRechargeCount(array('pdr_sn' => $recharge_info['pdr_sn'], 'pdr_payment_state' => 1)); if (intval($pdnum) > 0) { throw new Exception('订单已经处理'); } //更改充值状态 $state = $model_pd->editPdRecharge($update, $condition); if (!$state) { throw new Exception('更新充值状态失败'); } //变更会员预存款 $data = array(); $data['member_id'] = $recharge_info['pdr_member_id']; $data['member_name'] = $recharge_info['pdr_member_name']; $data['amount'] = $recharge_info['pdr_amount']; $data['pdr_sn'] = $recharge_info['pdr_sn']; $model_pd->changePd('recharge', $data); $model_pd->commit(); return uk86_callback(true); } catch (Exception $e) { $model_pd->rollback(); return uk86_callback(false, $e->getMessage()); } }
/** * 修改商品价格 * @param unknown $order_info */ private function _order_spay_price($order_info, $post) { $model_order = Model('order'); $logic_order = uk86_Logic('order'); if (!uk86_chksubmit()) { Tpl::output('order_info', $order_info); Tpl::output('order_id', $order_info['order_id']); Tpl::showpage('store_order.edit_spay_price', 'null_layout'); exit; } else { $if_allow = $model_order->getOrderOperateState('spay_price', $order_info); if (!$if_allow) { return uk86_callback(false, '无权操作'); } return $logic_order->changeOrderSpayPrice($order_info, 'seller', $_SESSION['member_name'], $post['goods_amount']); } }