PaymethodController.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\Paymethod;
  5. class PaymethodController extends Base
  6. {
  7. function index()
  8. {
  9. $weid = weid();
  10. $keyword = input('post.keyword', '', 'serach_in');
  11. Paymethod::datainitial();
  12. $query = Paymethod::where(['weid' => $weid]);
  13. if (!empty($keyword)) {
  14. $query->where('title', 'like', '%' . $keyword . '%');
  15. }
  16. $res = $query->order('sort asc')
  17. ->paginate(getpage())
  18. ->toArray();
  19. $data['data'] = $res;
  20. return $this->json($data);
  21. }
  22. function listUpdate()
  23. {
  24. $data = only('id,status');
  25. if (!$data['id']) throw new ValidateException('参数错误');
  26. Paymethod::update($data);
  27. return $this->json(['msg' => '操作成功']);
  28. }
  29. public function update()
  30. {
  31. $id = $this->request->post('id');
  32. $data = input('post.');
  33. unset($data['create_time']);
  34. $data['settings'] = serialize($data['settings']);
  35. if (empty($id)) {
  36. $data['weid'] = weid();
  37. try {
  38. $res = Paymethod::create($data);
  39. } catch (\Exception $e) {
  40. throw new ValidateException($e->getMessage());
  41. }
  42. return $this->json(['msg' => '添加成功', 'data' => $res->id]);
  43. } else {
  44. try {
  45. Paymethod::update($data);
  46. } catch (\Exception $e) {
  47. throw new ValidateException($e->getMessage());
  48. }
  49. return $this->json(['msg' => '修改成功']);
  50. }
  51. }
  52. function getInfo()
  53. {
  54. $id = $this->request->post('id', '', 'serach_in');
  55. if (!$id) throw new ValidateException('参数错误');
  56. $data = Paymethod::field('*')->find($id)->toArray();
  57. $data['settings'] = iunserializer($data['settings']);
  58. if(empty($data['settings'])){
  59. $data['settings'] = ['mchid'=>'','signkey'=>''];
  60. }
  61. return $this->json(['data' => $data]);
  62. }
  63. function delete()
  64. {
  65. return $this->del(new Paymethod());
  66. }
  67. }