User.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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\out;
  12. use app\Request;
  13. use app\services\out\UserServices;
  14. use app\services\user\UserAddressServices;
  15. use app\services\user\UserMoneyServices;
  16. /**
  17. * 用户类
  18. * Class StoreProductController
  19. * @package app\api\controller\store
  20. */
  21. class User
  22. {
  23. /**
  24. * 用户services
  25. * @var UserServices
  26. */
  27. protected $services;
  28. public function __construct(UserServices $services)
  29. {
  30. $this->services = $services;
  31. }
  32. /**
  33. * 获取用户信息
  34. * @param string $uid
  35. * @return mixed
  36. */
  37. public function index($uid)
  38. {
  39. return app('json')->success($this->services->getUserInfo($uid, 'uid,phone,nickname,now_money,integral,addres'));
  40. }
  41. /**
  42. * 执行编辑其他
  43. * @param Request $request
  44. * @param int $id
  45. * @return mixed
  46. */
  47. public function update_other(Request $request, $id = 0)
  48. {
  49. $data = $request->postMore([
  50. ['money_status', 0],
  51. ['money', 0],
  52. ['integration_status', 0],
  53. ['integration', 0],
  54. ]);
  55. if (!$id) return $this->fail('数据不存在');
  56. $data['adminId'] = $request->outId;
  57. $data['money'] = (string)$data['money'];
  58. $data['integration'] = (string)$data['integration'];
  59. $data['is_other'] = true;
  60. return app('json')->success($this->services->updateInfo($id, $data) ? '修改成功' : '修改失败');
  61. }
  62. /**
  63. *
  64. * @param Request $request
  65. * @param $id
  66. * @return mixed
  67. */
  68. public function update(Request $request, $id)
  69. {
  70. $data = $request->postMore([
  71. ['phone', 0],
  72. ['addres', ''],
  73. ['real_name', ''],
  74. ['card_id', ''],
  75. ['birthday', '']
  76. ]);
  77. if ($data['phone']) {
  78. if (!check_phone($data['phone'])) return app('json')->fail('手机号码格式不正确');
  79. }
  80. if ($data['card_id']) {
  81. try {
  82. if (!check_card($data['card_id'])) return app('json')->fail('请输入正确的身份证');
  83. } catch (\Throwable $e) {
  84. // return app('json')->fail('请输入正确的身份证');
  85. }
  86. }
  87. if (!$id) return app('json')->fail('数据不存在');
  88. $data['adminId'] = $request->outId;
  89. return app('json')->success($this->services->updateInfo($id, $data) ? '修改成功' : '修改失败');
  90. }
  91. /**
  92. * 获取地址信息
  93. * @param Request $request
  94. * @param UserAddressServices $services
  95. * @param int $uid
  96. * @return mixed
  97. */
  98. public function address_list(Request $request, UserAddressServices $services, $uid = 0)
  99. {
  100. if (!$uid) return app('json')->fail('数据不存在');
  101. return app('json')->successful($services->getUserAddressList($uid, 'id,real_name,phone,province,city,district,detail,is_default,city_id'));
  102. }
  103. /**
  104. * 获取余额
  105. * @param Request $request
  106. * @return mixed
  107. */
  108. public function money(Request $request, $uid)
  109. {
  110. if (!$uid) return app('json')->fail('数据不存在');
  111. return app('json')->success($this->services->getUserInfo($uid, 'now_money'));
  112. }
  113. /**
  114. * 消费明细
  115. * @param UserMoneyServices $services
  116. * @param $uid
  117. * @return mixed
  118. */
  119. public function spread_commission(UserMoneyServices $services, $uid)
  120. {
  121. if (!$uid) return app('json')->fail('数据不存在');
  122. return app('json')->successful($services->userMoneyList($uid, 1));
  123. }
  124. }