CommodityMaterialBoxModelService.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Services;
  3. use App\Traits\ServiceAppAop;
  4. use App\CommodityMaterialBoxModel;
  5. class CommodityMaterialBoxModelService
  6. {
  7. use ServiceAppAop;
  8. protected $modelClass=CommodityMaterialBoxModel::class;
  9. /**
  10. * 获取最大限值
  11. *
  12. * @param integer $modelId
  13. * @param integer $commodityId
  14. *
  15. * @return int|null
  16. */
  17. public function getMaximum(int $modelId, int $commodityId):?int
  18. {
  19. $model = CommodityMaterialBoxModel::query()->select("maximum")->where("commodity_id",$commodityId)
  20. ->where("material_box_model_id",$modelId)->first();
  21. return (int)$model->maximum ?? null;
  22. }
  23. /**
  24. * 设置最大限值
  25. *
  26. * @param integer|null $modelId
  27. * @param integer|null $commodityId
  28. * @param integer $maximum
  29. *
  30. * @return bool
  31. */
  32. public function setMaximum($modelId, $commodityId, $maximum):bool
  33. {
  34. if (!$modelId || !$commodityId)return false;
  35. $model = CommodityMaterialBoxModel::query()->select("maximum")->where("commodity_id",$commodityId)
  36. ->where("material_box_model_id",$modelId)->first();
  37. if (!$model)CommodityMaterialBoxModel::query()->create([
  38. "maximum" => $maximum,
  39. "commodity_id" => $commodityId,
  40. "material_box_model_id" => $modelId,
  41. ]);else $model->update(["maximum" => $maximum]);
  42. return true;
  43. }
  44. }