| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- namespace App;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\DB;
- use App\Traits\LogModelChanging;
- class OwnerPriceExpress extends Model
- {
- use LogModelChanging;
- protected $fillable = [
- "name", //名称
- "initial_weight", //首重
- "additional_weight",//续重
- ];
- public function owners()
- { //货主
- return $this->belongsToMany(Owner::class,"owner_price_express_owner","owner_price_express_id","owner_id");
- }
- public function logistics()
- { //物流
- return $this->belongsToMany(Logistic::class,"owner_price_express_logistic","owner_price_express_id","logistic_id");
- }
- public function details()
- { //计费详情
- return $this->hasMany(OwnerPriceExpressProvince::class,"owner_price_express_id","id");
- }
- public function getOwnerIdAttribute()
- { //获取货主ID数组
- return array_column(DB::select(DB::raw("SELECT * FROM owner_price_express_owner WHERE owner_price_express_id = ?"),[$this->id]),"owner_id");
- }
- public function getLogisticIdAttribute()
- { //获取快递ID数组
- return array_column(DB::select(DB::raw("SELECT * FROM owner_price_express_logistic WHERE owner_price_express_id = ?"),[$this->id]),"logistic_id");
- }
- }
|