ShopProductionOffer.php 825 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace app\data\model;
  3. use app\data\model\helpers\PurchaseOrderId;
  4. use think\admin\Model;
  5. class ShopProductionOffer extends Model
  6. {
  7. use PurchaseOrderId;
  8. protected $type=[
  9. 'images'=>'array',
  10. ];
  11. public static function onBeforeWrite(self $model)
  12. {
  13. if(empty($model['amount'])||$model['amount']==0){
  14. $model['amount']=null;
  15. }
  16. }
  17. public static function onAfterDelete(self $model): void
  18. {
  19. $model->amounts()->delete();
  20. }
  21. public function amounts(){
  22. return $this->hasMany(ShopProductionOfferAmount::class,'offer_id');
  23. }
  24. public function user(){
  25. return $this->belongsTo(DataUser::class,'user_id');
  26. }
  27. public function production(){
  28. return $this->belongsTo(ShopProduction::class,'production_id');
  29. }
  30. }