|
@@ -8,6 +8,8 @@ use app\api\model\OrderModel;
|
|
use app\api\model\Torder;
|
|
use app\api\model\Torder;
|
|
use app\api\model\UsersModel;
|
|
use app\api\model\UsersModel;
|
|
use app\common\controller\Api;
|
|
use app\common\controller\Api;
|
|
|
|
+use app\common\lib\WxPay;
|
|
|
|
+use think\Cache;
|
|
use think\Db;
|
|
use think\Db;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -21,7 +23,7 @@ class Order extends Api
|
|
/**
|
|
/**
|
|
* 购物车总价统计
|
|
* 购物车总价统计
|
|
* @ApiMethod (POST)
|
|
* @ApiMethod (POST)
|
|
- * @param string $list p_id colorid
|
|
|
|
|
|
+ * @param string $list colorid,number
|
|
*/
|
|
*/
|
|
public function carMoney()
|
|
public function carMoney()
|
|
{
|
|
{
|
|
@@ -31,12 +33,14 @@ class Order extends Api
|
|
}
|
|
}
|
|
$list = $params['list'];
|
|
$list = $params['list'];
|
|
foreach ($list as $v) {
|
|
foreach ($list as $v) {
|
|
- $commoditycolor[] = Commoditycolor::where('colorid', $v['colorid'])->find();
|
|
|
|
|
|
+ $commoditycolor[] = Commoditycolor::where('colorid', $v)->find();
|
|
}
|
|
}
|
|
if ($commoditycolor) {
|
|
if ($commoditycolor) {
|
|
$money = 0;
|
|
$money = 0;
|
|
- foreach ($commoditycolor as $v) {
|
|
|
|
- $money = $money + $v['money'];
|
|
|
|
|
|
+ $number = $params['number'];
|
|
|
|
+ $count = count($number);
|
|
|
|
+ for ($i = 0; $i < $count; $i++) {
|
|
|
|
+ $money = $money + $commoditycolor[$i]['money'] * $number[$i];
|
|
}
|
|
}
|
|
return $this->result('', $money, 200);
|
|
return $this->result('', $money, 200);
|
|
} else {
|
|
} else {
|
|
@@ -48,7 +52,7 @@ class Order extends Api
|
|
* 订单先提交
|
|
* 订单先提交
|
|
* @ApiMethod (POST)
|
|
* @ApiMethod (POST)
|
|
* @param string $user_id 用户id
|
|
* @param string $user_id 用户id
|
|
- * @param string $list 商品参数 c_id buy_number p_id colorid
|
|
|
|
|
|
+ * @param string $list 商品参数c_id,buy_number,p_id,colorid
|
|
*/
|
|
*/
|
|
public function orderGenerate()
|
|
public function orderGenerate()
|
|
{
|
|
{
|
|
@@ -140,7 +144,7 @@ class Order extends Api
|
|
* 支付订单
|
|
* 支付订单
|
|
* @ApiMethod (POST)
|
|
* @ApiMethod (POST)
|
|
* @param string $pre_id 预存id
|
|
* @param string $pre_id 预存id
|
|
- * @param string $list 商品参数 c_id buy_number p_id
|
|
|
|
|
|
+ * @param string $list 商品参数,c_id,buy_number,p_id
|
|
* @param string $user_id 用户id
|
|
* @param string $user_id 用户id
|
|
* @param string $money 总价
|
|
* @param string $money 总价
|
|
* @param string $a_id 地址id
|
|
* @param string $a_id 地址id
|
|
@@ -218,10 +222,10 @@ class Order extends Api
|
|
if (!isset($o_id)) {
|
|
if (!isset($o_id)) {
|
|
return $this->result('网络错误', '', 100);
|
|
return $this->result('网络错误', '', 100);
|
|
}
|
|
}
|
|
- $order = Db::name('order')->where('o_id',$o_id)->find();
|
|
|
|
|
|
+ $order = Db::name('order')->where('o_id', $o_id)->find();
|
|
$updOrder = OrderModel::where('o_id', $o_id)->update(['state' => 6]);
|
|
$updOrder = OrderModel::where('o_id', $o_id)->update(['state' => 6]);
|
|
- $updUserWhitebean = Db::name('users')->where('user_id',$order['user_id'])->setInc('user_whitebean',$order['whitebeon']);
|
|
|
|
- if ($updOrder&&$updUserWhitebean) {
|
|
|
|
|
|
+ $updUserWhitebean = Db::name('users')->where('user_id', $order['user_id'])->setInc('user_whitebean', $order['whitebeon']);
|
|
|
|
+ if ($updOrder && $updUserWhitebean) {
|
|
return $this->result('收货成功', '', 200);
|
|
return $this->result('收货成功', '', 200);
|
|
} else {
|
|
} else {
|
|
return $this->result('网络错误', '', 100);
|
|
return $this->result('网络错误', '', 100);
|
|
@@ -301,6 +305,7 @@ class Order extends Api
|
|
$res = $model->logistics($order);
|
|
$res = $model->logistics($order);
|
|
return $res;
|
|
return $res;
|
|
}
|
|
}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 退款订单显示
|
|
* 退款订单显示
|
|
* @ApiMethod (POST)
|
|
* @ApiMethod (POST)
|
|
@@ -310,7 +315,7 @@ class Order extends Api
|
|
{
|
|
{
|
|
$o_id = $this->request->post('o_id');
|
|
$o_id = $this->request->post('o_id');
|
|
if (!isset($o_id)) {
|
|
if (!isset($o_id)) {
|
|
- return $this->result('网络错误','', 100);
|
|
|
|
|
|
+ return $this->result('网络错误', '', 100);
|
|
}
|
|
}
|
|
$orderInfo = OrderModel::with(['OrderCommodityModel', 'OrderAddress'])->where('o_id', $o_id)->find();
|
|
$orderInfo = OrderModel::with(['OrderCommodityModel', 'OrderAddress'])->where('o_id', $o_id)->find();
|
|
if ($orderInfo) {
|
|
if ($orderInfo) {
|
|
@@ -319,6 +324,7 @@ class Order extends Api
|
|
return $this->result('网络错误', [], 100);
|
|
return $this->result('网络错误', [], 100);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 退款提交
|
|
* 退款提交
|
|
* @ApiMethod (POST)
|
|
* @ApiMethod (POST)
|
|
@@ -343,39 +349,40 @@ class Order extends Api
|
|
foreach ($files as $file) {
|
|
foreach ($files as $file) {
|
|
$imageName = $file['name'];
|
|
$imageName = $file['name'];
|
|
//后缀名
|
|
//后缀名
|
|
- $ext = strtolower(substr(strrchr($imageName,'.'),1));
|
|
|
|
|
|
+ $ext = strtolower(substr(strrchr($imageName, '.'), 1));
|
|
//保存文件名
|
|
//保存文件名
|
|
$fileName = uniqid();
|
|
$fileName = uniqid();
|
|
$tmp = $file['tmp_name'];
|
|
$tmp = $file['tmp_name'];
|
|
//保存 = 路径 + 文件名 + 后缀名
|
|
//保存 = 路径 + 文件名 + 后缀名
|
|
- $imageSavePath = ROOT_PATH . 'public' . DS . 'uploads/images/'.$fileName.'.'.$ext;
|
|
|
|
- $info = move_uploaded_file($tmp,$imageSavePath);
|
|
|
|
|
|
+ $imageSavePath = ROOT_PATH . 'public' . DS . 'uploads/images/' . $fileName . '.' . $ext;
|
|
|
|
+ $info = move_uploaded_file($tmp, $imageSavePath);
|
|
if ($info) {
|
|
if ($info) {
|
|
- $path = "/uploads/images/".$fileName.'.'.$ext;
|
|
|
|
- array_push($imageArr,$path);
|
|
|
|
|
|
+ $path = "/uploads/images/" . $fileName . '.' . $ext;
|
|
|
|
+ array_push($imageArr, $path);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//最终生成的字符串路径
|
|
//最终生成的字符串路径
|
|
- $params['images'] = implode(',',$imageArr);
|
|
|
|
|
|
+ $params['images'] = implode(',', $imageArr);
|
|
}
|
|
}
|
|
//修改订单状态
|
|
//修改订单状态
|
|
- $order = OrderModel::where('o_id',$params['o_id'])->find();
|
|
|
|
|
|
+ $order = OrderModel::where('o_id', $params['o_id'])->find();
|
|
$data = array(
|
|
$data = array(
|
|
- 'state' => 4,
|
|
|
|
|
|
+ 'state' => 4,
|
|
'tuikuan_state' => 3,
|
|
'tuikuan_state' => 3,
|
|
- 'state_save' => $order['state']
|
|
|
|
|
|
+ 'state_save' => $order['state']
|
|
);
|
|
);
|
|
$params['money'] = $order['money'];
|
|
$params['money'] = $order['money'];
|
|
- $params['create_time'] = date('Y-m-d H:i:s',time());
|
|
|
|
- $updOrder = OrderModel::where('o_id',$params['o_id'])->Update($data);
|
|
|
|
|
|
+ $params['create_time'] = date('Y-m-d H:i:s', time());
|
|
|
|
+ $updOrder = OrderModel::where('o_id', $params['o_id'])->Update($data);
|
|
$model = new Torder();
|
|
$model = new Torder();
|
|
$subTorder = $model->allowField(true)->save($params);
|
|
$subTorder = $model->allowField(true)->save($params);
|
|
if ($subTorder) {
|
|
if ($subTorder) {
|
|
- return $this->result('申请退款成功',[],200);
|
|
|
|
|
|
+ return $this->result('申请退款成功', [], 200);
|
|
} else {
|
|
} else {
|
|
- return $this->result('申请失败',[] ,100);
|
|
|
|
|
|
+ return $this->result('申请失败', [], 100);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 取消退款
|
|
* 取消退款
|
|
* @ApiMethod (POST)
|
|
* @ApiMethod (POST)
|
|
@@ -383,22 +390,23 @@ class Order extends Api
|
|
*/
|
|
*/
|
|
public function cancleTorder()
|
|
public function cancleTorder()
|
|
{
|
|
{
|
|
- $o_id =$this->request->post('o_id');
|
|
|
|
|
|
+ $o_id = $this->request->post('o_id');
|
|
if (!isset($o_id)) {
|
|
if (!isset($o_id)) {
|
|
return $this->result('网络错误', [], 100);
|
|
return $this->result('网络错误', [], 100);
|
|
}
|
|
}
|
|
- $order = OrderModel::where('o_id',$o_id)->find();
|
|
|
|
|
|
+ $order = OrderModel::where('o_id', $o_id)->find();
|
|
if (!$order) {
|
|
if (!$order) {
|
|
return $this->result('未找到该订单', [], 100);
|
|
return $this->result('未找到该订单', [], 100);
|
|
}
|
|
}
|
|
// 修改成为退款之前的状态
|
|
// 修改成为退款之前的状态
|
|
- $updOrder = OrderModel::where('o_id',$o_id)->update(['state' => $order['state_save']]);
|
|
|
|
|
|
+ $updOrder = OrderModel::where('o_id', $o_id)->update(['state' => $order['state_save']]);
|
|
if ($updOrder) {
|
|
if ($updOrder) {
|
|
return $this->result('取消成功', [], 200);
|
|
return $this->result('取消成功', [], 200);
|
|
} else {
|
|
} else {
|
|
- return $this->result('失败', [] , 100);
|
|
|
|
|
|
+ return $this->result('失败', [], 100);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 退款订单详情
|
|
* 退款订单详情
|
|
* @ApiMethod (POST)
|
|
* @ApiMethod (POST)
|
|
@@ -406,17 +414,18 @@ class Order extends Api
|
|
*/
|
|
*/
|
|
public function torderInfo()
|
|
public function torderInfo()
|
|
{
|
|
{
|
|
- $o_id =$this->request->post('o_id');
|
|
|
|
|
|
+ $o_id = $this->request->post('o_id');
|
|
if (!isset($o_id)) {
|
|
if (!isset($o_id)) {
|
|
return $this->result('网络错误', [], 100);
|
|
return $this->result('网络错误', [], 100);
|
|
}
|
|
}
|
|
- $orderInfo = OrderModel::with(['OrderCommodityModel', 'OrderAddress','Torder'])->where('o_id', $o_id)->find();
|
|
|
|
|
|
+ $orderInfo = OrderModel::with(['OrderCommodityModel', 'OrderAddress', 'Torder'])->where('o_id', $o_id)->find();
|
|
if ($orderInfo) {
|
|
if ($orderInfo) {
|
|
return $this->result('', $orderInfo, 200);
|
|
return $this->result('', $orderInfo, 200);
|
|
} else {
|
|
} else {
|
|
- return $this->result('未找到该订单', [] , 100);
|
|
|
|
|
|
+ return $this->result('未找到该订单', [], 100);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 微信订单支付回调
|
|
* 微信订单支付回调
|
|
* 可以通过@ApiInternal忽略请求的方法
|
|
* 可以通过@ApiInternal忽略请求的方法
|
|
@@ -435,12 +444,80 @@ class Order extends Api
|
|
//修改订单状态
|
|
//修改订单状态
|
|
$updOederstate = Db::name('order')->where('o_id', $order['o_id'])->update(['state' => 2]);
|
|
$updOederstate = Db::name('order')->where('o_id', $order['o_id'])->update(['state' => 2]);
|
|
if ($updOederstate) {
|
|
if ($updOederstate) {
|
|
- return "<xml>
|
|
|
|
- <return_code><![CDATA[SUCCESS]]></return_code>
|
|
|
|
- <return_msg><![CDATA[OK]]></return_msg>
|
|
|
|
- </xml>";
|
|
|
|
|
|
+ $arr = array(
|
|
|
|
+ 'return_code' => 'SUCCESS',
|
|
|
|
+ 'return_msg' => 'OK',
|
|
|
|
+ );
|
|
|
|
+ return $this->arrayToXml($arr);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 微信退款订单回调
|
|
|
|
+ * 可以通过@ApiInternal忽略请求的方法
|
|
|
|
+ * @ApiInternal
|
|
|
|
+ */
|
|
|
|
+ public function notify_refund()
|
|
|
|
+ {
|
|
|
|
+ $payXml = file_get_contents("php://input");
|
|
|
|
+ //将xml格式转化为json格式
|
|
|
|
+ $jsonXml = json_encode(simplexml_load_string($payXml, 'SimpleXMLElement', LIBXML_NOCDATA));
|
|
|
|
+ //将json格式转成数组格式 $result['out_trade_no']
|
|
|
|
+ $result = json_decode($jsonXml, true);
|
|
|
|
+ if ($result['return_code'] == "SUCCESS") {
|
|
|
|
+ $str = $result['req_info'];
|
|
|
|
+ // 对加密信息进行解密,需要用到商户秘钥
|
|
|
|
+ $data = $this->req_info_decrypt($str);
|
|
|
|
+ // Cache::set('req_info', $data);
|
|
|
|
+ if ($data['refund_status'] == "SUCCESS") {
|
|
|
|
+ //修改退款状态
|
|
|
|
+ $updstate = Db::name("order")->where('number', $data['out_trade_no'])->update(['tuikuan_state' => '1']);
|
|
|
|
+ $arr = array(
|
|
|
|
+ 'return_code' => 'SUCCESS',
|
|
|
|
+ 'return_msg' => 'OK',
|
|
|
|
+ );
|
|
|
|
+ return $this->arrayToXml($arr);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Cache::set('aaa', $result);
|
|
|
|
+ $arr = array(
|
|
|
|
+ 'return_code' => 'SUCCESS',
|
|
|
|
+ 'return_msg' => 'OK',
|
|
|
|
+ );
|
|
|
|
+ return $this->arrayToXml($arr);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 信息解密
|
|
|
|
+ * 对加密信息进行解密,需要用到商户秘钥
|
|
|
|
+ * 可以通过@ApiInternal忽略请求的方法
|
|
|
|
+ * @ApiInternal
|
|
|
|
+ */
|
|
|
|
+ public function req_info_decrypt($str)
|
|
|
|
+ {
|
|
|
|
+ //微信商户key
|
|
|
|
+ $key = "b3ae6bbf3cc4fa017eb169ae219e2c27";
|
|
|
|
+ $str = base64_decode($str);
|
|
|
|
+ $xml = openssl_decrypt($str, 'aes-256-ecb', md5($key), OPENSSL_RAW_DATA);
|
|
|
|
+ return json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 数组转xml
|
|
|
|
+ * @ApiInternal
|
|
|
|
+ */
|
|
|
|
+ public function arrayToXml($arr)
|
|
|
|
+ {
|
|
|
|
+ $xml = "<xml>";
|
|
|
|
+ foreach ($arr as $key => $val) {
|
|
|
|
+ if (is_numeric($val)) {
|
|
|
|
+ $xml .= "<" . $key . ">" . $val . "</" . $key . ">";
|
|
|
|
+ } else
|
|
|
|
+ $xml .= "<" . $key . "><![CDATA[" . $val . "]]></" . $key . ">";
|
|
|
|
+ }
|
|
|
|
+ $xml .= "</xml>";
|
|
|
|
+ return $xml;
|
|
|
|
+ }
|
|
}
|
|
}
|