'ID', 'mall_id' => '商城ID', 'goods_id' => '商品ID', 'province_id' => '省份ID', 'city_id' => '城市ID', 'district_id' => '区ID', 'town_id' => '镇ID', 'is_enable' => '是否启用[0禁用; 1启用]', 'status' => '状态[-1删除, 0禁用; 1正常]', 'created_at' => '创建时间', 'updated_at' => '更新时间', ]; } /** * @Description: 保存数据 * @Author: zsan * @DateTime 2024-02-22 18:23:51 * @param array $data * @return self|bool */ public static function setData(array $data) { try { foreach (self::$address_fields as $value) { $data[$value] = isset($data[$value]) ? (int)$data[$value] : 0; } $model = self::findOne(['goods_id' => $data['goods_id'], 'mall_id' => $data['mall_id'], 'status' => StatusEnum::ENABLED]); if (empty($model)) { $model = new self(); $model->loadDefaultValues(); } if (!$model->load($data, '') || !$model->save()) throw new \Exception($model->getErrorMessage()); return $model; } catch (\Exception $e) { self::setStaticError($e->getMessage()); return false; } } /** * @Description: 格式化地址id * @Author: zsan * @DateTime 2024-02-23 09:41:00 * @param integer $province_id * @param integer $city_id * @param integer $district_id * @return array */ public static function formatAddressIds($province_id, $city_id, $district_id) { return [$province_id, $city_id, $district_id]; } /** * @Description: 通过地址id获取商品id * @Author: zsan * @DateTime 2024-02-23 11:13:44 * @param integer $mall_id * @param array $params * @return array|bool */ public static function getGoodsIdByAddressIds($mall_id, $params) { $where = ['and', ['mall_id' => $mall_id], ['status' => StatusEnum::ENABLED], ['is_enable' => StatusEnum::ENABLED]]; $is_search = false; foreach (self::$address_fields as $value) { if (!empty($params[$value])) { $where[] = [$value => $params[$value]]; $is_search = true; } } if ($is_search === false) return false; return (array)self::find()->where($where)->select('goods_id')->asArray()->column(); } }