973 lines
45 KiB
PHP
973 lines
45 KiB
PHP
|
|
<?php
|
|||
|
|
|
|||
|
|
namespace App\Http\Controllers\Server\H5;
|
|||
|
|
|
|||
|
|
use App\Facades\WechatService;
|
|||
|
|
use App\Models\Coupon;
|
|||
|
|
use App\Models\SaasReservationConsultScheduling;
|
|||
|
|
use App\Models\SaasReservationTeacher;
|
|||
|
|
use App\Models\Server\CollageGroup;
|
|||
|
|
use App\Models\Server\CollageGroupHistories;
|
|||
|
|
use App\Models\Server\EvaluateDetail;
|
|||
|
|
use App\Models\Server\EvaluateList;
|
|||
|
|
use App\Models\Server\MEarningShare;
|
|||
|
|
use App\Models\Server\MerchantEvaluate;
|
|||
|
|
use App\Models\Server\UserEvaluate;
|
|||
|
|
use App\Models\UserCoupon;
|
|||
|
|
use App\Services\ConsultService;
|
|||
|
|
use App\Services\EvaluateService;
|
|||
|
|
use App\Utils\Messenger as Messengers;
|
|||
|
|
use Illuminate\Http\JsonResponse;
|
|||
|
|
use Illuminate\Http\Request;
|
|||
|
|
use App\Http\Controllers\Controller;
|
|||
|
|
use App\Models\ConsultAccount;
|
|||
|
|
use App\Models\Consultation;
|
|||
|
|
use App\Models\ConsultationRecords;
|
|||
|
|
use App\Models\Live\Anchor;
|
|||
|
|
use App\Models\MerchantUsers;
|
|||
|
|
use App\Models\Message;
|
|||
|
|
use App\Models\PayLog;
|
|||
|
|
use App\Models\Server\MerchantAccount;
|
|||
|
|
use App\Models\Server\MerchantUser;
|
|||
|
|
use App\Models\Server\SaasNotice;
|
|||
|
|
use App\Models\Server\TouristOrder;
|
|||
|
|
use App\Models\User;
|
|||
|
|
use App\Services\UserService;
|
|||
|
|
use App\Utils\Messenger;
|
|||
|
|
use Illuminate\Support\Facades\DB;
|
|||
|
|
use Illuminate\Support\Facades\Redis;
|
|||
|
|
|
|||
|
|
class ConsultController extends Controller
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 咨询列表
|
|||
|
|
* *
|
|||
|
|
* @param Request $request
|
|||
|
|
* @return JsonResponse|string
|
|||
|
|
*/
|
|||
|
|
public function BusinessconsultingService(Request $request)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$merchant_id = $request->merchant_id;
|
|||
|
|
$merchant_user_id = $request->merchant_user_id;
|
|||
|
|
$ids = ConsultAccount::where('merchant_id', $merchant_id)->pluck('id');
|
|||
|
|
$result = Consultation::wherein('consult_account_id', $ids)->where('status', 1)
|
|||
|
|
->orderBy('is_top', 'desc')->orderBy('top_time', 'desc')->orderBy('id', 'desc')
|
|||
|
|
->paginate();
|
|||
|
|
foreach ($result as $key => $value) {
|
|||
|
|
//咨询人数
|
|||
|
|
$value->pay_num = ConsultationRecords::where('consulation_id', $value->id)
|
|||
|
|
->where('status', 2)->groupBY('phone')->get()
|
|||
|
|
->count();
|
|||
|
|
//是否有未完成的预约
|
|||
|
|
$value->state = 0;
|
|||
|
|
$value->order_id = '';
|
|||
|
|
$data = ConsultationRecords::where('merchant_user_id', $merchant_user_id)->where('consulation_id', $value->id)
|
|||
|
|
->whereIn('pay_status', [1, 4])->orderBy('id', 'desc')
|
|||
|
|
->first();
|
|||
|
|
if ($data) {
|
|||
|
|
if ($data->status == 0) {
|
|||
|
|
$value->state = 1;
|
|||
|
|
} elseif ($data->status == 2 && !$data->Praise) {
|
|||
|
|
$value->state = 2;//待评分
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
$value->state = 0;
|
|||
|
|
}
|
|||
|
|
$teacher = ConsultAccount::where('id', $value->consult_account_id)->first();
|
|||
|
|
$value->introduction = $teacher->introduction;
|
|||
|
|
$value->name = $teacher->name;
|
|||
|
|
$data = ConsultationRecords::where('consulation_id', $value->id)->where('status', 2)
|
|||
|
|
->get();
|
|||
|
|
$array = json_decode($data, true);
|
|||
|
|
if (!empty($array)) {
|
|||
|
|
$Praise = $data->sum('Praise');
|
|||
|
|
$Praise_num = $data->count('Praise');
|
|||
|
|
if ($Praise && $Praise_num) {
|
|||
|
|
$value->Praise_num = number_format($Praise / $Praise_num, 1, '.', '');
|
|||
|
|
} else {
|
|||
|
|
$value->Praise_num = number_format(5.0, 1, '.', '');
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
$value->Praise_num = number_format(5.0, 1, '.', '');
|
|||
|
|
}
|
|||
|
|
$value->Praise_num = intval($value->Praise_num / 5 * 100);
|
|||
|
|
$value->label = json_decode($teacher->label, true);
|
|||
|
|
// $value->pic = $teacher->pic;
|
|||
|
|
$value->price = number_format($value->price, 2, '.', '');
|
|||
|
|
$value->experience = $teacher->experience;
|
|||
|
|
$value->seniority = $teacher->seniority;
|
|||
|
|
$value->designation = $teacher->designation;
|
|||
|
|
$time = date('Y-m-d H:i:s');
|
|||
|
|
$group = CollageGroup::where('type', 'consult')->where('type_id', $value->id)->where('start_time', '<', $time)
|
|||
|
|
->where('end_time', '>', $time)->first();
|
|||
|
|
if ($group) {
|
|||
|
|
$value->is_group = 1;
|
|||
|
|
} else {
|
|||
|
|
$value->is_group = 0;
|
|||
|
|
}
|
|||
|
|
//首次购买折扣
|
|||
|
|
$value->has_buy_discount = 0; //是否有首次购买折扣 1=有 0=无
|
|||
|
|
$value->first_discount_price = 0;
|
|||
|
|
$hasBuyOrder = ConsultationRecords::where('merchant_user_id', $merchant_user_id)
|
|||
|
|
// ->where('anchor_id',$value->consult_account_id)
|
|||
|
|
->where('consulation_id', $value->id)
|
|||
|
|
->whereIn('pay_status', [1, 4])->first();
|
|||
|
|
if (!$hasBuyOrder && $value->first_buy_discount < 1) {
|
|||
|
|
$value->has_buy_discount = 1;
|
|||
|
|
\Log::info($value->id);
|
|||
|
|
\Log::info($value->price);
|
|||
|
|
\Log::info($value->first_buy_discount);
|
|||
|
|
$value->first_discount_price = number_format($value->price * $value->first_buy_discount, 2, '.', '');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return $this->success('ok', $result);
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public function BusinessConsultationDetails(Request $request, ConsultService $s)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$merchant_id = $request->merchant_id;
|
|||
|
|
$consultation_id = $request->consultation_id;
|
|||
|
|
$lately_scheduling_day = $request->input('lately_scheduling_day', 5);
|
|||
|
|
$order_id = $request->order_id;
|
|||
|
|
$wechatUser = session('wechat.oauth_user.new');
|
|||
|
|
$openId = null;
|
|||
|
|
if ($wechatUser)
|
|||
|
|
$openId = $wechatUser->getId();
|
|||
|
|
$merchant_user_id = $request->merchant_user_id;
|
|||
|
|
$merchant_user = MerchantUser::where('id', $merchant_user_id)->first();
|
|||
|
|
$result = Consultation::withTrashed()->where('id', $consultation_id)->first();
|
|||
|
|
if (!$result)
|
|||
|
|
return $this->failure('咨询信息有误');
|
|||
|
|
$merchant_user->preview($result);
|
|||
|
|
$teacher = ConsultAccount::where('id', $result->consult_account_id)->first();
|
|||
|
|
if ($teacher) {
|
|||
|
|
$result->intro = $teacher->introduction;
|
|||
|
|
$result->name = $teacher->name;
|
|||
|
|
$result->mobile = $teacher->mobile;
|
|||
|
|
$result->label = json_decode($teacher->label, true);
|
|||
|
|
$result->t_pic = $teacher->pic;
|
|||
|
|
$result->experience = $teacher->experience;
|
|||
|
|
$result->seniority = $teacher->seniority;
|
|||
|
|
$result->designation = $teacher->designation;
|
|||
|
|
$result->credentials = json_decode($teacher->credentials, true) ?? [];
|
|||
|
|
} else {
|
|||
|
|
$result->intro = null;
|
|||
|
|
$result->name = null;
|
|||
|
|
$result->mobile = null;
|
|||
|
|
$result->label = null;
|
|||
|
|
$result->t_pic = null;
|
|||
|
|
$result->experience = null;
|
|||
|
|
$result->seniority = null;
|
|||
|
|
$result->designation = null;
|
|||
|
|
$result->credentials = null;
|
|||
|
|
}
|
|||
|
|
$result->consult_scheduling = $s->getLatelyScheduling($merchant_id, $result->consult_account_id, $lately_scheduling_day);
|
|||
|
|
|
|||
|
|
// $data = ConsultationRecords::where('consulation_id', $consultation_id)->whereNotNull('Praise')
|
|||
|
|
// ->where('status', 2)
|
|||
|
|
// ->get();
|
|||
|
|
$data = ConsultationRecords::where('consulation_id', $consultation_id)
|
|||
|
|
->where('pay_status', 1)
|
|||
|
|
->get();
|
|||
|
|
$Praise = $data->sum('Praise');
|
|||
|
|
$Praise_num = $data->count('Praise');
|
|||
|
|
|
|||
|
|
//评论人数
|
|||
|
|
$comment_num = ConsultationRecords::where('consulation_id', $consultation_id)
|
|||
|
|
->where('pay_status', 1)
|
|||
|
|
->whereNotNull('comment')
|
|||
|
|
->count();
|
|||
|
|
if ($Praise && $comment_num) {
|
|||
|
|
$avg = number_format($Praise / $comment_num, 1, '.', '');
|
|||
|
|
$result->Praise_num = intval($avg / 5 * 100);
|
|||
|
|
} else {
|
|||
|
|
$result->Praise_num = 0;
|
|||
|
|
}
|
|||
|
|
$result->pay_num = $Praise_num;
|
|||
|
|
if ($consultation_id == 380) {
|
|||
|
|
$result->pay_num = $Praise_num + 377;
|
|||
|
|
}
|
|||
|
|
$result->price = number_format($result->price, 2, '.', '');
|
|||
|
|
$state = 0;
|
|||
|
|
$record = ConsultationRecords::where('consulation_id', $consultation_id)
|
|||
|
|
->where('merchant_user_id', $request->merchant_user_id)->whereIn('pay_status', [1, 4])
|
|||
|
|
->orderBy('status', 'asc')
|
|||
|
|
->first();
|
|||
|
|
if (!$record) {
|
|||
|
|
$state = 0;
|
|||
|
|
} elseif ($record && $record->status == 0) {
|
|||
|
|
$state = 1;
|
|||
|
|
} elseif ($record->status == 2 && !$record->Praise) {
|
|||
|
|
$state = 2;
|
|||
|
|
} else {
|
|||
|
|
$state = 3;
|
|||
|
|
}
|
|||
|
|
$result->state = $state;
|
|||
|
|
$result->order_id = '';
|
|||
|
|
if ($order_id != 'null') {
|
|||
|
|
$result->order_id = $order_id;
|
|||
|
|
} else {
|
|||
|
|
$result->order_id = $record->id ?? 0;
|
|||
|
|
}
|
|||
|
|
Redis::zincrby('consulation', 1, $consultation_id);
|
|||
|
|
$jump_url = urlencode(env('APP_URL') . '/pu/#/consultingDetail/' . $consultation_id);
|
|||
|
|
$url = env('APP_URL') . '/api/official/live/wechat/FamilyAuth?merchant_id=' . $request->merchant_id . '&url=' . $jump_url . '&from_openid=' . $openId;
|
|||
|
|
// $qr_code = Redis::get('ConsultDetail_S' . $consultation_id);
|
|||
|
|
// if (!$qr_code) {
|
|||
|
|
$qr_code = $this->getPreviewQrcode($url);
|
|||
|
|
// Redis::setex('ConsultDetail_S' . $consultation_id, 60 * 60 * 24 * 30, $qr_code);
|
|||
|
|
// $qr_code = Redis::get('ConsultDetail_S' . $consultation_id);
|
|||
|
|
// }
|
|||
|
|
$result->share_qr_code = $qr_code;
|
|||
|
|
$user = MerchantUser::where('id', $request->merchant_user_id)->first();
|
|||
|
|
if (config('app.env') == 'production') {
|
|||
|
|
$user->addlog($result);
|
|||
|
|
}
|
|||
|
|
//下架或删除状态 0下架 1正常上架 2已删除
|
|||
|
|
$publish_state = 0;
|
|||
|
|
if ($result->deleted_at) {
|
|||
|
|
$publish_state = 2;
|
|||
|
|
} elseif ($result->status == 1) {
|
|||
|
|
$publish_state = 1;
|
|||
|
|
} else {
|
|||
|
|
$publish_state = 0;
|
|||
|
|
}
|
|||
|
|
$result->publish_state = $publish_state;
|
|||
|
|
|
|||
|
|
$linkmen['name'] = '';
|
|||
|
|
$linkmen['mobile'] = '';
|
|||
|
|
if ($merchant_user) {
|
|||
|
|
$result['share_nickname'] = $merchant_user->nickname ?? '匿名用户';
|
|||
|
|
$result['share_avatar'] = $merchant_user->pic ?? User::DefaultAvatar;
|
|||
|
|
$linkmen['name'] = $merchant_user->nickname;
|
|||
|
|
$linkmen['mobile'] = $merchant_user->mobile;
|
|||
|
|
}
|
|||
|
|
$result->linkmen = $linkmen;
|
|||
|
|
if ($request->from_openid && $request->from_openid != 'null') {
|
|||
|
|
$user_service = new UserService();
|
|||
|
|
$user_service->generateClientComment(0, $openId, $request->from_openid, '咨询', $result->id, $result->title);
|
|||
|
|
}
|
|||
|
|
$result->has_group = $teacher->hasGroup($result) ? 1 : 0;
|
|||
|
|
$result->group = $teacher->groupInformation($result);
|
|||
|
|
//首次购买折扣
|
|||
|
|
$result->has_buy_discount = 0; //是否有首次购买折扣 1=有 0=无
|
|||
|
|
$result->first_discount_price = 0;
|
|||
|
|
//优惠劵
|
|||
|
|
$user_coupon_id = $request->user_coupon_id;
|
|||
|
|
if ($user_coupon_id) {
|
|||
|
|
$user_coupon = UserCoupon::where('id', $user_coupon_id)->with('coupon')
|
|||
|
|
->first();
|
|||
|
|
if ($user_coupon && $user_coupon->coupon) {
|
|||
|
|
switch ($user_coupon->coupon->coupon_type) {
|
|||
|
|
case 1:
|
|||
|
|
$result->discount_amount = $result->price;
|
|||
|
|
$result->charge = 0.00;
|
|||
|
|
break;
|
|||
|
|
case 2:
|
|||
|
|
$result->discount_amount = number_format($result->price * (1 - $user_coupon->coupon->discount_rate), 2, '.', '');
|
|||
|
|
$result->charge = number_format($result->price - $result->discount_amount, 2, '.', '');
|
|||
|
|
break;
|
|||
|
|
case 3:
|
|||
|
|
$temp = number_format($result->price - $user_coupon->coupon->discount_rate, 2, '.', '');
|
|||
|
|
if ($temp < 0) {
|
|||
|
|
$result->discount_amount = $result->price;
|
|||
|
|
$result->charge = 0.00;
|
|||
|
|
} else {
|
|||
|
|
$result->discount_amount = $user_coupon->coupon->discount_rate;
|
|||
|
|
$result->charge = $temp;
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
$result->discount_amount = 0.00;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
//首次购买折扣
|
|||
|
|
$hasBuyOrder = ConsultationRecords::where('merchant_user_id', $merchant_user_id)
|
|||
|
|
// ->where('anchor_id',$result->consult_account_id)
|
|||
|
|
->where('consulation_id', $result->id)
|
|||
|
|
->whereIn('pay_status', [1, 4])->first();
|
|||
|
|
if (!$hasBuyOrder && $result->first_buy_discount < 1) {
|
|||
|
|
$result->has_buy_discount = 1;
|
|||
|
|
$result->first_discount_price = number_format($result->price * $result->first_buy_discount, 2, '.', '');
|
|||
|
|
}
|
|||
|
|
$result->discount_amount = 0.00;
|
|||
|
|
}
|
|||
|
|
if ($request->from_openid && $request->from_openid != $merchant_user->openid) {
|
|||
|
|
MEarningShare::create(["user_id" => $merchant_user->id, "type" => Consultation::class, 'type_id' => $request->consultation_id, 'from_openid' => $request->from_openid]);
|
|||
|
|
}
|
|||
|
|
return $this->success('ok', $result);
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure($e->getMessage());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 商户咨询-支付订单
|
|||
|
|
* *
|
|||
|
|
* @param Request $request
|
|||
|
|
* @return JsonResponse|string
|
|||
|
|
*/
|
|||
|
|
public function BusinessPayConsultation(Request $request)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$sku_id = $request->sku_id;
|
|||
|
|
$buy_type = $request->buy_type ?? 'normal';//normal:单独购买 group:拼团购买
|
|||
|
|
$consultation_id = $request->consultation_id;
|
|||
|
|
$num = $request->num ?? 1;
|
|||
|
|
$user_coupon_id = $request->user_coupon_id;
|
|||
|
|
$merchant_user_id = $request->merchant_user_id;
|
|||
|
|
$wechatUser = session('wechat.oauth_user.new');
|
|||
|
|
$openId = null;
|
|||
|
|
if ($wechatUser)
|
|||
|
|
$openId = $wechatUser->getId();
|
|||
|
|
if ($user_coupon_id && $buy_type == 'group') {
|
|||
|
|
return $this->failure('优惠券与团购不能同时使用');
|
|||
|
|
}
|
|||
|
|
$scheduling_id = $request->scheduling_id;//排班预约时间段id
|
|||
|
|
$config = Consultation::where('id', $consultation_id)->first();
|
|||
|
|
$has_buy_discount = 0;//是否有首次购买折扣
|
|||
|
|
if ($buy_type && $buy_type == 'group') {
|
|||
|
|
$time = date('Y-m-d H:i:s');
|
|||
|
|
$group = CollageGroup::where('type', 'consult')->where('type_id', $consultation_id)->first();
|
|||
|
|
if (!$group)
|
|||
|
|
return $this->failure('拼团信息不存在');
|
|||
|
|
$skus = json_decode($group->sku, true) ?? null;
|
|||
|
|
if ($skus && sizeof($skus) > 0 && $sku_id) {
|
|||
|
|
$skus = array_column($skus, null, 'sku_id');
|
|||
|
|
$sku = $skus[$sku_id];
|
|||
|
|
$price = $sku['discount_price'];
|
|||
|
|
} else {
|
|||
|
|
$price = $group->price;
|
|||
|
|
}
|
|||
|
|
$group_id = $group->id;
|
|||
|
|
$history_id = $request->history_id;
|
|||
|
|
$history = CollageGroupHistories::where('id', $history_id)->first();
|
|||
|
|
if ($history) {
|
|||
|
|
if ($history->deadline < $time)
|
|||
|
|
return $this->failure('你慢了一步,拼团已过有效期');
|
|||
|
|
if ($history->status == 1)
|
|||
|
|
return $this->failure('你慢了一步,该团已被他人完成');
|
|||
|
|
$m_order_ids = CollageGroupHistories::where('group_id', $history->group_id)
|
|||
|
|
->where('m_user_id', $request->merchant_user_id)->where('status', 0)->where('deadline', '>', $time)
|
|||
|
|
->pluck('m_order_id')->toArray();
|
|||
|
|
$exists = TouristOrder::whereIn('id', $m_order_ids)->whereIn('pay_status', [1, 4])->first();
|
|||
|
|
if ($exists)
|
|||
|
|
return $this->failure('该活动你有尚未完成的拼团,请耐心等待');
|
|||
|
|
$exists = CollageGroupHistories::with('tOrder')->whereHas('tOrder', function ($sql) {
|
|||
|
|
$sql->whereIn('pay_status', [1, 4]);
|
|||
|
|
})
|
|||
|
|
->where('group_id', $group->id)->where('m_user_id', $request->merchant_user_id)
|
|||
|
|
->where('status', 1)
|
|||
|
|
->first();
|
|||
|
|
if ($exists)
|
|||
|
|
return $this->failure('你已成功拼团参与过该活动,无需重复参与');
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
$price = $config->price;
|
|||
|
|
$group_id = null;
|
|||
|
|
if ($user_coupon_id) {
|
|||
|
|
$user_coupon = UserCoupon::where('id', $user_coupon_id)->with('coupon')->where('status', 0)
|
|||
|
|
->where('m_user_id', $merchant_user_id)->where('m_id', $request->merchant_id)
|
|||
|
|
->first();
|
|||
|
|
if (!$user_coupon || !$user_coupon->coupon) {
|
|||
|
|
return $this->failure('用户优惠券不存在');
|
|||
|
|
}
|
|||
|
|
if ($user_coupon->coupon->type != 'consult' || $user_coupon->coupon->type_id != $consultation_id) {
|
|||
|
|
return $this->failure('用户优惠券类型与购买的项目不符');
|
|||
|
|
}
|
|||
|
|
switch ($user_coupon->coupon->coupon_type) {
|
|||
|
|
case 1:
|
|||
|
|
$price = 0.00;
|
|||
|
|
break;
|
|||
|
|
case 2:
|
|||
|
|
$price = number_format($config->price * $user_coupon->coupon->discount_rate, 2, '.', '');
|
|||
|
|
break;
|
|||
|
|
case 3:
|
|||
|
|
$temp = number_format($config->price - $user_coupon->coupon->discount_rate, 2, '.', '');
|
|||
|
|
if ($temp < 0) {
|
|||
|
|
$price = 0.00;
|
|||
|
|
} else {
|
|||
|
|
$price = $temp;
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
$price = $config->price;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
//首次购买折扣
|
|||
|
|
$hasBuyOrder = ConsultationRecords::where('merchant_user_id', $request->merchant_user_id)
|
|||
|
|
// ->where('anchor_id',$config->consult_account_id)
|
|||
|
|
->where('consulation_id', $config->id)
|
|||
|
|
->whereIn('pay_status', [1, 4])->first();
|
|||
|
|
if (!$hasBuyOrder && $config->first_buy_discount < 1) {
|
|||
|
|
$price = number_format($config->price * $config->first_buy_discount, 2, '.', '');
|
|||
|
|
$has_buy_discount = 1;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
$trade_no = $this->getTradeNO();
|
|||
|
|
$from_open_id = $request->from_openid ?? 0;
|
|||
|
|
$user = MerchantUser::where('id', $request->merchant_user_id)->first();
|
|||
|
|
if (!$user)
|
|||
|
|
return $this->fail('信息有误', 2);
|
|||
|
|
|
|||
|
|
$scheduling = null;
|
|||
|
|
if ($scheduling_id) {
|
|||
|
|
$scheduling = SaasReservationConsultScheduling::where('id', $scheduling_id)
|
|||
|
|
->where('merchant_id', $request->merchant_id)
|
|||
|
|
->first();
|
|||
|
|
if ($scheduling->residue_num == 0) {
|
|||
|
|
return $this->failure('该时间段预约人数已满');
|
|||
|
|
}
|
|||
|
|
$start_time = substr($scheduling['date_range'], 0, 5);
|
|||
|
|
$start_time = strtotime($scheduling['date'] . ' ' . $start_time);
|
|||
|
|
if (time() > $start_time) {
|
|||
|
|
return $this->failure('该时间段已超过,无法预约');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$Consultation = new ConsultationRecords();
|
|||
|
|
$Consultation->anchor_id = $config->consult_account_id;
|
|||
|
|
$Consultation->merchant_id = $request->merchant_id;
|
|||
|
|
$Consultation->merchant_user_id = $request->merchant_user_id;
|
|||
|
|
$Consultation->consulation_id = $consultation_id;
|
|||
|
|
$Consultation->name = $request->name;
|
|||
|
|
$Consultation->phone = $request->phone;
|
|||
|
|
$Consultation->price = $price;
|
|||
|
|
$Consultation->num = $num;
|
|||
|
|
$Consultation->type = $request->type ?? 'voice';
|
|||
|
|
$Consultation->class = $request->class;
|
|||
|
|
$Consultation->expect = $request->expect;
|
|||
|
|
$Consultation->desc = $request->desc;
|
|||
|
|
$Consultation->pay_status = 0;
|
|||
|
|
$Consultation->duration = $config->duration;
|
|||
|
|
$Consultation->Remaining_duration = $config->duration * 60;
|
|||
|
|
$Consultation->viewer_id = 0;
|
|||
|
|
$Consultation->trade_no = $trade_no;
|
|||
|
|
$Consultation->from_open_id = $from_open_id;
|
|||
|
|
$Consultation->scheduling_id = $scheduling_id ?? 0;
|
|||
|
|
$Consultation->save();
|
|||
|
|
|
|||
|
|
list($pay_type, $sub_mch_id) = MerchantAccount::payType($request->merchant_id);
|
|||
|
|
|
|||
|
|
$TouristOrder = new TouristOrder();
|
|||
|
|
$TouristOrder->open_id = $openId;
|
|||
|
|
$TouristOrder->price = $price;
|
|||
|
|
$TouristOrder->type_id = $request->consultation_id;
|
|||
|
|
$TouristOrder->pay_type = $pay_type;
|
|||
|
|
$TouristOrder->type = 'consult';
|
|||
|
|
$TouristOrder->withdrawal_radio = 100;
|
|||
|
|
$TouristOrder->pay_status = 0;
|
|||
|
|
$TouristOrder->trade_no = $trade_no;
|
|||
|
|
$TouristOrder->group_id = $group_id;
|
|||
|
|
$TouristOrder->from_openid = $from_open_id;
|
|||
|
|
$TouristOrder->share_channel_id = $request->share_channel_id;
|
|||
|
|
$TouristOrder->name = $request->name;
|
|||
|
|
$TouristOrder->desc = $config->title;
|
|||
|
|
$TouristOrder->mobile = $request->phone;
|
|||
|
|
$TouristOrder->merchant_id = $request->merchant_id;
|
|||
|
|
$TouristOrder->account_id = $request->merchant_user_id;
|
|||
|
|
$TouristOrder->alliance_id = $request->alliance_id ?? null;
|
|||
|
|
$TouristOrder->extend = json_encode(compact('has_buy_discount'));
|
|||
|
|
if ($user_coupon_id) {
|
|||
|
|
$TouristOrder->user_coupon_id = $user_coupon_id;
|
|||
|
|
}
|
|||
|
|
$TouristOrder->save();
|
|||
|
|
if ($buy_type == 'group') {
|
|||
|
|
if ($request->history_id) {
|
|||
|
|
$history = CollageGroupHistories::find($request->history_id);
|
|||
|
|
$deadline = $history->deadline;
|
|||
|
|
$is_initiator = 0;
|
|||
|
|
$CollageGroupHistories = new CollageGroupHistories();
|
|||
|
|
$CollageGroupHistories->m_user_id = $TouristOrder->account_id;
|
|||
|
|
$CollageGroupHistories->group_id = $TouristOrder->group_id;
|
|||
|
|
$CollageGroupHistories->m_order_id = $TouristOrder->id;
|
|||
|
|
$CollageGroupHistories->group_master_id = $request->history_id;
|
|||
|
|
$CollageGroupHistories->is_initiator = $is_initiator;
|
|||
|
|
$CollageGroupHistories->status = 0;
|
|||
|
|
$CollageGroupHistories->deadline = $deadline;
|
|||
|
|
$CollageGroupHistories->save();
|
|||
|
|
} else {
|
|||
|
|
//分享不带history_id 就是团长
|
|||
|
|
$deadline = date('Y-m-d H:i:s', strtotime('+' . $group->expire_in . 'hours'));
|
|||
|
|
$is_initiator = 1;
|
|||
|
|
$CollageGroupHistories = new CollageGroupHistories();
|
|||
|
|
$CollageGroupHistories->m_user_id = $TouristOrder->account_id;
|
|||
|
|
$CollageGroupHistories->group_id = $TouristOrder->group_id;
|
|||
|
|
$CollageGroupHistories->m_order_id = $TouristOrder->id;
|
|||
|
|
$CollageGroupHistories->is_initiator = $is_initiator;
|
|||
|
|
$CollageGroupHistories->status = 0;
|
|||
|
|
$CollageGroupHistories->deadline = $deadline;
|
|||
|
|
$CollageGroupHistories->save();
|
|||
|
|
$CollageGroupHistories->group_master_id = $CollageGroupHistories->id;
|
|||
|
|
$CollageGroupHistories->save();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// if ($config->price != 0 && $consultation_id!=58) {
|
|||
|
|
if ($price != 0) {
|
|||
|
|
$callback = config('app.url') . '/api/app/callback/consultation/' . $trade_no;
|
|||
|
|
$attributes = array(
|
|||
|
|
'id' => $Consultation->id,
|
|||
|
|
'order_id' => $TouristOrder->id,
|
|||
|
|
'trade_type' => 'JSAPI', // JSAPI,NATIVE,APP...
|
|||
|
|
'body' => $config->title,
|
|||
|
|
'detail' => '咨询服务',
|
|||
|
|
'out_trade_no' => $trade_no,
|
|||
|
|
'total_fee' => round($price * 100),
|
|||
|
|
'notify_url' => $callback, // 支付结果通知网址,如果不设置则会使用配置里的默认地址
|
|||
|
|
'openid' => $openId ?? $user->openid,
|
|||
|
|
);
|
|||
|
|
if ($pay_type == 'partner') {
|
|||
|
|
$result = WechatService::partnerPay($TouristOrder->id, $sub_mch_id, $price, $attributes['openid'], $attributes['out_trade_no'], $attributes['notify_url'], $attributes['body']);
|
|||
|
|
} else {
|
|||
|
|
$result = WechatService::officialPay($attributes);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
return $this->success('ok', $result);
|
|||
|
|
} else {
|
|||
|
|
$Consultation->pay_status = 1;
|
|||
|
|
$TouristOrder->pay_status = 1;
|
|||
|
|
$TouristOrder->save();
|
|||
|
|
$data['status'] = 1;
|
|||
|
|
$data['id'] = $Consultation->id;
|
|||
|
|
$res = Consultation::where('id', $Consultation->consulation_id)->first();
|
|||
|
|
if ($scheduling) {
|
|||
|
|
$scheduling->decrement('residue_num', 1);
|
|||
|
|
// $TouristOrder->name .= "(预约时间:{$scheduling->date} {$scheduling->date_range})";
|
|||
|
|
$Consultation->reservation_time = "{$scheduling->date} {$scheduling->date_range}";
|
|||
|
|
}
|
|||
|
|
$Consultation->save();
|
|||
|
|
if (isset($user_coupon) && $user_coupon) {
|
|||
|
|
$user_coupon->status = 1;
|
|||
|
|
$user_coupon->save();
|
|||
|
|
}
|
|||
|
|
//通知用户
|
|||
|
|
$way = 'consulation';
|
|||
|
|
$type = 'merchant';
|
|||
|
|
$user_openid = $TouristOrder->open_id;
|
|||
|
|
\CommonUtilsService::sendBuySuccessNoticeToUser($res, $user_openid, $way, $trade_no, $Consultation->price);
|
|||
|
|
$merchant = MerchantAccount::where('id', $Consultation->merchant_id)->first();
|
|||
|
|
$merchant_openid = $merchant->openid;
|
|||
|
|
if (empty($merchant_openid))
|
|||
|
|
$merchant_openid = Anchor::where('m_id', $merchant->id)->value('openid');
|
|||
|
|
//通知商户
|
|||
|
|
\CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $merchant_openid, $type, $TouristOrder->price, $TouristOrder->mobile, $TouristOrder->name);
|
|||
|
|
//发送推荐人
|
|||
|
|
if ($TouristOrder->from_openid && $Consultation->from_openid != 'null') {
|
|||
|
|
$type = 'recommend';
|
|||
|
|
\CommonUtilsService::sendBuySuccessNoticeToBusiness($res, $TouristOrder->from_openid, $type, $TouristOrder->price, $TouristOrder->mobile, $TouristOrder->name);
|
|||
|
|
}
|
|||
|
|
//短信通知商家
|
|||
|
|
$jump_url = env('APP_URL') . '/pu_m/#/earningsRecord?merchant_id=' . $merchant->id;
|
|||
|
|
$short_url = \CommonUtilsService::shortUrl(env('APP_URL') . '/h5/#/jump_url?url=' . $jump_url);
|
|||
|
|
$title = $res->title;
|
|||
|
|
if (mb_strlen($title) > 5) {
|
|||
|
|
$title = mb_substr($title, 0, 5, 'utf-8') . '...';
|
|||
|
|
}
|
|||
|
|
$message = '有用户下单了~ ' . $TouristOrder->name . '购买了平台的《' . $title . '》' . $TouristOrder->price . '元,点击' . $short_url['url'] . ' 查看详情';
|
|||
|
|
Messenger::sendSMS($merchant->mobile, $message);
|
|||
|
|
//增加记录
|
|||
|
|
Message::create([
|
|||
|
|
'phone' => $merchant->mobile,
|
|||
|
|
'message' => $message,
|
|||
|
|
'confirmed' => 1,
|
|||
|
|
'code' => '购买通知',
|
|||
|
|
'ip' => request() ? request()->ip() : '127.0.0.1',
|
|||
|
|
]);
|
|||
|
|
//插入购买通知
|
|||
|
|
// $pay_name = $result->user ? $result->user->nickname : '匿名用户';
|
|||
|
|
$content = $Consultation->name . '购买了【' . $res->title . '】查看订单详情>>';
|
|||
|
|
SaasNotice::addRecord($TouristOrder->merchant_id, $TouristOrder->account_id, 'order', $TouristOrder->id, $content, 0);
|
|||
|
|
//通知老师
|
|||
|
|
// if ($request->merchant_id != 596){
|
|||
|
|
// return $this->success('ok', $data);
|
|||
|
|
// }
|
|||
|
|
$consult_account = ConsultAccount::find($config->consult_account_id);
|
|||
|
|
if ($consult_account && $consult_account->mobile) {
|
|||
|
|
//公众号
|
|||
|
|
$content = "有用户下单了【{$config->title}】咨询。";
|
|||
|
|
$teacher = MerchantUser::where('mobile', $consult_account->mobile)->first();
|
|||
|
|
if ($teacher && $teacher->openid) {
|
|||
|
|
\CommonUtilsService::consultCustomNotice(
|
|||
|
|
$teacher->openid,
|
|||
|
|
'',
|
|||
|
|
$TouristOrder->name,
|
|||
|
|
$scheduling ? "{$scheduling->date} {$scheduling->date_range}" : '',
|
|||
|
|
$content
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
//短信
|
|||
|
|
$content = "咨询预约通知:有用户下单了【{$config->title}】咨询。";
|
|||
|
|
if ($scheduling) {
|
|||
|
|
$content .= "预约时间{$scheduling->date} {$scheduling->date_range}";
|
|||
|
|
}
|
|||
|
|
Message::create([
|
|||
|
|
'phone' => $consult_account->mobile,
|
|||
|
|
'message' => $content,
|
|||
|
|
'confirmed' => 1,
|
|||
|
|
'ip' => request() ? request()->ip() : '127.0.0.1',
|
|||
|
|
]);
|
|||
|
|
Messengers::sendSMS($consult_account->mobile, $content);
|
|||
|
|
}
|
|||
|
|
return $this->success('ok', $data);
|
|||
|
|
}
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 商户-我的咨询
|
|||
|
|
* @param Request $request
|
|||
|
|
* @return JsonResponse|string
|
|||
|
|
*/
|
|||
|
|
public function BusinessMyConsultation(Request $request)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$status = $request->status;
|
|||
|
|
$merchant_id = $request->merchant_id;
|
|||
|
|
$merchant_user_id = $request->merchant_user_id;
|
|||
|
|
// Consultation::where('')
|
|||
|
|
$c_ids = ConsultAccount::where('merchant_id', $request->merchant_id)->pluck('id')->toArray();
|
|||
|
|
$consult_ids = Consultation::withTrashed()->whereIn('consult_account_id', $c_ids)->pluck('id')->toArray();
|
|||
|
|
|
|||
|
|
if ($request->type == 'user') {
|
|||
|
|
$result = ConsultationRecords::with('reservationConsult')
|
|||
|
|
->where('merchant_user_id', $merchant_user_id)
|
|||
|
|
->where('merchant_id', $merchant_id)
|
|||
|
|
->whereIn('pay_status', [1, 4]);
|
|||
|
|
} else {
|
|||
|
|
$result = ConsultationRecords::with('reservationConsult')
|
|||
|
|
->where('merchant_id', $merchant_id)
|
|||
|
|
->whereIn('pay_status', [1, 4]);
|
|||
|
|
}
|
|||
|
|
if ($status)
|
|||
|
|
$result = $result->where('status', $status);
|
|||
|
|
$result = $result->whereIn('consulation_id', $consult_ids)->orderBy('id', 'desc')->paginate();
|
|||
|
|
foreach ($result as $key => $value) {
|
|||
|
|
$config = Consultation::withTrashed()->where('id', $value->consulation_id)->first();
|
|||
|
|
$teacher = ConsultAccount::where('id', $config->consult_account_id)->first();
|
|||
|
|
$value->consult_account_id = $config->consult_account_id;
|
|||
|
|
$value->avatar = $teacher->pic;
|
|||
|
|
$value->mobile = $teacher->mobile;
|
|||
|
|
$value->duration = $config->duration;
|
|||
|
|
$value->name = $teacher->name;
|
|||
|
|
$value->designation = $teacher->designation;
|
|||
|
|
if (isset($teacher->label)) {
|
|||
|
|
$value->label = json_decode($teacher->label, true);
|
|||
|
|
} else {
|
|||
|
|
$value->label = null;
|
|||
|
|
}
|
|||
|
|
$value->price = floatval($value->price);
|
|||
|
|
// 订单状态
|
|||
|
|
$value->state = 0;
|
|||
|
|
if ($value->status == 0) {
|
|||
|
|
$value->state = 1;
|
|||
|
|
} elseif ($value->status == 2 && !$value->Praise) {
|
|||
|
|
$value->state = 2;//待评分
|
|||
|
|
} else {
|
|||
|
|
$value->state = 3; //已完成
|
|||
|
|
}
|
|||
|
|
unset($value->anchor);
|
|||
|
|
unset($value->viewer);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
return $this->success('ok', $result);
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure('服务器休息,请稍后再试');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 咨询-用户提交评价
|
|||
|
|
* @param Request $request
|
|||
|
|
* @return JsonResponse|string
|
|||
|
|
*/
|
|||
|
|
public function SubmitComment(Request $request)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
//咨询订单id
|
|||
|
|
$id = $request->id;
|
|||
|
|
$comment = $request->comment;
|
|||
|
|
$Praise = $request->Praise;
|
|||
|
|
$pic = $request->pic;
|
|||
|
|
$pay_log = new PayLog();
|
|||
|
|
$pay_log->type = 'SubmitComment';
|
|||
|
|
$pay_log->remark = $id;
|
|||
|
|
$pay_log->save();
|
|||
|
|
$is_anonymous = $request->input('is_anonymous', 0); //是否匿名评价
|
|||
|
|
// $result = ConsultationRecords::where('id', $id)->whereIn('pay_status', [1, 4])->where('status', '<>', 0)->first();
|
|||
|
|
$result = ConsultationRecords::where('id', $id)->whereIn('pay_status', [1, 4])->first();
|
|||
|
|
if (!$result)
|
|||
|
|
return $this->failure('未查询到该订单。');
|
|||
|
|
if ($result->comment)
|
|||
|
|
return $this->failure('您已经提交过评价啦1');
|
|||
|
|
$record = ConsultationRecords::where('id', $id)->first();
|
|||
|
|
$con = Consultation::where('id', $record->consulation_id)->first();
|
|||
|
|
$value = TouristOrder::where('type', 'consult')->where('type_id', $con->id)->first();
|
|||
|
|
$result->comment = $comment;
|
|||
|
|
$result->Praise = $Praise;
|
|||
|
|
if ($is_anonymous == 1) {
|
|||
|
|
$result->is_anonymous = $is_anonymous;
|
|||
|
|
}
|
|||
|
|
$result->comment_time = date('Y-m-d H:i:s');
|
|||
|
|
$result->save();
|
|||
|
|
$value->comment = $comment;
|
|||
|
|
$value->Praise = $Praise;
|
|||
|
|
$value->pic = json_encode($pic);
|
|||
|
|
$value->save();
|
|||
|
|
//通知老师
|
|||
|
|
$consult_account = ConsultAccount::find($con->consult_account_id);
|
|||
|
|
if ($consult_account && $consult_account->mobile) {
|
|||
|
|
//公众号
|
|||
|
|
$content = "用户{$result->name}提交了咨询评价,感谢您的辛勤付出!";
|
|||
|
|
$teacher = MerchantUser::where('mobile', $consult_account->mobile)->first();
|
|||
|
|
if ($teacher && $teacher->openid) {
|
|||
|
|
\CommonUtilsService::consultCustomNotice(
|
|||
|
|
$teacher->openid,
|
|||
|
|
'',
|
|||
|
|
$result->name,
|
|||
|
|
$result->reservation_time,
|
|||
|
|
$content
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
$content = "用户{$result->name}提交了【{$con->title}】咨询评价,感谢您的辛勤付出!";
|
|||
|
|
//短信
|
|||
|
|
Message::create([
|
|||
|
|
'phone' => $consult_account->mobile,
|
|||
|
|
'message' => $content,
|
|||
|
|
'confirmed' => 1,
|
|||
|
|
'ip' => request() ? request()->ip() : '127.0.0.1',
|
|||
|
|
]);
|
|||
|
|
Messengers::sendSMS($consult_account->mobile, $content);
|
|||
|
|
}
|
|||
|
|
return $this->success('ok');
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 商户咨询-用户评价列表
|
|||
|
|
* @param Request $request
|
|||
|
|
* @return JsonResponse|string
|
|||
|
|
*/
|
|||
|
|
public function BusinessConsultationComment(Request $request)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$consulation_id = $request->consultation_id;
|
|||
|
|
$result = ConsultationRecords::select(
|
|||
|
|
'id',
|
|||
|
|
'anchor_id',
|
|||
|
|
'name',
|
|||
|
|
'price',
|
|||
|
|
'type',
|
|||
|
|
'comment',
|
|||
|
|
'Praise',
|
|||
|
|
'created_at',
|
|||
|
|
'updated_at',
|
|||
|
|
'consulation_id',
|
|||
|
|
'merchant_id',
|
|||
|
|
'merchant_user_id',
|
|||
|
|
'is_anonymous',
|
|||
|
|
'comment_time'
|
|||
|
|
)
|
|||
|
|
// ->where('consulation_id', $consulation_id)
|
|||
|
|
->when($consulation_id, function ($query) use ($consulation_id) {
|
|||
|
|
if ($consulation_id == 358) {
|
|||
|
|
//id357咨询的评论同步到id358
|
|||
|
|
$query->whereIn('consulation_id', [358, 357]);
|
|||
|
|
} else {
|
|||
|
|
$query->where('consulation_id', $consulation_id);
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
->whereNotNull('Praise')
|
|||
|
|
->orderBy('comment_time', 'desc')
|
|||
|
|
->orderBy('updated_at', 'desc')
|
|||
|
|
->paginate();
|
|||
|
|
foreach ($result as $key => $value) {
|
|||
|
|
$time = date('Y-m-d H:i', strtotime($value->created_at));
|
|||
|
|
$value->time = $time;
|
|||
|
|
$teacher = Consultation::where('id', $consulation_id)->first();
|
|||
|
|
$user = MerchantUser::where('id', $value->merchant_user_id)->first();
|
|||
|
|
$value->avatar = $user->pic ?? User::DefaultAvatar;
|
|||
|
|
if ($user && $user->nickname) {
|
|||
|
|
$value->name = $user->nickname;
|
|||
|
|
}
|
|||
|
|
$value->duration = $teacher->duration ?? 60;
|
|||
|
|
unset($value->viewer);
|
|||
|
|
unset($value->anchor);
|
|||
|
|
//匿名
|
|||
|
|
if ($value->is_anonymous == 1) {
|
|||
|
|
$value->name = '匿名用户';
|
|||
|
|
$value->avatar = User::DefaultAvatar;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return $this->success('ok', $result);
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 商户咨询订单详情
|
|||
|
|
* *
|
|||
|
|
* @param Request $request
|
|||
|
|
* @return JsonResponse|string
|
|||
|
|
*/
|
|||
|
|
public function BusinessMyConsultationDetails(Request $request)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$id = $request->id;
|
|||
|
|
$result = ConsultationRecords::select(
|
|||
|
|
'id',
|
|||
|
|
'name',
|
|||
|
|
'phone',
|
|||
|
|
'price',
|
|||
|
|
'desc',
|
|||
|
|
'expect',
|
|||
|
|
'Praise',
|
|||
|
|
'comment',
|
|||
|
|
'status',
|
|||
|
|
'duration',
|
|||
|
|
'created_at',
|
|||
|
|
'record',
|
|||
|
|
'viewer_id',
|
|||
|
|
'trade_no'
|
|||
|
|
)
|
|||
|
|
->where('id', $id)->whereIn('pay_status', [1, 4])
|
|||
|
|
->first();
|
|||
|
|
$result->Praise = floatval($result->Praise);
|
|||
|
|
$result->price = floatval($result->price);
|
|||
|
|
$pic = TouristOrder::where('trade_no', $result->trade_no)->value('pic');
|
|||
|
|
$result->pic = json_decode($pic, true);
|
|||
|
|
$result->avatar = MerchantUser::where('id', $request->merchant_user_id)->value('pic') ?? User::DefaultAvatar;
|
|||
|
|
unset($result->viewer);
|
|||
|
|
return $this->success('ok', $result);
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure('服务器休息中,请稍后再试');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 预约排班
|
|||
|
|
* @param Request $request
|
|||
|
|
* @param ConsultService $s
|
|||
|
|
* @return JsonResponse|void
|
|||
|
|
*/
|
|||
|
|
public function reservationScheduling(Request $request, ConsultService $s)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$merchant_id = $request->merchant_id;
|
|||
|
|
$lately_day = $request->input('lately_day', 7);
|
|||
|
|
$consult_account_id = $request->input('consult_account_id');
|
|||
|
|
return $this->success('ok', $s->getLatelyScheduling($merchant_id, $consult_account_id, $lately_day));
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure($e->getMessage());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取指定日期的预约排班数据
|
|||
|
|
* @param Request $request
|
|||
|
|
* @return JsonResponse|string
|
|||
|
|
*/
|
|||
|
|
public function getSchedulingDetail(Request $request)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
$merchant_id = $request->merchant_id;
|
|||
|
|
$date = $request->input('date');
|
|||
|
|
$time = strtotime($date);
|
|||
|
|
$date = date('Y-m-d', $time);
|
|||
|
|
if (strtotime(date('Y-m-d')) > $time) {
|
|||
|
|
return $this->success('ok');
|
|||
|
|
}
|
|||
|
|
$consult_account_id = $request->input('consult_account_id');
|
|||
|
|
$reservation_teacher_id = SaasReservationTeacher::where('merchant_id', $merchant_id)
|
|||
|
|
->where('consult_account_id', $consult_account_id)
|
|||
|
|
->value('id');
|
|||
|
|
$where = [
|
|||
|
|
['date', '=', $date],
|
|||
|
|
['merchant_id', '=', $merchant_id],
|
|||
|
|
['reservation_teacher_id', '=', $reservation_teacher_id],
|
|||
|
|
['is_show', '=', 1]
|
|||
|
|
];
|
|||
|
|
$data = SaasReservationConsultScheduling::where($where)
|
|||
|
|
->selectRaw("*,left(date_range,5) as start_time,right(date_range,5) as end_time")
|
|||
|
|
->orderBy('start_time', 'asc')
|
|||
|
|
->get();
|
|||
|
|
return $this->success('ok', $data);
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure($e->getMessage());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 设置订单预约时间
|
|||
|
|
* @return JsonResponse|string
|
|||
|
|
*/
|
|||
|
|
public function consultOrderChange(Request $request)
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
DB::beginTransaction();
|
|||
|
|
$merchant_id = $request->merchant_id;
|
|||
|
|
$merchant_user_id = $request->merchant_user_id;
|
|||
|
|
$id = $request->id;
|
|||
|
|
$scheduling_id = $request->scheduling_id;
|
|||
|
|
$where = [
|
|||
|
|
['merchant_id', '=', $merchant_id],
|
|||
|
|
['merchant_user_id', '=', $merchant_user_id],
|
|||
|
|
['id', '=', $id]
|
|||
|
|
];
|
|||
|
|
$order = ConsultationRecords::where($where)
|
|||
|
|
->whereIn('pay_status', [1, 4])
|
|||
|
|
->first();
|
|||
|
|
if (!$order) {
|
|||
|
|
return $this->failure('未找到订单');
|
|||
|
|
}
|
|||
|
|
if ($order->scheduling_id) {
|
|||
|
|
return $this->failure('该订单已选择预约时间了');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$scheduling = SaasReservationConsultScheduling::find($scheduling_id);
|
|||
|
|
if (!$scheduling) {
|
|||
|
|
return $this->failure('预约配置数据未找到');
|
|||
|
|
}
|
|||
|
|
if ($scheduling->residue_num == 0) {
|
|||
|
|
return $this->failure('该时间段预约人数已满了');
|
|||
|
|
}
|
|||
|
|
$order->scheduling_id = $scheduling_id;
|
|||
|
|
$order->reservation_time = "{$scheduling->date} {$scheduling->date_range}";
|
|||
|
|
$order->save();
|
|||
|
|
$scheduling->decrement('residue_num', 1);
|
|||
|
|
DB::commit();
|
|||
|
|
return $this->success('ok');
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
DB::rollBack();
|
|||
|
|
$this->getError($e);
|
|||
|
|
return $this->failure($e->getMessage());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|