DepositAddress.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use app\admin\model\DepositAddress;
  5. use app\admin\validate\DepositAddressValidate;
  6. use Exception;
  7. use think\facade\Db;
  8. class DepositAddresses extends BaseController
  9. {
  10. /**
  11. * 区块链地址删除
  12. */
  13. function delete()
  14. {
  15. Db::startTrans();
  16. try {
  17. $params = $this->request->param();
  18. $count = DepositAddress::where('id', $params['id'])->delete();
  19. if ($count < 1) throw new Exception('操作失败');
  20. Db::commit();
  21. } catch (Exception $e) {
  22. Db::rollBack();
  23. return $this->error($e->getMessage());
  24. }
  25. return $this->success();
  26. }
  27. /**
  28. * /blockChain/update 区块链地址更新
  29. */
  30. public function update()
  31. {
  32. $errors = [];
  33. Db::startTrans();
  34. try {
  35. $params = (new DepositAddressValidate)->post()->goCheck('edit');
  36. $params['operator_id'] = $this->admin_id;
  37. $params['security_code'] = $params['security_code'] ?? '';
  38. $params['withdraw_fee'] = $params['withdraw_fee'] ?? 0;
  39. if (!empty($params['id'])) {
  40. if (DepositAddress::where('id', "<>", $params['id'])
  41. ->where('currency', $params['currency'])
  42. ->where('network_type', $params['network_type'])->value('id')) {
  43. $errors = ['currency' => $params['currency'], 'network_type' => $params['network_type']];
  44. throw new Exception('区块链地址已存在');
  45. }
  46. $chain = DepositAddress::findOrFail($params['id']);
  47. unset($params['id']);
  48. $chain->update($params);
  49. } else {
  50. if (DepositAddress::where('currency', $params['currency'])
  51. ->where('network_type', $params['network_type'])->value('id')) {
  52. $errors = [
  53. 'currency' => $params['currency'],
  54. 'network_type' => $params['network_type']
  55. ];
  56. throw new Exception('区块链地址已存在');
  57. }
  58. unset($params['id']);
  59. DepositAddress::create($params);
  60. }
  61. Db::commit();
  62. } catch (Exception $e) {
  63. Db::rollBack();
  64. return $this->error($e->getMessage(), $errors);
  65. }
  66. return $this->success();
  67. }
  68. /**
  69. * 区块链地址列表
  70. */
  71. function index()
  72. {
  73. try {
  74. $page = $this->request->param('page', 1);
  75. $limit = $this->request->param('limit', 15);
  76. $query = new DepositAddress();
  77. $count = $query->count();
  78. $list = $query
  79. ->limit($limit)
  80. ->page($page)
  81. ->order('currency','asc')
  82. ->selete()->toArray();
  83. } catch (Exception $e) {
  84. return $this->error($e->getMessage());
  85. }
  86. return $this->success(['count' => $count, 'list' => $list]);
  87. }
  88. }