706 lines
27 KiB
PHP
706 lines
27 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\Admin;
|
||
|
|
|
||
|
|
use App\Models\Platform;
|
||
|
|
use App\Models\Rbac\RoleUser;
|
||
|
|
use EasyWeChat\Factory;
|
||
|
|
use App\Models\Activity;
|
||
|
|
use App\Models\ActivityMember;
|
||
|
|
use App\Models\Coin;
|
||
|
|
use App\Models\Community;
|
||
|
|
use App\Models\CommunityMember;
|
||
|
|
use App\Models\OrderRemarks;
|
||
|
|
use App\Models\RatioCoin;
|
||
|
|
use App\Models\RefundOrder;
|
||
|
|
use App\Models\SingleService;
|
||
|
|
use App\Models\SubRank;
|
||
|
|
use App\Models\User;
|
||
|
|
use App\Models\Linking;
|
||
|
|
use App\Models\LinkingRequest;
|
||
|
|
use App\Models\Wechat;
|
||
|
|
use App\Models\ProfileCourtship;
|
||
|
|
use App\Models\ProfileMarriage;
|
||
|
|
use App\Models\Salary;
|
||
|
|
use App\Models\Order;
|
||
|
|
use App\Models\PayOrder;
|
||
|
|
use App\Models\Rank;
|
||
|
|
use App\Models\RankHistory;
|
||
|
|
use App\Models\FriendQuestionAnswer;
|
||
|
|
use App\Models\Notice;
|
||
|
|
use App\Models\ComplaintHistory;
|
||
|
|
use App\Models\UserGift;
|
||
|
|
use App\Models\Gift;
|
||
|
|
use App\Models\Goods;
|
||
|
|
use App\Models\VipQuestionAnswer;
|
||
|
|
use App\Models\VipAnswerResult;
|
||
|
|
use App\Models\VipQuestion;
|
||
|
|
use App\Models\VipQuestionOption;
|
||
|
|
use App\Models\GiftHistory;
|
||
|
|
use App\Models\ScoreHistory;
|
||
|
|
use App\Models\Dynamic;
|
||
|
|
use App\Models\Score;
|
||
|
|
use App\Models\Character;
|
||
|
|
use App\Models\LoveCharacter;
|
||
|
|
use App\Models\LoveLanguage;
|
||
|
|
use App\Models\InviteOrder;
|
||
|
|
use App\Utils\Messenger;
|
||
|
|
use App\Utils\Http;
|
||
|
|
use App\Events\NoticeServer;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use App\Repositories\Eloquent\SmsRepository as Sms;
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use App\Models\Appointment;
|
||
|
|
use App\Contracts\UserContract;
|
||
|
|
use App\Models\CommunityActivity;
|
||
|
|
use App\Models\Consultation;
|
||
|
|
use App\Models\Course\Course;
|
||
|
|
use App\Models\MerchantShop;
|
||
|
|
use App\Models\PaasOrder;
|
||
|
|
use App\Models\PaasActivity;
|
||
|
|
use App\Models\Server\MerchantInformation;
|
||
|
|
use App\Models\Server\TouristOrder;
|
||
|
|
use Illuminate\Support\Facades\DB;
|
||
|
|
use PhpParser\Node\Expr\Empty_;
|
||
|
|
|
||
|
|
class OrderController extends Controller
|
||
|
|
{
|
||
|
|
|
||
|
|
protected $sms;
|
||
|
|
protected $userCon;
|
||
|
|
public function __construct(Sms $sms, UserContract $userCon){
|
||
|
|
$this->sms = $sms;
|
||
|
|
$this->userCon = $userCon;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 订单列表
|
||
|
|
* @param Request $request 传入的参数
|
||
|
|
*/
|
||
|
|
public function orders(Request $request, PaasOrder $paas_order)
|
||
|
|
{
|
||
|
|
$orders = Order::with('orderRemarks', 'user','user.clientComment')->where('user_id', '!=', 616);
|
||
|
|
// ->whereHas('user',function($q){
|
||
|
|
// $q->whereNotNull('mobile');
|
||
|
|
// });
|
||
|
|
$admin_type = $request->session()->get('admin_type');
|
||
|
|
if ($admin_type == 'paas_admin') {
|
||
|
|
$paas_obj = $request->session()->get('paas_obj');
|
||
|
|
$type = $request->input('type');
|
||
|
|
if ($type == 'activity') {
|
||
|
|
$activity_ids = PaasActivity::where('paas_id', $paas_obj->id)->pluck('activity_id');
|
||
|
|
$orders = $orders->whereIn('type_id', $activity_ids)->where('type', 'activity');
|
||
|
|
}elseif (!empty($type)) {
|
||
|
|
$paas_user_ids = $this->userCon->paasUserIds($paas_obj->name, 'MAIN');
|
||
|
|
// $paas_order_ids = $paas_order->where('paas_id', $paas_obj->id)->pluck('order_id');
|
||
|
|
$orders = $orders->whereIn('user_id', $paas_user_ids)->where('type', $type);
|
||
|
|
}else{
|
||
|
|
$paas_user_ids = $this->userCon->paasUserIds($paas_obj->name, 'MAIN');
|
||
|
|
$paas_order_ids = Order::where('type', '<>', 'activity')->whereIn('user_id', $paas_user_ids)->pluck('id')->toArray();
|
||
|
|
$activity_ids = PaasActivity::where('paas_id', $paas_obj->id)->pluck('activity_id');
|
||
|
|
$paas_activity_order_ids = Order::whereIn('type_id', $activity_ids)->where('type', 'activity')->pluck('id')->toArray();
|
||
|
|
$new_paas_order_ids = array_merge($paas_order_ids, $paas_activity_order_ids);
|
||
|
|
$orders = $orders->whereIn('id', $new_paas_order_ids);
|
||
|
|
}
|
||
|
|
|
||
|
|
}else{
|
||
|
|
$type = $request->input('type', '');
|
||
|
|
if ($type) {
|
||
|
|
if ($type =='active') {
|
||
|
|
// $type_ids = Appointment::where('type',$type)->pluck('id');
|
||
|
|
// $orders = $orders->where(function($sql) use($type_ids) {
|
||
|
|
// $sql->where(function($query) use($type_ids){
|
||
|
|
// $sql->where('type', 'meet')->whereIn('type_id', $type_ids);
|
||
|
|
// })->orWhere('type', 'single_service')->whereIn('type_id', [2,4]);
|
||
|
|
// });
|
||
|
|
$orders = $orders->where('type', 'single_service')->whereIn('type_id', [2,4]);
|
||
|
|
}elseif($type == 'passive'){
|
||
|
|
$orders = $orders->where('type', 'single_service')->whereIn('type_id', [3,6]);
|
||
|
|
}else{
|
||
|
|
$orders = $orders->where('type', $type);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$admin_user_id = auth()->id();
|
||
|
|
//是否是推广团队
|
||
|
|
$is_promote = RoleUser::where('user_id', $admin_user_id)->where('role_id', 6)->count();
|
||
|
|
$platfroms = Platform::where('paas_id', 33)->pluck('app_id')->toArray();
|
||
|
|
if($is_promote){
|
||
|
|
$orders = $orders->whereHas('user', function($query) use ($platfroms){
|
||
|
|
$query->whereIn('from_platform', $platfroms);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
$keyword = $request->input('keyword');
|
||
|
|
if (!empty($keyword)) {
|
||
|
|
$keyword = trim($keyword);
|
||
|
|
$orders = $orders->where('goods', 'like', '%'.$keyword.'%')
|
||
|
|
->orWhereHas('user', function($sql) use($keyword){
|
||
|
|
$sql->where('nickname', 'like', '%'.$keyword.'%')->orWhere('mobile', 'like', '%'.$keyword."%");
|
||
|
|
});
|
||
|
|
}
|
||
|
|
if(is_numeric($request->tag_num)){
|
||
|
|
if($request->tag_num){
|
||
|
|
$orders = $orders->where('tag_num', '!=', 0);
|
||
|
|
}else{
|
||
|
|
$orders = $orders->where('tag_num', 0);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if(is_numeric($request->pay_status)){
|
||
|
|
$pay_status = $request->pay_status ? 'PAID' : 'UNPAID';
|
||
|
|
$orders = $orders->where('pay_status', $pay_status);
|
||
|
|
}
|
||
|
|
$start_time = $request->input('start_time');
|
||
|
|
$end_time = $request->input('end_time');
|
||
|
|
if ($start_time && $end_time) {
|
||
|
|
$orders = $orders->whereBetween('created_at', [$start_time, $end_time]);
|
||
|
|
}
|
||
|
|
if($request->orderby){
|
||
|
|
switch ($request->orderby){
|
||
|
|
case 'last_visit':
|
||
|
|
$order_user_id = $orders->pluck('user_id')->toArray();
|
||
|
|
$last_visit_id = User::whereIn('id', $order_user_id)->orderBy('last_visit', 'desc')->pluck('id')->toArray();
|
||
|
|
$last_visit_id = implode(',', $last_visit_id);
|
||
|
|
$orders = $orders->orderByRaw(DB::raw("FIELD(user_id, $last_visit_id) asc"));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if($request->start_last_visit && $request->end_last_visit){
|
||
|
|
$start_last_visit = $request->start_last_visit;
|
||
|
|
$end_last_visit = $request->end_last_visit;
|
||
|
|
$orders = $orders->whereHas('user', function($sql) use($start_last_visit, $end_last_visit){
|
||
|
|
$sql->whereBetween('last_visit', [$start_last_visit, $end_last_visit]);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
$orders = $orders->select('id', 'user_id', 'type', 'goods','type_id', 'price', 'created_at', 'pay_status', 'tag_num', 'remark')->orderBy('id', 'desc')->paginate();
|
||
|
|
foreach ($orders as $order) {
|
||
|
|
$user = $order->user;
|
||
|
|
if (empty($user)) {
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
$order->user_name = $user->name;
|
||
|
|
$wechat = Wechat::where('user_id', $order->user_id)->select('user_id', 'avatar', 'avatar2')->first();
|
||
|
|
if (empty($wechat)) {
|
||
|
|
$avatar = '';
|
||
|
|
}else{
|
||
|
|
$avatar = $wechat->avatar2?$wechat->avatar2:$wechat->avatar;
|
||
|
|
}
|
||
|
|
$order->avatar = $avatar;
|
||
|
|
$order->status = $this->orderStatus($order->pay_status);
|
||
|
|
if ($order->type=='meet') {
|
||
|
|
$order->type = Appointment::where('id', $order->type_id)->value('type');
|
||
|
|
}
|
||
|
|
$order->have_remark = $order->tag_num ? "已处理" : "未处理";
|
||
|
|
if($is_promote){
|
||
|
|
$order->mobile = substr_replace($user->mobile,'****',3,4);
|
||
|
|
}
|
||
|
|
// $order->user_remark = '';
|
||
|
|
$order->user_remark = count($order->user->clientComment) >= 1 ? $order->user->clientComment[0]['comment'] : '';
|
||
|
|
$order->user->mobile = '';
|
||
|
|
unset($order->user->clientComment);
|
||
|
|
}
|
||
|
|
|
||
|
|
return $this->success('ok', $orders);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 订单详情
|
||
|
|
* @param Request $request 传入参数
|
||
|
|
* @param integer $id 路由参数
|
||
|
|
* @return obj 订单详情
|
||
|
|
*/
|
||
|
|
public function order(Request $request, $order_id)
|
||
|
|
{
|
||
|
|
$order = Order::where('id', $order_id)->firstOrFail();
|
||
|
|
$pay_order = PayOrder::where('trade_no', $order->trade_no)->select('trade_no', 'score', 'cash')->first();
|
||
|
|
if (!empty($pay_order)) {
|
||
|
|
$order->score = $pay_order->score;
|
||
|
|
$order->cash = $pay_order->cash;
|
||
|
|
}else{
|
||
|
|
$order->score = 0;
|
||
|
|
$order->cash = 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
$user = User::where('id', $order->user_id)->select('id', 'name', 'mobile', 'sex', 'from_platform', 'photo', 'circle_avatar', 'app_avatar')->first();
|
||
|
|
$admin_user_id = auth()->id();
|
||
|
|
//是否是推广团队
|
||
|
|
$is_promote = RoleUser::where('user_id', $admin_user_id)->where('role_id', 6)->count();
|
||
|
|
$platfroms = Platform::where('paas_id', 33)->pluck('app_id')->toArray();
|
||
|
|
|
||
|
|
if($is_promote && !in_array($user->from_platform, $platfroms)){
|
||
|
|
return $this->failure('没有权限查看订单');
|
||
|
|
}
|
||
|
|
|
||
|
|
if (empty($user)) {
|
||
|
|
return $this->failure('订单用户不存在');
|
||
|
|
}
|
||
|
|
$wechat = Wechat::where('user_id', $order->user_id)->select('avatar', 'avatar2')->first();
|
||
|
|
if ($wechat) {
|
||
|
|
$user->avatar = $wechat->avatar2?$wechat->avatar2:$wechat->avatar;
|
||
|
|
}
|
||
|
|
$order->user = $user;
|
||
|
|
$order->status = $this->orderStatus($order->pay_status);
|
||
|
|
if ($order->type == 'gift') {
|
||
|
|
//赠送对象
|
||
|
|
$other_user_id = GiftHistory::where(['trade_no'=> $order->trade_no, 'type'=>'GIVEN', 'user_id'=>$order->user_id])->value('other_user_id');
|
||
|
|
$other_user_name = User::where('id', $other_user_id)->value('name');
|
||
|
|
$order->other_user_name = $other_user_name;
|
||
|
|
}elseif ($order->type == 'meet') {
|
||
|
|
$order->type = Appointment::where('id',$order->type_id)->value('type');
|
||
|
|
}
|
||
|
|
if($is_promote){
|
||
|
|
$order->user->mobile = substr_replace($order->user->mobile,'****',3,4);
|
||
|
|
}
|
||
|
|
|
||
|
|
return $this->success('ok', $order);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 交换状态
|
||
|
|
* @param string $status 状态
|
||
|
|
* @return string 状态结果
|
||
|
|
*/
|
||
|
|
public function orderStatus($status)
|
||
|
|
{
|
||
|
|
$result = '';
|
||
|
|
switch ($status) {
|
||
|
|
case 'UNPAID':
|
||
|
|
$result = '未支付';
|
||
|
|
break;
|
||
|
|
case 'PAID':
|
||
|
|
$result = '已支付';
|
||
|
|
break;
|
||
|
|
case 'SENT':
|
||
|
|
$result = '已发货';
|
||
|
|
break;
|
||
|
|
case 'SIGNED':
|
||
|
|
$result = '已签收';
|
||
|
|
break;
|
||
|
|
case 'SETTLED':
|
||
|
|
$result = '已完成';
|
||
|
|
break;
|
||
|
|
default:
|
||
|
|
$result = '已关闭';
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
return $result;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 新增订单备注
|
||
|
|
* @param Request $request
|
||
|
|
* @return mixed
|
||
|
|
*/
|
||
|
|
public function addRemark(Request $request)
|
||
|
|
{
|
||
|
|
$orderId = $request->order_id;
|
||
|
|
// $order = Order::find($orderId);
|
||
|
|
if(empty($orderId)){
|
||
|
|
return $this->failure('订单id不能为空');
|
||
|
|
}
|
||
|
|
$data = [];
|
||
|
|
$maker_user_id = $request->maker_user_id;
|
||
|
|
if(!is_array($orderId) && !is_array($maker_user_id)){
|
||
|
|
$orderIds[0] = $orderId;
|
||
|
|
$maker_user_ids[0] = $maker_user_id;
|
||
|
|
}else{
|
||
|
|
$orderIds = $orderId;
|
||
|
|
$maker_user_ids = $maker_user_id;
|
||
|
|
}
|
||
|
|
foreach ($orderIds as $key => $id) {
|
||
|
|
$me = [];
|
||
|
|
$me['order_id'] = $id;
|
||
|
|
$me['maker_user_id'] = $maker_user_ids[$key];
|
||
|
|
$me['type'] = $request->type ? $request->type : 'mobile';
|
||
|
|
$me['comment'] = $request->comment;
|
||
|
|
$me['pics'] = $request->pics ? json_encode($request->pics) : '';
|
||
|
|
$me['created_at'] = date('Y-m-d H:i:s');
|
||
|
|
$me['updated_at'] = date('Y-m-d H:i:s');
|
||
|
|
array_push($data, $me);
|
||
|
|
//触发websocket
|
||
|
|
}
|
||
|
|
|
||
|
|
try{
|
||
|
|
DB::beginTransaction();
|
||
|
|
OrderRemarks::insert($data);
|
||
|
|
Order::whereIn('id', $orderIds)->increment('tag_num');
|
||
|
|
DB::commit();
|
||
|
|
return $this->success('ok');
|
||
|
|
}catch (\Exception $e){
|
||
|
|
DB::rollBack();
|
||
|
|
return $e->getMessage();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 订单备注列表
|
||
|
|
* @param Request $request
|
||
|
|
* @return mixed
|
||
|
|
*/
|
||
|
|
public function remarkList(Request $request){
|
||
|
|
$orderId = $request->order_id;
|
||
|
|
// $comments = OrderRemarks::orderBy('id', 'desc')->where('order_id', $orderId)->paginate();
|
||
|
|
$comments = OrderRemarks::where('order_id', $orderId)->with('makerUser');
|
||
|
|
$admin_type = $request->session()->get('admin_type');
|
||
|
|
if ($admin_type == 'paas_admin') {
|
||
|
|
$paas_obj = $request->session()->get('paas_obj');
|
||
|
|
$admin_user_ids = Admin::where('type', $paas_obj->name)->pluck('user_id');
|
||
|
|
$comments = $comments->whereIn('maker_user_id', $admin_user_ids);
|
||
|
|
}
|
||
|
|
$comments = $comments->orderBy('id', 'desc')->paginate();
|
||
|
|
foreach ($comments as $comment) {
|
||
|
|
$comment->pics = json_decode($comment->pics, true)?json_decode($comment->pics, true):[];
|
||
|
|
$comment->type = $this->commentType($comment->type);
|
||
|
|
}
|
||
|
|
return $this->success('ok', $comments);
|
||
|
|
return $this->success('ok', $comments);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function commentType($type)
|
||
|
|
{
|
||
|
|
$result = '';
|
||
|
|
if ($type == 'mobile') {
|
||
|
|
$result = '电话访问';
|
||
|
|
}elseif ($type == 'active') {
|
||
|
|
$result = '见面服务';
|
||
|
|
}elseif ($result == 'passive') {
|
||
|
|
return $result = '托管服务';
|
||
|
|
}
|
||
|
|
return $result;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 订单备注详情
|
||
|
|
* @param Request $request
|
||
|
|
* @return mixed
|
||
|
|
*/
|
||
|
|
public function remarkInfo(Request $request){
|
||
|
|
{
|
||
|
|
$comment = OrderRemarks::find($request->remark_id);
|
||
|
|
if(empty($comment)){
|
||
|
|
return $this->failure('备注不存在');
|
||
|
|
}
|
||
|
|
$comment->pics = json_decode($comment->pics, true)?json_decode($comment->pics, true):[];
|
||
|
|
return $this->success('ok', $comment);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 订单备注更新
|
||
|
|
* @param Request $request
|
||
|
|
* @return mixed
|
||
|
|
*/
|
||
|
|
public function remarkUpdate(Request $request){
|
||
|
|
{
|
||
|
|
$remark = OrderRemarks::find($request->remark_id);
|
||
|
|
if(empty($remark)){
|
||
|
|
return $this->failure('备注不存在');
|
||
|
|
}
|
||
|
|
|
||
|
|
if($request->has('type') && $request->type != $remark->type){
|
||
|
|
$remark->type = $request->type;
|
||
|
|
}
|
||
|
|
if($request->has('pics') && json_encode($request->pics) != $remark->pics){
|
||
|
|
$remark->pics = json_encode($request->pics);
|
||
|
|
}
|
||
|
|
if($request->has('comment') && $request->comment != $remark->comment){
|
||
|
|
$remark->comment = $request->comment;
|
||
|
|
}
|
||
|
|
$remark->save();
|
||
|
|
return $this->success('ok');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
//订单退款
|
||
|
|
public function orderRefun(Request $request, $order_id){
|
||
|
|
$order = Order::find($order_id);
|
||
|
|
|
||
|
|
if(empty($order) || $order->pay_status != 'PAID'){
|
||
|
|
return $this->failure('没有支付订单');
|
||
|
|
}
|
||
|
|
|
||
|
|
$refund_order = RefundOrder::where([
|
||
|
|
'user_id'=>$order->user_id,
|
||
|
|
'trade_no'=>$order->trade_no,
|
||
|
|
])->first();
|
||
|
|
if ($refund_order) {
|
||
|
|
return $this->failure('退款已存在');
|
||
|
|
}
|
||
|
|
|
||
|
|
switch ($order->type){
|
||
|
|
case "coin":
|
||
|
|
$refund_desc = '充值福币退款';
|
||
|
|
switch($order->pay_type){
|
||
|
|
case 'wechat':
|
||
|
|
$coin = $order->price*10;
|
||
|
|
break;
|
||
|
|
case 'ios':
|
||
|
|
$coin = $order->coin*7;
|
||
|
|
break;
|
||
|
|
default:
|
||
|
|
}
|
||
|
|
$remain_amount = Coin::where('user_id', $order->user_id)->value('remain_amount');
|
||
|
|
if($remain_amount < $coin){
|
||
|
|
return $this->failure('用户福币不足');
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
case "activity":
|
||
|
|
$refund_desc = '活动退款';
|
||
|
|
$activity_start_time = Activity::where('id', $order->type_id)->value('start_time');
|
||
|
|
// if(date('Y-m-d H:i:s') > $activity_start_time || empty($activity_start_time)){
|
||
|
|
// return $this->failure('活动已经结束');
|
||
|
|
// }
|
||
|
|
break;
|
||
|
|
case "rank":
|
||
|
|
$refund_desc = '会员退款';
|
||
|
|
break;
|
||
|
|
default:
|
||
|
|
$refund_desc = '退款';
|
||
|
|
}
|
||
|
|
|
||
|
|
$refund_trade_no = $this->getRefundTradeNo();
|
||
|
|
$total_fee = $order->price;
|
||
|
|
$refund_fee = $order->price;
|
||
|
|
$array = ['refund_desc' => $refund_desc];
|
||
|
|
$result = \WechatService::orderRefund($order->trade_no, $refund_trade_no, $total_fee, $refund_fee, $array);
|
||
|
|
if (is_array($result) && $result['status'] === true) {
|
||
|
|
RefundOrder::create([
|
||
|
|
'user_id'=>$order->user_id,
|
||
|
|
'type'=>$order->type,
|
||
|
|
'trade_no'=>$order->trade_no,
|
||
|
|
'refund_trade_no'=>$refund_trade_no,
|
||
|
|
'total_fee'=>$total_fee,
|
||
|
|
'refund_fee'=>$refund_fee,
|
||
|
|
'is_hook'=>0,
|
||
|
|
'remark'=>$request->remark,
|
||
|
|
]);
|
||
|
|
return $this->success('退款成功');
|
||
|
|
}else{
|
||
|
|
return $this->failure('退款失败');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
//退款回调
|
||
|
|
public function orderRefunCallback(Request $request){
|
||
|
|
$config = config('wechat.payment');
|
||
|
|
$config['app_id'] = config('wechat.mini_program.app_id');
|
||
|
|
$app = Factory::payment($config);
|
||
|
|
|
||
|
|
$response = $app->handleRefundedNotify(function ($message, $reqInfo, $fail) {
|
||
|
|
if($message['return_code'] == 'FAIL'){
|
||
|
|
//\Log::info('请求退款失败'.$message['return_msg']);
|
||
|
|
return false;
|
||
|
|
}else{
|
||
|
|
$out_trade_no = $reqInfo['out_trade_no'];
|
||
|
|
$order = Order::where('trade_no', $out_trade_no)->first();
|
||
|
|
$pay_order = PayOrder::where('trade_no', $out_trade_no)->first();
|
||
|
|
$refun_order = RefundOrder::where('trade_no', $out_trade_no)->first();
|
||
|
|
if (empty($refun_order)) return $this->failure("订单回调失败,订单不存在");
|
||
|
|
switch ($reqInfo['refund_status']){
|
||
|
|
case "SUCCESS":
|
||
|
|
$refun_order->is_hook = 1;
|
||
|
|
$order->pay_status = 'REFUND';
|
||
|
|
$pay_order->pay_status = 'REFUND';
|
||
|
|
//退款后的操作
|
||
|
|
$this->logicAfterRefund($order);
|
||
|
|
break;
|
||
|
|
case "CHANGE":
|
||
|
|
$refun_order->is_hook = $reqInfo['refund_status'];
|
||
|
|
break;
|
||
|
|
case "REFUNDCLOSE":
|
||
|
|
$refun_order->is_hook = $reqInfo['refund_status'];
|
||
|
|
break;
|
||
|
|
default:
|
||
|
|
}
|
||
|
|
$refun_order->save();
|
||
|
|
$order->save();
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
return $response;
|
||
|
|
}
|
||
|
|
|
||
|
|
//退款之后的操作
|
||
|
|
public function logicAfterRefund($order){
|
||
|
|
switch ($order->type){
|
||
|
|
case 'score':
|
||
|
|
$this->takeScore($order);
|
||
|
|
break;
|
||
|
|
case 'rank':
|
||
|
|
$this->cancelRank($order);
|
||
|
|
break;
|
||
|
|
case 'other_rank':
|
||
|
|
$this->cancelRank($order);
|
||
|
|
break;
|
||
|
|
case 'gift':
|
||
|
|
$this->takeGift($order);
|
||
|
|
break;
|
||
|
|
case 'goods':
|
||
|
|
$this->takeGoods($order);
|
||
|
|
break;
|
||
|
|
case 'meet':
|
||
|
|
$this->cancelMeet($order);
|
||
|
|
break;
|
||
|
|
case 'approve':
|
||
|
|
$this->cancelApprove($order);
|
||
|
|
break;
|
||
|
|
case 'activity':
|
||
|
|
$this->cancelJoinActivity($order);
|
||
|
|
break;
|
||
|
|
case 'donation':
|
||
|
|
$this->cancelDonation($order);
|
||
|
|
break;
|
||
|
|
case 'single_service':
|
||
|
|
$this->cancelSingleService($order);
|
||
|
|
break;
|
||
|
|
case 'community':
|
||
|
|
$this->cancelJoinCommunity($order);
|
||
|
|
break;
|
||
|
|
case 'coin':
|
||
|
|
$this->takeCoin($order);
|
||
|
|
break;
|
||
|
|
default:
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
//退回福分
|
||
|
|
public function takeScore($order){
|
||
|
|
|
||
|
|
}
|
||
|
|
//取消会员
|
||
|
|
public function cancelRank($order){
|
||
|
|
$sub_rank = SubRank::find($order->type_id);
|
||
|
|
$user = User::find($order->user_id);
|
||
|
|
$rank_history = RankHistory::where('user_id', $user->id)->where('rank_id', $sub_rank->rank_id)->first();
|
||
|
|
if(empty($sub_rank) || empty($user) || empty($rank_history)){
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
$deadline = $rank_history->deadline->toDateTimeString();
|
||
|
|
$deadline = date('Y-m-d H:i:s', strtotime("$deadline -$sub_rank->month month"));
|
||
|
|
$rank_history->deadline = $deadline;
|
||
|
|
$rank_history->save();
|
||
|
|
}
|
||
|
|
|
||
|
|
//退回礼物
|
||
|
|
public function takeGift($order){
|
||
|
|
|
||
|
|
}
|
||
|
|
//退回物品
|
||
|
|
public function takeGoods($order){
|
||
|
|
|
||
|
|
}
|
||
|
|
//取消1次人工牵线
|
||
|
|
public function cancelMeet($order){
|
||
|
|
|
||
|
|
}
|
||
|
|
//取消认证
|
||
|
|
public function cancelApprove($order){
|
||
|
|
|
||
|
|
}
|
||
|
|
//取消加入活动
|
||
|
|
public function cancelJoinActivity($order){
|
||
|
|
$activity = Activity::find($order->type_id);
|
||
|
|
$user = User::find($order->user_id);
|
||
|
|
$activity_member = ActivityMember::where('user_id', $user->id)->where('activity_id', $activity->id)->first();
|
||
|
|
if(empty($activity) || empty($user) || empty($activity_member)){
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
$activity_member->delete();
|
||
|
|
}
|
||
|
|
//取消捐款
|
||
|
|
public function cancelDonation($order){
|
||
|
|
|
||
|
|
}
|
||
|
|
//取消人工牵线+市级年VIP
|
||
|
|
public function cancelSingleService($order){
|
||
|
|
$single_service = SingleService::find($order->type_id);
|
||
|
|
$user = User::find($order->user_id);
|
||
|
|
$rank_history = RankHistory::where('user_id', $user->id)->where('rank_id', $single_service->rank_id)->first();
|
||
|
|
if(empty($activity) || empty($user) || empty($rank_history)){
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
$deadline = $rank_history->deadline->toDateTimeString();
|
||
|
|
$deadline = date('Y-m-d H:i:s', strtotime("$deadline -$single_service->rank_month month"));
|
||
|
|
$rank_history->deadline = $deadline;
|
||
|
|
$rank_history->save();
|
||
|
|
}
|
||
|
|
//取消加入社群
|
||
|
|
public function cancelJoinCommunity($order){
|
||
|
|
$communitiy_member = CommunityMember::where('user_id', $order->user_id)->where('community_id', $order->type_id)->first();
|
||
|
|
if(empty($user) || empty($communitiy_member)){
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
$communitiy_member->delete();
|
||
|
|
}
|
||
|
|
|
||
|
|
//减去增加的福币
|
||
|
|
public function takeCoin($order){
|
||
|
|
$coin = $order->price*10;
|
||
|
|
if(empty($ratio_coins) || empty($coins)){
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
switch($order->pay_type){
|
||
|
|
case 'wechat':
|
||
|
|
$coins->increment('remain_amount', $coin);
|
||
|
|
break;
|
||
|
|
case 'ios':
|
||
|
|
$ios_coin = $coin*0.7;
|
||
|
|
$coins->increment('remain_amount', $ios_coin);
|
||
|
|
break;
|
||
|
|
default:
|
||
|
|
}
|
||
|
|
CoinLog::where('updated_at', $order->updated_at)->delete();
|
||
|
|
}
|
||
|
|
|
||
|
|
//商户订单列表
|
||
|
|
public function merchantOrders(Request $request){
|
||
|
|
$type = $request->type??'all';
|
||
|
|
$keyword = $request->keyword;
|
||
|
|
$orders = TouristOrder::with('merchant:id,mobile')->whereHas('merchant')->whereIn('pay_status',[1,4]);
|
||
|
|
$activity_ids = CommunityActivity::withTrashed()->where('class','one')->where('type','business')->pluck('id')->toArray();
|
||
|
|
$service_ids = CommunityActivity::withTrashed()->where('class','many')->where('type','business')->pluck('id')->toArray();
|
||
|
|
if($type == 'all'){
|
||
|
|
$orders = $orders->whereNotNull('id');
|
||
|
|
}elseif($type == 'activity'){
|
||
|
|
$orders = $orders->where('type','community')->orWhere('type','reward_activity')->whereIn('type_id',$activity_ids);
|
||
|
|
}elseif($type == 'service'){
|
||
|
|
$orders = $orders->where('type','community')->whereIn('type_id',$service_ids);
|
||
|
|
}else{
|
||
|
|
$orders = $orders->where('type',$type);
|
||
|
|
}
|
||
|
|
if($keyword){
|
||
|
|
$keyword = trim($keyword);
|
||
|
|
$orders = $orders->where(function($sql)use($keyword){
|
||
|
|
$sql->where('name','like','%'.$keyword.'%')
|
||
|
|
->orWhere('mobile','like','%'.$keyword.'%')
|
||
|
|
->orWhere('trade_no','like','%'.$keyword.'%');
|
||
|
|
});
|
||
|
|
}
|
||
|
|
$orders = $orders->orderBy('id','desc')->paginate();
|
||
|
|
foreach ($orders as $key => $order) {
|
||
|
|
$order->merchant->name = $order->merchant->anchorV2->name??'匿名商户';
|
||
|
|
$order->merchant->pic = $order->merchant->anchorV2->pic??User::DefaultAvatar;
|
||
|
|
unset($order->merchant->anchorV2);
|
||
|
|
if($order->type == 'community'){
|
||
|
|
$order->goods = CommunityActivity::withTrashed()->where('id',$order->type_id)->value('title');
|
||
|
|
}elseif($order->type == 'shop'){
|
||
|
|
$order->goods = MerchantShop::withTrashed()->where('id',$order->type_id)->value('title');
|
||
|
|
}elseif($order->type == 'consult'){
|
||
|
|
$order->goods = Consultation::withTrashed()->where('id',$order->type_id)->value('title');
|
||
|
|
}elseif($order->type == 'course'){
|
||
|
|
$order->goods = Course::withTrashed()->where('id',$order->type_id)->value('title');
|
||
|
|
}elseif($order->type == 'reward_info'){
|
||
|
|
$order->goods = MerchantInformation::withTrashed()->where('id',$order->type_id)->value('title');
|
||
|
|
}elseif($order->type == 'reward_activity'){
|
||
|
|
$goods = CommunityActivity::withTrashed()->where('id',$order->type_id)->value('title');
|
||
|
|
$order->goods = '打赏《'.$goods.'》';
|
||
|
|
}else{
|
||
|
|
$order->goods = '未获取';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return $this->success('ok',$orders);
|
||
|
|
}
|
||
|
|
}
|