$this->createOrderNum(), 'config_id' => $data['config_id'], 'info_id' => $data['info_id'], 'card_id' => $data['card_id'], 'uid' => $data['uid'], 'username' => $data['username'], 'name' => $data['name'], 'cash' => $data['cash'], 'price' => $data['price'], 'yue' => $data['yue'], ]; $order['id'] = Dever::db('account/pay')->insert($order); if ($order['id']) { # 需要支付 if ($data['pay_channel_id']) { $this->channel_id = $data['pay_channel_id']; } if ($data['pay_project_id']) { $this->project_id = $data['pay_project_id']; } if ($order['price'] > 0) { return $this->yes($order); } else { return $this->no($order); } } Dever::alert('支付失败'); } # 生成订单号 private function createOrderNum() { $where['order_num'] = Dever::order('P'); $state = Dever::db('account/pay')->one($where); if (!$state) { return $where['order_num']; } else { return $this->createOrderNum(); } } # 支付 private function yes($order) { $openid = Dever::load('user/lib/applet')->getOpenid($order['uid'], $this->system_source, $this->project_id); $param = array( 'project_id' => $this->project_id, 'channel_id' => $this->channel_id, 'system_source' => $this->system_source, 'uid' => $order['uid'], 'username' => isset($order['username']) ? $order['username'] : '', 'name' => $order['name'], 'cash' => $order['price'], 'product_id' => $order['id'], 'order_id' => $order['order_num'], 'openid' => $openid, ); $data = Dever::load('pay/api.pay', $param); $data['order_cash'] = Dever::number($order['cash']); $data['order_yue'] = Dever::number($order['yue']); $data['order_num'] = $order['order_num']; $data['order_id'] = $order['id']; return $data; } # 无需支付 private function no($order) { $param['pay_product_id'] = $order['id']; $param['pay_order_id'] = $order['order_num']; $param['pay_status'] = 2; $param['pay_cash'] = $order['price']; $param['pay_msg'] = ''; $this->success($param); return array( 'order' => '', 'order_cash' => Dever::number($order['cash']), 'order_yue' => Dever::number($order['yue']), 'order_num' => $order['order_num'], 'order_id' => $order['id'], 'type' => 'test', ); } # 支付成功回调 安全加密 设置token public function success_secure_api_token() { $project_id = Dever::input('pay_project_id'); $info = Dever::db('pay/project')->one($project_id); if ($info) { return $info['key']; } return 'account_dever'; } # 支付成功回调 安全加密 public function success_secure_api($param = array()) { $this->success($param); } # 支付成功回调 public function success($param = array()) { $send = $param ? $param : Dever::preInput('pay_'); $product_id = $send['pay_product_id']; $order_id = $send['pay_order_id']; $status = $send['pay_status']; $cash = $send['pay_cash']; $msg = $send['pay_msg']; $order = Dever::db('account/pay')->one(array('id' => $product_id, 'clear' => true)); if ($order && $order['status'] == 1) { $update = array(); if ($status == 2) { $update['status'] = $status; $update['where_id'] = $order['id']; Dever::db('account/pay')->update($update); $desc = '支付充值'; Dever::load('account/lib/info.up_commit', $order['uid'], $order['cash'], 'chongzhi', 'qianbao', $desc, 'account/pay', $order['id']); if (Dever::project('wechat_applet')) { //Dever::load('order/lib/applet')->add($order['id'], 2); } # 发消息 if ($order['uid'] && $order['uid'] > 0) { $this->payNotice($order); } } } return 'ok'; } public function payNotice($order) { if ($order['card_id'] > 0 && Dever::project('duihuan')) { Dever::load('duihuan/lib/give')->act($order['uid'], 1, $order['card_id'], $order['order_num']); } } }