214 lines
6.1 KiB
PHP
214 lines
6.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Server;
|
|
use App\Model\Server\TencentFaceidLog;
|
|
use App\Models\CommunityActivity;
|
|
use App\Models\Consultation;
|
|
use App\Models\Course\Course;
|
|
use App\Models\EnterpriseAlliance;
|
|
use App\Models\Live\Anchor;
|
|
use App\Models\MAdvanceEarning;
|
|
use App\Models\MerchantInformation;
|
|
use App\Models\MerchantShop;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use App\Models\User;
|
|
use App\Models\Live\Viewer;
|
|
use App\Models\MerchantUsers;
|
|
use App\Models\ShopRecive;
|
|
use App\Models\Server\MerchantUser;
|
|
use App\Models\Wechat;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class TouristOrder extends Model
|
|
{
|
|
protected $fillable = [];
|
|
protected $guarded = [];
|
|
|
|
public function user(){
|
|
return $this->hasOne(MerchantUsers::class,'id','account_id');
|
|
}
|
|
|
|
public function information(){
|
|
return $this->hasOne(MerchantInformation::class,'id','type_id')->withTrashed();
|
|
}
|
|
|
|
public function viewer(){
|
|
return $this->hasOne(Viewer::class,'openid','open_id');
|
|
}
|
|
public function fromUser(){
|
|
return $this->hasOne(Viewer::class,'openid','from_openid')->whereNotNull('openid');
|
|
}
|
|
public function recive(){
|
|
return $this->hasOne(ShopRecive::class,'order_id','id');
|
|
}
|
|
public function operator(){
|
|
return $this->hasOne(User::class,'id','operator')->select('id','nickname','name','app_avatar','circle_avatar','mobile');
|
|
|
|
}
|
|
public function mUser(){
|
|
return $this->hasOne(MerchantUser::class,'id','account_id')->select('id','nickname','pic','mobile');
|
|
}
|
|
public function merUser(){
|
|
return $this->hasOne(MerchantUser::class,'openid','open_id')->select('id','nickname','pic','openid','user_id','mobile');
|
|
}
|
|
|
|
public function mEarning(){
|
|
return $this->hasMany(MEarning::class,'m_order_id','id')->whereIn('sharer', ['first_sharer', 'other_sharer', 'last_sharer', 'merchant', 'agent_merchant']);
|
|
}
|
|
|
|
public function mAdvanceEarning(){
|
|
return $this->hasMany(MAdvanceEarning::class,'m_order_id','id')->whereIn('sharer', ['first_sharer', 'other_sharer', 'last_sharer', 'merchant']);
|
|
}
|
|
|
|
public function merchant(){
|
|
return $this->hasOne(MerchantAccount::class,'id','merchant_id');
|
|
}
|
|
|
|
public function activity(){
|
|
return $this->hasOne(CommunityActivity::class, 'id', 'type_id')->where('class','=', 'one');
|
|
}
|
|
|
|
public function service(){
|
|
return $this->hasOne(CommunityActivity::class, 'id', 'type_id')->where('class', '=','many');
|
|
}
|
|
|
|
public function activityService()
|
|
{
|
|
return $this->hasOne(CommunityActivity::class, 'id', 'type_id');
|
|
}
|
|
public function activities()
|
|
{
|
|
return $this->hasOne(CommunityActivity::class, 'id', 'type_id')->select('id','title','pic','price');
|
|
}
|
|
public function course(){
|
|
return $this->hasOne(Course::class, 'id', 'type_id')->withTrashed();
|
|
}
|
|
|
|
public function consult(){
|
|
return $this->hasOne(Consultation::class, 'id', 'type_id');
|
|
}
|
|
|
|
public function shop(){
|
|
return $this->hasOne(MerchantShop::class, 'id', 'type_id');
|
|
}
|
|
|
|
public function alliance(){
|
|
return $this->hasOne(EnterpriseAlliance::class, 'id', 'alliance_id');
|
|
}
|
|
|
|
public function tcfaceid()
|
|
{
|
|
return $this->hasOne(TencentFaceidLog::class, 'openid', 'open_id');
|
|
}
|
|
|
|
public function anchor()
|
|
{
|
|
return $this->hasOne(Anchor::class, 'm_id', 'merchant_id');
|
|
}
|
|
|
|
public function spreadAnchor()
|
|
{
|
|
return $this->hasOne(Anchor::class, 'm_id', 'spread_merchant_id');
|
|
}
|
|
|
|
public function levelDetail()
|
|
{
|
|
return $this->hasOne(SaasMemberLevel::class, 'id', 'type_id');
|
|
}
|
|
|
|
|
|
public function getChannelAttribute($value)
|
|
{
|
|
switch ($value) {
|
|
case 0:
|
|
return '商家';
|
|
break;
|
|
case 1:
|
|
return '福恋H5';
|
|
break;
|
|
case 2:
|
|
return '商家APP';
|
|
break;
|
|
case 3:
|
|
return '福恋小程序';
|
|
break;
|
|
case 4:
|
|
return '优惠券';
|
|
break;
|
|
case 5:
|
|
return '福姻';
|
|
break;
|
|
default:
|
|
return '商家';
|
|
break;
|
|
}
|
|
}
|
|
|
|
// public function getLinkmenAttribute($value)
|
|
// {
|
|
// return json_decode($value,true);
|
|
// }
|
|
|
|
public function user_evaluate(){
|
|
return $this->hasOne(UserEvaluate::class, 'order_id', 'trade_no');
|
|
}
|
|
|
|
public function merchant_evaluate(){
|
|
return $this->hasOne(MerchantEvaluate::class, 'id', 'type_id');
|
|
}
|
|
|
|
public function follow(){
|
|
return $this->hasMany(MOrderFollow::class,'order_id','id');
|
|
}
|
|
|
|
public function fromUsers(){
|
|
if($this->channel == '福恋小程序'){
|
|
return $this->hasOne(Wechat::class,'openid','from_openid')->select('nickname','openid','avatar2 as pic');
|
|
}else{
|
|
return $this->hasOne(MerchantUser::class,'openid','from_openid')->select('nickname','openid','pic');
|
|
}
|
|
}
|
|
|
|
public function orderStatusLink(){
|
|
return $this->hasOne(OrderStatusLink::class,'order_id','id');
|
|
}
|
|
|
|
public function refunds()
|
|
{
|
|
return $this->hasMany(MRefundOrder::class, 'trade_no', 'trade_no');
|
|
}
|
|
|
|
public function blacklist()
|
|
{
|
|
return $this->hasOne(MerchantBlacklist::class, 'user_id', 'account_id');
|
|
}
|
|
|
|
/**
|
|
* 获取规格购买人数
|
|
* @param $type_id
|
|
* @param $merchant_id
|
|
* @param $sku_id
|
|
* @return mixed
|
|
*/
|
|
public function getSkuBuyNum($type_id, $merchant_id, $sku_id)
|
|
{
|
|
$where = [
|
|
['type_id', '=', $type_id],
|
|
['merchant_id', '=', $merchant_id],
|
|
['sku_id', '=', $sku_id],
|
|
];
|
|
$data = $this->where($where)->whereIn('pay_status', [1, 4])->get();
|
|
// return $this->where($where)->whereIn('pay_status', [1, 4])->count();
|
|
$num = 0;
|
|
foreach ($data as $item){
|
|
$linkmen = json_decode($item->linkmen,true);
|
|
if(!is_array($linkmen)){
|
|
continue;
|
|
}
|
|
$num += count($linkmen);
|
|
}
|
|
return $num;
|
|
}
|
|
|
|
}
|