first commit
This commit is contained in:
111
芳林公司项目/www.zhiyuanhelp.com/application/api/controller/Order.php
Normal file
111
芳林公司项目/www.zhiyuanhelp.com/application/api/controller/Order.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Administrator
|
||||
* Date: 2020/4/17
|
||||
* Time: 13:24
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
use app\api\service\Order as OrderService;
|
||||
use app\api\validate\OrderValidate;
|
||||
use app\api\service\UserToken;
|
||||
use app\api\model\User;
|
||||
use app\lib\exception\ParamException;
|
||||
use think\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
class Order extends BaseController
|
||||
{
|
||||
/*
|
||||
* 创建订单
|
||||
* */
|
||||
public function placeOrder(){
|
||||
|
||||
(new OrderValidate())->goCheck();
|
||||
//获取传递参数
|
||||
$orderInfo = input('post.');
|
||||
|
||||
$orderInfo['subType'] = input('post.subType',0);
|
||||
$orderInfo['mySub'] = input('post.mySub',0);
|
||||
$uid = $this->verifyToken();
|
||||
//解密手机号
|
||||
$orderInfo['telnum'] = $this->rsaDecipher($telnum = input('telnum'));
|
||||
//手机号正则验证
|
||||
$check = '/^(1(([35789][0-9])|(47)))\d{8}$/';
|
||||
if (!preg_match($check, $orderInfo['telnum'])){
|
||||
throw new ParamException([
|
||||
'code' => 400,
|
||||
'msg' => '手机号格式不正确',
|
||||
'errorCode' => 10000
|
||||
]);
|
||||
}
|
||||
|
||||
$order = new OrderService();
|
||||
$result['status'] = $order->place($uid,$orderInfo);
|
||||
|
||||
return api_return('下单成功',$result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//未登录处理
|
||||
private function checkNoLogin($orderInfo){
|
||||
//检查参数并创建用户
|
||||
$this->checkUserParam($orderInfo);
|
||||
//解密手机号
|
||||
$orderInfo['phone'] = $this->rsaDecipher($telnum = input('telnum'));
|
||||
//手机号正则验证
|
||||
$check = '/^(1(([35789][0-9])|(47)))\d{8}$/';
|
||||
if (!preg_match($check, $orderInfo['phone'])){
|
||||
throw new ParamException([
|
||||
'code' => 400,
|
||||
'msg' => '手机号格式不正确',
|
||||
'errorCode' => 10000
|
||||
]);
|
||||
}
|
||||
|
||||
//检测手机号是否已注册,注册则登录,否则添加新数据
|
||||
$userCount = User::checkUserByTelnum( $orderInfo['phone']);
|
||||
if($userCount){
|
||||
throw new ParamException([
|
||||
'msg' => '手机号已注册!请登录',
|
||||
'errorCode' => 10000,
|
||||
'code' => 400,
|
||||
'status' => 1
|
||||
]);
|
||||
|
||||
}else{
|
||||
$resUser = User::addUserInfo($orderInfo);
|
||||
return $resUser;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 查询顶订单是否支付成功
|
||||
* */
|
||||
public function checkOrderPay(){
|
||||
$user_id = $this->verifyToken();
|
||||
$orderID = input('order_id');
|
||||
//参数验证
|
||||
if(!intval($orderID)){
|
||||
throw new ParamException([
|
||||
'msg' => '订单id参数错误',
|
||||
'errorCode' => 10000,
|
||||
'code' => 400
|
||||
]);
|
||||
}
|
||||
|
||||
$result = Db::table("orders")->field('status')->where([['user_id','=',$user_id],['id','=',$orderID]])->find();
|
||||
|
||||
if(empty($result)){
|
||||
throw new ParamException([
|
||||
'msg' => '订单不存在',
|
||||
'errorCode' => 10004,
|
||||
'code' => 404
|
||||
]);
|
||||
}
|
||||
|
||||
return api_return('ok',$result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user