Diy.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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\api\v1\diy;
  12. use app\Request;
  13. use app\services\activity\coupon\StoreCouponUserServices;
  14. use app\services\activity\newcomer\StoreNewcomerServices;
  15. use app\services\activity\video\VideoServices;
  16. use app\services\diy\DiyServices;
  17. use app\services\user\level\SystemUserLevelServices;
  18. use app\services\user\UserServices;
  19. /**
  20. * Class Diy
  21. * @package app\controller\api\v1\diy
  22. */
  23. class Diy
  24. {
  25. protected $services;
  26. public function __construct(DiyServices $services)
  27. {
  28. $this->services = $services;
  29. }
  30. /**
  31. * 获取diy用户数据
  32. * @param Request $request
  33. * @param UserServices $userServices
  34. * @return mixed
  35. */
  36. public function userInfo(Request $request, UserServices $userServices)
  37. {
  38. $uid = (int)$request->uid();
  39. $userInfo = [];
  40. if ($uid) {
  41. $userInfo = $userServices->getUserInfo($uid, 'uid,nickname,phone,avatar,level,integral,now_money,exp,is_money_level,bar_code');
  42. if ($userInfo) {
  43. $userInfo = $userInfo->toArray();
  44. /** @var StoreCouponUserServices $storeCoupon */
  45. $storeCoupon = app()->make(StoreCouponUserServices::class);
  46. $userInfo['coupon_num'] = $storeCoupon->getUserValidCouponCount((int)$uid);
  47. $userInfo['next_exp'] = 0;
  48. $userInfo['vip_name'] = '';
  49. if ($userInfo['level']) {
  50. /** @var SystemUserLevelServices $systemUserLevel */
  51. $systemUserLevel = app()->make(SystemUserLevelServices::class);
  52. $levelList = $systemUserLevel->getList(['is_del' => 0, 'is_show' => 1], 'id,name,exp_num');
  53. $i = 0;
  54. foreach ($levelList as &$level) {
  55. if ($level['id'] == $userInfo['level']) {
  56. $userInfo['vip_name'] = $level['name'];
  57. }
  58. $level['next_exp_num'] = $levelList[$i + 1]['exp_num'] ?? $level['exp_num'];
  59. $i++;
  60. }
  61. $levelList = array_combine(array_column($levelList,'id'), $levelList);
  62. $userInfo['next_exp'] = $levelList[$userInfo['level']]['next_exp_num'] ?? 0;
  63. } else {
  64. /** @var SystemUserLevelServices $systemUserLevel */
  65. $systemUserLevel = app()->make(SystemUserLevelServices::class);
  66. $levelList = $systemUserLevel->getList(['is_del' => 0, 'is_show' => 1], 'id,name,exp_num');
  67. $userInfo['next_exp'] = $levelList[0]['exp_num'] ?? 0;
  68. }
  69. }
  70. }
  71. return app('json')->success($userInfo);
  72. }
  73. /**
  74. * 获取diy短视频
  75. * @param Request $request
  76. * @param VideoServices $videoServices
  77. * @return mixed
  78. */
  79. public function videoList(Request $request, VideoServices $videoServices)
  80. {
  81. $uid = (int)$request->uid();
  82. return app('json')->success($videoServices->getDiyVideoList($uid));
  83. }
  84. /**
  85. * 获取新人礼商品
  86. * @param Request $request
  87. * @param StoreNewcomerServices $newcomerServices
  88. * @return mixed
  89. */
  90. public function newcomerList(Request $request, StoreNewcomerServices $newcomerServices)
  91. {
  92. $where = $request->getMore([
  93. ['priceOrder', ''],
  94. ['salesOrder', ''],
  95. ]);
  96. $uid = (int)$request->uid();
  97. return app('json')->success($newcomerServices->getDiyNewcomerList($uid, $where));
  98. }
  99. }