| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?php
- namespace App\Http\Controllers\Oapi;
- use App\Http\Validator\TradeValidator;
- use App\Services\ConfigService;
- use App\Services\Oapi\TradeOrderService;
- /**
- * 交易
- * Class TradeController
- * @package App\Http\Controllers\Oapi
- */
- class TradeController extends webApp
- {
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/11
- * NoticeController constructor.
- */
- public function __construct()
- {
- parent::__construct();
- $this->service = new TradeOrderService();
- }
- /**
- * 买入
- * @param TradeValidator $validate
- * @return array
- */
- public function buy(TradeValidator $validate)
- {
- $params = request()->post();
- $params = $validate->check($params,'trade_buy');
- if(!is_array($params)){
- return message($params, false);
- }
- // 额外验证没注册需要前往下载APP注册
- $tradeType = isset($params['trade_type']) ? intval($params['trade_type']) : 0;
- if($tradeType == 3 && (empty($this->userId) || $this->userInfo['idcard_check'] != 1)){
- $appUrl = ConfigService::make()->getConfigByCode('app_download_url');
- return message(2029, true, [
- 'app_url' => $appUrl,
- ]);
- }
- $params['api_id'] = $this->apiId;
- if($info = TradeOrderService::make()->buy($this->userId, $params)){
- return message(3006, true, $info);
- }else{
- return message(TradeOrderService::make()->getError(), false);
- }
- }
- /**
- * 出售
- * @param TradeValidator $validate
- * @return array
- */
- public function sell(TradeValidator $validate)
- {
- $params = request()->post();
- $params = $validate->check($params,'trade_sell');
- if(!is_array($params)){
- return message($params, false);
- }
- // 需要注册认证
- $tradeType = isset($params['trade_type']) ? intval($params['trade_type']) : 0;
- if($tradeType == 3 && (empty($this->userId) || $this->userInfo['idcard_check'] != 1)){
- $appUrl = ConfigService::make()->getConfigByCode('app_download_url');
- return message(2029, true, [
- 'app_url' => $appUrl,
- ]);
- }
- $params['api_id'] = $this->apiId;
- if($info = TradeOrderService::make()->sell($this->userId, $params)){
- return message(3007, true, $info);
- }else{
- return message(TradeOrderService::make()->getError(), false);
- }
- }
- /**
- * 确认打款
- * @param TradeValidator $validate
- * @return array
- */
- public function pay(TradeValidator $validate)
- {
- $params = request()->post();
- $params = $validate->check($params,'pay');
- if(!is_array($params)){
- return message($params, false);
- }
- if($info = TradeOrderService::make()->pay($this->userId, $params)){
- return message(3017, true, $info);
- }else{
- return message(TradeOrderService::make()->getError(), false);
- }
- }
- /**
- * 确认收款
- * @param TradeValidator $validate
- * @return array
- */
- public function collection(TradeValidator $validate)
- {
- $params = request()->post();
- $params = $validate->check($params,'info');
- if(!is_array($params)){
- return message($params, false);
- }
- if($info = TradeOrderService::make()->collection($this->userId, $params)){
- return message(3021, true, $info);
- }else{
- return message(TradeOrderService::make()->getError(), false);
- }
- }
- /**
- * 取消订单
- * @param TradeValidator $validate
- * @return array
- */
- public function cancel(TradeValidator $validate)
- {
- $params = request()->post();
- $params = $validate->check($params,'info');
- if(!is_array($params)){
- return message($params, false);
- }
- if($info = TradeOrderService::make()->cancel($this->userId, $params)){
- return message(3034, true, $info);
- }else{
- return message(TradeOrderService::make()->getError(), false);
- }
- }
- /**
- * 订单信息
- * @return array
- */
- public function info()
- {
- $orderNo = request()->post('order_no','');
- if(empty($orderNo)){
- return message(1013,false);
- }
- $info = $this->service->getInfoByNo($orderNo, $this->userId);
- if($info){
- return message(1002, true, $info);
- }else{
- return message(1002, false);
- }
- }
- }
|