Modules_Manage_Controllers_UsdtController.proxy.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <?php
  2. namespace Modules\Manage\Controllers;
  3. use App\Constants\CommonConstant;
  4. use App\Repositories\Criterias\OrderLimitCriteria;
  5. use App\Repositories\Criterias\UsdtChainLimitCriteria;
  6. use App\Repositories\UsdtChainRepository;
  7. use App\Repositories\UsdtTypeRepository;
  8. use Hyperf\Validation\Contract\ValidatorFactoryInterface;
  9. use Modules\Manage\Responses\CommonPagesResponse;
  10. use Modules\Manage\Responses\CommonSuccessPkResponse;
  11. use Modules\Manage\Responses\PaymentSuccessUidResponse;
  12. class UsdtController extends BaseController
  13. {
  14. use \Hyperf\Di\Aop\ProxyTrait;
  15. use \Hyperf\Di\Aop\PropertyHandlerTrait;
  16. function __construct()
  17. {
  18. if (method_exists(parent::class, '__construct')) {
  19. parent::__construct(...func_get_args());
  20. }
  21. $this->__handlePropertyHandler(__CLASS__);
  22. }
  23. /**
  24. * usdt类型列表
  25. *
  26. * @param ValidatorFactoryInterface $validatorFactory
  27. * @return mixed|CommonPagesResponse
  28. */
  29. public function lists(ValidatorFactoryInterface $validatorFactory)
  30. {
  31. $inputData = $this->getJsonData();
  32. $rules = ['page' => 'required|int', 'page_size' => 'required|int'];
  33. $validator = $validatorFactory->make($inputData, $rules);
  34. if ($validator->fails()) {
  35. return json_fail($validator->errors()->first());
  36. }
  37. $orders = [['id', 'DESC']];
  38. $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
  39. if ($pageSize > 500) {
  40. $pageSize = CommonConstant::PAGE_SIZE;
  41. }
  42. $page = format_page($inputData['page'] ?? 1);
  43. $res = make(UsdtTypeRepository::class)->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
  44. return new CommonPagesResponse($res);
  45. }
  46. /**
  47. * 新增usdt类型
  48. *
  49. * @param ValidatorFactoryInterface $validatorFactory
  50. * @return mixed|CommonSuccessPkResponse
  51. */
  52. public function add(ValidatorFactoryInterface $validatorFactory)
  53. {
  54. $inputData = $this->getJsonData();
  55. $rules = ['name' => 'required|string', 'code' => 'required|string', 'chain_type' => 'required|string'];
  56. $validator = $validatorFactory->make($inputData, $rules);
  57. if ($validator->fails()) {
  58. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  59. return json_fail($validator->errors()->first());
  60. }
  61. $setarr = ['name' => $inputData['name'], 'code' => $inputData['code'], 'chain_type' => $inputData['chain_type']];
  62. $result = make(UsdtTypeRepository::class)->create($setarr);
  63. if (!$result) {
  64. return json_fail('创建失败');
  65. } else {
  66. $logSubject = '添加一个新的usdt类型:' . $inputData['name'] . '-' . $inputData['code'];
  67. $logSvalue = $result->id;
  68. $logDbData = ['after_items' => [$result->toArray()], 'before_items' => []];
  69. $this->log($logSubject, $logSvalue, $logDbData);
  70. return new CommonSuccessPkResponse($result->uid);
  71. }
  72. }
  73. /**
  74. * 修改usdt类型
  75. *
  76. * @param ValidatorFactoryInterface $validatorFactory
  77. * @return mixed
  78. */
  79. public function update(ValidatorFactoryInterface $validatorFactory)
  80. {
  81. $inputData = $this->getJsonData();
  82. $rules = ['name' => 'nullable|string', 'code' => 'nullable|string', 'status' => 'nullable|in:1,2', 'chain_type' => 'nullable|string', 'uid' => 'required'];
  83. $validator = $validatorFactory->make($inputData, $rules);
  84. if ($validator->fails()) {
  85. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  86. return json_fail($validator->errors()->first());
  87. }
  88. $usdtTypeInfo = make(UsdtTypeRepository::class)->findBy('uid', $inputData['uid']);
  89. if (!$usdtTypeInfo) {
  90. return json_fail('该支付类型不存在!');
  91. }
  92. $oldUsdtTypeInfo = clone $usdtTypeInfo;
  93. if (!empty($inputData['name'])) {
  94. $usdtTypeInfo->name = $inputData['name'];
  95. }
  96. if (!empty($inputData['code'])) {
  97. $usdtTypeInfo->code = $inputData['code'];
  98. }
  99. if (!empty($inputData['status'])) {
  100. $usdtTypeInfo->status = $inputData['status'];
  101. }
  102. if (!empty($inputData['chain_type'])) {
  103. $usdtTypeInfo->chain_type = $inputData['chain_type'];
  104. }
  105. if (!$usdtTypeInfo->save()) {
  106. return json_fail('修改失败!');
  107. } else {
  108. $logSubject = '修改usdt类型:' . $oldUsdtTypeInfo->name;
  109. $logSvalue = $usdtTypeInfo->id;
  110. $logDbData = ['after_items' => [$usdtTypeInfo->toArray()], 'before_items' => [$oldUsdtTypeInfo->toArray()]];
  111. $this->log($logSubject, $logSvalue, $logDbData);
  112. }
  113. return new CommonSuccessPkResponse($oldUsdtTypeInfo->id);
  114. }
  115. /**
  116. * usdt支付链列表
  117. *
  118. * @param ValidatorFactoryInterface $validatorFactory
  119. * @return mixed|CommonPagesResponse
  120. */
  121. public function chainLists(ValidatorFactoryInterface $validatorFactory)
  122. {
  123. $inputData = $this->getJsonData();
  124. $rules = ['page' => 'required|int', 'page_size' => 'required|int', 'is_lock' => 'nullable|in:1,2', 'chain_address' => 'nullable', 'usdt_type_uid' => 'nullable'];
  125. $validator = $validatorFactory->make($inputData, $rules);
  126. if ($validator->fails()) {
  127. return json_fail($validator->errors()->first());
  128. }
  129. $orders = [['id', 'DESC']];
  130. $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
  131. if ($pageSize > 500) {
  132. $pageSize = CommonConstant::PAGE_SIZE;
  133. }
  134. $page = format_page($inputData['page'] ?? 1);
  135. $res = make(UsdtChainRepository::class)->pushCriteria(new UsdtChainLimitCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
  136. return new CommonPagesResponse($res);
  137. }
  138. /**
  139. * usdt支付链添加
  140. *
  141. * @param ValidatorFactoryInterface $validatorFactory
  142. * @return mixed|PaymentSuccessUidResponse
  143. */
  144. public function chainAdd(ValidatorFactoryInterface $validatorFactory)
  145. {
  146. $inputData = $this->getJsonData();
  147. $rules = ['usdt_type_uid' => 'required|string', 'chain_address' => 'required|string'];
  148. $validator = $validatorFactory->make($inputData, $rules);
  149. if ($validator->fails()) {
  150. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  151. return json_fail($validator->errors()->first());
  152. }
  153. $setarr = ['usdt_type_uid' => $inputData['usdt_type_uid'], 'chain_address' => $inputData['chain_address']];
  154. $result = make(UsdtChainRepository::class)->create($setarr);
  155. if (!$result) {
  156. return json_fail('添加usdt支付链失败');
  157. } else {
  158. $logSubject = '添加了一个usdt支付链:' . $inputData['chain_address'];
  159. $logSvalue = $result->id;
  160. $logDbData = ['after_items' => [$result->toArray()], 'before_items' => []];
  161. $this->log($logSubject, $logSvalue, $logDbData);
  162. return new PaymentSuccessUidResponse($result->manager_id);
  163. }
  164. }
  165. /**
  166. * usdt支付链修改
  167. *
  168. * @param ValidatorFactoryInterface $validatorFactory
  169. * @return mixed|CommonSuccessPkResponse
  170. */
  171. public function chainUpdate(ValidatorFactoryInterface $validatorFactory)
  172. {
  173. $inputData = $this->getJsonData();
  174. $rules = ['uid' => 'required|string', 'usdt_type_uid' => 'nullable|string', 'chain_address' => 'nullable|string', 'is_lock' => 'nullable|in:1,2'];
  175. $validator = $validatorFactory->make($inputData, $rules);
  176. if ($validator->fails()) {
  177. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  178. return json_fail($validator->errors()->first());
  179. }
  180. $usdtChainInfo = make(UsdtChainRepository::class)->findBy('uid', $inputData['uid']);
  181. if (!$usdtChainInfo) {
  182. return json_fail('该usdt支付链接不存在!');
  183. }
  184. $oldUsdtChainInfo = $usdtChainInfo;
  185. if (!empty($inputData['usdt_type_uid'])) {
  186. $usdtChainInfo->usdt_type_uid = $inputData['usdt_type_uid'];
  187. }
  188. if (!empty($inputData['chain_address'])) {
  189. $usdtChainInfo->chain_address = $inputData['chain_address'];
  190. }
  191. if (!empty($inputData['is_lock'])) {
  192. $usdtChainInfo->is_lock = $inputData['is_lock'];
  193. }
  194. $result = $usdtChainInfo->save();
  195. if (!$result) {
  196. return json_fail('修改失败');
  197. } else {
  198. $logSubject = '修改usdt链:' . $usdtChainInfo->chain_address;
  199. $logSvalue = $usdtChainInfo->id;
  200. $logDbData = ['after_items' => [$usdtChainInfo->toArray()], 'before_items' => [$oldUsdtChainInfo->toArray()]];
  201. $this->log($logSubject, $logSvalue, $logDbData);
  202. }
  203. return new CommonSuccessPkResponse($usdtChainInfo->id);
  204. }
  205. /**
  206. * usdt支付链删除
  207. *
  208. * @param ValidatorFactoryInterface $validatorFactory
  209. * @return mixed|CommonSuccessPkResponse
  210. */
  211. public function chainDelete(ValidatorFactoryInterface $validatorFactory)
  212. {
  213. $inputData = $this->getJsonData();
  214. $rules = ['uid' => 'required|string'];
  215. $validator = $validatorFactory->make($inputData, $rules);
  216. if ($validator->fails()) {
  217. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  218. return json_fail($validator->errors()->first());
  219. }
  220. $usdtChainInfo = make(UsdtChainRepository::class)->find($inputData['id']);
  221. if (!$usdtChainInfo) {
  222. return json_fail('该usdt支付链接不存在!');
  223. }
  224. $oldUsdtChainInfo = $usdtChainInfo;
  225. $result = $usdtChainInfo->delete();
  226. if (!$result) {
  227. return json_fail('删除失败');
  228. } else {
  229. $logSubject = '删除usdt支付链:' . $oldUsdtChainInfo->chain_address;
  230. $logSvalue = $oldUsdtChainInfo->id;
  231. $logDbData = ['after_items' => [], 'before_items' => [$oldUsdtChainInfo->toArray()]];
  232. $this->log($logSubject, $logSvalue, $logDbData);
  233. return new CommonSuccessPkResponse($inputData['id']);
  234. }
  235. }
  236. /**
  237. * usdt类型下拉
  238. *
  239. * @return CommonPagesResponse
  240. */
  241. public function usdtTypeDown()
  242. {
  243. $res = make(UsdtTypeRepository::class)->all(['name', 'uid'])->keyBy('uid');
  244. return new CommonPagesResponse($res);
  245. }
  246. }