StoreNewcomerController.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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\activity;
  12. use app\Request;
  13. use app\services\activity\coupon\StoreCouponUserServices;
  14. use app\services\activity\newcomer\StoreNewcomerServices;
  15. use app\services\other\CacheServices;
  16. use app\services\user\UserServices;
  17. use crmeb\services\SystemConfigService;
  18. /**
  19. * 新人商品类
  20. * Class StoreNewcomerController
  21. * @package app\controller\api\activity
  22. */
  23. class StoreNewcomerController
  24. {
  25. protected $services;
  26. public function __construct(StoreNewcomerServices $services)
  27. {
  28. $this->services = $services;
  29. }
  30. /**
  31. * 新人大礼包弹窗
  32. * @param Request $request
  33. * @return mixed
  34. * @throws \think\db\exception\DataNotFoundException
  35. * @throws \think\db\exception\DbException
  36. * @throws \think\db\exception\ModelNotFoundException
  37. */
  38. public function getGift(Request $request)
  39. {
  40. $data = [];
  41. $uid = (int)$request->uid();
  42. /** @var UserServices $userServices */
  43. $userServices = app()->make(UserServices::class);
  44. $userInfo = $userServices->getUserInfo($uid);
  45. $status = sys_config('newcomer_status');
  46. //新用户
  47. if ($status && $userInfo && $userInfo['add_time'] == $userInfo['last_time'] && $this->services->checkUserNewcomer($uid, $userInfo)) {
  48. $data = SystemConfigService::more([
  49. 'newcomer_limit_status',
  50. 'newcomer_limit_time',
  51. 'register_integral_status',
  52. 'register_give_integral',
  53. 'register_money_status',
  54. 'register_give_money',
  55. 'register_coupon_status',
  56. 'register_give_coupon',
  57. 'first_order_status',
  58. 'first_order_discount',
  59. 'first_order_discount_limit',
  60. 'register_price_status'
  61. ]);
  62. $data['product_count'] = 0;
  63. if ($data['register_price_status']) {
  64. /** @var StoreNewcomerServices $newcomerServices */
  65. $newcomerServices = app()->make(StoreNewcomerServices::class);
  66. $newcomerProducts = $newcomerServices->getCustomerProduct();
  67. $data['product_count'] = count($newcomerProducts);
  68. }
  69. $ids = $data['register_give_coupon'] ?? [];
  70. $data['register_give_coupon'] = [];
  71. if ($data['register_coupon_status'] && $ids) {
  72. /** @var StoreCouponUserServices $couponServices */
  73. $couponServices = app()->make(StoreCouponUserServices::class);
  74. $coupon = $couponServices->getList(['cid' => $ids, 'uid' => $uid]);
  75. if ($coupon) $coupon = $couponServices->tidyCouponList($coupon);
  76. $data['register_give_coupon'] = $coupon;
  77. }
  78. if (!$data['first_order_status']) {
  79. $data['first_order_discount'] = 0;
  80. }
  81. if (!$data['register_integral_status']) {
  82. $data['register_give_integral'] = 0;
  83. }
  84. if (!$data['register_money_status']) {
  85. $data['register_give_money'] = 0;
  86. }
  87. $data['coupon_count'] = count($data['register_give_coupon']);
  88. }
  89. return app('json')->success($data);
  90. }
  91. /**
  92. * 新人礼信息
  93. * @param Request $request
  94. * @return mixed
  95. */
  96. public function getInfo(Request $request)
  97. {
  98. $data = [];
  99. $uid = (int)$request->uid();
  100. /** @var UserServices $userServices */
  101. $userServices = app()->make(UserServices::class);
  102. $userInfo = $userServices->getUserInfo($uid);
  103. $status = sys_config('newcomer_status');
  104. if ($userInfo && $status) {
  105. $data = SystemConfigService::more([
  106. 'newcomer_limit_status',
  107. 'newcomer_limit_time',
  108. 'register_integral_status',
  109. 'register_give_integral',
  110. 'register_money_status',
  111. 'register_give_money',
  112. 'register_coupon_status',
  113. 'register_give_coupon',
  114. 'first_order_status',
  115. 'first_order_discount',
  116. 'first_order_discount_limit',
  117. 'register_price_status'
  118. ]);
  119. $data['product_count'] = 0;
  120. if ($data['register_price_status']) {
  121. /** @var StoreNewcomerServices $newcomerServices */
  122. $newcomerServices = app()->make(StoreNewcomerServices::class);
  123. $newcomerProducts = $newcomerServices->getCustomerProduct();
  124. $data['product_count'] = count($newcomerProducts);
  125. }
  126. /** @var CacheServices $cache */
  127. $cache = app()->make(CacheServices::class);
  128. $data['newcomer_agreement'] = $cache->getDbCache('newcomer_agreement', '');
  129. $ids = $data['register_give_coupon'] ?? [];
  130. $data['register_give_coupon'] = [];
  131. if ($data['register_coupon_status'] && $ids) {
  132. /** @var StoreCouponUserServices $couponServices */
  133. $couponServices = app()->make(StoreCouponUserServices::class);
  134. $coupon = $couponServices->getList(['cid' => $ids, 'uid' => $uid]);
  135. if ($coupon) $coupon = $couponServices->tidyCouponList($coupon);
  136. $data['register_give_coupon'] = $coupon;
  137. }
  138. $data['coupon_count'] = count($data['register_give_coupon']);
  139. $data['last_time'] = 0;
  140. if ($data['newcomer_limit_status'] && $data['newcomer_limit_time']) {
  141. $data['last_time'] = bcadd((string)$userInfo['add_time'], bcmul((string)$data['newcomer_limit_time'], '86400'));
  142. }
  143. if (!$data['first_order_status']) {
  144. $data['first_order_discount'] = 0;
  145. }
  146. if (!$data['register_integral_status']) {
  147. $data['register_give_integral'] = 0;
  148. }
  149. if (!$data['register_money_status']) {
  150. $data['register_give_money'] = 0;
  151. }
  152. }
  153. return app('json')->success($data);
  154. }
  155. /**
  156. * 新人商品列表
  157. * @param Request $request
  158. * @return mixed
  159. * @throws \think\db\exception\DataNotFoundException
  160. * @throws \think\db\exception\DbException
  161. * @throws \think\db\exception\ModelNotFoundException
  162. */
  163. public function lst(Request $request)
  164. {
  165. $uid = (int)$request->uid();
  166. /** @var UserServices $userServices */
  167. $userServices = app()->make(UserServices::class);
  168. $userInfo = $userServices->getUserInfo($uid);
  169. $status = sys_config('newcomer_status');
  170. $data = [];
  171. //新用户
  172. if ($status && $userInfo && $this->services->checkUserNewcomer($uid, $userInfo)) {
  173. $data = $this->services->getCustomerProduct();
  174. }
  175. return app('json')->successful(get_thumb_water($data, 'mid'));
  176. }
  177. /**
  178. * 秒杀商品详情
  179. * @param Request $request
  180. * @param $id
  181. * @return mixed
  182. */
  183. public function detail(Request $request, $id)
  184. {
  185. if (!$id) return app('json')->fail('缺少参数');
  186. $uid = (int)$request->uid();
  187. $data = $this->services->newcomerDetail($uid, (int)$id);
  188. return app('json')->success($data);
  189. }
  190. }