DeliveryLimit.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\store\model;
  13. use app\common\model\DeliveryLimit as DeliveryLimitModel;
  14. /**
  15. * 配送模板区域及运费模型
  16. * Class DeliveryRule
  17. * @package app\store\model
  18. */
  19. class DeliveryLimit extends DeliveryLimitModel
  20. {
  21. /**
  22. * 添加新记录
  23. * @param array $data
  24. * @return bool
  25. */
  26. public function add(array $data)
  27. {
  28. // 表单验证
  29. if (!$this->onValidate($data)) {
  30. return false;
  31. }
  32. $upd = [
  33. 'region' => $data['region'],
  34. 'region_text' => $data['region_text'],
  35. 'store_id' => self::$storeId
  36. ];
  37. $this->save($upd);
  38. return true;
  39. }
  40. /**
  41. * 编辑记录
  42. * @param array $data
  43. * @return bool
  44. */
  45. public function edit(array $data)
  46. {
  47. // 表单验证
  48. if (!$this->onValidate($data)) {
  49. return false;
  50. }
  51. $upd = [
  52. 'limit_id' => $data['limit_id'],
  53. 'region' => $data['region'],
  54. 'region_text' => $data['region_text']
  55. ];
  56. $this->save($upd);
  57. return true;
  58. }
  59. /**
  60. * 表单验证
  61. * @param $data
  62. * @return bool
  63. */
  64. private function onValidate(array $data)
  65. {
  66. if (!isset($data['region']) || empty($data['region'])) {
  67. $this->error = '请选择可配送区域';
  68. return false;
  69. }
  70. return true;
  71. }
  72. }