123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
- namespace App\Http\Controllers;
- use App\Models\AdminMerchant;
- use Dingo\Api\Routing\Helpers;
- use Illuminate\Support\Facades\Log;
- use Laravel\Lumen\Routing\Controller as BaseController;
- class Controller extends BaseController
- {
- use Helpers;
- protected static $MERCHANT_ID = 0;
- protected static $MERCHANT = [];
- protected static $ORDER_TAG = null;
- const SOURCE_TYPE_WECHAT = 'wechat';
- const SOURCE_TYPE_ALIPAY = 'alipay';
- protected static $SOURCE_TYPE = 'wechat';
- const PATMENT_TYPE_MINIAPP = 1;
- const PATMENT_TYPE_ACCOUNT = 2;
- const PATMENT_TYPE_ALIPAY_CARD = 3;
- public static $paymentTypeMaps = [
- self::PATMENT_TYPE_MINIAPP => '微信/支付宝',
- self::PATMENT_TYPE_ACCOUNT => '平台余额',
- self::PATMENT_TYPE_ALIPAY_CARD => '支付宝预支付(缴纳押金)',
- ];
- public static $URLS = [
- 'api/relay/order/auto-close',
- 'api/common/clear-cache',
- 'api/t',
- ];
- public function __construct()
- {
- $url = request()->path();
- if (!in_array($url, self::$URLS)) {
- $merchant_id = merchant_id();
- if (!$merchant_id) {
- return_json('商户id错误');
- }
- self::$MERCHANT_ID = $merchant_id;
- self::$MERCHANT = AdminMerchant::byId($merchant_id);
- if (!self::$MERCHANT) {
- return_json('平台暂停服务,如有不便敬请谅解');
- }
- self::$ORDER_TAG = self::$MERCHANT['order_key'];
- }
- self::$SOURCE_TYPE = source_type();
- if (!self::$SOURCE_TYPE) {
- return_json('没有获取到平台信息');
- }
- }
- // 返回错误的请求
- protected function errorBadRequest($msg)
- {
- return $this->response->array([
- 'message' => $msg
- ])->statusCode(400);
- }
- /**
- * 验证错误
- * @param $msg
- * User: Mead
- */
- protected function errorNoValidation($msg, $code = 422)
- {
- return $this->response->array([
- 'message' => $msg
- ])->statusCode($code);
- }
- /**
- * 验证错误
- * @param $msg
- * User: Mead
- */
- protected function errorNoYundong($msg)
- {
- return $this->response->array([
- 'message' => $msg
- ])->statusCode(450);
- }
- /**
- * 异常错误
- * @param $msg
- * User: Mead
- */
- protected function errorException($msg)
- {
- return $this->response->array([
- 'message' => $msg
- ])->statusCode(423);
- }
- /**
- * 获取当前登录的用户的openid
- * @return mixed
- * User: Mead
- */
- protected function getOpenId()
- {
- return $this->user->auth->credential;
- }
- /**
- * 处理异常信息
- * @param $exception
- * @return string
- * Author: Mead
- */
- public function exception($exception)
- {
- Log::error($exception);
- return $this->errorNoValidation('异常错误');
- }
- }
|