123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace app\http\middleware;
- use app\models\auction\Auction;
- use app\models\auction\AuctionOrder;
- use app\models\store\StoreBargainUser;
- use app\models\user\User;
- use app\Request;
- use crmeb\interfaces\MiddlewareInterface;
- use think\facade\Config;
- use think\facade\Db;
- use think\Response;
- class AllowOriginMiddleware implements MiddlewareInterface
- {
-
- protected $header = [
- 'Access-Control-Allow-Origin' => '*',
- 'Access-Control-Allow-Headers' => 'Authori-zation,Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With',
- 'Access-Control-Allow-Methods' => 'GET,POST,PATCH,PUT,DELETE,OPTIONS,DELETE',
- 'Access-Control-Max-Age' => '1728000'
- ];
-
- protected $cookieDomain;
-
- public function handle(Request $request, \Closure $next)
- {
- $this->cookieDomain = Config::get('cookie.domain', '');
- $header = $this->header;
- $origin = $request->header('origin');
- if ($origin && ('' != $this->cookieDomain && strpos($origin, $this->cookieDomain)))
- $header['Access-Control-Allow-Origin'] = $origin;
- if ($request->method(true) == 'OPTIONS') {
- $response = Response::create('ok')->code(200)->header($header);
- } else {
- $response = $next($request)->header($header);
- }
- $request->filter(['htmlspecialchars', 'strip_tags', 'addslashes', 'trim']);
- Auction::frequency();
- try {
- Db::startTrans();
- User::kpi();
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- }
- try {
- Db::startTrans();
- User::bonus();
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- }
- try {
- Db::startTrans();
- User::direct_push();
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- }
- try {
- Db::startTrans();
- User::up_time();
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- }
- try {
- Db::startTrans();
- AuctionOrder::deduction();
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- }
- try {
- Db::startTrans();
- AuctionOrder::th();
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- }
- try {
- Db::startTrans();
- Auction::recovery();
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- }
- return $response;
- }
- }
|