150], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => '主键', 'name' => '地区名', 'parent_id' => '上级ID', 'level' => '层级', 'short_title' => '缩写', 'areacode' => '区域编码', 'zipcode' => '邮政编码', 'initial' => '拼音首字母', 'lng' => '经度', 'lat' => '纬度', 'created_at' => '创建时间', 'updated_at' => '更新时间', ]; } /** * @param array $where * @param string $select * @param array $with * @param int $is_array * @return array|Region[]|\yii\db\ActiveRecord[] */ public static function getRegionList(array $where, $select = '*', array $with = [], int $is_array = 0) { $offset = 1; $limit = 1000; $params['where'] = $where; $params['with'] = $with; $params['select'] = $select; $params['limit'] = $limit; $list = []; $is_flag = true; do { $params['offset'] = ($offset - 1) * $limit; $rows = self::lists($params); $list = array_merge($list, $rows); if (empty($rows)) $is_flag = false; $offset++; } while ($is_flag); return $list; } /** * @Description: 获取用户地址信息 * @Author: qi * @DateTime 2022-11-02 17:39:28 * @param integer $user_id * @param integer $address_id * @return mixed */ public static function getUserAddress($user_id, $address_id = 0) { $default_cond = [['status' => StatusEnum::ENABLED, 'user_id' => $user_id]]; if ($address_id > 0) { $cond = array_merge($default_cond, [['id' => $address_id]]); return UserAddress::getOne($cond, true, [], false, 'id,province_id,city_id,district_id,name,mobile,province,city,district,town,detail'); } else { $result = []; //有默认地址取默认地址,没有取第一个 $list = UserAddress::lists([ 'where' => $default_cond, 'select' => 'id,name,mobile,province_id,city_id,district_id,province,city,district,town,detail,is_default', 'order' => 'is_default desc,id asc', 'offset' => 0, 'limit' => 2 ], true); foreach ($list as $item) { if ($item['is_default']) { $result = $item; break; } } if (empty($result) && !empty($list)) $result = $list[0]; return $result; } } }