InfoController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /**
  3. * 支付列表
  4. * @author system
  5. * @version 1.0
  6. * @date 2018-07-11 06:53:04
  7. *
  8. */
  9. namespace App\Http\Controllers\Admin\Payment;
  10. use App\Http\Controllers\Admin\Controller;
  11. use App\Models\UserInfoModel;
  12. use Illuminate\Http\Request;
  13. use App\Repositories\Base\Criteria\OrderBy;
  14. use App\Repositories\Payment\Criteria\MultiWhere;
  15. use App\Repositories\Payment\InfoRepository;
  16. class InfoController extends Controller
  17. {
  18. private $repository;
  19. public function __construct(InfoRepository $repository) {
  20. if(!$this->repository) $this->repository = $repository;
  21. }
  22. function index(Request $request) {
  23. $search['keyword'] = $request->input('keyword');
  24. $query = $this->repository->pushCriteria(new MultiWhere($search));
  25. if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  26. $query = $query->pushCriteria(new OrderBy($request['sort_field'],$request['sort_field_by']));
  27. }else{
  28. $query = $query->pushCriteria(new OrderBy('id','DESC'));
  29. }
  30. $list = $query->paginate();
  31. foreach ($list as $key=>$val) {
  32. if($val['user_id'] == 0){
  33. $list[$key]['user'] = '系统';
  34. } else {
  35. $user = UserInfoModel::find($val['user_id']);
  36. $list[$key]['user'] = $user->nickname;
  37. }
  38. if($val['to_user'] == 0){
  39. $list[$key]['to_user_name'] = '系统';
  40. } else {
  41. $user = UserInfoModel::find($val['to_user']);
  42. $list[$key]['to_user_name'] = $user->nickname;
  43. }
  44. switch ($val['type']) {
  45. case '0':
  46. $list[$key]['payment'] = '充值';
  47. break;
  48. case '1':
  49. $list[$key]['payment'] = '提现';
  50. break;
  51. case '3':
  52. $list[$key]['payment'] = '悬赏知识';
  53. break;
  54. case '2':
  55. $list[$key]['payment'] = '付费知识';
  56. break;
  57. }
  58. }
  59. return view('admin.payment.info.index',compact('list'));
  60. }
  61. function check(Request $request) {
  62. $request = $request->all();
  63. $search['keyword'] = $request->input('keyword');
  64. $orderby = array();
  65. if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  66. $orderby[$request['sort_field']] = $request['sort_field_by'];
  67. }
  68. $list = $this->repository->search($search,$orderby);
  69. return view('admin.payment.info.check',compact('list'));
  70. }
  71. /**
  72. * 添加
  73. *
  74. */
  75. public function create(Request $request)
  76. {
  77. if($request->method() == 'POST') {
  78. return $this->_createSave();
  79. }
  80. return view('admin.payment.info.edit');
  81. }
  82. /**
  83. * 保存修改
  84. */
  85. private function _createSave(){
  86. $data = (array) request('data');
  87. $id = $this->repository->create($data);
  88. if($id) {
  89. $url[] = array('url'=>U( 'Payment/Info/index'),'title'=>'返回列表');
  90. $url[] = array('url'=>U( 'Payment/Info/create'),'title'=>'继续添加');
  91. $this->showMessage('添加成功',$url);
  92. }else{
  93. $url[] = array('url'=>U( 'Payment/Info/index'),'title'=>'返回列表');
  94. return $this->showWarning('添加失败',$url);
  95. }
  96. }
  97. /**
  98. *
  99. * 修改
  100. *
  101. *
  102. */
  103. public function update(Request $request) {
  104. if($request->method() == 'POST') {
  105. return $this->_updateSave();
  106. }
  107. $data = $this->repository->find($request->get('id'));
  108. return view('admin.payment.info.edit',compact('data'));
  109. }
  110. /**
  111. * 保存修改
  112. */
  113. private function _updateSave() {
  114. $data = (array) request('data');
  115. $ok = $this->repository->update(request('id'),$data);
  116. if($ok) {
  117. $url[] = array('url'=>U( 'Payment/Info/index'),'title'=>'返回列表');
  118. return $this->showMessage('操作成功',urldecode(request('_referer')));
  119. }else{
  120. $url[] = array('url'=>U( 'Payment/Info/index'),'title'=>'返回列表');
  121. return $this->showWarning('操作失败',$url);
  122. }
  123. }
  124. public function view(Request $request) {
  125. $data = $this->repository->find(request('id'));
  126. return view('admin.payment.info.view',compact('data'));
  127. }
  128. /**
  129. *
  130. * 状态改变
  131. *
  132. */
  133. public function status(Request $request) {
  134. $ok = $this->repository->updateStatus(request('id'),request('status'));
  135. if($ok) {
  136. return $this->showMessage('操作成功');
  137. }else{
  138. return $this->showWarning('操作失败');
  139. }
  140. }
  141. /**
  142. * 删除
  143. */
  144. public function destroy(Request $request) {
  145. $bool = $this->repository->destroy($request->get('id'));
  146. if($bool) {
  147. return $this->showMessage('操作成功');
  148. }else{
  149. return $this->showWarning("操作失败");
  150. }
  151. }
  152. }