MoneyDetailsController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace App\Http\Controllers\MoneyDetail;
  3. use App\Http\Controllers\AdminBaseController;
  4. use App\Http\Requests\MoneyDetailCreateRequest;
  5. use App\Http\Requests\MoneyDetailUpdateRequest;
  6. use App\Models\MoneyDetail;
  7. use App\Repositories\Eloquent\MoneyDetailRepositoryEloquent;
  8. use App\Servers\MoneyDetailServer;
  9. use App\Validators\MoneyDetailValidator;
  10. /**
  11. * Class MoneyDetailsController.
  12. *
  13. * @package namespace App\Http\Controllers;
  14. */
  15. class MoneyDetailsController extends AdminBaseController
  16. {
  17. /**
  18. * @var MoneyDetailRepositoryEloquent
  19. */
  20. protected $repository;
  21. /**
  22. * @var MoneyDetailValidator
  23. */
  24. protected $validator;
  25. /**
  26. * MoneyDetailsController constructor.
  27. *
  28. * @param MoneyDetailRepositoryEloquent $repository
  29. * @param MoneyDetailValidator $validator
  30. */
  31. public function __construct(MoneyDetailRepositoryEloquent $repository, MoneyDetailValidator $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. foreach ($datum as $value){
  73. $value->{'type'}=MoneyDetailServer::creatServer()->getTypeArr($value->{'type'});
  74. $value->{'status'}=MoneyDetailServer::creatServer()->getStatusArr($value->{'status'});
  75. $value->{'add_reduce'}=MoneyDetailServer::creatServer()->getAddReduceArr($value->{'add_reduce'});
  76. }
  77. return $datum;
  78. }
  79. function _indexGet(){
  80. $type=MoneyDetailServer::creatServer()->getType();
  81. $status=MoneyDetailServer::creatServer()->getStatus();
  82. return ['type'=>$type,'status'=>$status];
  83. }
  84. function _indexJoin()
  85. {
  86. $model = MoneyDetail::from('money_details as d')
  87. ->leftJoin('members as m', 'm.id', '=', 'd.m_id');
  88. return $model;
  89. }
  90. function _indexSelect()
  91. {
  92. return ['d.*', 'm.address'];
  93. }
  94. }