CouponDetailService.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\admin\service\coupon;
  3. use app\model\CouponDetail;
  4. use app\model\SysSerial;
  5. use support\exception\BusinessException;
  6. class CouponDetailService
  7. {
  8. /**
  9. * @Desc 手动发券
  10. * @Author Gorden
  11. * @Date 2024/8/27 9:57
  12. *
  13. * @param $params
  14. * @return void
  15. * @throws BusinessException
  16. */
  17. public static function customSendCoupon($params)
  18. {
  19. try {
  20. CouponDetail::insert([
  21. 'coupon_detail_id' => 'CUDT' . date("ymdHi") . random_string(4, 'up'),
  22. 'join_detail_coupon_id' => $params['coupon_id'],
  23. 'join_coupon_detail_member_id' => $params['member_id'],
  24. 'coupon_detail_status' => 'ACTIVED',
  25. 'coupon_detail_gain_datetime' => $params['coupon_detail_gain_datetime'],
  26. 'coupon_detail_deadline_datetime' => $params['coupon_detail_deadline_datetime'],
  27. 'coupon_detail_period_num' => $params['coupon_detail_period_num'] ?? 0,
  28. 'coupon_detail_extend_json'=>json_encode(['gettype'=>'SEND']),
  29. 'coupon_detail_addtimes' => time(),
  30. ]);
  31. } catch (\Exception $e) {
  32. throw new BusinessException('写入优惠券失败');
  33. }
  34. }
  35. public static function customSendCouponHave($params)
  36. {
  37. try {
  38. CouponDetail::where('join_detail_coupon_id',$params['coupon_id'])
  39. ->whereIn('coupon_detail_status',['INIT','PENDING'])
  40. ->limit($params['chooseCouponNbr'])
  41. ->update([
  42. 'join_coupon_detail_member_id' => $params['member_id'],
  43. 'coupon_detail_gain_datetime' => $params['coupon_detail_gain_datetime'],
  44. 'coupon_detail_deadline_datetime' => $params['coupon_detail_deadline_datetime'],
  45. 'coupon_detail_extend_json'=>json_encode(['gettype'=>'SEND']),
  46. 'coupon_detail_status'=>'ACTIVED'
  47. ]);
  48. } catch (\Exception $e) {
  49. throw new BusinessException('写入优惠券失败');
  50. }
  51. }
  52. }