72 lines
1.3 KiB
PHP
72 lines
1.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Created by Reliese Model.
|
|
*/
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* Class ProductBuy
|
|
*
|
|
* @property int $id
|
|
* @property int $auth_user_id
|
|
* @property int $product_id
|
|
* @property int $num
|
|
* @property Carbon|null $created_at
|
|
* @property Carbon|null $updated_at
|
|
*
|
|
* @property Product $product
|
|
*
|
|
* @package App\Models
|
|
*/
|
|
class ProductBuy extends Model
|
|
{
|
|
protected $table = 'product_buys';
|
|
|
|
protected $casts = [
|
|
'auth_user_id' => 'int',
|
|
'product_id' => 'int',
|
|
'num' => 'int'
|
|
];
|
|
|
|
protected $fillable = [
|
|
'auth_user_id',
|
|
'product_id',
|
|
'num'
|
|
];
|
|
|
|
public function product()
|
|
{
|
|
return $this->belongsTo(Product::class);
|
|
}
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo('App\User','auth_user_id');
|
|
}
|
|
|
|
public function auth_user()
|
|
{
|
|
return $this->belongsTo('App\User','auth_user_id');
|
|
}
|
|
|
|
public static function getNotShowProductIDs($user_id){
|
|
$ret = [];
|
|
$ProductBuys = ProductBuy::where('auth_user_id', $user_id)->get();
|
|
if($ProductBuys){
|
|
foreach($ProductBuys as $ProductBuy){
|
|
if($ProductBuy->product){
|
|
if($ProductBuy->product->max_buy && $ProductBuy->num >= $ProductBuy->product->max_buy_num){
|
|
$ret[] = $ProductBuy->product->id;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
}
|