2024-06-24 11:52:30 +08:00
< ? php
2024-06-27 17:34:53 +08:00
2024-06-24 11:52:30 +08:00
namespace app\model ;
use support\Log ;
use think\facade\Db ;
use support\Redis ;
2024-06-27 17:34:53 +08:00
class Orders extends base
{
2024-06-24 11:52:30 +08:00
//orderStatus 1, 未付款 2 已取消 3 , 待使用 4, 已使用 5, 已退款
2024-06-27 17:34:53 +08:00
const OrderStatus = [ 1 => '未付款' , 2 => '已取消' , 3 => '待使用' , 4 => '已使用' , 5 => '已退款' ];
const KuaishouStatus = [ 1 => '已取消' , 2 => '待支付' , 3 => '订单确认中' , 4 => '待使用' , 5 => '已完成' , 6 => '已过期' , 7 => '待分享' ];
2024-06-24 11:52:30 +08:00
2024-06-27 17:34:53 +08:00
const DouyinReservationStatus = [ 1 => '未预约' , 2 => '待接单' , 3 => '已预约' , 4 => '已取消' , 5 => '已完成' , 6 => '取消/退款申请' ];
const DouyinStatus = [ 1 => '未核销' , 2 => '已核销' , 3 => '申请退款中' , 4 => '已退款' , 5 => '部分核销' ];
2024-06-24 11:52:30 +08:00
2024-09-02 17:41:24 +08:00
// 订单状态(100 - 待付款, 150-用户取消, 200-待使用, 205-预约中( 抖音) , 210-已预约( 抖音) , 310-已履约( 抖音) , 300-已完成, 400-已关闭)
const TongchengStatus = [ 100 => '待付款' , 150 => '用户取消' , 200 => '待使用' , 205 => '预约中(抖音)' , 210 => '已预约(抖音)' , 310 => '已履约(抖音)' , 300 => '已完成' , 400 => '已关闭' ];
2024-06-28 17:30:56 +08:00
const AllOssStatus = [ 1 => '待使用' , 2 => '已核销' , 3 => '已退款' ];
2024-07-05 11:32:37 +08:00
// 全部 未核销 已核销 已退款 未付款 已取消 待支付 申请退款中 部分核销
// 0 1 2 3 4 5 6 7 8
2024-06-28 17:30:56 +08:00
const AllOssStatusSql = [
2025-01-07 15:20:38 +08:00
1 => '( (os in (1,7) and order_status=3) or (os=2 and order_status=4) or (os in ("3", "5") and order_status=1) or (os in ("8") and order_status=200) )' , //待使用
2024-10-13 17:01:24 +08:00
2 => '((os in (1,7) and order_status=4) or (os=2 and order_status=5) or (os in ("3", "5") and order_status=2))' , //已核销
3 => '((os in (1,7) and order_status=5) or (os in ("3", "5") and order_status=4))' //已退款(快手暂无已退款状态)
2024-06-28 17:30:56 +08:00
];
2024-06-27 17:34:53 +08:00
const StatusName = [ '待跟进' , '跟进中' , '已核销' , '核销失败' , '放弃跟单' ];
2024-12-24 10:53:59 +08:00
const OSS = [ 1 => '美团(甄选)' , '7' => '美团(新国旅)' , 2 => '快手' , 3 => '抖音(甄选)' , '5' => '抖音(新国旅)' , '6' => '同程(视频号)' , '8' => '同程(抖音)' , 4 => '全平台' ];
2024-06-24 11:52:30 +08:00
const timeType = [ 'create_time' => '添加记录时间' , 'update_time' => '修改记录时间' , 'last_follow' => '最后跟进时间' , 'next_follow' => '下次跟进时间' , 'travel_date' => '出行时间' , 'create_at' => '下单时间' ];
2024-10-21 17:14:32 +08:00
// 客户端常量
const H5_OSS = [ 1 => '美团官方视频号直播' , '7' => '美团官方视频号直播' , 2 => '快手' , 3 => '抖音' , '5' => '抖音' , '6' => '同程' ];
const H5_STATUS_DESC = [
// 美团
1 => [ 1 => '未付款' , 2 => '已取消' , 3 => '未预约' , 4 => '已预约' , 5 => '已退款' ],
7 => [ 1 => '未付款' , 2 => '已取消' , 3 => '未预约' , 4 => '已预约' , 5 => '已退款' ],
// 抖音
3 => [ 1 => '未核销' , 2 => '已核销' , 3 => '申请退款中' , 4 => '已退款' , 5 => '部分核销' ],
5 => [ 1 => '未核销' , 2 => '已核销' , 3 => '申请退款中' , 4 => '已退款' , 5 => '部分核销' ],
];
2024-06-24 11:52:30 +08:00
protected $json = [ 'personnel' ];
2024-06-27 17:34:53 +08:00
public function getOrderStatusNameAttr ( $val )
{
2024-09-06 18:31:12 +08:00
if ( $this -> os == 1 || $this -> os == 7 )
2024-06-24 11:52:30 +08:00
return self :: OrderStatus [ $this -> order_status ] ? ? '未知' ;
2024-06-27 17:34:53 +08:00
elseif ( $this -> os == 3 )
2024-06-24 11:52:30 +08:00
return self :: DouyinStatus [ $this -> order_status ] ? ? '未知' ;
2024-09-02 17:41:24 +08:00
elseif ( $this -> os == 5 )
return self :: DouyinStatus [ $this -> order_status ] ? ? '未知' ;
2024-12-25 21:45:21 +08:00
elseif ( $this -> os == 6 || $this -> os == 8 )
2024-09-02 17:41:24 +08:00
return self :: TongchengStatus [ $this -> order_status ] ? ? '未知' ;
2024-06-24 11:52:30 +08:00
else
return self :: KuaishouStatus [ $this -> order_status ] ? ? '未知' ;
}
2024-06-27 17:34:53 +08:00
public function getStatusNameAttr ( $val )
{
2024-06-24 11:52:30 +08:00
return self :: StatusName [ $this -> status ] ? ? '未知' ;
}
2024-06-27 17:34:53 +08:00
public function getOsNameAttr ( $val )
{
2024-06-24 11:52:30 +08:00
return self :: OSS [ $this -> os ] ? ? '未知' ;
}
2024-10-21 17:14:32 +08:00
public function getH5OsNameAttr ( $val )
{
return self :: H5_OSS [ $this -> os ] ? ? '未知' ;
}
public function getH5OsStatusNameAttr ( $val )
{
return self :: H5_STATUS_DESC [ $this -> os ][ $this -> order_status ] ? ? '未知' ;
}
public function getCanBookAttr ( $val )
{
$canBook = false ;
2024-10-22 15:00:11 +08:00
if ( in_array ( $this -> os , [ 1 , 7 ]) && $this -> order_status == 3 && ! $this -> is_book ) {
2024-10-21 17:14:32 +08:00
$canBook = true ;
}
return $canBook ;
}
2024-06-27 17:34:53 +08:00
public function getAdminNameAttr ()
{
if ( $this -> admin_id > 0 ) {
2024-06-24 11:52:30 +08:00
return $this -> admin -> getData ( 'name' );
2024-06-27 17:34:53 +08:00
} else {
$aid = Redis :: get ( 'Travel:Order:' . $this -> id );
if ( $aid ) {
2024-06-24 11:52:30 +08:00
$a = Admins :: where ( 'id' , $aid ) -> find ();
2024-06-27 17:34:53 +08:00
return $a -> getData ( 'name' ) . '(电话中...) ' ;
2024-06-24 11:52:30 +08:00
}
}
return '' ;
}
2024-06-27 17:34:53 +08:00
public static function attimes ( $type , $times )
{
2024-06-24 11:52:30 +08:00
$query = self :: where ([]);
2024-06-27 17:34:53 +08:00
if ( in_array ( $type , array_keys ( self :: timeType ))) {
if ( is_string ( $times )) {
2024-06-24 11:52:30 +08:00
$times = explode ( ',' , $times );
2024-06-27 17:34:53 +08:00
} else {
if ( empty ( $times [ 0 ])) $times [ 0 ] = '' ;
if ( empty ( $times [ 1 ])) $times [ 1 ] = '' ;
2024-06-24 11:52:30 +08:00
}
}
switch ( $type ) {
case 'create_time' : //添加记录时间
$query -> whereBetween ( 'create_time' , [ strtotime ( $times [ 0 ]), strtotime ( $times [ 1 ])]);
2024-06-27 17:34:53 +08:00
Log :: warning ( " ==Orders====: " , [ 'a' => strtotime ( $times [ 0 ]), 'b' => strtotime ( $times [ 1 ])]);
2024-06-24 11:52:30 +08:00
break ;
case 'update_time' : //修改记录时间
$query -> whereBetween ( 'update_time' , [ strtotime ( $times [ 0 ]), strtotime ( $times [ 1 ])]);
break ;
2024-06-27 17:34:53 +08:00
2024-06-24 11:52:30 +08:00
case 'last_follow' : //最后跟进时间
2024-06-27 17:34:53 +08:00
$query -> whereBetween ( 'last_follow' , [ strtotime ( $times [ 0 ]) * 1000 , strtotime ( $times [ 1 ]) * 1000 + 999 ]);
2024-06-24 11:52:30 +08:00
break ;
2024-06-27 17:34:53 +08:00
2024-06-24 11:52:30 +08:00
case 'next_follow' : //下次跟进时间
2024-06-27 17:34:53 +08:00
$query -> whereBetween ( 'next_follow' , [ strtotime ( $times [ 0 ]) * 1000 , strtotime ( $times [ 1 ]) * 1000 + 999 ]);
2024-06-24 11:52:30 +08:00
break ;
case 'travel_date' : //出行时间
2024-06-27 17:34:53 +08:00
$query -> whereBetween ( 'travel_date' , [ date ( 'Y-m-d H:i:s' , strtotime ( $times [ 0 ])), date ( 'Y-m-d H:i:s' , strtotime ( $times [ 1 ]))]);
2024-06-24 11:52:30 +08:00
break ;
2024-06-27 17:34:53 +08:00
2024-06-24 11:52:30 +08:00
case 'create_at' : //下单时间
2024-06-27 17:34:53 +08:00
$query -> whereBetween ( 'create_at' , [ strtotime ( $times [ 0 ]) * 1000 , strtotime ( $times [ 1 ]) * 1000 + 999 ]);
2024-06-24 11:52:30 +08:00
break ;
2024-06-27 17:34:53 +08:00
2024-06-24 11:52:30 +08:00
default :
# code...
break ;
}
return $query ;
}
2024-10-21 17:14:32 +08:00
public function admin () {
$data = $this -> belongsTo ( Admins :: class , 'admin_id' ) -> visible ([ 'name' , 'username' , 'avatar' , 'wechat' , 'wechat_pic' , 'job' , 'service_promise' ]);
return $data ;
2024-06-24 11:52:30 +08:00
}
2024-06-27 17:34:53 +08:00
public function anchor ()
{
return $this -> belongsTo ( Admins :: class , 'zhubo' ) -> visible ([ 'name' , 'username' , 'avatar' ]);
2024-06-24 11:52:30 +08:00
}
2024-06-27 17:34:53 +08:00
public function backs ()
{
return $this -> hasOne ( Backs :: class , 'order_id' ) -> where ( 'status' , 0 ) -> visible ([ 'status' , 'admin_id' ]);
2024-06-24 20:58:23 +08:00
}
2024-06-27 17:34:53 +08:00
public function follow ()
{
return $this -> hasMany ( Follows :: class , 'order_id' ) -> order ( 'id' , 'desc' );
2024-06-24 11:52:30 +08:00
}
2024-06-27 17:34:53 +08:00
public function finance ()
{
return $this -> hasMany ( Finances :: class , 'order_id' ) -> order ( 'id' , 'desc' );
2024-06-24 11:52:30 +08:00
}
2024-10-21 17:14:32 +08:00
public function product ()
{
return $this -> belongsTo ( Products :: class , 'product_id' , 'third_product_id' );
}
2024-12-02 18:43:20 +08:00
public function dyOrderAppointments ()
{
return $this -> belongsTo ( DyOrderProductAppointments :: class , 'sn' , 'source_order_id' );
}
2024-06-27 17:34:53 +08:00
public static function fish ( $id , $admin_id )
{
return Db :: transaction ( function () use ( $id , $admin_id ) {
2024-06-24 11:52:30 +08:00
$order = Orders :: where ( 'id' , $id ) -> where ( 'admin_id' , 0 ) -> lock ( true ) -> find ();
2024-06-27 17:34:53 +08:00
if ( empty ( $order )) return false ;
2024-06-24 11:52:30 +08:00
$order -> admin_id = $admin_id ;
$order -> give_time = time ();
$order -> save ();
Logs :: todo ( $id , $admin_id , 6 );
return true ;
});
}
2024-08-08 21:08:23 +08:00
public function mobileInfo ()
{
return $this -> hasOne ( ThirdMobileLogs :: class , 'mobile' , 'mobile' );
}
2024-11-05 14:42:06 +08:00
}