AuctionProductController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace app\api\controller\auction;
  3. use app\admin\model\system\SystemConfig;
  4. use app\models\auction\Auction;
  5. use app\models\auction\AuctionBooking;
  6. use app\models\auction\AuctionOrder;
  7. use app\models\auction\AuctionProduct;
  8. use app\models\user\User;
  9. use app\models\user\UserBill;
  10. use app\Request;
  11. use Monolog\Handler\Curl\Util;
  12. use think\facade\Cache;
  13. use crmeb\services\{
  14. CacheService,
  15. ExpressService,
  16. SystemConfigService
  17. };
  18. use crmeb\services\UtilService;
  19. use crmeb\repositories\OrderRepository;
  20. use think\facade\Db;
  21. class AuctionProductController
  22. {
  23. /**
  24. * 购买随机返回一张订单
  25. * @param Request $request
  26. * @return void
  27. */
  28. public function purchase(Request $request)
  29. {
  30. $data = UtilService::postMore([
  31. ['id']
  32. ]);
  33. $auction = Auction::find($data['id']);
  34. if (!$auction) return app('json')->fail('场次不存在');
  35. if (AuctionOrder::where([['auction_id', '=', $data['id']], ['frequency', '=', $auction['frequency']], ['uid', '=', $request->uid()]])->count() >= 1) return app('json')->fail('当前场次已购买商品');
  36. $orderCount = AuctionOrder::where([['auction_id', '=', $data['id']], ['frequency', '=', $auction['frequency']]])->count(); // 查找出当前场次已派单多少
  37. $pd = AuctionBooking::where([['auction_id', '=', $data['id']], ['frequency', '=', $auction['frequency']]])->count(); // 当前预约人数
  38. $pds = ceil($pd * ($auction['dispatch']/100));
  39. if ($orderCount >= $pds) return app('json')->fail('商品已买完');
  40. $show = AuctionProduct::random($data['id'], $request->uid());
  41. if ($show == 'false') return app('json')->fail('购买失败');
  42. return app('json')->successful($show);
  43. }
  44. /**
  45. * 用户商品
  46. * @param Request $request
  47. * @return mixed
  48. * @throws \think\db\exception\DataNotFoundException
  49. * @throws \think\db\exception\DbException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. */
  52. public function user_product(Request $request)
  53. {
  54. $data = UtilService::getMore([
  55. [['page', 'd'], 0],
  56. [['limit', 'd'], 0],
  57. ]);
  58. return app('json')->successful(AuctionProduct::user_product( $data,$request->uid()));
  59. }
  60. /**
  61. * 用户订单
  62. * @param Request $request
  63. * @return mixed
  64. * @throws \think\db\exception\DataNotFoundException
  65. * @throws \think\db\exception\DbException
  66. * @throws \think\db\exception\ModelNotFoundException
  67. */
  68. public function user_auction_order(Request $request)
  69. {
  70. $data = UtilService::getMore([
  71. [['type', 'd'], 0],
  72. [['page', 'd'], 0],
  73. [['limit', 'd'], 0],
  74. ['order_id']
  75. ]);
  76. return app('json')->successful(AuctionOrder::userOrder($data,$request->uid()));
  77. }
  78. /**
  79. * 卖家显示订单
  80. * @param Request $request
  81. * @return void
  82. */
  83. public function seller(Request $request)
  84. {
  85. $data = UtilService::getMore([
  86. ['type', 0],
  87. [['page', 'd'], 0],
  88. [['limit', 'd'], 0],
  89. ['order_id']
  90. ]);
  91. return app('json')->successful(AuctionOrder::seller_list($data,$request->uid()));
  92. }
  93. /**
  94. * 支付订单
  95. * @param Request $request
  96. * @return void
  97. * @throws \think\db\exception\DataNotFoundException
  98. * @throws \think\db\exception\DbException
  99. * @throws \think\db\exception\ModelNotFoundException
  100. */
  101. public function zfpay(Request $request)
  102. {
  103. $data = UtilService::postMore([
  104. ['order_id']
  105. ]);
  106. $model = new User();
  107. $order = AuctionOrder::where('order_id', $data['order_id'])->find();
  108. if (!$order) return app('json')->fail('订单不存在');
  109. if ($order['status'] == 0 or $order['status'] == 2) return app('json')->fail('订单状态不对');
  110. $user = $model->where('uid', $request->uid())->find();
  111. if ($user['now_money'] < $order['actual_price']) return app('json')->fail('余额不足');
  112. try {
  113. Db::startTrans();
  114. AuctionOrder::pay($order, $request->uid());
  115. Db::commit();
  116. return app('json')->successful('支付成功');
  117. } catch (\Exception $e) {
  118. Db::rollback();
  119. return app('json')->fail('支付失败');
  120. }
  121. }
  122. }