first(); $configParams = json_decode($config->config_value_json, true); // 更新身份 Member::where('member_id', $params['member_id'])->update(['member_is_partner' => 'Y']); // 余额账户 $memberAccount = MemberAccount::where('join_account_member_id', $params['member_id'])->where('member_account_classify', 'CASH')->first(); // 分期付款 if (isset($params['order_amount_paid']) && $params['order_amount_paid'] > 0) { $params['order_amount_pay'] = $params['order_amount_paid'] + $params['order_amount_pay']; } // 增值到最后一条支付记录 $added = 0; $payDetail = PayDetail::whereJsonContains('join_pay_object_json->order_id', $params['orderId'])->orderBy('pay_addtimes', 'DESC')->first(); if (!empty($configParams['account']['added'])) { $params['order_amount_pay'] = 10000; $added = round($params['order_amount_pay'] * $configParams['account']['added'], 2); $payDetail->pay_extend_json = json_encode(['added_rate' => $configParams['account']['added'], 'added_amount' => $added]); $payDetail->save(); } // 入账 $memberAccount->member_account_income = $memberAccount->member_account_income + $params['order_amount_pay']; $memberAccount->member_account_surplus = $memberAccount->member_account_surplus + $params['order_amount_pay']; $memberAccount->member_account_added = $memberAccount->member_account_added + $added; $memberAccount->save(); //发放优惠券 $goods = Goods::where('goods_id', $params['join_sheet_goods_id'])->select('goods_attribute_json')->first(); if (!empty($goods) && !empty($goods->goods_attribute_json)) { $goodsAttributeJson = json_decode($goods->goods_attribute_json, true); if (!empty($goodsAttributeJson['coupon'])) { foreach ($goodsAttributeJson['coupon'] as $key => $coupon) { $couponModel = Coupon::where('coupon_id', $key)->select('coupon_id', 'coupon_validdate_day', 'coupon_validdate_end')->first(); if (empty($couponModel)) { continue; } // 券是否过期 if (!empty($couponModel->coupon_validdate_end) && strtotime($couponModel->coupon_validdate_end) < time()) { continue; } $endDate = ''; if (!empty($couponModel->coupon_validdate_end)) { $endDate = $couponModel->coupon_validdate_end; } elseif ($couponModel->coupon_validdate_day > 0) { $endDate = date('Y-m-d H:i:s', time() + ($couponModel->coupon_validdate_day * 24 * 3600) - 1); } $num = $coupon['num']; for ($i = 0; $i < $num; $i++) { CouponDetail::insert([ 'coupon_detail_id' => 'CUDT' . date("ymdHi") . random_string(4, 'up'), 'join_detail_coupon_id' => $key, 'join_coupon_detail_member_id' => $params['member_id'], 'coupon_detail_status' => 'ACTIVED', 'coupon_detail_gain_datetime' => date('Y-m-d H:i:s'), 'coupon_detail_deadline_datetime' => $endDate, 'coupon_detail_json' => '[]', 'coupon_detail_extend_json' => json_encode(['gettype' => 'PARTNER']), 'coupon_detail_addtimes' => time() ]); } } } } } }