提交其他文件
This commit is contained in:
890
app/api/logic/TeamasterLogic.php
Normal file
890
app/api/logic/TeamasterLogic.php
Normal file
@ -0,0 +1,890 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\order\OrderTeamaster;
|
||||
use app\common\model\order\OrderTeamasterLeaf;
|
||||
use app\common\model\teamaster\TeamasterAddress;
|
||||
use app\common\model\teastore\TeaStore;
|
||||
use app\common\model\user\User;
|
||||
use app\common\service\FileService;
|
||||
use DateTime;
|
||||
use think\facade\{Db, Config};
|
||||
use app\common\model\teamaster\Teamaster;
|
||||
use app\common\model\teamaster\TeamasterUser;
|
||||
use app\common\model\teamaster\TeamasterLeaf;
|
||||
use app\common\model\user\UserCoupon;
|
||||
use app\common\model\user\UserCouponType;
|
||||
use app\common\model\order\OrderTeamasterRenew;
|
||||
use app\common\service\pay\WxRefundService;
|
||||
|
||||
|
||||
|
||||
class TeamasterLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 茶艺师等级
|
||||
* @param array $params
|
||||
* @return array
|
||||
* @author Yzt
|
||||
* @date 2025/01/02 17:01
|
||||
*/
|
||||
public static function getTeaLevel(){
|
||||
return TeamasterLevel::where("status",1)->select()->toarray();
|
||||
}
|
||||
/**
|
||||
* @notes 茶艺师列表
|
||||
* @param array $params
|
||||
* @return array
|
||||
* @author Yzt
|
||||
* @date 2025/12/29 22:01
|
||||
*/
|
||||
public static function getTeamasterList($post){
|
||||
// 茶艺师等级多筛选
|
||||
$l = "";
|
||||
if(isset($post['level'])){
|
||||
$l = "a.level in (1,2,3,4,5)";
|
||||
if(!empty($post['level'])){
|
||||
$l = "a.level in (".$post['level'].")";
|
||||
}
|
||||
}
|
||||
$s = "";
|
||||
if(isset($post['search'])){
|
||||
if($post['search'] != ""){
|
||||
$b = $post['search'];
|
||||
$s = "b.name like '%".$b."%'";
|
||||
}
|
||||
}
|
||||
|
||||
$ca = "";
|
||||
if(isset($post['city_id'])){
|
||||
if($post['city_id'] != ""&&$post['city_id'] != null&&$post['city_id'] != 0){
|
||||
$ca = "c.ity_id = ".$post['city_id']."";
|
||||
}
|
||||
}
|
||||
$distance = "'--'";
|
||||
|
||||
$distance = "ROUND(
|
||||
6378.138 * 2 * ASIN(
|
||||
SQRT(
|
||||
POW(
|
||||
SIN(
|
||||
(
|
||||
{$post['latitude']} * PI() / 180 - c.latitude * PI() / 180
|
||||
) / 2
|
||||
),
|
||||
2
|
||||
) + COS({$post['latitude']} * PI() / 180) * COS(c.latitude * PI() / 180) * POW(
|
||||
SIN(
|
||||
(
|
||||
{$post['longitude']} * PI() / 180 - c.longitude * PI() / 180
|
||||
) / 2
|
||||
),
|
||||
2
|
||||
)
|
||||
)
|
||||
) * 1000
|
||||
)";
|
||||
|
||||
|
||||
$count = TeamasterUser::alias("a")
|
||||
->join("teamaster b", "b.team_user_id = a.id", "left")
|
||||
->join("teamaster_address c","a.address_id = c.id","left")
|
||||
->where($l)
|
||||
->where($ca)
|
||||
->where('a.del',0)
|
||||
->where('a.disable',0)
|
||||
->where('a.address_id','<>',0)
|
||||
->where($s)
|
||||
->count();
|
||||
$lists = TeamasterUser::alias("a")
|
||||
->join("teamaster b", "b.team_user_id = a.id", "left")
|
||||
->join("teamaster_address c","a.address_id = c.id","left")
|
||||
->where($l)
|
||||
->where($ca)
|
||||
->where('a.del',0)
|
||||
->where('a.disable',0)
|
||||
->where('a.address_id','<>',0)
|
||||
->where($s)
|
||||
->field("a.id as team_user_id,a.server_type,b.sex,b.both,b.name,b.image,a.level,a.price,c.latitude,c.longitude,a.state,a.avatar,
|
||||
a.work_start,a.work_end,{$distance} as distance")
|
||||
->page($post['page'], $post['size'])
|
||||
->order('distance asc')
|
||||
->select();
|
||||
|
||||
foreach($lists as $key=>$value){
|
||||
|
||||
$lists[$key]['distance'] = round( $lists[$key]['distance'] / 1000, 1);
|
||||
if($lists[$key]['distance']<10){
|
||||
$lists[$key]['is_time'] = '最快30分钟到达';
|
||||
}elseif($lists[$key]['distance']>10&&$lists[$key]['distance']<20){
|
||||
$lists[$key]['is_time'] = '最快一小时内到达';
|
||||
}else{
|
||||
$lists[$key]['is_time'] = '距离过远';
|
||||
}
|
||||
// if (isset($value['avatar']) && strpos($value['avatar'], 'uploads') !== false) {
|
||||
// // 包含 "uploads"
|
||||
// $lists[$key]['image']= !empty($value['avatar']) ? FileService::getFileUrl($value['avatar']) : '';
|
||||
// } else {
|
||||
// // 不包含 "uploads"
|
||||
// $lists[$key]['image']= !empty($value['avatar']) ? FileService::getFileUrl("uploads".$value['avatar']) : '';
|
||||
// }
|
||||
$lists[$key]['image']= !empty($value['avatar']) ? FileService::getImgUrl($value['avatar']) : '';
|
||||
$lists[$key]['both'] = (new DateTime())->diff(new DateTime($value['both']))->y;
|
||||
}
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
'page' => $post['page'],
|
||||
'size' => $post['size'],
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $post['page'], $post['size'])
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 茶艺师详情
|
||||
* @param array $params
|
||||
* @return array
|
||||
* @author 胥聪
|
||||
* @date 2025/10/14 17:01
|
||||
*/
|
||||
public static function getTeamasterDetails($post){
|
||||
$distance = "'--'";
|
||||
|
||||
$distance = "ROUND(
|
||||
6378.138 * 2 * ASIN(
|
||||
SQRT(
|
||||
POW(
|
||||
SIN(
|
||||
(
|
||||
{$post['latitude']} * PI() / 180 - c.latitude * PI() / 180
|
||||
) / 2
|
||||
),
|
||||
2
|
||||
) + COS({$post['latitude']} * PI() / 180) * COS(c.latitude * PI() / 180) * POW(
|
||||
SIN(
|
||||
(
|
||||
{$post['longitude']} * PI() / 180 - c.longitude * PI() / 180
|
||||
) / 2
|
||||
),
|
||||
2
|
||||
)
|
||||
)
|
||||
) * 1000
|
||||
)";
|
||||
|
||||
$lists = TeamasterUser::alias("a")
|
||||
->join("teamaster b", "b.team_user_id = a.id", "left")
|
||||
->join("teamaster_address c","a.address_id = c.id","left")
|
||||
->where('a.address_id','<>',0)
|
||||
->where('a.del',0)
|
||||
->where('a.id',$post['team_user_id'])
|
||||
->field("a.id as team_user_id,a.server_type,b.sex,b.both,b.name,b.image,a.level,a.price,a.mileage_price,b.weight,
|
||||
c.latitude,c.longitude,b.sex,a.is_mileage,a.star,b.height,hobby_introduce,a.sold,a.state,
|
||||
{$distance} as distance")
|
||||
->order('distance asc')
|
||||
->find();
|
||||
$lists['age_range'] = substr($lists['both'], 2, 1).'0';
|
||||
$lists['both'] = (new DateTime())->diff(new DateTime($lists['both']))->y;
|
||||
|
||||
$lists['distance'] = round( $lists['distance'] / 1000);
|
||||
|
||||
if($lists['distance']<10){
|
||||
$lists['is_time'] = '最快30分钟到达';
|
||||
}elseif($lists['distance']>10&&$lists['distance']<20){
|
||||
$lists['is_time'] = '最快一小时内到达';
|
||||
}else{
|
||||
$lists['is_time'] = '距离过远';
|
||||
}
|
||||
|
||||
$arr = explode(",", $lists['image'] ?? ''); // 使用 ?? 防止 $lists['image'] 为 null
|
||||
|
||||
$image_arr = [];
|
||||
foreach ($arr as $key => $value) {
|
||||
if (!empty(trim($value))) {
|
||||
// if (isset($value) && strpos($value, 'uploads') !== false) {
|
||||
// // 包含 "uploads"
|
||||
// $image_arr[$key]= !empty($value) ? FileService::getFileUrl($value) : '';
|
||||
// } else {
|
||||
// // 不包含 "uploads"
|
||||
// $image_arr[$key]= !empty($value) ? FileService::getFileUrl("uploads".$value) : '';
|
||||
// }
|
||||
$image_arr[$key] = FileService::getImgUrl($value);
|
||||
} else {
|
||||
$image_arr[$key] = '';
|
||||
}
|
||||
}
|
||||
$lists['image_arr'] = $image_arr;
|
||||
$lists['image'] = FileService::getImgUrl($arr[0]);
|
||||
|
||||
return $lists;
|
||||
}
|
||||
|
||||
public static function LeafList(){
|
||||
$left = TeamasterLeaf::where('del',0)->select();
|
||||
return $left->toArray();
|
||||
}
|
||||
|
||||
public static function addTeamOrder($post){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$team_user = TeamasterUser::where([
|
||||
'id'=>$post['team_user_id'],
|
||||
'del'=>0
|
||||
])->find();
|
||||
if(!$team_user){
|
||||
throw new \Exception('茶艺师不存在');
|
||||
}
|
||||
if($post['hours']<2){
|
||||
throw new \Exception('最低2小时起订');
|
||||
}
|
||||
$currentTime = time();
|
||||
$oneHourLater = $currentTime + 1740;
|
||||
if ($post['start_time'] < $oneHourLater) {
|
||||
throw new \Exception('需要至少提前一小时预定');
|
||||
}
|
||||
if (!isset($post['tea_id']) || $post['tea_id'] === '') {
|
||||
throw new \Exception('须选择一种茶叶');
|
||||
}
|
||||
$tea_ids = explode(',',$post['tea_id']);
|
||||
|
||||
$tea_leaf = TeamasterLeaf::whereIn('id',$tea_ids)->select();
|
||||
$leaf_amount =0;
|
||||
$teacup_price = 0;
|
||||
$server_all_price = $team_user['price']*$post['hours'];
|
||||
$mileage_server_price = 0;
|
||||
$coupon_price = 0;
|
||||
$tea_arr = [];
|
||||
foreach ($tea_leaf as $key=>$value){
|
||||
$leaf_amount += $value['price'] ?? 0;
|
||||
$tea_arr[$key]['leaf_id'] = $value['id'];
|
||||
$tea_arr[$key]['leaf_name']=$value['name'];
|
||||
}
|
||||
if($post['is_teacup'] == 1){
|
||||
$teacup_price = 20;
|
||||
}
|
||||
|
||||
$distance = "'--'";
|
||||
|
||||
$distance = "ROUND(
|
||||
6378.138 * 2 * ASIN(
|
||||
SQRT(
|
||||
POW(
|
||||
SIN(
|
||||
(
|
||||
{$post['latitude']} * PI() / 180 - latitude * PI() / 180
|
||||
) / 2
|
||||
),
|
||||
2
|
||||
) + COS({$post['latitude']} * PI() / 180) * COS(latitude * PI() / 180) * POW(
|
||||
SIN(
|
||||
(
|
||||
{$post['longitude']} * PI() / 180 - longitude * PI() / 180
|
||||
) / 2
|
||||
),
|
||||
2
|
||||
)
|
||||
)
|
||||
) * 1000
|
||||
)";
|
||||
$team_user_address = TeamasterAddress::where('id',$team_user['address_id'])
|
||||
->field("id, address, latitude, longitude,{$distance} as distance")
|
||||
->find();
|
||||
|
||||
$team_user_address['distance'] = round( $team_user_address['distance'] / 1000);
|
||||
|
||||
|
||||
if($team_user->is_mileage == 0){
|
||||
$mileage_server_price = $team_user_address['distance']*$team_user['mileage_price'];
|
||||
}
|
||||
$amount_all = $teacup_price+$server_all_price+$leaf_amount+$mileage_server_price;
|
||||
if($post['user_coupon_id'] !=0){
|
||||
$user_coupon = UserCoupon::where([
|
||||
'id'=>$post['user_coupon_id'],
|
||||
'status'=>0,
|
||||
'type_id'=>1
|
||||
])->find();
|
||||
if(!$user_coupon){
|
||||
throw new \Exception('优惠券不可用或已使用');
|
||||
}
|
||||
$coupon_type =UserCouponType::where([
|
||||
'id'=>$user_coupon['coupon_id'],
|
||||
'status'=>0
|
||||
])->find();
|
||||
if(!$coupon_type){
|
||||
throw new \Exception('优惠券不可用');
|
||||
}
|
||||
if($amount_all>=$coupon_type['use_price']){
|
||||
$coupon_price = $coupon_type['coupon_price'];
|
||||
}
|
||||
}
|
||||
|
||||
$order_amount = $amount_all-$coupon_price;
|
||||
$data = [
|
||||
'order_sn'=>createSn("order_teamaster","order_sn"),
|
||||
'user_id'=>$post['user_id'],
|
||||
'team_user_id'=>$post['team_user_id'],
|
||||
'store_id'=>$post['store_id'],
|
||||
'day_time'=>$post['start_time'],
|
||||
'start_time'=>$post['start_time'],
|
||||
'distance'=>$team_user_address['distance'],
|
||||
'end_time'=>$post['end_time'],
|
||||
'hours'=>$post['hours'],
|
||||
'server_number'=>$post['server_number'],
|
||||
'server_type'=>$post['server_type'],
|
||||
'address'=>$post['address'],
|
||||
'longitude'=>$post['longitude'],
|
||||
'latitude'=>$post['latitude'],
|
||||
'is_teacup'=>$post['is_teacup'],
|
||||
'server_price'=>$team_user['price'],
|
||||
'mileage_price'=>$team_user['mileage_price'],
|
||||
'server_all_price'=>$server_all_price,
|
||||
'mileage_server_price'=>$mileage_server_price,
|
||||
'user_coupon_id'=>$post['user_coupon_id'],
|
||||
'tea_price'=>$leaf_amount,
|
||||
'teacup_price'=>$teacup_price,
|
||||
'coupon_price'=>$coupon_price,
|
||||
'order_amount'=>round($order_amount,2),
|
||||
'team_income_price'=>round(((($order_amount-$mileage_server_price)+$coupon_price)*0.65)+$mileage_server_price,2),
|
||||
'dtime'=>time()
|
||||
];
|
||||
|
||||
$order = OrderTeamaster::create($data);
|
||||
$orderId =$order->id;
|
||||
foreach ($tea_arr as &$item){
|
||||
$item['order_id'] = $orderId;
|
||||
}
|
||||
|
||||
$result = OrderTeamasterLeaf::insertAll($tea_arr);
|
||||
Db::commit();
|
||||
$data = [
|
||||
'order_id'=>$orderId,
|
||||
'order_amount'=>$order_amount
|
||||
];
|
||||
return $data;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function countTeamPrice($post){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$team_user = TeamasterUser::where([
|
||||
'id'=>$post['team_user_id'],
|
||||
'del'=>0
|
||||
])->find();
|
||||
$hours = $post['hours'];
|
||||
$tea_id = $post['tea_id'];
|
||||
$server_price = $team_user->price;
|
||||
$server_all_price = $team_user['price']*$post['hours'];
|
||||
$mileage_price = 0;
|
||||
$team_user_distance = 0;
|
||||
$mileage_server_price = 0;
|
||||
$leaf_amount =0;
|
||||
$teacup_price = 0;
|
||||
$leaf_tea_all_price = 0;
|
||||
$coupon_price = 0;
|
||||
|
||||
if($tea_id !==0){
|
||||
$tea_ids = explode(',',$tea_id);
|
||||
$tea_leaf = TeamasterLeaf::whereIn('id',$tea_ids)->select();
|
||||
|
||||
$tea_arr = [];
|
||||
foreach ($tea_leaf as $key=>$value){
|
||||
$leaf_amount += $value['price'] ?? 0;
|
||||
$tea_arr[$key]['leaf_id'] = $value['id'];
|
||||
$tea_arr[$key]['leaf_name']=$value['name'];
|
||||
}
|
||||
}
|
||||
|
||||
if($post['is_teacup'] == 1){
|
||||
$teacup_price = 20;
|
||||
}
|
||||
|
||||
$distance = "'--'";
|
||||
|
||||
$distance = "ROUND(
|
||||
6378.138 * 2 * ASIN(
|
||||
SQRT(
|
||||
POW(
|
||||
SIN(
|
||||
(
|
||||
{$post['latitude']} * PI() / 180 - latitude * PI() / 180
|
||||
) / 2
|
||||
),
|
||||
2
|
||||
) + COS({$post['latitude']} * PI() / 180) * COS(latitude * PI() / 180) * POW(
|
||||
SIN(
|
||||
(
|
||||
{$post['longitude']} * PI() / 180 - longitude * PI() / 180
|
||||
) / 2
|
||||
),
|
||||
2
|
||||
)
|
||||
)
|
||||
) * 1000
|
||||
)";
|
||||
$team_user_address = TeamasterAddress::where('id',$team_user['address_id'])
|
||||
->field("id, address, latitude, longitude,{$distance} as distance")
|
||||
->find();
|
||||
|
||||
$team_user_address['distance'] = round( $team_user_address['distance'] / 1000);
|
||||
|
||||
$team_user_distance =$team_user_address['distance'];
|
||||
if($team_user->is_mileage == 0){
|
||||
$mileage_server_price = $team_user_address['distance']*$team_user['mileage_price'];
|
||||
|
||||
$mileage_price = $team_user['mileage_price'];
|
||||
}
|
||||
$amount_all = $teacup_price+$server_all_price+$leaf_amount+$mileage_server_price;
|
||||
if($post['user_coupon_id'] !=0){
|
||||
$user_coupon = UserCoupon::where([
|
||||
'id'=>$post['user_coupon_id'],
|
||||
])->find();
|
||||
$coupon_type =UserCouponType::where([
|
||||
'id'=>$user_coupon['coupon_id'],
|
||||
])->find();
|
||||
|
||||
if($amount_all>=$coupon_type['use_price']){
|
||||
$coupon_price = $coupon_type['coupon_price'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$order_amount = $amount_all-$coupon_price;
|
||||
$leaf_tea_all_price = $teacup_price+$leaf_amount;
|
||||
$data = [
|
||||
'order_amount'=>round($order_amount,2),
|
||||
'server_price'=>$server_price,
|
||||
'server_all_price'=>round($server_all_price,2),
|
||||
'mileage_price'=>round($mileage_price,2),
|
||||
'team_user_distance'=>$team_user_distance,
|
||||
'mileage_server_price'=>$mileage_server_price,
|
||||
'leaf_tea_all_price'=>$leaf_tea_all_price,
|
||||
'teacup_price'=>$teacup_price,
|
||||
'leaf_amount'=>$leaf_amount,
|
||||
'coupon_price'=>$coupon_price
|
||||
];
|
||||
|
||||
Db::commit();
|
||||
return $data;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function userCoupon($data){
|
||||
$user_coupon = UserCoupon::alias("a")
|
||||
->join("user_coupon_type b", "a.coupon_id = b.id", "left")
|
||||
->where('a.status',0)
|
||||
->where('a.type_id',1)
|
||||
->where('b.status',0)
|
||||
->where('a.user_id',$data['user_id'])
|
||||
->field("a.id,b.title,b.name,b.use_price,b.coupon_price,b.effect_time,b.status")
|
||||
->select()->toarray();
|
||||
return $user_coupon;
|
||||
}
|
||||
|
||||
public static function teamOrderList($post){
|
||||
$user_id =$post['user_id'];
|
||||
$os = [10,20,28,29,30,31,32,40,41,42,43];
|
||||
$od = "a.start_time desc";
|
||||
if(isset($post['order_status'])){
|
||||
if($post['order_status']!= "" || $post['order_status']!= null){
|
||||
|
||||
$os = explode(",",$post['order_status']);
|
||||
$od = "a.start_time asc";
|
||||
}
|
||||
}
|
||||
$s = "";
|
||||
if(isset($post['search'])){
|
||||
if($post['search']!= "" || $post['search']!= null){
|
||||
$a = $post['search'];
|
||||
$s = "c.name like '%".$a."%'";
|
||||
}
|
||||
}
|
||||
|
||||
$count = OrderTeamaster::alias("a")
|
||||
->join("teamaster_user b", "b.id = a.team_user_id", "left")
|
||||
->join("teamaster c", "c.team_user_id = a.team_user_id", "left")
|
||||
->where('a.del',0)
|
||||
->whereIn('a.order_status',$os)
|
||||
->where($s)
|
||||
->where('a.user_id',$user_id)
|
||||
->count();
|
||||
|
||||
$lists = OrderTeamaster::alias("a")
|
||||
->join("teamaster_user b", "b.id = a.team_user_id", "left")
|
||||
->join("teamaster c", "c.team_user_id = a.team_user_id", "left")
|
||||
->where('a.del',0)
|
||||
->whereIn('a.order_status',$os)
|
||||
->where($s)
|
||||
->where('a.user_id',$user_id)
|
||||
->field('a.id,c.name,b.level,a.server_type,c.sex,a.start_time,a.end_time,a.day_time,c.both,c.image,a.order_status,b.avatar')
|
||||
->page($post['page'], $post['size'])
|
||||
->order($od)
|
||||
->select();
|
||||
$timekeeping = 0;
|
||||
if($lists){
|
||||
foreach ($lists as &$item){
|
||||
if($item['order_status'] == 28){
|
||||
$timekeeping = $item['pay_time']-time();
|
||||
}
|
||||
$item['timekeeping'] =$timekeeping;
|
||||
$item['day_time'] = date('m-d', $item['day_time']);
|
||||
$item['start_time'] = date('H:i', $item['start_time']);
|
||||
$item['end_time'] = date('H:i', $item['end_time']);
|
||||
$arr = explode(",",$item['image']);
|
||||
$item['image'] = !empty($item['avatar']) ? FileService::getImgUrl($item['avatar']) : '';
|
||||
$item['both'] = (new DateTime())->diff(new DateTime($item['both']))->y;
|
||||
|
||||
}
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
'page' => $post['page'],
|
||||
'size' => $post['size'],
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $post['page'], $post['size'])
|
||||
];
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function teamOrderDetails($post){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$item = OrderTeamaster::where('del',0)
|
||||
->where('id',$post['id'])
|
||||
->find();
|
||||
|
||||
$team = Teamaster::where('team_user_id',$item['team_user_id'])->find();
|
||||
$team_user = TeamasterUser::where('id',$team['team_user_id'])->find();
|
||||
|
||||
$timekeeping = 0;
|
||||
if($item['order_status'] == 28){
|
||||
$timekeeping = $item['pay_time']-time();
|
||||
}
|
||||
$order_leaf = OrderTeamasterLeaf::where('order_id',$item['id'])->select();
|
||||
$leaf_name = [];
|
||||
foreach ($order_leaf as &$v){
|
||||
$leaf_name[] = $v['leaf_name'].'('.$v['num'].')泡';
|
||||
}
|
||||
|
||||
$item['timekeeping'] =$timekeeping;
|
||||
$item['tea_amount_all'] = $item['tea_price']+$item['teacup_price']+$item['renew_tea_price']+$item['renew_tea_price'];
|
||||
$item['order_amount'] = $item['order_amount']+$item['renew_tea_price']+$item['renew_tea_price'];
|
||||
$item['leaf_name'] = implode(',',$leaf_name);
|
||||
$item['title'] = $team->name;
|
||||
$item['team_mobile'] = $team_user->mobile;
|
||||
$item['day_time'] = date('m-d', $item['day_time']);
|
||||
$item['start_time'] = date('H:i', $item['start_time']);
|
||||
$item['end_time'] = date('H:i', $item['end_time']);
|
||||
$item['pay_time'] = date('Y-m-d H:i', $item['pay_time']);
|
||||
$item['dtime'] = date('Y-m-d H:i', $item['dtime']);
|
||||
$item['refund_time'] = date('Y-m-d H:i', $item['refund_time']);
|
||||
$item['take_order_time'] = date('Y-m-d H:i', $item['take_order_time']);
|
||||
$item['img_time'] = date('Y-m-d H:i', $item['img_time']);
|
||||
$item['img'] = FileService::getImgUrl($item['img']);
|
||||
$arr = explode(",",$team['image']);
|
||||
$item['image'] = !empty($team_user['avatar']) ? FileService::getImgUrl($team_user['avatar']) : '';
|
||||
$item['pay_way_title'] = '';
|
||||
if($item['pay_way'] == 1){
|
||||
$item['pay_way_title'] = "平台余额支付";
|
||||
}
|
||||
if($item['pay_way'] == 2){
|
||||
$item['pay_way_title'] = "微信支付";
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return $item->toarray();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static function addTeamRenwOrder($post){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = OrderTeamaster::where('id',$post['id'])->find();
|
||||
if(!$order){
|
||||
throw new \Exception('订单错误');
|
||||
}
|
||||
$hours = $post['hours'];
|
||||
$leaf_amount = 0;
|
||||
$tea_price =0;
|
||||
$renew_price = 0;
|
||||
$price = 0;
|
||||
$tea_arr = [];
|
||||
$tea_ids = explode(',',$post['tea_id']);
|
||||
$tea_leaf = TeamasterLeaf::whereIn('id',$tea_ids)->select();
|
||||
|
||||
if ($tea_leaf && !$tea_leaf->isEmpty()) {
|
||||
foreach ($tea_leaf as $value) {
|
||||
$leaf_amount += $value['price'] ?? 0;
|
||||
$tea_arr[] = [
|
||||
'leaf_id' => $value['id'],
|
||||
'leaf_name' => $value['name']
|
||||
];
|
||||
}
|
||||
}
|
||||
if($post['type'] == 1){
|
||||
$renew_price = $order->server_price*$hours;
|
||||
}elseif ($post['type']==2){
|
||||
$tea_price = $leaf_amount;
|
||||
foreach ($tea_arr as &$item){
|
||||
$item['order_id'] = $order->id;
|
||||
}
|
||||
$result = OrderTeamasterLeaf::insertAll($tea_arr);
|
||||
|
||||
}else{
|
||||
$renew_price = $order->server_price*$hours;
|
||||
$tea_price = $leaf_amount;
|
||||
foreach ($tea_arr as &$item){
|
||||
$item['order_id'] = $order->id;
|
||||
}
|
||||
$result = OrderTeamasterLeaf::insertAll($tea_arr);
|
||||
}
|
||||
$price = $tea_price+$renew_price;
|
||||
|
||||
$data = [
|
||||
'order_sn'=>createSn("order_teamaster_renew","order_sn"),
|
||||
'source_id'=>$order->id,
|
||||
'type'=>$post['type'],
|
||||
'user_id'=>$post['user_id'],
|
||||
'hours'=>$hours,
|
||||
'tea_price'=>$tea_price,
|
||||
'renew_price'=>$renew_price,
|
||||
'price'=>$price,
|
||||
'dtime'=>time()
|
||||
];
|
||||
$order_renew =OrderTeamasterRenew::create($data);
|
||||
|
||||
Db::commit();
|
||||
return [
|
||||
'order_id'=>$order_renew->id,
|
||||
'price'=>$price
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function cancelOrder($post){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = OrderTeamaster::where([
|
||||
'id'=>$post['id'],
|
||||
'order_status'=>10
|
||||
])->find();
|
||||
if(!$order){
|
||||
throw new \Exception('订单错误');
|
||||
}
|
||||
$order->order_status = 20;
|
||||
$order->update_time = time();
|
||||
$order->save();
|
||||
Db::commit();
|
||||
return [];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function delOrder($post){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = OrderTeamaster::where([
|
||||
'id'=>$post['id'],
|
||||
])->whereIn('order_status',[20,32,40,41,42])->find();
|
||||
if(!$order){
|
||||
throw new \Exception('订单错误');
|
||||
}
|
||||
$order->del = 1;
|
||||
$order->update_time = time();
|
||||
$order->save();
|
||||
Db::commit();
|
||||
return [];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function TeamRefund($post){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = OrderTeamaster::where([
|
||||
'id'=>$post['id'],
|
||||
])->whereIn('order_status',[28,29,30])->find();
|
||||
if(!$order){
|
||||
throw new \Exception('订单错误');
|
||||
}
|
||||
$WxRefundService = new WxRefundService();
|
||||
$result =$WxRefundService->Refund($order,$post['order_type'],41);
|
||||
|
||||
Db::commit();
|
||||
return [];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @notes 茶艺师收藏/取消
|
||||
* @author 胥聪
|
||||
* @date 2025/10/14 17:01
|
||||
*/
|
||||
public static function teamasterCollect($post){
|
||||
if($post['status'] == 1){
|
||||
$result = TeamasterCollect::where([
|
||||
"teamaster_id"=>$post['id'],
|
||||
"user_id"=>$post['user_id'],
|
||||
"status"=>1
|
||||
])->find();
|
||||
if($result){
|
||||
return false;
|
||||
}
|
||||
return TeamasterCollect::create([
|
||||
"teamaster_id"=>$post['id'],
|
||||
"user_id"=>$post['user_id'],
|
||||
"dtime"=>date("Y-m-d H:i:s")
|
||||
]);
|
||||
}else{
|
||||
$d['status'] = 0;
|
||||
$d['update_dtime'] = date("Y-m-d H:i:s");
|
||||
return TeamasterCollect::where('teamaster_id',$post['id'])
|
||||
->where("user_id",$post['user_id'])
|
||||
->update($d);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @notes 茶艺师收藏列表
|
||||
* @author 胥聪
|
||||
* @date 2025/10/14 17:01
|
||||
*/
|
||||
public static function teamasterCollectList($post,$userId){
|
||||
$count = TeamasterCollect::where('status',1)->where('user_id',$userId)
|
||||
->count();
|
||||
$lists = Teamaster::where('del',0)
|
||||
->alias("a")
|
||||
->field('a.id,a.authent_status,a.level_id,a.label_id,a.sex,a.both,a.name,a.image,a.price,a.star,a.status,a.dtime,a.update_dtime,a.up_status,a.longitude,a.latitude,a.del')
|
||||
->join("teamaster_collect b","a.id=b.teamaster_id","left")
|
||||
->with(['teamasterLevel'])
|
||||
->where('b.status',1)
|
||||
->where('b.user_id',$userId)
|
||||
->page($post['page'], $post['size'])
|
||||
->order('id asc')
|
||||
->select();
|
||||
foreach($lists as $key=>$value){
|
||||
$lists[$key]['count'] = TeamasterCollect::where('status',1)->where('teamaster_id',$value['id'])->count();
|
||||
$a = array_filter(explode(",",$value['label_id']));
|
||||
// 标签
|
||||
$lists[$key]['teamasterlabel'] = TeamasterLabel::wherein("id",$a)->select()->toArray();
|
||||
$lists[$key]['both'] = (new DateTime())->diff(new DateTime($value['both']))->y;
|
||||
}
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
'page' => $post['page'],
|
||||
'size' => $post['size'],
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $post['page'], $post['size'])
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 打赏金额查询
|
||||
* @param array $params
|
||||
* @return array
|
||||
* @author 胥聪
|
||||
* @date 2025/10/20 17:01
|
||||
*/
|
||||
public static function getTipAmount(){
|
||||
return TeamasterTipAmount::where('status',1)
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
/**
|
||||
* @notes 打赏
|
||||
* @author 胥聪
|
||||
* @date 2025/10/20 17:01
|
||||
* @data teamaster_id tip_price pay_type
|
||||
*/
|
||||
public static function giveTeamasterTipAmount($data,$user_id){
|
||||
$user_money = User::where("id",$user_id)->value("user_money");
|
||||
if($user_money < $data['tip_price']){
|
||||
throw new \Exception('余额账户不足');
|
||||
}
|
||||
return TeamasterTipAmountLog::create([
|
||||
"user_id"=>$user_id,
|
||||
"teamaster_id"=>$data['id'],
|
||||
"tip_price"=>$data['tip_price'],
|
||||
"pay_type"=>$data['pay_type'],
|
||||
"dtime"=>date("Y-m-d H:i:s")
|
||||
]);
|
||||
}
|
||||
public static function teaType(){
|
||||
return Tea::where("status",1)->select()->toArray();
|
||||
}
|
||||
|
||||
public static function invitation($post,$user_id){
|
||||
return TeamasterInvitation::create([
|
||||
'user_id'=>$user_id,
|
||||
'teamaster_id'=>$post['id'],
|
||||
'dtime'=>date("Y-m-d H:i:s")
|
||||
]);
|
||||
}
|
||||
public static function groupReservation($post,$user_id){
|
||||
return TeamasterGroupReservation::create([
|
||||
'user_id'=>$user_id,
|
||||
'numbers'=>$post['numbers'],
|
||||
'other_require'=>$post['other_require'],
|
||||
'res_time'=>$post['res_time'],
|
||||
'contact'=>$post['contact'],
|
||||
'phone'=>$post['phone'],
|
||||
'province'=>$post['province'],
|
||||
'city'=>$post['city'],
|
||||
'district'=>$post['district'],
|
||||
'address'=>$post['address'],
|
||||
'content'=>$post['content'],
|
||||
'dtime'=>date("Y-m-d H:i:s")
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user