537 lines
22 KiB
PHP
537 lines
22 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\Server\Admin;
|
||
|
|
|
||
|
|
|
||
|
|
use App\Models\ConsultAccount;
|
||
|
|
use App\Models\Consultation;
|
||
|
|
use App\Models\Course\UserCourses;
|
||
|
|
use App\Models\MerchantShop;
|
||
|
|
use App\Models\Server\MerchantAdmins;
|
||
|
|
use App\Models\Server\MerchantEvaluate;
|
||
|
|
use App\Models\Server\MerchantMembers;
|
||
|
|
use App\Models\Server\MerchantUser;
|
||
|
|
use App\Models\Server\TouristOrder;
|
||
|
|
use Illuminate\Http\JsonResponse;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use App\Models\CommunityActivity;
|
||
|
|
use App\Models\Coupon;
|
||
|
|
use App\Models\Course\Course;
|
||
|
|
use App\Models\Live\Anchor;
|
||
|
|
use App\Models\Server\MerchantAccount;
|
||
|
|
use App\Models\User;
|
||
|
|
use App\Models\UserCoupon;
|
||
|
|
use Illuminate\Support\Facades\Redis;
|
||
|
|
use Illuminate\Support\Facades\DB;
|
||
|
|
|
||
|
|
class CouponController extends Controller
|
||
|
|
{
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 新增优惠券
|
||
|
|
* @param Request $request
|
||
|
|
* @return JsonResponse|string
|
||
|
|
*/
|
||
|
|
public function addCoupon(Request $request)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$merchant_id = $request->account_id;
|
||
|
|
$admin_id = $request->merchant_admin_id ?? null;
|
||
|
|
$serve_tab = $request->serve_tab;
|
||
|
|
$type = $request->type ?: 'course';
|
||
|
|
$coupon_type = $request->coupon_type ?? 1;
|
||
|
|
$discount_rate = $request->discount_rate ?? 0.00;
|
||
|
|
if($discount_rate < 0){
|
||
|
|
return $this->failure('折扣价或折扣率不能小于0');
|
||
|
|
}
|
||
|
|
$remark = $request->remark;
|
||
|
|
if (!$remark) {
|
||
|
|
return $this->failure('发券理由必填');
|
||
|
|
}
|
||
|
|
$link = 'receiveCoupons';
|
||
|
|
if ($request->class == 'one') {
|
||
|
|
$link = 'activityCoupons';
|
||
|
|
$activity = CommunityActivity::where('merchant_id', $merchant_id)
|
||
|
|
->where('id', $request->type_id)
|
||
|
|
->first();
|
||
|
|
if (!$activity) {
|
||
|
|
return $this->failure('活动不属于此商户,无法发放优惠券');
|
||
|
|
} else {
|
||
|
|
$name = $activity->title;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if ($request->class == 'many') {
|
||
|
|
$link = 'serveCoupons';
|
||
|
|
$activity = CommunityActivity::where('merchant_id', $merchant_id)
|
||
|
|
->where('id', $request->type_id)
|
||
|
|
->first();
|
||
|
|
if (!$activity) {
|
||
|
|
return $this->failure('活动不属于此商户,无法发放优惠券');
|
||
|
|
} else {
|
||
|
|
$name = $activity->title;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if ($type == 'course') {
|
||
|
|
$link = 'receiveCoupons';
|
||
|
|
$course = Course::where('merchant_id', $merchant_id)
|
||
|
|
->where('id', $request->type_id)
|
||
|
|
->first();
|
||
|
|
if (!$course) {
|
||
|
|
return $this->failure('课程不属于此商户,无法发放优惠券');
|
||
|
|
} else {
|
||
|
|
$name = $course->title;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if ($type == 'evaluate') {
|
||
|
|
$link = 'evaluateCoupons';
|
||
|
|
$evaluate = MerchantEvaluate::where('merchant_id', $merchant_id)
|
||
|
|
->where('id', $request->type_id)
|
||
|
|
->first();
|
||
|
|
if (!$evaluate) {
|
||
|
|
return $this->failure('测评不属于此商户,无法发放优惠券');
|
||
|
|
} else {
|
||
|
|
$name = $evaluate->title;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($type == 'consult') {
|
||
|
|
$link = 'consultCoupons';
|
||
|
|
$consult = Consultation::query()->where('id', $request->type_id)->first();
|
||
|
|
if (!$consult) {
|
||
|
|
return $this->failure('咨询数据不存在');
|
||
|
|
}
|
||
|
|
$name = $consult->title ?? '';
|
||
|
|
}
|
||
|
|
|
||
|
|
if (env('APP_ENV') == 'production') {
|
||
|
|
if ($type == 'evaluate') {
|
||
|
|
// if ($merchant_id != 491) {
|
||
|
|
// return $this->failure('权限拒绝');
|
||
|
|
// }
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$coupon = new Coupon();
|
||
|
|
$coupon->name = $request->name ?? ($name ?? '优惠券');
|
||
|
|
$coupon->desc = $request->desc;
|
||
|
|
$coupon->type_id = $request->type_id;
|
||
|
|
$coupon->class = $request->class;
|
||
|
|
$coupon->type = $type;
|
||
|
|
$coupon->sku_id = $request->sku_id??null;
|
||
|
|
$coupon->sku = $request->sku??null;
|
||
|
|
$coupon->coupon_type = $coupon_type;
|
||
|
|
if ($coupon_type == 2) {
|
||
|
|
if($discount_rate >= 10 || $discount_rate <= 0){
|
||
|
|
return $this->failure('拆扣率不能小于等于零折或大于10折');
|
||
|
|
}
|
||
|
|
$coupon->discount_rate = number_format($discount_rate * 0.1,1);
|
||
|
|
} else {
|
||
|
|
$coupon->discount_rate = $discount_rate;
|
||
|
|
}
|
||
|
|
if ($coupon_type == 1) {
|
||
|
|
$coupon->payment_method = 'free';
|
||
|
|
} else {
|
||
|
|
$coupon->payment_method = 'discount';
|
||
|
|
}
|
||
|
|
$coupon->expiration_time = $request->expiration_time;
|
||
|
|
$coupon->total_num = $request->total_num;
|
||
|
|
$coupon->remain_num = $request->total_num;
|
||
|
|
$coupon->status = $request->status;
|
||
|
|
$coupon->remark = $remark;
|
||
|
|
$coupon->m_id = $request->account_id;
|
||
|
|
$coupon->admin_id = $admin_id;
|
||
|
|
if ($request->has('sku'))
|
||
|
|
$coupon->sku = json_encode($request->sku);
|
||
|
|
$coupon->save();
|
||
|
|
|
||
|
|
$jump_url = $request->jump_url ?: urlencode(env('APP_URL') . '/pu/#/' . $link . '/' . $coupon->id);
|
||
|
|
$url = env('APP_URL') . '/api/official/live/wechat/FamilyAuth?merchant_id=' . $request->account_id .
|
||
|
|
'&serve_tab=' . $serve_tab . '&url=' . $jump_url;
|
||
|
|
$qr_code = Redis::get('s_coupons' . $coupon->id);
|
||
|
|
if (!$qr_code) {
|
||
|
|
$qr_code = $this->getPreviewQrcode($url);
|
||
|
|
Redis::setex('s_coupon' . $coupon->id, 60 * 60 * 24 * 30, $qr_code);
|
||
|
|
$qr_code = Redis::get('s_coupon' . $coupon->id);
|
||
|
|
}
|
||
|
|
$coupon->qrcode = $qr_code;
|
||
|
|
$coupon->save();
|
||
|
|
return $this->success('ok', $coupon);
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 优惠券列表
|
||
|
|
* @param Request $request
|
||
|
|
* @return JsonResponse|string
|
||
|
|
*/
|
||
|
|
public function CouponList(Request $request)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$m_id = $request->account_id;
|
||
|
|
$serve_tab = $request->serve_tab;
|
||
|
|
$type = $request->type ?: 'course';
|
||
|
|
$class = $request->class ?: 'one';
|
||
|
|
$type_id = $request->type_id;
|
||
|
|
$result = Coupon::where('m_id', $m_id)->where('type', $type)
|
||
|
|
->when($type_id, function ($query) use ($type_id) {
|
||
|
|
$query->where('type_id', $type_id);
|
||
|
|
});
|
||
|
|
if ($type == 'community' && $class) {
|
||
|
|
$result = $result->where('class', $class);
|
||
|
|
}
|
||
|
|
$result = $result->orderBy('id', 'desc')->paginate();
|
||
|
|
foreach ($result as $key => $value) {
|
||
|
|
if ($value->type == 'course') {
|
||
|
|
if (!empty($value->course) && !empty($value->course->title)) {
|
||
|
|
$value->title = $value->course->title;
|
||
|
|
} else {
|
||
|
|
$value->title = null;
|
||
|
|
}
|
||
|
|
if (!empty($value->course) && !empty($value->course->thumb)) {
|
||
|
|
$value->thumb = $value->course->thumb;
|
||
|
|
} else {
|
||
|
|
$value->thumb = null;
|
||
|
|
}
|
||
|
|
unset($value->course);
|
||
|
|
} elseif ($value->type == 'community' && !empty($value->community)) {
|
||
|
|
if (!empty($value->community)) {
|
||
|
|
$value->title = $value->community->title;
|
||
|
|
$value->thumb = $value->community->pic;
|
||
|
|
unset($value->community);
|
||
|
|
} else {
|
||
|
|
$value->title = null;
|
||
|
|
$value->thumb = null;
|
||
|
|
}
|
||
|
|
$value->sku = json_decode($value->sku, true);
|
||
|
|
} elseif ($value->type == 'evaluate') {
|
||
|
|
if (!empty($value->evaluate)) {
|
||
|
|
$value->title = $value->evaluate->title;
|
||
|
|
$value->thumb = $value->evaluate->image;
|
||
|
|
unset($value->evaluate);
|
||
|
|
} else {
|
||
|
|
$value->title = null;
|
||
|
|
$value->thumb = null;
|
||
|
|
}
|
||
|
|
$value->sku = json_decode($value->sku, true);
|
||
|
|
} elseif ($value->type == 'consult'){
|
||
|
|
$value->title = $value->consult->title;
|
||
|
|
$value->thumb = $value->consult->pic;
|
||
|
|
} else {
|
||
|
|
$value->title = '';
|
||
|
|
$value->thumb = '';
|
||
|
|
}
|
||
|
|
$link = 'receiveCoupons';
|
||
|
|
if ($type == 'community' && $value->class == 'one')
|
||
|
|
$link = 'activityCoupons';
|
||
|
|
if ($type == 'community' && $value->class == 'many')
|
||
|
|
$link = 'serveCoupons';
|
||
|
|
if ($type == 'course')
|
||
|
|
$link = 'receiveCoupons';
|
||
|
|
if ($type == 'evaluate')
|
||
|
|
$link = 'evaluateCoupons';
|
||
|
|
if ($type == 'consult')
|
||
|
|
$link = 'consultCoupons';
|
||
|
|
$jump_url = urlencode(env('APP_URL') . '/pu/#/' . $link . '/' . $value->id);
|
||
|
|
$value->share_url = env('APP_URL') . '/api/official/live/wechat/FamilyAuth?merchant_id=' .
|
||
|
|
$request->account_id . '&serve_tab=' . $serve_tab . '&url=' . $jump_url;
|
||
|
|
if (!$value->qrcode) {
|
||
|
|
$value->qrcode = $this->getPreviewQrcode($value->share_url);
|
||
|
|
Coupon::where('m_id', $m_id)->where('type', $type)->where('id', $value->id)
|
||
|
|
->update(['qrcode' => $value->qrcode]);
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($value->admin_id) {
|
||
|
|
$value->sender_admin = MerchantMembers::where('mch_id', $request->account_id)
|
||
|
|
->where('admin_id', $value->admin_id)
|
||
|
|
->withTrashed()
|
||
|
|
->select('name as nickname', 'avatar')
|
||
|
|
->first();
|
||
|
|
if ($value->sender_admin) {
|
||
|
|
$value->sender_admin->mobile = MerchantAdmins::where('id', $value->admin_id)
|
||
|
|
->value('mobile');
|
||
|
|
}
|
||
|
|
} elseif ($value->m_id) {
|
||
|
|
$account = MerchantAccount::select('id', 'qr_code', 'share_icon', 'share_subtitle', 'share_title',
|
||
|
|
'openid', 'choose_tarbar', 'template_position', 'member_info', 'mobile', 'email')
|
||
|
|
->where('id', $request->account_id)
|
||
|
|
->first();
|
||
|
|
$anchor = Anchor::where('m_id', $account->id)->select('pic as avatar', 'name as nickname', 'mobile')
|
||
|
|
->first();
|
||
|
|
$value->sender_admin = $anchor;
|
||
|
|
}
|
||
|
|
if ($value->coupon_type == 2) {
|
||
|
|
$value->discount_rate = number_format(10 * $value->discount_rate, 1);
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return $this->success('ok', $result);
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 优惠券课程
|
||
|
|
* @param Request $request
|
||
|
|
* @return JsonResponse|string
|
||
|
|
*/
|
||
|
|
public function CourseList(Request $request)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$type = $request->type ?: 'course';
|
||
|
|
$m_id = $request->account_id;
|
||
|
|
$class = $request->class ?: 'one';
|
||
|
|
if ($type == 'course') {
|
||
|
|
$result = Course::select('id', 'thumb', 'title', 'charge as price')->where('merchant_id', $m_id)
|
||
|
|
->where('is_show',1);
|
||
|
|
if ($request->input('is_free', 0) == 0) {
|
||
|
|
$result = $result->where('charge', ">", 0);
|
||
|
|
}
|
||
|
|
$result = $result->orderBy('id', 'desc')->get();
|
||
|
|
} elseif ($type == 'community') {
|
||
|
|
$result = CommunityActivity::select('id', 'title', 'pic as thumb', 'sku')->where('merchant_id', $m_id)
|
||
|
|
->where('status',1)
|
||
|
|
->where('class', $class)->orderBy('id', 'desc')
|
||
|
|
->get();
|
||
|
|
foreach ($result as $key => $value) {
|
||
|
|
$value->sku = json_decode($value->sku, true);
|
||
|
|
}
|
||
|
|
} elseif ($type == 'shop') {
|
||
|
|
$result = MerchantShop::select('id', 'title', 'icon as thumb', 'sku')->where('merchant_id', $m_id)
|
||
|
|
->where('is_show',1)
|
||
|
|
->orderBy('id', 'desc')
|
||
|
|
->get();
|
||
|
|
foreach ($result as $key => $value) {
|
||
|
|
$value->sku = json_decode($value->sku, true);
|
||
|
|
}
|
||
|
|
} elseif ($type == 'evaluate') {
|
||
|
|
$result = MerchantEvaluate::select('id', 'title', 'image as thumb')->where('merchant_id', $m_id)
|
||
|
|
->where('status',1)
|
||
|
|
->orderBy('id', 'desc')
|
||
|
|
->get();
|
||
|
|
foreach ($result as $key => $value) {
|
||
|
|
$value->sku = json_decode($value->sku, true);
|
||
|
|
}
|
||
|
|
} elseif ($type == 'consult') {
|
||
|
|
$ids = ConsultAccount::where('merchant_id', $m_id)->pluck('id');
|
||
|
|
$result = Consultation::wherein('consult_account_id', $ids)->where('status', 1)
|
||
|
|
->orderBy('is_top', 'desc')->orderBy('top_time', 'desc')->orderBy('id', 'desc')
|
||
|
|
->select('id','title','pic as thumb','price')
|
||
|
|
->get();
|
||
|
|
}
|
||
|
|
if(empty($result)){
|
||
|
|
$result = [];
|
||
|
|
}
|
||
|
|
return $this->success('ok', $result);
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 优惠券详情
|
||
|
|
* @param Request $request
|
||
|
|
* @param $id
|
||
|
|
* @return JsonResponse|string
|
||
|
|
*/
|
||
|
|
public function CouponDetail(Request $request, $id)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$m_id = $request->account_id;
|
||
|
|
$result = Coupon::where('m_id', $m_id)->where('id', $id)->first();
|
||
|
|
$result->sku = json_decode($result->sku, true);
|
||
|
|
return $this->success('ok', $result);
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 已领取用户
|
||
|
|
* *
|
||
|
|
* @param Request $request
|
||
|
|
* @return JsonResponse|string
|
||
|
|
*/
|
||
|
|
public function CouponUser(Request $request)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$m_id = $request->account_id;
|
||
|
|
$coupon_id = $request->coupon_id;
|
||
|
|
$result = UserCoupon::where('m_id', $m_id)->where('coupons_id', $coupon_id)->orderBy('id', 'desc')
|
||
|
|
->paginate();
|
||
|
|
foreach ($result as $key => $value) {
|
||
|
|
if ($value->s_user) {
|
||
|
|
$value->name = $value->s_user->nickname ?: '匿名用户';
|
||
|
|
$value->pic = $value->s_user->pic ?: User::DefaultAvatar;
|
||
|
|
unset($value->s_user);
|
||
|
|
} else {
|
||
|
|
$value->name = null;
|
||
|
|
$value->pic = User::DefaultAvatar;
|
||
|
|
}
|
||
|
|
$value->linkmen = json_decode($value->linkmen, true);
|
||
|
|
}
|
||
|
|
return $this->success('ok', $result);
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 删除优惠券
|
||
|
|
* *
|
||
|
|
* @param Request $request
|
||
|
|
* @param $id
|
||
|
|
* @return JsonResponse|string
|
||
|
|
*/
|
||
|
|
public function delCoupon(Request $request, $id)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$m_id = $request->account_id;
|
||
|
|
$result = Coupon::where('m_id', $m_id)->where('id', $id)->delete();
|
||
|
|
return $this->success('ok', $result);
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 修改优惠券
|
||
|
|
* *
|
||
|
|
* @param Request $request
|
||
|
|
* @param $id
|
||
|
|
* @return JsonResponse|string
|
||
|
|
*/
|
||
|
|
public function changeCoupon(Request $request, $id)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$m_id = $request->account_id;
|
||
|
|
$result = Coupon::where('m_id', $m_id)->where('id', $id)->first();
|
||
|
|
if (!$result)
|
||
|
|
return $this->failure('该信息不存在');
|
||
|
|
if ($request->total_num < ($result->total_num - $result->remain_num))
|
||
|
|
return $this->failure('总数必须大于已领数');
|
||
|
|
$result->remain_num = intval($request->total_num) - $result->total_num + $result->remain_num;
|
||
|
|
if ($result->remain_num < 0)
|
||
|
|
$result->remain_num = $request->total_num;
|
||
|
|
$result->total_num = $request->total_num;
|
||
|
|
if ($request->has('coupon_type')) {
|
||
|
|
$result->coupon_type = $request->coupon_type;
|
||
|
|
}
|
||
|
|
if ($request->has('discount_rate') && $request->input('coupon_type') == 2) {
|
||
|
|
//$result->discount_rate = $request->discount_rate;
|
||
|
|
$result->discount_rate = number_format($request->discount_rate * 0.1,1);
|
||
|
|
}
|
||
|
|
$result->save();
|
||
|
|
return $this->success('ok', $result);
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 发放优惠券到个人帐户
|
||
|
|
*/
|
||
|
|
public function grantCouponToUser(Request $request)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
DB::beginTransaction();
|
||
|
|
$coupon_id = $request->coupon_id;
|
||
|
|
$merchant_users_id = $request->merchant_users_id;
|
||
|
|
if (config("app.debug")) {
|
||
|
|
if (!$coupon_id || !$merchant_users_id) {
|
||
|
|
return $this->failure('参数不全');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$coupon = Coupon::where('m_id', $request->account_id)->where('id', $coupon_id)
|
||
|
|
->where('remain_num', '>', 0)
|
||
|
|
->first();
|
||
|
|
if (!$coupon) {
|
||
|
|
return $this->failure('优惠券不存在或已分完');
|
||
|
|
}
|
||
|
|
$user_coupon = UserCoupon::where('m_user_id', $merchant_users_id)->where('coupons_id', $coupon_id)
|
||
|
|
->first();
|
||
|
|
if ($user_coupon) {
|
||
|
|
return $this->failure('用户已领取过这个优惠券');
|
||
|
|
}
|
||
|
|
$user_coupon = new UserCoupon();
|
||
|
|
$user_coupon->m_user_id = $merchant_users_id;
|
||
|
|
$user_coupon->m_id = $request->account_id;
|
||
|
|
$user_coupon->coupons_id = $coupon_id;
|
||
|
|
$user_coupon->save();
|
||
|
|
$coupon->remain_num = $coupon->remain_num - 1;
|
||
|
|
$coupon->save();
|
||
|
|
if($coupon->coupon_type == 1 && $coupon->type != 'evaluate'){
|
||
|
|
$user_id = $this->matchFulinkUser($merchant_users_id);
|
||
|
|
$merchant_user = MerchantUser::find($merchant_users_id);
|
||
|
|
if(!$merchant_user || !$merchant_user->mobile || !$merchant_user->nickname){
|
||
|
|
return $this->failure('发放的用户手机号或呢称未设置,无法发放免费券');
|
||
|
|
}
|
||
|
|
$trade_no = \CommonUtilsService::getTradeNO();
|
||
|
|
$user_coupon->status = 1;
|
||
|
|
$user_coupon->save();
|
||
|
|
//生成订单
|
||
|
|
$order = new TouristOrder();
|
||
|
|
$order->open_id = null;
|
||
|
|
$order->price = '0.00';
|
||
|
|
$order->num = 1;
|
||
|
|
$order->pay_type = 'free';
|
||
|
|
$order->pay_status = 4;
|
||
|
|
$order->user_coupon_id = $user_coupon->id;
|
||
|
|
$order->trade_no = $trade_no;
|
||
|
|
$order->withdrawal_radio = 100;
|
||
|
|
$order->from_openid = null;
|
||
|
|
$order->goods = '领取优惠券';
|
||
|
|
$order->merchant_id = $request->account_id;
|
||
|
|
$order->account_id = $merchant_users_id;
|
||
|
|
$order->channel = 0;
|
||
|
|
$order->linkmen = json_encode([]);
|
||
|
|
$order->name = $merchant_user->nickname;
|
||
|
|
$order->mobile = $merchant_user->mobile ;
|
||
|
|
$order->type = $coupon->type;
|
||
|
|
if ($coupon->type == 'evaluate') {
|
||
|
|
$merchant_evaluates_id = MerchantEvaluate::where('merchant_id', $request->account_id)
|
||
|
|
->where('test_item_id', $coupon->type_id)
|
||
|
|
->value('id');
|
||
|
|
$order->type_id = $merchant_evaluates_id;
|
||
|
|
} else {
|
||
|
|
$order->type_id = $coupon->type_id;
|
||
|
|
}
|
||
|
|
$order->desc = '领取优惠券';
|
||
|
|
$order->save();
|
||
|
|
if ($coupon->type == 'community') {
|
||
|
|
$remark = $this->numMember($order);
|
||
|
|
$order->remark = $remark;
|
||
|
|
$order->save();
|
||
|
|
}elseif($coupon->type == 'course'){
|
||
|
|
$user_course = new UserCourses();
|
||
|
|
$user_course->user_id = $user_id;
|
||
|
|
$user_course->course_id = $coupon->type_id;
|
||
|
|
$user_course->type = 'business';
|
||
|
|
$user_course->trade_no = $trade_no;
|
||
|
|
$user_course->status = 1;
|
||
|
|
$user_course->open_id = null;
|
||
|
|
$user_course->merchant_user_id = $merchant_users_id;
|
||
|
|
$user_course->save();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
DB::commit();
|
||
|
|
return $this->success('ok');
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
DB::rollBack();
|
||
|
|
$this->getError($e);
|
||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|