ContractsController.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace App\Http\Controllers\Contract;
  3. use App\Http\Controllers\AdminBaseController;
  4. use App\Http\Requests\ContractCreateRequest;
  5. use App\Http\Requests\ContractUpdateRequest;
  6. use App\Models\Contract;
  7. use App\Repositories\Eloquent\ContractRepositoryEloquent;
  8. use App\Validators\ContractValidator;
  9. /**
  10. * Class ContractsController.
  11. *
  12. * @package namespace App\Http\Controllers;
  13. */
  14. class ContractsController extends AdminBaseController
  15. {
  16. /**
  17. * @var ContractRepositoryEloquent
  18. */
  19. protected $repository;
  20. /**
  21. * @var ContractValidator
  22. */
  23. protected $validator;
  24. /**
  25. * ContractsController constructor.
  26. *
  27. * @param ContractRepositoryEloquent $repository
  28. * @param ContractValidator $validator
  29. */
  30. public function __construct(ContractRepositoryEloquent $repository, ContractValidator $validator)
  31. {
  32. parent::__construct($repository, $validator);
  33. }
  34. /**
  35. * 数据检索
  36. */
  37. public function _indexScopeQuery()
  38. {
  39. $where = [];
  40. $search = explode(";", request()->input('search', ""));
  41. $start = $end = null;
  42. $fieldSearchable=$this->repository->getFieldsSearchable();
  43. foreach ($search as $value) {
  44. if (!empty($value)) {
  45. list($one, $tow) = explode(":", $value);
  46. if (!empty($fieldSearchable[$one])) {
  47. if($fieldSearchable[$one]=='like')$tow="%{$tow}%";
  48. $where[]=[$one,$fieldSearchable[$one],$tow];
  49. } elseif ($one == 'start') {
  50. $start = $tow . " 00:00:00";
  51. } elseif ($one == 'end') {
  52. $end = $tow . " 23:59:59";
  53. } else {
  54. continue;
  55. }
  56. }
  57. }
  58. return function ($query) use ($where, $start, $end) {
  59. if ($start) $where[] = ['created_at', '>=', $start];
  60. if ($end) $where[] = ['created_at', '<=', $end];
  61. if ($where) {
  62. $query->where($where);
  63. }
  64. };
  65. }
  66. /**
  67. * 数据更新
  68. */
  69. protected function _indexPost($data)
  70. {
  71. $status=['','广播中','交易成功','交易失败','公排出局'];
  72. foreach ($data as $item){
  73. $item->{'status'}=empty($status[$item->{'status'}])?'状态异常':$status[$item->{'status'}];
  74. }
  75. return $data;
  76. }
  77. function _indexJoin()
  78. {
  79. return Contract::from('contracts as c')
  80. ->leftJoin('members as m','m.id','=','c.m_id')
  81. ->select(['c.id','c.m_id','c.status','c.hash','c.money','c.error_msg','c.created_at','c.updated_at','c.is_out','c.contract_sn','m.address']);
  82. }
  83. }