| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <?php
- namespace Modules\Manage\Controllers;
- use App\Constants\CommonConstant;
- use App\Repositories\Criterias\OrderLimitCriteria;
- use App\Repositories\Criterias\UsdtChainLimitCriteria;
- use App\Repositories\UsdtChainRepository;
- use App\Repositories\UsdtTypeRepository;
- use Hyperf\Validation\Contract\ValidatorFactoryInterface;
- use Modules\Manage\Responses\CommonPagesResponse;
- use Modules\Manage\Responses\CommonSuccessPkResponse;
- use Modules\Manage\Responses\PaymentSuccessUidResponse;
- class UsdtController extends BaseController
- {
- use \Hyperf\Di\Aop\ProxyTrait;
- use \Hyperf\Di\Aop\PropertyHandlerTrait;
- function __construct()
- {
- if (method_exists(parent::class, '__construct')) {
- parent::__construct(...func_get_args());
- }
- $this->__handlePropertyHandler(__CLASS__);
- }
- /**
- * usdt类型列表
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed|CommonPagesResponse
- */
- public function lists(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $rules = ['page' => 'required|int', 'page_size' => 'required|int'];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- return json_fail($validator->errors()->first());
- }
- $orders = [['id', 'DESC']];
- $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
- if ($pageSize > 500) {
- $pageSize = CommonConstant::PAGE_SIZE;
- }
- $page = format_page($inputData['page'] ?? 1);
- $res = make(UsdtTypeRepository::class)->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
- return new CommonPagesResponse($res);
- }
- /**
- * 新增usdt类型
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed|CommonSuccessPkResponse
- */
- public function add(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $rules = ['name' => 'required|string', 'code' => 'required|string', 'chain_type' => 'required|string'];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $setarr = ['name' => $inputData['name'], 'code' => $inputData['code'], 'chain_type' => $inputData['chain_type']];
- $result = make(UsdtTypeRepository::class)->create($setarr);
- if (!$result) {
- return json_fail('创建失败');
- } else {
- $logSubject = '添加一个新的usdt类型:' . $inputData['name'] . '-' . $inputData['code'];
- $logSvalue = $result->id;
- $logDbData = ['after_items' => [$result->toArray()], 'before_items' => []];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new CommonSuccessPkResponse($result->uid);
- }
- }
- /**
- * 修改usdt类型
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed
- */
- public function update(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $rules = ['name' => 'nullable|string', 'code' => 'nullable|string', 'status' => 'nullable|in:1,2', 'chain_type' => 'nullable|string', 'uid' => 'required'];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $usdtTypeInfo = make(UsdtTypeRepository::class)->findBy('uid', $inputData['uid']);
- if (!$usdtTypeInfo) {
- return json_fail('该支付类型不存在!');
- }
- $oldUsdtTypeInfo = clone $usdtTypeInfo;
- if (!empty($inputData['name'])) {
- $usdtTypeInfo->name = $inputData['name'];
- }
- if (!empty($inputData['code'])) {
- $usdtTypeInfo->code = $inputData['code'];
- }
- if (!empty($inputData['status'])) {
- $usdtTypeInfo->status = $inputData['status'];
- }
- if (!empty($inputData['chain_type'])) {
- $usdtTypeInfo->chain_type = $inputData['chain_type'];
- }
- if (!$usdtTypeInfo->save()) {
- return json_fail('修改失败!');
- } else {
- $logSubject = '修改usdt类型:' . $oldUsdtTypeInfo->name;
- $logSvalue = $usdtTypeInfo->id;
- $logDbData = ['after_items' => [$usdtTypeInfo->toArray()], 'before_items' => [$oldUsdtTypeInfo->toArray()]];
- $this->log($logSubject, $logSvalue, $logDbData);
- }
- return new CommonSuccessPkResponse($oldUsdtTypeInfo->id);
- }
- /**
- * usdt支付链列表
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed|CommonPagesResponse
- */
- public function chainLists(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $rules = ['page' => 'required|int', 'page_size' => 'required|int', 'is_lock' => 'nullable|in:1,2', 'chain_address' => 'nullable', 'usdt_type_uid' => 'nullable'];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- return json_fail($validator->errors()->first());
- }
- $orders = [['id', 'DESC']];
- $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
- if ($pageSize > 500) {
- $pageSize = CommonConstant::PAGE_SIZE;
- }
- $page = format_page($inputData['page'] ?? 1);
- $res = make(UsdtChainRepository::class)->pushCriteria(new UsdtChainLimitCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
- return new CommonPagesResponse($res);
- }
- /**
- * usdt支付链添加
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed|PaymentSuccessUidResponse
- */
- public function chainAdd(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $rules = ['usdt_type_uid' => 'required|string', 'chain_address' => 'required|string'];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $setarr = ['usdt_type_uid' => $inputData['usdt_type_uid'], 'chain_address' => $inputData['chain_address']];
- $result = make(UsdtChainRepository::class)->create($setarr);
- if (!$result) {
- return json_fail('添加usdt支付链失败');
- } else {
- $logSubject = '添加了一个usdt支付链:' . $inputData['chain_address'];
- $logSvalue = $result->id;
- $logDbData = ['after_items' => [$result->toArray()], 'before_items' => []];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new PaymentSuccessUidResponse($result->manager_id);
- }
- }
- /**
- * usdt支付链修改
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed|CommonSuccessPkResponse
- */
- public function chainUpdate(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $rules = ['uid' => 'required|string', 'usdt_type_uid' => 'nullable|string', 'chain_address' => 'nullable|string', 'is_lock' => 'nullable|in:1,2'];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $usdtChainInfo = make(UsdtChainRepository::class)->findBy('uid', $inputData['uid']);
- if (!$usdtChainInfo) {
- return json_fail('该usdt支付链接不存在!');
- }
- $oldUsdtChainInfo = $usdtChainInfo;
- if (!empty($inputData['usdt_type_uid'])) {
- $usdtChainInfo->usdt_type_uid = $inputData['usdt_type_uid'];
- }
- if (!empty($inputData['chain_address'])) {
- $usdtChainInfo->chain_address = $inputData['chain_address'];
- }
- if (!empty($inputData['is_lock'])) {
- $usdtChainInfo->is_lock = $inputData['is_lock'];
- }
- $result = $usdtChainInfo->save();
- if (!$result) {
- return json_fail('修改失败');
- } else {
- $logSubject = '修改usdt链:' . $usdtChainInfo->chain_address;
- $logSvalue = $usdtChainInfo->id;
- $logDbData = ['after_items' => [$usdtChainInfo->toArray()], 'before_items' => [$oldUsdtChainInfo->toArray()]];
- $this->log($logSubject, $logSvalue, $logDbData);
- }
- return new CommonSuccessPkResponse($usdtChainInfo->id);
- }
- /**
- * usdt支付链删除
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed|CommonSuccessPkResponse
- */
- public function chainDelete(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $rules = ['uid' => 'required|string'];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $usdtChainInfo = make(UsdtChainRepository::class)->find($inputData['id']);
- if (!$usdtChainInfo) {
- return json_fail('该usdt支付链接不存在!');
- }
- $oldUsdtChainInfo = $usdtChainInfo;
- $result = $usdtChainInfo->delete();
- if (!$result) {
- return json_fail('删除失败');
- } else {
- $logSubject = '删除usdt支付链:' . $oldUsdtChainInfo->chain_address;
- $logSvalue = $oldUsdtChainInfo->id;
- $logDbData = ['after_items' => [], 'before_items' => [$oldUsdtChainInfo->toArray()]];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new CommonSuccessPkResponse($inputData['id']);
- }
- }
- /**
- * usdt类型下拉
- *
- * @return CommonPagesResponse
- */
- public function usdtTypeDown()
- {
- $res = make(UsdtTypeRepository::class)->all(['name', 'uid'])->keyBy('uid');
- return new CommonPagesResponse($res);
- }
- }
|