|
@@ -1,113 +0,0 @@
|
|
|
-<?php namespace Place\Lib;
|
|
|
-use Dever;
|
|
|
-use Place;
|
|
|
-class Order
|
|
|
-{
|
|
|
- # 下单
|
|
|
- public function pay($info, $type = 1, $app)
|
|
|
- {
|
|
|
- $prefix = strtoupper(substr($app, 0, 2));
|
|
|
- $account = Dever::input('account', 'is_string', '账户', 'wechat');
|
|
|
- $env = Dever::input('env', 'is_numeric', '运行环境', 3);
|
|
|
- $result = Dever::load('util', 'api')->openid($account, $env, Place::$uid);
|
|
|
- if (isset($result['openid'])) {
|
|
|
- Place::$user['openid'] = $result['openid'];
|
|
|
- } elseif (isset($result['link'])) {
|
|
|
- return $result;
|
|
|
- }
|
|
|
-
|
|
|
- if ($type == 3) {
|
|
|
- $price = $info['value'];
|
|
|
- } else {
|
|
|
- $price = ($info['value']/Place::$info['score_per']);
|
|
|
- }
|
|
|
-
|
|
|
- # 支付账户
|
|
|
- $account = 'pay_' . $account;
|
|
|
- # 下单
|
|
|
- $order = array
|
|
|
- (
|
|
|
- 'uid' => Place::$uid,
|
|
|
- 'openid' => Place::$user['openid'] ?? '',
|
|
|
- 'order_num' => Dever::load('util', 'api')->createNumber($prefix, 'place/order', array('type' => $type)),
|
|
|
- 'cash' => $price*100,
|
|
|
- 'name' => $info['name'],
|
|
|
- 'time_expire' => time() + 3600,
|
|
|
- );
|
|
|
- # 设置支付成功的回调信息,多个参数用|隔开
|
|
|
- $param['notify'] = 'place/order.success|' . Dever::input('p') . '|' . $order['order_num'] . '|' . $type;
|
|
|
- $data['pay'] = Dever::load('account', 'api')->run($account, 'order', $order, $env);
|
|
|
- if ($data['pay']) {
|
|
|
- $order['status'] = 1;
|
|
|
- $order['type'] = $type;
|
|
|
- $order['type_id'] = $info['id'];
|
|
|
- $data['order_id'] = Dever::db('order', 'place')->insert($order);
|
|
|
- $data['order_num'] = $order['order_num'];
|
|
|
- if (isset($info['detail'])) {
|
|
|
- $detail['type'] = $type;
|
|
|
- foreach ($info['detail'] as $k => $v) {
|
|
|
- $detail['type_id'] = $v['id'];
|
|
|
- if (isset($v['sku_id'])) {
|
|
|
- $detail['sku_id'] = $v['sku_id'];
|
|
|
- }
|
|
|
- if (isset($v['sku_name'])) {
|
|
|
- $detail['sku_name'] = $v['sku_name'];
|
|
|
- }
|
|
|
- $detail['order_id'] = $data['order_id'];
|
|
|
- $detail['cash'] = $v['cash'];
|
|
|
- $detail['num'] = $v['num'];
|
|
|
- $detail['name'] = $v['name'];
|
|
|
- $detail['pic'] = $v['pic'];
|
|
|
- Dever::db('order_detail', 'place')->insert($detail);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return $data;
|
|
|
- }
|
|
|
-
|
|
|
- # 支付成功
|
|
|
- public function success($place, $order_num, $type, $status, $body = array())
|
|
|
- {
|
|
|
- Dever::input('authorization', 'is_string', '入口码', $place);
|
|
|
- $order = Dever::db('order', 'place')->find(array('type' => $type, 'order_num' => $order_num));
|
|
|
- if ($order && $order['status'] == 1) {
|
|
|
- if ($type == 3) {
|
|
|
- if ($status == 1) {
|
|
|
- $update['status'] = 5;
|
|
|
- } else {
|
|
|
- $update['status'] = 7;
|
|
|
- }
|
|
|
- } else {
|
|
|
- if ($status == 1) {
|
|
|
- $update['status'] = 2;
|
|
|
- } else {
|
|
|
- $update['status'] = 7;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $update['pdate'] = time();
|
|
|
- $state = Dever::db('order', 'place')->update($order['id'], $update);
|
|
|
- if (!$state) {
|
|
|
- return '订单更新失败';
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- # 获取某个资源的订单
|
|
|
- public function getInfoByType($type_id, $type, $status = 5)
|
|
|
- {
|
|
|
- $order = Dever::db('order', 'place')->find(array('type' => $type, 'type_id' => $type_id, 'uid' => Place::$uid, 'status' => $status));
|
|
|
- return $order;
|
|
|
- }
|
|
|
-
|
|
|
- # 获取某个订单的详情
|
|
|
- public function getDetail($id, $type)
|
|
|
- {
|
|
|
- $detail = Dever::db('order_detail', 'place')->select(array('type' => $type, 'order_id' => $id));
|
|
|
- $result = array();
|
|
|
- if ($detail) {
|
|
|
-
|
|
|
- }
|
|
|
- return $result;
|
|
|
- }
|
|
|
-}
|