123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace app\admin\service\coupon;
- use app\model\CouponDetail;
- use app\model\SysSerial;
- use support\exception\BusinessException;
- class CouponDetailService
- {
- /**
- * @Desc 手动发券
- * @Author Gorden
- * @Date 2024/8/27 9:57
- *
- * @param $params
- * @return void
- * @throws BusinessException
- */
- public static function customSendCoupon($params)
- {
- try {
- CouponDetail::insert([
- 'coupon_detail_id' => 'CUDT' . date("ymdHi") . random_string(4, 'up'),
- 'join_detail_coupon_id' => $params['coupon_id'],
- 'join_coupon_detail_member_id' => $params['member_id'],
- 'coupon_detail_status' => 'ACTIVED',
- 'coupon_detail_gain_datetime' => $params['coupon_detail_gain_datetime'],
- 'coupon_detail_deadline_datetime' => $params['coupon_detail_deadline_datetime'],
- 'coupon_detail_period_num' => $params['coupon_detail_period_num'] ?? 0,
- 'coupon_detail_extend_json'=>json_encode(['gettype'=>'SEND']),
- 'coupon_detail_addtimes' => time(),
- ]);
- } catch (\Exception $e) {
- throw new BusinessException('写入优惠券失败');
- }
- }
- public static function customSendCouponHave($params)
- {
- try {
- CouponDetail::where('join_detail_coupon_id',$params['coupon_id'])
- ->whereIn('coupon_detail_status',['INIT','PENDING'])
- ->limit($params['chooseCouponNbr'])
- ->update([
- 'join_coupon_detail_member_id' => $params['member_id'],
- 'coupon_detail_gain_datetime' => $params['coupon_detail_gain_datetime'],
- 'coupon_detail_deadline_datetime' => $params['coupon_detail_deadline_datetime'],
- 'coupon_detail_extend_json'=>json_encode(['gettype'=>'SEND']),
- 'coupon_detail_status'=>'ACTIVED'
- ]);
- } catch (\Exception $e) {
- throw new BusinessException('写入优惠券失败');
- }
- }
- }
|