PayConfigController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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|string|in:palmpay,wechatpay,tiktokpay',
  21. 'miniprogram_type' => 'nullable|string|in:wechat,tiktok',
  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. foreach ($result as $item) {
  50. $item->pay_type_str = $commonConfig['payType'][$item->pay_type] ?? '';
  51. $item->miniprogram_type_str = $commonConfig['miniprogramType'][$item->miniprogram_type] ?? '';
  52. }
  53. return $result;
  54. }
  55. /**
  56. * 修改备注
  57. * @param Request $request
  58. */
  59. public function remark(Request $request) {
  60. $this->validate($request, ['id' => 'required']);
  61. DB::table('pay_merchants')
  62. ->where(['id' => $request->input('id')])
  63. ->update(['remark' => $request->input('remark', ''),
  64. 'updated_at' => date('Y-m-d H:i:s')]);
  65. return 'ok';
  66. }
  67. /**
  68. * 添加支付配置信息
  69. * @param Request $request
  70. */
  71. public function addConfig(Request $request) {
  72. $this->validate($request, [
  73. 'name' => 'required|string|max:256',
  74. 'payee_name' => 'required|string|max:256',
  75. 'pay_appid' => 'required',
  76. 'pay_type' => 'required|string|in:palmpay,wechatpay,tiktokpay',
  77. 'pay_common_params' => 'required',
  78. 'miniprogram_type' => 'required|in:wechat,tiktok',
  79. 'remark' => 'nullable|string|max:256'
  80. ]);
  81. $data = $request->only(['name', 'payee_name', 'pay_appid', 'pay_type', 'miniprogram_type']);
  82. $now = date('Y-m-d H:i:s');
  83. $data['created_at'] = $data['updated_at'] = $now;
  84. $data['remark'] = $request->input('remark', '');
  85. DB::table('pay_merchants')
  86. ->insert($data);
  87. return 'ok';
  88. }
  89. }