RechargeLogic.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\api\logic;
  15. use app\common\enum\PayEnum;
  16. use app\common\logic\BaseLogic;
  17. use app\common\model\recharge\RechargeOrder;
  18. use app\common\model\user\User;
  19. use app\common\service\ConfigService;
  20. /**
  21. * 充值逻辑层
  22. * Class RechargeLogic
  23. * @package app\shopapi\logic
  24. */
  25. class RechargeLogic extends BaseLogic
  26. {
  27. /**
  28. * @notes 充值
  29. * @param array $params
  30. * @return array|false
  31. * @author 段誉
  32. * @date 2023/2/24 10:43
  33. */
  34. public static function recharge(array $params)
  35. {
  36. try {
  37. $data = [
  38. 'sn' => generate_sn(RechargeOrder::class, 'sn'),
  39. 'order_terminal' => $params['terminal'],
  40. 'user_id' => $params['user_id'],
  41. 'pay_status' => PayEnum::UNPAID,
  42. 'order_amount' => $params['money'],
  43. ];
  44. $order = RechargeOrder::create($data);
  45. return [
  46. 'order_id' => (int)$order['id'],
  47. 'from' => 'recharge'
  48. ];
  49. } catch (\Exception $e) {
  50. self::setError($e->getMessage());
  51. return false;
  52. }
  53. }
  54. public static function detail($order_id){
  55. try {
  56. $order = RechargeOrder::find($order_id)->toArray();
  57. return $order;
  58. } catch (\Exception $e) {
  59. self::setError($e->getMessage());
  60. return false;
  61. }
  62. }
  63. /**
  64. * @notes 充值配置
  65. * @param $userId
  66. * @return array
  67. * @author 段誉
  68. * @date 2023/2/24 16:56
  69. */
  70. public static function config($userId)
  71. {
  72. $userMoney = User::where(['id' => $userId])->value('user_money');
  73. $minAmount = ConfigService::get('recharge', 'min_amount', 0);
  74. $status = ConfigService::get('recharge', 'status', 0);
  75. return [
  76. 'status' => $status,
  77. 'min_amount' => $minAmount,
  78. 'user_money' => $userMoney,
  79. ];
  80. }
  81. }