// +---------------------------------------------------------------------- declare (strict_types = 1); namespace app\store\model; use app\common\model\DeliveryLimit as DeliveryLimitModel; /** * 配送模板区域及运费模型 * Class DeliveryRule * @package app\store\model */ class DeliveryLimit extends DeliveryLimitModel { /** * 添加新记录 * @param array $data * @return bool */ public function add(array $data) { // 表单验证 if (!$this->onValidate($data)) { return false; } $upd = [ 'region' => $data['region'], 'region_text' => $data['region_text'], 'store_id' => self::$storeId ]; $this->save($upd); return true; } /** * 编辑记录 * @param array $data * @return bool */ public function edit(array $data) { // 表单验证 if (!$this->onValidate($data)) { return false; } $upd = [ 'limit_id' => $data['limit_id'], 'region' => $data['region'], 'region_text' => $data['region_text'] ]; $this->save($upd); return true; } /** * 表单验证 * @param $data * @return bool */ private function onValidate(array $data) { if (!isset($data['region']) || empty($data['region'])) { $this->error = '请选择可配送区域'; return false; } return true; } }