ContractDistributionsController.php 3.1 KB

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