InfoController.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. switch ($val['state']) {
  59. case '0':
  60. $list[$key]['state'] = '未处理';
  61. break;
  62. case '1':
  63. $list[$key]['payment'] = '已通过';
  64. break;
  65. case '2':
  66. $list[$key]['payment'] = '已拒绝';
  67. break;
  68. }
  69. }
  70. return view('admin.payment.info.index',compact('list'));
  71. }
  72. function check(Request $request) {
  73. $request = $request->all();
  74. $search['keyword'] = $request->input('keyword');
  75. $orderby = array();
  76. if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  77. $orderby[$request['sort_field']] = $request['sort_field_by'];
  78. }
  79. $list = $this->repository->search($search,$orderby);
  80. return view('admin.payment.info.check',compact('list'));
  81. }
  82. /**
  83. * 添加
  84. *
  85. */
  86. public function create(Request $request)
  87. {
  88. if($request->method() == 'POST') {
  89. return $this->_createSave();
  90. }
  91. return view('admin.payment.info.edit');
  92. }
  93. /**
  94. * 保存修改
  95. */
  96. private function _createSave(){
  97. $data = (array) request('data');
  98. $id = $this->repository->create($data);
  99. if($id) {
  100. $url[] = array('url'=>U( 'Payment/Info/index'),'title'=>'返回列表');
  101. $url[] = array('url'=>U( 'Payment/Info/create'),'title'=>'继续添加');
  102. $this->showMessage('添加成功',$url);
  103. }else{
  104. $url[] = array('url'=>U( 'Payment/Info/index'),'title'=>'返回列表');
  105. return $this->showWarning('添加失败',$url);
  106. }
  107. }
  108. /**
  109. *
  110. * 修改
  111. *
  112. *
  113. */
  114. public function update(Request $request) {
  115. if($request->method() == 'POST') {
  116. return $this->_updateSave();
  117. }
  118. $data = $this->repository->find($request->get('id'));
  119. return view('admin.payment.info.edit',compact('data'));
  120. }
  121. /**
  122. * 保存修改
  123. */
  124. private function _updateSave() {
  125. $data = (array) request('data');
  126. $ok = $this->repository->update(request('id'),$data);
  127. if($ok) {
  128. $url[] = array('url'=>U( 'Payment/Info/index'),'title'=>'返回列表');
  129. return $this->showMessage('操作成功',urldecode(request('_referer')));
  130. }else{
  131. $url[] = array('url'=>U( 'Payment/Info/index'),'title'=>'返回列表');
  132. return $this->showWarning('操作失败',$url);
  133. }
  134. }
  135. public function view(Request $request) {
  136. $data = $this->repository->find(request('id'));
  137. return view('admin.payment.info.view',compact('data'));
  138. }
  139. /**
  140. *
  141. * 状态改变
  142. *
  143. */
  144. public function status(Request $request) {
  145. $ok = $this->repository->updateStatus(request('id'),request('status'));
  146. if($ok) {
  147. return $this->showMessage('操作成功');
  148. }else{
  149. return $this->showWarning('操作失败');
  150. }
  151. }
  152. /**
  153. * 删除
  154. */
  155. public function destroy(Request $request) {
  156. $bool = $this->repository->destroy($request->get('id'));
  157. if($bool) {
  158. return $this->showMessage('操作成功');
  159. }else{
  160. return $this->showWarning("操作失败");
  161. }
  162. }
  163. }