You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
166 lines
4.8 KiB
166 lines
4.8 KiB
<?php
|
|
|
|
namespace app\task\controller;
|
|
|
|
use app\service\pay\PayService;
|
|
use app\service\task\OrderService;
|
|
use think\facade\Db;
|
|
|
|
class Order extends Base
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->redis = new \Redis();
|
|
$this->redis->connect('127.0.0.1', 6379);
|
|
}
|
|
|
|
|
|
/**
|
|
* @title 超时订单
|
|
* @url /task/Order/payTimeout
|
|
* @method POST
|
|
* @param string page 用户名/手机号 / 是
|
|
* @param string limit 密码 / 是
|
|
* @return string msg 返回信息
|
|
* @return int code 状态码 200:成功;>=400:失败
|
|
*/
|
|
public function payTimeout(){
|
|
try {
|
|
if($this->redis->get('payTimeout') > 0){
|
|
return ;
|
|
}
|
|
$this->redis->set('payTimeout', 1, 20);
|
|
$orderService = new OrderService();
|
|
Db::startTrans();
|
|
$orderService->payTimeout();
|
|
Db::commit();
|
|
$this->redis->set('payTimeout', 0);
|
|
return _success('成功');
|
|
}catch(\Exception $e){
|
|
Db::rollback();
|
|
$this->redis->set('payTimeout', 0);
|
|
return _error($e->getMessage(), $e->getCode() ?: 400, $e);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @title 用户下载资源状态
|
|
* @url /task/Order/orderSourceDownload
|
|
* @method POST
|
|
* @return string msg 返回信息
|
|
* @return int code 状态码 200:成功;>=400:失败
|
|
*/
|
|
public function orderSourceDownload(){
|
|
try {
|
|
if($this->redis->get('orderSourceDownload') > 0){
|
|
return ;
|
|
}
|
|
$this->redis->set('orderSourceDownload', 1);
|
|
$orderService = new OrderService();
|
|
Db::startTrans();
|
|
$orderService->orderSourceDownload();
|
|
Db::commit();
|
|
$this->redis->set('orderSourceDownload', 0);
|
|
return _success('成功');
|
|
}catch(\Exception $e){
|
|
Db::rollback();
|
|
$this->redis->set('orderSourceDownload', 0);
|
|
return _error($e->getMessage(), $e->getCode() ?: 400, $e);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @title 支付完成
|
|
* @url /task/Order/payComplete
|
|
* @method POST
|
|
* @return string msg 返回信息
|
|
* @return int code 状态码 200:成功;>=400:失败
|
|
*/
|
|
public function payComplete(){
|
|
try {
|
|
if($this->redis->get('payComplete') > 0){
|
|
return ;
|
|
}
|
|
$this->redis->set('payComplete', 1, 60);
|
|
$payService = new PayService();
|
|
$result = $payService->payComplete();
|
|
$this->redis->set('payComplete', 0);
|
|
return _success('成功', $result);
|
|
}catch(\Exception $e){
|
|
$this->redis->set('payComplete', 0);
|
|
return _error($e->getMessage(), $e->getCode() ?: 400, $e);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @title 订单结算
|
|
* @url /task/Order/orderClose
|
|
* @method POST
|
|
* @return string msg 返回信息
|
|
* @return int code 状态码 200:成功;>=400:失败
|
|
*/
|
|
public function orderClose(){
|
|
try {
|
|
if($this->redis->get('orderClose') > 0){
|
|
return ;
|
|
}
|
|
$this->redis->set('orderClose', 1);
|
|
$orderService = new OrderService();
|
|
$orderService->orderClose();
|
|
$this->redis->set('orderClose', 0);
|
|
return _success('成功');
|
|
}catch(\Exception $e){
|
|
$this->redis->set('orderClose', 0);
|
|
return _error($e->getMessage(), $e->getCode() ?: 400, $e);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @title 订单生成发票
|
|
* @url /task/Order/orderCreateBill
|
|
* @method POST
|
|
* @return string msg 返回信息
|
|
* @return int code 状态码 200:成功;>=400:失败
|
|
*/
|
|
public function orderCreateBill(){
|
|
try {
|
|
if($this->redis->get('orderCreateBill') > 0){
|
|
return ;
|
|
}
|
|
$this->redis->set('orderCreateBill', 1, 30);
|
|
$orderService = new OrderService();
|
|
$orderService->orderCreateBill();
|
|
$this->redis->set('orderCreateBill', 0);
|
|
return _success('成功');
|
|
}catch(\Exception $e){
|
|
$this->redis->set('orderCreateBill', 0);
|
|
return _error($e->getMessage(), $e->getCode() ?: 400, $e);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @title 支付完成
|
|
* @url /api/Pay/payComplete
|
|
* @method POST
|
|
* @return string msg 返回信息
|
|
* @return int code 状态码 200:成功;>=400:失败
|
|
*/
|
|
public function test(){
|
|
try {
|
|
$payService = new PayService();
|
|
$result = $payService->test();
|
|
return _success('成功', $result);
|
|
}catch(\Exception $e){
|
|
return _error($e->getMessage(), $e->getCode() ?: 400, $e);
|
|
}
|
|
}
|
|
|
|
|
|
}
|