MemberbankcardController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace app\index\controller;
  3. use think\exception\ValidateException;
  4. use app\model\MemberBankcard;
  5. class MemberbankcardController extends Base
  6. {
  7. public function add()
  8. {
  9. $postdata = array_filter($this->getdata());
  10. if (empty($postdata['ptype'])) {
  11. $postdata['ptype'] = 1;
  12. }
  13. $postdata['weid'] = weid();
  14. $mb = MemberBankcard::create($postdata);
  15. $data['id'] = $mb->id;
  16. return $this->json(['data' => $data]);
  17. }
  18. public function update()
  19. {
  20. $postdata = $this->getdata();
  21. $id = (int) input('post.id', '', 'serach_in');
  22. if (empty($postdata['ptype'])) {
  23. $postdata['ptype'] = 1;
  24. }
  25. unset($postdata['weid']);
  26. unset($postdata['uid']);
  27. unset($postdata['isDefault']);
  28. $postdata['id'] = $id;
  29. if (!empty($id)) {
  30. MemberBankcard::update($postdata);
  31. }
  32. $data['id'] = $id;
  33. return $this->json(['data' => $data]);
  34. }
  35. public function delete()
  36. {
  37. $idx = $this->request->post('id', '', 'serach_in');
  38. if (!$idx) throw new ValidateException('参数错误');
  39. MemberBankcard::destroy(['id' => explode(',', $idx)], true);
  40. return $this->json(['msg' => '操作成功']);
  41. }
  42. public function getdata()
  43. {
  44. $postdata['weid'] = weid();
  45. $postdata['uid'] = UID();
  46. $postdata['name'] = input('post.name', '', 'serach_in');
  47. $postdata['ptype'] = input('post.ptype', '', 'serach_in');
  48. $postdata['accounts'] = input('post.accounts', '', 'serach_in');
  49. $postdata['bankname'] = input('post.bankname', '', 'serach_in');
  50. $postdata['branchname'] = input('post.branchname', '', 'serach_in');
  51. if ($postdata['branchname'] == 'undefined') {
  52. $postdata['branchname'] = '';
  53. }
  54. $postdata['isDefault'] = input('post.isDefault', '', 'serach_in');
  55. return $postdata;
  56. }
  57. public function setdefault()
  58. {
  59. $id = (int) input('post.id', '', 'serach_in');
  60. $postdata['isDefault'] = 1;
  61. if (!empty($id)) {
  62. MemberBankcard::where(['weid' => weid(), 'uid' => UID()])->update(['isDefault' => 0]);
  63. $postdata['id'] = $id;
  64. MemberBankcard::update($postdata);
  65. }
  66. $data['id'] = $id;
  67. return $this->json(['data' => $data]);
  68. }
  69. public function detail()
  70. {
  71. $id = (int) input('get.id', '', 'serach_in');
  72. if (!empty($id)) {
  73. $where['weid'] = weid();
  74. $where['uid'] = UID();
  75. $where['id'] = $id;
  76. $data = MemberBankcard::where($where)->find();
  77. if (!empty($data)) {
  78. $data = $data->toArray();
  79. }
  80. }
  81. return $this->json(['data' => $data]);
  82. }
  83. public function default()
  84. {
  85. $where['weid'] = weid();
  86. $where['uid'] = UID();
  87. $data = MemberBankcard::where($where)->order('isDefault desc')->find();
  88. if (!empty($data)) {
  89. $data = $data->toArray();
  90. }
  91. return $this->json(['data' => $data]);
  92. }
  93. public function list()
  94. {
  95. $where['weid'] = weid();
  96. $where['uid'] = UID();
  97. $data = MemberBankcard::where($where)
  98. ->order('isDefault desc')
  99. ->select()
  100. ->toArray();
  101. return $this->json(['data' => $data]);
  102. }
  103. public function listname()
  104. {
  105. $data = getcollect_type();
  106. return $this->json(['data' => $data]);
  107. }
  108. }