UserMember.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\store\user;
  12. use app\services\order\OtherOrderServices;
  13. use app\services\pay\OrderPayServices;
  14. use app\services\user\member\MemberShipServices;
  15. use app\services\user\UserServices;
  16. use think\facade\App;
  17. use app\controller\store\AuthController;
  18. /**
  19. * 付费会员类
  20. * Class UserMember
  21. * @package app\controller\store\user
  22. */
  23. class UserMember extends AuthController
  24. {
  25. protected $services = NUll;
  26. /**
  27. * UserMember constructor.
  28. * @param App $app
  29. * @param MemberShipServices $services
  30. */
  31. public function __construct(App $app, MemberShipServices $services)
  32. {
  33. parent::__construct($app);
  34. $this->services = $services;
  35. }
  36. /**
  37. * svip选择
  38. * @return mixed
  39. */
  40. public function index()
  41. {
  42. $isOpen = sys_config('member_card_status', 1);
  43. $data = [];
  44. if ($isOpen) {
  45. $data = $this->services->getApiList(['is_del' => 0]);
  46. }
  47. return app('json')->successful($data);
  48. }
  49. /**
  50. * 购买svip
  51. * @param UserServices $userServices
  52. * @param OtherOrderServices $otherOrderServices
  53. * @return mixed
  54. * @throws \think\db\exception\DataNotFoundException
  55. * @throws \think\db\exception\DbException
  56. * @throws \think\db\exception\ModelNotFoundException
  57. */
  58. public function payMember(UserServices $userServices, OtherOrderServices $otherOrderServices)
  59. {
  60. [$uid, $memberId] = $this->request->postMore([
  61. ['uid', 0],
  62. ['member_id', 0],
  63. ], true);
  64. if (!(int)$memberId) {
  65. return app('json')->fail('缺少购买会员类型ID');
  66. }
  67. $uid = (int)$uid;
  68. $memberInfo = $this->services->getMemberInfo((int)$memberId);
  69. $userInfo = $userServices->getUserInfo($uid);
  70. if (!$userInfo) {
  71. return app('json')->fail('用户不存在');
  72. }
  73. $order = $otherOrderServices->createOrder($uid, (int)$memberId, '0', $userInfo['user_type'],'weixin', $memberInfo['type'] == 'free' ? 0 : 1, (int)$this->storeId, (int)$this->storeStaffId);
  74. if (!$order) {
  75. return app('json')->fail('创建付费会员订单失败');
  76. }
  77. $order = $order->toArray();
  78. $info = ['order_id' => $order['order_id']];
  79. //支付金额为0
  80. if (bcsub((string)$order['pay_price'], '0', 2) <= 0) {
  81. //创建订单jspay支付
  82. $payPriceStatus = $otherOrderServices->zeroYuanPayment($order);
  83. if ($payPriceStatus)//0元支付成功
  84. return app('json')->status('success', '激活成功', $info);
  85. else
  86. return app('json')->status('pay_error');
  87. } else {
  88. /** @var OrderPayServices $payServices */
  89. $payServices = app()->make(OrderPayServices::class);
  90. $info['jsConfig'] = $payServices->orderPay($order, 'store');
  91. return app('json')->status('wechat_h5_pay', '前往支付', $info);
  92. }
  93. }
  94. }