ContractController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\FrontController;
  4. use App\Models\Contract;
  5. use App\Models\ContractDistribution;
  6. use App\Models\Invest;
  7. use App\Servers\CommonServer;
  8. use App\Servers\ContractServer;
  9. use App\Servers\IndentNumServer;
  10. use App\Servers\MemberServer;
  11. use App\Servers\RedisDataServer;
  12. use Illuminate\Support\Facades\Auth;
  13. use Illuminate\Validation\Rules\In;
  14. class ContractController extends FrontController
  15. {
  16. public function __construct()
  17. {
  18. parent::__construct();
  19. }
  20. /**
  21. * 获取基本投资信息
  22. * @return \Illuminate\Http\JsonResponse
  23. */
  24. function getInvestData()
  25. {
  26. $sysAddress = CommonServer::creatServer()->getConfigValue('sys_address');
  27. $investData = Invest::where('id', 1)->select(['id', 'invest_money'])->first();
  28. if (empty($investData)) {
  29. return $this->apiResponseError('sys.key_error');
  30. }
  31. $investData->{'sysAddress'} = $sysAddress;
  32. return $this->apiResponseSuccess('', $investData);
  33. }
  34. /**
  35. * 执行报单
  36. * @return \Illuminate\Http\JsonResponse
  37. */
  38. function setInvest()
  39. {
  40. $mId = MemberServer::creatServer()->getMemberId();
  41. $redis_on_name = 'setInvest' . $mId;
  42. $redis_time = RedisDataServer::creatServer()->getData($redis_on_name);
  43. $time = time();
  44. if (!empty($redis_time) && $redis_time > $time - 2) {
  45. return $this->apiResponseError('sys.key_num');
  46. }
  47. RedisDataServer::creatServer()->setData($redis_on_name, $time, 'str', 2, false);
  48. $investId = request()->input('id');
  49. $txid = request()->input('txid');
  50. if (empty($investId)) {
  51. return $this->apiResponseError('sys.key_error');
  52. }
  53. if (empty($txid)) {
  54. return $this->apiResponseError('sys.key_error');
  55. }
  56. $num = Contract::where('hash', $txid)->count();
  57. if ($num > 0) {
  58. return $this->apiResponseError('contract.no_hash');
  59. }
  60. $investData = Invest::where('id', $investId)->first();
  61. $contractData = Contract::create([
  62. 'm_id' => $mId,
  63. 'type' => $investId,
  64. 'status' => 1,
  65. 'hash' => $txid,
  66. 'broadcast_data' => '',
  67. 'is_out' => '0',
  68. 'error_msg' => '',
  69. 'money' => $investData->{'invest_money'},
  70. 'platform_money' => $investData->{'platform_money'},
  71. 'direct_proportion' => $investData->{'direct_proportion'},
  72. 'indirect_proportion' => $investData->{'indirect_proportion'},
  73. 'team_proportion' => $investData->{'team_proportion'},
  74. 'common_proportion' => $investData->{'common_proportion'},
  75. 'sediment_proportion' => $investData->{'sediment_proportion'},
  76. 'agency_proportion' => $investData->{'agency_proportion'},
  77. 'contract_sn' => IndentNumServer::creatServer()->getIndentNum(1),
  78. ]);
  79. if (empty($contractData)) {
  80. return $this->apiResponseError('contract.no');
  81. } else {
  82. ContractServer::creatServer()->addContractLog($contractData, '合约创建成功');
  83. return $this->apiResponseSuccess('contract.ok');
  84. }
  85. }
  86. /**
  87. * 获取收益明细
  88. * @return \Illuminate\Http\JsonResponse
  89. */
  90. function getEarnings()
  91. {
  92. $mId = MemberServer::creatServer()->getMemberId();
  93. $list = ContractDistribution::from('contract_distributions as cd')
  94. ->leftJoin('broadcasts as b', 'b.id', '=', 'cd.broadcast_id')
  95. ->where('to_m_id', $mId)
  96. ->whereIn('cd.status',[1,3])
  97. ->select(['cd.id', 'db_money', 'nbn_money', 'cd.created_at', 'cd.type', 'cd.status', 'b.hash','cd.service_money'])->paginate(15);
  98. return $this->apiResponseSuccess('', ['total' => $list->total(), 'items' => $list->items()]);
  99. }
  100. /**
  101. * 获取我的合约列表
  102. * @return \Illuminate\Http\JsonResponse
  103. */
  104. function getContractList(){
  105. $mId = MemberServer::creatServer()->getMemberId();
  106. $list=Contract::where('m_id',$mId)->select(['id','status','hash','money','created_at','is_out'])->orderBy('id','desc')->paginate(15);
  107. foreach ($list as $item){
  108. $item->{'statusName'}=__('contract.status'.$item->{'status'});
  109. if($item->{'status'}!=4){
  110. $item->{'out_num'}=Contract::where('status','=',2)->where('id','<=',$item->{'id'})->count();
  111. }else{
  112. $item->{'out_num'}=0;
  113. }
  114. }
  115. return $this->apiResponseSuccess('', ['total' => $list->total(), 'items' => $list->items()]);
  116. }
  117. }