RechargeLogic.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. */
  32. public static function recharge(array $params)
  33. {
  34. try {
  35. $data = [
  36. 'sn' => generate_sn(RechargeOrder::class, 'sn'),
  37. 'order_type'=>1,//充值订单
  38. 'order_terminal' => $params['terminal'],
  39. 'user_id' => $params['user_id'],
  40. 'pay_status' => PayEnum::UNPAID,
  41. 'order_amount' => $params['money'],
  42. ];
  43. $order = RechargeOrder::create($data);
  44. return [
  45. 'order_id' => (int)$order['id'],
  46. 'from' => 'recharge'
  47. ];
  48. } catch (\Exception $e) {
  49. self::setError($e->getMessage());
  50. return false;
  51. }
  52. }
  53. /**
  54. * @notes 充值配置
  55. * @param $userId
  56. * @return array
  57. */
  58. public static function config($userId)
  59. {
  60. $userMoney = User::where(['id' => $userId])->value('user_money');
  61. $minAmount = ConfigService::get('recharge', 'min_amount', 0);
  62. $status = ConfigService::get('recharge', 'status', 0);
  63. return [
  64. 'status' => $status,
  65. 'min_amount' => $minAmount,
  66. 'user_money' => $userMoney,
  67. ];
  68. }
  69. }