PayConfigController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace Modules\Manage\Http\Controllers;
  3. use Catch\Base\CatchController;
  4. use Illuminate\Foundation\Validation\ValidatesRequests;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\DB;
  7. /**
  8. * 支付配置管理
  9. */
  10. class PayConfigController extends CatchController
  11. {
  12. use ValidatesRequests;
  13. /**
  14. * 配置列表
  15. * @param Request $request
  16. */
  17. public function list(Request $request) {
  18. $this->validate($request,[
  19. 'name' => 'nullable|string|max:256',
  20. 'pay_type' => 'nullable|in:1,2,3',
  21. 'miniprogram_type' => 'nullable|in:1,2',
  22. 'remark' => 'nullable|string|max:256',
  23. 'pay_appid' => 'nullable|string|max:256',
  24. ]);
  25. $name = $request->input('name');
  26. $payType = $request->input('pay_type');
  27. $miniprogramType = $request->input('miniprogram_type');
  28. $payAppid = $request->input('pay_appid');
  29. $remark = $request->input('remark');
  30. $isAll = $request->input('is_all', 0);
  31. $commonConfig = config('common.common');
  32. $sql = DB::table('pay_merchants')
  33. ->when($name, function ($query, $name){
  34. return $query->where('name', 'like', '%'. $name .'%');
  35. })->when($payType, function ($query, $payType){
  36. return $query->where('pay_type', $payType);
  37. })->when($miniprogramType, function ($query, $miniprogramType) {
  38. return $query->where('miniprogram_type', $miniprogramType);
  39. })->when($payAppid, function ($query, $payAppid) {
  40. return $query->where('pay_appid', $payAppid);
  41. })->when($remark, function ($query, $remark){
  42. return $query->where('remark', 'like', '%'. $remark. '%');
  43. })->orderBy('id', 'desc');
  44. if($isAll) {
  45. $result = $sql->get();
  46. } else {
  47. $result = $sql->paginate($request->input('limit', 15));
  48. }
  49. $payTypeMap = collect($commonConfig['payType'])->keyBy('key');
  50. $miniprogramTypeMap = collect($commonConfig['miniprogramType'])->keyBy('key');
  51. foreach ($result as $item) {
  52. $item->pay_type_str = $payTypeMap[$item->pay_type]['val'] ?? '';
  53. $item->miniprogram_type_str = $miniprogramTypeMap[$item->miniprogram_type]['val'] ?? '';
  54. }
  55. return $result;
  56. }
  57. /**
  58. * 修改备注
  59. * @param Request $request
  60. */
  61. public function remark(Request $request) {
  62. $this->validate($request, ['id' => 'required']);
  63. DB::table('pay_merchants')
  64. ->where(['id' => $request->input('id')])
  65. ->update(['remark' => $request->input('remark', ''),
  66. 'updated_at' => date('Y-m-d H:i:s')]);
  67. return 'ok';
  68. }
  69. /**
  70. * 添加支付配置信息
  71. * @param Request $request
  72. */
  73. public function addConfig(Request $request) {
  74. $this->validate($request, [
  75. 'name' => 'required|string|max:256',
  76. 'payee_name' => 'required|string|max:256',
  77. 'pay_appid' => 'required',
  78. 'pay_type' => 'required|integer|in:1,2,3',
  79. 'pay_common_params' => 'required',
  80. 'miniprogram_type' => 'required|in:1,2',
  81. 'remark' => 'nullable|string|max:256'
  82. ]);
  83. $data = $request->only(['name', 'payee_name', 'pay_appid', 'pay_type', 'miniprogram_type']);
  84. $now = date('Y-m-d H:i:s');
  85. $data['created_at'] = $data['updated_at'] = $now;
  86. $data['pay_common_params'] = \json_encode($request->input('pay_common_params', []));
  87. $data['remark'] = $request->input('remark', '');
  88. DB::table('pay_merchants')
  89. ->insert($data);
  90. return 'ok';
  91. }
  92. }