PayController.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * 支付.
  4. *
  5. * @author nj
  6. * @date 2021-07-21 15:19
  7. */
  8. namespace Modules\InnerApi\Controllers;
  9. use App\Models\Mongo\PayLogsModel;
  10. use App\Models\Mysql\ChannelModel;
  11. use Modules\InnerApi\Requests\PayIncRequest;
  12. use Modules\InnerApi\Responses\SuccessCommonResponse;
  13. use Modules\InnerApi\Services\PayService;
  14. class PayController extends BaseController
  15. {
  16. public function inc(PayIncRequest $request, PayService $service)
  17. {
  18. $arrJson = $this->getJsonData();
  19. if (!empty($arrJson)) {
  20. foreach ($arrJson as $k => &$item) {
  21. $item['agent_uid'] = '';
  22. $item['is_deduction'] = 0;
  23. if (!empty($item['share_code']) && empty($item['invite_uid'])) {
  24. // 兼容一下,置顶定义混乱了, share_code, invite_uid.
  25. $item['invite_uid'] = $item['share_code'];
  26. }
  27. if (!empty($item['channel_uid'])) {
  28. $channelInfo = ChannelModel::where(['uid' => $item['channel_uid'], 'mom_app_uid' => $item['mom_app_uid']])->first(['agent_uid']);
  29. if (empty($channelInfo)) {
  30. logger('新增充值查不到渠道的报错日志:' . json_encode($item, true));
  31. continue;
  32. }
  33. $item['agent_uid'] = $channelInfo->agent_uid;
  34. $orderInt = PayLogsModel::query()->where(['order_sn' => $item['order_sn'], 'pay_status' => 1, 'order_status' => 1])->count();
  35. if (empty($orderInt)) {
  36. // 扣量计算
  37. $item = $service->oneRandDeduction($item);
  38. }
  39. }
  40. $arrJson[$k] = $item;
  41. }
  42. $service->inc($arrJson);
  43. }
  44. return new SuccessCommonResponse();
  45. }
  46. }