RechargeLogic.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. /**
  55. * @notes 充值配置
  56. * @param $userId
  57. * @return array
  58. * @author 段誉
  59. * @date 2023/2/24 16:56
  60. */
  61. public static function config($userId)
  62. {
  63. $userMoney = User::where(['id' => $userId])->value('user_money');
  64. $minAmount = ConfigService::get('recharge', 'min_amount', 0);
  65. $status = ConfigService::get('recharge', 'status', 0);
  66. return [
  67. 'status' => $status,
  68. 'min_amount' => $minAmount,
  69. 'user_money' => $userMoney,
  70. ];
  71. }
  72. }