GoodsDeliveryTemplateValidate.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace app\adminapi\validate\goods;
  3. use app\common\model\Goods;
  4. use app\common\validate\BaseValidate;
  5. class GoodsDeliveryTemplateValidate extends BaseValidate
  6. {
  7. protected $rule = [
  8. 'id' => [ 'require' ],
  9. 'name' => [ 'require' ],
  10. 'type' => [ 'require', 'in' => [ 0, 1 ] ],
  11. 'content' => [ 'requireIf' => 'type,0', 'max' => 255 ],
  12. 'content1' => [ 'requireIf' => 'type,1' ],
  13. ];
  14. protected $field = [
  15. 'id' => 'ID',
  16. 'name' => '名称',
  17. 'type' => '发货类型',
  18. 'content' => '固定内容',
  19. 'content1' => '自定义内容',
  20. ];
  21. function sceneAdd()
  22. {
  23. return $this->only([ 'name', 'type', 'content', 'content1' ]);
  24. }
  25. function sceneEdit()
  26. {
  27. return $this->only([ 'id', 'name', 'type', 'content', 'content1' ]);
  28. }
  29. function sceneDetail()
  30. {
  31. return $this->only([ 'id' ]);
  32. }
  33. function sceneDelete()
  34. {
  35. return $this->only([ 'id' ])->append('id', 'checkId');
  36. }
  37. function checkId($fieldValue, $rule, $data)
  38. {
  39. if (Goods::where('delivery_template_id', $data['id'])->value('id')) {
  40. return '存在商品使用此模版 不能删除';
  41. }
  42. return true;
  43. }
  44. }